@w6w/ui 0.2.11 → 0.2.54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +139 -2
- package/README.md +28 -10
- package/dist/AppPicker.d.ts +12 -1
- package/dist/CanvasContextMenu.d.ts +19 -0
- package/dist/{CodeBlock-BqXDA35P.js → CodeBlock-C-oIIYfC.js} +1436 -555
- package/dist/CodeBlock-C-oIIYfC.js.map +1 -0
- package/dist/CodeBlock-CymlfyeA.cjs +15 -0
- package/dist/CodeBlock-CymlfyeA.cjs.map +1 -0
- package/dist/CodeEditor.d.ts +4 -1
- package/dist/ConditionEditor.d.ts +11 -0
- package/dist/JsonEditor.d.ts +12 -0
- package/dist/ParamCustomization.d.ts +5 -0
- package/dist/ParamsForm.d.ts +11 -3
- package/dist/RouterEditor.d.ts +5 -0
- package/dist/StepBuilderModal.d.ts +83 -13
- package/dist/StepNameEditor.d.ts +11 -0
- package/dist/StopEditor.d.ts +5 -0
- package/dist/TriggerFillForm.d.ts +14 -1
- package/dist/WebhookListenPanel.d.ts +28 -0
- package/dist/WorkflowConnections.d.ts +29 -0
- package/dist/WorkflowFlowEditor.d.ts +64 -8
- package/dist/assets/script-completion.worker-DDJKkj5M.js +8290 -0
- package/dist/assets/script-completion.worker-DDJKkj5M.js.map +1 -0
- package/dist/canvas-context-menu.d.ts +27 -0
- package/dist/code.cjs +1 -1
- package/dist/code.mjs +3 -4
- package/dist/code.mjs.map +1 -1
- package/dist/components/AnchoredFlyout.d.ts +7 -0
- package/dist/components/ColumnsEditor.d.ts +27 -0
- package/dist/components/Combobox.d.ts +12 -1
- package/dist/components/CsvPanel.d.ts +21 -0
- package/dist/components/DataEntryEditor.d.ts +38 -0
- package/dist/components/DataEntryList.d.ts +33 -0
- package/dist/components/DataStoreList.d.ts +33 -0
- package/dist/components/DataTableGrid.d.ts +46 -0
- package/dist/components/EventbriteTriggerPicker.d.ts +7 -0
- package/dist/components/ExecutionDetail.d.ts +17 -1
- package/dist/components/ExecutionList.d.ts +19 -1
- package/dist/components/ExecutionLogPanel.d.ts +61 -3
- package/dist/components/ExpressionEditorModal.d.ts +33 -10
- package/dist/components/ExpressionOptions.d.ts +101 -15
- package/dist/components/HtmlPreview.d.ts +7 -0
- package/dist/components/JsonTree.d.ts +32 -0
- package/dist/components/ResolvedParams.d.ts +6 -1
- package/dist/components/ResultViewer.d.ts +46 -0
- package/dist/components/ScriptBindingsNotice.d.ts +31 -0
- package/dist/components/ScriptCodeField.d.ts +13 -0
- package/dist/components/StepStatusPill.d.ts +7 -0
- package/dist/components/expression-authoring.d.ts +13 -0
- package/dist/components/expression-dom.d.ts +17 -2
- package/dist/components/expression-template.d.ts +25 -3
- package/dist/components/icons.d.ts +1 -1
- package/dist/components/json-compose.d.ts +53 -0
- package/dist/components/result-format.d.ts +13 -0
- package/dist/condition-editor.d.ts +44 -0
- package/dist/data-stores/data-store-view.d.ts +371 -0
- package/dist/eventbrite-trigger-selection.d.ts +13 -0
- package/dist/flow-connect.d.ts +22 -16
- package/dist/flow-delete.d.ts +16 -0
- package/dist/flow-history.d.ts +75 -0
- package/dist/flow-layout.d.ts +13 -0
- package/dist/flow-loop-colors.d.ts +39 -0
- package/dist/flow-loop.d.ts +98 -0
- package/dist/flow-node-flags.d.ts +14 -0
- package/dist/flow-problems.d.ts +69 -0
- package/dist/flow-state.d.ts +20 -0
- package/dist/flow-types.d.ts +137 -9
- package/dist/flow-utils.d.ts +27 -13
- package/dist/flow.cjs +4 -2
- package/dist/flow.cjs.map +1 -1
- package/dist/flow.d.ts +7 -3
- package/dist/flow.mjs +3563 -1557
- package/dist/flow.mjs.map +1 -1
- package/dist/index.cjs +2 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +30 -4
- package/dist/index.mjs +2555 -1272
- package/dist/index.mjs.map +1 -1
- package/dist/node-samples-ChdyMBnJ.cjs +22 -0
- package/dist/node-samples-ChdyMBnJ.cjs.map +1 -0
- package/dist/node-samples-DkJL07EX.js +12302 -0
- package/dist/node-samples-DkJL07EX.js.map +1 -0
- package/dist/node-samples.d.ts +80 -0
- package/dist/output-shape.d.ts +30 -14
- package/dist/param-customization.d.ts +7 -0
- package/dist/provider.d.ts +119 -7
- package/dist/resolve-params.d.ts +45 -11
- package/dist/run-visuals.d.ts +14 -21
- package/dist/script-bindings.d.ts +63 -0
- package/dist/script-completion-service.d.ts +9 -0
- package/dist/script-completion.worker.d.ts +1 -0
- package/dist/script-completions.d.ts +2 -0
- package/dist/state-shape.d.ts +38 -0
- package/dist/step-preview-state.d.ts +155 -6
- package/dist/step-problems.d.ts +42 -12
- package/dist/test-inputs.d.ts +25 -0
- package/dist/trigger-registration.d.ts +28 -0
- package/dist/types.d.ts +70 -8
- package/dist/use-app-action-defs.d.ts +9 -1
- package/dist/use-test-input.d.ts +18 -0
- package/dist/workflow-connections.d.ts +30 -0
- package/package.json +16 -7
- package/src/code.css +60 -6
- package/src/styles/_canvas.scss +35 -0
- package/src/styles/_code-editor.scss +35 -0
- package/src/styles/_code.scss +6 -5
- package/src/styles/_copyable.scss +24 -0
- package/src/styles/_data-stores.scss +138 -0
- package/src/styles/_data-vars.scss +17 -6
- package/src/styles/_execution-history.scss +73 -0
- package/src/styles/_execution-log.scss +145 -1
- package/src/styles/_expression-modal.scss +106 -16
- package/src/styles/_fields.scss +11 -0
- package/src/styles/_flow.scss +160 -0
- package/src/styles/_fx.scss +3 -1
- package/src/styles/_incoming-state.scss +33 -0
- package/src/styles/_modal.scss +12 -0
- package/src/styles/_multiselect.scss +35 -0
- package/src/styles/_sections.scss +36 -0
- package/src/styles/_step-builder.scss +145 -0
- package/src/styles/_tester.scss +56 -0
- package/src/styles/_tokens.scss +27 -1
- package/src/styles.css +1290 -77
- package/src/styles.scss +2 -0
- package/dist/CodeBlock-BqXDA35P.js.map +0 -1
- package/dist/CodeBlock-CulfbnZD.cjs +0 -15
- package/dist/CodeBlock-CulfbnZD.cjs.map +0 -1
- package/dist/ConfirmModal-Ln99S9NT.js +0 -7919
- package/dist/ConfirmModal-Ln99S9NT.js.map +0 -1
- package/dist/ConfirmModal-fjHW5rN-.cjs +0 -14
- package/dist/ConfirmModal-fjHW5rN-.cjs.map +0 -1
- package/dist/Copyable-DA6eiU7w.cjs +0 -2
- package/dist/Copyable-DA6eiU7w.cjs.map +0 -1
- package/dist/Copyable-F4NTaG77.js +0 -847
- package/dist/Copyable-F4NTaG77.js.map +0 -1
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";const n=require("react/jsx-runtime"),Bn=require("@xyflow/react"),w=require("react"),cn=require("react-dom"),ue=require("./CodeBlock-CymlfyeA.cjs"),Mo=require("@codemirror/lang-json"),no=require("@codemirror/lint"),ls=require("@codemirror/view"),Do=require("@uiw/react-codemirror"),ie=require("@w6w/expr"),qn=require("@codemirror/lang-javascript"),Ii=require("@codemirror/lang-python"),$i=require("react-markdown");var $n=typeof document<"u"?document.currentScript:null;const Pi={ai:"AI",cms:"CMS",crm:"CRM",hr:"HR",devops:"DevOps"};function _i(e){if(typeof e!="string"||e.trim()==="")return"";const t=Pi[e];return t||e.split(/[-_\s]+/).filter(Boolean).map(s=>s.charAt(0).toUpperCase()+s.slice(1)).join(" ")}function Li(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:_i(s),count:o})).sort((s,o)=>o.count-s.count||s.label.localeCompare(o.label,void 0,{sensitivity:"base"}))}function Fi(e,t){if(t.length===0)return!0;const s=e.categories??[];return t.some(o=>s.includes(o))}function Ut(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 cs="out-error",hn="out-each",yt="done",Ho="each";function us(e){return e==="error"?cs:e==="each"?hn:void 0}function Mi(e){return e===cs?"error":e===hn?"each":"success"}const Di="@w6w/",Pe="@w6w/control",Bo="@w6w/script",Lt="@w6w/data",mn="@w6w/trigger",Hi="@w6w/http",Le="@w6w/webhook",ds="@w6w/scheduler",Bi="@w6w/respond",wn="@w6w/call",ps="@w6w/document",Pn="@w6w/model",qi="@w6w/template",Gt="@w6w/regex",De="@w6w/store",fs="@w6w/stop",qe="@w6w/router",Vt="@w6w/race",qo="Continue once with the first arriving path’s output. Later arrivals are ignored for this run. Other paths keep running.";function hs(e){var t;return e.uses.app!==qe||!Array.isArray((t=e.with)==null?void 0:t.routes)?[]:e.with.routes.filter(s=>!!s&&typeof s=="object"&&typeof s.id=="string")}const Nt=e=>`route:${e}`,Wi=e=>e!=null&&e.startsWith("route:")?e.slice(6):void 0,Ui=3,Vi=16;function zi(e){const t=e.find(r=>r.default),s=r=>({id:r.id,handleId:Nt(r.id),label:r.default?"Fallback":r.label||r.id}),o=e.filter(r=>r!==t);return{right:o.map((r,i)=>({...s(r),top:`${(i+.5)/o.length*100}%`})),...t?{bottom:s(t)}:{},...o.length>Ui?{minHeight:o.length*Vi}:{}}}const un="false";function ms(e){return e.uses.app===Pe&&e.uses.action==="if"}function Ji(){return{right:[{id:"true",label:"True",top:"50%"}],bottom:{id:un,handleId:Nt(un),label:"False"}}}function Ye(e){return e.startsWith(Di)}function Et(e){return e===Pe||e===Vt}function Ft(e){return e===mn||e===Le||e===ds}function Ki(e){return Ft(e.app)||e.trigger===!0}const so={in:1,out:Number.POSITIVE_INFINITY};function oo(e){return e==="many"?Number.POSITIVE_INFINITY:typeof e=="number"?e:void 0}function Gi(...e){let t,s;for(const o of e)t??(t=oo(o==null?void 0:o.in)),s??(s=oo(o==null?void 0:o.out));return{in:t??so.in,out:s??so.out}}function Mt(e,t){var i;if(e.uses.app===qe)return{in:1,out:hs(e).length};const{app:s,action:o}=e.uses,r=e.uses.trigger?{in:0,out:1}:void 0;return Gi(e.ports,t==null?void 0:t(s,o),((i=it(s,o))==null?void 0:i.ports)??r)}const Yi='<polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2" />',ro='<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" />',Xi='<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" />',Zi='<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" />',Qi='<circle cx="12" cy="12" r="9" /><polyline points="12 7 12 12 15 14" />',ea='<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" />',ta='<polyline points="16 18 22 12 16 6" /><polyline points="8 6 2 12 8 18" />',io='<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" />',na='<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" />',sa='<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" />',oa='<polyline points="9 17 4 12 9 7" /><path d="M20 18v-2a4 4 0 0 0-4-4H4" />',ao='<polygon points="22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3" />',ra='<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" />',ia='<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" />',_n='<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" />',aa='<path d="M8 3H7a2 2 0 0 0-2 2v4a2 2 0 0 1-2 2 2 2 0 0 1 2 2v4a2 2 0 0 0 2 2h1" /><path d="M16 3h1a2 2 0 0 1 2 2v4a2 2 0 0 0 2 2 2 2 0 0 0-2 2v4a2 2 0 0 1-2 2h-1" />',ot='<ellipse cx="12" cy="5" rx="9" ry="3" /><path d="M3 5v14c0 1.66 4.03 3 9 3s9-1.34 9-3V5" /><path d="M3 12c0 1.66 4.03 3 9 3s9-1.34 9-3" />',la=[{app:Gt,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:Gt,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:Gt,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:Gt,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"}]}],pt=[...la,{app:Vt,action:"race",label:"Race",displayName:"Race",group:"control",icon:'<path d="M3 5h4l5 7h9M3 19h4l5-7" /><polyline points="17 8 21 12 17 16" />',ports:{in:"many",out:1},params:[]},{app:qe,action:"route",label:"Router",displayName:"Router",group:"control",icon:ro,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:fs,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:mn,action:"manual",label:"Manual trigger",displayName:"Manual trigger",group:"trigger",icon:Yi,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"},{key:"required",label:"Required",type:"boolean",default:!1}]}}]},{app:Le,action:"webhook",label:"Webhook",displayName:"Webhook",group:"trigger",icon:sa,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:ds,action:"schedule",label:"Schedule",displayName:"Scheduler",group:"trigger",icon:ea,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:Pe,action:"if",label:"If",displayName:"If",group:"control",icon:ro,params:[{key:"condition",type:"json",label:"Condition",required:!0,default:!0,hint:"A boolean, or an expression like {{ nodes.x.output.ok }}."}]},{app:Pe,action:"foreach",label:"For each",displayName:"For each",group:"control",icon:Xi,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:Pe,action:"parallel",label:"Parallel",displayName:"Parallel",group:"control",icon:Zi,params:[]},{app:Pe,action:"wait",label:"Wait",displayName:"Wait",group:"control",icon:Qi,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:Bo,action:"run",label:"Run script",displayName:"Run script",group:"compute",icon:ta,params:[{key:"language",label:"Language",type:"select",default:"javascript",options:[{value:"javascript",label:"JavaScript"},{value:"typescript",label:"TypeScript"},{value:"python",label:"Python"}],hint:"Execution language for this step's code. TypeScript types are erased before it runs, not checked. Python runs CPython-on-WASM with no network."},{key:"code",type:"code",label:"Script",required:!0,scriptReads:!0,default:`// Runs as a function body. Return the step's output.
|
|
2
|
+
return input;`,hint:"Return the step's output. Read data from state, vars and consts; {{ }} isn't substituted in code. digest(value) returns a stable SHA-256 hex (await it in JavaScript or TypeScript)."},{key:"custom_input",type:"section",section:"collapsible",title:"Custom input (advanced)",openWhenSet:!0,children:[{key:"input",type:"json",label:"Input",whole:!0,hint:"Replaces what the script reads as `input` (by default, the run state). Each bound value keeps its type; a secret goes here, since state never holds one."}]}]},{app:qi,action:"render",label:"Render template",displayName:"Template",group:"compute",icon:aa,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:Lt,action:"set",label:"Data",displayName:"Data set",group:"compute",icon:io,params:[{key:"vars",type:"vars",label:"Variables",required:!0,default:[],hint:"Set values for downstream steps using individual fields or a JSON object."}]},{app:Lt,action:"update",label:"Update object",displayName:"Update object",group:"compute",icon:io,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:Hi,action:"request",label:"HTTP request",displayName:"HTTP",group:"request",icon:na,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:Bi,action:"respond",label:"Respond to Webhook",displayName:"Respond to Webhook",group:"request",icon:oa,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:Pe,action:"aggregate",label:"Aggregate",displayName:"Aggregate",group:"control",icon:ao,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:Pe,action:"merge",label:"Merge",displayName:"Merge",group:"control",icon:ao,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:wn,action:"call",label:"Call workflow",displayName:"Call",group:"compute",icon:ra,ports:{in:1,out:1},params:[{key:"targetKind",label:"Target kind",type:"select",required:!0,default:"workflow",hint:"Whether this node calls another Workflow or a Function.",options:[{value:"workflow",label:"Workflow"},{value:"function",label:"Function"}]},{key:"targetId",label:"Target id",type:"string",required:!0,default:"",placeholder:"e.g. wf_… or fn_…",hint:"Id of the Workflow (wf_…) or Function (fn_…) to call, within this project."},{key:"inputs",label:"Inputs",type:"json",default:{},hint:"Payload passed to the target — an object keyed by the callee's declared inputs. Values may be expressions."},{key:"wait",label:"Wait for completion",type:"boolean",default:!0,hint:"On: block until the sub-run finishes and expose its output. Off: return a run handle and continue."}]},{app:ps,action:"get",label:"Get document",displayName:"Document",group:"compute",icon:ia,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:Pn,action:"complete",label:"Complete with model",displayName:"Model",group:"compute",icon:_n,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:Pn,action:"list-models",label:"List models",displayName:"Model",group:"compute",icon:_n,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:Pn,action:"allowance",label:"Model allowance",displayName:"Model",group:"compute",icon:_n,ports:{in:1,out:1},params:[{key:"connection",label:"Connection",type:"string",required:!0,hint:"Connection id of the provider to read the allowance of."}]},{app:De,action:"get",label:"Get entry",displayName:"Store",group:"compute",icon:ot,ports:{in:1,out:1},params:[{key:"store",label:"Store",type:"data-store",required:!0,hint:"Name of a data store in this account and project."},{key:"key",label:"Key",type:"data-store-key",required:!0,hint:"Entry key — search the store's entries, type a key, or bind an expression."},{key:"required",label:"Required",type:"boolean",default:!1,hint:"Fail the step when the key is missing instead of returning found: false."}],output:[{key:"found"},{key:"key"},{key:"value"},{key:"version"},{key:"expiresAt"}]},{app:De,action:"set",label:"Set entry",displayName:"Store",group:"compute",icon:ot,ports:{in:1,out:1},params:[{key:"store",label:"Store",type:"data-store",required:!0,hint:"Name of a data store in this account and project."},{key:"key",label:"Key",type:"data-store-key",required:!0,hint:"Entry key — search the store's entries, type a key, or bind an expression."},{key:"value",label:"Value",type:"json",required:!0,hint:"The JSON value to store."},{key:"ifVersion",label:"If version",type:"number",hint:"Write only when the stored version equals this number."},{key:"ttlSeconds",label:"TTL (seconds)",type:"number",hint:"Expire the entry after this many seconds. Omit to keep it."}],output:[{key:"key"},{key:"value"},{key:"version"},{key:"expiresAt"}]},{app:De,action:"delete",label:"Delete entry",displayName:"Store",group:"compute",icon:ot,ports:{in:1,out:1},params:[{key:"store",label:"Store",type:"data-store",required:!0,hint:"Name of a data store in this account and project."},{key:"key",label:"Key",type:"data-store-key",required:!0,hint:"Entry key — search the store's entries, type a key, or bind an expression."}],output:[{key:"key"},{key:"deleted"}]},{app:De,action:"increment",label:"Increment counter",displayName:"Store",group:"compute",icon:ot,ports:{in:1,out:1},params:[{key:"store",label:"Store",type:"data-store",required:!0,hint:"Name of a data store in this account and project."},{key:"key",label:"Key",type:"data-store-key",required:!0,hint:"Entry key — search the store's entries, type a key, or bind an expression."},{key:"by",label:"By",type:"number",default:1,hint:"Amount to add; may be negative."}],output:[{key:"key"},{key:"value"},{key:"version"}]},{app:De,action:"list",label:"List entries",displayName:"Store",group:"compute",icon:ot,ports:{in:1,out:1},params:[{key:"store",label:"Store",type:"data-store",required:!0,hint:"Name of a data store in this account and project."},{key:"prefix",label:"Prefix",type:"string",hint:"Only entries whose key starts with this."},{key:"cursor",label:"Cursor",type:"string",hint:"The nextCursor of a previous page."},{key:"limit",label:"Limit",type:"number",default:50,hint:"Page size, at most 200."}],output:[{key:"items"},{key:"nextCursor"}]},{app:De,action:"query",label:"Query rows",displayName:"Store",group:"compute",icon:ot,ports:{in:1,out:1},params:[{key:"store",label:"Store",type:"data-store",required:!0,hint:"Name of a data store in this account and project."},{key:"where",label:"Where",type:"json",hint:"Column equality filter."},{key:"order",label:"Order",type:"string",hint:"Column to order by; prefix with - for descending."},{key:"limit",label:"Limit",type:"number",hint:"Maximum rows to return."}],output:[{key:"items"}]},{app:De,action:"insert",label:"Insert row",displayName:"Store",group:"compute",icon:ot,ports:{in:1,out:1},params:[{key:"store",label:"Store",type:"data-store",required:!0,hint:"Name of a data store in this account and project."},{key:"row",label:"Row",type:"json",required:!0,hint:"The row, keyed by column name."},{key:"ttlSeconds",label:"TTL (seconds)",type:"number",hint:"Expire the entry after this many seconds. Omit to keep it."}],output:[{key:"key"},{key:"value"},{key:"version"}]}];function it(e,t){return pt.find(s=>s.app===e&&s.action===t)}function ca(e,t){var s;return((s=it(e,t))==null?void 0:s.label)??t}function ua(e,t){var s;return((s=it(e,t))==null?void 0:s.icon)??""}function Wo(e,t){var s;return((s=it(e,t))==null?void 0:s.params)??[]}function dn(e,t){const s={};for(const o of Wo(e,t))o.default!==void 0&&(s[o.key]=o.default);return s}function da(e,t){return e.q===t.q&&(e.category??"")===(t.category??"")&&(e.ids??[]).join(",")===(t.ids??[]).join(",")}function Uo(e,t=0){return{query:e,generation:t,status:"loading",apps:[],hasMore:!1}}function pa(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 fa(e,t){switch(t.type){case"query-changed":return t.generation===e.generation&&da(t.query,e.query)?e:Uo(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=pa(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 ha(e){return e.filter(t=>!Ye(t.id))}function Ln(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 ma(e,t){const s=[];for(const o of e){const r=t.get(o);r&&s.push(r)}return s}const Vo=w.createContext(void 0);function lo(e,t){var o;if(e)return e;if(t)return t;if(typeof document>"u")return"light";const s=document.documentElement.getAttribute("data-theme");return s==="dark"||s==="light"?s:(o=window.matchMedia)!=null&&o.call(window,"(prefers-color-scheme: dark)").matches?"dark":"light"}function bn(e){const t=w.useContext(Vo),[s,o]=w.useState(()=>lo(e,t));return w.useEffect(()=>{if(e){o(e);return}if(t){o(t);return}if(typeof window>"u")return;const r=()=>o(lo(void 0,t)),i=window.matchMedia("(prefers-color-scheme: dark)");i.addEventListener("change",r);const a=new MutationObserver(r);return a.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]}),r(),()=>{i.removeEventListener("change",r),a.disconnect()}},[e,t]),s}function ft({src:e,srcDark:t,brandColor:s,name:o,size:r=32,theme:i}){const l=bn(i)==="dark"?t??e:e,[c,u]=w.useState(void 0);if(l&&l!==c)return n.jsx("img",{src:l,width:r,height:r,alt:"",onError:()=>u(l),style:{width:r,height:r,borderRadius:6,flexShrink:0,objectFit:"contain",padding:Math.max(1,Math.round(r*.06)),boxSizing:"border-box",background:"var(--w6w-icon-swatch, var(--w6w-panel-2))"}});const d=(o??"?").split(/\s+/).slice(0,2).map(f=>{var p;return((p=f[0])==null?void 0:p.toUpperCase())??""}).join("");return n.jsx("span",{"aria-hidden":"true",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:r,height:r,borderRadius:6,background:s??"var(--w6w-accent)",color:"#fff",fontWeight:700,fontSize:Math.round(r*.42),flexShrink:0},children:d})}const ws=w.createContext(null);function wa({api:e,theme:t,children:s}){const o=n.jsx(ws.Provider,{value:e,children:n.jsx(Vo.Provider,{value:t,children:s})});return t?n.jsx("div",{"data-theme":t,style:{display:"contents"},children:o}):o}function ye(){const e=w.useContext(ws);if(!e)throw new Error("useW6WApi must be used inside <W6WUIProvider>. Wrap your app root with <W6WUIProvider api={api}>...</W6WUIProvider>.");return e}function en(){return w.useContext(ws)??void 0}const zo=w.createContext(void 0),Jo=w.createContext(void 0);function ba({project:e,workflowId:t,children:s}){return n.jsx(zo.Provider,{value:e,children:n.jsx(Jo.Provider,{value:t,children:s})})}function bs(){return w.useContext(zo)}function ga(){return w.useContext(Jo)}const Fn=8,ya=60,xa=300;function co(e){const t=e.modelProvider;return!t||typeof t!="object"?null:t}function va(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 at({onSelectApp:e,theme:t,filter:s,searchPlaceholder:o,emptyMessage:r,search:i=!0,searchValue:a,onSearchChange:l,emptyAction:c,apps:u,categoryFilter:d=!1,providerFilter:f=!1,bridgeSupport:p,category:h,hasTriggers:b,ids:m,pageLimit:x=ya,loadPage:g}){const y=ye(),N=u!==void 0,A=m&&m.length>0?m.join(","):"",k=!N&&(g!==void 0||typeof y.listAppsPage=="function"),C=w.useRef(g);C.current=g;const[v,E]=w.useState(null),[R,F]=w.useState(null);w.useEffect(()=>{if(N||k)return;const B=y.listApps;if(typeof B!="function"){E([]);return}let Q=!1;return B().then(de=>!Q&&E(de)).catch(de=>!Q&&F(de.message)),()=>{Q=!0}},[y,N,k]);const[O,T]=w.useReducer(fa,Uo({q:"",category:h,ids:m},0)),[I,M]=w.useState(""),q=a??I,D=B=>{a===void 0&&M(B),l==null||l(B)},[Y,$]=w.useState(q.trim()),G=w.useRef(0),ne=w.useRef(null),oe=w.useCallback((B,Q,de)=>{var Kt;const Je=C.current,st=y.listAppsPage;if(!Je&&!st)return;(Kt=ne.current)==null||Kt.abort();const ke=new AbortController;ne.current=ke;let $e;try{$e=Je?Je({q:B.q||void 0,cursor:de,limit:x,...B.ids?{ids:B.ids}:{},signal:ke.signal}):st({q:B.q||void 0,category:B.category,...b?{hasTriggers:!0}:{},...B.ids?{ids:B.ids}:{},cursor:de,limit:x,compact:!0,signal:ke.signal})}catch(we){$e=Promise.reject(we)}$e.then(we=>{if(G.current===Q){if(!we||!Array.isArray(we.apps)){T({type:"page-failed",generation:Q,error:"The server returned a malformed apps page."});return}T({type:"page-loaded",generation:Q,apps:we.apps,nextCursor:we.nextCursor,requestedCursor:de,total:typeof we.total=="number"?we.total:void 0})}}).catch(we=>{if(G.current!==Q||we instanceof Error&&we.name==="AbortError")return;const j=we==null?void 0:we.code;if(de!==void 0&&(j==="snapshot_expired"||j==="unknown_snapshot")){const _=++G.current;T({type:"query-changed",query:B,generation:_}),oe(B,_,void 0);return}T({type:"page-failed",generation:Q,error:we.message})})},[y,x,b]);w.useEffect(()=>{if(!k)return;const B=setTimeout(()=>$(q.trim()),xa);return()=>clearTimeout(B)},[q,k]),w.useEffect(()=>{if(!k)return;const B=++G.current,Q={q:Y,category:h,...A?{ids:A.split(",")}:{}};return T({type:"query-changed",query:Q,generation:B}),oe(Q,B,void 0),()=>{var de;(de=ne.current)==null||de.abort()}},[k,Y,h,A,oe]),w.useEffect(()=>{if(k)return()=>{var B;return(B=ne.current)==null?void 0:B.abort()}},[k]);const X=()=>{if(!k||O.status!=="ready"||!O.hasMore)return;const B=G.current;T({type:"load-more"}),oe(O.query,B,O.cursor)},L=()=>{!k||O.status!=="error"||(T({type:"retry"}),oe(O.query,G.current,O.cursor))},[z,Z]=w.useState([]),[W,J]=w.useState(!1),[te,S]=w.useState(!1),U=B=>n.jsx("div",{className:"w6w-apppicker-host",children:B});let V,P=null,H=!1,ae=!1,fe=null,he=!1;if(N?V=u??null:k?(V=O.apps,he=O.status==="loading",H=O.status==="loading-more",ae=O.hasMore,O.status==="error"&&(O.apps.length===0?P=O.error??"Failed to load apps.":fe=O.error??"Failed to load apps.")):(V=v,P=R),!k&&P)return U(n.jsx("div",{className:"w6w-result w6w-error",children:P}));if(!k&&V===null)return U(n.jsx("p",{className:"w6w-muted w6w-small",children:"Loading apps…"}));V??(V=[]);const ge=ha(V),ve=s?ge.filter(s):ge;if(!k&&ve.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."}),c]}));const Ae=d?Li(ve):[],Te=Ae.slice(0,Fn),le=Ae.slice(Fn).filter(B=>z.includes(B.slug)),Ee=[...Te,...le],mt=Ae.length-Ee.length,Ue=W?Ae:Ee,Ct=B=>Z(Q=>Q.includes(B)?Q.filter(de=>de!==B):[...Q,B]),et=()=>Z([]),Ve=ve.filter(B=>co(B)!==null).length,tt=f&&Ve>0,Fe=tt&&te,me=Fe?ve.filter(B=>co(B)!==null):ve,Oe=d&&z.length>0?me.filter(B=>Fi(B,z)):me,nt=k?Oe:[...Oe].sort((B,Q)=>B.displayName.localeCompare(Q.displayName,void 0,{sensitivity:"base"})),xe=k?"":q.trim().toLowerCase(),je=q.trim().length>0,Ie=xe?nt.filter(B=>B.displayName.toLowerCase().includes(xe)||B.id.toLowerCase().includes(xe)):nt,Ne=s!==void 0&&ve.length!==ge.length||Fe&&me.length!==ve.length||d&&z.length>0&&Oe.length!==me.length,At=(d&&z.length>0||Fe)&&Ie.length===0,ze=Fe&&z.length===0,ee=()=>{Z([]),S(!1),D("")};return U(n.jsxs("div",{className:"w6w-stepbuilder-apps",children:[i&&n.jsx("input",{type:"text",className:"w6w-stepbuilder-search",placeholder:o??"Search apps…",value:q,onChange:B=>D(B.target.value),"aria-label":"Search apps"}),(tt||d&&Ae.length>0)&&n.jsxs("div",{className:"w6w-apppicker-cats",children:[tt&&n.jsxs("button",{type:"button",className:"w6w-apppicker-chip w6w-apppicker-provider-toggle","aria-pressed":te,"aria-label":"Filter to model providers",onClick:()=>S(B=>!B),children:["Model providers ",n.jsxs("span",{className:"w6w-muted",children:["(",Ve,")"]})]}),d&&Ae.length>0&&n.jsxs(n.Fragment,{children:[Ue.map(B=>n.jsxs("button",{type:"button",className:"w6w-apppicker-chip","aria-pressed":z.includes(B.slug),"aria-label":`Filter by ${B.label}`,onClick:()=>Ct(B.slug),children:[B.label," ",n.jsxs("span",{className:"w6w-muted",children:["(",B.count,")"]})]},B.slug)),!W&&mt>0&&n.jsxs("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:()=>J(!0),children:["+",mt," more"]}),W&&Ae.length>Fn&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:()=>J(!1),children:"Show less"}),z.length>0&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:et,children:"Clear"})]})]}),k&&he?n.jsx("p",{className:"w6w-muted w6w-small",children:"Loading apps…"}):k&&P?n.jsxs("div",{className:"w6w-result w6w-error",children:[P," ",n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:L,children:"Retry"})]}):Ie.length===0&&!ae?At?n.jsxs("div",{className:"w6w-stack",children:[n.jsx("p",{className:"w6w-muted w6w-small",children:ze?je?`No model providers match “${q}”.`:"No apps declare a model provider.":je?`No apps match “${q}” in the selected categories.`:"No apps match the selected categories."}),n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:ee,children:"Clear filters"})]}):k?n.jsxs("div",{className:"w6w-stack",children:[n.jsx("p",{className:"w6w-muted w6w-small",children:je?`No apps match “${q}”.`:r??"No apps registered yet. Register one from the Apps page first."}),!je&&c]}):n.jsxs("p",{className:"w6w-muted w6w-small",children:["No apps match “",q,"”."]}):n.jsxs(n.Fragment,{children:[Ie.length===0&&ae?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 Q=p==null?void 0:p.get(B.id),de=va(Q);return n.jsxs("button",{type:"button",className:"w6w-stepbuilder-item w6w-apppicker-card",onClick:()=>e(B),children:[n.jsx(ft,{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]}),de&&n.jsx("span",{className:Q!=null&&Q.supported?"w6w-chip w6w-apppicker-card-bridge":"w6w-chip w6w-apppicker-card-bridge w6w-apppicker-card-bridge-unsupported",title:de.title,children:de.text})]})]},B.id)})}),k&&typeof O.total=="number"&&n.jsx("div",{className:"w6w-small w6w-apppicker-count",children:Ne?`${Ie.length} ${Ie.length===1?"app":"apps"}`:`${O.apps.length} of ${O.total}`}),k&&fe&&n.jsxs("div",{className:"w6w-result w6w-error w6w-small",children:[fe," ",n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:L,children:"Retry"})]}),k&&ae&&!fe&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm w6w-apppicker-load-more",onClick:X,disabled:H,children:H?"Loading more…":"Load more"})]})]}))}const ja=new Set(["http:","https:","mailto:"]);function Na(e){try{return ja.has(new URL(e).protocol)?e:""}catch{return""}}const ka=["img"];function Sa({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 Ko(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 Ca({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 gs({content:e,className:t}){const{frontmatter:s,body:o}=Ko(e);return n.jsxs("div",{className:t,children:[(s==null?void 0:s.trim())&&n.jsx(Ca,{yaml:s}),n.jsx($i,{skipHtml:!0,urlTransform:Na,disallowedElements:ka,unwrapDisallowed:!0,components:{a:Sa},children:o})]})}const Aa=/^(#{1,6})\s+(.*)$/,Ea=new RegExp("\\*\\*(?=\\S)(.+?)(?<=\\S)\\*\\*","g");function Ra(e,t){const s=e.ownerDocument;e.replaceChildren();for(const o of t.split(`
|
|
3
|
+
`)){const r=Aa.exec(o),i=s.createElement(r?`h${r[1].length}`:"div"),a=r?r[2]:o;let l=0;for(const c of a.matchAll(Ea)){c.index>l&&i.append(s.createTextNode(a.slice(l,c.index)));const u=s.createElement("strong");u.textContent=c[1],i.append(u),l=c.index+c[0].length}l<a.length&&i.append(s.createTextNode(a.slice(l))),i.firstChild||i.append(s.createElement("br")),e.append(i)}}function Ta(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 Oa(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 i=s.slice(0,s.indexOf(r)),a=s.slice(i.length+r.length);return`${i}**${r}**${a}`}).join("")}function Ia(e){const t=[];let s=null;const o=a=>(s={level:a,runs:[]},t.push(s),s),r=(a,l,c)=>{if(a.nodeType===3){const m=(a.textContent??"").replace(/ /g," ").replace(/\n/g,"");m&&(s??o(l)).runs.push({text:m,bold:c});return}if(a.nodeType!==1)return;const u=a,d=u.tagName.toLowerCase();if(d==="br"){s||o(l),s=null;return}const f=/^h([1-6])$/.exec(d),p=f||["div","p","li","ul","ol","blockquote","pre"].includes(d);p&&(s=null);const h=f?Number(f[1]):l,b=d==="b"||d==="strong"?!0:Ta(u)??c;for(const m of u.childNodes)r(m,h,b);p&&(s=null)};for(const a of e.childNodes)r(a,0,!1);const i=t.map(a=>{const l=Oa(a.runs);return a.level>0?`${"#".repeat(a.level)} ${l.trimStart()}`:l});for(;i.length&&i[i.length-1].trim()==="";)i.pop();return i.join(`
|
|
4
|
+
`)}function $a(e){return e.replace(/([^\n])\n(?=[^\n])/g,`$1
|
|
5
|
+
`)}const Pa=-2,_a=-1,uo=1e3,La=["#facc15","#fb923c","#f87171","#f472b6","#a78bfa","#60a5fa","#2dd4bf","#4ade80","#9ca3af"],Fa=[{level:1,label:"Title"},{level:2,label:"Heading"},{level:3,label:"Subheading"},{level:0,label:"Body"}],Ma=80,Da=48,po=10,Ha=4,Mn=e=>e.stopPropagation();function Ba(e){const t=e.ownerDocument.getSelection();if(!t)return;const s=e.ownerDocument.createRange();s.selectNodeContents(e),t.removeAllRanges(),t.addRange(s)}function qa(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 Go({canvas:e,className:t,viewport:s,readOnly:o,zoom:r=1,onChange:i,onSectionDrop:a,onRequestDelete:l}){const[c,u]=w.useState({}),[d,f]=w.useState(null),[p,h]=w.useState(null),[b,m]=w.useState(null),[x,g]=w.useState(null),y=w.useRef(null),N=w.useRef(null),A=w.useRef(null);if(w.useEffect(()=>{if(!d&&!p)return;const S=d?`[data-note-id="${d}"], [data-note-toolbar="${d}"]`:`[data-section-label="${p}"], [data-section-toolbar="${p}"]`,U=V=>{var ae,fe;const P=V.target;if((ae=P==null?void 0:P.closest)!=null&&ae.call(P,S))return;const H=document.activeElement;(fe=H==null?void 0:H.closest)!=null&&fe.call(H,"[data-section-toolbar]")&&H.blur(),f(null),h(null),g(null)};return window.addEventListener("pointerdown",U,!0),()=>window.removeEventListener("pointerdown",U,!0)},[d,p]),!s)return null;const k=!o&&!!i,C=e.sections??[],v=e.notes??[],E=S=>c[S.id]??{x:S.position.x,y:S.position.y,w:S.size.width,h:S.size.height},R=S=>{const U=E(S);return{left:U.x,top:U.y,width:U.w,height:U.h,"--w6w-canvas-color":S.color}},F=(S,U)=>i==null?void 0:i({...e,notes:v.map(V=>V.id===S?{...V,...U}:V)}),O=(S,U)=>i==null?void 0:i({...e,sections:C.map(V=>V.id===S?{...V,...U}:V)}),T=S=>{const U=N.current,V=v.find(H=>H.id===S);if(!(U!=null&&U.isConnected)||!V)return;const P=Ia(U);P!==V.content&&F(S,{content:P})},I=S=>{h(null),f(S)},M=S=>{f(null),h(S)},q=(S,U)=>{A.current=U??null,I(S),m(S),g(null)},D=S=>U=>{if(!U||U.dataset.ready==="1")return;U.dataset.ready="1",N.current=U,Ra(U,S.content),U.focus();const V=A.current;A.current=null,V?(Ba(U),V(),T(S.id)):qa(U)},Y=(S,U,V)=>{var H;g(null);const P=()=>document.execCommand(U,!1,V);b===S&&((H=N.current)!=null&&H.isConnected)?(P(),T(S)):q(S,P)},$=S=>S.mode==="move"?{...S.base,x:S.base.x+S.dx,y:S.base.y+S.dy}:{...S.base,w:Math.max(Ma,S.base.w+S.dx),h:Math.max(Da,S.base.h+S.dy)},G=(S,U,V,P)=>{if(!k||S.button!==0)return;S.stopPropagation(),S.preventDefault();const H={kind:V,id:U.id,mode:P,sx:S.clientX,sy:S.clientY,base:E(U),dx:0,dy:0};y.current=H;const ae=he=>{H.dx=(he.clientX-H.sx)/(r||1),H.dy=(he.clientY-H.sy)/(r||1),u(ge=>({...ge,[H.id]:$(H)}))},fe=()=>{if(window.removeEventListener("pointermove",ae),window.removeEventListener("pointerup",fe),y.current=null,u(ve=>{const{[H.id]:Ae,...Te}=ve;return Te}),H.dx===0&&H.dy===0)return;const he=$(H),ge={position:{x:he.x,y:he.y},size:{width:he.w,height:he.h}};H.kind==="section"&&H.mode==="move"&&a?a(H.id,{dx:H.dx,dy:H.dy}):H.kind==="note"?F(H.id,ge):O(H.id,ge)};window.addEventListener("pointermove",ae),window.addEventListener("pointerup",fe)},ne=t?` ${t}`:"",oe="nopan nodrag nowheel",X=k?v.find(S=>S.id===d):void 0,L=k?C.find(S=>S.id===p):void 0,z=r||1,Z=S=>{const U=E(S);return{left:U.x+U.w/2,top:U.y,transform:`translate(-50%, calc(-100% - ${po/z}px)) scale(${1/z})`,transformOrigin:"50% 100%","--w6w-canvas-color":S.color}},W=(S,U)=>{const V=E(S);return{left:V.x,top:V.y,transform:`translate(0, calc(-100% - ${U/z}px)) scale(${1/z})`,transformOrigin:"0 100%","--w6w-canvas-color":S.color}},J=(S,U,V,P)=>n.jsxs("div",{className:"w6w-note-menu w6w-note-menu-colors",role:"menu",children:[La.map(H=>n.jsx("button",{type:"button",role:"menuitemradio","aria-checked":H===S,"aria-label":`Colour ${H}`,title:H,className:`w6w-note-swatch-btn${H===S?" active":""}`,style:{"--w6w-canvas-color":H},"data-testid":`${V}-option`,"data-color":H,onClick:()=>{g(null),H!==S&&P(H)}},H)),n.jsx("label",{className:"w6w-note-swatch-btn w6w-note-swatch-custom",title:"Custom",children:n.jsx("input",{type:"color","aria-label":`Custom ${U} colour`,"data-testid":`${V}-input`,value:S,onChange:H=>P(H.currentTarget.value)})})]}),te=S=>{S.target.closest("input")||S.preventDefault()};return cn.createPortal(n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:`w6w-canvas-layer w6w-canvas-sections${ne}`,style:{zIndex:Pa},"data-testid":"w6w-canvas-sections",children:[C.map(S=>n.jsx("div",{className:`w6w-canvas-section${p===S.id?" selected":""}`,style:R(S),"data-section-id":S.id,"data-testid":"section",children:k&&n.jsx("div",{className:`w6w-note-resize ${oe}`,"data-testid":"section-resize",onPointerDown:U=>G(U,S,"section","resize")})},S.id)),C.map(S=>(L==null?void 0:L.id)===S.id?null:n.jsx("div",{className:`w6w-canvas-section-title${k?` editable ${oe}`:""}`,style:W(S,Ha),"data-section-label":S.id,"data-testid":"section-label",title:k?"Click to edit · drag to move":void 0,onPointerDown:k?U=>{M(S.id),G(U,S,"section","move")}:void 0,children:S.title||(k?"Untitled section":"")},S.id))]}),n.jsx("div",{className:`w6w-canvas-layer w6w-canvas-notes${ne}`,style:{zIndex:_a},"data-testid":"w6w-canvas-notes",children:v.map(S=>{const U=k&&b===S.id;return n.jsxs("div",{className:`w6w-canvas-note${d===S.id?" selected":""}`,style:R(S),"data-note-id":S.id,"data-testid":"note",children:[U?n.jsx("div",{ref:D(S),className:`w6w-canvas-note-body w6w-canvas-note-editor ${oe}`,contentEditable:!0,suppressContentEditableWarning:!0,role:"textbox",tabIndex:0,"aria-multiline":"true","aria-label":"Note content","data-testid":"note-content",onPointerDown:Mn,onBlur:()=>{T(S.id),N.current=null,m(null)},onKeyDown:V=>{V.key==="Escape"&&V.currentTarget.blur()},onPaste:V=>{V.preventDefault(),document.execCommand("insertText",!1,V.clipboardData.getData("text/plain"))}},"editor"):n.jsx("div",{className:`w6w-canvas-note-body ${oe}`,"data-testid":"note-view",style:k?{cursor:"grab",touchAction:"none"}:void 0,onPointerDown:k?V=>{I(S.id),G(V,S,"note","move")}:void 0,onDoubleClick:k?()=>q(S.id):void 0,children:S.content.trim()?n.jsx(gs,{content:$a(S.content)}):k&&n.jsx("span",{className:"w6w-canvas-note-empty",children:"Double-click to write"})},"view"),k&&n.jsx("div",{className:`w6w-note-resize ${oe}`,"data-testid":"note-resize",onPointerDown:V=>G(V,S,"note","resize")})]},S.id)})}),L&&n.jsx("div",{className:`w6w-canvas-layer${ne}`,style:{zIndex:uo},"data-testid":"w6w-canvas-overlay",children:n.jsxs("div",{className:`w6w-note-toolbar w6w-section-toolbar ${oe}`,role:"toolbar","aria-label":"Section","data-testid":"section-toolbar","data-section-toolbar":L.id,style:W(L,po),onPointerDown:Mn,onMouseDown:te,children:[n.jsx("button",{type:"button",className:"w6w-icon-btn w6w-note-grip","aria-label":"Move section",title:"Drag to move","data-testid":"section-drag",onPointerDown:S=>G(S,L,"section","move"),children:n.jsx(ue.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:L.title,size:Math.max(8,Math.min(32,L.title.length+1)),onBlur:S=>{const U=S.currentTarget.value;U!==L.title&&O(L.id,{title:U})},onKeyDown:S=>{(S.key==="Enter"||S.key==="Escape")&&S.currentTarget.blur()}},`${L.id}:${L.title}`),n.jsx("span",{className:"w6w-note-toolbar-sep"}),n.jsxs("div",{className:"w6w-note-toolbar-group",children:[n.jsxs("button",{type:"button",className:`w6w-icon-btn${x==="color"?" active":""}`,"aria-label":"Section colour","aria-expanded":x==="color",title:"Colour","data-testid":"section-color",onClick:()=>g(x==="color"?null:"color"),children:[n.jsx("span",{className:"w6w-note-swatch"}),n.jsx(ue.Icon,{name:"chevron-down",size:12})]}),x==="color"&&J(L.color,"section","section-color",S=>O(L.id,{color:S}))]}),n.jsx("span",{className:"w6w-note-toolbar-sep"}),n.jsx("button",{type:"button",className:"w6w-icon-btn w6w-note-delete","aria-label":"Delete section",title:"Delete section","data-testid":"section-delete",onClick:()=>{g(null),l==null||l("section",L.id)},children:n.jsx(ue.Icon,{name:"trash"})})]})}),X&&n.jsx("div",{className:`w6w-canvas-layer${ne}`,style:{zIndex:uo},"data-testid":"w6w-canvas-overlay",children:n.jsxs("div",{className:`w6w-note-toolbar ${oe}`,role:"toolbar","aria-label":"Note","data-testid":"note-toolbar","data-note-toolbar":X.id,style:Z(X),onPointerDown:Mn,onMouseDown:te,children:[n.jsx("button",{type:"button",className:"w6w-icon-btn w6w-note-grip","aria-label":"Move note",title:"Drag to move","data-testid":"note-drag",onPointerDown:S=>G(S,X,"note","move"),children:n.jsx(ue.Icon,{name:"grip"})}),n.jsx("span",{className:"w6w-note-toolbar-sep"}),n.jsxs("div",{className:"w6w-note-toolbar-group",children:[n.jsxs("button",{type:"button",className:`w6w-icon-btn${x==="color"?" active":""}`,"aria-label":"Note colour","aria-expanded":x==="color",title:"Colour","data-testid":"note-color",onClick:()=>g(x==="color"?null:"color"),children:[n.jsx("span",{className:"w6w-note-swatch"}),n.jsx(ue.Icon,{name:"chevron-down",size:12})]}),x==="color"&&J(X.color,"note","note-color",S=>F(X.id,{color:S}))]}),n.jsx("span",{className:"w6w-note-toolbar-sep"}),n.jsxs("div",{className:"w6w-note-toolbar-group",children:[n.jsxs("button",{type:"button",className:`w6w-icon-btn w6w-note-size-btn${x==="size"?" active":""}`,"aria-label":"Text size","aria-expanded":x==="size",title:"Text size","data-testid":"note-size",onClick:()=>g(x==="size"?null:"size"),children:["Aa",n.jsx(ue.Icon,{name:"chevron-down",size:12})]}),x==="size"&&n.jsx("div",{className:"w6w-note-menu w6w-note-menu-sizes",role:"menu",children:Fa.map(S=>n.jsx("button",{type:"button",role:"menuitem",className:`w6w-note-menu-item w6w-note-size-${S.level}`,"data-testid":`note-size-${S.level}`,onClick:()=>Y(X.id,"formatBlock",S.level?`<h${S.level}>`:"<div>"),children:S.label},S.level))})]}),n.jsx("button",{type:"button",className:"w6w-icon-btn","aria-label":"Bold",title:"Bold","data-testid":"note-bold",onClick:()=>Y(X.id,"bold"),children:n.jsx(ue.Icon,{name:"bold"})}),n.jsx("span",{className:"w6w-note-toolbar-sep"}),n.jsx("button",{type:"button",className:"w6w-icon-btn w6w-note-delete","aria-label":"Delete note",title:"Delete note","data-testid":"note-delete",onClick:()=>{g(null),l==null||l("note",X.id)},children:n.jsx(ue.Icon,{name:"trash"})})]})})]}),s)}function Wa(e){const t=Bn.useStore(o=>{var r;return((r=o.domNode)==null?void 0:r.querySelector(".react-flow__viewport"))??null}),s=Bn.useStore(o=>o.transform[2]);return n.jsx(Go,{...e,zoom:e.zoom??s,viewport:t})}function Ua(e){return e.viewport!==void 0?n.jsx(Go,{...e,viewport:e.viewport}):n.jsx(Wa,{...e})}const ys={"&":{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 Va(){let e,t=0,s=!1;const o=new Map,r=()=>{e==null||e.terminate(),e=void 0;for(const a of o.values())a([]);o.clear()},i=async a=>{const l=a.matchBefore(/[\w$]*/);if(s||!l||!a.explicit&&l.from===l.to&&a.state.sliceDoc(a.pos-1,a.pos)!==".")return null;e||(e=new Worker(new URL(""+(typeof document>"u"?require("url").pathToFileURL(__dirname+"/assets/script-completion.worker-DDJKkj5M.js").href:new URL("assets/script-completion.worker-DDJKkj5M.js",document.currentScript&&document.currentScript.tagName.toUpperCase()==="SCRIPT"&&document.currentScript.src||document.baseURI).href),typeof document>"u"?require("url").pathToFileURL(__filename).href:$n&&$n.tagName.toUpperCase()==="SCRIPT"&&$n.src||new URL("node-samples-ChdyMBnJ.cjs",document.baseURI).href),{type:"module"}),e.onmessage=u=>{var d;(d=o.get(u.data.id))==null||d(u.data.options),o.delete(u.data.id)},e.onerror=r);const c=await new Promise(u=>{const d=++t;o.set(d,u),a.addEventListener("abort",()=>{o.delete(d),u([])},{onDocChange:!0}),e==null||e.postMessage({id:d,code:a.state.doc.toString(),position:a.pos})});return a.aborted||!c.length?null:{from:l.from,options:c}};return[qn.javascriptLanguage.data.of({autocomplete:i}),ls.ViewPlugin.define(()=>(s=!1,{destroy(){s=!0,r()}}))]}function za(e){switch(e){case"javascript":return qn.javascript();case"typescript":return qn.javascript({typescript:!0});case"python":return Ii.python()}}function xs(e){const t=bn(e.theme),s=w.useMemo(()=>[...e.language?[za(e.language)]:[],...e.language==="javascript"||e.language==="typescript"?[Va()]:[],ls.EditorView.theme(ys)],[e.language]);return n.jsx("div",{className:"w6w-code-editor","aria-label":e["aria-label"]??"Code editor",children:n.jsx(Do,{value:e.value,onChange:e.onChange,extensions:s,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}})})}function Ja(){const e=Mo.jsonParseLinter();return t=>t.state.doc.toString().trim()===""?[]:e(t)}function lt(e){const t=bn(e.theme),{copied:s,copy:o}=ue.useCopyToClipboard(e.value),r=w.useMemo(()=>[Mo.json(),...e.showDiagnostics===!1?[]:[no.linter(Ja()),no.lintGutter()],ls.EditorView.theme(ys)],[e.showDiagnostics]);function i(a){var l,c,u,d;if(e.onChange(a),!(!e.onValidChange&&!e.onValidityChange)){if(a.trim().length===0){(l=e.onValidityChange)==null||l.call(e,{valid:!1,error:"Empty"});return}try{const f=JSON.parse(a);(c=e.onValidChange)==null||c.call(e,f),(u=e.onValidityChange)==null||u.call(e,{valid:!0})}catch(f){(d=e.onValidityChange)==null||d.call(e,{valid:!1,error:f.message})}}}return n.jsxs("div",{className:"w6w-json-editor","aria-label":e["aria-label"]??"JSON editor",children:[n.jsx(Do,{value:e.value,onChange:i,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&&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(ue.CheckGlyph,{}):n.jsx(ue.CopyGlyph,{})}),n.jsx("span",{className:"w6w-copyable-status","aria-live":"polite",children:s?"Copied":""})]})]})}function Yo(e,t,s){return e*t>.6*s}function Xo(e,t){const s=t.trim().toLowerCase();return s?e.filter(o=>o.label.toLowerCase().includes(s)||o.value.toLowerCase().includes(s)):e}const Ka=240,Ga={display:"block",fontSize:"0.85em",opacity:.65,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},Ya={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 kt({options:e,value:t,onChange:s,placeholder:o,disabled:r,"aria-label":i,mode:a="auto",forceSelection:l=!0,optionHeight:c=32,listMaxHeight:u=Ka,className:d,onInputChange:f,emptyText:p="No matches",footer:h}){var Y;const b=a==="combobox"||a==="auto"&&Yo(e.length,c,typeof window>"u"?0:window.innerHeight),m=w.useId(),x=((Y=e.find($=>$.value===t))==null?void 0:Y.label)??(l?"":t),[g,y]=w.useState(x),[N,A]=w.useState(!1),[k,C]=w.useState(!1),[v,E]=w.useState(0),R=w.useRef(null);w.useEffect(()=>{y(x)},[x]);const F=w.useMemo(()=>k?Xo(e,g):e,[e,g,k]),O=w.useMemo(()=>({...Ya,maxHeight:u}),[u]);if(!b)return n.jsxs("select",{className:d,value:t,disabled:r,"aria-label":i,onChange:$=>s($.target.value),children:[o!==void 0&&t===""&&n.jsx("option",{value:"",disabled:!0,children:o}),e.map($=>n.jsx("option",{value:$.value,children:$.label},$.value))]});const T=$=>`${m}-opt-${$}`,I=()=>{A(!1),C(!1)},M=$=>{y($.label),s($.value),I()},q=$=>{$.key==="ArrowDown"?($.preventDefault(),N?E(G=>Math.min(G+1,F.length-1)):A(!0)):$.key==="ArrowUp"?($.preventDefault(),N?E(G=>Math.max(G-1,0)):A(!0)):$.key==="Enter"?N&&F[v]?($.preventDefault(),M(F[v])):l||(g!==x&&s(g),I()):$.key==="Escape"&&(N&&$.stopPropagation(),y(x),I())},D=()=>{l?y(x):g!==x&&s(g),I()};return n.jsxs("div",{ref:R,className:"w6w-combobox",style:{position:"relative"},children:[n.jsx("input",{type:"text",role:"combobox",className:d,value:g,disabled:r,placeholder:o,"aria-label":i,"aria-expanded":N,"aria-controls":`${m}-list`,"aria-autocomplete":"list","aria-activedescendant":N&&F[v]?T(v):void 0,autoComplete:"off",onFocus:()=>A(!0),onChange:$=>{y($.target.value),f==null||f($.target.value),C(!0),E(0),A(!0)},onKeyDown:q,onBlur:D}),N&&n.jsxs("div",{id:`${m}-list`,role:"listbox",tabIndex:-1,"aria-label":i,style:O,children:[F.map(($,G)=>n.jsxs("div",{id:T(G),role:"option",tabIndex:-1,"aria-selected":$.value===t,style:{padding:"6px 8px",cursor:"pointer",borderRadius:4,background:G===v?"var(--w6w-panel-2)":void 0},onMouseDown:ne=>{ne.preventDefault(),M($)},onMouseEnter:()=>E(G),children:[$.label,$.detail!==void 0&&n.jsx("span",{className:"w6w-combobox-detail",style:Ga,children:$.detail})]},$.value)),F.length===0&&n.jsx("div",{role:"presentation",style:{padding:"6px 8px",opacity:.6},children:p}),h!==void 0&&n.jsx("div",{role:"presentation",className:"w6w-combobox-footer",style:{padding:"6px 8px",opacity:.6,fontSize:"0.85em"},children:h})]})]})}function gn(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&e.source==="resolveFields"}function We(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&e.type==="expr"&&Array.isArray(e.parts)}function Ze(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&e.type==="secret"&&typeof e.ciphertext=="string"&&typeof e.iv=="string"}function fo(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 tn(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(fo)};let s="";for(const o of t){if(o.kind==="text"){s+=o.value??"";continue}Xa(s)%2===1&&(s+="\\"),s+=ie.serializeTemplate([fo(o)])}return s}function Xa(e){let t=0;for(;t<e.length&&e[e.length-1-t]==="\\";)t+=1;return t}const Zo={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(Zo));const ho=e=>Object.prototype.hasOwnProperty.call(Zo,e),mo=["state","var","vars"];function Qo(e){for(const t of mo)if(e===t||e.startsWith(`${t}.`)){const s=e.slice(t.length);return[...new Set([e,...mo.map(o=>o+s)])]}return[e]}function wo(e){const t=e.indexOf(".");return t===-1?e:e.slice(0,t)}function Xe(e){const t=ie.parseTemplate(e,"editor",Za);return t.every(yn)?t:[{kind:"text",value:e}]}function yn(e){if(e.kind==="var"){const t=e.ref??"";return!ie.hasRefusedChainToken(t)&&ho(wo(t))}if(e.kind==="expr"){const t=ie.coalesceOperandRefs(e.expr);return t===null?!0:t.every(s=>ho(wo(s)))}return!0}const Za={isOurs:yn,backslash:"keep"},er={isOurs:yn,backslash:"strip"};function ct(e){return We(e)?!0:typeof e=="string"&&e.includes("{{")&&Xe(e).some(t=>t.kind!=="text")}function xn(e){if(!e.includes("{{"))return null;const t=ie.parseTemplate(e,"editor",er);return t.every(yn)&&(t.some(s=>s.kind!=="text")||t.map(s=>s.value??"").join("")!==e)?t:null}function Qa(e){return e.includes("{{")?ie.parseTemplate(e,"editor",er).map(t=>t.kind==="text"?t.value??"":ie.serializeTemplate([t])).join(""):e}function Wn(e){if(Ze(e))return{parts:[],sealed:e};if(We(e))return{parts:e.parts.map(s=>({...s})),sealed:null};const t=typeof e=="string"?e:"";return{parts:t?Xe(t):[],sealed:null}}function el(e,t){let s="";for(const o of e)switch(o.kind){case"text":s+=Qa(o.value??"");break;case"var":case"render":{const r=Qo(o.ref??"").find(i=>i in t);s+=r===void 0?"":t[r];break}case"secret":s+="•••";break;case"expr":s+=ie.serializeTemplate([o]);break}return s}const xt="var.",bo="vars.",Un="documents.",Vn="const.",zn="state.";function tr(e){return e==="state"||e==="vars"?"var":e.startsWith(bo)?xt+e.slice(bo.length):e.startsWith(zn)?xt+e.slice(zn.length):e}function tl(e){return e.startsWith(zn)?3:e.startsWith(xt)?2:1}function nr(e){return e.rank>0?e.value:Object.fromEntries(Array.from(e.children,([t,s])=>[t,nr(s)]))}function vs(e,t,s,o){const r={children:new Map,rank:0},i={},a={};for(const[b,m]of Object.entries(e??{})){const x=tr(b);if(x.startsWith(xt)){const g=x.slice(xt.length),y=tl(b);let N=r;for(const A of g.split(".")){let k=N.children.get(A);k||(k={children:new Map,rank:0},N.children.set(A,k)),N=k}y>=N.rank&&(N.value=m,N.rank=y)}else x.startsWith(Un)?i[x.slice(Un.length)]=m:x.startsWith(Vn)&&(a[x.slice(Vn.length)]=m)}const l=nr(r),c=(t==null?void 0:t.steps)??{},u=e??{},d=Object.hasOwn(u,"foreach.item"),f=typeof u["foreach.index"]=="number",p=t==null?void 0:t.foreach,h=p?{...p}:d||f?{...d?{item:u["foreach.item"]}:{},...f?{index:u["foreach.index"]}:{}}:void 0;return{...h?{foreach:h}:{},vars:l,state:l,documents:i,constants:a,steps:c,nodes:c,trigger:(t==null?void 0:t.trigger)??{},flat:e??{},...s?{config:s}:{},...o?{meta:o}:{}}}function nl(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 sl=/^(?:nodes|steps)\.[^.]+\.(?:meta\.)?config(?:\.|$)/,ol=/^(?:nodes|steps)\.([^.]+)\.meta(?:\.|$)/;function rl(e,t,s){var r;if(!t&&!s)return e;const o={...e};for(const i of new Set([...Object.keys(s??{}),...Object.keys(t??{})])){const a=t==null?void 0:t[i];o[i]={...e[i],meta:{...s==null?void 0:s[i],...(r=e[i])==null?void 0:r.meta,...a?{config:a}:{}},...a?{config:a}:{}}}return o}function sr(e,t){var p;const s=tr(e);if(t.flat&&(s.startsWith(xt)||s.startsWith(Un)||s.startsWith(Vn))){const h=Qo(e).find(b=>Object.hasOwn(t.flat,b));if(h!==void 0)return{status:"resolved",ref:e,value:t.flat[h]}}const{vars:o,constants:r,config:i,meta:a,...l}=t,c=rl(t.nodes??t.steps,i,a),u={...l,var:o,...r?{const:r}:{},nodes:c,steps:c},d=nl(u,s);if(d.present)return{status:"resolved",ref:e,value:d.value};if(sl.test(s))return{status:"at-run",ref:e};const f=(p=ol.exec(s))==null?void 0:p[1];return f!==void 0&&(a!=null&&a[f])?{status:"at-run",ref:e}:{status:"unresolved",ref:e}}function go(e,t){switch(e.kind){case"text":return{status:"resolved",value:e.value??""};case"var":return sr(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 js(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&Object.keys(e).length===1&&"$"in e}function Ns(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&Object.keys(e).length===1&&"$expr"in e}function ks(e,t){if(Ze(e))return[{status:"masked"}];if(We(e))return e.parts.map(s=>go(s,t));if(typeof e=="string"){const s=xn(e);if(s)return s.map(o=>go(o,t))}return js(e)?[sr(String(e.$),t)]:Ns(e)?[{status:"not-evaluated"}]:[{status:"resolved",value:e}]}function Jn(e,t){if(e===t)return!0;if(typeof e!=typeof t||e===null||t===null||typeof e!="object")return!1;const s=Array.isArray(e),o=Array.isArray(t);if(s!==o)return!1;if(s){const c=e,u=t;return c.length===u.length&&c.every((d,f)=>Jn(d,u[f]))}const r=e,i=t,a=Object.keys(r),l=Object.keys(i);return a.length===l.length&&a.every(c=>c in i&&Jn(r[c],i[c]))}function or(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 il(e){return e.status==="resolved"&&e.value!==void 0?typeof e.value=="string"?e.value:JSON.stringify(e.value):String(or(e))}function al(e){return e.length===1?or(e[0]):e.map(il).join("")}function Dt(e,t){return al(ks(e,t))}function ll(e,t){const s={};for(const o of e)s[o.key||"(no key)"]=Dt(o.value,t);return s}const vn=w.forwardRef(function(t,s){const{label:o,children:r,icon:i,iconSize:a,title:l,onClick:c,disabled:u,className:d,danger:f,...p}=t,h=r??(i?n.jsx(ue.Icon,{name:i,size:a??16}):null);return n.jsx("button",{ref:s,type:"button",className:["w6w-icon-button",f?"w6w-icon-button-danger":"",d??""].filter(Boolean).join(" "),title:l??o,"aria-label":o,"aria-pressed":p["aria-pressed"],"aria-expanded":p["aria-expanded"],"aria-controls":p["aria-controls"],disabled:u,onClick:c,"data-testid":p["data-testid"],children:h})});vn.displayName="IconButton";const cl={default:"",wide:" w6w-modal-wide",xl:" w6w-modal-xl",full:" w6w-modal-full",fullscreen:" w6w-modal-fullscreen"};function Se({title:e,ariaLabel:t,onClose:s,children:o,size:r="default",titleIcon:i,subtitle:a,headerRight:l}){const c=w.useRef(null);return w.useEffect(()=>{const u=c.current;if(!u)return;u.open||u.showModal();const d=p=>{p.preventDefault(),s()},f=p=>{if(p.target!==u)return;const h=u.getBoundingClientRect();(p.clientX<h.left||p.clientX>h.right||p.clientY<h.top||p.clientY>h.bottom)&&s()};return u.addEventListener("cancel",d),u.addEventListener("click",f),()=>{u.removeEventListener("cancel",d),u.removeEventListener("click",f)}},[s]),n.jsx("div",{className:"w6w-modal-backdrop",children:n.jsxs("dialog",{ref:c,className:`w6w-modal${cl[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:[i,n.jsx("span",{children:e}),a&&n.jsx("span",{className:"w6w-modal-subtitle",children:a})]}),l]}),o]})})}const Ss=new Set(["nodes","steps","state","var","vars","const","inputs","output","trigger","foreach","documents"]),ul=/[=<>]|!=|&&|\|\||\?\?/,nn=e=>ul.test(e)||/^\s*\(*\s*!/.test(e),yo=e=>ie.expressionReferences(e).some(nn);function dl(e,t){var i,a,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(Ss.has(s))return e;const r=[...(i=t.steps)!=null&&i.some(c=>c.id===s)?[`nodes.${s}.output`]:[],...(a=t.vars)!=null&&a.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 Rt(e,t){var u,d,f,p,h;const s={parts:e,error:null},o=e.flatMap(b=>b.kind==="text"?Xe(b.value??""):[b]);if(o.some(b=>b.kind==="render"))return s;if(o.length===1&&o[0].kind==="expr"&&!yo(o[0].expr))return{parts:o,error:null};let r=o.map(b=>{if(b.kind==="text")return b.value??"";if(b.kind==="secret")return`{{ secrets.${b.ref??""} }}`;if(b.kind==="expr"){if(yo(b.expr)){const x=ie.serializeTemplate([b]);if(!x.startsWith("{{ ="))return`(${x.slice(2,-2).trim()})`}const m=ie.formatReadableExpression(b.expr);return m===null?ie.serializeTemplate([b]):`(${m})`}return nn(b.ref??"")?b.ref??"":`{{ ${b.ref??""} }}`}).join("").trim();if(!nn(r))return s;const i=/^\{\{([^{}]+)\}\}$/.exec(r);i&&nn(i[1])&&(r=i[1].trim());const a=r.replace(/^[\s(!]+/,""),l=(u=/^(?:\{\{\s*)?([A-Za-z_$][\w$-]*)/.exec(a))==null?void 0:u[1],c=a.startsWith("{{")||l!==void 0&&(Ss.has(l)||l==="secrets"||((d=t.steps)==null?void 0:d.some(b=>b.id===l))||((f=t.vars)==null?void 0:f.includes(l))||((p=t.constants)==null?void 0:p.includes(l)));if(!c&&!/^(?:["']|-?\d|true\b|false\b|null\b)/.test(a))return s;if(c&&!/^\s*\(*\s*!/.test(r)){const b=(h=/^(?:\{\{[^{}]+\}\}|[A-Za-z_$][\w$-]*(?:\.[\w$-]+)*)/.exec(a))==null?void 0:h[0];if(b){const m=a.slice(b.length).replace(/^[\s)]+/,"");if(!/^(?:[=<>(]|!=|&&|\|\||\?\?)/.test(m)||/^<\/?[A-Za-z][^>]*>/.test(m))return s}}try{return{parts:[{kind:"expr",expr:ie.parseReadableExpression(r,m=>dl(m,t))}],error:null}}catch(b){return{parts:o,error:b instanceof Error?b.message:"Check the expression."}}}function pl(e){return[...new Set(e.flatMap(t=>t.kind==="expr"?ie.expressionReferences(t.expr):(t.kind==="var"||t.kind==="render")&&t.ref?[t.ref]:[]))]}function fl(e){return e.replace(/^(?:vars|state)(?=\.|$)/,"var").replace(/^steps(?=\.|$)/,"nodes")}function hl(e){const t=Object.create(null);for(const[s,o]of Object.entries(e).sort(([r],[i])=>r.split(".").length-i.split(".").length)){const r=fl(s).split(".");if(!Ss.has(r[0])||r.some(a=>["__proto__","constructor","prototype"].includes(a)))continue;let i=t;for(const a of r.slice(0,-1)){const l=i[a],c=l&&typeof l=="object"?{...l}:{};i[a]=c,i=c}i[r[r.length-1]]=o}return t.steps=t.nodes,t.vars=t.var,t.state=t.var,t}function ml(e,t={},s={}){const o={...t};for(const[a,l]of Object.entries(s))try{o[a]=JSON.parse(l)}catch{o[a]=l}const r=hl(o),i=Object.fromEntries(Object.entries(o).map(([a,l])=>[a,typeof l=="string"?l:JSON.stringify(l)]));return e.map(a=>{if(a.kind!=="expr"||ie.formatReadableExpression(a.expr)===null)return el([a],i);if(ie.expressionReferences(a.expr).some(u=>!u||u.split(".")[0]==="secrets"))return"••••";const c=ie.evaluate(a.expr,r);return typeof c=="string"?c:JSON.stringify(c)??""}).join("")}const wl=/^(?:nodes|steps)\.([^.]+)\.output(?:\.(.+))?$/,bl=/^(?:nodes|steps)\.([^.]+)\.meta\.(app|version|action|connectionId)$/,Ge=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=wl.exec(e);if(t)return t[2]?`${t[1]}.${t[2]}`:t[1];const s=bl.exec(e);return s?`${s[1]} meta · ${s[2]}`:e};function gl(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 yl(e){const t=e.op==="or"?"||":"??",s=e.operands.map(o=>{const r=gl(o);return r!==void 0?Ge(r):JSON.stringify(o)}).join(` ${t} `);return s.length>40?`${s.slice(0,40)}…`:s}const xl=/[.{}]/;function wt(e){return e===""||e!==e.trim()?!1:!xl.test(e)}function Yt(e){return e.split(".").every(wt)}function xo(e){const t=new Set(e.filter(s=>s.path).map(s=>s.key));return e.map(s=>{if(!s.path)return{field:s,depth:0,name:s.key};const o=s.key.split(".");let r=0,i=0;for(let a=1;a<o.length;a++)t.has(o.slice(0,a).join("."))&&(r++,i=a);return{field:s,depth:r,name:o.slice(i).join(".")}})}function It(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 i=e.createElement("span");if(i.className="w6w-expr-chip-label",t.kind==="var")o.setAttribute("data-ref",t.ref??""),r.textContent="◆",i.textContent=Ge(t.ref??""),o.title=`Variable: ${t.ref??""}`;else if(t.kind==="render")o.setAttribute("data-ref",t.ref??""),r.textContent="▤",i.textContent=Ge(t.ref??""),o.title=`Render as template: ${t.ref??""}`;else if(t.kind==="secret")o.setAttribute("data-ref",t.ref??""),r.textContent="🔒",i.textContent=t.ref??"",o.title=`Secret: ${t.ref??""}`;else{const l=typeof t.expr=="string"?t.expr:JSON.stringify(t.expr??"");o.setAttribute("data-expr",l),r.textContent="ƒ";const c=ie.parseCoalesceChain(t.expr);if(c)i.textContent=yl(c),o.title=`Expression: ${ie.serializeTemplate([t])}`;else{const u=ie.formatReadableExpression(t.expr,Ge);i.textContent=u??(l.length>24?`${l.slice(0,24)}…`:l||"expr"),o.title=`Expression: ${u??l}`}}if(o.append(r,i),(t.kind==="var"||t.kind==="render")&&s){const l=e.createElement("span");l.className="w6w-expr-chip-toggle",l.setAttribute("data-render-toggle","1"),l.setAttribute("role","button");const c=t.kind==="render"?"Stop rendering as a template":"Render this as a template";l.setAttribute("aria-label",c),l.title=c,l.textContent="⇄",o.append(l)}const a=e.createElement("span");return a.className="w6w-expr-chip-x",a.setAttribute("data-x","1"),a.setAttribute("role","button"),a.setAttribute("aria-label","Remove"),a.textContent="×",o.append(a),o}const rr=new Set(["div","p"]);function ir(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 Tt(e){const t=[],s=i=>{if(!i)return;const a=t[t.length-1];a&&a.kind==="text"?a.value=(a.value??"")+i:t.push({kind:"text",value:i})},o=(i,a)=>{if(i.nodeType===Node.TEXT_NODE){s(i.textContent??"");return}if(i.nodeType!==Node.ELEMENT_NODE)return;const l=i,c=ir(l);if(c){t.push(c);return}const u=(l.tagName??"").toLowerCase();if(u==="br"){a||s(`
|
|
6
|
+
`);return}const d=rr.has(u);d&&t.length>0&&s(`
|
|
7
|
+
`),r(l,d)},r=(i,a)=>{const l=Array.from(i.childNodes);l.forEach((c,u)=>o(c,a&&u===l.length-1))};return r(e,!0),t}const ar=e=>!!e&&(e.tagName??"").toLowerCase()==="br";function lr(e){ar(e.lastChild)||e.appendChild(e.ownerDocument.createElement("br"))}function vl(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 cr(e){lr(vl(e))}const jl=e=>e.getAttribute("aria-multiline")!=="false";function ur(e,t,s){var i;const o=e.ownerDocument;e.textContent="";for(const a of t)a.kind==="text"?a.value&&e.appendChild(o.createTextNode(a.value)):e.appendChild(It(o,a,s));const r=t[t.length-1];(r==null?void 0:r.kind)==="text"&&((i=r.value)!=null&&i.endsWith(`
|
|
8
|
+
`))&&jl(e)&&lr(e)}function Cs(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 Ot(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 i=s.createRange();i.setStartAfter(t),i.collapse(!0),o==null||o.removeAllRanges(),o==null||o.addRange(i)}else ar(e.lastChild)?e.insertBefore(t,e.lastChild):e.appendChild(t),Cs(e);e.focus()}function dr(e,t={}){const s=e.ownerDocument,o=s.getSelection();if(!o||o.rangeCount===0||!o.isCollapsed)return!1;const r=o.getRangeAt(0),i=r.startContainer;if(i.nodeType!==Node.TEXT_NODE||!e.contains(i))return!1;const a=r.startOffset,l=i.textContent??"";if(a<2||l.slice(a-2,a)!=="}}")return!1;const c=l.lastIndexOf("{{",a-2);if(c===-1)return!1;const u=l.slice(c,a),d=Xe(u);if(d.length!==1||d[0].kind==="text")return!1;let f=0;for(;c-1-f>=0&&l[c-1-f]==="\\";)f+=1;if(f%2===1)return!1;const p=s.createRange();p.setStart(i,c),p.setEnd(i,a),p.deleteContents();const h=It(s,d[0],t);p.insertNode(h);const b=s.createRange();return b.setStartAfter(h),b.collapse(!0),o.removeAllRanges(),o.addRange(b),!0}function pr(e){const t=ir(e);if(!t)return null;const s=t.kind==="expr"&&!ie.parseCoalesceChain(t.expr)?ie.formatReadableExpression(t.expr):null,o=e.ownerDocument.createTextNode(s??ie.serializeTemplate([t]));return e.replaceWith(o),o}function Nl(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 kl(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 Sl(e,t){const s=[];let o=!1;for(let i=0;i<t&&i<e.length;i++){const a=e[i];if(o){a==="\\"?i++:a==='"'&&(o=!1);continue}a==='"'?o=!0:a==="{"||a==="["?s.push(a):(a==="}"||a==="]")&&s.pop()}const r=s[s.length-1];return r==="{"||r==="["?r:null}function Cl(e,t){if(!e||!Object.hasOwn(e,t))return t;let s=2;for(;Object.hasOwn(e,`${t}_${s}`);)s++;return`${t}_${s}`}function vo(e,t,s,o){var x;const r=o?JSON.stringify(o.value)??"null":"",i=o?JSON.stringify(typeof o.value=="string"?o.value:r).slice(1,-1):`{{ ${s} }}`,a=o?r:JSON.stringify(i),l=(g,y)=>({text:e.slice(0,g)+y+e.slice(g),caret:g+y.length});if(Nl(e,t))return l(t,i);let c,u=!0;try{c=JSON.parse(e)}catch{u=!1}const d=u&&c!==null&&typeof c=="object"&&!Array.isArray(c)?c:null,f=()=>`${JSON.stringify(Cl(d,kl(s)))}: ${a}`,p=e.slice(0,t).trimEnd(),h=p[p.length-1],b=e.slice(t).trimStart()[0],m=Sl(e,t);if(h===":"||h==="["||h===","&&m==="[")return l(t,a+(h!==":"&&b!==void 0&&b!=="]"?", ":""));if(h==="{"||h===","&&m==="{"){const g=b!==void 0&&b!=="}"?", ":"";return l(t,(h===","?" ":"")+f()+g)}if(u&&(d||Array.isArray(c))){const g=e.lastIndexOf(d?"}":"]"),y=e.slice(0,g).trimEnd(),N=y.endsWith(d?"{":"["),A=d?f():a,k=e.slice(y.length,g);if(k.includes(`
|
|
9
|
+
`)){const E=N?`${k.slice(k.lastIndexOf(`
|
|
10
|
+
`)+1)} `:((x=/^\s*/.exec(y.slice(y.lastIndexOf(`
|
|
11
|
+
`)+1)))==null?void 0:x[0])??"",R=`${N?"":","}
|
|
12
|
+
${E}${A}`;return{text:y+R+e.slice(y.length),caret:y.length+R.length}}const C=`${N?"":","} ${A} `,v=y.length;return{text:e.slice(0,v)+C+e.slice(g),caret:v+C.length-1}}return l(t,a)}const Al=/^\{\{\s*((?:var|vars|const|steps|nodes|trigger|foreach|inputs|output|documents)(?:\.[^\s{}]+)?)\s*\}\}$/;function El(e){const t=Al.exec(e.trim());return t?`{{ ${t[1]} }}`:null}function Qe(e){if(typeof e=="string"){if(!e.includes("{{"))return null;const t=Xe(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 Rl(e){var s;const t={};for(const[o,r]of Object.entries(e??{})){const i=/^(?:steps|nodes)\.([^.]+)\.output$/.exec(o);if(i){t[i[1]]={...t[i[1]],output:r};continue}const a=/^(?:steps|nodes)\.([^.]+)\.meta\.([^.]+)$/.exec(o);if(a){t[s=a[1]]??(t[s]={});const l=t[a[1]];l.meta={...l.meta,[a[2]]:r}}}return{steps:t}}function Kn(e,t){if(typeof e=="string"){const s=xn(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=>Kn(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,Kn(r,t)]))}return e}function zt({value:e,masked:t,multiline:s,options:o,fieldLabel:r,onSave:i,onClose:a,mode:l,jsonValue:c,onSaveJson:u,whole:d,startingState:f,jsonProblem:p,title:h}){var we;const b=l==="json-binding",m=b&&f===!0,[x,g]=w.useState("ref"),[y,N]=w.useState(()=>c===void 0?"":JSON.stringify(c,null,2)),A=w.useRef(null),k=w.useRef(!1),C=w.useMemo(()=>{if(y.trim()==="")return{ok:!1};try{return{ok:!0,value:JSON.parse(y)}}catch{return{ok:!1}}},[y]),v=m?(p==null?void 0:p(y))??null:null,E=m?(y.trim()===""||C.ok)&&v===null:C.ok,R=()=>vs(o.sampleValues,Rl(o.sampleValues),o.nodeConfig,o.nodeMeta),F=j=>{const _=A.current,K=_?_.state.doc.toString():y;if(m){const Me=x==="value"?{value:Dt(`{{ ${j} }}`,R())??null}:void 0,to=K.trim()===""?"{}":K,Oi=k.current&&_?_.state.selection.main.head:to.length,In=vo(to,Oi,j,Me);if(!_){N(In.text);return}_.dispatch({changes:{from:0,to:K.length,insert:In.text},selection:{anchor:In.caret}}),_.focus();return}let se=null;try{se=K.trim()===""?null:Qe(JSON.parse(K))}catch{se=null}let pe=!1;if(d)try{const Me=JSON.parse(K);pe=Array.isArray(Me)?Me.length===0:typeof Me=="object"&&Me!==null&&Object.keys(Me).length===0}catch{pe=!1}if(K.trim()===""||se!==null||pe){u==null||u(`{{ ${j} }}`),a();return}if(!_)return;const ce=k.current?_.state.selection.main.head:K.length,re=vo(K,ce,j);_.dispatch({changes:{from:0,to:K.length,insert:re.text},selection:{anchor:re.caret}}),_.focus()},[O,T]=w.useState(()=>Rt(Wn(e).parts,o).parts),I=w.useMemo(()=>Rt(O,o),[O,o]),[M,q]=w.useState(0),D=w.useRef(null),Y=w.useRef(!1),[$,G]=w.useState({}),[ne,oe]=w.useState(null),[X,L]=w.useState(()=>new Set),z=j=>{L(_=>{const K=new Set(_);return K.has(j)?K.delete(j):K.add(j),K})},[Z,W]=w.useState("auto");w.useLayoutEffect(()=>{const j=D.current;j&&(ur(j,O,{renderToggle:!0}),Y.current&&(Y.current=!1,Cs(j),j.focus()))},[M]);const J=()=>{const j=D.current;j&&T(Tt(j))},te=j=>{const _=D.current;_&&(Ot(_,It(_.ownerDocument,j,{renderToggle:!0})),T(Tt(_)))},S=O.some(j=>j.kind==="render"),U=(j,{restoreFocus:_})=>{T(Rt(Xe(j),o).parts),q(K=>K+1)},V=()=>{const j=D.current,_=Rt(j?Tt(j):O,o);_.error||(i==null||i(tn(_.parts)),a())},P=()=>{oe(null),Y.current=!0,q(j=>j+1)},H=o.vars??[],ae=o.constants??[],fe=o.secrets??[],he=o.inputs??[],ge=o.documents??[],ve=o.steps??[],Ae=o.nodeConfigs??[],Te=o.loop,le=new Map(Ae.map(j=>[j.id,j.keys.filter(wt)]).filter(([,j])=>j.length>0)),Ee=o.nodeMeta??{},mt=j=>Tl.filter(([_])=>Ol.has(_)?Ct(j):Object.hasOwn(Ee[j]??{},_)),Ue=ve.filter(j=>j.hasMeta===!0).map(j=>j.id),Ct=j=>{var K;if(Ue.includes(j))return!0;const _=(K=Ee[j])==null?void 0:K.app;return typeof _=="string"&&!Ye(_)},et=j=>mt(j).map(([_,K])=>Q(K,{kind:"var",ref:`nodes.${j}.meta.${_}`},"w6w-exprmodal-field",null)),Ve=[...new Set([...Object.keys(Ee),...Ue,...le.keys()])],tt=ve.length>0||!!o.hasTrigger,Fe=!m&&(tt||!!Te),me=m?[]:(((we=o.stateShape)==null?void 0:we.fields)??[]).filter(j=>Yt(j.key)),Oe=[...Fe?["state"]:[],...me.length>0?["runstate"]:[],...Ve.length>0?["meta"]:[],...o.inputs!==void 0?["inputs"]:[],"vars",...ae.length>0?["consts"]:[],...!b||m?["docs"]:[],...b?[]:["secrets"]],nt=Z==="auto"||Z!==null&&!Oe.includes(Z)?Oe.find(j=>j!=="meta")??null:Z,xe=j=>({open:nt===j,onToggle:()=>W(nt===j?null:j)}),je=((Te==null?void 0:Te.itemOutputs)??[]).filter(j=>j.path?Yt(j.key):wt(j.key)),Ie=(o.eventOutputs??[]).filter(j=>j.path?Yt(j.key):wt(j.key)),Ne=ie.serializeTemplate(I.parts),At=w.useMemo(()=>{const j={};for(const[_,K]of Object.entries(o.sampleValues??{}))j[_]=typeof K=="string"?K:JSON.stringify(K);return{...j,...$}},[o.sampleValues,$]),ze=w.useMemo(()=>pl(I.parts),[I.parts]),ee=w.useMemo(()=>{if(I.error)return"";try{return ml(I.parts,o.sampleValues,$)}catch{return Ne}},[I,o.sampleValues,$,Ne]),B=w.useMemo(()=>{var _;const j=new Set;for(const K of ze){if($[K]!==void 0)continue;const se=(_=o.valueSources)==null?void 0:_[K];se==="sample"?j.add("example from the app"):se==="persisted"&&j.add("from last test")}return[...j]},[ze,$,o.valueSources]),Q=(j,_,K,se,pe=!1,ce,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 ${K}${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)??j}`,"aria-label":ce,onClick:()=>b?_.kind==="var"&&F(_.ref??""):te(_),children:[se!==null&&n.jsx("span",{className:"w6w-expr-chip-sigil",children:se}),n.jsx("span",{className:"w6w-exprmodal-source-label",children:j}),(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"})]}),!b&&n.jsx(vn,{icon:"copy",iconSize:14,label:"Copy to expression editor","data-testid":"expr-copy-to-editor",onClick:()=>te(_)})]},`${_.kind}:${_.ref??j}`),de=X.has("loop:item"),Je=Q("Current item",{kind:"var",ref:"foreach.item"},"w6w-expr-chip-var","↻"),st=(j,_)=>{if(_.length===0)return null;const K=X.has(`mcfg:${j}`);return n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"w6w-exprmodal-source-row",children:n.jsxs("button",{type:"button",className:"w6w-exprmodal-tree-toggle","data-testid":"expr-config-toggle","aria-expanded":K,title:K?"Hide config":"Show config",onClick:()=>z(`mcfg:${j}`),children:[n.jsx("span",{className:"w6w-exprmodal-tree-caret","aria-hidden":"true",children:K?"▾":"▸"}),"config"]})}),K&&n.jsx("div",{className:"w6w-exprmodal-subsources","data-testid":"expr-config-fields",children:_.map(se=>Q(se,{kind:"var",ref:`nodes.${j}.meta.config.${se}`},"w6w-exprmodal-field",null))})]})},ke=(j,_,K=`nodes.${j}.output`)=>xo(_).map(({field:se,depth:pe,name:ce})=>{const re=`${K}.${se.key}`;return Q(ce,{kind:"var",ref:re},"w6w-exprmodal-field",null,!1,void 0,{name:Ge(re),depth:pe,declaredOnly:se.declaredOnly===!0})}),$e=j=>j==="fresh"||j==="persisted"?n.jsx("span",{className:"w6w-exprmodal-shape-note","data-testid":"expr-fields-from-test",children:j==="fresh"?"Fields from the last test run":"Fields from last test"}):j==="declared"||j==="sample"?n.jsx("span",{className:"w6w-exprmodal-shape-note","data-testid":`expr-fields-from-${j}`,children:j==="declared"?"declared by the app":"example from the app"}):null,Kt=j=>{const _=`mnode:${j}`,K=X.has(_);return n.jsxs(w.Fragment,{children:[n.jsxs("div",{className:"w6w-exprmodal-source-row","data-testid":"expr-metadata-node",children:[n.jsx("button",{type:"button",className:"w6w-exprmodal-caret-btn","data-testid":"expr-metadata-node-toggle","aria-expanded":K,"aria-label":K?`Hide ${j} metadata`:`Show ${j} metadata`,title:K?"Hide metadata":"Show metadata",onClick:()=>z(_),children:K?"▾":"▸"}),Q(j,{kind:"var",ref:`nodes.${j}.meta`},"w6w-expr-chip-var w6w-exprmodal-node",null,!0)]}),K&&n.jsxs("div",{className:"w6w-exprmodal-subsources","data-testid":"expr-metadata-fields",children:[et(j),st(j,le.get(j)??[])]})]},_)};return n.jsxs(Se,{title:h??(b?"Edit JSON value":"Edit expression"),subtitle:r?n.jsx("code",{children:r}):void 0,onClose:a,size:"full",headerRight:b?n.jsxs("div",{className:"w6w-exprmodal-actions",children:[n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:a,children:"Cancel"}),n.jsx("button",{type:"button",className:"w6w-btn","data-testid":"expr-json-save",disabled:!E,title:E?"Save the composed JSON":v??"Compose valid JSON to save",onClick:()=>{E&&(u==null||u(C.ok?C.value:void 0),a())},children:"Save"})]}):n.jsxs("div",{className:"w6w-exprmodal-actions",children:[!t&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",disabled:S,title:S?"Unavailable — a render part has no plain-text form. Flip it back to a variable first.":"Close the expression and keep the text as a literal value",onClick:()=>{i==null||i(ie.serializeTemplate(O)),a()},children:"Use a plain value"}),n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:a,children:"Cancel"}),n.jsx("button",{type:"button",className:"w6w-btn",onClick:V,"data-testid":"expr-save",disabled:I.error!==null,children:"Save"})]}),children:[n.jsxs("div",{className:"w6w-exprmodal",children:[n.jsxs("aside",{className:"w6w-exprmodal-sources",children:[m&&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(([j,_,K])=>n.jsx("button",{type:"button","aria-pressed":x===j,"data-testid":`expr-insert-as-${j}`,title:K,className:`w6w-btn w6w-btn-sm${x===j?"":" w6w-btn-ghost"}`,onClick:()=>g(j),children:_},j))]}),b&&!m&&!Fe&&n.jsx("span",{className:"w6w-expr-menu-empty",children:"No upstream steps"}),Fe&&n.jsxs(Ke,{label:"Previous steps",...xe("state"),children:[Te&&n.jsxs("div",{className:"w6w-exprmodal-subgroup","data-testid":"expr-loop-group",children:[n.jsx("span",{className:"w6w-exprmodal-shape-note",children:"Loop"}),je.length>0?n.jsxs("div",{className:"w6w-exprmodal-source-row",children:[Je,n.jsx(Xt,{count:je.length,open:de,onToggle:()=>z("loop:item")})]}):Je,je.length>0&&de&&n.jsx("div",{className:"w6w-exprmodal-subsources","data-testid":"expr-loop-fields",children:je.map(j=>{const _=`foreach.item.${j.key}`;return Q(j.key,{kind:"var",ref:_},"w6w-exprmodal-field",null)})}),Q("Index",{kind:"var",ref:"foreach.index"},"w6w-expr-chip-var","#")]}),o.hasTrigger&&(Ie.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":X.has("event"),"aria-label":X.has("event")?"Hide fields":"Show fields",title:X.has("event")?"Hide fields":"Show fields",onClick:()=>z("event"),children:X.has("event")?"▾":"▸"}),Q("trigger.event",{kind:"var",ref:"trigger.event"},"w6w-expr-chip-var w6w-exprmodal-node","⚡",!0)]}),X.has("event")&&n.jsxs("div",{className:"w6w-exprmodal-subsources","data-testid":"expr-event-fields",children:[$e(o.eventOutputsFrom),ke("",Ie,"trigger.event")]})]}):n.jsxs("div",{className:"w6w-exprmodal-source-row",children:[n.jsx("span",{className:"w6w-exprmodal-caret-spacer","aria-hidden":"true"}),Q("trigger.event",{kind:"var",ref:"trigger.event"},"w6w-expr-chip-var w6w-exprmodal-node","⚡")]})),ve.map(j=>{const _=(j.outputs??[]).filter(ce=>ce.path?Yt(ce.key):wt(ce.key)),K=`step:${j.id}`,se=X.has(K),pe=Q(j.label??j.id,{kind:"var",ref:`nodes.${j.id}.output`},"w6w-expr-chip-var w6w-exprmodal-node",null,_.length>0);return b?n.jsxs(w.Fragment,{children:[n.jsx("span",{className:"w6w-exprmodal-shape-note",children:j.label??j.id}),Q("Entire output",{kind:"var",ref:`nodes.${j.id}.output`},"w6w-expr-chip-var",null,!1,`Entire output of ${j.label??j.id}`),j.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":se,"aria-label":se?"Hide fields":"Show fields",title:se?"Hide fields":"Show fields",onClick:()=>z(K),children:se?"▾":"▸"}),n.jsx(Xt,{count:_.length,open:se,onToggle:()=>z(K)})]}),se&&n.jsxs("div",{className:"w6w-exprmodal-subsources",children:[$e(j.outputsFrom),ke(j.id,_)]})]})]},j.id):n.jsxs(w.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":se,"aria-label":se?"Hide fields":"Show fields",title:se?"Hide fields":"Show fields",onClick:()=>z(K),children:se?"▾":"▸"}),pe,n.jsx(Xt,{count:_.length,open:se,onToggle:()=>z(K)})]}):n.jsxs("div",{className:"w6w-exprmodal-source-row",children:[n.jsx("span",{className:"w6w-exprmodal-caret-spacer","aria-hidden":"true"}),pe]}),j.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&&se&&n.jsxs("div",{className:"w6w-exprmodal-subsources",children:[$e(j.outputsFrom),ke(j.id,_)]})]},j.id)})]}),me.length>0&&n.jsxs(Ke,{label:"State",testId:"expr-state-group",...xe("runstate"),children:[Q("state",{kind:"var",ref:"state"},"w6w-expr-chip-var","◇",!0),n.jsx("div",{className:"w6w-exprmodal-subsources","data-testid":"expr-state-fields",children:xo(me).map(({field:j,depth:_,name:K})=>{const se=`state.${j.key}`;return Q(K,{kind:"var",ref:se},"w6w-exprmodal-field",null,!1,void 0,{name:Ge(se),depth:_,somePaths:j.paths==="some"})})})]}),Ve.length>0&&n.jsx(Ke,{label:"Metadata",testId:"expr-metadata-group",...xe("meta"),children:Ve.map(j=>Kt(j))}),n.jsxs(n.Fragment,{children:[o.inputs!==void 0&&n.jsxs(Ke,{label:"Inputs",...xe("inputs"),children:[he.length===0&&n.jsx("span",{className:"w6w-expr-menu-empty",children:"No inputs"}),he.map(j=>Q(j,{kind:"var",ref:`inputs.${j}`},"w6w-expr-chip-var","⇥"))]}),n.jsxs(Ke,{label:"Variables",...xe("vars"),action:o.createVar&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm","data-testid":"expr-add-var",onClick:()=>oe("var"),children:"+ Add"}),children:[H.length===0&&n.jsx("span",{className:"w6w-expr-menu-empty",children:"No variables"}),H.map(j=>Q(j,{kind:"var",ref:`var.${j}`},"w6w-expr-chip-var","◆"))]}),ae.length>0&&n.jsx(Ke,{label:"Constants",testId:"expr-constants-group",...xe("consts"),children:ae.map(j=>Q(j,{kind:"var",ref:`const.${j}`},"w6w-expr-chip-var","◈"))})]}),(!b||m)&&n.jsxs(Ke,{label:"Documents",...xe("docs"),children:[ge.length===0&&n.jsx("span",{className:"w6w-expr-menu-empty",children:"No documents"}),ge.map(j=>{const _=(j.fields??[]).filter(ce=>wt(ce.key)),K=`doc:${j.key}`,se=X.has(K),pe=Q(j.key,{kind:"var",ref:`documents.${j.key}`},"w6w-expr-chip-var","▦",_.length>0);return n.jsxs(w.Fragment,{children:[_.length>0?n.jsxs("div",{className:"w6w-exprmodal-source-row",children:[pe,n.jsx(Xt,{count:_.length,open:se,onToggle:()=>z(K)})]}):pe,_.length>0&&se&&n.jsx("div",{className:"w6w-exprmodal-subsources",children:_.map(ce=>{const re=`documents.${j.key}.${ce.key}`;return n.jsxs("div",{className:"w6w-exprmodal-subsource-row",children:[Q(ce.key,{kind:"var",ref:re},"w6w-expr-chip-var","·"),!b&&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:()=>te({kind:"render",ref:re}),children:"▤"})]},re)})})]},j.key)})]}),!b&&n.jsxs(Ke,{label:"Secrets",...xe("secrets"),action:o.createSecret&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm","data-testid":"expr-add-secret",onClick:()=>oe("secret"),children:"+ Add"}),children:[fe.length===0&&n.jsx("span",{className:"w6w-expr-menu-empty",children:"No secrets"}),fe.map(j=>Q(j,{kind:"secret",ref:j},"w6w-expr-chip-secret","🔒"))]})]}),b&&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:()=>{k.current=!0},children:n.jsx(lt,{value:y,onChange:N,height:"100%",minHeight:"0px","aria-label":"Compose JSON",placeholder:m?'{ "region": "us", "template": "{{ documents.welcome }}" }':'{ "key": "{{ nodes.step_1.output }}" }',onCreateEditor:j=>{A.current=j}})})]}),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:[" ",m?" — the state each run starts with, against the sample values":" — live preview against the sample values"]})]}),v&&n.jsx("span",{className:"w6w-muted w6w-small",role:"alert","data-testid":"expr-json-problem",children:v}),n.jsx("pre",{className:"w6w-exprmodal-result","data-testid":"expr-json-result",children:C.ok?JSON.stringify(Kn(C.value,j=>Dt(j,R())),null,2):y.trim()===""?"":"Invalid JSON"})]})]}),!b&&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:D,className:`w6w-exprmodal-chips${t?" is-masked":""}${O.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":I.error!==null,"aria-describedby":I.error?"expression-problem":void 0,spellCheck:!1,onInput:()=>{const j=D.current;j&&dr(j,{renderToggle:!0}),J()},onDoubleClick:j=>{const _=j.target;if(_.closest("[data-x]")||_.closest("[data-render-toggle]"))return;const K=_.closest(".w6w-expr-chip");if(!K)return;j.preventDefault();const se=pr(K);if(se){const pe=se.ownerDocument,ce=pe.createRange();ce.setStartAfter(se),ce.collapse(!0);const re=pe.getSelection();re==null||re.removeAllRanges(),re==null||re.addRange(ce)}J()},onBlur:()=>{const j=D.current;j&&U(ie.serializeTemplate(Tt(j)),{restoreFocus:!1})},onPaste:j=>{var se;j.preventDefault();const _=D.current;if(!_)return;const K=((se=j.clipboardData)==null?void 0:se.getData("text/plain"))??"";for(const pe of Xe(K))pe.kind==="text"?Ot(_,_.ownerDocument.createTextNode(pe.value??"")):Ot(_,It(_.ownerDocument,pe,{renderToggle:!0}));J()},onClick:j=>{var pe;const _=j.target,K=_.closest("[data-x]");if(K){j.preventDefault(),(pe=K.closest(".w6w-expr-chip"))==null||pe.remove(),J();return}const se=_.closest("[data-render-toggle]");if(se){j.preventDefault();const ce=se.closest(".w6w-expr-chip");if(ce){const re=ce.getAttribute("data-ref")??"",Me=ce.getAttribute("data-kind")==="render"?"var":"render";ce.replaceWith(It(ce.ownerDocument,{kind:Me,ref:re},{renderToggle:!0}))}J()}},onKeyDown:j=>{if(j.key!=="Enter"||(j.preventDefault(),!s))return;const _=D.current;_&&(Ot(_,_.ownerDocument.createTextNode(`
|
|
13
|
+
`)),cr(_),J())}}),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."]}),I.error&&n.jsx("span",{id:"expression-problem",role:"alert",className:"w6w-error",children:I.error})]}),ze.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"]})]}),ze.map(j=>n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:j}),n.jsx("input",{type:"text",value:$[j]??At[j]??"",placeholder:"sample value",onChange:_=>G(K=>({...K,[j]:_.target.value}))})]},j))]}),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(ue.Copyable,{value:ee,readOnly:!0,children:n.jsx("pre",{className:"w6w-exprmodal-result",children:ee||" "})}),B.length>0&&n.jsx("span",{className:"w6w-muted w6w-small","data-testid":"expr-result-source",children:B.join(" · ")})]})]})]}),ne==="var"&&o.createVar&&n.jsx(jo,{kind:"var",onCreate:o.createVar,onClose:P}),ne==="secret"&&o.createSecret&&n.jsx(jo,{kind:"secret",onCreate:o.createSecret,onClose:P})]})}function Ke({label:e,open:t,onToggle:s,action:o,testId:r,children:i}){const a=w.useId(),l=w.useRef(null);return w.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":a,onClick:s,children:[n.jsx("span",{className:"w6w-exprmodal-group-label",children:e}),n.jsx("span",{className:"w6w-exprmodal-group-caret","aria-hidden":"true",children:"›"})]}),o]}),n.jsx("div",{id:a,ref:l,className:"w6w-exprmodal-group-body","aria-hidden":!t,children:n.jsx("div",{className:"w6w-exprmodal-group-inner",children:i})})]})}function Xt({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 Tl=[["app","App"],["version","App version"],["action","Action"],["connectionId","Connection ID"],["subscriptionId","Subscription ID"],["url","Webhook URL"]],Ol=new Set(["app","version","action","connectionId"]);function jo({kind:e,onCreate:t,onClose:s}){const[o,r]=w.useState(""),[i,a]=w.useState(""),[l,c]=w.useState(""),[u,d]=w.useState(null),[f,p]=w.useState(!1),h=e==="var"?"variable":"secret";async function b(){d(null),p(!0);try{await t({name:o,value:i,description:l||void 0}),s()}catch(m){d(m.message)}finally{p(!1)}}return n.jsxs(Se,{title:`Add ${h}`,onClose:s,children:[n.jsx("div",{className:"w6w-modal-body",children:n.jsxs("div",{className:"w6w-stack",children:[n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"Name"}),n.jsx("input",{type:"text",value:o,onChange:m=>r(m.target.value),placeholder:e==="var"?"e.g. api_base_url":"e.g. openai_api_key",autoComplete:"off","data-testid":"expr-add-value-name",autoFocus:!0}),n.jsx("span",{className:"w6w-muted w6w-small",children:"Letters, digits, and underscores. Must start with a letter or underscore. Case-sensitive."})]}),n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"Value"}),n.jsx("input",{type:e==="secret"?"password":"text",value:i,onChange:m=>a(m.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:m=>c(m.target.value),placeholder:"Optional",autoComplete:"off"})]}),u&&n.jsx("div",{className:"w6w-result w6w-error",children:u})]})}),n.jsxs("div",{className:"w6w-modal-actions",children:[n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost","data-testid":"expr-add-value-cancel",onClick:s,children:"Cancel"}),n.jsx("button",{type:"button",className:"w6w-btn","data-testid":"expr-add-value-save",disabled:!o||!i||f,onClick:b,children:f?"Saving…":"Save"})]})]})}function Il(e,t){return t?e.filter(s=>s.id!==t):e}const Gn=w.createContext({});function $l({value:e,children:t}){const s=w.useContext(Gn),o=w.useMemo(()=>({...s,...e}),[s,e]);return n.jsx(Gn.Provider,{value:o,children:t})}function ht(){return w.useContext(Gn)}function Ht({value:e,onChange:t,placeholder:s,masked:o,multiline:r,readOnly:i,options:a,"aria-label":l}){const[c,u]=w.useState(()=>Wn(e)),{parts:d,sealed:f}=c,[p,h]=w.useState(0),[b,m]=w.useState(!1),[x,g]=w.useState(!1),y=w.useRef(!1),N=w.useRef(null),A=w.useRef(null),k=ht(),C={...k,...a??{}},v=k.sealSecret;w.useLayoutEffect(()=>{const T=N.current;!T||f||(ur(T,d),(y.current||T.ownerDocument.activeElement===T)&&(T.focus(),Cs(T),y.current=!1))},[p,f]);const E=()=>{const T=N.current;if(!T)return;const I=Tt(T);u(q=>({...q,parts:I}));const M=Rt(I,C);t(tn(M.parts))},R=async T=>{if(!v)return!1;m(!0);try{const I=await v(T);return y.current=!1,u({parts:[],sealed:I}),h(M=>M+1),t(I),!0}catch{return!1}finally{m(!1)}},F=T=>{var q;if(x||!o||i||b)return;const I=T.relatedTarget;if(I&&((q=A.current)!=null&&q.contains(I)))return;const M=tn(d);typeof M=="string"&&M!==""&&!ct(M)&&R(M)},O=T=>{if(o&&typeof T=="string"&&T.trim()!==""&&!ct(T)){R(T);return}y.current=!1,u(Wn(T)),h(I=>I+1),t(T)};return f?n.jsxs("div",{className:`w6w-expr-sealed${i?" is-readonly":""}`,"aria-label":l,children:[n.jsxs("span",{className:"w6w-expr-chip w6w-expr-chip-secret",title:"Encrypted secret",children:[n.jsx("span",{className:"w6w-expr-chip-sigil",children:"🔒"}),n.jsx("span",{className:"w6w-expr-chip-label",children:"••••••"})]}),!i&&n.jsx("button",{type:"button",className:"w6w-expr-replace",onClick:()=>{y.current=!0,u({parts:[],sealed:null}),h(T=>T+1),t("")},children:"Replace"})]}):n.jsxs("div",{className:"w6w-expr",ref:A,onBlur:F,children:[n.jsxs("div",{className:"w6w-expr-field",children:[n.jsx("div",{ref:N,className:`w6w-expr-editor${o?" is-masked":""}${d.length===0?" is-empty":""}${i?" is-readonly":""}`,contentEditable:!i,suppressContentEditableWarning:!0,role:"textbox",tabIndex:i?-1:0,"aria-multiline":r?"true":"false","aria-label":l,"data-placeholder":s??"",spellCheck:!1,onInput:()=>{const T=N.current;T&&dr(T),E()},onClick:T=>{var M;const I=T.target.closest("[data-x]");I&&(T.preventDefault(),(M=I.closest(".w6w-expr-chip"))==null||M.remove(),E())},onDoubleClick:T=>{const I=T.target;if(I.closest("[data-x]"))return;const M=I.closest(".w6w-expr-chip");if(!M)return;T.preventDefault();const q=pr(M);if(q){const D=q.ownerDocument,Y=D.createRange();Y.setStartAfter(q),Y.collapse(!0);const $=D.getSelection();$==null||$.removeAllRanges(),$==null||$.addRange(Y)}E()},onKeyDown:T=>{if(T.key!=="Enter"||(T.preventDefault(),!r))return;const I=N.current;I&&(Ot(I,I.ownerDocument.createTextNode(`
|
|
14
|
+
`)),cr(I),E())}}),!i&&n.jsx("button",{type:"button",className:"w6w-expr-edit",title:"Edit expression — browse variables, secrets & step outputs","aria-label":"Edit expression",onClick:()=>g(!0),children:"ƒx"})]}),x&&n.jsx(zt,{value:tn(d),masked:o,multiline:r,options:C,fieldLabel:l,onSave:O,onClose:()=>g(!1)})]})}const Pl=/\{\{\s*([^{}]*?)\s*\}\}/g;function fr(e,t="javascript"){const s=t==="python",o=[],r=[];let i=0;for(;i<e.length;){const l=e[i],c=e.slice(i,i+2),u=e.slice(i,i+3);if(s&&l==="#"||!s&&c==="//"){const d=e.indexOf(`
|
|
15
|
+
`,i),f=d===-1?e.length:d;r.push({start:i,end:f}),i=f}else if(!s&&c==="/*"){const d=e.indexOf("*/",i+2),f=d===-1?e.length:d+2;r.push({start:i,end:f}),i=f}else if(s&&(u==='"""'||u==="'''")){const d=e.indexOf(u,i+3),f=d===-1?e.length:d+3;o.push({start:i,end:f,quote:u}),i=f}else if(l==="'"||l==='"'||!s&&l==="`"){let d=i+1;for(;d<e.length&&e[d]!==l;){if(e[d]==="\\")d++;else if(l!=="`"&&e[d]===`
|
|
16
|
+
`)break;d++}const f=Math.min(d+1,e.length);o.push({start:i,end:f,quote:l}),i=f}else i++}const a=[];for(const l of e.matchAll(Pl)){const c=l.index??0,u=c+l[0].length;if(r.some(f=>c>=f.start&&c<f.end))continue;const d=o.find(f=>c>f.start&&c<f.end);a.push({start:c,end:u,ref:l[1],context:d?{kind:"string",...d}:{kind:"code"}})}return a}const _l=/^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$-]*|\[\d+\]|\["[^"\\]*"\]|\['[^'\\]*'\])*$/,Ll=/\.([A-Za-z_$][\w$-]*)|\[(\d+)\]|\["([^"\\]*)"\]|\['([^'\\]*)'\]/g,Fl={nodes:["run","nodes"],steps:["run","nodes"],trigger:["run","trigger"],foreach:["run","foreach"],state:["state"],var:["state"],vars:["state"],const:["consts"],consts:["consts"]};function sn(e,t="javascript"){var c;const s=e.trim();if(!_l.test(s))return null;const o=((c=/^[A-Za-z_$][\w$]*/.exec(s))==null?void 0:c[0])??"",r=Fl[o];if(!r)return null;const i=[...r.slice(1)];for(const u of s.slice(o.length).matchAll(Ll))i.push(u[2]!==void 0?Number(u[2]):u[1]??u[3]??u[4]);const a=r[0]==="run"?i.shift():r[0];return`${t==="python"?"ctx":"$"}.get(${[a,...i].map(u=>JSON.stringify(u)).join(", ")})`}function Ml(e,t="javascript"){const s=t==="python";let o="",r=0,i=0,a=0;for(const l of fr(e,t)){const c=sn(l.ref,t);if(c===null){a++;continue}const u=l.context;if(u.kind==="code"){o+=e.slice(r,l.start)+c,r=l.end,i++;continue}const d=u.quote,f=l.start===u.start+d.length,p=l.end===u.end-d.length;if(f&&p)o+=e.slice(r,u.start)+c,r=u.end,i++;else if(!s&&d==="`")o+=`${e.slice(r,l.start)}\${${c}}`,r=l.end,i++;else if(d.length===1&&!(s&&/[A-Za-z]/.test(e[u.start-1]??""))){const h=s?`str(${c})`:c;o+=f?`${e.slice(r,u.start)}${h} + ${d}`:`${e.slice(r,l.start)}${d} + ${h}`,p?r=u.end:(f||(o+=` + ${d}`),r=l.end),i++}else a++}return o+=e.slice(r),{code:o,converted:i,left:a}}function Dl({param:e,value:t,language:s,label:o,req:r,readOnly:i,onChange:a}){var A;const l=w.useRef(null),[c,u]=w.useState(!1),d=ht(),f=d.steps??[],p=s==="python",h=k=>{const C=l.current;if(!C){a(t+k);return}C.dispatch(C.state.replaceSelection(k)),C.focus()},b=k=>{const C=Qe(k);if(C!==null){const v=sn(C,s);v&&h(v);return}k===void 0||k===""||h(JSON.stringify(k,null,2).replace(/"\{\{\s*([^{}"]*?)\s*\}\}"/g,(v,E)=>sn(E,s)??v))},m=((A=f[0])==null?void 0:A.id)??"<step-id>",x=p?"ctx":"$",g=[[`${x}.get("nodes", ${JSON.stringify(m)}, "output")`,"a step's output"],[`${x}.get("state", "region")`,"a workflow state value"],[`${x}.get("consts", "api_base")`,"a constant"]],y=Math.max(...g.map(([k])=>k.length)),N=p?"#":"//";return n.jsxs("div",{className:"w6w-field w6w-script-code",children:[n.jsxs("span",{children:[o,r]}),n.jsx(xs,{value:t,readOnly:i,minHeight:"180px",language:s,"aria-label":`${e.key} code`,onChange:a,onCreateEditor:k=>{l.current=k}}),!i&&n.jsxs("div",{className:"w6w-seed-chips w6w-script-insert",children:[n.jsx("span",{className:"w6w-muted w6w-small",children:"Insert"}),f.map(k=>{const C=sn(`nodes[${JSON.stringify(k.id)}].output`,s)??"";return n.jsx("button",{type:"button",className:"w6w-chip w6w-seed-chip",title:`Insert ${C}`,onClick:()=>h(C),children:n.jsx("code",{children:k.id})},k.id)}),n.jsx("button",{type:"button",className:"w6w-chip w6w-seed-chip",title:"Pick a step field, variable or constant to insert as code","aria-label":`Insert a value into ${o}`,onClick:()=>u(!0),children:"ƒx"})]}),e.hint&&n.jsx("span",{className:"w6w-hint",children:e.hint}),n.jsxs("details",{className:"w6w-script-help",children:[n.jsx("summary",{className:"w6w-muted w6w-small",children:"How to read data"}),n.jsx("pre",{className:"w6w-script-help-examples",children:g.map(([k,C])=>`${k.padEnd(y)} ${N} ${C}`).join(`
|
|
17
|
+
`)}),n.jsxs("span",{className:"w6w-hint",children:[n.jsx("code",{children:"input"})," is the same as ",n.jsx("code",{children:"run"})," unless you set Custom input."]}),n.jsx("span",{className:"w6w-hint",children:p?n.jsxs(n.Fragment,{children:["Use ",n.jsx("code",{children:"ctx.state"})," and ",n.jsx("code",{children:"ctx.nodes"})," directly, or"," ",n.jsx("code",{children:"ctx.get(root, *keys)"})," for literal keys. Missing paths return"," ",n.jsx("code",{children:"None"}),". Existing globals still work."]}):n.jsxs(n.Fragment,{children:["Use ",n.jsx("code",{children:"$.state"})," and ",n.jsx("code",{children:"$.nodes"})," directly, or"," ",n.jsx("code",{children:"$.get(root, ...keys)"})," for literal keys. Existing ",n.jsx("code",{children:"run"}),","," ",n.jsx("code",{children:"state"}),", ",n.jsx("code",{children:"vars"})," and ",n.jsx("code",{children:"consts"})," reads still work. Type a dot for suggestions, or press Ctrl+Space."]})})]}),c&&n.jsx(zt,{mode:"json-binding",value:void 0,jsonValue:void 0,options:d,fieldLabel:o,whole:!0,onSaveJson:b,onClose:()=>u(!1)})]})}function jn(e){const t=[];for(const s of e)t.push(s),s.type==="section"&&s.children&&t.push(...jn(s.children));return t}function hr(e){return ct(e)||Ze(e)?!0:typeof e=="object"&&e!==null&&!Array.isArray(e)&&Object.prototype.hasOwnProperty.call(e,"$")}function pn(e){var t;return((t=e.config)==null?void 0:t.allowCustom)===!0}function Yn(e){return jn(e).filter(t=>gn(t.options))}function As(e){return gn(e.options)?e.options.refreshOn??[]:[]}function Xn(e,t){const s={},o=[];for(const r of jn(e)){if(r.type==="section")continue;const i=t[r.key]!==void 0?t[r.key]:r.default;i!==void 0&&(hr(i)?o.push(r.key):s[r.key]=i)}return{form:s,unresolved:o}}function Hl(e,t,s,o,r){const{form:i,unresolved:a}=Xn(e,t),l=new Set(a),c=Yn(e).filter(d=>{const f=As(d);return s==="change"&&!(o??[]).some(p=>f.includes(p))?!1:f.every(p=>!l.has(p))}).map(d=>d.key);if(c.length===0)return null;const u={reason:s,form:i,fields:c,unresolved:a};return s==="change"&&(u.changed=[...o??[]],u.previous=Xn(e,r??{}).form),u}function No(e,t,s){return JSON.stringify([e.appId,e.version??null,e.actionKey,e.connectionId??null,t.key,As(t).map(o=>s[o]??null)])}function ko(e){return!(gn(e.options)&&e.options.cache==="none")}function Bl(e,t){return e.some(s=>t.includes(s))}function ql(e,t,s,o){var l;if(!o.connectionId)return{reason:"no-connection",hint:"Connect an account to load choices"};const r=new Set(Xn(t,s).unresolved),i=As(e).find(c=>r.has(c));return i===void 0?null:{reason:"unresolved-dependency",hint:`Options unavailable while ${((l=jn(t).find(c=>c.key===i))==null?void 0:l.label)??i} is an expression`}}function So(e,t,s){return e==null||e===""?{action:"keep"}:hr(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 Wl(e,t,s,o){var N;const r=(N=en())==null?void 0:N.resolveActionFields,i=!!(s&&r),[a,l]=w.useState({}),c=w.useRef({params:e,values:t,dynamic:s,onChange:o,resolve:r});c.current={params:e,values:t,dynamic:s,onChange:o,resolve:r};const u=w.useRef(new Map),d=w.useRef([]),f=w.useCallback((A,k,C,v,E)=>{const{params:R,values:F,dynamic:O,resolve:T}=c.current,I=E??F;if(!O||!T||!O.connectionId)return;const M=Hl(R,I,A,k,C);if(!M)return;const q=new Map(Yn(R).map(W=>[W.key,W])),D=[],Y={},$=[],G=O.appName??O.appId,ne=(W,J)=>{const te=q.get(W);if(!te)return;So(I[W],J,{allowCustom:pn(te),reason:A,appLabel:G}).action==="clear"&&D.push(W)};for(const W of M.fields){if(v!==void 0&&W!==v)continue;const J=q.get(W);if(!J)continue;const te=v===void 0&&ko(J)?u.current.get(No(O,J,M.form)):void 0;te?(Y[W]={options:te,loading:!1},ne(W,te)):$.push(W)}const oe=(W=!1)=>{if(D.length===0)return;const J={...W?I:c.current.values};for(const te of D)delete J[te];c.current.onChange(J)};if(Object.keys(Y).length>0&&l(W=>({...W,...Y})),$.length===0){oe(!0);return}for(const W of d.current)Bl(W.fields,$)&&W.controller.abort();const X=new AbortController,L={fields:$,controller:X};d.current=[...d.current.filter(W=>!W.controller.signal.aborted),L],l(W=>{var te;const J={...W};for(const S of $)J[S]={options:(te=W[S])==null?void 0:te.options,loading:!0};return J});const z={...M,fields:$,connectionId:O.connectionId,...O.version!==void 0?{version:O.version}:{}},Z=W=>{d.current=d.current.filter(J=>J!==L),l(J=>({...J,...W}))};Promise.resolve().then(()=>T(O.appId,O.actionKey,z,{signal:X.signal})).then(W=>{var te;if(X.signal.aborted)return;const J={};for(const S of $){const U=(te=W==null?void 0:W.fields)==null?void 0:te[S],V=q.get(S);if(!U||!V)J[S]={loading:!1};else if(U.error)J[S]={loading:!1,error:U.error};else{const P=Array.isArray(U.options)?U.options:[];J[S]={loading:!1,options:P},ko(V)&&u.current.set(No(O,V,M.form),P),ne(S,P)}}Z(J),oe()}).catch(W=>{if(X.signal.aborted)return;const J=W instanceof Error?W.message:String(W),te={};for(const S of $)te[S]={loading:!1,error:J||"Request failed"};Z(te)})},[]),p=s?JSON.stringify([s.appId,s.actionKey,s.version,s.connectionId]):"";w.useEffect(()=>{if(i)return l({}),f("init"),()=>{for(const A of d.current)A.controller.abort();d.current=[]}},[p,i,f]);const h=w.useRef(new Map),b=w.useCallback((A,k)=>{const C=h.current.get(A)??c.current.values;h.current.delete(A),f("change",[A],C,void 0,{...c.current.values,[A]:k})},[f]),m=w.useCallback(A=>{h.current.has(A)||h.current.set(A,c.current.values)},[]),x=w.useCallback(A=>{const k=h.current.get(A);if(h.current.delete(A),!k)return;const C=c.current.values;JSON.stringify(k[A])!==JSON.stringify(C[A])&&f("change",[A],k)},[f]),g=w.useCallback(A=>f("init",void 0,void 0,A),[f]);return{fields:w.useMemo(()=>{const A={};if(!i||!s)return A;const k=s.appName??s.appId;for(const C of Yn(e)){const v=ql(C,e,t,s);if(v){A[C.key]={loading:!1,hint:v.hint};continue}const E=a[C.key]??{loading:!0},R={...E};if(E.options){const F=So(t[C.key],E.options,{allowCustom:pn(C),reason:"init",appLabel:k});F.action==="flag"&&(R.notInList=F.message)}A[C.key]=R}return A},[i,s,e,t,a]),commit:b,focus:m,blur:x,retry:g}}function Jt(e,t){return e.hidden===!0?!1:e.showIf?ie.matchesParamCondition(e.showIf,t):!0}function vt(e){const t=[];for(const s of e)t.push(s),s.type==="section"&&s.children&&t.push(...vt(s.children));return t}function Bt(e,t){const s=[];for(let o=0;o<e.length;){const r=e[o].row;if(r){const i=[];for(;o<e.length&&e[o].row===r;)i.push(e[o++]);s.push(n.jsx("div",{className:"w6w-field-row",children:i.map(t)},`row:${r}`))}else s.push(t(e[o])),o++}return s}function mr(e,t,s,o){const r=i=>i.type==="section"?n.jsx(Ul,{param:i,effective:s,renderOne:r},i.key):i.repeat&&i.type!=="array"?n.jsx(Kl,{param:i,value:e[i.key],onChange:t,readOnly:o},i.key):i.type==="group"&&i.children&&i.children.length>0?n.jsx(Jl,{param:i,value:e[i.key],onChange:t,effective:s,readOnly:o},i.key):n.jsx(Yl,{param:i,value:e[i.key],onChange:t,effective:s,readOnly:o},i.key);return r}const Nn=w.createContext(null);function He({params:e,values:t,onChange:s,readOnly:o,dynamic:r}){const i=Wl(e,t,r,s),a=vt(e),l=h=>{var b;return t[h]!==void 0?t[h]:(b=a.find(m=>m.key===h))==null?void 0:b.default},c=e.filter(h=>Jt(h,l)).map(h=>ie.effectiveParam(h,l)),u=c.filter(h=>h.required||!h.advanced),d=c.filter(h=>!h.required&&h.advanced),f=(h,b)=>{if(h==="language"){const m={...t,[h]:b};for(const x of a){if(x.type!=="code")continue;const g=t[x.key];(g===void 0||g===x.default||g===Zn||Gl.includes(g))&&(m[x.key]=b==="python"?Zn:x.default)}s(m);return}s({...t,[h]:b})};if(e.length===0)return n.jsx("p",{className:"w6w-muted w6w-small",children:"This action takes no parameters."});const p=mr(t,f,l,o);return n.jsx(Nn.Provider,{value:i,children:n.jsxs("div",{className:"w6w-stack",children:[Bt(u,p),d.length>0&&n.jsxs("details",{className:"w6w-params-optional",children:[n.jsxs("summary",{className:"w6w-muted w6w-small",children:["Additional parameters (",d.length,")"]}),n.jsx("div",{className:"w6w-stack",style:{marginTop:8},children:Bt(d,p)})]})]})})}function Ul({param:e,effective:t,renderOne:s}){const o=(e.children??[]).filter(r=>Jt(r,t)).map(r=>ie.effectiveParam(r,t));return e.section==="collapsible"?n.jsxs("details",{className:"w6w-section",open:e.collapsed===!1||e.openWhenSet===!0&&o.some(r=>{const i=t(r.key);return i!=null&&i!==""}),children:[n.jsxs("summary",{className:"w6w-section-summary",children:[n.jsx("span",{className:"w6w-section-title",children:e.title??e.label??e.key}),e.subtitle&&n.jsx("span",{className:"w6w-section-subtitle",children:e.subtitle})]}),n.jsx("div",{className:"w6w-stack w6w-section-body",children:Bt(o,s)})]}):e.layout==="row"?n.jsx("div",{className:"w6w-field-row",children:o.map(s)}):n.jsx("div",{className:"w6w-stack",children:Bt(o,s)})}const Vl=new Set(["string","text","number","boolean","select"]);function zl(e){return e.length>0&&e.every(t=>Vl.has(t.type)&&!t.children)}function Jl({param:e,value:t,onChange:s,effective:o,readOnly:r}){const i=e.children??[],a=t??{},l=(p,h)=>s(e.key,{...a,[p]:h}),c=vt(i),u=p=>{const h=c.find(b=>b.key===p);return h?a[p]!==void 0?a[p]:h.default:o(p)},d=i.filter(p=>Jt(p,u)).map(p=>ie.effectiveParam(p,u)),f=mr(a,l,u,r);return n.jsx(Nn.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:Bt(d,f)})]})})}function Kl({param:e,value:t,onChange:s,readOnly:o}){if(e.type==="group"){const i=e.children??[];if(!zl(i))return n.jsx(Es,{param:e,value:t,onChange:s,readOnly:o});const a={...e,item:{type:"object",fields:i}};return n.jsx(Qn,{param:a,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(Qn,{param:r,value:t,onChange:s,readOnly:o})}const Zn=`# Runs as a function body. Return the step's output.
|
|
18
|
+
return input`,Gl=["// 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 Yl(e){const t=w.useContext(Nn),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(Xl,{...e})})}function Xl({param:e,value:t,onChange:s,effective:o,readOnly:r}){var A,k,C,v,E;const i=(A=en())==null?void 0:A.listModelRoutes,a=(k=en())==null?void 0:k.listDataStores,l=(C=en())==null?void 0:C.listDataStoreEntries,c=bs(),u=w.useContext(Nn),d=u==null?void 0:u.fields[e.key],f=(R,F)=>{s(R,F),u==null||u.commit(R,F)},p=s,h=e.label??e.key,b=e.required&&e.type!=="boolean"?" *":"",m=w.useId();if(e.type==="boolean"){const R=!!(t??e.default??!1);return n.jsx(_e,{param:e,value:t,onChange:p,readOnly:r,label:h,req:b,variant:"inline",controlId:m,children:n.jsx("input",{id:m,type:"checkbox",checked:R,disabled:r,onChange:F=>f(e.key,F.target.checked)})})}if(e.type==="json"||e.type==="group")return n.jsx(Es,{param:e,value:t,onChange:p,readOnly:r});if(e.type==="code"){const R=o==null?void 0:o("language"),F=R==="python"||R==="javascript"||R==="typescript"?R:void 0,O=F==="python"?Zn:e.default,T=t??O??"";return e.scriptReads?n.jsx(Dl,{param:e,value:String(T),language:R==="python"?"python":"javascript",label:h,req:b,readOnly:r,onChange:I=>p(e.key,I)}):n.jsxs("div",{className:"w6w-field",children:[n.jsxs("span",{children:[h,b]}),n.jsx(xs,{value:String(T),readOnly:r,minHeight:"180px",language:F,"aria-label":`${e.key} code`,onChange:I=>p(e.key,I)}),e.hint&&n.jsx("span",{className:"w6w-hint",children:e.hint})]})}if(e.type==="model-route"&&i)return n.jsx(Zl,{param:e,value:t,onChange:p,readOnly:r,label:h,req:b,listModelRoutes:i,project:c});if(e.type==="data-store"&&a)return n.jsx(Ql,{param:e,value:t,onChange:p,readOnly:r,label:h,req:b,listDataStores:a,project:c});const x=o==null?void 0:o("store");if(e.type==="data-store-key"&&l&&typeof x=="string"&&x.trim()!=="")return n.jsx(sc,{param:e,value:t,onChange:p,readOnly:r,label:h,req:b,store:x,listDataStoreEntries:l,project:c});if(e.type==="vars")return n.jsx(cc,{param:e,value:t,onChange:p,readOnly:r});if(e.type==="text"||(v=e.config)!=null&&v.multiline){const R=t??e.default??"";return n.jsx(_e,{param:e,value:t,onChange:p,readOnly:r,label:h,req:b,children:n.jsx("textarea",{rows:3,value:String(R),readOnly:r,"aria-label":h,onChange:F=>p(e.key,F.target.value)})})}if(e.type==="multiselect")return n.jsx(oc,{param:e,value:t,onChange:f,readOnly:r});if(e.type==="array")return n.jsx(Qn,{param:e,value:t,onChange:p,readOnly:r});if(u&&d&&!d.hint)return n.jsx(Co,{param:e,value:t,onChange:f,readOnly:r,label:h,req:b,state:d,retry:()=>u.retry(e.key)});if(Array.isArray(e.options)&&e.options.length>0&&pn(e))return n.jsx(Co,{param:e,value:t,onChange:f,readOnly:r,label:h,req:b,state:{loading:!1,options:e.options}});if(Array.isArray(e.options)&&e.options.length>0){const R=!e.required&&e.default===void 0&&typeof e.placeholder=="string"&&e.placeholder?e.placeholder:void 0,F=t??e.default??(R!==void 0?"":(E=e.options[0])==null?void 0:E.value)??"",O=e.type==="number";return n.jsx(_e,{param:e,value:t,onChange:p,readOnly:r,label:h,req:b,children:n.jsxs("select",{value:String(F),disabled:r,"aria-label":h,onChange:T=>{const I=T.target.value;R!==void 0&&I===""?f(e.key,void 0):f(e.key,O?Number(I):I)},children:[R!==void 0&&n.jsx("option",{value:"",children:R}),e.options.map(T=>n.jsx("option",{value:String(T.value),children:T.label},String(T.value)))]})})}if(e.type==="secret"){const R=t??e.default;return n.jsxs("div",{className:"w6w-field",children:[n.jsxs("span",{children:[h,b]}),n.jsx(Ht,{value:R,masked:!0,readOnly:r,"aria-label":h,onChange:F=>p(e.key,F)}),e.hint&&n.jsx("span",{className:"w6w-hint",children:e.hint})]})}const g=e.type==="number"?"number":"text",y=t??e.default??"",N=typeof y=="object"&&y!==null?JSON.stringify(y):String(y??"");return n.jsxs(_e,{param:e,value:t,onChange:p,readOnly:r,label:h,req:b,children:[n.jsx("input",{type:g,value:N,readOnly:r,"aria-label":h,autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",spellCheck:!1,"data-1p-ignore":"true","data-lpignore":"true","data-bwignore":"true","data-form-type":"other",onChange:R=>p(e.key,e.type==="number"?Number(R.target.value):R.target.value)}),(d==null?void 0:d.hint)&&n.jsx("span",{className:"w6w-hint",children:d.hint})]})}function Co({param:e,value:t,onChange:s,readOnly:o,label:r,req:i,state:a,retry:l}){const c=t??e.default??"",u=typeof c=="string"||typeof c=="number"?String(c):"";return n.jsxs(_e,{param:e,value:t,onChange:s,readOnly:o,label:r,req:i,children:[n.jsx("div",{className:"w6w-fx-grow","aria-busy":a.loading?"true":"false",children:n.jsx(kt,{mode:"combobox",forceSelection:!pn(e),"aria-label":r,disabled:o,value:u,placeholder:a.loading?"Loading…":e.placeholder,options:(a.options??[]).map(d=>({value:String(d.value),label:d.label})),onChange:d=>s(e.key,d)})}),a.notInList&&n.jsx("span",{className:"w6w-hint",children:a.notInList}),a.error&&n.jsxs("span",{role:"alert",className:"w6w-hint",children:[a.error,l&&n.jsx("button",{type:"button",onClick:l,children:"Retry"})]})]})}function Zl({param:e,value:t,onChange:s,readOnly:o,label:r,req:i,listModelRoutes:a,project:l}){const[c,u]=w.useState([]);w.useEffect(()=>{let p=!0;return Promise.resolve().then(()=>a(l)).then(h=>p&&u(Array.isArray(h)?h:[])).catch(()=>p&&u([])),()=>{p=!1}},[a,l]);const d=t??e.default??"",f=typeof d=="string"?d:"";return n.jsx(_e,{param:e,value:t,onChange:s,readOnly:o,label:r,req:i,children:n.jsx(kt,{mode:"combobox",forceSelection:!1,"aria-label":r,disabled:o,value:f,placeholder:"Select a route…",options:c.map(p=>({value:p.name,label:p.status==="broken"?`${p.name} (broken)`:p.name})),onChange:p=>s(e.key,p)})})}function Ql({param:e,value:t,onChange:s,readOnly:o,label:r,req:i,listDataStores:a,project:l}){const[c,u]=w.useState([]);w.useEffect(()=>{let p=!0;return Promise.resolve().then(()=>a(l)).then(h=>p&&u(Array.isArray(h)?h:[])).catch(()=>p&&u([])),()=>{p=!1}},[a,l]);const d=t??e.default??"",f=typeof d=="string"?d:"";return n.jsx(_e,{param:e,value:t,onChange:s,readOnly:o,label:r,req:i,children:n.jsx(kt,{mode:"combobox",forceSelection:!1,"aria-label":r,disabled:o,value:f,placeholder:"Select a store…",options:c.map(p=>({value:p.name,label:`${p.name} (${p.kind})`})),onChange:p=>s(e.key,p)})})}const ec=25,tc=200,Ao=60;function nc(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>Ao&&(t=`${t.slice(0,Ao-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 sc({param:e,value:t,onChange:s,readOnly:o,label:r,req:i,store:a,listDataStoreEntries:l,project:c}){const[u,d]=w.useState(""),[f,p]=w.useState({items:[]}),[h,b]=w.useState(!0);w.useEffect(()=>{const y=new AbortController;b(!0);const N=u.trim(),A=setTimeout(()=>{Promise.resolve().then(()=>l(a,{project:c,prefix:N===""?void 0:N,limit:ec,signal:y.signal})).then(k=>{y.signal.aborted||(p(k&&Array.isArray(k.items)?k:{items:[]}),b(!1))}).catch(()=>{y.signal.aborted||(p({items:[]}),b(!1))})},N===""?0:tc);return()=>{clearTimeout(A),y.abort()}},[l,a,c,u]);const m=t??e.default??"",x=typeof m=="string"?m:"",g=u.trim();return n.jsx(_e,{param:e,value:t,onChange:s,readOnly:o,label:r,req:i,children:n.jsx(kt,{mode:"combobox",forceSelection:!1,"aria-label":r,disabled:o,value:x,placeholder:"Search entries or type a key…",options:f.items.map(y=>({value:y.key,label:y.key,detail:nc(y)||void 0})),onInputChange:d,emptyText:h?"Searching…":g!==""?`No key starts with "${g}" — Enter keeps it as typed`:"No entries in this store",footer:f.more?"More entries — type to narrow by key":void 0,onChange:y=>s(e.key,y)})})}function _e({param:e,value:t,onChange:s,readOnly:o,label:r,req:i,bare:a,variant:l="boxed",controlId:c,children:u}){var g;const d=ct(t),f=e.type==="text"||!!((g=e.config)!=null&&g.multiline),[p,h]=w.useState(!1),b=ht(),m=l==="inline"&&!d,x=n.jsxs(n.Fragment,{children:[n.jsx("div",{className:m?"w6w-fx-inline":`w6w-fx-wrap${d?" is-fx":""}`,children:d?n.jsx(Ht,{value:t,multiline:f,readOnly:o,"aria-label":r,onChange:y=>s(e.key,y)}):n.jsxs(n.Fragment,{children:[u,!o&&n.jsx("button",{type:"button",className:"w6w-expr-fx",title:"Use an expression","aria-label":`Use an expression for ${r}`,onClick:()=>h(!0),children:"ƒx"}),m&&n.jsxs("label",{className:"w6w-fx-inline-label",htmlFor:c,children:[r,i]})]})}),p&&n.jsx(zt,{value:t,multiline:f,options:b,fieldLabel:r,onSave:y=>s(e.key,y),onClose:()=>h(!1)})]});return a?x:n.jsxs("div",{className:"w6w-field",children:[!m&&n.jsxs("span",{children:[r,i]}),x,e.hint&&n.jsx("span",{className:"w6w-hint",children:e.hint})]})}function Es({param:e,value:t,onChange:s,readOnly:o,headerActions:r,onValidityChange:i}){const a=Qe(t)??"",l=a!=="",c=t??e.default,[u,d]=w.useState(()=>l||c===void 0?"":JSON.stringify(c,null,2)),[f,p]=w.useState(!1),[h,b]=w.useState(!1),[m,x]=w.useState(!1),g=ht(),y=g.steps??[];w.useEffect(()=>{if(l)return;let R;try{R=u.trim()===""?void 0:JSON.parse(u)}catch{R=void 0}JSON.stringify(R)!==JSON.stringify(c)&&(d(c===void 0?"":JSON.stringify(c,null,2)),p(!1))},[c,e.key,l]);const N=R=>{d(R)},A=R=>{p(!1),i==null||i(!0),s(e.key,R)},k=({valid:R,error:F})=>{if(i==null||i(R||F==="Empty"),!R&&F==="Empty"){p(!1),s(e.key,void 0);return}p(!R)},C=()=>{const R=El(u);R&&(p(!1),s(e.key,R))},v=e.label??e.key,E=()=>{let R;try{R=u.trim()===""?void 0:JSON.parse(u)}catch{R=void 0}s(e.key,R)};return n.jsxs("div",{className:"w6w-field",children:[n.jsxs("span",{className:"w6w-field-labelrow",children:[n.jsxs("span",{children:[v,e.required?" *":""]}),r,!l&&n.jsx("button",{type:"button",className:"w6w-icon-btn w6w-btn-sm",title:"Open in full view","aria-label":`Open ${v} in full view`,onClick:()=>b(!0),children:n.jsx(ue.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":a,title:`Variable: ${a}`,children:[n.jsx("span",{className:"w6w-expr-chip-sigil",children:"◆"}),n.jsx("span",{className:"w6w-expr-chip-label",children:Ge(a)}),!o&&n.jsx("button",{type:"button",className:"w6w-expr-chip-x","aria-label":`Remove the reference from ${v}`,style:{border:0,padding:0,font:"inherit"},onClick:E,children:"×"})]})}),!o&&n.jsx("button",{type:"button",className:"w6w-expr-edit",title:"Edit expression — browse step outputs, metadata & variables","aria-label":`Edit expression for ${v}`,onClick:()=>x(!0),children:"ƒx"})]})})}):n.jsx(lt,{value:u,onChange:N,onBlur:C,readOnly:o,minHeight:"34px",maxHeight:"260px","aria-label":`${e.key} JSON`,onValidChange:A,onValidityChange:k,overlay:o?void 0:n.jsx("button",{type:"button",className:"w6w-expr-fx",title:"Use an expression","aria-label":`Use an expression for ${v}`,onClick:()=>x(!0),children:"ƒx"})}),m&&n.jsx(zt,{mode:"json-binding",value:void 0,jsonValue:t,options:g,fieldLabel:v,whole:e.whole,onSaveJson:R=>s(e.key,R),onClose:()=>x(!1)}),!l&&f&&n.jsx("span",{className:"w6w-hint",style:{color:"var(--w6w-danger)"},children:"Invalid JSON"}),e.whole&&!l&&!o&&y.length>0&&n.jsxs("div",{className:"w6w-seed-chips w6w-json-quickbind",children:[n.jsx("span",{className:"w6w-muted w6w-small",children:"Use the output of"}),y.map(R=>n.jsx("button",{type:"button",className:"w6w-chip w6w-seed-chip",title:`Bind ${v} to {{ nodes.${R.id}.output }}`,onClick:()=>s(e.key,`{{ nodes.${R.id}.output }}`),children:n.jsx("code",{children:R.id})},R.id))]}),e.hint&&n.jsx("span",{className:"w6w-hint",children:e.hint}),h&&!l&&n.jsxs(Se,{title:v,subtitle:n.jsx("code",{children:"JSON"}),size:"wide",onClose:()=>b(!1),children:[n.jsx("div",{className:"w6w-json-fullview",children:n.jsx(lt,{value:u,onChange:N,readOnly:o,height:"100%",minHeight:"360px","aria-label":`${e.key} JSON (full view)`,onValidChange:A,onValidityChange:k})}),f&&n.jsx("span",{className:"w6w-hint",style:{color:"var(--w6w-danger)"},children:"Invalid JSON"})]})]})}function oc({param:e,value:t,onChange:s,readOnly:o}){var g;const r=Array.isArray(e.options)?e.options:[],i=((g=e.config)==null?void 0:g.valueFormat)==="csv",a=t??e.default,l=Array.isArray(a)?a:i&&typeof a=="string"?a.split(",").map(y=>y.trim()).filter(Boolean):[],c=new Set(l.map(String)),u=r.filter(y=>!c.has(String(y.value))),d=y=>{var N;return((N=r.find(A=>String(A.value)===String(y)))==null?void 0:N.label)??String(y)},f=y=>s(e.key,i?y.join(","):y),p=y=>{if(!y||c.has(y))return;const N=r.find(A=>String(A.value)===y);f([...l,N?N.value:y])},h=y=>f(l.filter(N=>String(N)!==String(y))),b=typeof e.placeholder=="string"&&e.placeholder?e.placeholder:"Select…",m=e.label??e.key,x=e.required?" *":"";return n.jsx(_e,{param:e,value:t,onChange:s,readOnly:o,label:m,req:x,children:e.ui==="checkboxes"?n.jsxs("div",{className:"w6w-multiselect-checks w6w-fx-grow",children:[n.jsxs("div",{className:"w6w-multiselect-checks-toolbar",children:[n.jsxs("span",{className:"w6w-muted w6w-small",children:[l.length," selected"]}),!o&&n.jsxs(n.Fragment,{children:[n.jsx("button",{type:"button",className:"w6w-linkbtn",disabled:u.length===0,onClick:()=>f([...l,...u.map(y=>y.value)]),children:"Select all"}),n.jsx("button",{type:"button",className:"w6w-linkbtn",disabled:l.length===0,onClick:()=>f([]),children:"Clear"})]})]}),n.jsx("fieldset",{className:"w6w-multiselect-checks-options","aria-label":m,children:[...r,...l.filter(y=>!r.some(N=>String(N.value)===String(y))).map(y=>({value:y,label:String(y)}))].map(y=>n.jsxs("label",{className:"w6w-multiselect-check",children:[n.jsx("input",{type:"checkbox",checked:c.has(String(y.value)),disabled:o,onChange:N=>N.target.checked?p(String(y.value)):h(y.value)}),n.jsx("span",{children:y.label})]},String(y.value)))})]}):n.jsx(n.Fragment,{children:n.jsxs("div",{className:`w6w-multiselect${o?" is-readonly":""}`,children:[l.map(y=>n.jsxs("span",{className:"w6w-chip",children:[d(y),!o&&n.jsx("button",{type:"button",className:"w6w-chip-x","aria-label":`Remove ${d(y)}`,title:"Remove",onClick:()=>h(y),children:"×"})]},String(y))),!o&&n.jsxs("select",{className:"w6w-multiselect-add",value:"",disabled:u.length===0,"aria-label":`Add to ${e.label??e.key}`,onChange:y=>p(y.target.value),children:[n.jsx("option",{value:"",children:u.length>0?l.length?"Add more…":b:"All selected"}),u.map(y=>n.jsx("option",{value:String(y.value),children:y.label},String(y.value)))]})]})})})}function rc({field:e,value:t,onChange:s,readOnly:o}){var a;const r=e.placeholder??e.label??e.key;if(Array.isArray(e.options)&&e.options.length>0)return n.jsx("select",{className:"w6w-array-input",value:String(t??e.default??((a=e.options[0])==null?void 0:a.value)??""),disabled:o,"aria-label":e.label??e.key,onChange:l=>s(l.target.value),children:e.options.map(l=>n.jsx("option",{value:String(l.value),children:l.label},String(l.value)))});if(e.type==="boolean")return n.jsxs("label",{className:"w6w-array-check",title:e.label??e.key,children:[n.jsx("input",{type:"checkbox",checked:!!(t??e.default??!1),disabled:o,"aria-label":e.label??e.key,onChange:l=>s(l.target.checked)}),n.jsx("span",{children:e.label??e.key})]});const i=e.type==="number";return n.jsx("input",{className:"w6w-array-input",type:i?"number":"text",value:String(t??e.default??""),placeholder:r,"aria-label":e.label??e.key,readOnly:o,onChange:l=>s(i?Number(l.target.value):l.target.value)})}function Qn({param:e,value:t,onChange:s,readOnly:o}){const r=e.item??{type:"string"},i=r.type==="object",a=Array.isArray(t)?t:Array.isArray(e.default)?e.default:[],l=d=>s(e.key,d),c=()=>i?Object.fromEntries((r.fields??[]).map(d=>[d.key,d.default??""])):r.type==="number"?0:"",u=(d,f)=>l(a.map((p,h)=>h===d?f:p));return n.jsxs("div",{className:"w6w-field",children:[n.jsxs("span",{children:[e.label??e.key,e.required?" *":""]}),n.jsxs("div",{className:"w6w-array",children:[a.length===0&&n.jsx("p",{className:"w6w-muted w6w-small",children:"None yet — add one below."}),a.map((d,f)=>n.jsxs("div",{className:"w6w-array-row",children:[i?n.jsx("div",{className:"w6w-array-cells",children:(r.fields??[]).map(p=>n.jsx(rc,{field:p,value:d==null?void 0:d[p.key],readOnly:o,onChange:h=>u(f,{...d??{},[p.key]:h})},p.key))}):n.jsx("input",{className:"w6w-array-input",type:r.type==="number"?"number":"text",value:String(d??""),placeholder:r.placeholder,readOnly:o,onChange:p=>u(f,r.type==="number"?Number(p.target.value):p.target.value)}),!o&&n.jsx("button",{type:"button",className:"w6w-array-x","aria-label":"Remove item",title:"Remove",onClick:()=>l(a.filter((p,h)=>h!==f)),children:"×"})]},f)),!o&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm w6w-array-add",onClick:()=>l([...a,c()]),children:"+ Add"})]}),e.hint&&n.jsx("span",{className:"w6w-hint",children:e.hint})]})}const ic=["string","number","boolean","json"],ac=[];function fn(e,t=[]){return Array.isArray(e)?e.every(s=>s&&typeof s=="object"&&typeof s.key=="string")?e:null:!e||typeof e!="object"||ct(e)||Qe(e)||"$expr"in e?null:Object.entries(e).map(([s,o])=>{const r=t.find(a=>a.key===s),i=typeof o;return{key:s,type:r&&JSON.stringify(r.value)===JSON.stringify(o)?r.type:i==="string"||i==="number"||i==="boolean"?i:"json",value:o}})}function lc(e){const t=Array.isArray(e)?fn(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 Eo(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 Ro(e){return e==null?"":typeof e=="object"?JSON.stringify(e):String(e)}function cc({param:e,value:t,onChange:s,readOnly:o}){const r=t??e.default??ac,i=w.useMemo(()=>lc(r),[r]),[a,l]=w.useState(()=>Array.isArray(r)?"fields":"json"),c=w.useRef([]),[u,d]=w.useState(!1),[f,p]=w.useState(null),h=fn(r,c.current),b=h??[],m=a==="json"||h===null,x=e.label??e.key,g=n.jsxs("div",{className:"w6w-view-toggle w6w-datavar-modes",children:[n.jsx("button",{type:"button",className:`w6w-btn w6w-btn-sm w6w-btn-ghost${m?"":" active"}`,"aria-label":`Edit ${x} as fields`,"aria-pressed":!m,disabled:u||!!f||h===null,title:h===null?"Use a literal JSON object to edit individual fields":"Edit individual fields",onClick:()=>{!o&&!Array.isArray(r)&&s(e.key,b),l("fields")},children:"Fields"}),n.jsx("button",{type:"button",className:`w6w-btn w6w-btn-sm w6w-btn-ghost${m?" active":""}`,"aria-label":`Edit ${x} as JSON`,"aria-pressed":m,onClick:()=>{c.current=b,l("json")},children:"JSON"})]});if(m)return n.jsxs("div",{className:"w6w-datavar-json",children:[n.jsx(Es,{param:{...e,type:"json",whole:!0,default:{},hint:"Enter a JSON object or use ƒx to bind one. Switch to Fields to edit individual values."},value:i,readOnly:o,headerActions:g,onValidityChange:A=>d(!A),onChange:(A,k)=>{if(k!==void 0&&fn(k)===null&&!Qe(k)&&!ct(k)&&!(k&&typeof k=="object"&&"$expr"in k)){p("Use a JSON object, a typed key/value array, or an object binding.");return}p(null),d(!1),s(A,k)}}),f&&n.jsx("span",{className:"w6w-hint w6w-datavar-error","aria-live":"polite",children:f})]});const y=A=>s(e.key,A),N=(A,k)=>y(b.map((C,v)=>v===A?{...C,...k}:C));return n.jsxs("div",{className:"w6w-field",children:[n.jsxs("span",{className:"w6w-field-labelrow",children:[n.jsxs("span",{children:[x,e.required?" *":""]}),g]}),n.jsxs("div",{className:"w6w-stack",children:[b.length===0&&n.jsx("p",{className:"w6w-muted w6w-small",children:"No variables yet — add one below."}),b.map((A,k)=>n.jsxs("div",{className:"w6w-datavar-row",children:[n.jsx("input",{type:"text",placeholder:"key",value:A.key,readOnly:o,onChange:C=>N(k,{key:C.target.value})}),n.jsx("select",{value:A.type,disabled:o,onChange:C=>{const v=C.target.value;N(k,{type:v,value:Eo(v,Ro(A.value))})},children:ic.map(C=>n.jsx("option",{value:C,children:C},C))}),n.jsx(_e,{bare:!0,param:e,value:A.value,onChange:(C,v)=>N(k,{value:v}),readOnly:o,label:A.key||"value",req:"",children:A.type==="boolean"?n.jsxs("select",{value:A.value===!0?"true":"false",disabled:o,onChange:C=>N(k,{value:C.target.value==="true"}),children:[n.jsx("option",{value:"true",children:"true"}),n.jsx("option",{value:"false",children:"false"})]}):n.jsx("input",{type:A.type==="number"?"number":"text",placeholder:"value",value:Ro(A.value),readOnly:o,onChange:C=>N(k,{value:Eo(A.type,C.target.value)})})}),!o&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost","aria-label":`Remove variable ${A.key||k+1}`,title:"Remove",onClick:()=>y(b.filter((C,v)=>v!==k)),children:"×"})]},k)),!o&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>y([...b,{key:"",type:"string",value:""}]),children:"+ Add variable"})]}),e.hint&&n.jsx("span",{className:"w6w-hint",children:e.hint})]})}const qt=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),Rs=[["is-true","is true"],["is-false","is false"],["===","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)"]],Zt={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."},uc=new Set(Rs.map(([e])=>e)),To={...Object.fromEntries(Rs),"==":"equals","!=":"does not equal",in:"is in"};function dc(e){return e.startsWith("not:")?`Not (${To[e.slice(4)]??e.slice(4)})`:To[e]??e}const wr=[["and","All of (AND)"],["or","Any of (OR)"],["xor","Exactly one of (XOR)"]],br=Object.fromEntries(wr);function pc(e){return br[e]??e}function Ts(e,t=!0){if(!qt(e))return;const s=Object.entries(e);if(s.length!==1)return;const[o,r]=s[0];if(t&&o==="!"&&Array.isArray(r)&&r.length===1){const i=Ts(r[0],!1);return!i||i.negated?void 0:{...i,negated:!0}}if(!(!uc.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(!(o==="is-true"||o==="is-false"))return{left:r[0],operator:o,right:r[1]}}}function fc(e){if(!(!qt(e)||Object.keys(e).length!==1))return Ts(e.$expr)}function hc(e){const t=fc(e);if(t)return{combinator:"and",rows:[t]};if(!qt(e)||Object.keys(e).length!==1||!qt(e.$expr))return;const s=Object.entries(e.$expr);if(s.length!==1)return;const[o,r]=s[0];if(!Object.hasOwn(br,o)||!Array.isArray(r)||r.length===0)return;const i=r.map(a=>Ts(a));if(!i.some(a=>a===void 0))return{combinator:o,rows:i}}function Oo(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]:[s.left,s.right]};return s.negated?{"!":[o]}:o});return t.length===0?!1:{$expr:t.length===1?t[0]:{[e.combinator]:t}}}function es(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"?xn(e):We(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 Io(e){return typeof e=="string"?es(e)===e?e:JSON.stringify(e):qt(e)?Object.keys(e).length===1&&typeof e.var=="string"?ie.serializeTemplate([{kind:"var",ref:e.var}]):ie.serializeTemplate([{kind:"expr",expr:e}]):JSON.stringify(e)??""}const gr={left:"",operator:"is-true",right:!0},$o={combinator:"and",rows:[gr]},mc=(e,t)=>JSON.stringify(e)===JSON.stringify(t);function kn({values:e,onChange:t,readOnly:s,purpose:o="if"}){const r=ht(),i=e.condition===void 0?!0:e.condition,a=hc(i),[l,c]=w.useState(!1),[u,d]=w.useState(a??$o),f=w.useRef(0),[p,h]=w.useState(()=>u.rows.map(()=>f.current++)),b=a!==void 0||typeof i=="boolean",m=mc(Oo(u),i)?u:a??$o,x=m.rows.map((C,v)=>p[v]??-1-v),g=(C,v=x)=>{d(C),h(v),t({...e,condition:Oo(C)})},y=(C,v)=>g({...m,rows:m.rows.map((E,R)=>R===C?{...E,...v}:E)}),N=()=>g({...m,rows:[...m.rows,gr]},[...x,f.current++]),A=C=>g({...m,rows:m.rows.filter((v,E)=>E!==C)},x.filter((v,E)=>E!==C)),k=m.rows.length>1;return n.jsxs("div",{className:"w6w-condition-editor",children:[l||!b?n.jsx(He,{params:[{key:"condition",label:"Condition",type:"json",required:!0}],values:e,onChange:t,readOnly:s}):n.jsxs("div",{className:"w6w-condition-rows",children:[k&&n.jsx("select",{className:"w6w-condition-comparison w6w-condition-combinator","aria-label":"Combine conditions",disabled:s,value:m.combinator,onChange:C=>g({...m,combinator:C.target.value}),children:wr.map(([C,v])=>n.jsx("option",{value:C,children:v},C))}),m.rows.map((C,v)=>{const E=C.operator==="is-true"||C.operator==="is-false";return n.jsxs("div",{className:`w6w-condition-row${k?" w6w-condition-row-removable":""}${E?" 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 ${v+1}`,checked:C.negated??!1,disabled:s,onChange:R=>y(v,{negated:R.target.checked})}),"Not"]}),n.jsx(Ht,{value:Io(C.left),"aria-label":"Condition field",placeholder:"Field or expression",readOnly:s,onChange:R=>y(v,{left:es(R)})}),n.jsx("select",{className:"w6w-condition-comparison","aria-label":"Condition comparison",title:Zt[C.operator],disabled:s,value:C.operator,onChange:R=>y(v,{operator:R.target.value,right:R.target.value==="is-true"?!0:R.target.value==="is-false"?!1:E?"":C.right}),children:Rs.map(([R,F])=>n.jsx("option",{value:R,title:Zt[R],children:F},R))}),!E&&n.jsx(Ht,{value:Io(C.right),"aria-label":"Condition value",placeholder:"Value or expression",readOnly:s,onChange:R=>y(v,{right:es(R)})}),k&&!s&&n.jsx("button",{type:"button",className:"w6w-icon-btn w6w-condition-remove",title:"Remove condition","aria-label":`Remove condition ${v+1}`,onClick:()=>A(v),children:n.jsx(ue.Icon,{name:"trash",size:14})})]},x[v])}),!s&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm w6w-condition-add",onClick:N,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(m.rows.map(C=>C.operator))].map(C=>Zt[C]?n.jsx("p",{className:"w6w-muted w6w-small",children:Zt[C]},C):null)]}),b&&n.jsx("button",{type:"button",className:"w6w-icon-btn w6w-condition-mode",title:l?"Use comparison fields":"Edit condition expression","aria-label":l?"Use comparison fields":"Edit condition expression",onClick:()=>c(!l),children:n.jsx(ue.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 wc={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 yr({value:e,onChange:t,readOnly:s,target:o="step"}){const r=!!e,i=(e==null?void 0:e.maxAttempts)??3,a=(e==null?void 0:e.delayMs)??1e3,l=(e==null?void 0:e.backoff)??"fixed",c=u=>t({maxAttempts:i,delayMs:a,backoff:l,...e,...u});return n.jsxs(n.Fragment,{children:[n.jsxs("label",{className:"w6w-field",children:[n.jsxs("span",{children:[n.jsx("input",{type:"checkbox",checked:r,disabled:s,onChange:u=>t(u.target.checked?{maxAttempts:i,delayMs:a,backoff:l}:void 0)})," ","Retry on failure"]}),n.jsx("span",{className:"w6w-hint",children:wc[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:i,readOnly:s,onChange:u=>c({maxAttempts:Math.max(1,Number(u.target.value)||1)})})]}),n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"Delay (ms)"}),n.jsx("input",{type:"number",min:0,value:a,readOnly:s,onChange:u=>c({delayMs:Math.max(0,Number(u.target.value)||0)})})]}),n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"Backoff"}),n.jsxs("select",{value:l,disabled:s,onChange:u=>c({backoff:u.target.value}),children:[n.jsx("option",{value:"fixed",children:"Fixed"}),n.jsx("option",{value:"exponential",children:"Exponential"})]})]})]})]})}function Os({config:e,onChange:t,readOnly:s,hasGraph:o=!0,failureHandling:r=!0,retryControls:i=!0,reroute:a}){const l=e.onError??"fail";return n.jsxs("div",{className:"w6w-stack",children:[r&&n.jsxs(n.Fragment,{children:[i&&n.jsx(yr,{value:e.retry,onChange:c=>t({...e,retry:c}),readOnly:s}),n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"On error"}),n.jsxs("select",{value:l,disabled:s,onChange:c=>{const u=c.target.value;t({...e,onError:u==="fail"?void 0:u})},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."]})]})]}),a&&n.jsxs("div",{className:"w6w-field",children:[n.jsx("span",{children:"Reroute on failure"}),n.jsxs("div",{className:"w6w-field-row",children:[a.picker,a.value&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",disabled:s,onClick:()=>a.onChange(void 0),children:"Clear"})]}),n.jsx("span",{className:"w6w-hint",children:"Invoked once, after retry is exhausted, if this step still fails; its output becomes this step's output."})]}),n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"Notes"}),n.jsx("textarea",{rows:3,value:e.notes??"",readOnly:s,placeholder:"A short description — shown under this step on the canvas. Not executed.",onChange:c=>t({...e,notes:c.target.value||void 0})})]})]})}function Sn(e){return e.$merge!==void 0}function xr(e){const t=e.$merge;if(t===void 0)return e;if(!(Qe(t)||We(t)||Ns(t)||typeof t=="string"&&xn(t)))return t&&typeof t=="object"&&!Array.isArray(t)&&!Ze(t)&&!("$merge"in t)?{...e,...t}:null}function vr(e,t,s=[]){if(We(e)||Ze(e)||js(e)||Ns(e)||e===null||typeof e!="object")return Dt(e,t);const o=r=>vr(r,t);return Array.isArray(e)?e.map(o):Object.fromEntries(Object.entries(e).map(([r,i])=>[r,s.includes(r)?i:o(i)]))}function Is({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(He,{params:[{key:"$merge",label:"JSON customization",type:"json",required:!0,default:{},whole:!0}],values:e,onChange:t,readOnly:s}),xr(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&&Sn(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 ts(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 on({fields:e,values:t,onChange:s,enterSubmitProps:o,mode:r="create"}){const i=(a,l)=>s({...t,[a]:l});return n.jsxs("div",{className:"w6w-stack",children:[e.length===0&&n.jsx("p",{className:"w6w-muted w6w-small",children:"This auth method declares no fields — nothing to fill in. The credential will be an empty object."}),e.map(a=>{const l=r==="edit",c=t[a.key]??(l?void 0:a.default)??"";if(a.type==="boolean")return n.jsxs("label",{className:"w6w-field",children:[n.jsxs("span",{children:[n.jsx("input",{type:"checkbox",checked:!!c,onChange:f=>i(a.key,f.target.checked),...o}),a.label,a.required?" *":""]}),a.hint&&n.jsx("span",{className:"w6w-hint",children:a.hint})]},a.key);const u=a.type==="secret"||a.secret===!0;if(a.type==="json"||a.type==="text")return n.jsxs("label",{className:"w6w-field",children:[n.jsxs("span",{children:[a.label,a.required?" *":""]}),n.jsx("textarea",{className:u?"w6w-secret-input":void 0,rows:a.type==="json"?6:3,value:String(c??""),placeholder:l&&u?"•••••• (unchanged)":void 0,onChange:f=>i(a.key,f.target.value),name:`w6w-cred-${a.key}`,autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",spellCheck:!1,"data-1p-ignore":"true","data-lpignore":"true","data-bwignore":"true","data-form-type":"other"}),a.hint&&n.jsx("span",{className:"w6w-hint",children:a.hint})]},a.key);const d=a.type==="number"?"number":"text";return n.jsxs("label",{className:"w6w-field",children:[n.jsxs("span",{children:[a.label,a.required?" *":""]}),n.jsx("input",{type:d,className:u?"w6w-secret-input":void 0,value:String(c??""),placeholder:l&&u?"•••••• (unchanged)":void 0,onChange:f=>i(a.key,a.type==="number"&&!(l&&f.target.value==="")?Number(f.target.value):f.target.value),name:`w6w-cred-${a.key}`,autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",spellCheck:!1,"data-1p-ignore":"true","data-lpignore":"true","data-bwignore":"true","data-form-type":"other",...o}),a.hint&&n.jsx("span",{className:"w6w-hint",children:a.hint})]},a.key)})]})}function jr({credentials:e,mode:t,onModeChange:s,selectedId:o,onSelect:r,canUseExisting:i=!0,contract:a}){const l=c=>{const u=Object.values(c.display??{}).filter(Boolean);return u.length>0?`${c.name} (${u.join(", ")})`:c.name};return n.jsxs("div",{className:"w6w-stack",children:[i&&n.jsxs("div",{className:"w6w-field",role:"radiogroup","aria-label":"Credential",children:[n.jsxs("span",{children:["Credential",a?` (${a})`:""]}),n.jsxs("label",{children:[n.jsx("input",{type:"radio",name:"w6w-credential-mode",checked:t==="existing",onChange:()=>s("existing")})," ","Use existing"]}),n.jsxs("label",{children:[n.jsx("input",{type:"radio",name:"w6w-credential-mode",checked:t==="new",onChange:()=>s("new")})," ","Create new"]})]}),i&&t==="existing"&&n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"Stored credential"}),n.jsx("select",{name:"w6w-credential-id",value:o,onChange:c=>r(c.target.value),children:e.map(c=>n.jsx("option",{value:c.id,children:l(c)},c.id))})]})]})}function Nr(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:"Impersonated user",type:"string",required:e.impersonation==="required"},...t]}function kr(e,t){const s={},o={};for(const r of e){const i=t[r.key];i==null||i===""||(r.key==="delegatedUser"?s.delegatedUser=String(i):o[r.key]=i)}return Object.keys(o).length>0&&(s.settings=o),Object.keys(s).length>0?s:void 0}const bc="width=560,height=720,menubar=no,toolbar=no,location=no";function Sr(e){return new Promise((t,s)=>{const o=window.open(e,"w6w-oauth",bc);if(!o){s(new Error("Popup blocked — allow popups for this site and try again."));return}let r=!1;const i=()=>{r=!0,window.removeEventListener("message",a),window.clearInterval(l)},a=c=>{const u=c.data;if((u==null?void 0:u.w6w)==="oauth-result"){i();try{o.close()}catch{}u.ok&&typeof u.connectionId=="string"?t({connectionId:u.connectionId}):s(new Error(u.error??"OAuth flow failed."))}};window.addEventListener("message",a);const l=window.setInterval(()=>{r||o.closed&&(i(),s(new Error("OAuth popup was closed before the flow completed.")))},500)})}const gc=new Set(["checkbox","radio","button","submit","reset","file","range","color","image","hidden","date","datetime-local","month","week","time"]);function yc(e){return e.closest('[contenteditable]:not([contenteditable="false"])')!==null}function Cr(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"&&(yc(o)||o.tagName==="INPUT"&&gc.has(o.type)||(s.preventDefault(),e()))}}}function $s(e){const t=ye(),[s,o]=w.useState(null),[r,i]=w.useState(!!e.initialAppId);return w.useEffect(()=>{const a=e.initialAppId;if(!a)return;let l=!1;const c=f=>{l||(o(f),i(!1))},u=t.listAppsByIds;if(u)return u([a]).then(f=>c(f.find(p=>p.id===a)??null)).catch(()=>c(null)),()=>{l=!0};const d=t.listApps;return typeof d=="function"?d().then(f=>c(f.find(p=>p.id===a)??null)).catch(()=>c(null)):c(null),()=>{l=!0}},[t,e.initialAppId]),s?n.jsx(Se,{title:s.displayName,subtitle:n.jsxs(n.Fragment,{children:[n.jsx("code",{children:s.id}),s.version&&` · v${s.version}`]}),onClose:e.onClose,size:"xl",titleIcon:n.jsx(ft,{src:s.iconSvg,srcDark:s.iconSvgDark,brandColor:s.brandColor,name:s.displayName,theme:e.theme,size:22}),headerRight:e.initialAppId?void 0:n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>o(null),children:"← Apps"}),children:n.jsx(xc,{app:s,onCreated:e.onCreated,onClose:e.onClose})}):r?n.jsx(Se,{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(Se,{title:"Add connection",onClose:e.onClose,size:"xl",children:n.jsx("div",{className:"w6w-stepbuilder-content",children:n.jsx(at,{onSelectApp:o,theme:e.theme,searchPlaceholder:"Search apps to connect…",categoryFilter:!0})})})}function xc({app:e,onCreated:t,onClose:s}){var U,V;const o=ye(),[r,i]=w.useState(null),[a,l]=w.useState(""),[c,u]=w.useState(""),[d,f]=w.useState({}),[p,h]=w.useState(null),[b,m]=w.useState(!1),[x,g]=w.useState(null),[y,N]=w.useState(null),[A,k]=w.useState(""),[C,v]=w.useState(""),[E,R]=w.useState({}),F=w.useRef(null);w.useEffect(()=>{let P=!1;return i(null),o.getAppAuth(e.id).then(H=>!P&&i(H.filter(ae=>ae.available!==!1))).catch(H=>!P&&h(H.message)),()=>{P=!0}},[o,e.id]);const O=r??[],T=O.find(P=>P.key===a)??O.find(P=>P.default===!0)??O[0],I=(T==null?void 0:T.fields)??[],M=(T==null?void 0:T.type)==="oauth2",q=T==null?void 0:T.serviceAccount,D=o.listCredentials,Y=o.createCredential,$=!M&&!!q&&typeof D=="function"&&typeof Y=="function",G=((U=q==null?void 0:q.accepts)==null?void 0:U[0])??"",ne=(x??[]).filter(P=>P.contract===G&&P.status==="active"),oe=ne.length===0?"new":y??"existing",X=ne.some(P=>P.id===A)?A:((V=ne[0])==null?void 0:V.id)??"",L=$&&q?Nr(q):[];w.useEffect(()=>{if(!$||!D)return;let P=!1;return g(null),N(null),F.current=null,D.call(o,{contract:G}).then(H=>!P&&g(H)).catch(()=>!P&&g([])),()=>{P=!0}},[o,$,G,D]);const z=(T==null?void 0:T.key)==="zero-credential",Z=P=>P===void 0||P==="",W=!M&&!z&&($?x===null||L.some(P=>P.required&&Z(E[P.key]))||(oe==="existing"?X==="":C.trim()===""||I.some(P=>P.required&&Z(d[P.key]))):I.some(P=>P.required&&Z(d[P.key]))),J=!T||!M&&!z&&W||b;async function te(){if(T){h(null),m(!0);try{if(z)t({connectionId:`zerocred:${e.id}`});else if(M){const{authorizationUrl:P}=await o.startAppOAuthFlow(e.id,T.key,{displayName:c||void 0}),{connectionId:H}=await Sr(P);t({connectionId:H})}else if($&&Y){let P=oe==="existing"?X:F.current;if(P===null){const he=ts(I,d);if("error"in he){h(he.error);return}const ge=await Y.call(o,{name:C.trim(),contract:G,source:he.values});F.current=ge.id,P=ge.id}const H=kr(L,E),ae={authKey:T.key,credentialId:P,...H?{binding:H}:{},...c?{displayName:c}:{}},fe=await o.createConnection(e.id,ae);t({connectionId:fe.id})}else{const P=ts(I,d);if("error"in P){h(P.error);return}const H=await o.createConnection(e.id,{authKey:T.key,credential:P.values,displayName:c||void 0});t({connectionId:H.id})}}catch(P){h(P.message)}finally{m(!1)}}}const S=Cr(te,{enabled:!J});return n.jsxs("div",{className:"w6w-stepconfig",children:[n.jsx("div",{className:"w6w-modal-body",children:n.jsxs("div",{className:"w6w-stack",children:[r===null&&n.jsx("p",{className:"w6w-muted w6w-small",children:"Loading auth methods…"}),r!==null&&O.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."}),O.length>1&&n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"Auth method"}),n.jsx("select",{value:(T==null?void 0:T.key)??"",onChange:P=>{l(P.target.value),f({}),R({}),F.current=null,h(null)},children:O.map(P=>n.jsxs("option",{value:P.key,children:[P.displayName??P.key," (",P.type,")"]},P.key))})]}),T&&n.jsxs(n.Fragment,{children:[!z&&n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"Display name"}),n.jsx("input",{type:"text",value:c,onChange:P=>u(P.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",...S})]}),T.description&&n.jsx("p",{className:"w6w-muted w6w-small",children:T.description}),z?null:M?n.jsxs("p",{className:"w6w-muted w6w-small",children:["You'll be redirected to ",n.jsx("strong",{children:T.displayName??T.key})," to authorize this connection."]}):$&&q?n.jsxs(n.Fragment,{children:[n.jsx(jr,{credentials:ne,mode:oe,onModeChange:P=>{N(P),F.current=null},selectedId:X,onSelect:k,canUseExisting:ne.length>0,contract:G}),q.scopes.length>0&&n.jsxs("p",{className:"w6w-muted w6w-small",children:["Scopes: ",n.jsx("code",{children:q.scopes.join(" ")})]}),L.length>0&&n.jsx(on,{fields:L,values:E,onChange:R,enterSubmitProps:S}),oe==="new"&&n.jsxs(n.Fragment,{children:[n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"Credential name *"}),n.jsx("input",{type:"text",value:C,onChange:P=>v(P.target.value),placeholder:"e.g. Workspace automation",maxLength:80,name:"w6w-credential-name",autoComplete:"off","data-1p-ignore":"true","data-lpignore":"true","data-bwignore":"true","data-form-type":"other",...S})]}),n.jsx(on,{fields:I,values:d,onChange:f,enterSubmitProps:S})]})]}):n.jsx(on,{fields:I,values:d,onChange:f,enterSubmitProps:S})]}),p&&n.jsx("div",{className:"w6w-result w6w-error",children:p})]})}),n.jsxs("div",{className:"w6w-modal-actions",children:[n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:s,children:"Cancel"}),n.jsx("button",{type:"button",className:"w6w-btn",disabled:J,onClick:te,children:b?z?"Saving…":M?"Waiting for authorization…":"Saving…":z?"Use this":M?`Sign in with ${(T==null?void 0:T.displayName)??(T==null?void 0:T.key)??"provider"}`:"Save connection"})]})]})}function Ar(e){const{label:t,onClick:s,disabled:o,className:r,...i}=e;return n.jsx(vn,{label:t,onClick:s,disabled:o,className:r,danger:!0,icon:"delete","data-testid":i["data-testid"]})}function Er({values:e,onChange:t,readOnly:s}){const o=Array.isArray(e.routes)?e.routes:dn(qe,"route").routes,r=o.filter(g=>!g.default),[i,a]=w.useState(null),[l,c]=w.useState(null),[u,d]=w.useState(null),[f,p]=w.useState(""),h=g=>t({...e,routes:[...g,...o.filter(y=>y.default)]}),b=(g,y)=>h(r.map(N=>N.id===g?{...N,...y}:N)),m=(g,y)=>{const N=r.findIndex(C=>C.id===g);if(N<0||y<0||y>=r.length||N===y)return;const A=[...r],[k]=A.splice(N,1);A.splice(y,0,k),h(A)},x=g=>{f.trim()&&b(g.id,{label:f.trim()}),d(null)};return n.jsxs("div",{className:"w6w-router-editor",children:[n.jsx("p",{className:"w6w-muted w6w-small",children:"First match wins. Drag routes to change their order."}),n.jsx("div",{className:"w6w-router-routes",children:r.map((g,y)=>n.jsxs("div",{className:`w6w-router-route${i===g.id?" is-dragging":""}${l===g.id?" is-drop-target":""}`,"data-route-id":g.id,onDragOver:N=>{s||!i||i===g.id||(N.preventDefault(),N.dataTransfer.dropEffect="move",c(g.id))},onDrop:N=>{N.preventDefault(),!s&&i&&m(i,y),a(null),c(null)},children:[n.jsxs("div",{className:"w6w-router-route-heading",children:[n.jsx("button",{type:"button",className:"w6w-icon-btn w6w-router-grip",draggable:!s,disabled:s,"aria-label":`Reorder ${g.label||g.id}`,title:"Drag to reorder · arrow keys to move",onDragStart:N=>{N.dataTransfer.effectAllowed="move",N.dataTransfer.setData("text/plain",g.id);const A=N.currentTarget.closest(".w6w-router-route");A&&N.dataTransfer.setDragImage(A,16,16),a(g.id)},onDragEnd:()=>{a(null),c(null)},onKeyDown:N=>{N.key!=="ArrowUp"&&N.key!=="ArrowDown"||(N.preventDefault(),m(g.id,y+(N.key==="ArrowUp"?-1:1)))},children:n.jsx(ue.Icon,{name:"grip",size:14})}),n.jsx("span",{className:"w6w-step-rename",children:u===g.id&&!s?n.jsx("input",{autoFocus:!0,"aria-label":"Route name",value:f,onChange:N=>p(N.target.value),onBlur:()=>x(g),onKeyDown:N=>{N.key==="Enter"&&x(g),N.key==="Escape"&&d(null)}}):n.jsxs("button",{type:"button",className:"w6w-router-route-name",disabled:s,"aria-label":`Rename ${g.label||g.id}`,onClick:()=>{p(g.label||g.id),d(g.id)},children:[g.label||g.id,!s&&n.jsx(ue.Icon,{name:"edit",size:12})]})}),n.jsx(Ar,{label:`Remove ${g.label||g.id}`,disabled:s,onClick:()=>h(r.filter(N=>N.id!==g.id))})]}),n.jsx(kn,{values:{condition:g.condition??!1},onChange:N=>b(g.id,{condition:N.condition}),readOnly:s,purpose:"router"})]},g.id))}),n.jsxs("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm w6w-router-add",disabled:s,onClick:()=>{let g=1;for(;o.some(y=>y.id===`route_${g}`);)g++;h([...r,{id:`route_${g}`,label:`Route ${g}`,condition:!1}])},children:[n.jsx("span",{"aria-hidden":"true",children:"+"})," Add route"]})]})}function Rr({value:e,onCommit:t,readOnly:s}){const[o,r]=w.useState(!1),[i,a]=w.useState(e),[l,c]=w.useState(null),u=()=>{const d=i.trim(),f=d&&d!==e?t(d):null;if(f){c(f);return}c(null),r(!1)};return n.jsxs("span",{className:"w6w-step-rename",children:[o&&!s?n.jsx("input",{autoFocus:!0,"aria-label":"Node name",value:i,onChange:d=>{a(d.target.value),c(null)},onBlur:u,onKeyDown:d=>{d.key==="Enter"&&u(),d.key==="Escape"&&(a(e),c(null),r(!1))}}):n.jsxs(n.Fragment,{children:[n.jsx("code",{children:e}),!s&&n.jsx("button",{type:"button",className:"w6w-icon-btn w6w-btn-sm",title:"Rename node","aria-label":"Rename node",onClick:()=>{a(e),r(!0)},children:n.jsx(ue.Icon,{name:"edit",size:15})})]}),l&&n.jsx("span",{className:"w6w-hint",role:"alert",style:{color:"var(--w6w-danger)"},children:l})]})}function Tr({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 i=r.target.value==="condition";t({...e,condition:!i})},children:[n.jsx("option",{value:"always",children:"Always"}),n.jsx("option",{value:"condition",children:"A condition matches"})]})]}),o?n.jsx(kn,{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 Or="default-src 'none'; style-src 'unsafe-inline'; img-src data:; base-uri 'none'; form-action 'none'";function Ir(e){return`<!doctype html><meta http-equiv="Content-Security-Policy" content="${Or}">${e}`}function $r({html:e}){return n.jsx("iframe",{title:"HTML preview",className:"w6w-html-preview",sandbox:"",referrerPolicy:"no-referrer",srcDoc:Ir(e)})}function Pr(e){return typeof e=="string"?"string":typeof e=="number"?"number":typeof e=="boolean"?"boolean":"null"}function vc(e){return Pr(e)==="string"?JSON.stringify(e):String(e)}function jc(e){return typeof e=="object"&&e!==null}function Nc(e,t){return`${t} ${e?"item":"key"}${t===1?"":"s"}`}function kc({value:e,expandDepth:t=2}){return n.jsx(_r,{label:void 0,value:e,depth:0,expandDepth:t})}function _r(e){const{label:t,value:s,depth:o,expandDepth:r}=e,i=jc(s),a=Array.isArray(s),l=i?a?s.map((u,d)=>[d,u]):Object.entries(s):[],c=t===void 0?null:n.jsx("span",{className:"w6w-json-key",children:t});return i&&l.length>0?n.jsxs("details",{className:"w6w-json-node",open:o<r,children:[n.jsxs("summary",{children:[c,a?"[…]":"{…}"," ",n.jsx("span",{className:"w6w-json-count",children:Nc(a,l.length)})]}),n.jsx("div",{className:"w6w-json-children",children:l.map(([u,d])=>n.jsx(_r,{label:u,value:d,depth:o+1,expandDepth:r},String(u)))})]}):n.jsxs("div",{className:"w6w-json-leaf",children:[c,c===null?null:": ",n.jsx("span",{className:`w6w-json-${i?"null":Pr(s)}`,children:i?a?"[]":"{}":vc(s)})]})}const Lr=262144,Sc=/^#{1,6}\s+\S/,Cc=/^```/,Ac=/^\s*(?:[-*+]|\d+\.)\s+\S/,Ec=/\[[^\]\n]+\]\(https?:\/\/[^)\s]+\)/;function Fr(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(`
|
|
19
|
+
`);return s.some(o=>Sc.test(o)||Cc.test(o))||s.filter(o=>Ac.test(o)).length>=2||Ec.test(t)?{format:"markdown",text:e}:{format:"text",text:e}}function Mr(e){return e.format==="json"?JSON.stringify(e.data,null,2)??"":e.text}const Rc=65536;function Dn(e,t){return e.length>Rc?n.jsx("pre",{className:"w6w-result-viewer-text",children:e}):n.jsx(ue.CodeBlock,{code:e,language:t,copyable:!1,wrap:!0})}function Re(e){const{value:t,format:s="auto",maxHeight:o=320,className:r}=e,i=w.useMemo(()=>s==="json"?{format:"json",data:t}:Fr(t),[t,s]),[a,l]=w.useState("rendered"),[c,u]=w.useState(2),[d,f]=w.useState(0),p=i.format==="json"?"":i.text,h=i.format==="html"||i.format==="markdown",b=h&&p.length>Lr,m=w.useMemo(()=>{try{return Mr(i)}catch{return typeof t=="string"?t:String(t)}},[i,t]);let x;if(i.format==="json")x=n.jsx(kc,{value:i.data,expandDepth:c},d);else if(i.format==="xml")x=Dn(i.text,"markup");else if(i.format==="text")x=n.jsx("pre",{className:"w6w-result-viewer-text",children:i.text});else{const y=i.format==="html"?"markup":"markdown";b?x=n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"w6w-muted w6w-small w6w-result-viewer-note",children:"Too large to render — showing source."}),Dn(i.text,y)]}):a==="source"?x=Dn(i.text,y):i.format==="html"?x=n.jsx($r,{html:i.text}):x=n.jsx(gs,{content:i.text})}let g=null;return i.format==="json"?g=n.jsxs("div",{className:"w6w-result-viewer-bar",children:[n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>{u(Number.POSITIVE_INFINITY),f(y=>y+1)},children:"Expand all"}),n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>{u(1),f(y=>y+1)},children:"Collapse all"})]}):h&&!b&&(g=n.jsxs("div",{className:"w6w-result-viewer-bar",children:[n.jsx("button",{type:"button",className:`w6w-btn w6w-btn-ghost${a==="rendered"?" active":""}`,"data-mode":"rendered","aria-pressed":a==="rendered",onClick:()=>l("rendered"),children:"Rendered"}),n.jsx("button",{type:"button",className:`w6w-btn w6w-btn-ghost${a==="source"?" active":""}`,"data-mode":"source","aria-pressed":a==="source",onClick:()=>l("source"),children:"Source"})]})),n.jsxs("div",{className:["w6w-result-viewer",r??""].filter(Boolean).join(" "),"data-format":i.format,children:[g,n.jsx(ue.Copyable,{value:m,label:"Copy result",className:"w6w-copyable--hover",children:n.jsx("div",{className:"w6w-result-viewer-body",style:{maxHeight:o,overflow:"auto"},children:x})})]})}function Dr(e,t){const s=e.filter(o=>o.appId===Le);return s.find(o=>o.nodeId===t)??s.find(o=>!o.nodeId)??s[0]??null}const Tc=/auth|token|secret|passw|cookie|api[-_]?key|signature|session/i,Oc="••••••";function Ic(e){const t={};for(const[s,o]of Object.entries(e))t[s]=Tc.test(s)?Oc:o;return t}const $c=20;function Pc({workflowId:e,stepId:t,stepWith:s,readOnly:o,onUse:r,using:i}){const a=ye(),[l,c]=w.useState(void 0),[u,d]=w.useState(!1),[f,p]=w.useState({phase:"idle"}),[h,b]=w.useState(()=>Date.now()),m=w.useRef(null);w.useEffect(()=>{const C=a.listSubscriptionsForWorkflow;if(!C)return;let v=!1;return C(e).then(E=>!v&&c(Dr(E,t))).catch(E=>!v&&p({phase:"error",message:E.message})),()=>{v=!0}},[a,e,t]);const x=w.useCallback(C=>{var E;const v=m.current;m.current=null,v&&(v.abort.abort(),C&&((E=a.stopWebhookListen)==null||E.call(a,v.subId,v.sessionId).catch(()=>{})))},[a]);w.useEffect(()=>()=>x(!0),[x]),w.useEffect(()=>{if(f.phase!=="waiting")return;const C=setInterval(()=>b(Date.now()),1e3);return()=>clearInterval(C)},[f.phase]);const g=()=>{const C=a.createSubscription;C&&(d(!0),C(Le,"webhook",{workflowId:e,connectionId:null,params:s??{}}).then(v=>c(v)).catch(v=>p({phase:"error",message:v.message})).finally(()=>d(!1)))},y=async()=>{var O;const C=a.startWebhookListen,v=a.pollWebhookListen;if(!l||!C||!v)return;x(!0),p({phase:"starting"});let E;try{E=(await C(l.id)).session}catch(T){p({phase:"error",message:T.message});return}const R=new AbortController,F={subId:l.id,sessionId:E.id,abort:R};for(m.current=F,b(Date.now()),p({phase:"waiting",session:E});;){let T;try{T=await v(l.id,E.id,{waitSeconds:$c,signal:R.signal})}catch(I){if(m.current!==F)return;m.current=null,p({phase:"error",message:I.message});return}if(m.current!==F)return;if(T.status==="captured"&&T.request){m.current=null,p({phase:"captured",session:T,request:T.request});return}if(T.status==="expired"){m.current=null,(O=a.stopWebhookListen)==null||O.call(a,l.id,E.id).catch(()=>{}),p({phase:"expired"});return}}},N=()=>{x(!0),p({phase:"idle"})};if(!a.startWebhookListen||!a.pollWebhookListen)return null;const A=l==null?void 0:l.webhookUrl,k=f.phase==="waiting"?Math.max(0,Math.ceil((Date.parse(f.session.expiresAt)-h)/1e3)):0;return n.jsxs("div",{className:"w6w-stack w6w-listen","data-testid":"webhook-listen",children:[l===void 0?n.jsx("p",{className:"w6w-muted w6w-small",children:"Loading…"}):A?n.jsxs(n.Fragment,{children:[n.jsx(ue.Copyable,{value:A,readOnly:!0,children:n.jsx("input",{type:"text",readOnly:!0,value:A,"aria-label":"Webhook URL"})}),f.phase==="waiting"||f.phase==="starting"?n.jsxs("div",{className:"w6w-listen-waiting",children:[n.jsx("span",{className:"w6w-listen-pulse","aria-hidden":"true"}),n.jsxs("output",{className:"w6w-small",children:["Waiting for a request to ",n.jsx("code",{children:A}),"…",f.phase==="waiting"&&n.jsxs("span",{className:"w6w-muted",children:[" ",_c(k)," left"]})]}),n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:N,children:"Stop"})]}):n.jsxs("div",{className:"w6w-steptest-bar",children:[n.jsx("button",{type:"button",className:"w6w-btn",disabled:o,onClick:()=>void y(),children:f.phase==="captured"?"Listen again":"Listen for test event"}),f.phase==="idle"&&n.jsx("span",{className:"w6w-muted w6w-small",children:"Send a request to this URL — it works before you publish, and starts no run."})]})]}):n.jsxs("div",{className:"w6w-stack",children:[n.jsx("p",{className:"w6w-muted w6w-small",children:"This webhook has no URL yet. Create one, then listen for a test request."}),!o&&a.createSubscription&&n.jsx("button",{type:"button",className:"w6w-btn",disabled:u,onClick:g,children:u?"Creating…":"Create webhook URL"})]}),f.phase==="expired"&&n.jsx("p",{className:"w6w-muted w6w-small",children:"No request arrived in time. Listen again, then send the request."}),f.phase==="error"&&n.jsx("div",{className:"w6w-result w6w-error",children:f.message}),f.phase==="captured"&&n.jsx(Lc,{request:f.request,receivedAt:f.session.receivedAt,readOnly:o,using:i,onUse:()=>r(f.request),stepId:t})]})}function _c(e){const t=Math.floor(e/60);return t>0?`${t}:${String(e%60).padStart(2,"0")}`:`${e}s`}function Lc({request:e,receivedAt:t,readOnly:s,using:o,onUse:r,stepId:i}){const a=Object.keys(e.query??{}).length>0;return n.jsxs("div",{className:"w6w-testout w6w-listen-captured","data-testid":"webhook-captured",children:[n.jsxs("div",{className:"w6w-testout-label",children:["Request received",t&&n.jsxs("span",{className:"w6w-muted",children:[" · ",new Date(t).toLocaleTimeString()]})]}),n.jsxs("div",{className:"w6w-small",children:[n.jsx("code",{children:e.method})," ",n.jsx("code",{children:e.path})]}),a&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"w6w-testout-label",children:"Query"}),n.jsx(Re,{value:e.query,maxHeight:120})]}),n.jsx("div",{className:"w6w-testout-label",children:"Headers"}),n.jsx(Re,{value:Ic(e.headers??{}),maxHeight:160}),n.jsx("div",{className:"w6w-testout-label",children:"Body"}),n.jsx(Re,{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.${i}.output.body… }}`}),"."]})]})]})}function Ps(e){return Array.isArray(e)?e:[]}function Hr(e){return e==="object"||e==="array"?"json":e==="number"||e==="boolean"||e==="json"?e:"string"}function Br(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 _s(e){return e.filter(t=>typeof t.key=="string"&&t.key.trim()!=="").map(t=>({key:t.key,label:t.key,type:Hr(t.type),required:!!t.required}))}function ns(e){const t={};for(const s of e){if(typeof s.key!="string"||s.key.trim()==="")continue;const o=Br(s.type,s.default);o!==void 0&&(t[s.key]=o)}return t}function qr(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 Fc(e){return We(e)||typeof e=="string"&&e.includes("{{")}function Ls(e,t=[]){const s=new Set(t.filter(r=>r.type==="secret").map(r=>r.key)),o={};for(const[r,i]of Object.entries(e))i===void 0||Ze(i)||s.has(r)&&!Fc(i)||(o[r]=i);return o}const ss=new Set;function Wr(e){const t=e.then(()=>{},()=>{});return ss.add(t),t.then(()=>ss.delete(t)),e}async function Ur(){await Promise.all([...ss])}function Vr(e,t){const s=ye(),o=typeof s.loadTestInputs=="function"&&!!e&&!!t,[r,i]=w.useState(!o),[a,l]=w.useState(void 0);w.useEffect(()=>{if(!o||!e||!t||!s.loadTestInputs){i(!0);return}let f=!1;return i(!1),Ur().then(()=>{var p;return((p=s.loadTestInputs)==null?void 0:p.call(s,e))??[]}).then(p=>{f||(l(qr(p,t)),i(!0))}).catch(()=>{f||i(!0)}),()=>{f=!0}},[s,o,e,t]);const c=w.useCallback(f=>{l(f),!(!e||!t||typeof s.saveTestInput!="function")&&Wr(s.saveTestInput(e,t,f)).catch(p=>{console.error("test input save failed",p)})},[s,e,t]),u=w.useCallback((f,p)=>c(Ls(f,p)),[c]),d=w.useCallback(()=>c({}),[c]);return{loaded:r,supported:o,input:a,save:u,clear:d}}function zr({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 Mc=600;function Jr({app:e,action:t,fields:s,persist:o,listen:r}){const i=ye(),a=bs(),l=w.useMemo(()=>Ps(s),[s]),c=w.useMemo(()=>_s(l),[l]),u=c.length>0,[d,f]=w.useState(()=>ns(l)),[p,h]=w.useState(null),b=o==null?void 0:o.workflowId,m=o==null?void 0:o.stepId,x=Vr(b,m),[g,y]=w.useState(!1),[N,A]=w.useState(!1),[k,C]=w.useState(!b||!m);w.useEffect(()=>{if(!b||!m){C(!0);return}if(!x.loaded)return;if(x.input!==void 0){const z=x.input;Object.keys(z).length>0&&(f(Z=>({...Z,...z})),y(!0),A(!0)),C(!0);return}let L=!1;return i.listStepTests(b,m).then(z=>{if(L)return;const Z=z.length?z[z.length-1]:null;Z!=null&&Z.with&&(f(W=>({...W,...Z.with})),Object.keys(Z.with).length>0&&A(!0)),C(!0)}).catch(()=>{L||C(!0)}),()=>{L=!0}},[i,b,m,x.loaded]);const[v,E]=w.useState(0),R=()=>{clearTimeout(O.current),F.current=null,x.clear(),y(!1),f(ns(l)),E(L=>L+1)},F=w.useRef(null),O=w.useRef(void 0),T=w.useRef(()=>{});T.current=()=>{clearTimeout(O.current);const L=F.current;F.current=null,L&&x.save(L,c)},w.useEffect(()=>()=>T.current(),[]);const I=L=>{f(L),!(!b||!m||!k)&&(F.current=L,clearTimeout(O.current),O.current=setTimeout(()=>T.current(),Mc))},[M,q]=w.useState(!0),D=M&&jt(c,d),Y=async L=>{const z=L??d;clearTimeout(O.current),F.current=null,o&&x.save(z,c),h({status:"running"});let Z;try{const W=await i.invokeAction(e,t,{input:z},{project:a});Z={status:"done",value:W.value,logs:W.logs}}catch(W){const J=W;Z={status:"error",error:J.message??String(W),errorCode:J.code,logs:J.logs}}if(h(Z),o)try{const W=await i.saveStepTest(o.workflowId,o.stepId,{input:o.input,with:z});await i.recordStepTestRun(o.workflowId,o.stepId,{stepTestId:W.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(W){console.error("step test persist failed",W)}},$=p&&p.status!=="running"?p.logs:void 0,G=L=>{const z={...L};f(z),Y(z)},ne=r&&o&&n.jsx(Pc,{workflowId:o.workflowId,stepId:o.stepId,stepWith:r.stepWith,readOnly:r.readOnly,onUse:G,using:(p==null?void 0:p.status)==="running"});return n.jsxs("div",{className:"w6w-stack",children:[ne,ne?n.jsxs("details",{className:"w6w-listen-manual","data-testid":"trigger-sample-payload",open:N,onToggle:L=>A(L.currentTarget.open),children:[n.jsx("summary",{className:"w6w-small",children:"Or test with a sample payload"}),oe()]}):oe(),X()]});function oe(){return n.jsxs("div",{className:"w6w-stack",children:[k?n.jsxs(n.Fragment,{children:[g&&n.jsx(zr,{onClear:R}),n.jsx(Ri,{params:c,values:d,onChange:I,onValidityChange:q},v),!u&&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:!k||!D||(p==null?void 0:p.status)==="running",onClick:()=>void Y(),children:(p==null?void 0:p.status)==="running"?"Running…":"▶ Test run"}),k&&!D&&n.jsx("span",{className:"w6w-muted w6w-small",children:M?"Fill the required fields to test.":"The payload must be a JSON object to test."})]})})]})}function X(){return n.jsxs("div",{className:"w6w-steptest",children:[(p==null?void 0:p.status)==="error"&&n.jsxs("div",{className:"w6w-result w6w-error",children:[p.errorCode&&n.jsx("div",{className:"w6w-small",style:{opacity:.75,marginBottom:4},children:n.jsx("code",{children:p.errorCode})}),p.error]}),(p==null?void 0:p.status)==="done"&&n.jsxs("div",{className:"w6w-testout",children:[n.jsx("div",{className:"w6w-testout-label",children:"Output state (filled values)"}),n.jsx(Re,{value:p.value,maxHeight:220})]}),$&&$.length>0&&n.jsxs("div",{className:"w6w-testout",children:[n.jsx("div",{className:"w6w-testout-label",children:"Console output"}),n.jsx("pre",{className:"w6w-result w6w-testout-console",style:{whiteSpace:"pre-wrap",maxHeight:160,overflow:"auto",margin:0},children:$.join(`
|
|
20
|
+
`)})]})]})}}const Dc=[["s","Seconds"],["m","Minutes"],["h","Hours"],["d","Days"],["w","Weeks"]],Hc=/^(?=\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 Kr({values:e,onChange:t,readOnly:s}){const o=e.duration??"1s",r=typeof o=="string"?o.match(/^(\d+(?:\.\d+)?)([smhdw])$/i):null,[i,a]=w.useState("s"),[l,c]=w.useState("text"),[u,d]=w.useState(e.until?"until":"duration"),f=typeof o=="string"&&(!Hc.test(o.trim())||/^P$/i.test(o.trim()));return n.jsxs("div",{className:"w6w-params-form",children:[n.jsxs("label",{children:["Wait for",n.jsxs("select",{"aria-label":"Wait for",disabled:s,value:u,onChange:p=>{const h=p.target.value;d(h),t({...e,duration:h==="duration"?"1s":"",until:""})},children:[n.jsx("option",{value:"duration",children:"A duration"}),n.jsx("option",{value:"until",children:"Until a timestamp"})]})]}),u==="until"?n.jsx(He,{params:[{key:"until",label:"Until",type:"string",hint:"ISO-8601 timestamp, e.g. 2026-10-08T09:00:00Z."}],values:e,onChange:t,readOnly:s}):n.jsxs(n.Fragment,{children:[n.jsxs("label",{children:["Duration input",n.jsxs("select",{"aria-label":"Duration input",disabled:s,value:l,onChange:p=>{r&&a((r==null?void 0:r[2].toLowerCase())??i),c(p.target.value)},children:[n.jsx("option",{value:"text",children:"Shorthand"}),n.jsx("option",{value:"value",disabled:!r,children:"Value and unit"})]})]}),l==="value"?n.jsxs("div",{className:"w6w-field-row",children:[n.jsxs("label",{children:["Value",n.jsx("input",{"aria-label":"Duration value",type:"number",min:"0",step:((r==null?void 0:r[2].toLowerCase())??i)==="s"?"any":"1",disabled:s,value:(r==null?void 0:r[1])??"",onChange:p=>t({...e,duration:`${p.target.value}${(r==null?void 0:r[2].toLowerCase())??i}`})})]}),n.jsxs("label",{children:["Unit",n.jsx("select",{"aria-label":"Duration unit",disabled:s,value:(r==null?void 0:r[2].toLowerCase())??i,onChange:p=>{a(p.target.value),t({...e,duration:`${(r==null?void 0:r[1])??""}${p.target.value}`})},children:Dc.map(([p,h])=>n.jsx("option",{value:p,children:h},p))})]})]}):n.jsx(He,{params:[{key:"duration",label:"Duration",type:"string",default:"1s",hint:"Use 30s, 1h30m30s, or 3d30s. Units: w, d, h, m, s, in that order. Uppercase and ISO-8601 also work. Value and unit is available for single-unit durations."}],values:e,onChange:t,readOnly:s}),f&&n.jsx("p",{role:"alert",children:"Enter a duration such as 30s or 1h30m30s, using units w, d, h, m, s in order."})]})]})}function Gr({anchorRef:e,onClose:t,children:s}){const o=w.useRef(null),[r,i]=w.useState(null),[a,l]=w.useState(null);return w.useEffect(()=>{const c=e.current;if(!c)return;const u=c.getBoundingClientRect();i({top:u.bottom+6,left:u.left,width:u.width}),l(c.closest("dialog")??document.body)},[e]),w.useEffect(()=>{function c(d){var p,h;const f=d.target;(p=o.current)!=null&&p.contains(f)||(h=e.current)!=null&&h.contains(f)||t()}function u(d){d.key==="Escape"&&t()}return document.addEventListener("mousedown",c),document.addEventListener("keydown",u),()=>{document.removeEventListener("mousedown",c),document.removeEventListener("keydown",u)}},[t,e]),!r||!a?null:cn.createPortal(n.jsx("div",{ref:o,className:"w6w-flyout",style:{top:r.top,left:r.left,width:r.width},children:s}),a)}function Yr(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)&&Yr(e[r],t[r]))}function Bc(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:i,...a}=s.data;return{...s,data:a}}return r&&Yr(r,o)?s:{...s,data:{...s.data,stepProblems:structuredClone(o)}}})}const qc={body_not_literal:"This loop's body is not a list of step ids",body_unknown_step:"This loop's body names a step that doesn't exist",body_self:"This loop's body contains the For each itself",body_duplicate:"This loop's body lists a step twice",body_claimed_twice:"A step in this loop's body is also owned by another control step",body_contains_control:"This loop's body contains a control step (If, For each, Parallel…)",body_step_has_edges:"A step in this loop's body also has its own connections",legacy_not_linear:"The steps after this For each aren't one straight line, so they can't be read as its loop body"};function Wc(e){switch(e.code){case"unknown_connection":return`Connection ${e.connection} no longer exists — open the step and choose another on the Setup tab`;case"foreach_wrapped_items":return"Items wraps a list in another list — this loops once";case"foreach_body_refs_output":return`Refers to the For each's output (${e.refs.join(", ")}) from inside its loop — use Current item instead`;case"loop_body_invalid":{const t=qc[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 Uc(e,t){return(t==null?void 0:t.some(s=>s.code==="unknown_connection"&&e.uses.connection===s.connection))??!1}function Vc(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 St(e,t){const{connectionRef:s,connection:o,app:r}=e.uses;if(s===void 0)return o??void 0;const i=t&&Object.hasOwn(t,s)?t[s]:void 0;return(i==null?void 0:i.app)===r?i.connection??void 0:void 0}function Xr(e,t){let s=e;for(let o=2;Object.hasOwn(t,s);o++)s=`${e}_${o}`;return s}function Zr(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 i=Object.hasOwn(t,r.id)?t[r.id]:void 0,a=(i==null?void 0:i.app)===r.uses.app&&i.connection===r.uses.connection?r.id:Xr(r.id,t);return t={...t,[a]:{app:r.uses.app,connection:r.uses.connection}},s=!0,Fs(r,a)});return s?{...e,nodes:o,connections:t}:e}function zc(e){if(!e.connections)return e;const t=new Set(e.nodes.map(r=>r.uses.connectionRef)),s=Object.entries(e.connections),o=s.filter(([r])=>t.has(r));return o.length===s.length?e:{...e,connections:Object.fromEntries(o)}}function Fs(e,t){const{connection:s,...o}=e.uses;return{...e,uses:{...o,connectionRef:t}}}function Jc(e,t,s,o){if(!t){const{connection:l,connectionRef:c,...u}=e.uses;return{step:{...e,uses:u},connections:o}}const r=e.uses.connectionRef,i=r&&s.some(l=>l.id!==e.id&&l.uses.connectionRef===r),a=r&&!i?r:Xr(e.id,o);return{step:Fs(e,a),connections:{...o,[a]:{app:e.uses.app,connection:t}}}}function rn(e,t,s,o){return t?s.filter(r=>r.uses.app===e&&St(r,o)===t):[]}function Qr(e,t,s,o,r){if(r)return{connection:r};for(const l of[...s].reverse()){if(l.id===e.id||l.uses.app!==e.uses.app)continue;const c=St(l,o);if(!(!c||!t.some(u=>u.id===c&&u.appId===e.uses.app)))return l.uses.connectionRef?{connectionRef:l.uses.connectionRef}:{connection:c}}const i=t.filter(l=>l.appId===e.uses.app),a=i.find(l=>l.builtIn)??i[0];return a?{connection:a.id}:{}}function Po(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 Kc(e,t,s,o,r){const i=new Set(rn(e,t,o,r).map(a=>a.uses.connectionRef));return Object.fromEntries(Object.entries(r).map(([a,l])=>[a,i.has(a)?{...l,connection:s}:l]))}const ei=w.createContext(null);function Ms(){return w.useContext(ei)}function ti({step:e,conns:t,failed:s=!1,readOnly:o,open:r,onOpenChange:i,anchorRef:a,onChangeConnection:l,onChangeConnectionRef:c,onConnectionCreated:u}){var E,R,F;const d=Ms(),f=o||(d==null?void 0:d.readOnly),p=(d==null?void 0:d.connections)??{},h=(d==null?void 0:d.nodes)??[],b=(t??[]).map(O=>({conn:O,users:rn(e.uses.app,O.id,h,p)})).sort((O,T)=>+(T.users.length>0)-+(O.users.length>0)),m=St(e,p)??(e.uses.connectionRef===void 0?(E=t==null?void 0:t.find(O=>O.builtIn&&O.appId===e.uses.app))==null?void 0:E.id:void 0),x=rn(e.uses.app,m,h,p).filter(O=>O.id!==e.id),[g,y]=w.useState(null),[N,A]=w.useState(!1),k=g||N?((F=(R=a.current)==null?void 0:R.closest("dialog"))==null?void 0:F.parentElement)??document.body:null,C=(O,T)=>{if(!f){if(T&&d&&m){d.setConnections(Kc(e.uses.app,m,O,h,p));const I=h.find(M=>M.id===e.id)??e;I.uses.connectionRef?c(I.uses.connectionRef):l(O)}else{const I=rn(e.uses.app,O,h,p).filter(M=>M.id!==e.id&&M.uses.connectionRef).at(-1);I!=null&&I.uses.connectionRef?c(I.uses.connectionRef):l(O)}y(null),i(!1)}},v=O=>{f||(i(!1),O!==m&&(x.length>0&&h.some(T=>T.id===e.id)?y(O):C(O,!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:()=>i(!r),children:n.jsx("span",{className:"w6w-conn-label-name",children:t===null&&!s&&!m?"Loading connections…":Vc(m,t,s)})}),r&&n.jsx(Gr,{anchorRef:a,onClose:()=>i(!1),children:n.jsxs("div",{className:"w6w-stack",children:[s&&n.jsx("p",{role:"alert",className:"w6w-field-error",children:"Couldn’t load connections."}),n.jsx("div",{className:"w6w-stepbuilder-list",children:b.map(({conn:O,users:T})=>n.jsx("button",{type:"button",className:"w6w-stepbuilder-item",disabled:f,"aria-pressed":O.id===m,"data-connection-id":O.id,onClick:()=>v(O.id),children:n.jsxs("span",{className:"w6w-stepbuilder-item-main",children:[n.jsx("strong",{children:O.builtIn?"Built-in":O.displayName||O.id}),n.jsx("span",{className:"w6w-muted w6w-small",children:T.length>0?`In use in this workflow · ${T.map(I=>I.id).join(", ")}`:O.builtIn?"Built-in connection":O.state})]})},O.id))}),n.jsx("button",{type:"button",className:"w6w-btn",disabled:f,onClick:()=>{i(!1),A(!0)},children:"+ New connection"})]})}),N&&k&&cn.createPortal(n.jsx($s,{initialAppId:e.uses.app,onClose:()=>A(!1),onCreated:({connectionId:O})=>{A(!1),u(),v(O)}}),k),g&&k&&cn.createPortal(n.jsxs(Se,{title:"Change connection",onClose:()=>y(null),children:[n.jsxs("div",{className:"w6w-modal-body",children:[n.jsx("p",{children:"Change the connection for all these nodes, or only this node?"}),n.jsxs("ul",{children:[n.jsx("li",{children:e.id||"New node"}),x.map(O=>n.jsx("li",{children:O.id},O.id))]})]}),n.jsxs("div",{className:"w6w-modal-actions",children:[n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>y(null),children:"Cancel"}),n.jsxs("button",{type:"button",className:"w6w-btn w6w-btn-ghost",disabled:f,onClick:()=>C(g,!0),children:["All ",x.length+1," nodes"]}),n.jsx("button",{type:"button",className:"w6w-btn",disabled:f,onClick:()=>C(g,!1),children:"Only this node"})]})]}),k)]})}function Gc(e,t){return`${e.method}-${e.url??e.host}-${t}`}function ni({calls:e,defaultOpen:t,keyOf:s,title:o}){if(e.length===0)return null;const r=s??Gc;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((i,a)=>n.jsxs("details",{open:t,className:"w6w-result",style:{padding:8},children:[n.jsx("summary",{style:{cursor:"pointer"},children:n.jsxs("span",{className:"w6w-small",children:[i.method," ",i.url??i.host," →"," ",n.jsx("strong",{children:i.error?"failed":i.status}),i.durationMs!==void 0&&n.jsxs("span",{className:"w6w-muted",children:[" · ",i.durationMs,"ms"]})]})}),n.jsxs("div",{className:"w6w-stack",style:{gap:6,marginTop:8},children:[i.error&&n.jsx("div",{className:"w6w-error w6w-small",children:i.error}),n.jsx("div",{className:"w6w-muted w6w-small",children:"Request headers"}),n.jsx("pre",{className:"w6w-result",children:JSON.stringify(i.requestHeaders??{},null,2)}),i.requestBody&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"w6w-muted w6w-small",children:"Request body"}),n.jsx(Re,{value:i.requestBody,maxHeight:240})]}),n.jsx("div",{className:"w6w-muted w6w-small",children:"Response headers"}),n.jsx("pre",{className:"w6w-result",children:JSON.stringify(i.responseHeaders??{},null,2)}),i.responseBody&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"w6w-muted w6w-small",children:"Response body"}),n.jsx(Re,{value:i.responseBody,maxHeight:240})]}),i.truncated&&n.jsx("div",{className:"w6w-muted w6w-small",children:"A captured body exceeded the size cap and was truncated."})]})]},r(i,a)))]})}function si({choices:e,onChange:t,readOnly:s}){const o=new Set(e.selected),r=e.options.every(a=>o.has(a.value)),i=[...e.options,...e.selected.filter(a=>!e.options.some(l=>l.value===a)).map(a=>({value:a,label:a}))];return n.jsxs("div",{className:"w6w-field",children:[n.jsx("span",{children:"Triggers *"}),n.jsxs("div",{className:"w6w-multiselect-checks",children:[n.jsxs("div",{className:"w6w-multiselect-checks-toolbar",children:[n.jsxs("label",{className:"w6w-multiselect-check",children:[n.jsx("input",{type:"checkbox",checked:r,ref:a=>{a&&(a.indeterminate=!r&&o.size>0)},disabled:s,onChange:a=>t(a.target.checked?e.options.map(l=>l.value):[])}),n.jsx("span",{children:"All events"})]}),n.jsxs("span",{className:"w6w-muted w6w-small",children:[o.size," selected"]})]}),n.jsx("fieldset",{className:"w6w-multiselect-checks-options","aria-label":"Eventbrite events",children:i.map(a=>n.jsxs("label",{className:"w6w-multiselect-check",children:[n.jsx("input",{type:"checkbox",checked:o.has(a.value),disabled:s,onChange:l=>t(l.target.checked?[...e.selected,a.value]:e.selected.filter(c=>c!==a.value))}),n.jsx("span",{children:a.label})]},a.value))})]}),n.jsx("span",{className:"w6w-hint",children:"Start this workflow when any selected event occurs."})]})}function Cn({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 oi(e,t,s,o){var c;if(e!=="io.w6w.eventbrite")return null;const r=t==null?void 0:t.find(u=>u.key==="activity"),i=(c=r==null?void 0:r.params)==null?void 0:c.find(u=>u.key==="actions"&&u.type==="multiselect");if(!r||!Array.isArray(i==null?void 0:i.options)||!i.options.length)return null;const a=i.options.map(u=>{var p;const d=String(u.value),f=d.replace(/[._]/g,"-");return{value:d,label:((p=t==null?void 0:t.find(h=>h.key===f))==null?void 0:p.title)??u.label,triggerKey:f}}),l=a.find(u=>u.triggerKey===s);return s&&s!==r.key&&!l||s===r.key&&o.actions!=null&&!Array.isArray(o.actions)?null:{triggerKey:r.key,options:a.sort((u,d)=>u.label.localeCompare(d.label)),selected:l?[l.value]:Array.isArray(o.actions)?o.actions.filter(u=>typeof u=="string"):[]}}function Ce(e){var t;return((t=e==null?void 0:e.uses)==null?void 0:t.app)===Pe&&e.uses.action==="foreach"}function ri(e){var t;return((t=e==null?void 0:e.uses)==null?void 0:t.app)===Pe}function os(e){var t,s;return(e==null?void 0:e.uses.app)===qe?!0:!ri(e)||(e==null?void 0:e.uses.action)==="if"&&((t=e.with)==null?void 0:t.then)===void 0&&((s=e.with)==null?void 0:s.else)===void 0}function Ds(e){if(!ri(e))return[];const t=e.with??{},s=[],o=r=>{if(typeof r=="string")s.push(r);else if(Array.isArray(r))for(const i of r)o(i)};return o(t.body),o(t.branches),o(t.then),o(t.else),s}function Yc(e){const t=new Set;for(const s of e)for(const o of Ds(s))t.add(o);return t}function an(e,t,s,o){return{id:ut(e,t,"each",o),source:e,target:t,sourceHandle:o!==void 0?Nt(o):s?hn:void 0,animated:!1,data:{when:"each",...o===void 0?{}:{route:o}},...Ut("each",void 0)}}const Hs=e=>{var t;return typeof((t=e.data)==null?void 0:t.route)=="string"?e.data.route:void 0};function An(e,t,s,o){const r=new Set(t.map(b=>b.id)),i=s.filter(b=>be(b)==="each"),a=new Set([e]),l=[],c=[e];for(let b=0;b<c.length;b++)for(const m of i)m.source===c[b]&&(!r.has(m.target)||a.has(m.target)||o!=null&&o.has(m.target)||(a.add(m.target),l.push(m.target),c.push(m.target)));const u=new Map(l.map((b,m)=>[b,m])),d=i.filter(b=>b.source!==e&&u.has(b.source)&&u.has(b.target)),f=new Map(l.map(b=>[b,0]));for(const b of d)f.set(b.target,(f.get(b.target)??0)+1);const p=[],h=new Set;for(;;){const b=l.find(m=>!h.has(m)&&f.get(m)===0);if(b===void 0)break;h.add(b),p.push(b);for(const m of d)m.source===b&&f.set(m.target,(f.get(m.target)??0)-1)}for(const b of l)h.has(b)||p.push(b);return p}function ii(e,t){const s=new Set(e);return t.filter(o=>be(o)==="each"&&s.has(o.source)&&s.has(o.target))}function Xc(e,t){const s=ii(e,t),o=new Set;for(const r of s){if(Hs(r)!==void 0||o.has(r.source))return!1;o.add(r.source)}return!0}function Zc(e,t){const s=[];for(const o of En(e,t).values())if(!Xc(o,t))for(const r of ii(o,t)){const i=Hs(r);s.push({from:r.source,to:r.target,...i===void 0?{}:{route:i}})}return s}function En(e,t){var r;const s=new Map,o=new Set;for(const i of e){if(!Ce((r=i.data)==null?void 0:r.step))continue;const a=An(i.id,e,t,o);for(const l of a)o.add(l);s.set(i.id,a)}return s}function Be(e,t){const s={};for(const[o,r]of En(e,t))for(const i of r)s[i]=o;return s}function Qc(e,t,s){const o=f=>f.source===e||f.target===e,r=s.filter(f=>!o(f));if(Ce((f=>{var p,h;return(h=(p=t.find(b=>b.id===f))==null?void 0:p.data)==null?void 0:h.step})(e))){const f=An(e,t,s),p=new Set(f);return r.filter(h=>!(be(h)==="each"&&(h.source===e||p.has(h.source))&&p.has(h.target)))}const a=Be(t,s)[e];if(a===void 0)return r;const l=s.filter(f=>f.target===e&&be(f)==="each"),c=s.filter(f=>f.source===e&&be(f)==="each");if(l.length!==1||c.length!==1)return r;const u=l[0].source,d=c[0].target;return r.some(f=>f.source===u&&f.target===d&&be(f)==="each")?r:[...r,an(u,d,u===a,Hs(l[0]))]}function Bs(e){if(!Ce(e)||!e.with||!("body"in e.with))return e;const{body:t,...s}=e.with;return{...e,with:s}}function ai(e,t,s,o,r){const i=Be(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 a=u=>{var d,f;return(f=(d=o.find(p=>p.id===u))==null?void 0:d.data)==null?void 0:f.step},l=Ce(a(e))?e:i[e];if(l===void 0)return null;if(t===l)return"loop_cycle";const c=()=>e!==l||!r.some(u=>u.source===e&&be(u)==="each");return i[t]===l?e===l||eu(t,e,r)?"loop_cycle":c()?null:"body_branch":i[t]!==void 0?"already_in_loop":os(a(t))?c()?r.some(u=>u.source===t||u.target===t)?"body_exit":null:"body_branch":"control_in_body"}function eu(e,t,s){const o=new Set([e]),r=[e];for(;r.length>0;){const i=r.pop();if(i===t)return!0;for(const a of s)a.source!==i||be(a)!=="each"||o.has(a.target)||(o.add(a.target),r.push(a.target))}return!1}const tu={error_lane_in_body:"A step inside a loop can't have an error connection. Handle the failure outside the loop.",outside_inbound:"This step is inside a loop, so nothing outside it can connect into it. Connect from the loop's Each item side instead.",loop_cycle:"A loop body can't connect back to its own For each.",already_in_loop:"That step is already inside another loop.",control_in_body:"A loop body supports plain steps, If conditions and Routers. Nested control blocks aren't supported here yet.",body_branch:"A For each's Each item port connects to one first step. Branch inside the loop from that step onward.",body_exit:"That step is already connected elsewhere in the workflow. Use a step with no connections, or disconnect it first."};function nu(e){return tu[e]}function su(e,t){const s=Be(e,t);let o=!1;const r=e.map(i=>{const a=s[i.id];if(i.data.loopOf===a)return i;if(o=!0,a===void 0){const{loopOf:l,...c}=i.data;return{...i,data:c}}return{...i,data:{...i.data,loopOf:a}}});return o?r:e}function ou(e,t,s){var a,l;const o=`Delete node "${e}"? Its connections are removed too.`,r=(l=(a=t.find(c=>c.id===e))==null?void 0:a.data)==null?void 0:l.step;if(!Ce(r))return o;const i=An(e,t,s);return i.length===0?o:`${o} Its loop body steps ${i.map(c=>`"${c}"`).join(", ")} stay as standalone steps.`}function qs(e){if(e.edges)return e.edges;const t=Yc(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 ln=e=>(e.when??"success")==="success",Ws=e=>e.route===Ho&&ln(e);function Us(e){const t=new Map(e.nodes.map(c=>[c.id,c])),s=new Map;for(const c of e.nodes)for(const u of Ds(c)){const d=s.get(u)??new Set;d.add(c.id),s.set(u,d)}const o=qs(e),r=e.edges??[],i={};for(const c of e.nodes){if(!Ce(c))continue;const u=c.with??{};if("body"in u){i[c.id]=a(c.id,u.body);continue}i[c.id]=l(c.id)}return i;function a(c,u){const d=(m,x)=>({invalid:x===void 0?{reason:m}:{reason:m,stepId:x}});if(!Array.isArray(u)||u.some(m=>typeof m!="string"))return d("body_not_literal");const f=u,p=new Set(f),h=new Set;for(const m of f){if(!t.has(m))return d("body_unknown_step",m);if(m===c)return d("body_self",m);if(h.has(m))return d("body_duplicate",m);if(h.add(m),!os(t.get(m)))return d("body_contains_control",m);const x=s.get(m);if(x&&[...x].some(g=>g!==c))return d("body_claimed_twice",m)}const b=[];for(const m of r){if(Ws(m)&&m.from===c&&m.to===f[0]||!(p.has(m.from)||p.has(m.to)))continue;if(!(p.has(m.from)&&p.has(m.to)&&ln(m)&&m.to!==f[0]))return d("body_step_has_edges",p.has(m.from)?m.from:m.to);b.push(m)}return b.length>0?{body:f,source:"body",edges:b}:{body:f,source:"body"}}function l(c){var m;const u=o.filter(x=>x.from===c&&ln(x)&&x.route===void 0);if(u.length===0)return{body:[],source:"body"};const d=x=>({invalid:{reason:"legacy_not_linear",stepId:x}});if(u.length>1)return d(c);const f=[],p=new Set([c]);let h=c,b=u[0].to;for(;b!==void 0;){const x=b,g=t.get(x);if(!g||p.has(x)||!os(g)||s.has(x))return d(x);const y=o.filter(A=>A.to===x);if(y.length!==1||y[0].from!==h)return d(x);const N=o.filter(A=>A.from===x);if(N.length>1||N.length===1&&!ln(N[0]))return d(x);p.add(x),f.push(x),h=x,b=(m=N[0])==null?void 0:m.to}return{body:f,source:"legacy"}}}function be(e){var s;const t=(s=e.data)==null?void 0:s.when;return t==="error"?"error":t==="each"?"each":"success"}function li(e,t){var s;return((s=e.find(o=>o.id===t))==null?void 0:s.id)??null}function ci(e,t,s,o,r,i){var d,f;if(!e||!t||e===t||o.some(p=>{var h;return p.source===e&&p.target===t&&((h=p.data)==null?void 0:h.route)===i}))return!1;const a=(d=s.find(p=>p.id===e))==null?void 0:d.data.step,l=(f=s.find(p=>p.id===t))==null?void 0:f.data.step;if(!a||!l)return!1;const c=Mt(a,r),u=Mt(l,r);return c.out>=1&&u.in>=1}function Vs(e,t,s,o,r,i,a){var k,C,v;const l=r==="success"&&Ce((k=s.find(E=>E.id===e))==null?void 0:k.data.step),c=l&&a===void 0?yt:a;if(!ci(e,t,s,o,i,c)||!e||!t)return null;const u=(C=s.find(E=>E.id===e))==null?void 0:C.data.step,d=(v=s.find(E=>E.id===t))==null?void 0:v.data.step;if(!u||!d)return null;const f=ms(u);if(l){if(c!==yt)return null}else if(u.uses.app===qe&&r==="success"){if(!hs(u).some(E=>E.id===c))return null}else if(f&&r==="success"){if(c!==void 0&&c!==un)return null}else if(c!==void 0)return null;const p=Be(s,o)[e]!==void 0,h=r==="success"&&p?"each":r;if(h==="each"&&!p&&!Ce(u))return null;const b=ai(e,t,h,s,o);if(b)return{next:o,conflict:null,refusal:{refused:"loop",reason:b}};const m=Mt(u,i),x=o,g=x.filter(E=>{var R;return E.source===e&&be(E)===h&&((R=E.data)==null?void 0:R.route)===c}),y=c===void 0||f||l?m.out:1;if(g.length>=y)return{next:o,conflict:null,refusal:{refused:"out_cap",cap:y}};const N=ut(e,t,h,c),A=h==="each"&&p?void 0:us(h);return{next:Bn.addEdge({source:e,target:t,id:N,sourceHandle:c===void 0?A:Nt(c),data:{when:h,...c===void 0?{}:{route:c}},...Ut(h,void 0)},x),conflict:li(x,N),refusal:null}}function ru(e,t,s,o,r="success",i,a){const l=Vs(e,t,s,o,r,i,a);return!l||l.conflict||l.refusal?null:l.next}function iu(e,t,s,o,r="success",i,a){var l;return((l=Vs(e,t,s,o,r,i,a))==null?void 0:l.conflict)??null}function au(e,t,s,o,r="success",i,a){var l;return((l=Vs(e,t,s,o,r,i,a))==null?void 0:l.refusal)??null}function zs(e,t,s,o,r){var y;const i=e.filter(N=>N.id===t);if(i.length!==1)return null;const a=i[0];if(be(a)==="each")return null;const l=(y=o.find(N=>N.id===a.source))==null?void 0:y.data.step;if(!l||l.uses.app===qe||l.uses.app===Vt)return null;const c=Mt(l,r).out,u=e.filter(N=>N.id!==t);if((be(a)===s?[]:u.filter(N=>N.source===a.source&&be(N)===s)).length>=c)return{next:e,conflict:null,refusal:{refused:"out_cap",cap:c}};const f=Ut(s,void 0),p=Ce(l),h=p&&s==="success"?yt:void 0,{route:b,...m}=a.data??{},x={...a,id:ut(a.source,a.target,s,h),data:p?{...m,when:s,...h?{route:h}:{}}:{...a.data,when:s},className:f.className,label:f.label,sourceHandle:h?Nt(h):us(s)},g=li(u,x.id);return{next:e.map(N=>N.id===t?x:N),conflict:g,refusal:null}}function lu(e,t,s,o,r){const i=zs(e,t,s,o,r);return!i||i.conflict||i.refusal?null:i.next}function cu(e,t,s,o,r){var i;return((i=zs(e,t,s,o,r))==null?void 0:i.conflict)??null}function uu(e,t,s,o,r){var i;return((i=zs(e,t,s,o,r))==null?void 0:i.refusal)??null}function du(e,t,s){return e.map(o=>{var a;const r=o.source===t?s:o.source,i=o.target===t?s:o.target;return{...o,source:r,target:i,id:ut(r,i,be(o),typeof((a=o.data)==null?void 0:a.route)=="string"?o.data.route:void 0)}})}function ut(e,t,s,o){const r=s==="error"?`${e}->${t}:error`:`${e}->${t}`;return o===void 0?r:`${r}:route:${encodeURIComponent(o)}`}function pu(e){return e.includes(".")?"A step id can't contain a dot (.).":null}function ui(e,t){const s=pu(e);if(s)return s;for(const o of t)if(o===e)return`A step named "${e}" already exists.`;return null}function fu(e,t,s){const o=(f,p)=>!f||!p?void 0:ut(f,p)===t?"success":ut(f,p,"error")===t?"error":void 0,r=o(s[0],s[1]),i=o(s[2],s[3]),a=r!==void 0&&r===i,l=r!==void 0&&i!==void 0&&r!==i,c=r==="success"?s[1]:s[3],u=a?s.find(f=>!!f&&f.includes("->")):l&&(c!=null&&c.endsWith(":error"))?c:void 0,d=u===void 0?"Rename one of the steps it connects, then try again.":a?`A step id containing “->” collides with the edge-id separator, so two different edges mint one id — rename the step “${u}”, then try again.`:`A step id ending in “:error” collides with the error-lane marker, so two different edges mint one id — rename the step “${u}”, then try again.`;return`${e}: the id “${t}” is already taken by another edge. ${d}`}const hu=240,mu=100,wu=40,bu=40;function Js(e,t){return{x:wu+e*hu,y:bu+t*mu}}function gu(e,t){var l;const s=new Map,o=new Map;for(const c of e)s.set(c.id,0),o.set(c.id,[]);for(const c of t)(l=o.get(c.to))==null||l.push(c.from);const r=e.length+1;let i=0,a=!0;for(;a&&i<r;){i++,a=!1;for(const c of e){const u=o.get(c.id)??[];if(u.length===0)continue;const d=u.reduce((f,p)=>Math.max(f,(s.get(p)??0)+1),0);(s.get(c.id)??0)<d&&(s.set(c.id,d),a=!0)}}if(a){const c=Math.max(0,e.length-1);for(const[u,d]of s)d>c&&s.set(u,c)}return s}function di(e,t){var c;const s=gu(e,t),o=new Map(e.map((u,d)=>[u.id,d])),r=new Map;for(const{from:u,to:d}of t){const f=s.get(u),p=s.get(d);if(f===void 0||p===void 0||f>=p)continue;const h=r.get(d);(h===void 0||f<(s.get(h)??0)||f===s.get(h)&&(o.get(u)??0)<(o.get(h)??0))&&r.set(d,u)}const i=new Map(e.map(u=>[u.id,[]]));for(const[u,d]of r)(c=i.get(d))==null||c.push(u);for(const u of i.values())u.sort((d,f)=>(s.get(f)??0)-(s.get(d)??0)||(o.get(d)??0)-(o.get(f)??0));const a=new Map;let l=0;for(const u of e.filter(d=>!r.has(d.id))){const d=[u.id];for(;d.length;){const f=d.pop();if(f===void 0)continue;a.set(f,Js(s.get(f)??0,l));const p=i.get(f)??[];if(p.length===0)l++;else for(let h=p.length-1;h>=0;h--)d.push(p[h])}}return a}function yu(e){const t=e.position;if(!(!t||!Number.isFinite(t.x)||!Number.isFinite(t.y)))return{x:t.x,y:t.y}}function Ks(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 xu(e){const t=Ks(e),s=t.nodes;let o=qs(t);const r=[],i=new Map,a=new Set,l=new Set;for(const[h,b]of Object.entries(Us(t))){if("invalid"in b)continue;let m=h;if(b.edges&&b.body.length>0){r.push(an(h,b.body[0],!0));for(const x of b.edges)l.add(x),r.push(an(x.from,x.to,!1,x.route));for(const x of b.body)i.set(x,h);continue}for(const x of b.body){if(b.source==="legacy"){const g=o.find(y=>y.from===m&&y.to===x&&(y.when??"success")==="success");g&&l.add(g)}r.push(an(m,x,m===h)),i.set(x,h),m=x}b.source==="legacy"&&a.add(h)}const c=new Set(s.filter(Ce).map(h=>h.id));for(const h of o)c.has(h.from)&&Ws(h)&&l.add(h);l.size>0&&(o=o.filter(h=>!l.has(h)));const u=di(s,[...o,...r.map(h=>({from:h.source,to:h.target}))]),d=s.map(h=>{const b=Ye(h.uses.app);return{id:h.id,type:b?"control":"step",position:yu(h)??u.get(h.id)??Js(0,0),data:{step:h,isInternal:b,...i.has(h.id)?{loopOf:i.get(h.id)}:{},...a.has(h.id)?{legacyLoop:!0}:{}}}}),f=new Set(s.filter(ms).map(h=>h.id)),p=o.map(h=>{const b=h.when==="error"&&h.route===void 0&&f.has(h.from)?{from:h.from,to:h.to,route:un}:c.has(h.from)&&h.route===void 0&&h.when!=="error"?{...h,route:yt}:h,m=b.when??"success";return{id:ut(b.from,b.to,m,b.route),source:b.from,target:b.to,sourceHandle:b.route===void 0?us(m):`route:${b.route}`,animated:!1,data:{when:m,...b.route===void 0?{}:{route:b.route}},...Ut(m,void 0)}});return{nodes:d,edges:[...p,...r]}}function vu(e,t){const s=e.map(r=>({...r.data.step,id:r.id})),o=di(s,t.map(r=>({from:r.source,to:r.target})));return e.map(r=>({...r,position:o.get(r.id)??Js(0,0)}))}function ju(e,t,s){var k,C;const o=Ks(e),r=((k=o.settings)==null?void 0:k.savePosition)!==!1,i=new Map(t.map(v=>[v.id,v])),a=v=>{var R;if(!r)return v;const E=(R=i.get(v.id))==null?void 0:R.position;return!E||!Number.isFinite(E.x)||!Number.isFinite(E.y)?v:{...v,position:{x:Math.round(E.x),y:Math.round(E.y)}}},l=new Map;for(const v of o.nodes)l.set(v.id,v);for(const v of t)(C=v.data)!=null&&C.step&&l.set(v.id,v.data.step);const c=En(t,s),u=Us(o),d=new Map(o.nodes.map(v=>[v.id,v])),f=new Set;for(const v of s)be(v)==="success"&&f.add(v.source);const p=v=>{if(!Ce(v))return v;const E=c.get(v.id)??[],R=d.get(v.id),F=u[v.id];let O;E.length>0?O={value:E}:F&&"invalid"in F&&F.invalid.reason!=="legacy_not_linear"?O=R!=null&&R.with&&"body"in R.with?{value:R.with.body}:null:F&&"invalid"in F?O=null:f.has(v.id)||R!=null&&R.with&&"body"in R.with?O={value:[]}:O=null;const T=v.with??{};return O===null?"body"in T?Bs(v):v:{...v,with:{...T,body:O.value}}},h=v=>a(p(v)),b=[],m=new Set;for(const v of o.nodes){const E=l.get(v.id);E&&t.some(R=>R.id===v.id)&&(b.push(h(E)),m.add(v.id))}for(const v of t){if(m.has(v.id))continue;const E=l.get(v.id);E&&b.push(h(E))}const x=new Set;for(const v of c.values())for(const E of v)x.add(E);const g=new Set(t.filter(v=>{var E;return Ce((E=v.data)==null?void 0:E.step)}).map(v=>v.id)),y=s.filter(v=>be(v)!=="each"&&!x.has(v.source)&&!x.has(v.target)).map(v=>{var R;const E=typeof((R=v.data)==null?void 0:R.route)=="string"?v.data.route:g.has(v.source)&&be(v)==="success"?yt:void 0;return{from:v.source,to:v.target,...be(v)==="error"?{when:"error"}:{},...E===void 0?{}:{route:E}}}),N=[];for(const[v,E]of c)E.length>0&&N.push({from:v,to:E[0],route:Ho});const A=[...y,...N,...Zc(t,s)];return zc(Zr({...o,nodes:b,edges:A}))}function pi(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 Nu(e,t){var a;if(!(((a=e.settings)==null?void 0:a.savePosition)!==!1)||!Number.isFinite(t.x)||!Number.isFinite(t.y)||!Number.isFinite(t.zoom))return e;const o={x:Math.round(t.x),y:Math.round(t.y),zoom:Math.round(t.zoom*1e3)/1e3},r=pi(e);if(r&&r.x===o.x&&r.y===o.y&&r.zoom===o.zoom)return e;const i=typeof e.settings=="object"&&e.settings!==null&&!Array.isArray(e.settings)?e.settings:void 0;return{...e,settings:{...i,viewport:o}}}function ku(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"")||"step"}function Su(e,t){const s=new Set(t.map(o=>o.target));return e.find(o=>!s.has(o.id))}function Cu(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 Au(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 Gs(e){return JSON.stringify(Bs(e),null,2)}const Eu=3,Ru=100;function dt(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function fi(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(!dt(r)||typeof r.key!="string"||r.key==="")continue;const i=typeof r.label=="string"&&r.label!==""?r.label:void 0;if(o({key:r.key,...i?{label:i}:{},path:!0}),r.type==="array"&&Array.isArray(r.items))for(const a of r.items){if(!dt(a)||typeof a.key!="string"||a.key==="")continue;const l=typeof a.label=="string"&&a.label!==""?a.label:void 0;o({key:`${r.key}.0.${a.key}`,...l?{label:l}:{},path:!0})}}return t.length>0?t:void 0}function Tu(e,t){var o;if(!Array.isArray(e))return;const s=e.find(r=>dt(r)&&r.key===t);if(!(!dt(s)||!Array.isArray(s.items)))return(o=fi([{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 rt(e){if(!dt(e))return;const t=[],s=(o,r,i)=>{for(const[a,l]of Object.entries(o)){if(t.length>=Ru)return;const c=r?`${r}.${a}`:a;t.push({key:c,path:!0}),dt(l)&&i<Eu&&s(l,c,i+1)}};return s(e,"",1),t.length>0?t:void 0}function $t(e,t){let s=e;for(const o of t.split(".")){if(!dt(s)||!(o in s))return;s=s[o]}return s}function bt(e,t,s){const o=fi(e==null?void 0:e.output),r=rt(t),i=r??rt(s);if(i){const l=new Map((o??[]).map(d=>[d.key,d])),c=new Set(i.map(d=>d.key)),u=i.map(d=>{const f=l.get(d.key);return f!=null&&f.label?{...d,label:f.label}:d});for(const d of o??[])c.has(d.key)||u.push({...d,declaredOnly:!0});return{fields:u,from:r?"fresh":"persisted"}}if(o)return{fields:o,from:"declared"};const a=rt(e==null?void 0:e.sample);if(a)return{fields:a,from:"sample"}}function Ys(e,t){const s=new Map;for(const i of t){const a=s.get(i.target)??[];a.push(i.source),s.set(i.target,a)}const o=new Set,r=[e];for(;r.length;){const i=r.pop();for(const a of s.get(i)??[])o.has(a)||(o.add(a),r.push(a))}return o}function hi(e,t,s={}){var a,l,c,u,d,f,p;const o=[];let r=!1,i;for(const h of t){if(!e.has(h.id))continue;const b=h.data.step;if(b.uses.app===fs)continue;const m=((a=it(b.uses.app,b.uses.action))==null?void 0:a.group)==="trigger",x=(l=s.testOutputs)==null?void 0:l[b.id],g=(c=s.persistedOutputs)==null?void 0:c[b.id];if(b.uses.trigger===!0){r=!0;const E=bt((u=s.triggerDef)==null?void 0:u.call(s,b.uses.app,b.uses.action),x,g);if(i??(i=E),E&&(E.from==="fresh"||E.from==="persisted")){o.push({id:b.id,label:b.id,outputs:E.fields,outputsFrom:E.from});continue}}m&&(r=!0);const y=m&&b.uses.app===mn,N=y?_s(Ps((d=b.with)==null?void 0:d.fields)).map(E=>({key:E.key,label:E.label})):((f=it(b.uses.app,b.uses.action))==null?void 0:f.output)??[],A={id:b.id,label:b.id};if(N.length>0){o.push({...A,outputs:N});continue}if(m){const E=bt(void 0,x,g);E&&!y&&(i??(i=E)),o.push(E?{...A,outputs:E.fields,outputsFrom:E.from}:A);continue}if(Ye(b.uses.app)){const E=bt(void 0,x,g);o.push(E?{...A,outputs:E.fields,outputsFrom:E.from}:A);continue}const k=(p=s.actionDef)==null?void 0:p.call(s,b.uses.app,b.uses.action),C=bt(k,x,g),v=b.uses.app.trim()!==""?{hasMeta:!0}:{};C?o.push({...A,outputs:C.fields,outputsFrom:C.from,...v}):o.push(k?{...A,needsTest:!0,...v}:{...A,...v})}return{steps:o,hasTrigger:r,...i?{eventOutputs:i.fields,eventOutputsFrom:i.from}:{}}}function Ou(e,t){const s={};for(const[o,r]of Object.entries(t))s[o]={output:r};return mi(e,{steps:s})}function mi(e,t){if(Qe(e)!==null){const s=ks(e,vs(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 Iu=10;function $u(e,t){return{input:t,with:{items:e.slice(0,Iu),itemCount:e.length}}}function Pu(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 wi(e,t,s,o,r={}){const i=Be(s,o),a=new Set;for(const f of e){if(f===t)continue;const p=i[f];p!==void 0&&p!==t||a.add(f)}const l=hi(a,s,r),c=En(s,o),u=[];return{steps:l.steps.map(f=>{var y,N,A;const p=c.get(f.id);if(!p||p.length===0)return f;const h=p[p.length-1],b=(y=s.find(k=>k.id===h))==null?void 0:y.data.step,m=r.testOutputs??{},x=b?bt((N=r.actionDef)==null?void 0:N.call(r,b.uses.app,b.uses.action),m[h],(A=r.persistedOutputs)==null?void 0:A[h]):void 0;u.includes(h)||u.push(h);const g=((x==null?void 0:x.fields)??[]).map(k=>({key:`items.0.${k.key}`,path:!0,...k.declaredOnly?{declaredOnly:!0}:{}}));return{id:f.id,label:f.label,outputs:[{key:"items",path:!0},...g],...x?{outputsFrom:x.from}:{}}}),hasTrigger:l.hasTrigger,extraSampleIds:u,...l.eventOutputs?{eventOutputs:l.eventOutputs,eventOutputsFrom:l.eventOutputsFrom}:{}}}function _u(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 Lu(e,t,s){var f,p;const o=Qe(e),r=o?_u(o):void 0,i=r?(f=t.find(h=>h.id===r.id))==null?void 0:f.data.step:void 0;if(!r||!i)return;const a=(p=s.actionDef)==null?void 0:p.call(s,i.uses.app,i.uses.action),l=$t(a==null?void 0:a.sample,r.path),c=Array.isArray(l)&&l.length>0?l[0]:void 0,d=Tu(a==null?void 0:a.output,r.path)??rt(c);if(!(c===void 0&&!d))return{...c!==void 0?{itemSample:c}:{},...d?{itemOutputs:d}:{}}}function bi(e,t,s={}){var u,d,f;const o={foreachId:e},r=(d=(u=t.find(p=>p.id===e))==null?void 0:u.data.step.with)==null?void 0:d.items,i={...s.persistedOutputs??{},...s.testOutputs??{}},a=Ou(r,i),l=a&&a.length>0?a:(f=s.loopSamples)==null?void 0:f[e];if(l&&l.length>0){o.itemSample=l[0];const p=rt(l[0]);return p&&(o.itemOutputs=p),o}const c=Lu(r,t,s);return(c==null?void 0:c.itemSample)!==void 0&&(o.itemSample=c.itemSample),c!=null&&c.itemOutputs&&(o.itemOutputs=c.itemOutputs),o}function Fu(e,t,s,o,r){let i=e;if(!i&&r&&(s.some(c=>c.target===r)||Be(t,s)[r]!==void 0)&&(i=r),!i)return hi(new Set(t.map(c=>c.id)),t,o);const a=Be(t,s)[i],l=wi(Ys(i,s),a,t,s,o);return a&&!l.extraSampleIds.includes(a)&&l.extraSampleIds.push(a),{steps:l.steps,hasTrigger:l.hasTrigger,...l.eventOutputs?{eventOutputs:l.eventOutputs,eventOutputsFrom:l.eventOutputsFrom}:{},...a?{loop:bi(a,t,o)}:{},...l.extraSampleIds.length>0?{extraSampleIds:l.extraSampleIds}:{}}}function Mu(e,t,s,o){if(!e||e.handleType==="target")return[];const r=Ys(e.nodeId,s);r.add(e.nodeId);const i=gi(e,t,s);return wi(r,i,t,s,o).steps}function gi(e,t,s){const o=t.find(r=>r.id===e.nodeId);return e.lane==="each"&&Ce(o==null?void 0:o.data.step)?e.nodeId:Be(t,s)[e.nodeId]}function Du(e,t,s,o){if(!e||e.handleType==="target")return;const r=gi(e,t,s);return r?bi(r,t,o):void 0}async function Hu(e,t){return(await Promise.all(t.map(async o=>{try{const r=await e(o.id),i=r.length?r[r.length-1]:null;return i?{stepId:o.id,label:o.label??o.id,test:i}:null}catch{return null}}))).filter(o=>o!==null)}function Xs(e,t){const s={};for(const r of e){const i=r.test.lastRunOutput,a=i!=null;if(!a&&r.test.lastRunStatus!=="succeeded")continue;const l=r.test.lastRunMeta;s[r.stepId]={output:a?i: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}}:o?{steps:s}:void 0}function yi(e){if(e)return{..."itemSample"in e?{item:e.itemSample}:{},index:0}}function Bu(e){return!e||!("itemSample"in e)?"":JSON.stringify(e.itemSample,null,2)??""}function qu(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 Wu(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 Uu(e,t,s,o,r){return xi(e,t,s,o,r).values}function Vu(e,t,s,o,r){return xi(e,t,s,o,r).sources}function zu(e,t){var r,i,a,l;const s={};let o;for(const c of e){const u=c.data.step.uses;if(u.trigger===!0){const f=(i=(r=t.triggerDef)==null?void 0:r.call(t,u.app,u.action))==null?void 0:i.sample;o===void 0&&f!==void 0&&(o=f);continue}if(Ye(u.app))continue;const d=(l=(a=t.actionDef)==null?void 0:a.call(t,u.app,u.action))==null?void 0:l.sample;d!==void 0&&(s[c.id]=d)}return{samples:s,...o!==void 0?{event:o}:{}}}function xi(e,t,s,o,r={}){var l,c;const i={},a={};for(const u of e){Object.assign(i,Wu(u.id,s[u.id]));const d=[["sample",(l=r.samples)==null?void 0:l[u.id]],["persisted",(c=r.persisted)==null?void 0:c[u.id]],["fresh",t[u.id]]];for(const[f,p]of d){if(p===void 0)continue;const h=(b,m)=>{for(const x of["nodes","steps"])i[`${x}.${b}`]=m,a[`${x}.${b}`]=f};if(h(`${u.id}.output`,p),typeof p=="object"&&p!==null&&!Array.isArray(p))for(const[b,m]of Object.entries(p))h(`${u.id}.output.${b}`,m);for(const b of u.outputs??[]){if(!b.path||!b.key.includes("."))continue;const m=$t(p,b.key);m!==void 0&&h(`${u.id}.output.${b.key}`,m)}}}if(r.event!==void 0){const u=(d,f)=>{i[d]=f,a[d]="sample"};if(u("trigger.event",r.event),typeof r.event=="object"&&r.event!==null&&!Array.isArray(r.event))for(const[d,f]of Object.entries(r.event))u(`trigger.event.${d}`,f);for(const d of rt(r.event)??[]){const f=$t(r.event,d.key);f!==void 0&&u(`trigger.event.${d.key}`,f)}}if(o&&"itemSample"in o){i["foreach.item"]=o.itemSample;for(const u of o.itemOutputs??[]){const d=$t(o.itemSample,u.key);d!==void 0&&(i[`foreach.item.${u.key}`]=d)}i["foreach.index"]=0}return{values:i,sources:a}}function Ju(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 Ku(e){const t=[];for(const s of e){const o=s.data.step,r=Object.entries(o.with??{}).filter(([,a])=>a!==void 0&&!Ju(a)).map(([a])=>a);(o.uses.app===Le||o.uses.trigger===!0)&&!r.includes("url")&&r.unshift("url"),r.length>0&&t.push({id:o.id,keys:r})}return t}function rs(e){if(!(We(e)||Ze(e))){if(Array.isArray(e))return e.map(rs).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,i]of Object.entries(t)){const a=rs(i);a!==void 0&&(o[r]=a)}return o}return e}}function Gu(e,t){const s={};for(const o of e){const r=o.data.step,i={...rs(r.with??{})??{}},a=vi(r,t);a!=null&&a.webhookUrl&&(i.url=a.webhookUrl),Object.keys(i).length>0&&(s[r.id]=i)}return s}function vi(e,t){if(!(e.uses.app!==Le&&e.uses.trigger!==!0))return t.find(s=>s.nodeId===e.id)??(e.uses.app===Le?t.find(s=>s.appId===Le):void 0)}function Yu(e,t,s,o){var i;const r={};for(const a of e){const l=a.data.step;if(!l.uses.app)continue;const c={app:l.uses.app,action:l.uses.action,connectionId:St(l,o)??null},u=(i=s==null?void 0:s.get(l.uses.app))==null?void 0:i.version;u&&(c.version=u);const d=vi(l,t);d&&(c.subscriptionId=d.id),d!=null&&d.webhookUrl&&(c.url=d.webhookUrl),r[l.id]=c}return r}function Xu(e){const t={};for(const[s,o]of Object.entries(e))for(const[r,i]of Object.entries(o))t[`nodes.${s}.meta.${r}`]=i,t[`steps.${s}.meta.${r}`]=i;return t}function Zs(e,t,s){const o=ye(),[r,i]=w.useState([]),a=JSON.stringify(t.map(l=>[l.id,l.label]));return w.useEffect(()=>{const l=JSON.parse(a);if(!s||l.length===0){i([]);return}let c=!1;return Hu(u=>o.listStepTests(e,u),l.map(([u,d])=>({id:u,label:d}))).then(u=>{c||i(u)}),()=>{c=!0}},[o,e,a,s]),r}const Zu=["function","workflow"],Qu={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"/>'},Hn={props:{label:"Form",icon:"form"},code:{label:"JSON",icon:"code"},"params-code":{label:"Params JSON",icon:"braces"},config:{label:"Node settings",icon:"settings-2"}},ed=["props","code","params-code","config"];function Rn({view:e,onChange:t,disabled:s,views:o=ed,customized:r=!1}){const i=a=>n.jsx("button",{type:"button",title:Hn[a].label,"aria-label":Hn[a].label,"aria-pressed":e===a,disabled:s,className:`w6w-icon-btn${e===a&&!s?" active":""}`,onClick:()=>t(a),children:n.jsx(ue.Icon,{name:Hn[a].icon,size:15})},a);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(i)]})}function td({onClose:e,onAdd:t,onDraftChange:s,theme:o,appsOnly:r,callables:i=Zu,initialTab:a,title:l,workflowId:c,stepId:u,upstreamSteps:d=[],loop:f,initialApp:p,initialAction:h,initialConnection:b,initialWith:m,appsFilter:x,appsIds:g,connectionOnly:y,onConnected:N,excludeCallableIds:A,onOpenStep:k,stepIds:C=[]}){const[v,E]=w.useState(null),[R,F]=w.useState(null),O=w.useRef(null),T=P=>{const H=t(P);return typeof H=="string"&&(O.current=P,E(H),F(null)),H},I=s?(P,H)=>{O.current=H,s(P,H)}:void 0,M=()=>{v&&R&&R!==v&&I&&O.current&&I(v,{...O.current,id:R}),e()},q=P=>v&&s?n.jsxs("span",{className:"w6w-stepbuilder-title",children:[P,n.jsx(Rr,{value:R??v,onCommit:H=>{const ae=ui(H,C.filter(fe=>fe!==v));return ae||F(H),ae}})]}):P,[D,Y]=w.useState(a??"connected"),[$,G]=w.useState(""),[ne,oe]=w.useState(p??null),[X,L]=w.useState(null),[z,Z]=w.useState(null),[W,J]=w.useState(null),te=!!g&&g.length>0,S=Si(i,x,A,g),U=S.state!=="empty";if(w.useEffect(()=>{!U&&D==="connected"&&Y("apps")},[U,D]),W)return n.jsx(Se,{title:q(W.label),ariaLabel:W.label,subtitle:n.jsx("code",{children:W.id}),onClose:e,size:"xl",headerRight:n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>J(null),children:"← Back"}),children:n.jsx("div",{className:"w6w-stepbuilder-config",children:n.jsx(cd,{family:W.family,targetId:W.id,targetLabel:W.label,onAdd:T,onClose:e,onDone:M,onDraftChange:I})})});if(X)return n.jsx(Se,{title:q(X.groupActions?X.displayName:X.label),ariaLabel:X.groupActions?X.displayName:X.label,titleIcon:n.jsx(Cn,{icon:X.icon,size:22}),subtitle:n.jsxs("code",{children:[X.app,!X.groupActions&&` · ${X.action}`]}),onClose:e,size:"xl",headerRight:n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>L(null),children:"← Back"}),children:n.jsx("div",{className:"w6w-stepbuilder-config",children:n.jsx(id,{node:X,onAdd:T,onClose:e,onDone:M,onDraftChange:I,onOpenStep:k,workflowId:c,upstreamSteps:d,loop:f})})});const V=z??ne;if(V){const P=z?"trigger":"action",H=()=>{oe(null),Z(null)};return n.jsx(Se,{title:q(V.displayName),ariaLabel:V.displayName,subtitle:n.jsxs(n.Fragment,{children:[n.jsx("code",{children:V.id}),V.version&&` · v${V.version}`]}),onClose:e,size:"xl",titleIcon:n.jsx(ft,{src:V.iconSvg,srcDark:V.iconSvgDark,brandColor:V.brandColor,name:V.displayName,theme:o,size:22}),children:n.jsx("div",{className:"w6w-stepbuilder-config",children:y&&P==="action"?n.jsx(gd,{appId:V.id,app:V,onClose:e,onChangeApp:H,theme:o,initialConnection:b,onConnected:(ae,fe)=>N==null?void 0:N(ae,fe)}):n.jsx(bd,{kind:P,onOpenStep:k,appId:V.id,app:V,onAdd:T,onClose:e,onDone:M,onDraftChange:I,onChangeApp:H,theme:o,workflowId:c,stepId:u,upstreamSteps:d,loop:f,...P==="action"?{initialAction:h,initialConnection:b,initialWith:m}:{}})})})}return n.jsx(Se,{title:l??"Add a node",onClose:e,size:"xl",children:n.jsxs("div",{className:"w6w-stepbuilder-picker",children:[n.jsx("input",{type:"search",className:"w6w-stepbuilder-search","aria-label":"Search nodes and apps",placeholder:"Search this tab…",value:$,onChange:P=>G(P.target.value)}),n.jsxs("div",{className:"w6w-stepbuilder",children:[n.jsxs("nav",{className:"w6w-stepbuilder-sidebar",children:[U&&n.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${D==="connected"?" active":""}`,onClick:()=>Y("connected"),children:"Ready to use"}),n.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${D==="apps"?" active":""}`,onClick:()=>Y("apps"),children:"Apps"}),n.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${D==="ai"?" active":""}`,onClick:()=>Y("ai"),children:"AI"}),i.includes("workflow")&&n.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${D==="workflows"?" active":""}`,onClick:()=>Y("workflows"),children:"Workflows"}),i.includes("function")&&n.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${D==="functions"?" active":""}`,onClick:()=>Y("functions"),children:"Functions"}),!r&&n.jsxs(n.Fragment,{children:[n.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${D==="triggers"?" active":""}`,onClick:()=>Y("triggers"),children:"Triggers"}),n.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${D==="controls"?" active":""}`,onClick:()=>Y("controls"),children:"Controls"}),n.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${D==="utilities"?" active":""}`,onClick:()=>Y("utilities"),children:"Utilities"}),n.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${D==="data"?" active":""}`,onClick:()=>Y("data"),children:"Data"})]})]}),n.jsx("div",{className:"w6w-stepbuilder-content",children:D==="connected"?n.jsx(wd,{data:S,query:$,appsFilter:x,onSelectApp:oe,onSelectCallable:J,theme:o}):D==="functions"?n.jsx(_o,{family:"function",query:$,excludeIds:A,onSelect:P=>J({family:"function",...P})}):D==="workflows"?n.jsx(_o,{family:"workflow",query:$,excludeIds:A,onSelect:P=>J({family:"workflow",...P})}):D==="apps"?n.jsx(at,{search:!1,searchValue:$,onSelectApp:oe,theme:o,filter:x,ids:g}):D==="ai"?n.jsx(at,{search:!1,searchValue:$,onSelectApp:oe,theme:o,category:te?void 0:"ai",ids:g,filter:P=>{var H;return((x==null?void 0:x(P))??!0)&&(te||(((H=P.categories)==null?void 0:H.includes("ai"))??!1))},emptyMessage:"No AI apps registered yet."}):D==="triggers"?n.jsx(nd,{query:$,onSelect:L,onSelectApp:Z,theme:o,appsFilter:x,appsIds:g}):D==="controls"?n.jsx(sd,{query:$,onSelect:L}):D==="data"?n.jsx(rd,{query:$,onSelect:L}):n.jsx(od,{query:$,onSelect:L})})]})]})})}function Pt(e,...t){const s=t.filter(Boolean).join(" ").toLowerCase();return e.trim().toLowerCase().split(/\s+/).every(o=>s.includes(o))}function ji(e,t){return Pt(t,e.label,e.displayName,e.app,e.action)}function Qs({nodes:e,onSelect:t,query:s}){const o=new Set,r=e.filter(i=>ji(i,s)?i.groupActions?o.has(i.app)?!1:(o.add(i.app),!0):!0:!1);return r.length?n.jsx("div",{className:"w6w-stepbuilder-list",children:r.map(i=>n.jsx(Ni,{node:i,onSelect:t},`${i.app}:${i.action}`))}):n.jsxs("p",{className:"w6w-muted w6w-small",children:["No nodes match “",s,"”."]})}function Ni({node:e,onSelect:t}){return n.jsxs("button",{type:"button",className:"w6w-stepbuilder-item",onClick:()=>t(e),children:[n.jsx(Cn,{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 nd({query:e,onSelect:t,onSelectApp:s,theme:o,appsFilter:r,appsIds:i}){var b;const a=ye(),l=pt.filter(m=>m.group==="trigger"&&ji(m,e)),[c,u]=w.useState(!1),d=Si([],r,void 0,i,{resolveInline:!0});if(c)return n.jsxs("div",{className:"w6w-stack",children:[n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:()=>u(!1),children:"← Back"}),n.jsx(at,{onSelectApp:s,theme:o,filter:r,ids:i?[...i]:void 0,hasTriggers:!0,search:!1,searchValue:e,emptyMessage:"No apps declare triggers yet."})]});const p=d.apps.filter(m=>(m.triggerCount??0)>0&&Pt(e,m.displayName,m.id)).sort(_t(m=>m.displayName)).map(m=>n.jsx(Ci,{app:m,theme:o,onSelect:s},m.id));d.moreApps&&p.push(n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:d.loadMoreApps,children:"Load more"},"__load_more_apps"));let h;return d.state==="error"?h=n.jsx("div",{className:"w6w-result w6w-error",children:d.error}):d.state==="loading"?h=n.jsx("p",{className:"w6w-muted w6w-small",children:"Loading…"}):e.trim()&&((b=d.appIds)!=null&&b.length)&&typeof a.listAppsPage=="function"?h=n.jsx(at,{search:!1,searchValue:e,ids:d.appIds,hasTriggers:!0,filter:r,onSelectApp:s,theme:o}):p.length===0?h=n.jsxs("p",{className:"w6w-muted w6w-small w6w-readytouse-empty",children:[e.trim()?`No connected apps match “${e}”.`:"No connected apps with triggers yet"," ","·"," ",n.jsx("button",{type:"button",className:"w6w-linkbtn",onClick:()=>u(!0),children:"Search all apps"})]}):h=n.jsx("div",{className:"w6w-stepbuilder-list w6w-stepbuilder-scroll",children:p}),n.jsxs("div",{className:"w6w-apppicker-host",children:[n.jsxs("div",{className:"w6w-readytouse","data-cols":2,children:[n.jsxs("section",{className:"w6w-readytouse-col","data-col":"your-apps",children:[n.jsx("h4",{className:"w6w-readytouse-heading",children:"Your apps"}),h]}),n.jsx("div",{className:"w6w-readytouse-stack",children:n.jsxs("section",{className:"w6w-readytouse-col","data-col":"built-in",children:[n.jsx("h4",{className:"w6w-readytouse-heading",children:"Built-in"}),n.jsxs("div",{className:"w6w-stepbuilder-list w6w-stepbuilder-scroll",children:[l.length===0&&n.jsxs("p",{className:"w6w-muted w6w-small",children:["No built-in triggers match “",e,"”."]}),l.map(m=>n.jsx(Ni,{node:m,onSelect:t},`${m.app}:${m.action}`))]})]})})]}),n.jsx("div",{className:"w6w-readytouse-footer",children:n.jsx("button",{type:"button",className:"w6w-btn",onClick:()=>u(!0),children:"Search all apps"})})]})}function sd({onSelect:e,query:t}){const s=pt.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(Qs,{nodes:s,onSelect:e,query:t})]})}function od({onSelect:e,query:t}){const s=pt.filter(o=>o.group!=="control"&&o.group!=="trigger"&&o.app!==Lt&&o.app!==ps&&o.app!==De&&!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(Qs,{nodes:s,onSelect:e,query:t})]})}function rd({onSelect:e,query:t}){const s=pt.filter(o=>(o.app===Lt||o.app===De||o.app===ps)&&!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(Qs,{nodes:s,onSelect:e,query:t})]})}function id({node:e,onAdd:t,onClose:s,onDone:o,onDraftChange:r,onOpenStep:i,workflowId:a,upstreamSteps:l=[],loop:c}){const[u,d]=w.useState(e),f=e.groupActions?pt.filter(q=>q.app===e.app&&!q.hidden):[],[p,h]=w.useState(()=>dn(u.app,u.action)),b=!Et(u.app),m=Zs(a??"",l,b&&!!a),x=Xs(m,yi(c)),[g,y]=w.useState("configure"),[N,A]=w.useState("props"),[k,C]=w.useState("{}"),[v,E]=w.useState({}),R=jt(u.params,p),[F,O]=w.useState(null),T=()=>({uses:{app:u.app,action:u.action},with:p,...v});w.useEffect(()=>{if(!r)return;const q=t(T());q&&O(q),q&&u.app===Le&&(i==null||i(q))},[]),w.useEffect(()=>{!r||F===null||r(F,T())},[F,p,v,u]);const I=q=>{q==="code"&&C(Gs(T())),A(q)},M=()=>t(T());return n.jsxs("div",{className:"w6w-stepconfig",children:[n.jsxs("div",{className:"w6w-tabsbar",children:[n.jsxs("div",{className:"w6w-subtabs",children:[n.jsx("button",{type:"button",className:`w6w-subtab${g==="configure"?" active":""}`,onClick:()=>y("configure"),children:"Configure"}),b&&n.jsx("button",{type:"button",disabled:!R,title:R?void 0:"Fill the required fields first",className:`w6w-subtab${g==="test"?" active":""}`,onClick:()=>R&&y("test"),children:"Test"})]}),n.jsx(Rn,{view:N,customized:Sn(p),onChange:I,disabled:g!=="configure"})]}),n.jsxs("div",{className:"w6w-stepconfig-body",children:[g==="configure"&&N==="props"&&f.length>1&&n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"Action"}),n.jsx("select",{className:"w6w-input","aria-label":"Action",value:u.action,onChange:q=>{const D=f.find($=>$.action===q.target.value);if(!D)return;const Y=dn(D.app,D.action);h(Object.fromEntries(D.params.flatMap($=>$.key in p?[[$.key,p[$.key]]]:$.key in Y?[[$.key,Y[$.key]]]:[]))),d(D)},children:f.map(q=>n.jsx("option",{value:q.action,children:q.label},q.action))})]}),g==="configure"&&(N==="props"?u.app===Vt?n.jsx("p",{className:"w6w-muted w6w-small",children:qo}):u.action==="wait"&&Et(u.app)?n.jsx(Kr,{values:p,onChange:h}):u.action==="if"&&Et(u.app)?n.jsx(kn,{values:p,onChange:h}):u.app===fs?n.jsx(Tr,{values:p,onChange:h}):u.app===qe?n.jsx(Er,{values:p,onChange:h}):n.jsx(He,{params:u.params,values:p,onChange:h}):N==="code"?n.jsx(lt,{value:k,onChange:()=>{},readOnly:!0,minHeight:"240px",height:"100%","aria-label":"Node JSON",copyable:!0}):N==="params-code"?n.jsx(Is,{values:p,onChange:h}):n.jsx(Os,{config:v,onChange:E,failureHandling:!Ft(u.app),retryControls:!Et(u.app)&&u.app!==wn})),g==="test"&&b&&(Ft(u.app)?n.jsx(Jr,{app:u.app,action:u.action,fields:p.fields}):n.jsx(eo,{app:u.app,action:u.action,values:p,canRun:R,state:x}))]}),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"}),g==="configure"&&b?n.jsx("button",{type:"button",className:"w6w-btn",disabled:!R,onClick:()=>y("test"),children:"Next →"}):n.jsx("button",{type:"button",className:"w6w-btn",onClick:F!==null?o??s:M,children:F!==null?"Done":"Add node"})]})]})}function _o({family:e,query:t,excludeIds:s,onSelect:o}){const r=ye(),[i,a]=w.useState(null),[l,c]=w.useState(null),u=e==="function"?"Functions":"Workflows";w.useEffect(()=>{let m=!1;return(e==="function"?r.listFunctions():r.listWorkflows()).then(g=>!m&&a(g)).catch(g=>!m&&c(g.message)),()=>{m=!0}},[r,e]);const d=m=>n.jsx("div",{className:"w6w-apppicker-host",children:m});if(l)return d(n.jsx("div",{className:"w6w-result w6w-error",children:l}));if(i===null)return d(n.jsxs("p",{className:"w6w-muted w6w-small",children:["Loading ",u.toLowerCase(),"…"]}));if(i.length===0)return d(n.jsxs("p",{className:"w6w-muted w6w-small",children:["No ",u.toLowerCase()," registered yet."]}));const f=gt,p=t.trim().toLowerCase(),h=is(i,s).sort(_t(f)),b=p?h.filter(m=>f(m).toLowerCase().includes(p)||m.id.toLowerCase().includes(p)):h;return d(n.jsx("div",{className:"w6w-stepbuilder-apps",children:b.length===0?n.jsxs("p",{className:"w6w-muted w6w-small",children:["No ",u.toLowerCase()," match “",t,"”."]}):n.jsx("div",{className:"w6w-stepbuilder-list w6w-stepbuilder-scroll",children:b.map(m=>n.jsx(as,{family:e,item:m,onSelect:o},m.id))})}))}const ad=["string","number","boolean","json"];function ld(e){var r;const t=(e.nodes??e.steps??[]).find(i=>Ft(i.uses.app)),s=(r=t==null?void 0:t.with)==null?void 0:r.fields;if(!Array.isArray(s))return[];const o=[];for(const i of s){if(typeof i!="object"||i===null)continue;const a=i,l=typeof a.key=="string"?a.key:"";if(!l)continue;const c=typeof a.type=="string"?a.type:"string";o.push({key:l,label:l,type:ad.includes(c)?c:"string",default:a.default,required:!!a.required})}return o}function cd({family:e,targetId:t,targetLabel:s,onAdd:o,onClose:r,onDone:i,onDraftChange:a}){const l=ye(),[c,u]=w.useState(null),[d,f]=w.useState(null),[p,h]=w.useState({}),[b,m]=w.useState(!0),[x,g]=w.useState("configure"),[y,N]=w.useState(null);w.useEffect(()=>{let v=!1;return u(null),f(null),(e==="function"?l.getFunction(t).then(R=>R.inputs):l.getWorkflow(t).then(ld)).then(R=>!v&&u(R)).catch(R=>!v&&f(R.message)),()=>{v=!0}},[l,e,t]);const A=c!==null&&jt(c,p),k=()=>({uses:{app:wn,action:"call"},with:{targetKind:e,targetId:t,inputs:p,wait:b}});w.useEffect(()=>{if(!a)return;const v=o(k());v&&N(v)},[]),w.useEffect(()=>{!a||y===null||a(y,k())},[y,p,b]);const C=()=>o(k());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${x==="configure"?" active":""}`,onClick:()=>g("configure"),children:"Configure"}),n.jsx("button",{type:"button",disabled:!A,title:A?void 0:"Fill the required fields first",className:`w6w-subtab${x==="test"?" active":""}`,onClick:()=>A&&g("test"),children:"Test"})]})}),n.jsx("div",{className:"w6w-stepconfig-body",children:x==="configure"?n.jsxs("div",{className:"w6w-stack",children:[d?n.jsx("div",{className:"w6w-result w6w-error",children:d}):c===null?n.jsxs("p",{className:"w6w-muted w6w-small",children:["Loading ",s,"’s inputs…"]}):c.length===0?n.jsxs("p",{className:"w6w-muted w6w-small",children:[s," declares no inputs — it can be called as-is."]}):n.jsx(He,{params:c,values:p,onChange:h}),n.jsxs("label",{className:"w6w-field",children:[n.jsxs("span",{children:[n.jsx("input",{type:"checkbox",checked:b,onChange:v=>m(v.target.checked)})," ","Wait for completion"]}),n.jsx("span",{className:"w6w-hint",children:"On: block until the sub-run finishes and expose its output. Off: return a run handle and continue."})]})]}):n.jsx(ud,{family:e,targetId:t,inputs:p,canRun:A})}),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"}),x==="configure"?n.jsx("button",{type:"button",className:"w6w-btn",disabled:!A,onClick:()=>g("test"),children:"Next →"}):n.jsx("button",{type:"button",className:"w6w-btn",onClick:y!==null?i??r:C,children:y!==null?"Done":"Add node"})]})]})}function ud({family:e,targetId:t,inputs:s,canRun:o}){const r=ye(),[i,a]=w.useState(null),l=async()=>{if(!(!o||(i==null?void 0:i.status)==="running")){a({status:"running"});try{if(e==="function"){const c=await r.invokeFunction(t,s);a({status:"done",output:c,terminal:!0})}else{const c=await r.runWorkflow(t,{input:s});a({status:"done",output:c.output,runId:c.runId,terminal:c.terminal,error:c.error})}}catch(c){a({status:"error",error:c.message??String(c)})}}};return n.jsxs("div",{className:"w6w-steptest",children:[n.jsxs("div",{className:"w6w-steptest-bar",children:[n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",disabled:!o||(i==null?void 0:i.status)==="running",onClick:l,children:(i==null?void 0:i.status)==="running"?"Running…":"▶ Test run"}),!o&&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("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(Re,{value:i.output,maxHeight:220})]})]})}function dd(e){const t={};for(const s of e)ct(s.default)&&(t[s.key]=s.default);return t}function jt(e,t){const s=xr(t);if(s===null)return!1;if(s===void 0)return!0;const o=vt(e),r=a=>{var l;return s[a]!==void 0?s[a]:(l=o.find(c=>c.key===a))==null?void 0:l.default},i=(a,l,c)=>a.every(u=>{const d=ie.effectiveParam(u,c);if(d.type==="section")return i(d.children??[],l,c);if(d.type==="group"){const p=d.children??[],h=vt(p),b=x=>g=>{const y=h.find(N=>N.key===g);return y?x[g]!==void 0?x[g]:y.default:c(g)};if(d.repeat){const x=Array.isArray(l[d.key])?l[d.key]:[];return x.length===0?!d.required:x.every(g=>{const y=g??{};return i(p,y,b(y))})}const m=l[d.key]??{};return i(p,m,b(m))}if(!d.required||!Jt(u,c))return!0;const f=l[d.key]??d.default;return f==null?!1:typeof f=="string"?f.trim()!=="":!0});return i(e,s,r)}function ki(e){const t=e==null?void 0:e.testRequired;return typeof t=="boolean"?t:!0}function pd(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 fd(e){const t=e==null?void 0:e.apiCalls;return Array.isArray(t)?t:[]}function hd({log:e,onClose:t}){return n.jsx(Se,{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(Re,{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(Re,{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(ni,{calls:e.apiCalls,title:!1,defaultOpen:!0}):n.jsxs("div",{className:"w6w-muted w6w-small",children:["No HTTP request reached the vendor API — the action",e.response.ok?" made no outbound call":" failed before sending one","."]})]})]})})}const eo=w.forwardRef(function({app:t,action:s,connectionId:o,values:r,canRun:i,hideRunButton:a,persist:l,state:c,onBusyChange:u,onResult:d},f){const p=ye(),h=bs(),b=ga(),[m,x]=w.useState(null),[g,y]=w.useState(null),[N,A]=w.useState(!1),k=w.useRef(!1),[C,v]=w.useState(null),E=l==null?void 0:l.workflowId,R=l==null?void 0:l.stepId,F=ht().nodeMeta,O=R?F==null?void 0:F[R]:void 0;w.useEffect(()=>{if(!E||!R)return;let M=!1;return p.listStepTests(E,R).then(q=>{let D;for(const Y of q)!Y.lastRunAt||!Y.lastRunStatus||(!D||Date.parse(Y.lastRunAt)>Date.parse(D.lastRunAt))&&(D=Y);!D||!D.lastRunAt||M||k.current||(D.lastRunStatus==="succeeded"?x({status:"done",value:D.lastRunOutput,...D.lastRunMeta?{meta:D.lastRunMeta}:{}}):x({status:"error",error:typeof D.lastRunError=="string"?D.lastRunError:D.lastRunError==null?"Test failed":JSON.stringify(D.lastRunError)}),v(D.lastRunAt))}).catch(()=>{}),()=>{M=!0}},[p,E,R]);const T=async()=>{var $;if(!i||(m==null?void 0:m.status)==="running")return;k.current=!0,v(null),x({status:"running"}),u==null||u(!0);let M;const q=new Date,D={method:"POST",path:`/apps/${encodeURIComponent(t)}/actions/${encodeURIComponent(s)}/invoke`,body:{params:r,...o?{connectionId:o}:{},...h?{project:h}:{},...c?{state:c}:{},...b?{workflowId:b}:{}}},Y=G=>y({startedAt:q.toLocaleString(),durationMs:Date.now()-q.getTime(),request:D,response:G,apiCalls:fd(G.body)});try{const G=await p.invokeAction(t,s,r,{...o?{connectionId:o}:{},project:h,...c?{state:c}:{},...b?{workflowId:b}:{}});Y({ok:!0,body:G}),M={status:"done",value:G.value,logs:G.logs,...G.meta?{meta:G.meta}:{}}}catch(G){const ne=G;Y({ok:!1,...typeof ne.status=="number"?{status:ne.status}:{},body:pd(G)}),M={status:"error",error:ne.message??String(G),errorCode:ne.code,logs:ne.logs}}if(x(M),d==null||d(M.status==="done"),l){($=p.saveTestInput)==null||$.call(p,l.workflowId,l.stepId,Ls(l.input)).catch(G=>console.error("test input save failed",G));try{const G=await p.saveStepTest(l.workflowId,l.stepId,{input:l.input,with:r});await p.recordStepTestRun(l.workflowId,l.stepId,{stepTestId:G.id,status:M.status==="done"?"succeeded":"failed",input:l.input,output:M.status==="done"?M.value:void 0,error:M.status==="error"?M.error:void 0,...M.status==="done"&&M.meta?{meta:M.meta}:{}})}catch(G){console.error("step test persist failed",G)}}u==null||u(!1)};w.useImperativeHandle(f,()=>({run:T}));const I=m&&m.status!=="running"?m.logs:void 0;return n.jsxs("div",{className:"w6w-steptest",children:[(!a||g)&&n.jsxs("div",{className:"w6w-steptest-bar",children:[!a&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",disabled:!i||(m==null?void 0:m.status)==="running",onClick:T,children:(m==null?void 0:m.status)==="running"?"Running…":"▶ Test run"}),g&&(m==null?void 0:m.status)!=="running"&&n.jsxs("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>A(!0),title:"The full request and response of the last test run",children:["Log",g.apiCalls.length>0?` (${g.apiCalls.length})`:""]}),!a&&!i&&n.jsx("span",{className:"w6w-muted w6w-small",children:"Fill the required fields to test."})]}),N&&g&&n.jsx(hd,{log:g,onClose:()=>A(!1)}),C&&((m==null?void 0:m.status)==="done"||(m==null?void 0:m.status)==="error")&&n.jsxs("div",{className:"w6w-muted w6w-small w6w-testout-restored",children:["Last run · ",new Date(C).toLocaleString()]}),(m==null?void 0:m.status)==="error"&&n.jsxs("div",{className:"w6w-result w6w-error",children:[m.errorCode&&n.jsx("div",{className:"w6w-small",style:{opacity:.75,marginBottom:4},children:n.jsx("code",{children:m.errorCode})}),m.error]}),(m==null?void 0:m.status)==="done"&&n.jsxs("div",{className:"w6w-testout",children:[n.jsx("div",{className:"w6w-testout-label",children:"Result (return value)"}),n.jsx(Re,{value:m.value,maxHeight:220}),(m.meta||O)&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"w6w-testout-label",children:"Metadata"}),n.jsx(Re,{value:{...O,...m.meta},maxHeight:220})]})]}),(m==null?void 0:m.status)!=="done"&&(m==null?void 0:m.status)!=="running"&&O&&n.jsxs("div",{className:"w6w-testout","data-testid":"steptest-static-meta",children:[n.jsx("div",{className:"w6w-testout-label",children:"Metadata"}),n.jsx(Re,{value:O,maxHeight:220})]}),I&&I.length>0&&n.jsxs("div",{className:"w6w-testout",children:[n.jsx("div",{className:"w6w-testout-label",children:"Console output"}),n.jsx("pre",{className:"w6w-result w6w-testout-console",style:{whiteSpace:"pre-wrap",maxHeight:160,overflow:"auto",margin:0},children:I.join(`
|
|
21
|
+
`)})]})]})}),Lo=12,Qt=new Set;function Si(e,t,s,o,r){const i=o&&o.length>0?new Set(o):null,a=L=>(i?i.has(L.id):!0)&&((t==null?void 0:t(L))??!0),l=ye(),[c,u]=w.useState(null),[d,f]=w.useState(null),[p,h]=w.useState(null),[b,m]=w.useState(null),[x,g]=w.useState(null),[y,N]=w.useState(()=>new Map),[A,k]=w.useState(()=>new Set),[C,v]=w.useState(Qt),E=w.useRef(Qt),R=w.useCallback(L=>{E.current=L,v(L)},[]),F=w.useRef(Qt),O=e.includes("function"),T=e.includes("workflow"),I=typeof l.listAppsByIds=="function";w.useEffect(()=>{let L=!1;const z=Z=>!L&&g(Z.message);return l.listConnections().then(Z=>{if(L)return;const W=[],J=new Set,te=new Map;for(const S of Z)Ye(S.appId)||(I&&!(r!=null&&r.resolveInline)&&S.app&&!te.has(S.appId)&&te.set(S.appId,{...S.app,id:S.appId}),!J.has(S.appId)&&(J.add(S.appId),W.push(S.appId)));te.size>0&&(F.current=new Set(te.keys()),N(S=>new Map([...S,...te])),k(S=>new Set([...S,...te.keys()]))),u(W)}).catch(z),O?l.listFunctions().then(Z=>!L&&h(Z)).catch(z):h([]),T?l.listWorkflows().then(Z=>!L&&m(Z)).catch(z):m([]),()=>{L=!0}},[l,I,O,T,r==null?void 0:r.resolveInline]),w.useEffect(()=>{if(I)return;const L=l.listApps;if(typeof L!="function"){f([]);return}let z=!1;return L().then(Z=>!z&&f(Z)).catch(Z=>!z&&g(Z.message)),()=>{z=!0}},[l,I]);const M=w.useRef(!0);w.useEffect(()=>(M.current=!0,()=>{M.current=!1}),[]);const q=w.useCallback(L=>{const z=l.listAppsByIds;!z||L.length===0||E.current.size>0||(R(new Set(L)),z(L).then(Z=>{M.current&&(R(Qt),N(W=>{const J=new Map(W);for(const te of Z)J.set(te.id,te);return J}),k(W=>new Set([...W,...L])))}).catch(Z=>M.current&&g(Z.message)))},[l,R]),D=w.useRef(!1);w.useEffect(()=>{if(!I||c===null||D.current)return;const L=Ln(c,F.current,Lo);L.length!==0&&(D.current=!0,q(L))},[I,c,q]);const Y=()=>{if(!I||c===null||E.current.size>0)return;const L=new Set([...A,...E.current]);q(Ln(c,L,Lo))};if(x)return{state:"error",error:x,apps:[],fns:[],wfs:[],moreApps:!1,loadMoreApps:Y};if(p===null||b===null)return{state:"loading",apps:[],fns:[],wfs:[],moreApps:!1,loadMoreApps:Y};const $=is(p,s),G=is(b,s);if(I){if(c===null)return{state:"loading",apps:[],fns:$,wfs:G,moreApps:!1,loadMoreApps:Y};if(c.length>0&&A.size===0)return{state:"loading",apps:[],fns:$,wfs:G,moreApps:!1,loadMoreApps:Y};const L=ma(c,y).filter(a),z=C.size===0&&Ln(c,new Set([...A,...C]),1).length>0;return{state:L.length===0&&$.length===0&&G.length===0&&!z?"empty":"ready",apps:L,appIds:c.filter(W=>!i||i.has(W)),fns:$,wfs:G,moreApps:z,loadMoreApps:Y}}if(d===null)return{state:"loading",apps:[],fns:$,wfs:G,moreApps:!1,loadMoreApps:Y};const ne=new Set(c??[]),oe=d.filter(L=>!Ye(L.id)&&a(L)&&(ne.has(L.id)||L.zeroCredential===!0));return{state:oe.length===0&&$.length===0&&G.length===0?"empty":"ready",apps:oe,fns:$,wfs:G,moreApps:!1,loadMoreApps:Y}}function is(e,t){return t&&t.length>0?e.filter(s=>!t.includes(s.id)):[...e]}function _t(e){return(t,s)=>e(t).localeCompare(e(s),void 0,{sensitivity:"base"})}function gt(e){const t=e.displayName;return t!=null&&t.trim()?t:"name"in e?e.name:e.id}function as({family:e,item:t,onSelect:s}){const o=gt(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(Cn,{icon:Qu[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 md(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 Ci({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(ft,{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 wd({data:e,query:t,appsFilter:s,onSelectApp:o,onSelectCallable:r,theme:i}){var x;const a=ye(),l=g=>n.jsx("div",{className:"w6w-apppicker-host",children:g});if(e.state==="error")return l(n.jsx("div",{className:"w6w-result w6w-error",children:e.error}));if(e.state==="loading")return l(n.jsx("p",{className:"w6w-muted w6w-small",children:"Loading…"}));const c=e.apps.filter(g=>Pt(t,g.displayName,g.id)).sort(_t(g=>g.displayName)),u=e.fns.filter(g=>Pt(t,gt(g),g.id)).sort(_t(gt)),d=e.wfs.filter(g=>Pt(t,gt(g),g.id)).sort(_t(gt)),f=md,p=c.map(g=>n.jsx(Ci,{app:g,theme:i,onSelect:o},g.id));e.moreApps&&p.push(n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:e.loadMoreApps,children:"Load more"},"__load_more_apps"));const h=t.trim()&&((x=e.appIds)!=null&&x.length)&&typeof a.listAppsPage=="function"?n.jsxs("section",{className:"w6w-readytouse-col",children:[n.jsx("h4",{className:"w6w-readytouse-heading",children:"Connected apps"}),n.jsx(at,{search:!1,searchValue:t,ids:e.appIds,filter:s,onSelectApp:o,theme:i})]}):f("Connected apps",p),b=[f("Functions",u.map(g=>n.jsx(as,{family:"function",item:g,onSelect:y=>r({family:"function",...y})},g.id))),f("Workflows",d.map(g=>n.jsx(as,{family:"workflow",item:g,onSelect:y=>r({family:"workflow",...y})},g.id)))].filter(Boolean),m=(h?1:0)+(b.length>0?1:0);return l(m?n.jsxs("div",{className:"w6w-readytouse","data-cols":m,children:[h,b.length>0&&n.jsx("div",{className:"w6w-readytouse-stack",children:b})]}):n.jsxs("p",{className:"w6w-muted w6w-small",children:["Nothing ready to use matches “",t,"”."]}))}function Ai(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 Ei({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 bd({kind:e="action",onOpenStep:t,appId:s,app:o,onAdd:r,onClose:i,onDone:a,onDraftChange:l,onChangeApp:c,theme:u,workflowId:d,stepId:f,upstreamSteps:p=[],loop:h,initialAction:b,initialConnection:m,initialWith:x}){const g=ye(),y=e==="trigger",N=y?"a trigger":"an action",[A,k]=w.useState(null),[C,v]=w.useState(null),[E,R]=w.useState(null),[F,O]=w.useState(null),[T,I]=w.useState(m??""),[M,q]=w.useState(),D=Ms(),Y=w.useRef(D);Y.current=D;const $=M?St({uses:{app:s,action:"",connectionRef:M}},D==null?void 0:D.connections)??"":T,G=w.useCallback(ee=>{q(void 0),I(ee)},[]),[ne,oe]=w.useState(b??""),[X,L]=w.useState(x??{}),z=w.useRef(null),[Z,W]=w.useState(!1),[J,te]=w.useState(b&&x?"configure":"setup"),[S,U]=w.useState("props"),[V,P]=w.useState("{}"),[H,ae]=w.useState({});w.useEffect(()=>{let ee=!1;O(null);const B=y?Ai(g,s):g.getAppActions(s);return Promise.all([g.getAppAuth(s),g.listConnectionsForApp(s),B]).then(([Q,de,Je])=>{if(ee)return;const st=Po(s,Q,de);k(Q),v(st),R(Je);const ke=Y.current,$e=Qr({id:f??"",uses:{app:s,action:""}},st,(ke==null?void 0:ke.nodes)??[],(ke==null?void 0:ke.connections)??{},m);$e.connectionRef?q($e.connectionRef):G($e.connection??"")}).catch(Q=>!ee&&O(Q.message)),()=>{ee=!0}},[g,s,y,G,m,f]);const fe=async()=>{const ee=await g.listConnectionsForApp(s);v(Po(s,A??[],ee))},he=(A??[]).filter(ee=>ee.available!==!1),ge=he.some(ee=>ee.autoSatisfied===!0&&(ee.type==="tenantAuth"||ee.type==="jit")),ve=ge&&!he.some(ee=>ee.autoSatisfied===!0&&ee.type==="tenantAuth"),Ae=he.length>0&&!ge,Te=(C??[]).length>0,le=(E??[]).find(ee=>ee.key===ne),Ee=y?oi(s,E,ne,X):null,mt=[...E??[]].sort((ee,B)=>(ee.title??ee.key).localeCompare(B.title??B.key,void 0,{sensitivity:"base"})),Ue=ki(o),[Ct,et]=w.useState(!1);w.useEffect(()=>{if(!Ue||!d||!f)return;let ee=!1;return g.listStepTests(d,f).then(B=>{!ee&&B.some(Q=>Q.lastRunStatus==="succeeded")&&et(!0)}).catch(()=>{}),()=>{ee=!0}},[g,Ue,d,f]);const Ve=Zs(d??"",p,!!d),tt=Xs(Ve,yi(h)),me=!!ne&&(!Ae||Te&&!!$)&&(!Ee||Ee.selected.length>0),Oe=me&&!!le&&jt(le.params??[],X),nt=me,xe=(C??[]).find(ee=>ee.id===$);function je(){return{uses:{app:s,action:(le==null?void 0:le.key)??ne,...M?{connectionRef:M}:$?{connection:$}:{},...y?{trigger:!0}:{}},with:X,...H}}function Ie(){le&&r(je())}const[Ne,At]=w.useState(null);w.useEffect(()=>{if(!l||Ne!==null||!me||Ee&&J==="setup")return;const ee=r(je());ee&&At(ee),ee&&y&&(t==null||t(ee))},[l,Ne,me,J]),w.useEffect(()=>{!l||Ne===null||l(Ne,je())},[Ne,X,H,$,M]);const ze=ee=>{ee==="code"&&P(Gs(je())),U(ee)};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${J==="setup"?" active":""}`,onClick:()=>te("setup"),children:"Setup"}),n.jsx("button",{type:"button",disabled:!me,title:me?void 0:"Complete Setup first",className:`w6w-subtab${J==="configure"?" active":""}`,onClick:()=>me&&te("configure"),children:"Configure"}),n.jsx("button",{type:"button",disabled:!Oe,title:Oe?void 0:"Fill the required fields first",className:`w6w-subtab${J==="test"?" active":""}`,onClick:()=>Oe&&te("test"),children:"Test"})]}),n.jsx(Rn,{view:S,customized:Sn(X),onChange:ze,disabled:J!=="configure"})]}),n.jsxs("div",{className:"w6w-stepconfig-body",children:[J==="setup"&&n.jsxs("div",{className:"w6w-stack",children:[F&&n.jsx("div",{className:"w6w-result w6w-error",children:F}),A===null&&!F&&n.jsx("p",{className:"w6w-muted w6w-small",children:"Loading…"}),n.jsxs("div",{className:"w6w-field",children:[n.jsx("span",{children:"App"}),n.jsxs("div",{className:"w6w-app-conn-row",ref:z,children:[n.jsxs("button",{type:"button",className:"w6w-app-conn-btn","aria-label":"App",onClick:c,disabled:!c,children:[o&&n.jsx(ft,{src:o.iconSvg,srcDark:o.iconSvgDark,brandColor:o.brandColor,name:o.displayName,theme:u,size:20}),n.jsx("span",{className:"w6w-conn-label-name",children:(o==null?void 0:o.displayName)??s})]}),n.jsx(ti,{step:{id:Ne??f??"",uses:{app:s,action:ne,...M?{connectionRef:M}:{connection:$||void 0}}},conns:C,failed:!!F,open:Z,onOpenChange:W,anchorRef:z,onChangeConnection:G,onChangeConnectionRef:q,onConnectionCreated:()=>{fe()}})]}),ve&&(xe==null?void 0:xe.builtIn)&&n.jsx("span",{className:"w6w-hint",children:"Scheduled or queued runs need a stored connection. Choose one from the connection menu."}),A!==null&&Ae&&!Te&&n.jsx("span",{className:"w6w-hint",children:"This app needs a connection before its actions can run."})]}),E!==null&&(E.length===0?n.jsx("p",{className:"w6w-muted w6w-small",children:y?"This app declares no triggers.":"This app exposes no actions."}):Ee?n.jsx(si,{choices:Ee,onChange:ee=>{oe(Ee.triggerKey),L(B=>({...B,actions:ee}))}}):n.jsxs("label",{className:"w6w-field",children:[n.jsxs("span",{children:[y?"Trigger":"Action",ne?"":" *"]}),n.jsx(kt,{value:ne,placeholder:`— pick ${N} —`,mode:"combobox",listMaxHeight:200,onChange:ee=>{var B;oe(ee),L(dd(((B=(E??[]).find(Q=>Q.key===ee))==null?void 0:B.params)??[])),et(!1)},options:mt.map(ee=>({value:ee.key,label:`${ee.title??ee.key} (${ee.key})`}))}),(le==null?void 0:le.description)&&n.jsx("span",{className:"w6w-hint",children:le.description})]}))]}),J==="configure"&&(le?S==="props"?n.jsx(He,{params:le.params??[],values:X,onChange:L,dynamic:{appId:s,actionKey:le.key,connectionId:$||void 0,appName:o==null?void 0:o.displayName}}):S==="code"?n.jsx(lt,{value:V,onChange:()=>{},readOnly:!0,minHeight:"240px",height:"100%","aria-label":"Node JSON",copyable:!0}):S==="params-code"?n.jsx(Is,{values:X,onChange:L}):n.jsx(Os,{config:H,onChange:ae,failureHandling:!y}):n.jsxs("p",{className:"w6w-muted w6w-small",children:["Pick ",N," in Setup first."]})),J==="test"&&(le&&y?n.jsx(Ei,{title:le.title??le.key,app:(o==null?void 0:o.displayName)??s}):le?n.jsx(eo,{app:s,action:le.key,connectionId:$||void 0,values:X,canRun:me&&jt(le.params??[],X),state:tt,onResult:et}):n.jsx("p",{className:"w6w-muted w6w-small",children:"Pick an action in Setup first."}))]}),J==="test"&&n.jsx("div",{className:"w6w-stepconfig-testnote",children:Ue&&!Ct&&n.jsx("span",{className:"w6w-muted w6w-small",children:"Not yet tested. You can publish without running a test."})}),n.jsxs("div",{className:"w6w-modal-actions w6w-stepconfig-footer",children:[n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:i,children:"Cancel"}),J==="test"?n.jsx("button",{type:"button",className:"w6w-btn",disabled:Ne===null&&!nt,onClick:Ne!==null?a??i:Ie,children:Ne!==null?"Done":"Add node"}):n.jsx("button",{type:"button",className:"w6w-btn",disabled:J==="setup"?!me:!Oe,onClick:()=>te(J==="setup"?"configure":"test"),children:"Next →"})]})]})}function gd({appId:e,app:t,onClose:s,onChangeApp:o,theme:r,initialConnection:i,onConnected:a}){const l=ye(),[c,u]=w.useState(null),[d,f]=w.useState(null),[p,h]=w.useState(null),[b,m]=w.useState(i??""),[x,g]=w.useState(!1),[y,N]=w.useState(!1);w.useEffect(()=>{let I=!1;return h(null),Promise.all([l.getAppAuth(e),l.listConnectionsForApp(e)]).then(([M,q])=>{if(I)return;u(M),f(q),!(M??[]).some(Y=>Y.autoSatisfied===!0)&&q.length>0&&m(q[0].id)}).catch(M=>!I&&h(M.message)),()=>{I=!0}},[l,e]);const A=async()=>{const I=await l.listConnectionsForApp(e);f(I),I.length>0&&m(M=>M||I[0].id)},k=(c??[]).filter(I=>I.available!==!1),C=k.some(I=>I.autoSatisfied===!0&&(I.type==="tenantAuth"||I.type==="jit")),v=C&&!k.some(I=>I.autoSatisfied===!0&&I.type==="tenantAuth"),E=k.length>0&&!C,R=(d??[]).length>0,F=!E||R&&!!b,O=(d??[]).find(I=>I.id===b),T=y||!b;return n.jsxs("div",{className:"w6w-stepconfig",children:[n.jsx("div",{className:"w6w-stepconfig-body",children:n.jsxs("div",{className:"w6w-stack",children:[p&&n.jsx("div",{className:"w6w-result w6w-error",children:p}),c===null&&!p&&n.jsx("p",{className:"w6w-muted w6w-small",children:"Loading…"}),n.jsxs("div",{className:"w6w-field",children:[n.jsx("span",{children:"App"}),n.jsxs("div",{className:"w6w-conn-label",children:[t&&n.jsx(ft,{src:t.iconSvg,srcDark:t.iconSvgDark,brandColor:t.brandColor,name:t.displayName,theme:r,size:20}),n.jsx("span",{className:"w6w-conn-label-name",children:(t==null?void 0:t.displayName)??e}),o&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:o,children:"Change"})]})]}),c!==null&&C&&n.jsxs("div",{className:"w6w-field",children:[n.jsx("span",{children:"Connection"}),n.jsxs("div",{className:"w6w-conn-label",children:[n.jsx("span",{className:"w6w-conn-label-name",children:"Connected automatically — this app needs no connection for your organization."}),n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:()=>g(!0),children:"Create connection"})]}),v&&n.jsx("span",{className:"w6w-hint",children:'A scheduled or queued run of this workflow still needs a connection configured on this step — use "Create connection" if this step will run on a schedule.'})]}),c!==null&&E&&(R?T?n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"Connection"}),n.jsxs("div",{style:{display:"flex",gap:6},children:[n.jsx("select",{value:b,onChange:I=>{m(I.target.value),N(!1)},style:{flex:1},children:(d??[]).map(I=>n.jsxs("option",{value:I.id,children:[I.displayName||I.id," ",I.state?`(${I.state})`:""]},I.id))}),n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>g(!0),children:"+ New"})]})]}):n.jsxs("div",{className:"w6w-field",children:[n.jsx("span",{children:"Connection"}),n.jsxs("div",{className:"w6w-conn-label",children:[n.jsxs("span",{className:"w6w-conn-label-name",children:[(O==null?void 0:O.displayName)||(O==null?void 0:O.id)||b,O!=null&&O.state?` (${O.state})`:""]}),n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:()=>N(!0),children:"Change"}),n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:()=>g(!0),children:"+ New"})]})]}):n.jsxs("div",{className:"w6w-result w6w-stepconfig-conn-empty",children:[n.jsx("div",{style:{marginBottom:8},children:"This app needs a connection before its actions can run."}),n.jsx("button",{type:"button",className:"w6w-btn",onClick:()=>g(!0),children:"Create connection"})]}))]})}),n.jsxs("div",{className:"w6w-modal-actions w6w-stepconfig-footer",children:[n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:s,children:"Cancel"}),n.jsx("button",{type:"button",className:"w6w-btn",disabled:!F||!t,onClick:()=>t&&a(b,t),children:"Next →"})]}),x&&n.jsx($s,{theme:r,initialAppId:e,onClose:()=>g(!1),onCreated:async({connectionId:I})=>{g(!1),m(I),N(!1),await A()}})]})}const yd=["props","code"];function xd(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function Ri({params:e,values:t,onChange:s,onValidityChange:o,readOnly:r,initialView:i="props"}){const a=e.length>0,[l,c]=w.useState(i),u=!a||l==="code",[d,f]=w.useState(()=>Fo(t)),[p,h]=w.useState(!0),b=w.useRef(!0),m=y=>{y!==b.current&&(b.current=y,h(y),o==null||o(y))},x=y=>{y==="code"&&f(Fo(t)),m(!0),c(y)},g=a?"Values (JSON)":"Payload";return n.jsxs("div",{className:"w6w-stack",children:[a&&n.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:n.jsx(Rn,{view:l,views:[...yd],onChange:y=>x(y)})}),u?n.jsxs("div",{className:"w6w-field",children:[n.jsx("span",{children:g}),n.jsx(lt,{value:d,onChange:f,readOnly:r,minHeight:"140px","aria-label":`${g} JSON`,onValidChange:y=>{const N=xd(y);m(N),N&&s(y)},onValidityChange:y=>{y.valid||m(!1)}}),!p&&n.jsx("span",{className:"w6w-hint",children:"This draft isn’t a JSON object yet — the collected values are unchanged until it is."})]}):n.jsx(He,{params:e,values:t,onChange:s,readOnly:r})]})}function Fo(e){return JSON.stringify(e??{},null,2)}function vd({title:e,message:t,onConfirm:s,onClose:o,confirmLabel:r="Confirm",cancelLabel:i="Cancel",destructive:a=!0,children:l}){return n.jsxs(Se,{title:e,onClose:o,children:[n.jsxs("div",{className:"w6w-modal-body",children:[n.jsx("p",{className:"w6w-muted w6w-small",children:t}),l]}),n.jsxs("div",{className:"w6w-modal-actions",children:[n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:o,children:i}),n.jsx("button",{type:"button",className:a?"w6w-btn w6w-btn-danger":"w6w-btn",onClick:s,children:r})]})]})}function Wt(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]=Wt(o);return t}case"array":return e.items?[Wt(e.items)]:[];default:return null}}function jd(e){const t={};for(const s of e??[])s&&typeof s.nodeId=="string"&&s.nodeId!==""&&(t[s.nodeId]=s);return t}function Tn(e){return e.sampleOmitted!==!0&&"sample"in e&&e.sample!==void 0}function On(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 Ti(e,t,s,o){const r=t[e],i=s[e];return r!==void 0&&(!i||!On(i,o==null?void 0:o[e]))||!i?r:Tn(i)?i.sample:Wt(i.shape)}function Nd(e,t,s){const o={};for(const r of new Set([...Object.keys(e),...Object.keys(t)])){const i=Ti(r,e,t,s);i!==void 0&&(o[r]=i)}return o}function kd(e,t,s){const o={...e};for(const[r,i]of Object.entries(t))Tn(i)&&(e[r]===void 0||On(i,s==null?void 0:s[r]))&&(o[r]=i.sample);return o}function Sd(e,t,s){const o={...e},r={};for(const[i,a]of Object.entries(t))e[i]!==void 0&&!On(a,s==null?void 0:s[i])||(delete o[i],r[i]=Tn(a)?a.sample:Wt(a.shape));return{fresh:o,persisted:r}}function Cd(e,t,s){const o={...e},r={};for(const[i,a]of Object.entries(t))Tn(a)&&(e[i]===void 0||On(a,s==null?void 0:s[i]))&&(delete o[i],r[i]=a.sample);return{fresh:o,persisted:r}}exports.AddConnectionModal=$s;exports.AnchoredFlyout=Gr;exports.ApiCallsPanel=ni;exports.AppIcon=ft;exports.AppPicker=at;exports.AppTriggerTestNote=Ei;exports.AuthFieldsForm=on;exports.CALL_APP=wn;exports.CONTROL_APP=Pe;exports.CanvasLayer=Ua;exports.CodeEditor=xs;exports.Combobox=kt;exports.ConditionEditor=kn;exports.ConfigViewToggle=Rn;exports.ConfirmModal=vd;exports.CredentialPicker=jr;exports.DATA_APP=Lt;exports.DeleteButton=Ar;exports.EACH_SOURCE_HANDLE=hn;exports.EDITOR_THEME_SPEC=ys;exports.ERROR_SOURCE_HANDLE=cs;exports.EventbriteTriggerPicker=si;exports.ExpressionEditorModal=zt;exports.ExpressionInput=Ht;exports.ExpressionOptionsProvider=$l;exports.FOREACH_DONE_ROUTE=yt;exports.HTML_PREVIEW_CSP=Or;exports.HtmlPreview=$r;exports.INTERNAL_NODES=pt;exports.IconButton=vn;exports.InternalIcon=Cn;exports.JsonEditor=lt;exports.LastUsedNote=zr;exports.Markdown=gs;exports.Modal=Se;exports.NodeConfigForm=Os;exports.ParamCustomization=Is;exports.ParamsForm=He;exports.PropertyEntryForm=Ri;exports.RACE_APP=Vt;exports.RACE_DESCRIPTION=qo;exports.RESULT_RENDER_MAX_CHARS=Lr;exports.ROUTER_APP=qe;exports.ResultViewer=Re;exports.RetryPolicyFields=yr;exports.RouterEditor=Er;exports.SCHEDULER_APP=ds;exports.SCRIPT_APP=Bo;exports.StepBuilderModal=td;exports.StepNameEditor=Rr;exports.StepTestRun=eo;exports.StopEditor=Tr;exports.TRIGGER_APP=mn;exports.TriggerFillForm=Jr;exports.W6WUIProvider=wa;exports.WEBHOOK_APP=Le;exports.WaitEditor=Kr;exports.WorkflowConnectionPicker=ti;exports.WorkflowConnectionsContext=ei;exports.WorkflowProjectProvider=ba;exports.ancestorIds=Ys;exports.applyConnect=ru;exports.applyStepProblems=Bc;exports.asFieldDefs=Ps;exports.bindingFieldsFor=Nr;exports.bridgeDeletedBodyStep=Qc;exports.buildBinding=kr;exports.buildResolveScope=vs;exports.canConnect=ci;exports.centralizeConnections=Zr;exports.coerceDefault=Br;exports.conditionCombinatorLabel=pc;exports.conditionOperatorLabel=dc;exports.connectConflict=iu;exports.connectRefusal=au;exports.connectionIdFor=St;exports.controlOwnedIds=Ds;exports.convertCodeBindingsToReads=Ml;exports.dataVarRows=fn;exports.declaredSamples=zu;exports.deepEqual=Jn;exports.defaultConnectionFor=Qr;exports.definitionLoops=Us;exports.deleteStepMessage=ou;exports.detectResultFormat=Fr;exports.edgeLane=be;exports.edgeVisuals=Ut;exports.edgeWhenConflict=cu;exports.effectiveEdges=qs;exports.effectiveNodeOutput=Ti;exports.effectiveNodeOutputs=Nd;exports.eventbriteTriggerChoices=oi;exports.excludeSelfStep=Il;exports.fieldWidget=Hr;exports.fieldsToParams=_s;exports.filterOptions=Xo;exports.findChainRoot=Su;exports.findChainTail=Cu;exports.findCodeBindings=fr;exports.findTestInput=qr;exports.flattenParams=vt;exports.flowToWorkflow=ju;exports.foreachTestFixture=$u;exports.foreachTestSample=Pu;exports.getTriggerDefs=Ai;exports.hasParamCustomization=Sn;exports.htmlPreviewSrcDoc=Ir;exports.idClashMessage=fu;exports.ifPortLayout=Ji;exports.indexNodeSamples=jd;exports.inferOutputFields=rt;exports.internalNodeDef=it;exports.internalNodeDefaults=dn;exports.internalNodeIcon=ua;exports.internalNodeLabel=ca;exports.internalNodeParams=Wo;exports.isConnectionBlocked=Uc;exports.isControlApp=Et;exports.isDollarPath=js;exports.isEachLink=Ws;exports.isExprValue=We;exports.isForeachStep=Ce;exports.isFormResolvedOptions=gn;exports.isIfStep=ms;exports.isInternalApp=Ye;exports.isParamVisible=Jt;exports.isSecretValue=Ze;exports.isTestRequired=ki;exports.isTriggerApp=Ft;exports.isTriggerStep=Ki;exports.laneForSourceHandle=Mi;exports.loopBody=An;exports.loopItemText=Bu;exports.loopMembership=Be;exports.loopRefusal=ai;exports.loopRefusalMessage=nu;exports.nodeConfigSources=Ku;exports.nodeConfigValues=Gu;exports.nodeMetaSampleValues=Xu;exports.nodeMetaValues=Yu;exports.nodePortsForStep=Mt;exports.normalizeInput=Ks;exports.parseJsonFields=ts;exports.parseLoopSeed=qu;exports.parseRootAnchoredTemplate=Xe;exports.pickWebhookSubscription=Dr;exports.previewCustomization=vr;exports.previewNodeOutputs=kd;exports.relaneRefusal=uu;exports.relayoutNodes=vu;exports.rememberableInput=Ls;exports.renameStepInEdges=du;exports.requiredParamsFilled=jt;exports.resolveLoopItemsInState=mi;exports.resolveOutputShape=bt;exports.resolveParamJson=Dt;exports.resolveParamValue=ks;exports.resolveVarsJson=ll;exports.resultCopyText=Mr;exports.routeFromHandle=Wi;exports.routeHandle=Nt;exports.routerPortLayout=zi;exports.routesForStep=hs;exports.seedValues=ns;exports.selectNodeConnection=Jc;exports.setEdgeWhen=lu;exports.shapeToSkeleton=Wt;exports.shouldUseCombobox=Yo;exports.slugifyLabel=ku;exports.splitFrontmatter=Ko;exports.splitNodeOutputs=Sd;exports.splitPreviewOutputs=Cd;exports.stampLoopOf=su;exports.startOAuthPopup=Sr;exports.startStateFromSeeds=Xs;exports.stepBuilderLoop=Du;exports.stepBuilderUpstreamSteps=Mu;exports.stepNameError=ui;exports.stepProblemTooltip=Wc;exports.stepToJson=Gs;exports.storedViewport=pi;exports.stripBody=Bs;exports.suggestStepId=Au;exports.testInputSavesSettled=Ur;exports.trackTestInputSave=Wr;exports.upstreamSampleValueSources=Vu;exports.upstreamSampleValues=Uu;exports.upstreamStateSources=Fu;exports.useEffectiveTheme=bn;exports.useEnterSubmit=Cr;exports.useExpressionOptions=ht;exports.useRememberedTestInput=Vr;exports.useSeedSources=Zs;exports.useW6WApi=ye;exports.useWorkflowConnections=Ms;exports.valueAtPath=$t;exports.varLabel=Ge;exports.withConnectionRef=Fs;exports.withViewport=Nu;exports.workflowToFlow=xu;
|
|
22
|
+
//# sourceMappingURL=node-samples-ChdyMBnJ.cjs.map
|