@w6w/ui 0.2.0 → 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.
Files changed (160) hide show
  1. package/CHANGELOG.md +146 -2
  2. package/README.md +28 -10
  3. package/dist/AppPicker.d.ts +58 -2
  4. package/dist/CanvasContextMenu.d.ts +19 -0
  5. package/dist/CanvasLayer.d.ts +38 -0
  6. package/dist/{CodeBlock-Dot3Pd7P.js → CodeBlock-C-oIIYfC.js} +1436 -555
  7. package/dist/CodeBlock-C-oIIYfC.js.map +1 -0
  8. package/dist/CodeBlock-CymlfyeA.cjs +15 -0
  9. package/dist/CodeBlock-CymlfyeA.cjs.map +1 -0
  10. package/dist/CodeEditor.d.ts +4 -1
  11. package/dist/ConditionEditor.d.ts +11 -0
  12. package/dist/EditConnectionModal.d.ts +6 -1
  13. package/dist/JsonEditor.d.ts +20 -0
  14. package/dist/Markdown.d.ts +25 -0
  15. package/dist/ParamCustomization.d.ts +5 -0
  16. package/dist/ParamsForm.d.ts +18 -4
  17. package/dist/RouterEditor.d.ts +5 -0
  18. package/dist/StepBuilderModal.d.ts +103 -15
  19. package/dist/StepNameEditor.d.ts +11 -0
  20. package/dist/StopEditor.d.ts +5 -0
  21. package/dist/TriggerFillForm.d.ts +14 -1
  22. package/dist/WebhookListenPanel.d.ts +28 -0
  23. package/dist/WorkflowConnections.d.ts +29 -0
  24. package/dist/WorkflowFlowEditor.d.ts +74 -7
  25. package/dist/app-pages.d.ts +2 -0
  26. package/dist/assets/script-completion.worker-DDJKkj5M.js +8290 -0
  27. package/dist/assets/script-completion.worker-DDJKkj5M.js.map +1 -0
  28. package/dist/canvas-context-menu.d.ts +27 -0
  29. package/dist/canvas-types.d.ts +36 -0
  30. package/dist/canvas-utils.d.ts +44 -0
  31. package/dist/code.cjs +1 -1
  32. package/dist/code.mjs +3 -4
  33. package/dist/code.mjs.map +1 -1
  34. package/dist/components/AnchoredFlyout.d.ts +7 -0
  35. package/dist/components/AuthFieldsForm.d.ts +11 -0
  36. package/dist/components/BudgetMeter.d.ts +15 -0
  37. package/dist/components/CallableList.d.ts +3 -2
  38. package/dist/components/ColumnsEditor.d.ts +27 -0
  39. package/dist/components/Combobox.d.ts +19 -1
  40. package/dist/components/ConnectionList.d.ts +2 -3
  41. package/dist/components/CredentialPicker.d.ts +35 -0
  42. package/dist/components/CsvPanel.d.ts +21 -0
  43. package/dist/components/DataEntryEditor.d.ts +38 -0
  44. package/dist/components/DataEntryList.d.ts +33 -0
  45. package/dist/components/DataStoreList.d.ts +33 -0
  46. package/dist/components/DataTable.d.ts +27 -0
  47. package/dist/components/DataTableGrid.d.ts +46 -0
  48. package/dist/components/EmptyState.d.ts +9 -0
  49. package/dist/components/EventbriteTriggerPicker.d.ts +7 -0
  50. package/dist/components/ExecutionDetail.d.ts +17 -1
  51. package/dist/components/ExecutionList.d.ts +19 -1
  52. package/dist/components/ExecutionLogPanel.d.ts +61 -3
  53. package/dist/components/ExpressionEditorModal.d.ts +33 -10
  54. package/dist/components/ExpressionOptions.d.ts +101 -15
  55. package/dist/components/HtmlPreview.d.ts +7 -0
  56. package/dist/components/JsonTree.d.ts +32 -0
  57. package/dist/components/ResolvedParams.d.ts +6 -1
  58. package/dist/components/ResultViewer.d.ts +46 -0
  59. package/dist/components/ScriptBindingsNotice.d.ts +31 -0
  60. package/dist/components/ScriptCodeField.d.ts +13 -0
  61. package/dist/components/StepStatusPill.d.ts +7 -0
  62. package/dist/components/expression-authoring.d.ts +13 -0
  63. package/dist/components/expression-dom.d.ts +17 -2
  64. package/dist/components/expression-template.d.ts +25 -3
  65. package/dist/components/icons.d.ts +1 -1
  66. package/dist/components/json-compose.d.ts +53 -0
  67. package/dist/components/result-format.d.ts +13 -0
  68. package/dist/condition-editor.d.ts +44 -0
  69. package/dist/data-stores/data-store-view.d.ts +371 -0
  70. package/dist/dynamic-fields.d.ts +60 -0
  71. package/dist/editor-theme.d.ts +24 -0
  72. package/dist/eventbrite-trigger-selection.d.ts +13 -0
  73. package/dist/flow-connect.d.ts +22 -16
  74. package/dist/flow-delete.d.ts +16 -0
  75. package/dist/flow-fanout.d.ts +2 -2
  76. package/dist/flow-history.d.ts +75 -0
  77. package/dist/flow-layout.d.ts +13 -0
  78. package/dist/flow-loop-colors.d.ts +39 -0
  79. package/dist/flow-loop.d.ts +98 -0
  80. package/dist/flow-node-flags.d.ts +14 -0
  81. package/dist/flow-problems.d.ts +69 -0
  82. package/dist/flow-state.d.ts +20 -0
  83. package/dist/flow-types.d.ts +155 -10
  84. package/dist/flow-utils.d.ts +33 -12
  85. package/dist/flow.cjs +4 -2
  86. package/dist/flow.cjs.map +1 -1
  87. package/dist/flow.d.ts +15 -2
  88. package/dist/flow.mjs +3737 -1350
  89. package/dist/flow.mjs.map +1 -1
  90. package/dist/index.cjs +2 -1
  91. package/dist/index.cjs.map +1 -1
  92. package/dist/index.d.ts +43 -5
  93. package/dist/index.mjs +2855 -1333
  94. package/dist/index.mjs.map +1 -1
  95. package/dist/node-samples-ChdyMBnJ.cjs +22 -0
  96. package/dist/node-samples-ChdyMBnJ.cjs.map +1 -0
  97. package/dist/node-samples-DkJL07EX.js +12302 -0
  98. package/dist/node-samples-DkJL07EX.js.map +1 -0
  99. package/dist/node-samples.d.ts +80 -0
  100. package/dist/note-markdown.d.ts +22 -0
  101. package/dist/output-shape.d.ts +30 -14
  102. package/dist/param-customization.d.ts +7 -0
  103. package/dist/provider.d.ts +174 -13
  104. package/dist/resolve-params.d.ts +50 -11
  105. package/dist/run-visuals.d.ts +18 -22
  106. package/dist/script-bindings.d.ts +63 -0
  107. package/dist/script-completion-service.d.ts +9 -0
  108. package/dist/script-completion.worker.d.ts +1 -0
  109. package/dist/script-completions.d.ts +2 -0
  110. package/dist/state-shape.d.ts +38 -0
  111. package/dist/step-preview-state.d.ts +155 -6
  112. package/dist/step-problems.d.ts +64 -0
  113. package/dist/test-inputs.d.ts +25 -0
  114. package/dist/trigger-registration.d.ts +28 -0
  115. package/dist/types.d.ts +179 -11
  116. package/dist/use-app-action-defs.d.ts +9 -1
  117. package/dist/use-dynamic-fields.d.ts +23 -0
  118. package/dist/use-test-input.d.ts +18 -0
  119. package/dist/workflow-connections.d.ts +30 -0
  120. package/package.json +18 -7
  121. package/src/code.css +60 -6
  122. package/src/styles/_budget-meter.scss +46 -0
  123. package/src/styles/_callable-list.scss +15 -6
  124. package/src/styles/_canvas.scss +353 -0
  125. package/src/styles/_code-editor.scss +35 -0
  126. package/src/styles/_code.scss +6 -5
  127. package/src/styles/_connections.scss +2 -14
  128. package/src/styles/_copyable.scss +24 -0
  129. package/src/styles/_data-stores.scss +138 -0
  130. package/src/styles/_data-table.scss +55 -0
  131. package/src/styles/_data-vars.scss +17 -6
  132. package/src/styles/_empty-state.scss +21 -0
  133. package/src/styles/_execution-history.scss +73 -0
  134. package/src/styles/_execution-log.scss +145 -1
  135. package/src/styles/_expression-modal.scss +106 -16
  136. package/src/styles/_fields.scss +11 -0
  137. package/src/styles/_flow.scss +171 -0
  138. package/src/styles/_fx.scss +26 -1
  139. package/src/styles/_incoming-state.scss +33 -0
  140. package/src/styles/_layout.scss +10 -0
  141. package/src/styles/_markdown.scss +20 -0
  142. package/src/styles/_modal.scss +12 -0
  143. package/src/styles/_multiselect.scss +35 -0
  144. package/src/styles/_sections.scss +36 -0
  145. package/src/styles/_step-builder.scss +145 -0
  146. package/src/styles/_tester.scss +57 -14
  147. package/src/styles/_tokens.scss +27 -1
  148. package/src/styles.css +1861 -115
  149. package/src/styles.scss +7 -0
  150. package/dist/CodeBlock-CZu4TFSi.cjs +0 -15
  151. package/dist/CodeBlock-CZu4TFSi.cjs.map +0 -1
  152. package/dist/CodeBlock-Dot3Pd7P.js.map +0 -1
  153. package/dist/ConfirmModal-ChoiGy2K.cjs +0 -11
  154. package/dist/ConfirmModal-ChoiGy2K.cjs.map +0 -1
  155. package/dist/ConfirmModal-Wx3i8F1n.js +0 -6359
  156. package/dist/ConfirmModal-Wx3i8F1n.js.map +0 -1
  157. package/dist/Copyable-1niV9gUa.js +0 -771
  158. package/dist/Copyable-1niV9gUa.js.map +0 -1
  159. package/dist/Copyable-CYZU1o4X.cjs +0 -2
  160. package/dist/Copyable-CYZU1o4X.cjs.map +0 -1
@@ -1,11 +0,0 @@
1
- "use strict";const t=require("react/jsx-runtime"),d=require("react"),Ot=require("@codemirror/lang-json"),Ft=require("@codemirror/lint"),Kt=require("@codemirror/view"),Yt=require("@uiw/react-codemirror"),de=require("./Copyable-CYZU1o4X.cjs"),Us=require("@codemirror/lang-javascript"),Bs=require("@codemirror/lang-python"),oe=require("@w6w/expr"),Js={ai:"AI",cms:"CMS",crm:"CRM",hr:"HR",devops:"DevOps"};function zs(e){if(typeof e!="string"||e.trim()==="")return"";const s=Js[e];return s||e.split(/[-_\s]+/).filter(Boolean).map(n=>n.charAt(0).toUpperCase()+n.slice(1)).join(" ")}function Gs(e){const s=new Map;for(const n of e)for(const r of n.categories??[])s.set(r,(s.get(r)??0)+1);return[...s.entries()].map(([n,r])=>({slug:n,label:zs(n),count:r})).sort((n,r)=>r.count-n.count||n.label.localeCompare(r.label,void 0,{sensitivity:"base"}))}function Ks(e,s){if(s.length===0)return!0;const n=e.categories??[];return s.some(r=>n.includes(r))}function Xt(e,s){const n=e==="error"?{className:"w6w-edge-error",label:"on error"}:{};if(!s)return n;const r=s==="taken"?"w6w-edge-taken":"w6w-edge-skipped";return{className:n.className?`${n.className} ${r}`:r,...n.label?{label:n.label}:{}}}const mt="out-error";function Qt(e){return e==="error"?mt:void 0}function Ys(e){return e===mt?"error":"success"}const Xs="@w6w/",ce="@w6w/control",Zt="@w6w/script",Be="@w6w/data",Je="@w6w/trigger",Qs="@w6w/http",bt="@w6w/webhook",xt="@w6w/scheduler",Zs="@w6w/respond",ze="@w6w/call",en="@w6w/document",tn="@w6w/template";function fe(e){return e.startsWith(Xs)}function De(e){return e===ce}function qe(e){return e===Je||e===bt||e===xt}const $t={in:1,out:Number.POSITIVE_INFINITY};function Lt(e){return e==="many"?Number.POSITIVE_INFINITY:typeof e=="number"?e:void 0}function sn(...e){let s,n;for(const r of e)s??(s=Lt(r==null?void 0:r.in)),n??(n=Lt(r==null?void 0:r.out));return{in:s??$t.in,out:n??$t.out}}function nn(e,s){var a;const{app:n,action:r}=e.uses;return sn(e.ports,s==null?void 0:s(n,r),(a=me(n,r))==null?void 0:a.ports)}const rn='<polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2" />',an='<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" />',on='<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" />',ln='<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" />',cn='<circle cx="12" cy="12" r="9" /><polyline points="12 7 12 12 15 14" />',un='<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" />',dn='<polyline points="16 18 22 12 16 6" /><polyline points="8 6 2 12 8 18" />',pn='<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" />',wn='<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" />',hn='<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" />',fn='<polyline points="9 17 4 12 9 7" /><path d="M20 18v-2a4 4 0 0 0-4-4H4" />',Dt='<polygon points="22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3" />',mn='<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" />',bn='<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" />',xn='<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" />',je=[{app:Je,action:"manual",label:"Manual trigger",displayName:"Manual trigger",group:"trigger",icon:rn,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 {"$": "steps.<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:bt,action:"webhook",label:"Webhook",displayName:"Webhook",group:"trigger",icon:hn,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 = { "message": "Workflow was started" }.',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:xt,action:"schedule",label:"Schedule",displayName:"Scheduler",group:"trigger",icon:un,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:ce,action:"if",label:"If",displayName:"If",group:"control",icon:an,params:[{key:"condition",type:"json",label:"Condition",required:!0,default:!0,hint:'A boolean, or an expression binding like { "$": "steps.x.output.ok" }.'}]},{app:ce,action:"foreach",label:"For each",displayName:"For each",group:"control",icon:on,params:[{key:"items",type:"json",label:"Items",required:!0,default:[],hint:"An array to iterate, or an expression binding to one."}]},{app:ce,action:"parallel",label:"Parallel",displayName:"Parallel",group:"control",icon:ln,params:[]},{app:ce,action:"wait",label:"Wait",displayName:"Wait",group:"control",icon:cn,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:Zt,action:"run",label:"Run script",displayName:"Run script",group:"compute",icon:dn,params:[{key:"language",label:"Language",type:"select",default:"javascript",options:[{value:"javascript",label:"JavaScript"},{value:"python",label:"Python"}],hint:"Execution language for this step's code. Python runs CPython-on-WASM with no network."},{key:"code",type:"code",label:"Script",required:!0,default:`// Runs as a function body. Return the step's output.
2
- return input;`,hint:"Function body; return the step's output."}]},{app:tn,action:"render",label:"Render template",displayName:"Template",group:"compute",icon:xn,output:[{key:"result"}],params:[{key:"template",label:"Template",type:"text",required:!0,hint:"Handlebars template. Placeholder names are workflow-agnostic — bind them below. {{name}} is HTML-escaped; use {{{name}}} for raw output."},{key:"values",label:"Values",type:"vars",required:!0,default:[],hint:'A typed key/value array: [{ "key": "data", "type": "json", "value": ... }]. Each key becomes a top-level placeholder root.'}]},{app:Be,action:"set",label:"Data",displayName:"Data set",group:"compute",icon:pn,params:[{key:"vars",type:"vars",label:"Variables",required:!0,default:[],hint:"Typed key/value variables for downstream steps to reference."}]},{app:Qs,action:"request",label:"HTTP request",displayName:"HTTP",group:"request",icon:wn,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:Zs,action:"respond",label:"Respond to Webhook",displayName:"Respond to Webhook",group:"request",icon:fn,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:ce,action:"aggregate",label:"Aggregate",displayName:"Aggregate",group:"control",icon:Dt,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:ce,action:"merge",label:"Merge",displayName:"Merge",group:"control",icon:Dt,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:ze,action:"call",label:"Call workflow",displayName:"Call",group:"compute",icon:mn,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:en,action:"get",label:"Get document",displayName:"Document",group:"compute",icon:bn,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."}]}];function me(e,s){return je.find(n=>n.app===e&&n.action===s)}function gn(e,s){var n;return((n=me(e,s))==null?void 0:n.label)??s}function yn(e,s){var n;return((n=me(e,s))==null?void 0:n.icon)??""}function es(e,s){var n;return((n=me(e,s))==null?void 0:n.params)??[]}function ts(e,s){const n={};for(const r of es(e,s))r.default!==void 0&&(n[r.key]=r.default);return n}function jn(e,s){return e.q===s.q&&(e.category??"")===(s.category??"")}function ss(e,s=0){return{query:e,generation:s,status:"loading",apps:[],hasMore:!1}}function vn(e,s){const n=new Set(e.map(a=>a.id)),r=[];for(const a of s)n.has(a.id)||(n.add(a.id),r.push(a));return r.length===0?e:[...e,...r]}function Nn(e,s){switch(s.type){case"query-changed":return s.generation===e.generation&&jn(s.query,e.query)?e:ss(s.query,s.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(s.generation!==e.generation)return e;const n=vn(e.apps,s.apps),r=s.nextCursor!==void 0&&s.nextCursor===s.requestedCursor,a=!!s.nextCursor&&!r;return{...e,status:"ready",apps:n,cursor:a?s.nextCursor:void 0,hasMore:a,total:typeof s.total=="number"?s.total:e.total,error:void 0}}case"page-failed":return s.generation!==e.generation?e:{...e,status:"error",error:s.error};default:return e}}function kn(e){return e.filter(s=>!fe(s.id))}function st(e,s,n){if(n<=0)return[];const r=[];for(const a of e)if(!s.has(a)&&(r.push(a),r.length>=n))break;return r}function Cn(e,s){const n=[];for(const r of e){const a=s.get(r);a&&n.push(a)}return n}const ns=d.createContext(void 0);function _t(e,s){var r;if(e)return e;if(s)return s;if(typeof document>"u")return"light";const n=document.documentElement.getAttribute("data-theme");return n==="dark"||n==="light"?n:(r=window.matchMedia)!=null&&r.call(window,"(prefers-color-scheme: dark)").matches?"dark":"light"}function Ge(e){const s=d.useContext(ns),[n,r]=d.useState(()=>_t(e,s));return d.useEffect(()=>{if(e){r(e);return}if(s){r(s);return}if(typeof window>"u")return;const a=()=>r(_t(void 0,s)),o=window.matchMedia("(prefers-color-scheme: dark)");o.addEventListener("change",a);const l=new MutationObserver(a);return l.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]}),a(),()=>{o.removeEventListener("change",a),l.disconnect()}},[e,s]),n}function we({src:e,srcDark:s,brandColor:n,name:r,size:a=32,theme:o}){const i=Ge(o)==="dark"?s??e:e,[c,u]=d.useState(void 0);if(i&&i!==c)return t.jsx("img",{src:i,width:a,height:a,alt:"",onError:()=>u(i),style:{width:a,height:a,borderRadius:6,flexShrink:0,objectFit:"contain",padding:Math.max(1,Math.round(a*.06)),boxSizing:"border-box",background:"var(--w6w-icon-swatch, var(--w6w-panel-2))"}});const m=(r??"?").split(/\s+/).slice(0,2).map(p=>{var h;return((h=p[0])==null?void 0:h.toUpperCase())??""}).join("");return t.jsx("span",{"aria-hidden":"true",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:a,height:a,borderRadius:6,background:n??"var(--w6w-accent)",color:"#fff",fontWeight:700,fontSize:Math.round(a*.42),flexShrink:0},children:m})}const rs=d.createContext(null);function Sn({api:e,theme:s,children:n}){const r=t.jsx(rs.Provider,{value:e,children:t.jsx(ns.Provider,{value:s,children:n})});return s?t.jsx("div",{"data-theme":s,style:{display:"contents"},children:r}):r}function te(){const e=d.useContext(rs);if(!e)throw new Error("useW6WApi must be used inside <W6WUIProvider>. Wrap your app root with <W6WUIProvider api={api}>...</W6WUIProvider>.");return e}const as=d.createContext(void 0);function An({project:e,children:s}){return t.jsx(as.Provider,{value:e,children:s})}function os(){return d.useContext(as)}const nt=8,En=60,Tn=300;function be({onSelectApp:e,theme:s,filter:n,searchPlaceholder:r,emptyMessage:a,search:o=!0,emptyAction:l,apps:i,categoryFilter:c=!1,category:u,pageLimit:m=En,loadPage:p}){const h=te(),f=i!==void 0,w=!f&&(p!==void 0||typeof h.listAppsPage=="function"),b=d.useRef(p);b.current=p;const[S,y]=d.useState(null),[x,N]=d.useState(null);d.useEffect(()=>{if(f||w)return;const T=h.listApps;if(typeof T!="function"){y([]);return}let Y=!1;return T().then(X=>!Y&&y(X)).catch(X=>!Y&&N(X.message)),()=>{Y=!0}},[h,f,w]);const[j,A]=d.useReducer(Nn,ss({q:"",category:u},0)),[k,P]=d.useState(""),[E,I]=d.useState(""),L=d.useRef(0),D=d.useRef(null),v=d.useCallback((T,Y,X)=>{var R;const ke=b.current,re=h.listAppsPage;if(!ke&&!re)return;(R=D.current)==null||R.abort();const Ce=new AbortController;D.current=Ce;let Se;try{Se=ke?ke({q:T.q||void 0,cursor:X,limit:m,signal:Ce.signal}):re({q:T.q||void 0,category:T.category,cursor:X,limit:m,compact:!0,signal:Ce.signal})}catch(U){Se=Promise.reject(U)}Se.then(U=>{if(L.current===Y){if(!U||!Array.isArray(U.apps)){A({type:"page-failed",generation:Y,error:"The server returned a malformed apps page."});return}A({type:"page-loaded",generation:Y,apps:U.apps,nextCursor:U.nextCursor,requestedCursor:X,total:typeof U.total=="number"?U.total:void 0})}}).catch(U=>{if(L.current!==Y||U instanceof Error&&U.name==="AbortError")return;const ie=U==null?void 0:U.code;if(X!==void 0&&(ie==="snapshot_expired"||ie==="unknown_snapshot")){const $e=++L.current;A({type:"query-changed",query:T,generation:$e}),v(T,$e,void 0);return}A({type:"page-failed",generation:Y,error:U.message})})},[h,m]);d.useEffect(()=>{if(!w)return;const T=setTimeout(()=>I(k.trim()),Tn);return()=>clearTimeout(T)},[k,w]),d.useEffect(()=>{if(!w)return;const T=++L.current,Y={q:E,category:u};return A({type:"query-changed",query:Y,generation:T}),v(Y,T,void 0),()=>{var X;(X=D.current)==null||X.abort()}},[w,E,u,v]),d.useEffect(()=>{if(w)return()=>{var T;return(T=D.current)==null?void 0:T.abort()}},[w]);const C=()=>{if(!w||j.status!=="ready"||!j.hasMore)return;const T=L.current;A({type:"load-more"}),v(j.query,T,j.cursor)},_=()=>{!w||j.status!=="error"||(A({type:"retry"}),v(j.query,L.current,j.cursor))},[B,M]=d.useState([]),[W,H]=d.useState(!1),Q=T=>t.jsx("div",{className:"w6w-apppicker-host",children:T});let ee,G=null,z=!1,ae=!1,K=null,g=!1;if(f?ee=i??null:w?(ee=j.apps,g=j.status==="loading",z=j.status==="loading-more",ae=j.hasMore,j.status==="error"&&(j.apps.length===0?G=j.error??"Failed to load apps.":K=j.error??"Failed to load apps.")):(ee=S,G=x),!w&&G)return Q(t.jsx("div",{className:"w6w-result w6w-error",children:G}));if(!w&&ee===null)return Q(t.jsx("p",{className:"w6w-muted w6w-small",children:"Loading apps…"}));ee??(ee=[]);const O=kn(ee),F=n?O.filter(n):O;if(!w&&F.length===0)return Q(t.jsxs("div",{className:"w6w-stack",children:[t.jsx("p",{className:"w6w-muted w6w-small",children:a??"No apps registered yet. Register one from the Apps page first."}),l]}));const V=c?Gs(F):[],q=V.slice(0,nt),J=V.slice(nt).filter(T=>B.includes(T.slug)),$=[...q,...J],Z=V.length-$.length,ve=W?V:$,et=T=>M(Y=>Y.includes(T)?Y.filter(X=>X!==T):[...Y,T]),Ne=()=>M([]),Me=c&&B.length>0?F.filter(T=>Ks(T,B)):F,Oe=w?Me:[...Me].sort((T,Y)=>T.displayName.localeCompare(Y.displayName,void 0,{sensitivity:"base"})),Fe=w?"":k.trim().toLowerCase(),se=k.trim().length>0,le=Fe?Oe.filter(T=>T.displayName.toLowerCase().includes(Fe)||T.id.toLowerCase().includes(Fe)):Oe,tt=c&&B.length>0&&le.length===0;return Q(t.jsxs("div",{className:"w6w-stepbuilder-apps",children:[o&&t.jsx("input",{type:"text",className:"w6w-stepbuilder-search",placeholder:r??"Search apps…",value:k,onChange:T=>P(T.target.value),"aria-label":"Search apps"}),c&&V.length>0&&t.jsxs("div",{className:"w6w-apppicker-cats",children:[ve.map(T=>t.jsxs("button",{type:"button",className:"w6w-apppicker-chip","aria-pressed":B.includes(T.slug),"aria-label":`Filter by ${T.label}`,onClick:()=>et(T.slug),children:[T.label," ",t.jsxs("span",{className:"w6w-muted",children:["(",T.count,")"]})]},T.slug)),!W&&Z>0&&t.jsxs("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:()=>H(!0),children:["+",Z," more"]}),W&&V.length>nt&&t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:()=>H(!1),children:"Show less"}),B.length>0&&t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:Ne,children:"Clear"})]}),w&&g?t.jsx("p",{className:"w6w-muted w6w-small",children:"Loading apps…"}):w&&G?t.jsxs("div",{className:"w6w-result w6w-error",children:[G," ",t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:_,children:"Retry"})]}):le.length===0&&!ae?tt?t.jsxs("div",{className:"w6w-stack",children:[t.jsx("p",{className:"w6w-muted w6w-small",children:se?`No apps match “${k}” in the selected categories.`:"No apps match the selected categories."}),t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:()=>{M([]),P("")},children:"Clear filters"})]}):w?t.jsxs("div",{className:"w6w-stack",children:[t.jsx("p",{className:"w6w-muted w6w-small",children:se?`No apps match “${k}”.`:a??"No apps registered yet. Register one from the Apps page first."}),!se&&l]}):t.jsxs("p",{className:"w6w-muted w6w-small",children:["No apps match “",k,"”."]}):t.jsxs(t.Fragment,{children:[le.length===0&&ae?t.jsx("p",{className:"w6w-muted w6w-small",children:"No matching apps on this page yet — try “Load more”."}):t.jsx("div",{className:"w6w-stepbuilder-list w6w-apppicker-grid w6w-stepbuilder-scroll",children:le.map(T=>t.jsxs("button",{type:"button",className:"w6w-stepbuilder-item w6w-apppicker-card",onClick:()=>e(T),children:[t.jsx(we,{src:T.iconSvg,srcDark:T.iconSvgDark,brandColor:T.brandColor,name:T.displayName,theme:s,size:24}),t.jsxs("span",{className:"w6w-stepbuilder-item-main",children:[t.jsx("strong",{children:T.displayName}),t.jsx("code",{className:"w6w-apppicker-card-id",children:T.id}),T.version&&t.jsxs("span",{className:"w6w-apppicker-card-version",children:["v",T.version]})]})]},T.id))}),w&&typeof j.total=="number"&&t.jsxs("div",{className:"w6w-small w6w-apppicker-count",children:[j.apps.length," of ",j.total]}),w&&K&&t.jsxs("div",{className:"w6w-result w6w-error w6w-small",children:[K," ",t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:_,children:"Retry"})]}),w&&ae&&!K&&t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm w6w-apppicker-load-more",onClick:C,disabled:z,children:z?"Loading more…":"Load more"})]})]}))}function ls({fields:e,values:s,onChange:n,enterSubmitProps:r,mode:a="create"}){const o=(l,i)=>n({...s,[l]:i});return t.jsxs("div",{className:"w6w-stack",children:[e.length===0&&t.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(l=>{const i=a==="edit",c=s[l.key]??(i?void 0:l.default)??"";if(l.type==="boolean")return t.jsxs("label",{className:"w6w-field",children:[t.jsxs("span",{children:[t.jsx("input",{type:"checkbox",checked:!!c,onChange:p=>o(l.key,p.target.checked),...r}),l.label,l.required?" *":""]}),l.hint&&t.jsx("span",{className:"w6w-hint",children:l.hint})]},l.key);const u=l.type==="secret",m=l.type==="number"?"number":"text";return t.jsxs("label",{className:"w6w-field",children:[t.jsxs("span",{children:[l.label,l.required?" *":""]}),t.jsx("input",{type:m,className:u?"w6w-secret-input":void 0,value:String(c??""),placeholder:i&&u?"•••••• (unchanged)":void 0,onChange:p=>o(l.key,l.type==="number"&&!(i&&p.target.value==="")?Number(p.target.value):p.target.value),name:`w6w-cred-${l.key}`,autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",spellCheck:!1,"data-1p-ignore":"true","data-lpignore":"true","data-bwignore":"true","data-form-type":"other",...r}),l.hint&&t.jsx("span",{className:"w6w-hint",children:l.hint})]},l.key)})]})}const Rn={default:"",wide:" w6w-modal-wide",xl:" w6w-modal-xl",full:" w6w-modal-full",fullscreen:" w6w-modal-fullscreen"};function ne({title:e,ariaLabel:s,onClose:n,children:r,size:a="default",titleIcon:o,subtitle:l,headerRight:i}){const c=d.useRef(null);return d.useEffect(()=>{const u=c.current;if(!u)return;u.open||u.showModal();const m=h=>{h.preventDefault(),n()},p=h=>{if(h.target!==u)return;const f=u.getBoundingClientRect();(h.clientX<f.left||h.clientX>f.right||h.clientY<f.top||h.clientY>f.bottom)&&n()};return u.addEventListener("cancel",m),u.addEventListener("click",p),()=>{u.removeEventListener("cancel",m),u.removeEventListener("click",p)}},[n]),t.jsx("div",{className:"w6w-modal-backdrop",children:t.jsxs("dialog",{ref:c,className:`w6w-modal${Rn[a]}`,"aria-label":s??(typeof e=="string"?e:void 0),children:[t.jsxs("div",{className:"w6w-modal-header",children:[t.jsxs("h3",{className:"w6w-modal-title",children:[o,t.jsx("span",{children:e}),l&&t.jsx("span",{className:"w6w-modal-subtitle",children:l})]}),i]}),r]})})}const In="width=560,height=720,menubar=no,toolbar=no,location=no";function is(e){return new Promise((s,n)=>{const r=window.open(e,"w6w-oauth",In);if(!r){n(new Error("Popup blocked — allow popups for this site and try again."));return}let a=!1;const o=()=>{a=!0,window.removeEventListener("message",l),window.clearInterval(i)},l=c=>{const u=c.data;if((u==null?void 0:u.w6w)==="oauth-result"){o();try{r.close()}catch{}u.ok&&typeof u.connectionId=="string"?s({connectionId:u.connectionId}):n(new Error(u.error??"OAuth flow failed."))}};window.addEventListener("message",l);const i=window.setInterval(()=>{a||r.closed&&(o(),n(new Error("OAuth popup was closed before the flow completed.")))},500)})}const Pn=new Set(["checkbox","radio","button","submit","reset","file","range","color","image","hidden","date","datetime-local","month","week","time"]);function Mn(e){return e.closest('[contenteditable]:not([contenteditable="false"])')!==null}function cs(e,s){return{onKeyDown:n=>{if((s==null?void 0:s.enabled)===!1||n.key!=="Enter"||n.shiftKey||n.altKey||n.ctrlKey||n.metaKey||n.nativeEvent.isComposing)return;const r=n.target;r.tagName!=="TEXTAREA"&&(Mn(r)||r.tagName==="INPUT"&&Pn.has(r.type)||(n.preventDefault(),e()))}}}function gt(e){const s=te(),[n,r]=d.useState(null),[a,o]=d.useState(!!e.initialAppId);return d.useEffect(()=>{const l=e.initialAppId;if(!l)return;let i=!1;const c=p=>{i||(r(p),o(!1))},u=s.listAppsByIds;if(u)return u([l]).then(p=>c(p.find(h=>h.id===l)??null)).catch(()=>c(null)),()=>{i=!0};const m=s.listApps;return typeof m=="function"?m().then(p=>c(p.find(h=>h.id===l)??null)).catch(()=>c(null)):c(null),()=>{i=!0}},[s,e.initialAppId]),n?t.jsx(ne,{title:n.displayName,subtitle:t.jsxs(t.Fragment,{children:[t.jsx("code",{children:n.id}),n.version&&` · v${n.version}`]}),onClose:e.onClose,size:"xl",titleIcon:t.jsx(we,{src:n.iconSvg,srcDark:n.iconSvgDark,brandColor:n.brandColor,name:n.displayName,theme:e.theme,size:22}),headerRight:e.initialAppId?void 0:t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>r(null),children:"← Apps"}),children:t.jsx(On,{app:n,onCreated:e.onCreated,onClose:e.onClose})}):a?t.jsx(ne,{title:"Add connection",onClose:e.onClose,size:"xl",children:t.jsx("div",{className:"w6w-stepbuilder-content",children:t.jsx("p",{className:"w6w-muted w6w-small",children:"Loading…"})})}):t.jsx(ne,{title:"Add connection",onClose:e.onClose,size:"xl",children:t.jsx("div",{className:"w6w-stepbuilder-content",children:t.jsx(be,{onSelectApp:r,theme:e.theme,searchPlaceholder:"Search apps to connect…",categoryFilter:!0})})})}function On({app:e,onCreated:s,onClose:n}){const r=te(),[a,o]=d.useState(null),[l,i]=d.useState(""),[c,u]=d.useState(""),[m,p]=d.useState({}),[h,f]=d.useState(null),[w,b]=d.useState(!1);d.useEffect(()=>{let I=!1;return o(null),r.getAppAuth(e.id).then(L=>!I&&o(L.filter(D=>D.available!==!1))).catch(L=>!I&&f(L.message)),()=>{I=!0}},[r,e.id]);const S=a??[],y=S.find(I=>I.key===l)??S.find(I=>I.default===!0)??S[0],x=(y==null?void 0:y.fields)??[],N=(y==null?void 0:y.type)==="oauth2",j=(y==null?void 0:y.key)==="zero-credential",A=!N&&!j&&x.some(I=>I.required&&(m[I.key]===void 0||m[I.key]==="")),k=!y||!N&&!j&&A||w;async function P(){if(y){f(null),b(!0);try{if(j)s({connectionId:`zerocred:${e.id}`});else if(N){const{authorizationUrl:I}=await r.startAppOAuthFlow(e.id,y.key,{displayName:c||void 0}),{connectionId:L}=await is(I);s({connectionId:L})}else{const I=await r.createConnection(e.id,{authKey:y.key,credential:m,displayName:c||void 0});s({connectionId:I.id})}}catch(I){f(I.message)}finally{b(!1)}}}const E=cs(P,{enabled:!k});return t.jsxs("div",{className:"w6w-stepconfig",children:[t.jsx("div",{className:"w6w-modal-body",children:t.jsxs("div",{className:"w6w-stack",children:[a===null&&t.jsx("p",{className:"w6w-muted w6w-small",children:"Loading auth methods…"}),a!==null&&S.length===0&&t.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."}),S.length>1&&t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:"Auth method"}),t.jsx("select",{value:(y==null?void 0:y.key)??"",onChange:I=>{i(I.target.value),p({}),f(null)},children:S.map(I=>t.jsxs("option",{value:I.key,children:[I.displayName??I.key," (",I.type,")"]},I.key))})]}),y&&t.jsxs(t.Fragment,{children:[!j&&t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:"Display name"}),t.jsx("input",{type:"text",value:c,onChange:I=>u(I.target.value),placeholder:"e.g. Production API key",maxLength:80,name:"w6w-connection-label",autoComplete:"off","data-1p-ignore":"true","data-lpignore":"true","data-bwignore":"true","data-form-type":"other",...E})]}),y.description&&t.jsx("p",{className:"w6w-muted w6w-small",children:y.description}),j?null:N?t.jsxs("p",{className:"w6w-muted w6w-small",children:["You'll be redirected to ",t.jsx("strong",{children:y.displayName??y.key})," to authorize this connection."]}):t.jsx(ls,{fields:x,values:m,onChange:p,enterSubmitProps:E})]}),h&&t.jsx("div",{className:"w6w-result w6w-error",children:h})]})}),t.jsxs("div",{className:"w6w-modal-actions",children:[t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:n,children:"Cancel"}),t.jsx("button",{type:"button",className:"w6w-btn",disabled:k,onClick:P,children:w?j?"Saving…":N?"Waiting for authorization…":"Saving…":j?"Use this":N?`Sign in with ${(y==null?void 0:y.displayName)??(y==null?void 0:y.key)??"provider"}`:"Save connection"})]})]})}function ue(e){const s=Ge(e.theme),{copied:n,copy:r}=de.useCopyToClipboard(e.value),a=d.useMemo(()=>[Ot.json(),Ft.linter(Ot.jsonParseLinter()),Ft.lintGutter(),Kt.EditorView.theme({"&":{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:"2px solid 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"}})],[]);function o(l){var i,c,u,m;if(e.onChange(l),!(!e.onValidChange&&!e.onValidityChange)){if(l.trim().length===0){(i=e.onValidityChange)==null||i.call(e,{valid:!1,error:"Empty"});return}try{const p=JSON.parse(l);(c=e.onValidChange)==null||c.call(e,p),(u=e.onValidityChange)==null||u.call(e,{valid:!0})}catch(p){(m=e.onValidityChange)==null||m.call(e,{valid:!1,error:p.message})}}}return t.jsxs("div",{className:"w6w-json-editor","aria-label":e["aria-label"]??"JSON editor",children:[t.jsx(Yt,{value:e.value,onChange:o,extensions:a,placeholder:e.placeholder,readOnly:e.readOnly,editable:!e.readOnly,theme:s,height:e.height,minHeight:e.minHeight??"240px",maxHeight:e.maxHeight,basicSetup:{lineNumbers:!0,foldGutter:!0,highlightActiveLine:!e.readOnly,autocompletion:!0,bracketMatching:!0,closeBrackets:!0}}),e.copyable&&t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",className:`w6w-icon-btn w6w-copyable-btn${n?" is-copied":""}`,"aria-label":"Copy",onClick:()=>void r(),children:n?t.jsx(de.CheckGlyph,{}):t.jsx(de.CopyGlyph,{})}),t.jsx("span",{className:"w6w-copyable-status","aria-live":"polite",children:n?"Copied":""})]})]})}const Fn={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 us({value:e,onChange:s,readOnly:n,target:r="step"}){const a=!!e,o=(e==null?void 0:e.maxAttempts)??3,l=(e==null?void 0:e.delayMs)??1e3,i=(e==null?void 0:e.backoff)??"fixed",c=u=>s({maxAttempts:o,delayMs:l,backoff:i,...e,...u});return t.jsxs(t.Fragment,{children:[t.jsxs("label",{className:"w6w-field",children:[t.jsxs("span",{children:[t.jsx("input",{type:"checkbox",checked:a,disabled:n,onChange:u=>s(u.target.checked?{maxAttempts:o,delayMs:l,backoff:i}:void 0)})," ","Retry on failure"]}),t.jsx("span",{className:"w6w-hint",children:Fn[r]})]}),a&&t.jsxs("div",{className:"w6w-field-row",children:[t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:"Attempts"}),t.jsx("input",{type:"number",min:1,value:o,readOnly:n,onChange:u=>c({maxAttempts:Math.max(1,Number(u.target.value)||1)})})]}),t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:"Delay (ms)"}),t.jsx("input",{type:"number",min:0,value:l,readOnly:n,onChange:u=>c({delayMs:Math.max(0,Number(u.target.value)||0)})})]}),t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:"Backoff"}),t.jsxs("select",{value:i,disabled:n,onChange:u=>c({backoff:u.target.value}),children:[t.jsx("option",{value:"fixed",children:"Fixed"}),t.jsx("option",{value:"exponential",children:"Exponential"})]})]})]})]})}function yt({config:e,onChange:s,readOnly:n,hasGraph:r=!0,failureHandling:a=!0,retryControls:o=!0,reroute:l}){const i=e.onError??"fail";return t.jsxs("div",{className:"w6w-stack",children:[a&&t.jsxs(t.Fragment,{children:[o&&t.jsx(us,{value:e.retry,onChange:c=>s({...e,retry:c}),readOnly:n}),t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:"On error"}),t.jsxs("select",{value:i,disabled:n,onChange:c=>{const u=c.target.value;s({...e,onError:u==="fail"?void 0:u})},children:[t.jsx("option",{value:"fail",children:"Stop the run (default)"}),t.jsx("option",{value:"continue",children:"Continue to the next step"}),r&&t.jsx("option",{value:"continue-record",children:"Continue to the next step & record the error"})]}),r?t.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, ",t.jsx("strong",{children:"Continue"})," and"," ",t.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"," ",t.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."]}):t.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 ",t.jsx("strong",{children:"reroute"})," target below to send a failure somewhere else instead of stopping."]})]})]}),l&&t.jsxs("div",{className:"w6w-field",children:[t.jsx("span",{children:"Reroute on failure"}),t.jsxs("div",{className:"w6w-field-row",children:[l.picker,l.value&&t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",disabled:n,onClick:()=>l.onChange(void 0),children:"Clear"})]}),t.jsx("span",{className:"w6w-hint",children:"Invoked once, after retry is exhausted, if this step still fails; its output becomes this step's output."})]}),t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:"Notes"}),t.jsx("textarea",{rows:3,value:e.notes??"",readOnly:n,placeholder:"A short description — shown under this step on the canvas. Not executed.",onChange:c=>s({...e,notes:c.target.value||void 0})})]})]})}function $n(e){switch(e){case"javascript":return Us.javascript();case"python":return Bs.python()}}function ds(e){const s=Ge(e.theme),n=d.useMemo(()=>[...e.language?[$n(e.language)]:[],Kt.EditorView.theme({"&":{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:"2px solid 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"}})],[e.language]);return t.jsx("div",{className:"w6w-code-editor","aria-label":e["aria-label"]??"Code editor",children:t.jsx(Yt,{value:e.value,onChange:e.onChange,extensions:n,placeholder:e.placeholder,readOnly:e.readOnly,theme:s,height:e.height,minHeight:e.minHeight??"160px",maxHeight:e.maxHeight,basicSetup:{lineNumbers:!0,foldGutter:!1,highlightActiveLine:!e.readOnly,bracketMatching:!0,closeBrackets:!0}})})}const jt=d.forwardRef(function(s,n){const{label:r,children:a,icon:o,iconSize:l,title:i,onClick:c,disabled:u,className:m,danger:p,...h}=s,f=a??(o?t.jsx(de.Icon,{name:o,size:l??16}):null);return t.jsx("button",{ref:n,type:"button",className:["w6w-icon-button",p?"w6w-icon-button-danger":"",m??""].filter(Boolean).join(" "),title:i??r,"aria-label":r,"aria-pressed":h["aria-pressed"],"aria-expanded":h["aria-expanded"],"aria-controls":h["aria-controls"],disabled:u,onClick:c,"data-testid":h["data-testid"],children:f})});jt.displayName="IconButton";function Ke(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&e.type==="expr"&&Array.isArray(e.parts)}function vt(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&e.type==="secret"&&typeof e.ciphertext=="string"&&typeof e.iv=="string"}function Ln(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 Te(e){const s=e.filter(n=>n.kind!=="text"||(n.value??"")!=="");return s.length===0?"":s.length===1&&s[0].kind==="text"?s[0].value??"":{type:"expr",parts:s.map(Ln)}}const ps={vars:!0,steps:!0,trigger:!0,foreach:!0,inputs:!0,output:!0,secrets:!0,documents:!0};Object.freeze(Object.keys(ps));const qt=e=>Object.prototype.hasOwnProperty.call(ps,e);function Ht(e){const s=e.indexOf(".");return s===-1?e:e.slice(0,s)}function He(e){const s=oe.parseTemplate(e);return s.every(r=>{if(r.kind==="var"){const a=r.ref??"";return!oe.hasRefusedChainToken(a)&&qt(Ht(a))}if(r.kind==="expr"){const a=oe.coalesceOperandRefs(r.expr);return a===null?!0:a.every(o=>qt(Ht(o)))}return!0})?s:[{kind:"text",value:e}]}function ot(e){if(vt(e))return{parts:[],sealed:e};if(Ke(e))return{parts:e.parts.map(n=>({...n})),sealed:null};const s=typeof e=="string"?e:"";return{parts:s?He(s):[],sealed:null}}function Dn(e,s){let n="";for(const r of e)switch(r.kind){case"text":n+=r.value??"";break;case"var":case"render":{const a=r.ref??"";n+=a in s?s[a]:"";break}case"secret":n+="•••";break;case"expr":n+=oe.serializeTemplate([r]);break}return n}const _n=/^steps\.([^.]+)\.output(?:\.(.+))?$/,qn=/^steps\.([^.]+)\.meta\.(app|version|action|connectionId)$/,xe=e=>{if(e.startsWith("vars."))return e.slice(5);const s=_n.exec(e);if(s)return s[2]?`${s[1]}.${s[2]}`:s[1];const n=qn.exec(e);return n?`${n[1]} meta · ${n[2]}`:e};function Hn(e){if(e===null||typeof e!="object"||Array.isArray(e))return;const s=Object.keys(e);if(s.length!==1||s[0]!=="var")return;const n=e.var;return typeof n=="string"?n:void 0}function Vn(e){const s=e.op==="or"?"||":"??",n=e.operands.map(r=>{const a=Hn(r);return a!==void 0?xe(a):JSON.stringify(r)}).join(` ${s} `);return n.length>40?`${n.slice(0,40)}…`:n}const Wn=/[.{}]/;function lt(e){return e===""||e!==e.trim()?!1:!Wn.test(e)}function Un(e){return e.split(".").every(lt)}function Re(e,s,{renderToggle:n}={}){const r=e.createElement("span");r.contentEditable="false",r.className=`w6w-expr-chip w6w-expr-chip-${s.kind}`,r.setAttribute("data-kind",s.kind);const a=e.createElement("span");a.className="w6w-expr-chip-sigil";const o=e.createElement("span");if(o.className="w6w-expr-chip-label",s.kind==="var")r.setAttribute("data-ref",s.ref??""),a.textContent="◆",o.textContent=xe(s.ref??""),r.title=`Variable: ${s.ref??""}`;else if(s.kind==="render")r.setAttribute("data-ref",s.ref??""),a.textContent="▤",o.textContent=xe(s.ref??""),r.title=`Render as template: ${s.ref??""}`;else if(s.kind==="secret")r.setAttribute("data-ref",s.ref??""),a.textContent="🔒",o.textContent=s.ref??"",r.title=`Secret: ${s.ref??""}`;else{const i=typeof s.expr=="string"?s.expr:JSON.stringify(s.expr??"");r.setAttribute("data-expr",i),a.textContent="ƒ";const c=oe.parseCoalesceChain(s.expr);c?(o.textContent=Vn(c),r.title=`Expression: ${oe.serializeTemplate([s])}`):(o.textContent=i.length>24?`${i.slice(0,24)}…`:i||"expr",r.title=`Expression: ${i}`)}if(r.append(a,o),(s.kind==="var"||s.kind==="render")&&n){const i=e.createElement("span");i.className="w6w-expr-chip-toggle",i.setAttribute("data-render-toggle","1"),i.setAttribute("role","button");const c=s.kind==="render"?"Stop rendering as a template":"Render this as a template";i.setAttribute("aria-label",c),i.title=c,i.textContent="⇄",r.append(i)}const l=e.createElement("span");return l.className="w6w-expr-chip-x",l.setAttribute("data-x","1"),l.setAttribute("role","button"),l.setAttribute("aria-label","Remove"),l.textContent="×",r.append(l),r}const ws=new Set(["div","p"]);function hs(e){const s=e.getAttribute("data-kind");if(s==="var"||s==="secret"||s==="render")return{kind:s,ref:e.getAttribute("data-ref")??""};if(s==="expr"){const n=e.getAttribute("data-expr")??"";let r=n;try{r=JSON.parse(n)}catch{r=n}return{kind:"expr",expr:r}}return null}function Ae(e){const s=[],n=o=>{if(!o)return;const l=s[s.length-1];l&&l.kind==="text"?l.value=(l.value??"")+o:s.push({kind:"text",value:o})},r=(o,l)=>{if(o.nodeType===Node.TEXT_NODE){n(o.textContent??"");return}if(o.nodeType!==Node.ELEMENT_NODE)return;const i=o,c=hs(i);if(c){s.push(c);return}const u=(i.tagName??"").toLowerCase();if(u==="br"){l||n(`
3
- `);return}const m=ws.has(u);m&&s.length>0&&n(`
4
- `),a(i,m)},a=(o,l)=>{const i=Array.from(o.childNodes);i.forEach((c,u)=>r(c,l&&u===i.length-1))};return a(e,!0),s}const fs=e=>!!e&&(e.tagName??"").toLowerCase()==="br";function ms(e){fs(e.lastChild)||e.appendChild(e.ownerDocument.createElement("br"))}function Bn(e){const s=e.ownerDocument.getSelection(),n=s!=null&&s.rangeCount?s.getRangeAt(0):null;if(!n||!e.contains(n.endContainer))return e;let r=n.endContainer;for(;r&&r!==e;){if(r.nodeType===Node.ELEMENT_NODE){const a=r;if(ws.has((a.tagName??"").toLowerCase()))return a}r=r.parentNode}return e}function bs(e){ms(Bn(e))}const Jn=e=>e.getAttribute("aria-multiline")!=="false";function xs(e,s,n){var o;const r=e.ownerDocument;e.textContent="";for(const l of s)l.kind==="text"?l.value&&e.appendChild(r.createTextNode(l.value)):e.appendChild(Re(r,l,n));const a=s[s.length-1];(a==null?void 0:a.kind)==="text"&&((o=a.value)!=null&&o.endsWith(`
5
- `))&&Jn(e)&&ms(e)}function Nt(e){const s=e.ownerDocument.getSelection();if(!s)return;const n=e.ownerDocument.createRange();n.selectNodeContents(e),n.collapse(!1),s.removeAllRanges(),s.addRange(n)}function Ee(e,s){const n=e.ownerDocument,r=n.getSelection(),a=r!=null&&r.rangeCount?r.getRangeAt(0):null;if(a&&e.contains(a.commonAncestorContainer)){a.deleteContents(),a.insertNode(s);const o=n.createRange();o.setStartAfter(s),o.collapse(!0),r==null||r.removeAllRanges(),r==null||r.addRange(o)}else fs(e.lastChild)?e.insertBefore(s,e.lastChild):e.appendChild(s),Nt(e);e.focus()}function gs(e,s={}){const n=e.ownerDocument,r=n.getSelection();if(!r||r.rangeCount===0||!r.isCollapsed)return!1;const a=r.getRangeAt(0),o=a.startContainer;if(o.nodeType!==Node.TEXT_NODE||!e.contains(o))return!1;const l=a.startOffset,i=o.textContent??"";if(l<2||i.slice(l-2,l)!=="}}")return!1;const c=i.lastIndexOf("{{",l-2);if(c===-1)return!1;const u=i.slice(c,l),m=He(u);if(m.length!==1||m[0].kind==="text")return!1;const p=n.createRange();p.setStart(o,c),p.setEnd(o,l),p.deleteContents();const h=Re(n,m[0],s);p.insertNode(h);const f=n.createRange();return f.setStartAfter(h),f.collapse(!0),r.removeAllRanges(),r.addRange(f),!0}function ys(e){const s=hs(e);if(!s)return null;const n=e.ownerDocument.createTextNode(oe.serializeTemplate([s]));return e.replaceWith(n),n}function kt({value:e,masked:s,multiline:n,options:r,fieldLabel:a,onSave:o,onClose:l,mode:i,onBind:c}){const u=i==="json-binding",[m,p]=d.useState(()=>ot(e).parts),[h,f]=d.useState(0),w=d.useRef(null),b=d.useRef(!1),[S,y]=d.useState({}),[x,N]=d.useState(null),[j,A]=d.useState(()=>new Set),k=g=>{A(O=>{const F=new Set(O);return F.has(g)?F.delete(g):F.add(g),F})};d.useLayoutEffect(()=>{const g=w.current;g&&(xs(g,m,{renderToggle:!0}),b.current&&(b.current=!1,Nt(g),g.focus()))},[h]);const P=()=>{const g=w.current;g&&p(Ae(g))},E=g=>{const O=w.current;O&&(Ee(O,Re(O.ownerDocument,g,{renderToggle:!0})),p(Ae(O)))},I=m.some(g=>g.kind==="render"),L=(g,{restoreFocus:O})=>{p(He(g)),f(F=>F+1)},D=()=>{const g=w.current;o==null||o(Te(g?Ae(g):m)),l()},v=g=>{u?c==null||c({$:g.ref??""}):o==null||o(Te([g])),l()},C=()=>{N(null),b.current=!0,f(g=>g+1)},_=r.vars??[],B=r.secrets??[],M=r.inputs??[],W=r.documents??[],H=r.steps??[],Q=H.length>0||!!r.hasTrigger,ee=oe.serializeTemplate(m),G=d.useMemo(()=>{const g={};for(const[O,F]of Object.entries(r.sampleValues??{}))g[O]=typeof F=="string"?F:JSON.stringify(F);return{...g,...S}},[r.sampleValues,S]),z=d.useMemo(()=>{const g=new Set,O=[];for(const F of m)(F.kind==="var"||F.kind==="render")&&F.ref&&!g.has(F.ref)&&(g.add(F.ref),O.push(F.ref));return O},[m]),ae=d.useMemo(()=>{try{return Dn(m,G)}catch{return ee}},[m,G,ee]),K=(g,O,F,V,q=!1,J)=>t.jsxs("div",{className:"w6w-exprmodal-item",style:{display:"flex",alignItems:"center",gap:4,minWidth:0},children:[t.jsxs("button",{type:"button",className:`w6w-exprmodal-source ${F}`,style:{flex:1,minWidth:0},title:q?`Insert ${g}`:`Use ${g}`,"aria-label":J,onClick:()=>q?E(O):v(O),children:[V!==null&&t.jsx("span",{className:"w6w-expr-chip-sigil",children:V}),t.jsx("span",{className:"w6w-exprmodal-source-label",children:g})]}),!u&&t.jsx(jt,{icon:"copy",iconSize:14,label:"Copy to expression editor","data-testid":"expr-copy-to-editor",onClick:()=>E(O)})]},`${O.kind}:${O.ref??g}`);return t.jsxs(ne,{title:u?"Bind to a step output":"Edit expression",subtitle:a?t.jsx("code",{children:a}):void 0,onClose:l,size:"full",headerRight:u?t.jsx("div",{className:"w6w-exprmodal-actions",children:t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:l,children:"Cancel"})}):t.jsxs("div",{className:"w6w-exprmodal-actions",children:[!s&&t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",disabled:I,title:I?"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:()=>{o==null||o(oe.serializeTemplate(m)),l()},children:"Use a plain value"}),t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:l,children:"Cancel"}),t.jsx("button",{type:"button",className:"w6w-btn",onClick:D,children:"Save"})]}),children:[t.jsxs("div",{className:"w6w-exprmodal",style:u?{gridTemplateColumns:"1fr"}:void 0,children:[t.jsxs("aside",{className:"w6w-exprmodal-sources",children:[u&&!Q&&t.jsx("span",{className:"w6w-expr-menu-empty",children:"No upstream steps"}),Q&&t.jsxs("div",{className:"w6w-exprmodal-group",children:[t.jsx("span",{className:"w6w-exprmodal-group-label",children:"Workflow state"}),r.hasTrigger&&K("trigger.event",{kind:"var",ref:"trigger.event"},"w6w-expr-chip-var","⚡"),H.map(g=>{const O=$=>{const Z=j.has(`meta:${$}`);return t.jsxs("button",{type:"button",className:"w6w-exprmodal-toggle-btn","data-testid":"expr-meta-toggle","aria-expanded":Z,title:Z?"Hide metadata":"Show metadata",onClick:()=>k(`meta:${$}`),children:["Metadata ",Z?"⌄":"›"]})},F=(g.outputs??[]).filter($=>$.path?Un($.key):lt($.key)),V=`step:${g.id}`,q=j.has(V),J=K(g.label??g.id,{kind:"var",ref:`steps.${g.id}.output`},"w6w-expr-chip-var",F.length>0?null:"▸",F.length>0);return u?t.jsxs(d.Fragment,{children:[t.jsx("span",{className:"w6w-exprmodal-shape-note",children:g.label??g.id}),K("Entire output",{kind:"var",ref:`steps.${g.id}.output`},"w6w-expr-chip-var","▸",!1,`Entire output of ${g.label??g.id}`),g.needsTest&&t.jsx("div",{className:"w6w-exprmodal-subsources",children:t.jsx("span",{className:"w6w-exprmodal-shape-note","data-testid":"expr-needs-test",children:"Run a test of this step to see its fields"})}),F.length>0&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"w6w-exprmodal-source-row",children:[t.jsx("button",{type:"button",className:"w6w-exprmodal-caret-btn","data-testid":"expr-caret-fields","aria-expanded":q,"aria-label":q?"Hide fields":"Show fields",title:q?"Hide fields":"Show fields",onClick:()=>k(V),children:q?"▾":"▸"}),t.jsx(rt,{count:F.length,open:q,onToggle:()=>k(V)})]}),q&&t.jsx("div",{className:"w6w-exprmodal-subsources",children:F.map($=>{const Z=`steps.${g.id}.output.${$.key}`;return K(xe(Z),{kind:"var",ref:Z},"w6w-expr-chip-var","·")})})]})]},g.id):t.jsxs(d.Fragment,{children:[F.length>0?t.jsxs("div",{className:"w6w-exprmodal-source-row",children:[t.jsx("button",{type:"button",className:"w6w-exprmodal-caret-btn","data-testid":"expr-caret-fields","aria-expanded":q,"aria-label":q?"Hide fields":"Show fields",title:q?"Hide fields":"Show fields",onClick:()=>k(V),children:q?"▾":"▸"}),J,t.jsxs("div",{className:"w6w-exprmodal-toggle-stack",children:[t.jsx(rt,{count:F.length,open:q,onToggle:()=>k(V)}),g.hasMeta===!0&&O(g.id)]})]}):J,g.needsTest&&t.jsx("div",{className:"w6w-exprmodal-subsources",children:t.jsx("span",{className:"w6w-exprmodal-shape-note","data-testid":"expr-needs-test",children:"Run a test of this step to see its fields"})}),F.length>0&&q&&t.jsxs("div",{className:"w6w-exprmodal-subsources",children:[g.outputsFrom==="test"&&t.jsx("span",{className:"w6w-exprmodal-shape-note","data-testid":"expr-fields-from-test",children:"Fields from the last test run"}),F.map($=>{const Z=`steps.${g.id}.output.${$.key}`;return K(xe(Z),{kind:"var",ref:Z},"w6w-expr-chip-var","·")})]}),g.hasMeta===!0&&t.jsxs(t.Fragment,{children:[F.length===0&&t.jsx("div",{className:"w6w-exprmodal-source-row w6w-exprmodal-meta-row",children:O(g.id)}),j.has(`meta:${g.id}`)&&t.jsx("div",{className:"w6w-exprmodal-subsources","data-testid":"expr-meta-fields",children:zn.map(([$,Z])=>K(Z,{kind:"var",ref:`steps.${g.id}.meta.${$}`},"w6w-expr-chip-var","·"))})]})]},g.id)})]}),!u&&t.jsxs(t.Fragment,{children:[r.inputs!==void 0&&t.jsxs("div",{className:"w6w-exprmodal-group",children:[t.jsx("span",{className:"w6w-exprmodal-group-label",children:"Inputs"}),M.length===0&&t.jsx("span",{className:"w6w-expr-menu-empty",children:"No inputs"}),M.map(g=>K(g,{kind:"var",ref:`inputs.${g}`},"w6w-expr-chip-var","⇥"))]}),t.jsxs("div",{className:"w6w-exprmodal-group",children:[t.jsxs("div",{className:"w6w-field-labelrow",children:[t.jsx("span",{className:"w6w-exprmodal-group-label",children:"Variables"}),r.createVar&&t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm","data-testid":"expr-add-var",onClick:()=>N("var"),children:"+ Add"})]}),_.length===0&&t.jsx("span",{className:"w6w-expr-menu-empty",children:"No variables"}),_.map(g=>K(g,{kind:"var",ref:`vars.${g}`},"w6w-expr-chip-var","◆"))]}),t.jsxs("div",{className:"w6w-exprmodal-group",children:[t.jsx("span",{className:"w6w-exprmodal-group-label",children:"Documents"}),W.length===0&&t.jsx("span",{className:"w6w-expr-menu-empty",children:"No documents"}),W.map(g=>{const O=(g.fields??[]).filter(J=>lt(J.key)),F=`doc:${g.key}`,V=j.has(F),q=K(g.key,{kind:"var",ref:`documents.${g.key}`},"w6w-expr-chip-var","▦",O.length>0);return t.jsxs(d.Fragment,{children:[O.length>0?t.jsxs("div",{className:"w6w-exprmodal-source-row",children:[q,t.jsx(rt,{count:O.length,open:V,onToggle:()=>k(F)})]}):q,O.length>0&&V&&t.jsx("div",{className:"w6w-exprmodal-subsources",children:O.map(J=>{const $=`documents.${g.key}.${J.key}`;return t.jsxs("div",{className:"w6w-exprmodal-subsource-row",children:[K(J.key,{kind:"var",ref:$},"w6w-expr-chip-var","·"),t.jsx("button",{type:"button",className:"w6w-exprmodal-render-btn","data-testid":"expr-insert-render",title:`Insert ${$} and render its {{ }} placeholders`,"aria-label":`Insert ${$} and render its {{ }} placeholders`,onClick:()=>E({kind:"render",ref:$}),children:"▤"})]},$)})})]},g.key)})]}),t.jsxs("div",{className:"w6w-exprmodal-group",children:[t.jsxs("div",{className:"w6w-field-labelrow",children:[t.jsx("span",{className:"w6w-exprmodal-group-label",children:"Secrets"}),r.createSecret&&t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm","data-testid":"expr-add-secret",onClick:()=>N("secret"),children:"+ Add"})]}),B.length===0&&t.jsx("span",{className:"w6w-expr-menu-empty",children:"No secrets"}),B.map(g=>K(g,{kind:"secret",ref:g},"w6w-expr-chip-secret","🔒"))]})]})]}),!u&&t.jsxs("div",{className:"w6w-exprmodal-main",children:[t.jsxs("div",{className:"w6w-exprmodal-editor",children:[t.jsxs("span",{className:"w6w-exprmodal-pane-label",children:["Expression",t.jsx("span",{className:"w6w-muted w6w-small",children:" — click a source on the left, or type"})]}),t.jsx("div",{ref:w,className:`w6w-exprmodal-chips${s?" is-masked":""}${m.length===0?" is-empty":""}`,contentEditable:!0,suppressContentEditableWarning:!0,role:"textbox",tabIndex:0,"aria-multiline":n?"true":"false","aria-label":"Expression","data-placeholder":"Type text and insert {x} variables, 🔒 secrets, or ▸ step outputs…",spellCheck:!1,onInput:()=>{const g=w.current;g&&gs(g,{renderToggle:!0}),P()},onDoubleClick:g=>{const O=g.target;if(O.closest("[data-x]")||O.closest("[data-render-toggle]"))return;const F=O.closest(".w6w-expr-chip");if(!F)return;g.preventDefault();const V=ys(F);if(V){const q=V.ownerDocument,J=q.createRange();J.setStartAfter(V),J.collapse(!0);const $=q.getSelection();$==null||$.removeAllRanges(),$==null||$.addRange(J)}P()},onBlur:()=>{const g=w.current;g&&L(oe.serializeTemplate(Ae(g)),{restoreFocus:!1})},onPaste:g=>{var V;g.preventDefault();const O=w.current;if(!O)return;const F=((V=g.clipboardData)==null?void 0:V.getData("text/plain"))??"";for(const q of He(F))q.kind==="text"?Ee(O,O.ownerDocument.createTextNode(q.value??"")):Ee(O,Re(O.ownerDocument,q,{renderToggle:!0}));P()},onClick:g=>{var q;const O=g.target,F=O.closest("[data-x]");if(F){g.preventDefault(),(q=F.closest(".w6w-expr-chip"))==null||q.remove(),P();return}const V=O.closest("[data-render-toggle]");if(V){g.preventDefault();const J=V.closest(".w6w-expr-chip");if(J){const $=J.getAttribute("data-ref")??"",Z=J.getAttribute("data-kind")==="render"?"var":"render";J.replaceWith(Re(J.ownerDocument,{kind:Z,ref:$},{renderToggle:!0}))}P()}},onKeyDown:g=>{if(g.key!=="Enter"||(g.preventDefault(),!n))return;const O=w.current;O&&(Ee(O,O.ownerDocument.createTextNode(`
6
- `)),bs(O),P())}})]}),z.length>0&&t.jsxs("div",{className:"w6w-exprmodal-preview",children:[t.jsxs("span",{className:"w6w-exprmodal-pane-label",children:["Sample values",t.jsxs("span",{className:"w6w-muted w6w-small",children:[" ","— try the expression against example data"]})]}),z.map(g=>t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:g}),t.jsx("input",{type:"text",value:S[g]??"",placeholder:"sample value",onChange:O=>y(F=>({...F,[g]:O.target.value}))})]},g))]}),t.jsxs("div",{className:"w6w-exprmodal-preview w6w-exprmodal-result-pane",children:[t.jsxs("span",{className:"w6w-exprmodal-pane-label",children:["Result",t.jsxs("span",{className:"w6w-muted w6w-small",children:[" ","— live preview against the sample values"]})]}),t.jsx(de.Copyable,{value:ae,readOnly:!0,children:t.jsx("pre",{className:"w6w-exprmodal-result",children:ae||" "})})]})]})]}),x==="var"&&r.createVar&&t.jsx(Vt,{kind:"var",onCreate:r.createVar,onClose:C}),x==="secret"&&r.createSecret&&t.jsx(Vt,{kind:"secret",onCreate:r.createSecret,onClose:C})]})}function rt({count:e,open:s,onToggle:n}){return t.jsxs("button",{type:"button",className:"w6w-exprmodal-toggle-btn","data-testid":"expr-toggle-fields","aria-expanded":s,title:s?"Hide fields":"Show fields",onClick:n,children:[e," ",e===1?"field":"fields"," ",s?"⌄":"›"]})}const zn=[["app","App"],["version","App version"],["action","Action"],["connectionId","Connection ID"]];function Vt({kind:e,onCreate:s,onClose:n}){const[r,a]=d.useState(""),[o,l]=d.useState(""),[i,c]=d.useState(""),[u,m]=d.useState(null),[p,h]=d.useState(!1),f=e==="var"?"variable":"secret";async function w(){m(null),h(!0);try{await s({name:r,value:o,description:i||void 0}),n()}catch(b){m(b.message)}finally{h(!1)}}return t.jsxs(ne,{title:`Add ${f}`,onClose:n,children:[t.jsx("div",{className:"w6w-modal-body",children:t.jsxs("div",{className:"w6w-stack",children:[t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:"Name"}),t.jsx("input",{type:"text",value:r,onChange:b=>a(b.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}),t.jsx("span",{className:"w6w-muted w6w-small",children:"Lowercase letters, digits, and underscores. Must start with a letter or underscore."})]}),t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:"Value"}),t.jsx("input",{type:e==="secret"?"password":"text",value:o,onChange:b=>l(b.target.value),autoComplete:"off","data-testid":"expr-add-value-value"}),e==="secret"&&t.jsx("span",{className:"w6w-muted w6w-small",children:"Stored encrypted at rest. Once saved, it is not readable through the UI."})]}),t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:"Description"}),t.jsx("input",{type:"text",value:i,onChange:b=>c(b.target.value),placeholder:"Optional",autoComplete:"off"})]}),u&&t.jsx("div",{className:"w6w-result w6w-error",children:u})]})}),t.jsxs("div",{className:"w6w-modal-actions",children:[t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost","data-testid":"expr-add-value-cancel",onClick:n,children:"Cancel"}),t.jsx("button",{type:"button",className:"w6w-btn","data-testid":"expr-add-value-save",disabled:!r||!o||p,onClick:w,children:p?"Saving…":"Save"})]})]})}function Gn(e,s){return s?e.filter(n=>n.id!==s):e}const it=d.createContext({});function Kn({value:e,children:s}){const n=d.useContext(it),r=d.useMemo(()=>({...n,...e}),[n,e]);return t.jsx(it.Provider,{value:r,children:s})}function Ye(){return d.useContext(it)}function Ct({value:e,onChange:s,placeholder:n,masked:r,multiline:a,readOnly:o,options:l,"aria-label":i}){const[c,u]=d.useState(()=>ot(e)),{parts:m,sealed:p}=c,[h,f]=d.useState(0),[w,b]=d.useState(!1),[S,y]=d.useState(!1),x=d.useRef(!1),N=d.useRef(null),j=d.useRef(null),A=Ye(),k={...A,...l??{}},P=A.sealSecret;d.useLayoutEffect(()=>{const v=N.current;!v||p||(xs(v,m),(x.current||v.ownerDocument.activeElement===v)&&(v.focus(),Nt(v),x.current=!1))},[h,p]);const E=()=>{const v=N.current;if(!v)return;const C=Ae(v);u(_=>({..._,parts:C})),s(Te(C))},I=async v=>{if(!P)return!1;b(!0);try{const C=await P(v);return x.current=!1,u({parts:[],sealed:C}),f(_=>_+1),s(C),!0}catch{return!1}finally{b(!1)}},L=v=>{var B;if(S||!r||o||w)return;const C=v.relatedTarget;if(C&&((B=j.current)!=null&&B.contains(C)))return;const _=Te(m);typeof _=="string"&&_!==""&&I(_)},D=v=>{if(r&&typeof v=="string"&&v.trim()!==""){I(v);return}x.current=!1,u(ot(v)),f(C=>C+1),s(v)};return p?t.jsxs("div",{className:`w6w-expr-sealed${o?" is-readonly":""}`,"aria-label":i,children:[t.jsxs("span",{className:"w6w-expr-chip w6w-expr-chip-secret",title:"Encrypted secret",children:[t.jsx("span",{className:"w6w-expr-chip-sigil",children:"🔒"}),t.jsx("span",{className:"w6w-expr-chip-label",children:"••••••"})]}),!o&&t.jsx("button",{type:"button",className:"w6w-expr-replace",onClick:()=>{x.current=!0,u({parts:[],sealed:null}),f(v=>v+1),s("")},children:"Replace"})]}):t.jsxs("div",{className:"w6w-expr",ref:j,onBlur:L,children:[t.jsxs("div",{className:"w6w-expr-field",children:[t.jsx("div",{ref:N,className:`w6w-expr-editor${r?" is-masked":""}${m.length===0?" is-empty":""}${o?" is-readonly":""}`,contentEditable:!o,suppressContentEditableWarning:!0,role:"textbox",tabIndex:o?-1:0,"aria-multiline":a?"true":"false","aria-label":i,"data-placeholder":n??"",spellCheck:!1,onInput:()=>{const v=N.current;v&&gs(v),E()},onClick:v=>{var _;const C=v.target.closest("[data-x]");C&&(v.preventDefault(),(_=C.closest(".w6w-expr-chip"))==null||_.remove(),E())},onDoubleClick:v=>{const C=v.target;if(C.closest("[data-x]"))return;const _=C.closest(".w6w-expr-chip");if(!_)return;v.preventDefault();const B=ys(_);if(B){const M=B.ownerDocument,W=M.createRange();W.setStartAfter(B),W.collapse(!0);const H=M.getSelection();H==null||H.removeAllRanges(),H==null||H.addRange(W)}E()},onKeyDown:v=>{if(v.key!=="Enter"||(v.preventDefault(),!a))return;const C=N.current;C&&(Ee(C,C.ownerDocument.createTextNode(`
7
- `)),bs(C),E())}}),!o&&t.jsx("button",{type:"button",className:"w6w-expr-edit",title:"Edit expression — browse variables, secrets & step outputs","aria-label":"Edit expression",onClick:()=>y(!0),children:"ƒx"})]}),S&&t.jsx(kt,{value:Te(m),masked:r,multiline:a,options:k,fieldLabel:i,onSave:D,onClose:()=>y(!1)})]})}const ct="vars.",ut="documents.";function js(e,s){const n={},r={};for(const[a,o]of Object.entries(e??{}))a.startsWith(ct)?n[a.slice(ct.length)]=o:a.startsWith(ut)&&(r[a.slice(ut.length)]=o);return{vars:n,documents:r,steps:(s==null?void 0:s.steps)??{},trigger:(s==null?void 0:s.trigger)??{},flat:e??{}}}function Yn(e,s){const n=s.split(".");let r=e;for(const a of n){if(r===null||typeof r!="object")return{present:!1,value:void 0};if(!(a in r))return{present:!1,value:void 0};r=r[a]}return{present:!0,value:r}}function vs(e,s){if(s.flat&&(e.startsWith(ct)||e.startsWith(ut))&&Object.hasOwn(s.flat,e))return{status:"resolved",ref:e,value:s.flat[e]};const n=Yn(s,e);return n.present?{status:"resolved",ref:e,value:n.value}:{status:"unresolved",ref:e}}function Xn(e,s){switch(e.kind){case"text":return{status:"resolved",value:e.value??""};case"var":return vs(e.ref??"",s);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 Ns(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&Object.keys(e).length===1&&"$"in e}function Qn(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&Object.keys(e).length===1&&"$expr"in e}function ks(e,s){return vt(e)?[{status:"masked"}]:Ke(e)?e.parts.map(n=>Xn(n,s)):Ns(e)?[vs(String(e.$),s)]:Qn(e)?[{status:"not-evaluated"}]:[{status:"resolved",value:e}]}function dt(e,s){if(e===s)return!0;if(typeof e!=typeof s||e===null||s===null||typeof e!="object")return!1;const n=Array.isArray(e),r=Array.isArray(s);if(n!==r)return!1;if(n){const c=e,u=s;return c.length===u.length&&c.every((m,p)=>dt(m,u[p]))}const a=e,o=s,l=Object.keys(a),i=Object.keys(o);return l.length===i.length&&l.every(c=>c in o&&dt(a[c],o[c]))}function Cs(e){switch(e.status){case"resolved":return e.value===void 0?"<not set>":e.value;case"unresolved":return`<unresolved: ${e.ref}>`;case"not-evaluated":return"<not evaluated>";case"masked":return e.ref?`<masked: ${e.ref}>`:"<masked>"}}function Zn(e){return e.status==="resolved"&&e.value!==void 0?typeof e.value=="string"?e.value:JSON.stringify(e.value):String(Cs(e))}function er(e){return e.length===1?Cs(e[0]):e.map(Zn).join("")}function St(e,s){return er(ks(e,s))}function tr(e,s){const n={};for(const r of e)n[r.key||"(no key)"]=St(r.value,s);return n}function Pe(e,s){const n=e.showIf;if(!n)return!0;const r=s(n.field);return n.equals!==void 0?r===n.equals:n.in?n.in.some(a=>a===r):n.notIn?!n.notIn.some(a=>a===r):n.truthy!==void 0?n.truthy?!!r:!r:!0}function ge(e){const s=[];for(const n of e)s.push(n),n.type==="section"&&n.children&&s.push(...ge(n.children));return s}function Ie(e,s){const n=[];for(let r=0;r<e.length;){const a=e[r].row;if(a){const o=[];for(;r<e.length&&e[r].row===a;)o.push(e[r++]);n.push(t.jsx("div",{className:"w6w-field-row",children:o.map(s)},`row:${a}`))}else n.push(s(e[r])),r++}return n}function Ss(e,s,n,r){const a=o=>o.type==="section"?t.jsx(sr,{param:o,effective:n,renderOne:a},o.key):o.repeat&&o.type!=="array"?t.jsx(or,{param:o,value:e[o.key],onChange:s,readOnly:r},o.key):o.type==="group"&&o.children&&o.children.length>0?t.jsx(ar,{param:o,value:e[o.key],onChange:s,effective:n,readOnly:r},o.key):t.jsx(lr,{param:o,value:e[o.key],onChange:s,effective:n,readOnly:r},o.key);return a}function pe({params:e,values:s,onChange:n,readOnly:r}){const a=ge(e),o=p=>{var h;return s[p]!==void 0?s[p]:(h=a.find(f=>f.key===p))==null?void 0:h.default},l=e.filter(p=>Pe(p,o)),i=l.filter(p=>p.required||!p.advanced),c=l.filter(p=>!p.required&&p.advanced),u=(p,h)=>{if(p==="language"){const f={...s,[p]:h};for(const w of a){if(w.type!=="code")continue;const b=s[w.key];(b===void 0||b===w.default||b===pt)&&(f[w.key]=h==="python"?pt:w.default)}n(f);return}n({...s,[p]:h})};if(e.length===0)return t.jsx("p",{className:"w6w-muted w6w-small",children:"This action takes no parameters."});const m=Ss(s,u,o,r);return t.jsxs("div",{className:"w6w-stack",children:[Ie(i,m),c.length>0&&t.jsxs("details",{className:"w6w-params-optional",children:[t.jsxs("summary",{className:"w6w-muted w6w-small",children:["Additional parameters (",c.length,")"]}),t.jsx("div",{className:"w6w-stack",style:{marginTop:8},children:Ie(c,m)})]})]})}function sr({param:e,effective:s,renderOne:n}){const r=(e.children??[]).filter(a=>Pe(a,s));return e.section==="collapsible"?t.jsxs("details",{className:"w6w-section",open:e.collapsed===!1,children:[t.jsxs("summary",{className:"w6w-section-summary",children:[t.jsx("span",{className:"w6w-section-title",children:e.title??e.label??e.key}),e.subtitle&&t.jsx("span",{className:"w6w-section-subtitle",children:e.subtitle})]}),t.jsx("div",{className:"w6w-stack w6w-section-body",children:Ie(r,n)})]}):e.layout==="row"?t.jsx("div",{className:"w6w-field-row",children:r.map(n)}):t.jsx("div",{className:"w6w-stack",children:Ie(r,n)})}const nr=new Set(["string","text","number","boolean","select"]);function rr(e){return e.length>0&&e.every(s=>nr.has(s.type)&&!s.children)}function ar({param:e,value:s,onChange:n,effective:r,readOnly:a}){const o=e.children??[],l=s??{},i=(h,f)=>n(e.key,{...l,[h]:f}),c=ge(o),u=h=>{const f=c.find(w=>w.key===h);return f?l[h]!==void 0?l[h]:f.default:r(h)},m=o.filter(h=>Pe(h,u)),p=Ss(l,i,u,a);return t.jsxs("div",{className:"w6w-stack",children:[t.jsx("span",{className:"w6w-section-title",children:e.label??e.key}),t.jsx("div",{className:"w6w-stack w6w-section-body",children:Ie(m,p)})]})}function or({param:e,value:s,onChange:n,readOnly:r}){if(e.type==="group"){const o=e.children??[];if(!rr(o))return t.jsx(As,{param:e,value:s,onChange:n,readOnly:r});const l={...e,item:{type:"object",fields:o}};return t.jsx(wt,{param:l,value:s,onChange:n,readOnly:r})}const a={...e,item:{type:e.type,options:e.options}};return t.jsx(wt,{param:a,value:s,onChange:n,readOnly:r})}const pt=`# Runs as a function body. Return the step's output.
8
- return input`;function lr({param:e,value:s,onChange:n,effective:r,readOnly:a}){var p,h;const o=e.label??e.key,l=e.required&&e.type!=="boolean"?" *":"",i=d.useId();if(e.type==="boolean"){const f=!!(s??e.default??!1);return t.jsx(he,{param:e,value:s,onChange:n,readOnly:a,label:o,req:l,variant:"inline",controlId:i,children:t.jsx("input",{id:i,type:"checkbox",checked:f,disabled:a,onChange:w=>n(e.key,w.target.checked)})})}if(e.type==="json"||e.type==="group")return t.jsx(As,{param:e,value:s,onChange:n,readOnly:a});if(e.type==="code"){const f=r==null?void 0:r("language"),w=f==="python"?"python":f==="javascript"?"javascript":void 0,b=w==="python"?pt:e.default,S=s??b??"";return t.jsxs("div",{className:"w6w-field",children:[t.jsxs("span",{children:[o,l]}),t.jsx(ds,{value:String(S),readOnly:a,minHeight:"180px",language:w,"aria-label":`${e.key} code`,onChange:y=>n(e.key,y)}),e.hint&&t.jsx("span",{className:"w6w-hint",children:e.hint})]})}if(e.type==="vars")return t.jsx(dr,{param:e,value:s,onChange:n,readOnly:a});if(e.type==="text"||(p=e.config)!=null&&p.multiline){const f=s??e.default??"";return t.jsx(he,{param:e,value:s,onChange:n,readOnly:a,label:o,req:l,children:t.jsx("textarea",{rows:3,value:String(f),readOnly:a,"aria-label":o,onChange:w=>n(e.key,w.target.value)})})}if(e.type==="multiselect")return t.jsx(ir,{param:e,value:s,onChange:n,readOnly:a});if(e.type==="array")return t.jsx(wt,{param:e,value:s,onChange:n,readOnly:a});if(Array.isArray(e.options)&&e.options.length>0){const f=s??e.default??((h=e.options[0])==null?void 0:h.value)??"",w=e.type==="number";return t.jsx(he,{param:e,value:s,onChange:n,readOnly:a,label:o,req:l,children:t.jsx("select",{value:String(f),disabled:a,"aria-label":o,onChange:b=>n(e.key,w?Number(b.target.value):b.target.value),children:e.options.map(b=>t.jsx("option",{value:String(b.value),children:b.label},String(b.value)))})})}if(e.type==="secret"){const f=s??e.default;return t.jsxs("div",{className:"w6w-field",children:[t.jsxs("span",{children:[o,l]}),t.jsx(Ct,{value:f,masked:!0,readOnly:a,"aria-label":o,onChange:w=>n(e.key,w)}),e.hint&&t.jsx("span",{className:"w6w-hint",children:e.hint})]})}const c=e.type==="number"?"number":"text",u=s??e.default??"",m=typeof u=="object"&&u!==null?JSON.stringify(u):String(u??"");return t.jsx(he,{param:e,value:s,onChange:n,readOnly:a,label:o,req:l,children:t.jsx("input",{type:c,value:m,readOnly:a,"aria-label":o,autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",spellCheck:!1,"data-1p-ignore":"true","data-lpignore":"true","data-bwignore":"true","data-form-type":"other",onChange:f=>n(e.key,e.type==="number"?Number(f.target.value):f.target.value)})})}function he({param:e,value:s,onChange:n,readOnly:r,label:a,req:o,bare:l,variant:i="boxed",controlId:c,children:u}){var y;const m=Ke(s),p=e.type==="text"||!!((y=e.config)!=null&&y.multiline),[h,f]=d.useState(!1),w=Ye(),b=i==="inline"&&!m,S=t.jsxs(t.Fragment,{children:[t.jsx("div",{className:b?"w6w-fx-inline":`w6w-fx-wrap${m?" is-fx":""}`,children:m?t.jsx(Ct,{value:s,multiline:p,readOnly:r,"aria-label":a,onChange:x=>n(e.key,x)}):t.jsxs(t.Fragment,{children:[u,!r&&t.jsx("button",{type:"button",className:"w6w-expr-fx",title:"Use an expression","aria-label":`Use an expression for ${a}`,onClick:()=>f(!0),children:"ƒx"}),b&&t.jsxs("label",{className:"w6w-fx-inline-label",htmlFor:c,children:[a,o]})]})}),h&&t.jsx(kt,{value:s,multiline:p,options:w,fieldLabel:a,onSave:x=>n(e.key,x),onClose:()=>f(!1)})]});return l?S:t.jsxs("div",{className:"w6w-field",children:[!b&&t.jsxs("span",{children:[a,o]}),S,e.hint&&t.jsx("span",{className:"w6w-hint",children:e.hint})]})}function As({param:e,value:s,onChange:n,readOnly:r}){const a=Ns(s)&&typeof s.$=="string",o=a?String(s.$):"",l=s??e.default,[i,c]=d.useState(()=>a||l===void 0?"":JSON.stringify(l,null,2)),[u,m]=d.useState(!1),[p,h]=d.useState(!1),[f,w]=d.useState(!1),b=Ye();d.useEffect(()=>{if(a)return;let A;try{A=i.trim()===""?void 0:JSON.parse(i)}catch{A=void 0}JSON.stringify(A)!==JSON.stringify(l)&&(c(l===void 0?"":JSON.stringify(l,null,2)),m(!1))},[l,e.key,a]);const S=A=>{c(A)},y=A=>{m(!1),n(e.key,A)},x=e.label??e.key,N=()=>{let A;try{A=i.trim()===""?void 0:JSON.parse(i)}catch{A=void 0}n(e.key,A)},j=(()=>{if(!a)return"";const A={};for(const[k,P]of Object.entries(b.sampleValues??{})){const E=/^steps\.([^.]+)\.output$/.exec(k);E&&(A[E[1]]={output:P})}return JSON.stringify(St(s,js(void 0,{steps:A})),null,2)})();return t.jsxs("div",{className:"w6w-field",children:[t.jsxs("span",{className:"w6w-field-labelrow",children:[t.jsxs("span",{children:[x,e.required?" *":""]}),!r&&!a&&t.jsx("button",{type:"button",className:"w6w-expr-fx",title:"Use an expression","aria-label":`Use an expression for ${x}`,onClick:()=>w(!0),children:"ƒx"}),!a&&t.jsx("button",{type:"button",className:"w6w-icon-btn w6w-btn-sm",title:"Open in full view","aria-label":`Open ${x} in full view`,onClick:()=>h(!0),children:t.jsx(de.Icon,{name:"maximize",size:14})})]}),a?t.jsxs("div",{className:"w6w-json-binding",children:[t.jsxs("div",{className:"w6w-fx-wrap is-fx",children:[t.jsx("code",{children:o}),!r&&t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:()=>w(!0),children:"Edit"}),t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:N,children:"Clear"})]})]}),t.jsx("pre",{className:"w6w-json-binding-preview","data-testid":"json-binding-preview",style:{margin:0,maxHeight:260,overflow:"auto",fontSize:"0.85em"},children:j})]}):t.jsx(ue,{value:i,onChange:S,readOnly:r,minHeight:"34px",maxHeight:"260px","aria-label":`${e.key} JSON`,onValidChange:y,onValidityChange:({valid:A})=>m(!A)}),f&&t.jsx(kt,{mode:"json-binding",value:void 0,options:b,fieldLabel:x,onBind:A=>n(e.key,A),onClose:()=>w(!1)}),!a&&u&&t.jsx("span",{className:"w6w-hint",style:{color:"var(--w6w-danger)"},children:"Invalid JSON"}),e.hint&&t.jsx("span",{className:"w6w-hint",children:e.hint}),p&&!a&&t.jsxs(ne,{title:x,subtitle:t.jsx("code",{children:"JSON"}),size:"wide",onClose:()=>h(!1),children:[t.jsx("div",{className:"w6w-json-fullview",children:t.jsx(ue,{value:i,onChange:S,readOnly:r,height:"100%",minHeight:"360px","aria-label":`${e.key} JSON (full view)`,onValidChange:y,onValidityChange:({valid:A})=>m(!A)})}),u&&t.jsx("span",{className:"w6w-hint",style:{color:"var(--w6w-danger)"},children:"Invalid JSON"})]})]})}function ir({param:e,value:s,onChange:n,readOnly:r}){const a=Array.isArray(e.options)?e.options:[],o=Array.isArray(s)?s:Array.isArray(e.default)?e.default:[],l=new Set(o.map(String)),i=a.filter(w=>!l.has(String(w.value))),c=w=>{var b;return((b=a.find(S=>String(S.value)===String(w)))==null?void 0:b.label)??String(w)},u=w=>{if(!w||l.has(w))return;const b=a.find(S=>String(S.value)===w);n(e.key,[...o,b?b.value:w])},m=w=>n(e.key,o.filter(b=>String(b)!==String(w))),p=typeof e.placeholder=="string"&&e.placeholder?e.placeholder:"Select…",h=e.label??e.key,f=e.required?" *":"";return t.jsx(he,{param:e,value:s,onChange:n,readOnly:r,label:h,req:f,children:t.jsxs("div",{className:`w6w-multiselect${r?" is-readonly":""}`,children:[o.map(w=>t.jsxs("span",{className:"w6w-chip",children:[c(w),!r&&t.jsx("button",{type:"button",className:"w6w-chip-x","aria-label":`Remove ${c(w)}`,title:"Remove",onClick:()=>m(w),children:"×"})]},String(w))),!r&&t.jsxs("select",{className:"w6w-multiselect-add",value:"",disabled:i.length===0,"aria-label":`Add to ${e.label??e.key}`,onChange:w=>u(w.target.value),children:[t.jsx("option",{value:"",children:i.length>0?o.length?"Add more…":p:"All selected"}),i.map(w=>t.jsx("option",{value:String(w.value),children:w.label},String(w.value)))]})]})})}function cr({field:e,value:s,onChange:n,readOnly:r}){var l;const a=e.placeholder??e.label??e.key;if(Array.isArray(e.options)&&e.options.length>0)return t.jsx("select",{className:"w6w-array-input",value:String(s??e.default??((l=e.options[0])==null?void 0:l.value)??""),disabled:r,"aria-label":e.label??e.key,onChange:i=>n(i.target.value),children:e.options.map(i=>t.jsx("option",{value:String(i.value),children:i.label},String(i.value)))});if(e.type==="boolean")return t.jsxs("label",{className:"w6w-array-check",title:e.label??e.key,children:[t.jsx("input",{type:"checkbox",checked:!!(s??e.default??!1),disabled:r,"aria-label":e.label??e.key,onChange:i=>n(i.target.checked)}),t.jsx("span",{children:e.label??e.key})]});const o=e.type==="number";return t.jsx("input",{className:"w6w-array-input",type:o?"number":"text",value:String(s??e.default??""),placeholder:a,"aria-label":e.label??e.key,readOnly:r,onChange:i=>n(o?Number(i.target.value):i.target.value)})}function wt({param:e,value:s,onChange:n,readOnly:r}){const a=e.item??{type:"string"},o=a.type==="object",l=Array.isArray(s)?s:Array.isArray(e.default)?e.default:[],i=m=>n(e.key,m),c=()=>o?Object.fromEntries((a.fields??[]).map(m=>[m.key,m.default??""])):a.type==="number"?0:"",u=(m,p)=>i(l.map((h,f)=>f===m?p:h));return t.jsxs("div",{className:"w6w-field",children:[t.jsxs("span",{children:[e.label??e.key,e.required?" *":""]}),t.jsxs("div",{className:"w6w-array",children:[l.length===0&&t.jsx("p",{className:"w6w-muted w6w-small",children:"None yet — add one below."}),l.map((m,p)=>t.jsxs("div",{className:"w6w-array-row",children:[o?t.jsx("div",{className:"w6w-array-cells",children:(a.fields??[]).map(h=>t.jsx(cr,{field:h,value:m==null?void 0:m[h.key],readOnly:r,onChange:f=>u(p,{...m??{},[h.key]:f})},h.key))}):t.jsx("input",{className:"w6w-array-input",type:a.type==="number"?"number":"text",value:String(m??""),placeholder:a.placeholder,readOnly:r,onChange:h=>u(p,a.type==="number"?Number(h.target.value):h.target.value)}),!r&&t.jsx("button",{type:"button",className:"w6w-array-x","aria-label":"Remove item",title:"Remove",onClick:()=>i(l.filter((h,f)=>f!==p)),children:"×"})]},p)),!r&&t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm w6w-array-add",onClick:()=>i([...l,c()]),children:"+ Add"})]}),e.hint&&t.jsx("span",{className:"w6w-hint",children:e.hint})]})}const ur=["string","number","boolean","json"];function Wt(e,s){if(e==="number"){if(s.trim()==="")return"";const n=Number(s);return Number.isNaN(n)?s:n}if(e==="boolean")return s==="true";if(e==="json")try{return JSON.parse(s)}catch{return s}return s}function Ut(e){return e==null?"":typeof e=="object"?JSON.stringify(e):String(e)}function dr({param:e,value:s,onChange:n,readOnly:r}){const a=Array.isArray(s)?s:Array.isArray(e.default)?e.default:[],o=i=>n(e.key,i),l=(i,c)=>o(a.map((u,m)=>m===i?{...u,...c}:u));return t.jsxs("div",{className:"w6w-field",children:[t.jsxs("span",{children:[e.label??e.key,e.required?" *":""]}),t.jsxs("div",{className:"w6w-stack",children:[a.length===0&&t.jsx("p",{className:"w6w-muted w6w-small",children:"No variables yet — add one below."}),a.map((i,c)=>t.jsxs("div",{className:"w6w-datavar-row",children:[t.jsx("input",{type:"text",placeholder:"key",value:i.key,readOnly:r,onChange:u=>l(c,{key:u.target.value})}),t.jsx("select",{value:i.type,disabled:r,onChange:u=>{const m=u.target.value;l(c,{type:m,value:Wt(m,Ut(i.value))})},children:ur.map(u=>t.jsx("option",{value:u,children:u},u))}),t.jsx(he,{bare:!0,param:e,value:i.value,onChange:(u,m)=>l(c,{value:m}),readOnly:r,label:i.key||"value",req:"",children:i.type==="boolean"?t.jsxs("select",{value:i.value===!0?"true":"false",disabled:r,onChange:u=>l(c,{value:u.target.value==="true"}),children:[t.jsx("option",{value:"true",children:"true"}),t.jsx("option",{value:"false",children:"false"})]}):t.jsx("input",{type:i.type==="number"?"number":"text",placeholder:"value",value:Ut(i.value),readOnly:r,onChange:u=>l(c,{value:Wt(i.type,u.target.value)})})}),!r&&t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost","aria-label":`Remove variable ${i.key||c+1}`,title:"Remove",onClick:()=>o(a.filter((u,m)=>m!==c)),children:"×"})]},c)),!r&&t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>o([...a,{key:"",type:"string",value:""}]),children:"+ Add variable"})]}),e.hint&&t.jsx("span",{className:"w6w-hint",children:e.hint})]})}function At(e){return Array.isArray(e)?e:[]}function Es(e){return e==="object"||e==="array"?"json":e==="number"||e==="boolean"||e==="json"?e:"string"}function Ts(e,s){if(!(s==null||s==="")){if(typeof s=="object")return s;if(e==="number"){const n=Number(s);return Number.isFinite(n)?n:void 0}if(e==="boolean")return s===!0||s==="true";if(e==="json")try{return JSON.parse(String(s))}catch{return}return String(s)}}function Et(e){return e.filter(s=>typeof s.key=="string"&&s.key.trim()!=="").map(s=>({key:s.key,label:s.key,type:Es(s.type),required:!!s.required}))}function Rs(e){const s={};for(const n of e){if(typeof n.key!="string"||n.key.trim()==="")continue;const r=Ts(n.type,n.default);r!==void 0&&(s[n.key]=r)}return s}function Is({app:e,action:s,fields:n,persist:r}){const a=te(),o=os(),l=d.useMemo(()=>At(n),[n]),i=d.useMemo(()=>Et(l),[l]),c=i.length>0,[u,m]=d.useState(()=>Rs(l)),[p,h]=d.useState(null),f=r==null?void 0:r.workflowId,w=r==null?void 0:r.stepId,[b,S]=d.useState(!f||!w);d.useEffect(()=>{if(!f||!w){S(!0);return}let k=!1;return a.listStepTests(f,w).then(P=>{if(k)return;const E=P.length?P[P.length-1]:null;E!=null&&E.with&&m(I=>({...I,...E.with})),S(!0)}).catch(()=>{k||S(!0)}),()=>{k=!0}},[a,f,w]);const[y,x]=d.useState(!0),N=y&&ye(i,u),j=async()=>{h({status:"running"});let k;try{const P=await a.invokeAction(e,s,{input:u},{project:o});k={status:"done",value:P.value,logs:P.logs}}catch(P){const E=P;k={status:"error",error:E.message??String(P),errorCode:E.code,logs:E.logs}}if(h(k),r)try{const P=await a.saveStepTest(r.workflowId,r.stepId,{input:r.input,with:u});await a.recordStepTestRun(r.workflowId,r.stepId,{stepTestId:P.id,status:k.status==="done"?"succeeded":"failed",input:r.input,output:k.status==="done"?k.value:void 0,error:k.status==="error"?k.error:void 0})}catch(P){console.error("step test persist failed",P)}},A=p&&p.status!=="running"?p.logs:void 0;return t.jsxs("div",{className:"w6w-stack",children:[b?t.jsxs(t.Fragment,{children:[t.jsx(Vs,{params:i,values:u,onChange:m,onValidityChange:x}),!c&&t.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 (",t.jsx("code",{children:"input"}),")."]})]}):t.jsx("p",{className:"w6w-muted w6w-small",children:"Loading saved values…"}),t.jsxs("div",{className:"w6w-steptest",children:[t.jsxs("div",{className:"w6w-steptest-bar",children:[t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",disabled:!b||!N||(p==null?void 0:p.status)==="running",onClick:j,children:(p==null?void 0:p.status)==="running"?"Running…":"▶ Test run"}),b&&!N&&t.jsx("span",{className:"w6w-muted w6w-small",children:y?"Fill the required fields to test.":"The payload must be a JSON object to test."})]}),(p==null?void 0:p.status)==="error"&&t.jsxs("div",{className:"w6w-result w6w-error",children:[p.errorCode&&t.jsx("div",{className:"w6w-small",style:{opacity:.75,marginBottom:4},children:t.jsx("code",{children:p.errorCode})}),p.error]}),(p==null?void 0:p.status)==="done"&&t.jsxs("div",{className:"w6w-testout",children:[t.jsx("div",{className:"w6w-testout-label",children:"Output state (filled values)"}),t.jsx("pre",{className:"w6w-result",style:{whiteSpace:"pre-wrap",maxHeight:220,overflow:"auto",margin:0},children:JSON.stringify(p.value,null,2)})]}),A&&A.length>0&&t.jsxs("div",{className:"w6w-testout",children:[t.jsx("div",{className:"w6w-testout-label",children:"Console output"}),t.jsx("pre",{className:"w6w-result w6w-testout-console",style:{whiteSpace:"pre-wrap",maxHeight:160,overflow:"auto",margin:0},children:A.join(`
9
- `)})]})]})]})}const pr=[["s","Seconds"],["m","Minutes"],["h","Hours"],["d","Days"],["w","Weeks"]],wr=/^(?=\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 Ps({values:e,onChange:s,readOnly:n}){const r=e.duration??"1s",a=typeof r=="string"?r.match(/^(\d+(?:\.\d+)?)([smhdw])$/i):null,[o,l]=d.useState("s"),[i,c]=d.useState("text"),[u,m]=d.useState(e.until?"until":"duration"),p=typeof r=="string"&&(!wr.test(r.trim())||/^P$/i.test(r.trim()));return t.jsxs("div",{className:"w6w-params-form",children:[t.jsxs("label",{children:["Wait for",t.jsxs("select",{"aria-label":"Wait for",disabled:n,value:u,onChange:h=>{const f=h.target.value;m(f),s({...e,duration:f==="duration"?"1s":"",until:""})},children:[t.jsx("option",{value:"duration",children:"A duration"}),t.jsx("option",{value:"until",children:"Until a timestamp"})]})]}),u==="until"?t.jsx(pe,{params:[{key:"until",label:"Until",type:"string",hint:"ISO-8601 timestamp, e.g. 2026-10-08T09:00:00Z."}],values:e,onChange:s,readOnly:n}):t.jsxs(t.Fragment,{children:[t.jsxs("label",{children:["Duration input",t.jsxs("select",{"aria-label":"Duration input",disabled:n,value:i,onChange:h=>{a&&l((a==null?void 0:a[2].toLowerCase())??o),c(h.target.value)},children:[t.jsx("option",{value:"text",children:"Shorthand"}),t.jsx("option",{value:"value",disabled:!a,children:"Value and unit"})]})]}),i==="value"?t.jsxs("div",{className:"w6w-field-row",children:[t.jsxs("label",{children:["Value",t.jsx("input",{"aria-label":"Duration value",type:"number",min:"0",step:((a==null?void 0:a[2].toLowerCase())??o)==="s"?"any":"1",disabled:n,value:(a==null?void 0:a[1])??"",onChange:h=>s({...e,duration:`${h.target.value}${(a==null?void 0:a[2].toLowerCase())??o}`})})]}),t.jsxs("label",{children:["Unit",t.jsx("select",{"aria-label":"Duration unit",disabled:n,value:(a==null?void 0:a[2].toLowerCase())??o,onChange:h=>{l(h.target.value),s({...e,duration:`${(a==null?void 0:a[1])??""}${h.target.value}`})},children:pr.map(([h,f])=>t.jsx("option",{value:h,children:f},h))})]})]}):t.jsx(pe,{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:s,readOnly:n}),p&&t.jsx("p",{role:"alert",children:"Enter a duration such as 30s or 1h30m30s, using units w, d, h, m, s in order."})]})]})}function Ms(e,s,n){return e*s>.6*n}function Os(e,s){const n=s.trim().toLowerCase();return n?e.filter(r=>r.label.toLowerCase().includes(n)||r.value.toLowerCase().includes(n)):e}const hr={position:"absolute",zIndex:50,left:0,right:0,top:"100%",maxHeight:240,overflowY:"auto",margin:0,padding:4,listStyle:"none",background:"var(--w6w-surface, #fff)",border:"1px solid var(--w6w-border, #ccc)",borderRadius:6,boxShadow:"0 4px 12px rgba(0,0,0,0.15)"};function Fs({options:e,value:s,onChange:n,placeholder:r,disabled:a,"aria-label":o,mode:l="auto",forceSelection:i=!0,optionHeight:c=32,className:u}){var v;const m=l==="combobox"||l==="auto"&&Ms(e.length,c,typeof window>"u"?0:window.innerHeight),p=d.useId(),h=((v=e.find(C=>C.value===s))==null?void 0:v.label)??(i?"":s),[f,w]=d.useState(h),[b,S]=d.useState(!1),[y,x]=d.useState(!1),[N,j]=d.useState(0),A=d.useRef(null);d.useEffect(()=>{w(h)},[h]);const k=d.useMemo(()=>y?Os(e,f):e,[e,f,y]);if(!m)return t.jsxs("select",{className:u,value:s,disabled:a,"aria-label":o,onChange:C=>n(C.target.value),children:[r!==void 0&&s===""&&t.jsx("option",{value:"",disabled:!0,children:r}),e.map(C=>t.jsx("option",{value:C.value,children:C.label},C.value))]});const P=C=>`${p}-opt-${C}`,E=()=>{S(!1),x(!1)},I=C=>{w(C.label),n(C.value),E()},L=C=>{C.key==="ArrowDown"?(C.preventDefault(),b?j(_=>Math.min(_+1,k.length-1)):S(!0)):C.key==="ArrowUp"?(C.preventDefault(),b?j(_=>Math.max(_-1,0)):S(!0)):C.key==="Enter"?b&&k[N]?(C.preventDefault(),I(k[N])):i||(n(f),E()):C.key==="Escape"&&(b&&C.stopPropagation(),w(h),E())},D=()=>{i?w(h):f!==s&&n(f),E()};return t.jsxs("div",{ref:A,style:{position:"relative"},children:[t.jsx("input",{type:"text",role:"combobox",className:u,value:f,disabled:a,placeholder:r,"aria-label":o,"aria-expanded":b,"aria-controls":`${p}-list`,"aria-autocomplete":"list","aria-activedescendant":b&&k[N]?P(N):void 0,autoComplete:"off",onFocus:()=>S(!0),onChange:C=>{w(C.target.value),x(!0),j(0),S(!0)},onKeyDown:L,onBlur:D}),b&&t.jsxs("div",{id:`${p}-list`,role:"listbox",tabIndex:-1,"aria-label":o,style:hr,children:[k.map((C,_)=>t.jsx("div",{id:P(_),role:"option",tabIndex:-1,"aria-selected":C.value===s,style:{padding:"6px 8px",cursor:"pointer",borderRadius:4,background:_===N?"var(--w6w-hover, rgba(127,127,127,0.18))":void 0},onMouseDown:B=>{B.preventDefault(),I(C)},onMouseEnter:()=>j(_),children:C.label},C.value)),k.length===0&&t.jsx("div",{role:"presentation",style:{padding:"6px 8px",opacity:.6},children:"No matches"})]})]})}function Xe({icon:e,size:s=28}){return t.jsx("span",{"aria-hidden":"true",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:s,height:s,borderRadius:6,flexShrink:0,background:"var(--w6w-icon-swatch, var(--w6w-panel-2))",color:"var(--w6w-accent)"},children:t.jsx("svg",{width:Math.round(s*.6),height:Math.round(s*.6),viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",dangerouslySetInnerHTML:{__html:e}})})}function Ve(e,s,n){return n==="error"?`${e}->${s}:error`:`${e}->${s}`}function fr(e){return e.includes(".")?"A step id can't contain a dot (.).":null}function mr(e,s,n){const r=(p,h)=>!p||!h?void 0:Ve(p,h)===s?"success":Ve(p,h,"error")===s?"error":void 0,a=r(n[0],n[1]),o=r(n[2],n[3]),l=a!==void 0&&a===o,i=a!==void 0&&o!==void 0&&a!==o,c=a==="success"?n[1]:n[3],u=l?n.find(p=>!!p&&p.includes("->")):i&&(c!=null&&c.endsWith(":error"))?c:void 0,m=u===void 0?"Rename one of the steps it connects, then try again.":l?`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 “${s}” is already taken by another edge. ${m}`}const br=240,xr=100,gr=40,yr=40;function $s(e,s){return{x:gr+e*br,y:yr+s*xr}}function Ls(e,s){var i;const n=new Map,r=new Map;for(const c of e)n.set(c.id,0),r.set(c.id,[]);for(const c of s)(i=r.get(c.to))==null||i.push(c.from);const a=e.length+1;let o=0,l=!0;for(;l&&o<a;){o++,l=!1;for(const c of e){const u=r.get(c.id)??[];if(u.length===0)continue;const m=u.reduce((p,h)=>Math.max(p,(n.get(h)??0)+1),0);(n.get(c.id)??0)<m&&(n.set(c.id,m),l=!0)}}if(l){const c=Math.max(0,e.length-1);for(const[u,m]of n)m>c&&n.set(u,c)}return n}function jr(e){const s=e.position;if(!(!s||!Number.isFinite(s.x)||!Number.isFinite(s.y)))return{x:s.x,y:s.y}}function vr(e){const s=e.edges??Sr(e.steps),n=Ls(e.steps,s),r=new Map,a=e.steps.map(l=>{const i=fe(l.uses.app),c=n.get(l.id)??0,u=r.get(c)??0;return r.set(c,u+1),{id:l.id,type:i?"control":"step",position:jr(l)??$s(c,u),data:{step:l,isInternal:i}}}),o=s.map(l=>{const i=l.when??"success";return{id:Ve(l.from,l.to,i),source:l.from,target:l.to,sourceHandle:Qt(i),animated:!1,data:{when:i},...Xt(i,void 0)}});return{nodes:a,edges:o}}function Nr(e,s){const n=e.map(o=>({...o.data.step,id:o.id})),r=Ls(n,s.map(o=>({from:o.source,to:o.target}))),a=new Map;return e.map(o=>{const l=r.get(o.id)??0,i=a.get(l)??0;return a.set(l,i+1),{...o,position:$s(l,i)}})}function kr(e,s,n){var m,p;const r=((m=e.settings)==null?void 0:m.savePosition)!==!1,a=new Map(s.map(h=>[h.id,h])),o=h=>{var w;if(!r)return h;const f=(w=a.get(h.id))==null?void 0:w.position;return!f||!Number.isFinite(f.x)||!Number.isFinite(f.y)?h:{...h,position:{x:Math.round(f.x),y:Math.round(f.y)}}},l=new Map;for(const h of e.steps)l.set(h.id,h);for(const h of s)(p=h.data)!=null&&p.step&&l.set(h.id,h.data.step);const i=[],c=new Set;for(const h of e.steps){const f=l.get(h.id);f&&s.some(w=>w.id===h.id)&&(i.push(o(f)),c.add(h.id))}for(const h of s){if(c.has(h.id))continue;const f=l.get(h.id);f&&i.push(o(f))}const u=n.map(h=>{var w;const f=(w=h.data)==null?void 0:w.when;return f==="error"?{from:h.source,to:h.target,when:f}:{from:h.source,to:h.target}});return{...e,steps:i,edges:u}}function Ds(e){var n;const s=(n=e.settings)==null?void 0:n.viewport;if(!(!s||!Number.isFinite(s.x)||!Number.isFinite(s.y)||!Number.isFinite(s.zoom)))return{x:s.x,y:s.y,zoom:s.zoom}}function Cr(e,s){var l;if(!(((l=e.settings)==null?void 0:l.savePosition)!==!1)||!Number.isFinite(s.x)||!Number.isFinite(s.y)||!Number.isFinite(s.zoom))return e;const r={x:Math.round(s.x),y:Math.round(s.y),zoom:Math.round(s.zoom*1e3)/1e3},a=Ds(e);if(a&&a.x===r.x&&a.y===r.y&&a.zoom===r.zoom)return e;const o=typeof e.settings=="object"&&e.settings!==null&&!Array.isArray(e.settings)?e.settings:void 0;return{...e,settings:{...o,viewport:r}}}function Sr(e){const s=[];for(let n=0;n<e.length-1;n++)s.push({from:e[n].id,to:e[n+1].id});return s}function Ar(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"")||"step"}function Er(e,s){const n=new Set(s.map(r=>r.target));return e.find(r=>!n.has(r.id))}function Tr(e,s){const n=new Set(s.map(r=>r.source));for(let r=e.length-1;r>=0;r--)if(!n.has(e[r].id))return e[r]}function Rr(e,s="step"){const n=new Set(e);for(let r=1;r<1e3;r++){const a=`${s}_${r}`;if(!n.has(a))return a}return`${s}_${crypto.randomUUID().slice(0,8)}`}function Tt(e){return JSON.stringify(e,null,2)}function Rt(e){return JSON.stringify(e.with??{},null,2)}const Ir=3,Pr=100;function We(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Mr(e){if(!Array.isArray(e))return;const s=[];for(const n of e){if(!We(n)||typeof n.key!="string"||n.key==="")continue;const r=typeof n.label=="string"&&n.label!==""?n.label:void 0;s.push(r?{key:n.key,label:r,path:!0}:{key:n.key,path:!0})}return s.length>0?s:void 0}function ht(e){if(!We(e))return;const s=[],n=(r,a,o)=>{for(const[l,i]of Object.entries(r)){if(s.length>=Pr)return;const c=a?`${a}.${l}`:l;s.push({key:c,path:!0}),We(i)&&o<Ir&&n(i,c,o+1)}};return n(e,"",1),s.length>0?s:void 0}function Or(e,s){let n=e;for(const r of s.split(".")){if(!We(n)||!(r in n))return;n=n[r]}return n}function Fr(e,s){const n=Mr(e==null?void 0:e.output);if(n)return{fields:n,from:"declared"};const r=ht(e==null?void 0:e.sample);if(r)return{fields:r,from:"sample"};const a=ht(s);if(a)return{fields:a,from:"test"}}function _s(e,s){const n=new Map;for(const o of s){const l=n.get(o.target)??[];l.push(o.source),n.set(o.target,l)}const r=new Set,a=[e];for(;a.length;){const o=a.pop();for(const l of n.get(o)??[])r.has(l)||(r.add(l),a.push(l))}return r}function qs(e,s,n={}){var o,l,i,c,u;const r=[];let a=!1;for(const m of s){if(!e.has(m.id))continue;const p=m.data.step,h=((o=me(p.uses.app,p.uses.action))==null?void 0:o.group)==="trigger";h&&(a=!0);const w=h&&p.uses.app===Je?Et(At((l=p.with)==null?void 0:l.fields)).map(j=>({key:j.key,label:j.label})):((i=me(p.uses.app,p.uses.action))==null?void 0:i.output)??[],b={id:p.id,label:p.id};if(w.length>0){r.push({...b,outputs:w});continue}if(h){r.push(b);continue}const S=(c=n.testOutputs)==null?void 0:c[p.id];if(fe(p.uses.app)){const j=ht(S);r.push(j?{...b,outputs:j,outputsFrom:"test"}:b);continue}const y=(u=n.actionDef)==null?void 0:u.call(n,p.uses.app,p.uses.action),x=Fr(y,S),N=p.uses.app.trim()!==""?{hasMeta:!0}:{};x?r.push({...b,outputs:x.fields,outputsFrom:x.from,...N}):r.push(y?{...b,needsTest:!0,...N}:{...b,...N})}return{steps:r,hasTrigger:a}}function $r(e,s,n,r){const a=e?_s(e,n):new Set(s.map(o=>o.id));return qs(a,s,r)}function Lr(e,s,n,r){if(!e||e.handleType==="target")return[];const a=_s(e.nodeId,n);return a.add(e.nodeId),qs(a,s,r).steps}async function Dr(e,s){return(await Promise.all(s.map(async r=>{try{const a=await e(r.id),o=a.length?a[a.length-1]:null;return o?{stepId:r.id,label:r.label??r.id,test:o}:null}catch{return null}}))).filter(r=>r!==null)}function It(e){const s={};for(const n of e){const r=n.test.lastRunOutput,a=r!=null;if(!a&&n.test.lastRunStatus!=="succeeded")continue;const o=n.test.lastRunMeta;s[n.stepId]={output:a?r:null,...o?{meta:o}:{}}}return Object.keys(s).length>0?{steps:s}:void 0}function _r(e,s){if(!s)return{};const n=`steps.${e}.meta`;return{[`${n}.app`]:s.app,[`${n}.version`]:s.version,[`${n}.action`]:s.action,[`${n}.connectionId`]:s.connectionId}}function Pt(e,s,n){const r=te(),[a,o]=d.useState([]),l=JSON.stringify(s.map(i=>[i.id,i.label]));return d.useEffect(()=>{const i=JSON.parse(l);if(!n||i.length===0){o([]);return}let c=!1;return Dr(u=>r.listStepTests(e,u),i.map(([u,m])=>({id:u,label:m}))).then(u=>{c||o(u)}),()=>{c=!0}},[r,e,l,n]),a}const qr=["function","workflow"],Hr={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"/>'},at={props:{label:"Form",icon:"form"},code:{label:"JSON",icon:"code"},"params-code":{label:"Params JSON",icon:"braces"},config:{label:"Node settings",icon:"settings-2"}},Vr=["props","code","params-code","config"];function Qe({view:e,onChange:s,disabled:n,views:r=Vr}){const a=o=>t.jsx("button",{type:"button",title:at[o].label,"aria-label":at[o].label,"aria-pressed":e===o,disabled:n,className:`w6w-icon-btn${e===o&&!n?" active":""}`,onClick:()=>s(o),children:t.jsx(de.Icon,{name:at[o].icon,size:15})},o);return t.jsx("div",{className:"w6w-view-toggle",children:r.map(a)})}function Wr({onClose:e,onAdd:s,onDraftChange:n,theme:r,appsOnly:a,callables:o=qr,initialTab:l,title:i,workflowId:c,stepId:u,upstreamSteps:m=[],initialApp:p,initialAction:h,initialConnection:f,initialWith:w,appsFilter:b,connectionOnly:S,onConnected:y}){const[x,N]=d.useState(l??"connected"),[j,A]=d.useState(p??null),[k,P]=d.useState(null),[E,I]=d.useState(null),L=sa(o,b),D=L.state!=="empty";return d.useEffect(()=>{!D&&x==="connected"&&N("apps")},[D,x]),E?t.jsx(ne,{title:E.label,subtitle:t.jsx("code",{children:E.id}),onClose:e,size:"xl",headerRight:t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>I(null),children:"← Back"}),children:t.jsx("div",{className:"w6w-stepbuilder-config",children:t.jsx(ea,{family:E.family,targetId:E.id,targetLabel:E.label,onAdd:s,onClose:e,onDraftChange:n})})}):k?t.jsx(ne,{title:k.label,titleIcon:t.jsx(Xe,{icon:k.icon,size:22}),subtitle:t.jsxs("code",{children:[k.app," · ",k.action]}),onClose:e,size:"xl",headerRight:t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>P(null),children:"← Back"}),children:t.jsx("div",{className:"w6w-stepbuilder-config",children:t.jsx(Xr,{node:k,onAdd:s,onClose:e,onDraftChange:n,workflowId:c,upstreamSteps:m})})}):j?t.jsx(ne,{title:j.displayName,subtitle:t.jsxs(t.Fragment,{children:[t.jsx("code",{children:j.id}),j.version&&` · v${j.version}`]}),onClose:e,size:"xl",titleIcon:t.jsx(we,{src:j.iconSvg,srcDark:j.iconSvgDark,brandColor:j.brandColor,name:j.displayName,theme:r,size:22}),children:t.jsx("div",{className:"w6w-stepbuilder-config",children:S?t.jsx(aa,{appId:j.id,app:j,onClose:e,onChangeApp:()=>A(null),theme:r,initialConnection:f,onConnected:(v,C)=>y==null?void 0:y(v,C)}):t.jsx(ra,{appId:j.id,app:j,onAdd:s,onClose:e,onDraftChange:n,onChangeApp:()=>A(null),theme:r,workflowId:c,stepId:u,upstreamSteps:m,initialAction:h,initialConnection:f,initialWith:w})})}):t.jsx(ne,{title:i??"Add a step",onClose:e,size:"xl",children:t.jsxs("div",{className:"w6w-stepbuilder",children:[t.jsxs("nav",{className:"w6w-stepbuilder-sidebar",children:[D&&t.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${x==="connected"?" active":""}`,onClick:()=>N("connected"),children:"Ready to use"}),t.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${x==="apps"?" active":""}`,onClick:()=>N("apps"),children:"Apps"}),t.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${x==="ai"?" active":""}`,onClick:()=>N("ai"),children:"AI"}),o.includes("workflow")&&t.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${x==="workflows"?" active":""}`,onClick:()=>N("workflows"),children:"Workflows"}),o.includes("function")&&t.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${x==="functions"?" active":""}`,onClick:()=>N("functions"),children:"Functions"}),!a&&t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${x==="triggers"?" active":""}`,onClick:()=>N("triggers"),children:"Triggers"}),t.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${x==="controls"?" active":""}`,onClick:()=>N("controls"),children:"Controls"}),t.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${x==="utilities"?" active":""}`,onClick:()=>N("utilities"),children:"Utilities"}),t.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${x==="data"?" active":""}`,onClick:()=>N("data"),children:"Data"})]})]}),t.jsx("div",{className:"w6w-stepbuilder-content",children:x==="connected"?t.jsx(na,{data:L,onSelectApp:A,onSelectCallable:I,theme:r}):x==="functions"?t.jsx(Bt,{family:"function",onSelect:v=>I({family:"function",...v})}):x==="workflows"?t.jsx(Bt,{family:"workflow",onSelect:v=>I({family:"workflow",...v})}):x==="apps"?t.jsx(be,{onSelectApp:A,theme:r,filter:b}):x==="ai"?t.jsx(be,{onSelectApp:A,theme:r,category:"ai",filter:v=>{var C;return((b==null?void 0:b(v))??!0)&&(((C=v.categories)==null?void 0:C.includes("ai"))??!1)},searchPlaceholder:"Search AI apps…",emptyMessage:"No AI apps registered yet."}):x==="triggers"?t.jsx(Ur,{onSelect:P,workflowId:c,onClose:e}):x==="controls"?t.jsx(Gr,{onSelect:P}):x==="data"?t.jsx(Yr,{onSelect:P}):t.jsx(Kr,{onSelect:P})})]})})}function Ze({nodes:e,onSelect:s}){return t.jsx("div",{className:"w6w-stepbuilder-list",children:e.map(n=>t.jsxs("button",{type:"button",className:"w6w-stepbuilder-item",onClick:()=>s(n),children:[t.jsx(Xe,{icon:n.icon,size:24}),t.jsxs("span",{className:"w6w-stepbuilder-item-main",children:[t.jsx("strong",{children:n.label}),t.jsxs("code",{className:"w6w-muted w6w-small",children:[n.app," · ",n.action]})]})]},`${n.app}:${n.action}`))})}function Ur({onSelect:e,workflowId:s,onClose:n}){const r=je.filter(o=>o.group==="trigger"),a=te();return t.jsxs("div",{className:"w6w-stack",children:[t.jsx("p",{className:"w6w-muted w6w-small",children:"Triggers start a workflow — run it manually or on an inbound webhook."}),t.jsx(Ze,{nodes:r,onSelect:e}),s&&a.listTriggerApps&&t.jsx(Jr,{workflowId:s,onClose:n})]})}function Br(e){return(e.triggerCount??0)>0}function Jr({workflowId:e,onClose:s}){const n=te(),r=typeof n.listAppsPage=="function",[a,o]=d.useState(null),[l,i]=d.useState(null),[c,u]=d.useState(null);return d.useEffect(()=>{if(r)return;const m=n.listTriggerApps;if(!m)return;let p=!1;return m().then(h=>!p&&o(h)).catch(h=>!p&&i(h.message)),()=>{p=!0}},[n,r]),!r&&!n.listTriggerApps?null:t.jsxs("div",{className:"w6w-stack",children:[t.jsxs("p",{className:"w6w-muted w6w-small",children:[t.jsx("strong",{children:"App triggers"})," — bind one of these apps' declared triggers to this workflow."]}),c?t.jsx(zr,{app:c,workflowId:e,onBack:()=>u(null),onClose:s}):r?t.jsx(be,{onSelectApp:u,filter:Br,search:!0,searchPlaceholder:"Search apps with triggers…",emptyMessage:"No apps declare triggers yet."}):l?t.jsx("div",{className:"w6w-result w6w-error",children:l}):t.jsx(be,{apps:a,onSelectApp:u,search:!1,emptyMessage:"No apps declare triggers yet."})]})}function zr({app:e,workflowId:s,onBack:n,onClose:r}){const a=te(),[o,l]=d.useState(null),[i,c]=d.useState(null),[u,m]=d.useState(!1),[p,h]=d.useState(null),[f,w]=d.useState("5");d.useEffect(()=>{const x=a.getAppTriggers;if(!x)return;let N=!1;return x(e.id).then(j=>!N&&l(j)).catch(j=>!N&&c(j.message)),()=>{N=!0}},[a,e.id]);const b=x=>Math.max(1,Math.ceil((x.minIntervalMs??0)/6e4)),S=x=>{if(x.type!=="poll")return y(x.key);c(null),h(x),w(String(Math.max(5,Math.ceil((x.minIntervalMs??0)/6e4))))},y=(x,N)=>{const j=a.createSubscription;j&&(c(null),m(!0),j(e.id,x,{workflowId:s,connectionId:null,params:{},...N===void 0?{}:{intervalMs:N}}).then(()=>r()).catch(A=>{m(!1),c(A instanceof Error?A.message:String(A))}))};return t.jsxs("div",{className:"w6w-stack",children:[t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:n,children:"← Back"}),t.jsx("strong",{children:e.displayName}),i&&t.jsx("div",{className:"w6w-result w6w-error",children:i}),o===null?t.jsx("p",{className:"w6w-muted w6w-small",children:"Loading triggers…"}):o.length===0?t.jsx("p",{className:"w6w-muted w6w-small",children:"This app declares no triggers."}):t.jsx("div",{className:"w6w-stepbuilder-list",children:o.map(x=>t.jsx("button",{type:"button",className:"w6w-stepbuilder-item",disabled:u,onClick:()=>S(x),children:t.jsxs("span",{className:"w6w-stepbuilder-item-main",children:[t.jsx("strong",{children:x.title}),t.jsx("code",{className:"w6w-muted w6w-small",children:x.key}),x.description&&t.jsx("span",{className:"w6w-muted w6w-small",children:x.description})]})},x.key))}),p&&t.jsxs("div",{className:"w6w-stack",children:[t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:"Check every … minutes"}),t.jsx("input",{type:"number",min:b(p),step:1,value:f,disabled:u,onChange:x=>w(x.target.value),onBlur:()=>w(String(zt(f,b(p))))})]}),t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-primary w6w-btn-sm",disabled:u,onClick:()=>y(p.key,zt(f,b(p))*6e4),children:"Add trigger"})]})]})}function Gr({onSelect:e}){const s=je.filter(n=>n.group==="control"&&!n.hidden);return t.jsxs("div",{className:"w6w-stack",children:[t.jsx("p",{className:"w6w-muted w6w-small",children:"Flow-control nodes branch, loop, parallelize, or pause the run."}),t.jsx(Ze,{nodes:s,onSelect:e})]})}function Kr({onSelect:e}){const s=je.filter(n=>n.group!=="control"&&n.group!=="trigger"&&n.app!==Be&&!n.hidden);return t.jsxs("div",{className:"w6w-stack",children:[t.jsx("p",{className:"w6w-muted w6w-small",children:"Utilities run a script, call an HTTP(S) endpoint, or respond to a webhook."}),t.jsx(Ze,{nodes:s,onSelect:e})]})}function Yr({onSelect:e}){const s=je.filter(n=>n.app===Be);return t.jsxs("div",{className:"w6w-stack",children:[t.jsx("p",{className:"w6w-muted w6w-small",children:"Declare typed key/value variables for downstream steps to reference."}),t.jsx(Ze,{nodes:s,onSelect:e})]})}function Xr({node:e,onAdd:s,onClose:n,onDraftChange:r,workflowId:a,upstreamSteps:o=[]}){const[l,i]=d.useState(()=>ts(e.app,e.action)),c=!De(e.app),u=Pt(a??"",o,c&&!!a),m=It(u),[p,h]=d.useState("configure"),[f,w]=d.useState("props"),[b,S]=d.useState("{}"),[y,x]=d.useState("{}"),[N,j]=d.useState({}),A=ye(e.params,l),[k,P]=d.useState(null),E=()=>({uses:{app:e.app,action:e.action},with:l,...N});d.useEffect(()=>{if(!r)return;const D=s(E());D&&P(D)},[]),d.useEffect(()=>{!r||k===null||r(k,E())},[k,l,N]);const I=D=>{D==="code"?S(Tt(E())):D==="params-code"&&x(Rt(E())),w(D)},L=()=>s(E());return t.jsxs("div",{className:"w6w-stepconfig",children:[t.jsxs("div",{className:"w6w-tabsbar",children:[t.jsxs("div",{className:"w6w-subtabs",children:[t.jsx("button",{type:"button",className:`w6w-subtab${p==="configure"?" active":""}`,onClick:()=>h("configure"),children:"Configure"}),c&&t.jsx("button",{type:"button",disabled:!A,title:A?void 0:"Fill the required fields first",className:`w6w-subtab${p==="test"?" active":""}`,onClick:()=>A&&h("test"),children:"Test"})]}),t.jsx(Qe,{view:f,onChange:I,disabled:p!=="configure"})]}),t.jsxs("div",{className:"w6w-stepconfig-body",children:[p==="configure"&&(f==="props"?e.action==="wait"&&De(e.app)?t.jsx(Ps,{values:l,onChange:i}):t.jsx(pe,{params:e.params,values:l,onChange:i}):f==="code"?t.jsx(ue,{value:b,onChange:()=>{},readOnly:!0,minHeight:"240px",height:"100%","aria-label":"Step JSON",copyable:!0}):f==="params-code"?t.jsx(ue,{value:y,onChange:x,minHeight:"240px",height:"100%","aria-label":"Parameters JSON",copyable:!0,onValidChange:D=>D&&typeof D=="object"&&!Array.isArray(D)&&i(D)}):t.jsx(yt,{config:N,onChange:j,failureHandling:!qe(e.app),retryControls:!De(e.app)&&e.app!==ze})),p==="test"&&c&&(qe(e.app)?t.jsx(Is,{app:e.app,action:e.action,fields:l.fields}):t.jsx(Mt,{app:e.app,action:e.action,values:l,canRun:A,state:m}))]}),t.jsxs("div",{className:"w6w-modal-actions w6w-stepconfig-footer",children:[t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:n,children:"Cancel"}),p==="configure"&&c?t.jsx("button",{type:"button",className:"w6w-btn",disabled:!A,onClick:()=>h("test"),children:"Next →"}):t.jsx("button",{type:"button",className:"w6w-btn",onClick:k!==null?n:L,children:k!==null?"Done":"Add step"})]})]})}function Bt({family:e,onSelect:s}){const n=te(),[r,a]=d.useState(null),[o,l]=d.useState(null),[i,c]=d.useState(""),u=e==="function"?"Functions":"Workflows";d.useEffect(()=>{let b=!1;return(e==="function"?n.listFunctions():n.listWorkflows()).then(y=>!b&&a(y)).catch(y=>!b&&l(y.message)),()=>{b=!0}},[n,e]);const m=b=>t.jsx("div",{className:"w6w-apppicker-host",children:b});if(o)return m(t.jsx("div",{className:"w6w-result w6w-error",children:o}));if(r===null)return m(t.jsxs("p",{className:"w6w-muted w6w-small",children:["Loading ",u.toLowerCase(),"…"]}));if(r.length===0)return m(t.jsxs("p",{className:"w6w-muted w6w-small",children:["No ",u.toLowerCase()," registered yet."]}));const p=Ue,h=i.trim().toLowerCase(),f=[...r].sort(_e(p)),w=h?f.filter(b=>p(b).toLowerCase().includes(h)||b.id.toLowerCase().includes(h)):f;return m(t.jsxs("div",{className:"w6w-stepbuilder-apps",children:[t.jsx("input",{type:"text",className:"w6w-stepbuilder-search",placeholder:`Search ${u.toLowerCase()}…`,value:i,onChange:b=>c(b.target.value),"aria-label":`Search ${u.toLowerCase()}`}),w.length===0?t.jsxs("p",{className:"w6w-muted w6w-small",children:["No ",u.toLowerCase()," match “",i,"”."]}):t.jsx("div",{className:"w6w-stepbuilder-list w6w-stepbuilder-scroll",children:w.map(b=>t.jsx(ft,{family:e,item:b,onSelect:s},b.id))})]}))}const Qr=["string","number","boolean","json"];function Zr(e){var a;const s=e.steps.find(o=>qe(o.uses.app)),n=(a=s==null?void 0:s.with)==null?void 0:a.fields;if(!Array.isArray(n))return[];const r=[];for(const o of n){if(typeof o!="object"||o===null)continue;const l=o,i=typeof l.key=="string"?l.key:"";if(!i)continue;const c=typeof l.type=="string"?l.type:"string";r.push({key:i,label:i,type:Qr.includes(c)?c:"string",default:l.default,required:!!l.required})}return r}function ea({family:e,targetId:s,targetLabel:n,onAdd:r,onClose:a,onDraftChange:o}){const l=te(),[i,c]=d.useState(null),[u,m]=d.useState(null),[p,h]=d.useState({}),[f,w]=d.useState(!0),[b,S]=d.useState("configure"),[y,x]=d.useState(null);d.useEffect(()=>{let k=!1;return c(null),m(null),(e==="function"?l.getFunction(s).then(E=>E.inputs):l.getWorkflow(s).then(Zr)).then(E=>!k&&c(E)).catch(E=>!k&&m(E.message)),()=>{k=!0}},[l,e,s]);const N=i!==null&&ye(i,p),j=()=>({uses:{app:ze,action:"call"},with:{targetKind:e,targetId:s,inputs:p,wait:f}});d.useEffect(()=>{if(!o)return;const k=r(j());k&&x(k)},[]),d.useEffect(()=>{!o||y===null||o(y,j())},[y,p,f]);const A=()=>r(j());return t.jsxs("div",{className:"w6w-stepconfig",children:[t.jsx("div",{className:"w6w-tabsbar",children:t.jsxs("div",{className:"w6w-subtabs",children:[t.jsx("button",{type:"button",className:`w6w-subtab${b==="configure"?" active":""}`,onClick:()=>S("configure"),children:"Configure"}),t.jsx("button",{type:"button",disabled:!N,title:N?void 0:"Fill the required fields first",className:`w6w-subtab${b==="test"?" active":""}`,onClick:()=>N&&S("test"),children:"Test"})]})}),t.jsx("div",{className:"w6w-stepconfig-body",children:b==="configure"?t.jsxs("div",{className:"w6w-stack",children:[u?t.jsx("div",{className:"w6w-result w6w-error",children:u}):i===null?t.jsxs("p",{className:"w6w-muted w6w-small",children:["Loading ",n,"’s inputs…"]}):i.length===0?t.jsxs("p",{className:"w6w-muted w6w-small",children:[n," declares no inputs — it can be called as-is."]}):t.jsx(pe,{params:i,values:p,onChange:h}),t.jsxs("label",{className:"w6w-field",children:[t.jsxs("span",{children:[t.jsx("input",{type:"checkbox",checked:f,onChange:k=>w(k.target.checked)})," ","Wait for completion"]}),t.jsx("span",{className:"w6w-hint",children:"On: block until the sub-run finishes and expose its output. Off: return a run handle and continue."})]})]}):t.jsx(ta,{family:e,targetId:s,inputs:p,canRun:N})}),t.jsxs("div",{className:"w6w-modal-actions w6w-stepconfig-footer",children:[t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:a,children:"Cancel"}),b==="configure"?t.jsx("button",{type:"button",className:"w6w-btn",disabled:!N,onClick:()=>S("test"),children:"Next →"}):t.jsx("button",{type:"button",className:"w6w-btn",onClick:y!==null?a:A,children:y!==null?"Done":"Add step"})]})]})}function ta({family:e,targetId:s,inputs:n,canRun:r}){const a=te(),[o,l]=d.useState(null),i=async()=>{if(!(!r||(o==null?void 0:o.status)==="running")){l({status:"running"});try{if(e==="function"){const c=await a.invokeFunction(s,n);l({status:"done",output:c,terminal:!0})}else{const c=await a.runWorkflow(s,{input:n});l({status:"done",output:c.output,runId:c.runId,terminal:c.terminal,error:c.error})}}catch(c){l({status:"error",error:c.message??String(c)})}}};return t.jsxs("div",{className:"w6w-steptest",children:[t.jsxs("div",{className:"w6w-steptest-bar",children:[t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",disabled:!r||(o==null?void 0:o.status)==="running",onClick:i,children:(o==null?void 0:o.status)==="running"?"Running…":"▶ Test run"}),!r&&t.jsx("span",{className:"w6w-muted w6w-small",children:"Fill the required fields to test."})]}),(o==null?void 0:o.status)==="error"&&t.jsx("div",{className:"w6w-result w6w-error",children:o.error}),(o==null?void 0:o.status)==="done"&&!o.terminal&&t.jsxs("div",{className:"w6w-testout",children:[t.jsx("div",{className:"w6w-testout-label",children:"Still running"}),t.jsxs("div",{className:"w6w-result",children:["Run ",t.jsx("code",{children:o.runId})," has not finished yet — check its status from the workflow's run history."]})]}),(o==null?void 0:o.status)==="done"&&o.terminal&&o.error!==void 0&&t.jsxs("div",{className:"w6w-testout",children:[t.jsx("div",{className:"w6w-testout-label",children:"Run failed"}),t.jsx("pre",{className:"w6w-result w6w-error",style:{whiteSpace:"pre-wrap",maxHeight:220,overflow:"auto",margin:0},children:JSON.stringify(o.error,null,2)})]}),(o==null?void 0:o.status)==="done"&&o.terminal&&o.error===void 0&&t.jsxs("div",{className:"w6w-testout",children:[t.jsx("div",{className:"w6w-testout-label",children:"Result"}),t.jsx("pre",{className:"w6w-result",style:{whiteSpace:"pre-wrap",maxHeight:220,overflow:"auto",margin:0},children:JSON.stringify(o.output,null,2)})]})]})}function ye(e,s){const n=ge(e),r=o=>{var l;return s[o]!==void 0?s[o]:(l=n.find(i=>i.key===o))==null?void 0:l.default},a=(o,l,i)=>o.every(c=>{if(c.type==="section")return a(c.children??[],l,i);if(c.type==="group"){const m=c.children??[],p=ge(m),h=w=>b=>{const S=p.find(y=>y.key===b);return S?w[b]!==void 0?w[b]:S.default:i(b)};if(c.repeat){const w=Array.isArray(l[c.key])?l[c.key]:[];return w.length===0?!c.required:w.every(b=>{const S=b??{};return a(m,S,h(S))})}const f=l[c.key]??{};return a(m,f,h(f))}if(!c.required||!Pe(c,i))return!0;const u=l[c.key]??c.default;return u==null?!1:typeof u=="string"?u.trim()!=="":!0});return a(e,s,r)}function Hs(e){const s=e==null?void 0:e.testRequired;return typeof s=="boolean"?s:!0}const Mt=d.forwardRef(function({app:s,action:n,connectionId:r,values:a,canRun:o,hideRunButton:l,persist:i,state:c,onBusyChange:u,onResult:m},p){const h=te(),f=os(),[w,b]=d.useState(null),S=async()=>{if(!o||(w==null?void 0:w.status)==="running")return;b({status:"running"}),u==null||u(!0);let x;try{const N=await h.invokeAction(s,n,a,{...r?{connectionId:r}:{},project:f,...c?{state:c}:{}});x={status:"done",value:N.value,logs:N.logs,...N.meta?{meta:N.meta}:{}}}catch(N){const j=N;x={status:"error",error:j.message??String(N),errorCode:j.code,logs:j.logs}}if(b(x),m==null||m(x.status==="done"),i)try{const N=await h.saveStepTest(i.workflowId,i.stepId,{input:i.input,with:a});await h.recordStepTestRun(i.workflowId,i.stepId,{stepTestId:N.id,status:x.status==="done"?"succeeded":"failed",input:i.input,output:x.status==="done"?x.value:void 0,error:x.status==="error"?x.error:void 0,...x.status==="done"&&x.meta?{meta:x.meta}:{}})}catch(N){console.error("step test persist failed",N)}u==null||u(!1)};d.useImperativeHandle(p,()=>({run:S}));const y=w&&w.status!=="running"?w.logs:void 0;return t.jsxs("div",{className:"w6w-steptest",children:[!l&&t.jsxs("div",{className:"w6w-steptest-bar",children:[t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",disabled:!o||(w==null?void 0:w.status)==="running",onClick:S,children:(w==null?void 0:w.status)==="running"?"Running…":"▶ Test run"}),!o&&t.jsx("span",{className:"w6w-muted w6w-small",children:"Fill the required fields to test."})]}),(w==null?void 0:w.status)==="error"&&t.jsxs("div",{className:"w6w-result w6w-error",children:[w.errorCode&&t.jsx("div",{className:"w6w-small",style:{opacity:.75,marginBottom:4},children:t.jsx("code",{children:w.errorCode})}),w.error]}),(w==null?void 0:w.status)==="done"&&t.jsxs("div",{className:"w6w-testout",children:[t.jsx("div",{className:"w6w-testout-label",children:"Result (return value)"}),t.jsx("pre",{className:"w6w-result",style:{whiteSpace:"pre-wrap",maxHeight:220,overflow:"auto",margin:0},children:JSON.stringify(w.value,null,2)}),w.meta&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"w6w-testout-label",children:"Metadata"}),t.jsx("pre",{className:"w6w-result",style:{whiteSpace:"pre-wrap",maxHeight:220,overflow:"auto",margin:0},children:JSON.stringify(w.meta,null,2)})]})]}),y&&y.length>0&&t.jsxs("div",{className:"w6w-testout",children:[t.jsx("div",{className:"w6w-testout-label",children:"Console output"}),t.jsx("pre",{className:"w6w-result w6w-testout-console",style:{whiteSpace:"pre-wrap",maxHeight:160,overflow:"auto",margin:0},children:y.join(`
10
- `)})]})]})}),Jt=12,Le=new Set;function zt(e,s){const n=Number(e.trim());return e.trim()===""||!Number.isFinite(n)||n<s?s:Math.max(s,Math.round(n))}function sa(e,s){const n=te(),[r,a]=d.useState(null),[o,l]=d.useState(null),[i,c]=d.useState(null),[u,m]=d.useState(null),[p,h]=d.useState(null),[f,w]=d.useState(()=>new Map),[b,S]=d.useState(()=>new Set),[y,x]=d.useState(Le),N=d.useRef(Le),j=d.useCallback(M=>{N.current=M,x(M)},[]),A=d.useRef(Le),k=e.includes("function"),P=e.includes("workflow"),E=typeof n.listAppsByIds=="function";d.useEffect(()=>{let M=!1;const W=H=>!M&&h(H.message);return n.listConnections().then(H=>{if(M)return;const Q=[],ee=new Set,G=new Map;for(const z of H)fe(z.appId)||(E&&z.app&&!G.has(z.appId)&&G.set(z.appId,{...z.app,id:z.appId}),!ee.has(z.appId)&&(ee.add(z.appId),Q.push(z.appId)));G.size>0&&(A.current=new Set(G.keys()),w(z=>new Map([...z,...G])),S(z=>new Set([...z,...G.keys()]))),a(Q)}).catch(W),k?n.listFunctions().then(H=>!M&&c(H)).catch(W):c([]),P?n.listWorkflows().then(H=>!M&&m(H)).catch(W):m([]),()=>{M=!0}},[n,E,k,P]),d.useEffect(()=>{if(E)return;const M=n.listApps;if(typeof M!="function"){l([]);return}let W=!1;return M().then(H=>!W&&l(H)).catch(H=>!W&&h(H.message)),()=>{W=!0}},[n,E]);const I=d.useRef(!0);d.useEffect(()=>()=>{I.current=!1},[]);const L=d.useCallback(M=>{const W=n.listAppsByIds;!W||M.length===0||N.current.size>0||(j(new Set(M)),W(M).then(H=>{I.current&&(j(Le),w(Q=>{const ee=new Map(Q);for(const G of H)ee.set(G.id,G);return ee}),S(Q=>new Set([...Q,...M])))}).catch(H=>I.current&&h(H.message)))},[n,j]),D=d.useRef(!1);d.useEffect(()=>{if(!E||r===null||D.current)return;const M=st(r,A.current,Jt);M.length!==0&&(D.current=!0,L(M))},[E,r,L]);const v=()=>{if(!E||r===null||N.current.size>0)return;const M=new Set([...b,...N.current]);L(st(r,M,Jt))};if(p)return{state:"error",error:p,apps:[],fns:[],wfs:[],moreApps:!1,loadMoreApps:v};if(i===null||u===null)return{state:"loading",apps:[],fns:[],wfs:[],moreApps:!1,loadMoreApps:v};if(E){if(r===null)return{state:"loading",apps:[],fns:i,wfs:u,moreApps:!1,loadMoreApps:v};if(r.length>0&&b.size===0)return{state:"loading",apps:[],fns:i,wfs:u,moreApps:!1,loadMoreApps:v};const M=Cn(r,f).filter(Q=>(s==null?void 0:s(Q))??!0),W=y.size===0&&st(r,new Set([...b,...y]),1).length>0;return{state:M.length===0&&i.length===0&&u.length===0&&!W?"empty":"ready",apps:M,fns:i,wfs:u,moreApps:W,loadMoreApps:v}}if(o===null)return{state:"loading",apps:[],fns:i,wfs:u,moreApps:!1,loadMoreApps:v};const C=new Set(r??[]),_=o.filter(M=>!fe(M.id)&&((s==null?void 0:s(M))??!0)&&(C.has(M.id)||M.zeroCredential===!0));return{state:_.length===0&&i.length===0&&u.length===0?"empty":"ready",apps:_,fns:i,wfs:u,moreApps:!1,loadMoreApps:v}}function _e(e){return(s,n)=>e(s).localeCompare(e(n),void 0,{sensitivity:"base"})}function Ue(e){const s=e.displayName;return s!=null&&s.trim()?s:"name"in e?e.name:e.id}function ft({family:e,item:s,onSelect:n}){const r=Ue(s);return t.jsxs("button",{type:"button",className:"w6w-stepbuilder-item w6w-stepbuilder-item--callable","data-kind":e,onClick:()=>n({id:s.id,label:r}),children:[t.jsx(Xe,{icon:Hr[e],size:24}),t.jsxs("span",{className:"w6w-stepbuilder-item-main",children:[t.jsx("strong",{children:r}),t.jsx("code",{className:"w6w-muted w6w-small",children:s.id})]})]})}function na({data:e,onSelectApp:s,onSelectCallable:n,theme:r}){const a=f=>t.jsx("div",{className:"w6w-apppicker-host",children:f});if(e.state==="error")return a(t.jsx("div",{className:"w6w-result w6w-error",children:e.error}));if(e.state==="loading")return a(t.jsx("p",{className:"w6w-muted w6w-small",children:"Loading…"}));const o=[...e.apps].sort(_e(f=>f.displayName)),l=[...e.fns].sort(_e(Ue)),i=[...e.wfs].sort(_e(Ue)),c=(f,w)=>w.length===0?null:t.jsxs("section",{className:"w6w-readytouse-col",children:[t.jsx("h4",{className:"w6w-readytouse-heading",children:f}),t.jsx("div",{className:"w6w-stepbuilder-list w6w-stepbuilder-scroll",children:w})]},f),u=o.map(f=>t.jsxs("button",{type:"button",className:"w6w-stepbuilder-item","data-kind":"app",onClick:()=>s(f),children:[t.jsx(we,{src:f.iconSvg,srcDark:f.iconSvgDark,brandColor:f.brandColor,name:f.displayName,theme:r,size:24}),t.jsxs("span",{className:"w6w-stepbuilder-item-main",children:[t.jsx("strong",{children:f.displayName}),t.jsx("code",{className:"w6w-muted w6w-small",children:f.id})]})]},f.id));e.moreApps&&u.push(t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:e.loadMoreApps,children:"Load more"},"__load_more_apps"));const m=c("Connected apps",u),p=[c("Functions",l.map(f=>t.jsx(ft,{family:"function",item:f,onSelect:w=>n({family:"function",...w})},f.id))),c("Workflows",i.map(f=>t.jsx(ft,{family:"workflow",item:f,onSelect:w=>n({family:"workflow",...w})},f.id)))].filter(Boolean),h=(m?1:0)+(p.length>0?1:0);return a(t.jsxs("div",{className:"w6w-readytouse","data-cols":h,children:[m,p.length>0&&t.jsx("div",{className:"w6w-readytouse-stack",children:p})]}))}function ra({appId:e,app:s,onAdd:n,onClose:r,onDraftChange:a,onChangeApp:o,theme:l,workflowId:i,stepId:c,upstreamSteps:u=[],initialAction:m,initialConnection:p,initialWith:h}){const f=te(),[w,b]=d.useState(null),[S,y]=d.useState(null),[x,N]=d.useState(null),[j,A]=d.useState(null),[k,P]=d.useState(p??""),[E,I]=d.useState(m??""),[L,D]=d.useState(h??{}),[v,C]=d.useState(!1),[_,B]=d.useState(!1),[M,W]=d.useState(m&&h?"configure":"setup"),[H,Q]=d.useState("props"),[ee,G]=d.useState("{}"),[z,ae]=d.useState("{}"),[K,g]=d.useState({});d.useEffect(()=>{let R=!1;return A(null),Promise.all([f.getAppAuth(e),f.listConnectionsForApp(e),f.getAppActions(e)]).then(([U,ie,$e])=>{if(R)return;b(U),y(ie),N($e),!(U??[]).some(Ws=>Ws.autoSatisfied===!0)&&ie.length>0&&P(ie[0].id)}).catch(U=>!R&&A(U.message)),()=>{R=!0}},[f,e]);const O=async()=>{const R=await f.listConnectionsForApp(e);y(R),R.length>0&&P(U=>U||R[0].id)},F=(w??[]).filter(R=>R.available!==!1),V=F.some(R=>R.autoSatisfied===!0&&(R.type==="tenantAuth"||R.type==="jit")),q=F.length>0&&!V,J=(S??[]).length>0,$=(x??[]).find(R=>R.key===E),Z=[...x??[]].sort((R,U)=>(R.title??R.key).localeCompare(U.title??U.key,void 0,{sensitivity:"base"})),ve=Hs(s),[et,Ne]=d.useState(!1);d.useEffect(()=>{if(!ve||!i||!c)return;let R=!1;return f.listStepTests(i,c).then(U=>{!R&&U.some(ie=>ie.lastRunStatus==="succeeded")&&Ne(!0)}).catch(()=>{}),()=>{R=!0}},[f,ve,i,c]);const Me=Pt(i??"",u,!!i),Oe=It(Me),se=!!E&&(!q||J&&!!k),le=se&&!!$&&ye($.params??[],L),tt=se,T=(S??[]).find(R=>R.id===k),Y=_||!k;function X(){return{uses:{app:e,action:($==null?void 0:$.key)??E,...(q||V)&&k?{connection:k}:{}},with:L,...K}}function ke(){$&&n(X())}const[re,Ce]=d.useState(null);d.useEffect(()=>{if(!a||re!==null||!se)return;const R=n(X());R&&Ce(R)},[a,re,se]),d.useEffect(()=>{!a||re===null||a(re,X())},[re,L,K,k]);const Se=R=>{R==="code"?G(Tt(X())):R==="params-code"&&ae(Rt(X())),Q(R)};return t.jsxs("div",{className:"w6w-stepconfig",children:[t.jsxs("div",{className:"w6w-tabsbar",children:[t.jsxs("div",{className:"w6w-subtabs",children:[t.jsx("button",{type:"button",className:`w6w-subtab${M==="setup"?" active":""}`,onClick:()=>W("setup"),children:"Setup"}),t.jsx("button",{type:"button",disabled:!se,title:se?void 0:"Complete Setup first",className:`w6w-subtab${M==="configure"?" active":""}`,onClick:()=>se&&W("configure"),children:"Configure"}),t.jsx("button",{type:"button",disabled:!le,title:le?void 0:"Fill the required fields first",className:`w6w-subtab${M==="test"?" active":""}`,onClick:()=>le&&W("test"),children:"Test"})]}),t.jsx(Qe,{view:H,onChange:Se,disabled:M!=="configure"})]}),t.jsxs("div",{className:"w6w-stepconfig-body",children:[M==="setup"&&t.jsxs("div",{className:"w6w-stack",children:[j&&t.jsx("div",{className:"w6w-result w6w-error",children:j}),w===null&&!j&&t.jsx("p",{className:"w6w-muted w6w-small",children:"Loading…"}),t.jsxs("div",{className:"w6w-field",children:[t.jsx("span",{children:"App"}),t.jsxs("div",{className:"w6w-conn-label",children:[s&&t.jsx(we,{src:s.iconSvg,srcDark:s.iconSvgDark,brandColor:s.brandColor,name:s.displayName,theme:l,size:20}),t.jsx("span",{className:"w6w-conn-label-name",children:(s==null?void 0:s.displayName)??e}),o&&t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:o,children:"Change"})]})]}),w!==null&&V&&t.jsxs("div",{className:"w6w-field",children:[t.jsx("span",{children:"Connection"}),t.jsxs("div",{className:"w6w-conn-label",children:[t.jsx("span",{className:"w6w-conn-label-name",children:"Connected automatically — this app needs no connection for your organization."}),t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:()=>C(!0),children:"Create connection"})]}),t.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.'})]}),w!==null&&q&&(J?Y?t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:"Connection"}),t.jsxs("div",{style:{display:"flex",gap:6},children:[t.jsx("select",{value:k,onChange:R=>{P(R.target.value),B(!1)},style:{flex:1},children:(S??[]).map(R=>t.jsxs("option",{value:R.id,children:[R.displayName||R.id," ",R.state?`(${R.state})`:""]},R.id))}),t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>C(!0),children:"+ New"})]})]}):t.jsxs("div",{className:"w6w-field",children:[t.jsx("span",{children:"Connection"}),t.jsxs("div",{className:"w6w-conn-label",children:[t.jsxs("span",{className:"w6w-conn-label-name",children:[(T==null?void 0:T.displayName)||(T==null?void 0:T.id)||k,T!=null&&T.state?` (${T.state})`:""]}),t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:()=>B(!0),children:"Change"}),t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:()=>C(!0),children:"+ New"})]})]}):t.jsxs("div",{className:"w6w-result w6w-stepconfig-conn-empty",children:[t.jsx("div",{style:{marginBottom:8},children:"This app needs a connection before its actions can run."}),t.jsx("button",{type:"button",className:"w6w-btn",onClick:()=>C(!0),children:"Create connection"})]})),x!==null&&(x.length===0?t.jsx("p",{className:"w6w-muted w6w-small",children:"This app exposes no actions."}):t.jsxs("label",{className:"w6w-field",children:[t.jsxs("span",{children:["Action",E?"":" *"]}),t.jsx(Fs,{value:E,placeholder:"— pick an action —",onChange:R=>{I(R),D({}),Ne(!1)},options:Z.map(R=>({value:R.key,label:`${R.title??R.key} (${R.key})`}))}),($==null?void 0:$.description)&&t.jsx("span",{className:"w6w-hint",children:$.description})]}))]}),M==="configure"&&($?H==="props"?t.jsx(pe,{params:$.params??[],values:L,onChange:D}):H==="code"?t.jsx(ue,{value:ee,onChange:()=>{},readOnly:!0,minHeight:"240px",height:"100%","aria-label":"Step JSON",copyable:!0}):H==="params-code"?t.jsx(ue,{value:z,onChange:ae,minHeight:"240px",height:"100%","aria-label":"Parameters JSON",copyable:!0,onValidChange:R=>R&&typeof R=="object"&&!Array.isArray(R)&&D(R)}):t.jsx(yt,{config:K,onChange:g}):t.jsx("p",{className:"w6w-muted w6w-small",children:"Pick an action in Setup first."})),M==="test"&&($?t.jsx(Mt,{app:e,action:$.key,connectionId:(q||V)&&k?k:void 0,values:L,canRun:se&&ye($.params??[],L),state:Oe,onResult:Ne}):t.jsx("p",{className:"w6w-muted w6w-small",children:"Pick an action in Setup first."}))]}),M==="test"&&t.jsx("div",{className:"w6w-stepconfig-testnote",children:ve&&!et&&t.jsx("span",{className:"w6w-muted w6w-small",children:"Not yet tested — a passing test is required before this step can be published."})}),t.jsxs("div",{className:"w6w-modal-actions w6w-stepconfig-footer",children:[t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:r,children:"Cancel"}),M==="test"?t.jsx("button",{type:"button",className:"w6w-btn",disabled:re===null&&!tt,onClick:re!==null?r:ke,children:re!==null?"Done":"Add step"}):t.jsx("button",{type:"button",className:"w6w-btn",disabled:M==="setup"?!se:!le,onClick:()=>W(M==="setup"?"configure":"test"),children:"Next →"})]}),v&&t.jsx(gt,{theme:l,initialAppId:e,onClose:()=>C(!1),onCreated:async({connectionId:R})=>{C(!1),P(R),B(!1),await O()}})]})}function aa({appId:e,app:s,onClose:n,onChangeApp:r,theme:a,initialConnection:o,onConnected:l}){const i=te(),[c,u]=d.useState(null),[m,p]=d.useState(null),[h,f]=d.useState(null),[w,b]=d.useState(o??""),[S,y]=d.useState(!1),[x,N]=d.useState(!1);d.useEffect(()=>{let v=!1;return f(null),Promise.all([i.getAppAuth(e),i.listConnectionsForApp(e)]).then(([C,_])=>{if(v)return;u(C),p(_),!(C??[]).some(M=>M.autoSatisfied===!0)&&_.length>0&&b(_[0].id)}).catch(C=>!v&&f(C.message)),()=>{v=!0}},[i,e]);const j=async()=>{const v=await i.listConnectionsForApp(e);p(v),v.length>0&&b(C=>C||v[0].id)},A=(c??[]).filter(v=>v.available!==!1),k=A.some(v=>v.autoSatisfied===!0&&(v.type==="tenantAuth"||v.type==="jit")),P=A.length>0&&!k,E=(m??[]).length>0,I=!P||E&&!!w,L=(m??[]).find(v=>v.id===w),D=x||!w;return t.jsxs("div",{className:"w6w-stepconfig",children:[t.jsx("div",{className:"w6w-stepconfig-body",children:t.jsxs("div",{className:"w6w-stack",children:[h&&t.jsx("div",{className:"w6w-result w6w-error",children:h}),c===null&&!h&&t.jsx("p",{className:"w6w-muted w6w-small",children:"Loading…"}),t.jsxs("div",{className:"w6w-field",children:[t.jsx("span",{children:"App"}),t.jsxs("div",{className:"w6w-conn-label",children:[s&&t.jsx(we,{src:s.iconSvg,srcDark:s.iconSvgDark,brandColor:s.brandColor,name:s.displayName,theme:a,size:20}),t.jsx("span",{className:"w6w-conn-label-name",children:(s==null?void 0:s.displayName)??e}),r&&t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:r,children:"Change"})]})]}),c!==null&&k&&t.jsxs("div",{className:"w6w-field",children:[t.jsx("span",{children:"Connection"}),t.jsxs("div",{className:"w6w-conn-label",children:[t.jsx("span",{className:"w6w-conn-label-name",children:"Connected automatically — this app needs no connection for your organization."}),t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:()=>y(!0),children:"Create connection"})]}),t.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&&P&&(E?D?t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:"Connection"}),t.jsxs("div",{style:{display:"flex",gap:6},children:[t.jsx("select",{value:w,onChange:v=>{b(v.target.value),N(!1)},style:{flex:1},children:(m??[]).map(v=>t.jsxs("option",{value:v.id,children:[v.displayName||v.id," ",v.state?`(${v.state})`:""]},v.id))}),t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>y(!0),children:"+ New"})]})]}):t.jsxs("div",{className:"w6w-field",children:[t.jsx("span",{children:"Connection"}),t.jsxs("div",{className:"w6w-conn-label",children:[t.jsxs("span",{className:"w6w-conn-label-name",children:[(L==null?void 0:L.displayName)||(L==null?void 0:L.id)||w,L!=null&&L.state?` (${L.state})`:""]}),t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:()=>N(!0),children:"Change"}),t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:()=>y(!0),children:"+ New"})]})]}):t.jsxs("div",{className:"w6w-result w6w-stepconfig-conn-empty",children:[t.jsx("div",{style:{marginBottom:8},children:"This app needs a connection before its actions can run."}),t.jsx("button",{type:"button",className:"w6w-btn",onClick:()=>y(!0),children:"Create connection"})]}))]})}),t.jsxs("div",{className:"w6w-modal-actions w6w-stepconfig-footer",children:[t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:n,children:"Cancel"}),t.jsx("button",{type:"button",className:"w6w-btn",disabled:!I||!s,onClick:()=>s&&l(w,s),children:"Next →"})]}),S&&t.jsx(gt,{theme:a,initialAppId:e,onClose:()=>y(!1),onCreated:async({connectionId:v})=>{y(!1),b(v),N(!1),await j()}})]})}const oa=["props","code"];function la(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function Vs({params:e,values:s,onChange:n,onValidityChange:r,readOnly:a,initialView:o="props"}){const l=e.length>0,[i,c]=d.useState(o),u=!l||i==="code",[m,p]=d.useState(()=>Gt(s)),[h,f]=d.useState(!0),w=d.useRef(!0),b=x=>{x!==w.current&&(w.current=x,f(x),r==null||r(x))},S=x=>{x==="code"&&p(Gt(s)),b(!0),c(x)},y=l?"Values (JSON)":"Payload";return t.jsxs("div",{className:"w6w-stack",children:[l&&t.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:t.jsx(Qe,{view:i,views:[...oa],onChange:x=>S(x)})}),u?t.jsxs("div",{className:"w6w-field",children:[t.jsx("span",{children:y}),t.jsx(ue,{value:m,onChange:p,readOnly:a,minHeight:"140px","aria-label":`${y} JSON`,onValidChange:x=>{const N=la(x);b(N),N&&n(x)},onValidityChange:x=>{x.valid||b(!1)}}),!h&&t.jsx("span",{className:"w6w-hint",children:"This draft isn’t a JSON object yet — the collected values are unchanged until it is."})]}):t.jsx(pe,{params:e,values:s,onChange:n,readOnly:a})]})}function Gt(e){return JSON.stringify(e??{},null,2)}function ia({title:e,message:s,onConfirm:n,onClose:r,confirmLabel:a="Confirm",cancelLabel:o="Cancel",destructive:l=!0,children:i}){return t.jsxs(ne,{title:e,onClose:r,children:[t.jsxs("div",{className:"w6w-modal-body",children:[t.jsx("p",{className:"w6w-muted w6w-small",children:s}),i]}),t.jsxs("div",{className:"w6w-modal-actions",children:[t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:r,children:o}),t.jsx("button",{type:"button",className:l?"w6w-btn w6w-btn-danger":"w6w-btn",onClick:n,children:a})]})]})}exports.AddConnectionModal=gt;exports.AppIcon=we;exports.AppPicker=be;exports.AuthFieldsForm=ls;exports.CALL_APP=ze;exports.CONTROL_APP=ce;exports.CodeEditor=ds;exports.Combobox=Fs;exports.ConfigViewToggle=Qe;exports.ConfirmModal=ia;exports.DATA_APP=Be;exports.ERROR_SOURCE_HANDLE=mt;exports.ExpressionInput=Ct;exports.ExpressionOptionsProvider=Kn;exports.INTERNAL_NODES=je;exports.IconButton=jt;exports.InternalIcon=Xe;exports.JsonEditor=ue;exports.Modal=ne;exports.NodeConfigForm=yt;exports.ParamsForm=pe;exports.PropertyEntryForm=Vs;exports.RetryPolicyFields=us;exports.SCHEDULER_APP=xt;exports.SCRIPT_APP=Zt;exports.StepBuilderModal=Wr;exports.StepTestRun=Mt;exports.TRIGGER_APP=Je;exports.TriggerFillForm=Is;exports.W6WUIProvider=Sn;exports.WEBHOOK_APP=bt;exports.WaitEditor=Ps;exports.WorkflowProjectProvider=An;exports.asFieldDefs=At;exports.buildResolveScope=js;exports.coerceDefault=Ts;exports.deepEqual=dt;exports.edgeVisuals=Xt;exports.excludeSelfStep=Gn;exports.fieldWidget=Es;exports.fieldsToParams=Et;exports.filterOptions=Os;exports.findChainRoot=Er;exports.findChainTail=Tr;exports.flattenParams=ge;exports.flowEdgeId=Ve;exports.flowToWorkflow=kr;exports.idClashMessage=mr;exports.internalNodeDefaults=ts;exports.internalNodeIcon=yn;exports.internalNodeLabel=gn;exports.internalNodeParams=es;exports.isControlApp=De;exports.isExprValue=Ke;exports.isInternalApp=fe;exports.isParamVisible=Pe;exports.isSecretValue=vt;exports.isTestRequired=Hs;exports.isTriggerApp=qe;exports.laneForSourceHandle=Ys;exports.nodePortsForStep=nn;exports.paramsToJson=Rt;exports.relayoutNodes=Nr;exports.requiredParamsFilled=ye;exports.resolveParamJson=St;exports.resolveParamValue=ks;exports.resolveVarsJson=tr;exports.seedValues=Rs;exports.shouldUseCombobox=Ms;exports.slugifyLabel=Ar;exports.sourceHandleForLane=Qt;exports.startOAuthPopup=is;exports.startStateFromSeeds=It;exports.stepBuilderUpstreamSteps=Lr;exports.stepIdError=fr;exports.stepMetaSampleValues=_r;exports.stepToJson=Tt;exports.storedViewport=Ds;exports.suggestStepId=Rr;exports.upstreamStateSources=$r;exports.useEffectiveTheme=Ge;exports.useEnterSubmit=cs;exports.useExpressionOptions=Ye;exports.useSeedSources=Pt;exports.useW6WApi=te;exports.valueAtPath=Or;exports.varLabel=xe;exports.withViewport=Cr;exports.workflowToFlow=vr;
11
- //# sourceMappingURL=ConfirmModal-ChoiGy2K.cjs.map