@powerhousedao/workflow 6.2.3-dev.30 → 6.2.3-dev.32

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 (374) hide show
  1. package/README.md +8 -8
  2. package/dist/browser/BlockSelector-BHJQOhie.js +3051 -0
  3. package/dist/browser/BlockSelector-BHJQOhie.js.map +1 -0
  4. package/dist/browser/{connection-form-D-NETdDQ.js → connection-form-CaduwBiu.js} +349 -50
  5. package/dist/browser/connection-form-CaduwBiu.js.map +1 -0
  6. package/dist/browser/{data-tree-DA4sc7B7.js → data-tree-8219PVfh.js} +2 -2
  7. package/dist/browser/{data-tree-DA4sc7B7.js.map → data-tree-8219PVfh.js.map} +1 -1
  8. package/dist/browser/document-models/index.js +2 -2
  9. package/dist/browser/document-models/workflow/index.js +3 -3
  10. package/dist/browser/{document-models-BohsduV4.js → document-models-C1ZgIZyV.js} +7 -2
  11. package/dist/browser/{document-models-BohsduV4.js.map → document-models-C1ZgIZyV.js.map} +1 -1
  12. package/dist/browser/{editor-B6N0PCuZ.js → editor-BHV1MZS8.js} +2437 -6283
  13. package/dist/browser/editor-BHV1MZS8.js.map +1 -0
  14. package/dist/{node/editor-StBssjcQ.mjs → browser/editor-C0C1eB0R.js} +385 -119
  15. package/dist/browser/editor-C0C1eB0R.js.map +1 -0
  16. package/dist/browser/{editor-BkdwuOC-.js → editor-CFcXlZY2.js} +14 -24
  17. package/dist/browser/editor-CFcXlZY2.js.map +1 -0
  18. package/dist/browser/editors/connection-editor/module.js +1 -1
  19. package/dist/browser/editors/workflow-editor/module.js +1 -1
  20. package/dist/browser/editors/workflow-studio/module.js +1 -1
  21. package/dist/browser/index.js +97 -43
  22. package/dist/browser/index.js.map +1 -1
  23. package/dist/browser/{module-Bkms70LV.js → module-DU2vb3FH.js} +574 -94
  24. package/dist/browser/module-DU2vb3FH.js.map +1 -0
  25. package/dist/browser/{piece-auth-Z4mZEOtL.js → piece-auth-BS5CtQOG.js} +45 -12
  26. package/dist/browser/piece-auth-BS5CtQOG.js.map +1 -0
  27. package/dist/browser/reactor/index.js +2 -2
  28. package/dist/browser/runtime-queries-Ds2kk-Ow.js +2535 -0
  29. package/dist/browser/runtime-queries-Ds2kk-Ow.js.map +1 -0
  30. package/dist/browser/trigger-text-BkcklsMX.js +5569 -0
  31. package/dist/browser/trigger-text-BkcklsMX.js.map +1 -0
  32. package/dist/browser/{upgrade-manifests-BLrv3cf2.js → upgrade-manifests-BpakVE9l.js} +2 -2
  33. package/dist/browser/{upgrade-manifests-BLrv3cf2.js.map → upgrade-manifests-BpakVE9l.js.map} +1 -1
  34. package/dist/browser/{workflow-CGtVlhr8.js → workflow-BxShRhVy.js} +3 -2
  35. package/dist/browser/workflow-BxShRhVy.js.map +1 -0
  36. package/dist/node/BlockSelector-lOcIiaqt.mjs +3055 -0
  37. package/dist/node/BlockSelector-lOcIiaqt.mjs.map +1 -0
  38. package/dist/node/{connection-form-C9vbfSnA.mjs → connection-form-DWt29kft.mjs} +349 -50
  39. package/dist/node/connection-form-DWt29kft.mjs.map +1 -0
  40. package/dist/node/{data-tree-CbqpF3lC.mjs → data-tree-Cdx85Y19.mjs} +2 -2
  41. package/dist/node/{data-tree-CbqpF3lC.mjs.map → data-tree-Cdx85Y19.mjs.map} +1 -1
  42. package/dist/node/document-models/index.mjs +2 -2
  43. package/dist/node/document-models/workflow/index.mjs +3 -3
  44. package/dist/{browser/editor-CZ5NvCyv.js → node/editor-CR823u-y.mjs} +385 -119
  45. package/dist/node/editor-CR823u-y.mjs.map +1 -0
  46. package/dist/node/{editor-DP36YDk5.mjs → editor-CwX-G2Jv.mjs} +2437 -7479
  47. package/dist/node/editor-CwX-G2Jv.mjs.map +1 -0
  48. package/dist/node/{editor-By9BHI8e.mjs → editor-D_t8OtZn.mjs} +14 -24
  49. package/dist/node/editor-D_t8OtZn.mjs.map +1 -0
  50. package/dist/node/editors/connection-editor/module.mjs +1 -1
  51. package/dist/node/editors/workflow-editor/module.mjs +1 -1
  52. package/dist/node/editors/workflow-studio/module.mjs +1 -1
  53. package/dist/node/index.mjs +102 -43
  54. package/dist/node/index.mjs.map +1 -1
  55. package/dist/node/{module-DuxxhgKs.mjs → module-Dhe5E-VA.mjs} +574 -94
  56. package/dist/node/module-Dhe5E-VA.mjs.map +1 -0
  57. package/dist/node/{piece-auth-Z4mZEOtL.mjs → piece-auth-BS5CtQOG.mjs} +45 -12
  58. package/dist/node/piece-auth-BS5CtQOG.mjs.map +1 -0
  59. package/dist/node/pieces/index.mjs +0 -1
  60. package/dist/node/pieces/index.mjs.map +1 -1
  61. package/dist/node/pieces/reactor/descriptor.json +85 -3
  62. package/dist/node/pieces/reactor/index.mjs +14843 -163
  63. package/dist/node/pieces/reactor/index.mjs.map +1 -1
  64. package/dist/node/pieces/reactor/package.json +1 -1
  65. package/dist/node/runtime-queries-D5EGaCrH.mjs +2544 -0
  66. package/dist/node/runtime-queries-D5EGaCrH.mjs.map +1 -0
  67. package/dist/node/trigger-text-DJIAQBWg.mjs +6765 -0
  68. package/dist/node/trigger-text-DJIAQBWg.mjs.map +1 -0
  69. package/dist/node/{upgrade-manifests-C1sl_M-H.mjs → upgrade-manifests-CmNd742Y.mjs} +2 -2
  70. package/dist/node/{upgrade-manifests-C1sl_M-H.mjs.map → upgrade-manifests-CmNd742Y.mjs.map} +1 -1
  71. package/dist/node/{workflow-C-uuQPnf.mjs → workflow-CGzYGZnr.mjs} +3 -2
  72. package/dist/node/workflow-CGzYGZnr.mjs.map +1 -0
  73. package/dist/powerhouse.manifest.json +6 -1
  74. package/dist/style.css +151 -19
  75. package/dist/types/ai/tools.d.ts +3 -1
  76. package/dist/types/ai/tools.d.ts.map +1 -1
  77. package/dist/types/ai/workflow-tools.d.ts.map +1 -1
  78. package/dist/types/document-models/document-models.d.ts +3 -0
  79. package/dist/types/document-models/document-models.d.ts.map +1 -1
  80. package/dist/types/document-models/workflow/v1/actions.d.ts +3 -0
  81. package/dist/types/document-models/workflow/v1/actions.d.ts.map +1 -1
  82. package/dist/types/document-models/workflow/v1/gen/actions.d.ts +3 -1
  83. package/dist/types/document-models/workflow/v1/gen/actions.d.ts.map +1 -1
  84. package/dist/types/document-models/workflow/v1/gen/creators.d.ts +2 -0
  85. package/dist/types/document-models/workflow/v1/gen/creators.d.ts.map +1 -1
  86. package/dist/types/document-models/workflow/v1/gen/document-model.d.ts.map +1 -1
  87. package/dist/types/document-models/workflow/v1/gen/document-schema.d.ts +3 -0
  88. package/dist/types/document-models/workflow/v1/gen/document-schema.d.ts.map +1 -1
  89. package/dist/types/document-models/workflow/v1/gen/index.d.ts +1 -0
  90. package/dist/types/document-models/workflow/v1/gen/index.d.ts.map +1 -1
  91. package/dist/types/document-models/workflow/v1/gen/ph-factories.d.ts.map +1 -1
  92. package/dist/types/document-models/workflow/v1/gen/publishing/actions.d.ts +16 -0
  93. package/dist/types/document-models/workflow/v1/gen/publishing/actions.d.ts.map +1 -0
  94. package/dist/types/document-models/workflow/v1/gen/publishing/creators.d.ts +5 -0
  95. package/dist/types/document-models/workflow/v1/gen/publishing/creators.d.ts.map +1 -0
  96. package/dist/types/document-models/workflow/v1/gen/publishing/error.d.ts +14 -0
  97. package/dist/types/document-models/workflow/v1/gen/publishing/error.d.ts.map +1 -0
  98. package/dist/types/document-models/workflow/v1/gen/publishing/operations.d.ts +12 -0
  99. package/dist/types/document-models/workflow/v1/gen/publishing/operations.d.ts.map +1 -0
  100. package/dist/types/document-models/workflow/v1/gen/reducer.d.ts.map +1 -1
  101. package/dist/types/document-models/workflow/v1/gen/runtime/actions.d.ts +6 -2
  102. package/dist/types/document-models/workflow/v1/gen/runtime/actions.d.ts.map +1 -1
  103. package/dist/types/document-models/workflow/v1/gen/runtime/creators.d.ts +3 -2
  104. package/dist/types/document-models/workflow/v1/gen/runtime/creators.d.ts.map +1 -1
  105. package/dist/types/document-models/workflow/v1/gen/runtime/error.d.ts +13 -1
  106. package/dist/types/document-models/workflow/v1/gen/runtime/error.d.ts.map +1 -1
  107. package/dist/types/document-models/workflow/v1/gen/runtime/operations.d.ts +2 -1
  108. package/dist/types/document-models/workflow/v1/gen/runtime/operations.d.ts.map +1 -1
  109. package/dist/types/document-models/workflow/v1/gen/schema/types.d.ts +102 -12
  110. package/dist/types/document-models/workflow/v1/gen/schema/types.d.ts.map +1 -1
  111. package/dist/types/document-models/workflow/v1/gen/schema/zod.d.ts +21 -1
  112. package/dist/types/document-models/workflow/v1/gen/schema/zod.d.ts.map +1 -1
  113. package/dist/types/document-models/workflow/v1/gen/steps/error.d.ts +26 -1
  114. package/dist/types/document-models/workflow/v1/gen/steps/error.d.ts.map +1 -1
  115. package/dist/types/document-models/workflow/v1/gen/trigger/error.d.ts +13 -1
  116. package/dist/types/document-models/workflow/v1/gen/trigger/error.d.ts.map +1 -1
  117. package/dist/types/document-models/workflow/v1/gen/utils.d.ts.map +1 -1
  118. package/dist/types/document-models/workflow/v1/gen/variables/error.d.ts +13 -1
  119. package/dist/types/document-models/workflow/v1/gen/variables/error.d.ts.map +1 -1
  120. package/dist/types/document-models/workflow/v1/gen/workflow/error.d.ts +13 -1
  121. package/dist/types/document-models/workflow/v1/gen/workflow/error.d.ts.map +1 -1
  122. package/dist/types/document-models/workflow/v1/module.d.ts +3 -0
  123. package/dist/types/document-models/workflow/v1/module.d.ts.map +1 -1
  124. package/dist/types/document-models/workflow/v1/src/helpers.d.ts +15 -0
  125. package/dist/types/document-models/workflow/v1/src/helpers.d.ts.map +1 -0
  126. package/dist/types/document-models/workflow/v1/src/reducers/edges.d.ts.map +1 -1
  127. package/dist/types/document-models/workflow/v1/src/reducers/publishing.d.ts +3 -0
  128. package/dist/types/document-models/workflow/v1/src/reducers/publishing.d.ts.map +1 -0
  129. package/dist/types/document-models/workflow/v1/src/reducers/runtime.d.ts.map +1 -1
  130. package/dist/types/document-models/workflow/v1/src/reducers/steps.d.ts.map +1 -1
  131. package/dist/types/document-models/workflow/v1/src/reducers/trigger.d.ts.map +1 -1
  132. package/dist/types/document-models/workflow/v1/src/reducers/variables.d.ts.map +1 -1
  133. package/dist/types/document-models/workflow/v1/src/reducers/workflow.d.ts.map +1 -1
  134. package/dist/types/document-models/workflow/v1/tests/block-validation-and-enable.test.d.ts +2 -0
  135. package/dist/types/document-models/workflow/v1/tests/block-validation-and-enable.test.d.ts.map +1 -0
  136. package/dist/types/document-models/workflow/v1/tests/config-and-variables.test.d.ts +2 -0
  137. package/dist/types/document-models/workflow/v1/tests/config-and-variables.test.d.ts.map +1 -0
  138. package/dist/types/document-models/workflow/v1/tests/draft-and-publish.test.d.ts +2 -0
  139. package/dist/types/document-models/workflow/v1/tests/draft-and-publish.test.d.ts.map +1 -0
  140. package/dist/types/document-models/workflow/v1/tests/updated-at.test.d.ts +2 -0
  141. package/dist/types/document-models/workflow/v1/tests/updated-at.test.d.ts.map +1 -0
  142. package/dist/types/editors/connection-editor/ConnectionToolbar.d.ts.map +1 -1
  143. package/dist/types/editors/connection-editor/UsedBy.d.ts.map +1 -1
  144. package/dist/types/editors/connection-editor/connection-callbacks.d.ts.map +1 -1
  145. package/dist/types/editors/connection-editor/connection-form.d.ts +2 -1
  146. package/dist/types/editors/connection-editor/connection-form.d.ts.map +1 -1
  147. package/dist/types/editors/connection-editor/connection-usage.d.ts +3 -2
  148. package/dist/types/editors/connection-editor/connection-usage.d.ts.map +1 -1
  149. package/dist/types/editors/connection-editor/editor.d.ts.map +1 -1
  150. package/dist/types/editors/connection-editor/piece-auth.d.ts +7 -1
  151. package/dist/types/editors/connection-editor/piece-auth.d.ts.map +1 -1
  152. package/dist/types/editors/connection-editor/status.d.ts +2 -1
  153. package/dist/types/editors/connection-editor/status.d.ts.map +1 -1
  154. package/dist/types/editors/shared/controls.d.ts +17 -1
  155. package/dist/types/editors/shared/controls.d.ts.map +1 -1
  156. package/dist/types/editors/shared/editor-chrome.d.ts +2 -0
  157. package/dist/types/editors/shared/editor-chrome.d.ts.map +1 -1
  158. package/dist/types/editors/shared/icons.d.ts +2 -0
  159. package/dist/types/editors/shared/icons.d.ts.map +1 -1
  160. package/dist/types/editors/shared/undo-plan.d.ts +20 -0
  161. package/dist/types/editors/shared/undo-plan.d.ts.map +1 -0
  162. package/dist/types/editors/shared/undo-plan.test.d.ts +2 -0
  163. package/dist/types/editors/shared/undo-plan.test.d.ts.map +1 -0
  164. package/dist/types/editors/workflow-editor/document/useWorkflowModel.d.ts.map +1 -1
  165. package/dist/types/editors/workflow-editor/editor.d.ts +0 -1
  166. package/dist/types/editors/workflow-editor/editor.d.ts.map +1 -1
  167. package/dist/types/editors/workflow-editor/run-kinds.d.ts +5 -0
  168. package/dist/types/editors/workflow-editor/run-kinds.d.ts.map +1 -0
  169. package/dist/types/editors/workflow-editor/runtime-api.d.ts +12 -139
  170. package/dist/types/editors/workflow-editor/runtime-api.d.ts.map +1 -1
  171. package/dist/types/editors/workflow-editor/runtime-client.d.ts +260 -0
  172. package/dist/types/editors/workflow-editor/runtime-client.d.ts.map +1 -0
  173. package/dist/types/editors/workflow-editor/runtime-client.test.d.ts +2 -0
  174. package/dist/types/editors/workflow-editor/runtime-client.test.d.ts.map +1 -0
  175. package/dist/types/editors/workflow-editor/runtime-context.d.ts +45 -0
  176. package/dist/types/editors/workflow-editor/runtime-context.d.ts.map +1 -0
  177. package/dist/types/editors/workflow-editor/runtime-persist.d.ts +23 -0
  178. package/dist/types/editors/workflow-editor/runtime-persist.d.ts.map +1 -0
  179. package/dist/types/editors/workflow-editor/runtime-persist.test.d.ts +2 -0
  180. package/dist/types/editors/workflow-editor/runtime-persist.test.d.ts.map +1 -0
  181. package/dist/types/editors/workflow-editor/runtime-queries.d.ts +128 -0
  182. package/dist/types/editors/workflow-editor/runtime-queries.d.ts.map +1 -0
  183. package/dist/types/editors/workflow-editor/ui/BlockSelector.d.ts +3 -3
  184. package/dist/types/editors/workflow-editor/ui/BlockSelector.d.ts.map +1 -1
  185. package/dist/types/editors/workflow-editor/ui/CanvasContextMenu.d.ts +4 -3
  186. package/dist/types/editors/workflow-editor/ui/CanvasContextMenu.d.ts.map +1 -1
  187. package/dist/types/editors/workflow-editor/ui/ConnectionField.d.ts +2 -3
  188. package/dist/types/editors/workflow-editor/ui/ConnectionField.d.ts.map +1 -1
  189. package/dist/types/editors/workflow-editor/ui/CreateConnectionModal.d.ts.map +1 -1
  190. package/dist/types/editors/workflow-editor/ui/ExpressionPicker.d.ts +6 -5
  191. package/dist/types/editors/workflow-editor/ui/ExpressionPicker.d.ts.map +1 -1
  192. package/dist/types/editors/workflow-editor/ui/PropertyForm.d.ts +7 -1
  193. package/dist/types/editors/workflow-editor/ui/PropertyForm.d.ts.map +1 -1
  194. package/dist/types/editors/workflow-editor/ui/PublishControls.d.ts +34 -0
  195. package/dist/types/editors/workflow-editor/ui/PublishControls.d.ts.map +1 -0
  196. package/dist/types/editors/workflow-editor/ui/ScheduleBuilder.d.ts.map +1 -1
  197. package/dist/types/editors/workflow-editor/ui/StepPanel.d.ts +2 -3
  198. package/dist/types/editors/workflow-editor/ui/StepPanel.d.ts.map +1 -1
  199. package/dist/types/editors/workflow-editor/ui/StepTest.d.ts +11 -0
  200. package/dist/types/editors/workflow-editor/ui/StepTest.d.ts.map +1 -0
  201. package/dist/types/editors/workflow-editor/ui/VariablesEditor.d.ts +0 -1
  202. package/dist/types/editors/workflow-editor/ui/VariablesEditor.d.ts.map +1 -1
  203. package/dist/types/editors/workflow-editor/ui/WorkflowCanvas.d.ts +1 -3
  204. package/dist/types/editors/workflow-editor/ui/WorkflowCanvas.d.ts.map +1 -1
  205. package/dist/types/editors/workflow-editor/ui/WorkflowEditorApp.d.ts +1 -3
  206. package/dist/types/editors/workflow-editor/ui/WorkflowEditorApp.d.ts.map +1 -1
  207. package/dist/types/editors/workflow-editor/ui/add-follow-up.d.ts +31 -0
  208. package/dist/types/editors/workflow-editor/ui/add-follow-up.d.ts.map +1 -0
  209. package/dist/types/editors/workflow-editor/ui/add-follow-up.test.d.ts +2 -0
  210. package/dist/types/editors/workflow-editor/ui/add-follow-up.test.d.ts.map +1 -0
  211. package/dist/types/editors/workflow-editor/ui/ap-edge.d.ts.map +1 -1
  212. package/dist/types/editors/workflow-editor/ui/ap-layout.d.ts +2 -1
  213. package/dist/types/editors/workflow-editor/ui/ap-layout.d.ts.map +1 -1
  214. package/dist/types/editors/workflow-editor/ui/ap-nodes.d.ts +7 -9
  215. package/dist/types/editors/workflow-editor/ui/ap-nodes.d.ts.map +1 -1
  216. package/dist/types/editors/workflow-editor/ui/block-meta.d.ts +10 -5
  217. package/dist/types/editors/workflow-editor/ui/block-meta.d.ts.map +1 -1
  218. package/dist/types/editors/workflow-editor/ui/blocks.d.ts +43 -2
  219. package/dist/types/editors/workflow-editor/ui/blocks.d.ts.map +1 -1
  220. package/dist/types/editors/workflow-editor/ui/blocks.test.d.ts +2 -0
  221. package/dist/types/editors/workflow-editor/ui/blocks.test.d.ts.map +1 -0
  222. package/dist/types/editors/workflow-editor/ui/canvas-menu.d.ts +4 -2
  223. package/dist/types/editors/workflow-editor/ui/canvas-menu.d.ts.map +1 -1
  224. package/dist/types/editors/workflow-editor/ui/connection-create.d.ts +3 -3
  225. package/dist/types/editors/workflow-editor/ui/connection-create.d.ts.map +1 -1
  226. package/dist/types/editors/workflow-editor/ui/design-time.d.ts +92 -0
  227. package/dist/types/editors/workflow-editor/ui/design-time.d.ts.map +1 -0
  228. package/dist/types/editors/workflow-editor/ui/design-time.test.d.ts +2 -0
  229. package/dist/types/editors/workflow-editor/ui/design-time.test.d.ts.map +1 -0
  230. package/dist/types/editors/workflow-editor/ui/expression-scope.d.ts +10 -2
  231. package/dist/types/editors/workflow-editor/ui/expression-scope.d.ts.map +1 -1
  232. package/dist/types/editors/workflow-editor/ui/forms.d.ts +35 -6
  233. package/dist/types/editors/workflow-editor/ui/forms.d.ts.map +1 -1
  234. package/dist/types/editors/workflow-editor/ui/model.d.ts +58 -13
  235. package/dist/types/editors/workflow-editor/ui/model.d.ts.map +1 -1
  236. package/dist/types/editors/workflow-editor/ui/piece-source.d.ts +11 -6
  237. package/dist/types/editors/workflow-editor/ui/piece-source.d.ts.map +1 -1
  238. package/dist/types/editors/workflow-editor/ui/prop-controls.d.ts +5 -0
  239. package/dist/types/editors/workflow-editor/ui/prop-controls.d.ts.map +1 -1
  240. package/dist/types/editors/workflow-editor/ui/prop-controls.test.d.ts +2 -0
  241. package/dist/types/editors/workflow-editor/ui/prop-controls.test.d.ts.map +1 -0
  242. package/dist/types/editors/workflow-editor/ui/prop-defaults.d.ts +4 -0
  243. package/dist/types/editors/workflow-editor/ui/prop-defaults.d.ts.map +1 -0
  244. package/dist/types/editors/workflow-editor/ui/prop-defaults.test.d.ts +2 -0
  245. package/dist/types/editors/workflow-editor/ui/prop-defaults.test.d.ts.map +1 -0
  246. package/dist/types/editors/workflow-editor/ui/query-keys.d.ts +54 -0
  247. package/dist/types/editors/workflow-editor/ui/query-keys.d.ts.map +1 -0
  248. package/dist/types/editors/workflow-editor/ui/schedule-draft.d.ts +3 -8
  249. package/dist/types/editors/workflow-editor/ui/schedule-draft.d.ts.map +1 -1
  250. package/dist/types/editors/workflow-editor/ui/secret-ref.d.ts +18 -0
  251. package/dist/types/editors/workflow-editor/ui/secret-ref.d.ts.map +1 -0
  252. package/dist/types/editors/workflow-editor/ui/step-test.d.ts +14 -0
  253. package/dist/types/editors/workflow-editor/ui/step-test.d.ts.map +1 -0
  254. package/dist/types/editors/workflow-editor/ui/step-test.test.d.ts +2 -0
  255. package/dist/types/editors/workflow-editor/ui/step-test.test.d.ts.map +1 -0
  256. package/dist/types/editors/workflow-editor/ui/test-state.d.ts +7 -0
  257. package/dist/types/editors/workflow-editor/ui/test-state.d.ts.map +1 -0
  258. package/dist/types/editors/workflow-editor/ui/trigger-text.d.ts +2 -1
  259. package/dist/types/editors/workflow-editor/ui/trigger-text.d.ts.map +1 -1
  260. package/dist/types/editors/workflow-editor/ui/use-validity.d.ts +28 -0
  261. package/dist/types/editors/workflow-editor/ui/use-validity.d.ts.map +1 -0
  262. package/dist/types/editors/workflow-editor/ui/validation.d.ts +33 -1
  263. package/dist/types/editors/workflow-editor/ui/validation.d.ts.map +1 -1
  264. package/dist/types/editors/workflow-editor/ui/variable-types.d.ts +14 -0
  265. package/dist/types/editors/workflow-editor/ui/variable-types.d.ts.map +1 -0
  266. package/dist/types/editors/workflow-editor/ui/variable-types.test.d.ts +2 -0
  267. package/dist/types/editors/workflow-editor/ui/variable-types.test.d.ts.map +1 -0
  268. package/dist/types/editors/workflow-editor/ui/version-badge.d.ts +33 -0
  269. package/dist/types/editors/workflow-editor/ui/version-badge.d.ts.map +1 -0
  270. package/dist/types/editors/workflow-editor/ui/version-badge.test.d.ts +2 -0
  271. package/dist/types/editors/workflow-editor/ui/version-badge.test.d.ts.map +1 -0
  272. package/dist/types/editors/workflow-editor/use-runtime-url.d.ts +0 -1
  273. package/dist/types/editors/workflow-editor/use-runtime-url.d.ts.map +1 -1
  274. package/dist/types/editors/workflow-studio/components/RunsTable.d.ts +1 -1
  275. package/dist/types/editors/workflow-studio/components/RunsTable.d.ts.map +1 -1
  276. package/dist/types/editors/workflow-studio/components/RunsView.d.ts +4 -1
  277. package/dist/types/editors/workflow-studio/components/RunsView.d.ts.map +1 -1
  278. package/dist/types/editors/workflow-studio/components/Sidebar.d.ts.map +1 -1
  279. package/dist/types/editors/workflow-studio/components/WorkflowBoard.d.ts +1 -1
  280. package/dist/types/editors/workflow-studio/components/WorkflowBoard.d.ts.map +1 -1
  281. package/dist/types/editors/workflow-studio/components/WorkflowHeader.d.ts +2 -1
  282. package/dist/types/editors/workflow-studio/components/WorkflowHeader.d.ts.map +1 -1
  283. package/dist/types/editors/workflow-studio/components/WorkflowMenu.d.ts +13 -0
  284. package/dist/types/editors/workflow-studio/components/WorkflowMenu.d.ts.map +1 -0
  285. package/dist/types/editors/workflow-studio/components/WorkflowSteps.d.ts +1 -1
  286. package/dist/types/editors/workflow-studio/components/WorkflowSteps.d.ts.map +1 -1
  287. package/dist/types/editors/workflow-studio/components/WorkflowStudio.d.ts +0 -1
  288. package/dist/types/editors/workflow-studio/components/WorkflowStudio.d.ts.map +1 -1
  289. package/dist/types/editors/workflow-studio/components/chain.d.ts +5 -3
  290. package/dist/types/editors/workflow-studio/components/chain.d.ts.map +1 -1
  291. package/dist/types/editors/workflow-studio/components/run-format.d.ts +11 -2
  292. package/dist/types/editors/workflow-studio/components/run-format.d.ts.map +1 -1
  293. package/dist/types/editors/workflow-studio/components/step-outline.d.ts +3 -1
  294. package/dist/types/editors/workflow-studio/components/step-outline.d.ts.map +1 -1
  295. package/dist/types/editors/workflow-studio/components/ui.d.ts +2 -0
  296. package/dist/types/editors/workflow-studio/components/ui.d.ts.map +1 -1
  297. package/dist/types/editors/workflow-studio/components/useRuns.d.ts +4 -1
  298. package/dist/types/editors/workflow-studio/components/useRuns.d.ts.map +1 -1
  299. package/dist/types/editors/workflow-studio/editor.d.ts.map +1 -1
  300. package/dist/types/pieces/index.d.ts.map +1 -1
  301. package/dist/types/pieces/reactor/lib/actions/action-list-prop.test.d.ts +2 -0
  302. package/dist/types/pieces/reactor/lib/actions/action-list-prop.test.d.ts.map +1 -0
  303. package/dist/types/pieces/reactor/lib/actions/document-create.d.ts +14 -1
  304. package/dist/types/pieces/reactor/lib/actions/document-create.d.ts.map +1 -1
  305. package/dist/types/pieces/reactor/lib/actions/document-dispatch.d.ts +14 -1
  306. package/dist/types/pieces/reactor/lib/actions/document-dispatch.d.ts.map +1 -1
  307. package/dist/types/pieces/reactor/lib/actions/document-get.d.ts +1 -0
  308. package/dist/types/pieces/reactor/lib/actions/document-get.d.ts.map +1 -1
  309. package/dist/types/pieces/reactor/lib/actions/document-schema.d.ts +1 -0
  310. package/dist/types/pieces/reactor/lib/actions/document-schema.d.ts.map +1 -1
  311. package/dist/types/pieces/reactor/lib/input-props.d.ts.map +1 -1
  312. package/dist/types/pieces/reactor/lib/input-schema.d.ts +11 -2
  313. package/dist/types/pieces/reactor/lib/input-schema.d.ts.map +1 -1
  314. package/dist/types/pieces/reactor/lib/parse.d.ts +22 -4
  315. package/dist/types/pieces/reactor/lib/parse.d.ts.map +1 -1
  316. package/dist/types/pieces/reactor/lib/reactor.d.ts +15 -1
  317. package/dist/types/pieces/reactor/lib/reactor.d.ts.map +1 -1
  318. package/dist/types/scripts/ui-stack.d.ts +53 -11
  319. package/dist/types/scripts/ui-stack.d.ts.map +1 -1
  320. package/dist/types/test/ui/block-picker.spec.d.ts +2 -0
  321. package/dist/types/test/ui/block-picker.spec.d.ts.map +1 -0
  322. package/dist/types/test/ui/branch.spec.d.ts +2 -0
  323. package/dist/types/test/ui/branch.spec.d.ts.map +1 -0
  324. package/dist/types/test/ui/canvas-logos.spec.d.ts +2 -0
  325. package/dist/types/test/ui/canvas-logos.spec.d.ts.map +1 -0
  326. package/dist/types/test/ui/fixtures.d.ts +1 -0
  327. package/dist/types/test/ui/fixtures.d.ts.map +1 -1
  328. package/dist/types/test/ui/global-setup.d.ts.map +1 -1
  329. package/dist/types/test/ui/harness/prop-controls.d.ts.map +1 -1
  330. package/dist/types/test/ui/piece-version.spec.d.ts +2 -0
  331. package/dist/types/test/ui/piece-version.spec.d.ts.map +1 -0
  332. package/dist/types/test/ui/ports.spec.d.ts +2 -0
  333. package/dist/types/test/ui/ports.spec.d.ts.map +1 -0
  334. package/dist/types/test/ui/publish.spec.d.ts +2 -0
  335. package/dist/types/test/ui/publish.spec.d.ts.map +1 -0
  336. package/dist/types/test/ui/step-test.spec.d.ts +2 -0
  337. package/dist/types/test/ui/step-test.spec.d.ts.map +1 -0
  338. package/dist/types/test/ui/variables.spec.d.ts +2 -0
  339. package/dist/types/test/ui/variables.spec.d.ts.map +1 -0
  340. package/dist/types/test/ui/webhook.spec.d.ts +2 -0
  341. package/dist/types/test/ui/webhook.spec.d.ts.map +1 -0
  342. package/dist/types/test/ui/workflow-menu.spec.d.ts +2 -0
  343. package/dist/types/test/ui/workflow-menu.spec.d.ts.map +1 -0
  344. package/package.json +11 -10
  345. package/dist/browser/BlockSelector-D24DIiSX.js +0 -1388
  346. package/dist/browser/BlockSelector-D24DIiSX.js.map +0 -1
  347. package/dist/browser/connection-form-D-NETdDQ.js.map +0 -1
  348. package/dist/browser/editor-B6N0PCuZ.js.map +0 -1
  349. package/dist/browser/editor-BkdwuOC-.js.map +0 -1
  350. package/dist/browser/editor-CZ5NvCyv.js.map +0 -1
  351. package/dist/browser/module-Bkms70LV.js.map +0 -1
  352. package/dist/browser/piece-auth-Z4mZEOtL.js.map +0 -1
  353. package/dist/browser/runtime-api-DDMQc4PB.js +0 -558
  354. package/dist/browser/runtime-api-DDMQc4PB.js.map +0 -1
  355. package/dist/browser/trigger-text-CUv5Z2Uk.js +0 -551
  356. package/dist/browser/trigger-text-CUv5Z2Uk.js.map +0 -1
  357. package/dist/browser/workflow-CGtVlhr8.js.map +0 -1
  358. package/dist/node/BlockSelector-CTmmpYxu.mjs +0 -1388
  359. package/dist/node/BlockSelector-CTmmpYxu.mjs.map +0 -1
  360. package/dist/node/connection-form-C9vbfSnA.mjs.map +0 -1
  361. package/dist/node/editor-By9BHI8e.mjs.map +0 -1
  362. package/dist/node/editor-DP36YDk5.mjs.map +0 -1
  363. package/dist/node/editor-StBssjcQ.mjs.map +0 -1
  364. package/dist/node/module-DuxxhgKs.mjs.map +0 -1
  365. package/dist/node/piece-auth-Z4mZEOtL.mjs.map +0 -1
  366. package/dist/node/runtime-api-DDMQc4PB.mjs +0 -558
  367. package/dist/node/runtime-api-DDMQc4PB.mjs.map +0 -1
  368. package/dist/node/trigger-text-Bzq6VfOQ.mjs +0 -551
  369. package/dist/node/trigger-text-Bzq6VfOQ.mjs.map +0 -1
  370. package/dist/node/workflow-C-uuQPnf.mjs.map +0 -1
  371. package/dist/types/editors/workflow-editor/runtime-api.test.d.ts +0 -2
  372. package/dist/types/editors/workflow-editor/runtime-api.test.d.ts.map +0 -1
  373. package/dist/types/editors/workflow-editor/runtime-piece-source.d.ts +0 -2
  374. package/dist/types/editors/workflow-editor/runtime-piece-source.d.ts.map +0 -1
@@ -0,0 +1,3051 @@
1
+ import { $ as pinBlock, A as keepPreviousData, B as Subscribable, C as infiniteQueryBehavior, D as focusManager, E as pendingThenable, F as resolveStaleTime, G as BRANCH_BLOCK, H as createRuntimeClient, I as shallowEqualObjects, J as SCHEDULE_TRIGGER, L as shouldThrowError, M as replaceData, N as replaceEqualDeep, O as isServer, P as resolveEnabled, Q as isCoreBlock, R as timeUntilStale, S as hasPreviousPage, T as notifyManager, U as isSyncingError, W as ASSERT_BLOCK, Z as WEBHOOK_TRIGGER, _ as runtimeKeys, a as pieceActionsQuery, b as QueryClient, c as runQuery, d as secretStatQuery, dt as scheduleConfigIssue, g as queryKind, h as blockRefKey, j as noop, k as isValidTimeout, m as SHARED_STALE_MS, n as catalogQuery, o as pieceTriggersQuery, p as RESOLVER_STALE_MS, q as MANUAL_TRIGGER, r as createRuntimeQueryClient, s as runPagesQuery, st as checkTriggerStrategy, tt as stepBlock, u as runsQuery, w as fetchState, x as hasNextPage, z as timeoutManager } from "./runtime-queries-Ds2kk-Ow.js";
2
+ import { Rt as blockKey, zt as compareVersions } from "./module-DU2vb3FH.js";
3
+ import * as React$1 from "react";
4
+ import { Component, Fragment, createContext, useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
5
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
6
+ import { DEFAULT_SWITCHBOARD_URL, parseDriveUrl, subgraphUrlFromGraphqlUrl, useDefaultDrivesUrl, useSelectedDriveSafe, useSyncList } from "@powerhousedao/reactor-browser";
7
+ import { DOCUMENT_SCOPE_ACTION_TYPES } from "@powerhousedao/shared/document-model";
8
+ import { createPortal } from "react-dom";
9
+ //#region ../../node_modules/.pnpm/@tanstack+query-core@5.90.20/node_modules/@tanstack/query-core/build/modern/queryObserver.js
10
+ var QueryObserver = class extends Subscribable {
11
+ constructor(client, options) {
12
+ super();
13
+ this.options = options;
14
+ this.#client = client;
15
+ this.#selectError = null;
16
+ this.#currentThenable = pendingThenable();
17
+ this.bindMethods();
18
+ this.setOptions(options);
19
+ }
20
+ #client;
21
+ #currentQuery = void 0;
22
+ #currentQueryInitialState = void 0;
23
+ #currentResult = void 0;
24
+ #currentResultState;
25
+ #currentResultOptions;
26
+ #currentThenable;
27
+ #selectError;
28
+ #selectFn;
29
+ #selectResult;
30
+ #lastQueryWithDefinedData;
31
+ #staleTimeoutId;
32
+ #refetchIntervalId;
33
+ #currentRefetchInterval;
34
+ #trackedProps = /* @__PURE__ */ new Set();
35
+ bindMethods() {
36
+ this.refetch = this.refetch.bind(this);
37
+ }
38
+ onSubscribe() {
39
+ if (this.listeners.size === 1) {
40
+ this.#currentQuery.addObserver(this);
41
+ if (shouldFetchOnMount(this.#currentQuery, this.options)) this.#executeFetch();
42
+ else this.updateResult();
43
+ this.#updateTimers();
44
+ }
45
+ }
46
+ onUnsubscribe() {
47
+ if (!this.hasListeners()) this.destroy();
48
+ }
49
+ shouldFetchOnReconnect() {
50
+ return shouldFetchOn(this.#currentQuery, this.options, this.options.refetchOnReconnect);
51
+ }
52
+ shouldFetchOnWindowFocus() {
53
+ return shouldFetchOn(this.#currentQuery, this.options, this.options.refetchOnWindowFocus);
54
+ }
55
+ destroy() {
56
+ this.listeners = /* @__PURE__ */ new Set();
57
+ this.#clearStaleTimeout();
58
+ this.#clearRefetchInterval();
59
+ this.#currentQuery.removeObserver(this);
60
+ }
61
+ setOptions(options) {
62
+ const prevOptions = this.options;
63
+ const prevQuery = this.#currentQuery;
64
+ this.options = this.#client.defaultQueryOptions(options);
65
+ if (this.options.enabled !== void 0 && typeof this.options.enabled !== "boolean" && typeof this.options.enabled !== "function" && typeof resolveEnabled(this.options.enabled, this.#currentQuery) !== "boolean") throw new Error("Expected enabled to be a boolean or a callback that returns a boolean");
66
+ this.#updateQuery();
67
+ this.#currentQuery.setOptions(this.options);
68
+ if (prevOptions._defaulted && !shallowEqualObjects(this.options, prevOptions)) this.#client.getQueryCache().notify({
69
+ type: "observerOptionsUpdated",
70
+ query: this.#currentQuery,
71
+ observer: this
72
+ });
73
+ const mounted = this.hasListeners();
74
+ if (mounted && shouldFetchOptionally(this.#currentQuery, prevQuery, this.options, prevOptions)) this.#executeFetch();
75
+ this.updateResult();
76
+ if (mounted && (this.#currentQuery !== prevQuery || resolveEnabled(this.options.enabled, this.#currentQuery) !== resolveEnabled(prevOptions.enabled, this.#currentQuery) || resolveStaleTime(this.options.staleTime, this.#currentQuery) !== resolveStaleTime(prevOptions.staleTime, this.#currentQuery))) this.#updateStaleTimeout();
77
+ const nextRefetchInterval = this.#computeRefetchInterval();
78
+ if (mounted && (this.#currentQuery !== prevQuery || resolveEnabled(this.options.enabled, this.#currentQuery) !== resolveEnabled(prevOptions.enabled, this.#currentQuery) || nextRefetchInterval !== this.#currentRefetchInterval)) this.#updateRefetchInterval(nextRefetchInterval);
79
+ }
80
+ getOptimisticResult(options) {
81
+ const query = this.#client.getQueryCache().build(this.#client, options);
82
+ const result = this.createResult(query, options);
83
+ if (shouldAssignObserverCurrentProperties(this, result)) {
84
+ this.#currentResult = result;
85
+ this.#currentResultOptions = this.options;
86
+ this.#currentResultState = this.#currentQuery.state;
87
+ }
88
+ return result;
89
+ }
90
+ getCurrentResult() {
91
+ return this.#currentResult;
92
+ }
93
+ trackResult(result, onPropTracked) {
94
+ return new Proxy(result, { get: (target, key) => {
95
+ this.trackProp(key);
96
+ onPropTracked?.(key);
97
+ if (key === "promise") {
98
+ this.trackProp("data");
99
+ if (!this.options.experimental_prefetchInRender && this.#currentThenable.status === "pending") this.#currentThenable.reject(/* @__PURE__ */ new Error("experimental_prefetchInRender feature flag is not enabled"));
100
+ }
101
+ return Reflect.get(target, key);
102
+ } });
103
+ }
104
+ trackProp(key) {
105
+ this.#trackedProps.add(key);
106
+ }
107
+ getCurrentQuery() {
108
+ return this.#currentQuery;
109
+ }
110
+ refetch({ ...options } = {}) {
111
+ return this.fetch({ ...options });
112
+ }
113
+ fetchOptimistic(options) {
114
+ const defaultedOptions = this.#client.defaultQueryOptions(options);
115
+ const query = this.#client.getQueryCache().build(this.#client, defaultedOptions);
116
+ return query.fetch().then(() => this.createResult(query, defaultedOptions));
117
+ }
118
+ fetch(fetchOptions) {
119
+ return this.#executeFetch({
120
+ ...fetchOptions,
121
+ cancelRefetch: fetchOptions.cancelRefetch ?? true
122
+ }).then(() => {
123
+ this.updateResult();
124
+ return this.#currentResult;
125
+ });
126
+ }
127
+ #executeFetch(fetchOptions) {
128
+ this.#updateQuery();
129
+ let promise = this.#currentQuery.fetch(this.options, fetchOptions);
130
+ if (!fetchOptions?.throwOnError) promise = promise.catch(noop);
131
+ return promise;
132
+ }
133
+ #updateStaleTimeout() {
134
+ this.#clearStaleTimeout();
135
+ const staleTime = resolveStaleTime(this.options.staleTime, this.#currentQuery);
136
+ if (isServer || this.#currentResult.isStale || !isValidTimeout(staleTime)) return;
137
+ const timeout = timeUntilStale(this.#currentResult.dataUpdatedAt, staleTime) + 1;
138
+ this.#staleTimeoutId = timeoutManager.setTimeout(() => {
139
+ if (!this.#currentResult.isStale) this.updateResult();
140
+ }, timeout);
141
+ }
142
+ #computeRefetchInterval() {
143
+ return (typeof this.options.refetchInterval === "function" ? this.options.refetchInterval(this.#currentQuery) : this.options.refetchInterval) ?? false;
144
+ }
145
+ #updateRefetchInterval(nextInterval) {
146
+ this.#clearRefetchInterval();
147
+ this.#currentRefetchInterval = nextInterval;
148
+ if (isServer || resolveEnabled(this.options.enabled, this.#currentQuery) === false || !isValidTimeout(this.#currentRefetchInterval) || this.#currentRefetchInterval === 0) return;
149
+ this.#refetchIntervalId = timeoutManager.setInterval(() => {
150
+ if (this.options.refetchIntervalInBackground || focusManager.isFocused()) this.#executeFetch();
151
+ }, this.#currentRefetchInterval);
152
+ }
153
+ #updateTimers() {
154
+ this.#updateStaleTimeout();
155
+ this.#updateRefetchInterval(this.#computeRefetchInterval());
156
+ }
157
+ #clearStaleTimeout() {
158
+ if (this.#staleTimeoutId) {
159
+ timeoutManager.clearTimeout(this.#staleTimeoutId);
160
+ this.#staleTimeoutId = void 0;
161
+ }
162
+ }
163
+ #clearRefetchInterval() {
164
+ if (this.#refetchIntervalId) {
165
+ timeoutManager.clearInterval(this.#refetchIntervalId);
166
+ this.#refetchIntervalId = void 0;
167
+ }
168
+ }
169
+ createResult(query, options) {
170
+ const prevQuery = this.#currentQuery;
171
+ const prevOptions = this.options;
172
+ const prevResult = this.#currentResult;
173
+ const prevResultState = this.#currentResultState;
174
+ const prevResultOptions = this.#currentResultOptions;
175
+ const queryInitialState = query !== prevQuery ? query.state : this.#currentQueryInitialState;
176
+ const { state } = query;
177
+ let newState = { ...state };
178
+ let isPlaceholderData = false;
179
+ let data;
180
+ if (options._optimisticResults) {
181
+ const mounted = this.hasListeners();
182
+ const fetchOnMount = !mounted && shouldFetchOnMount(query, options);
183
+ const fetchOptionally = mounted && shouldFetchOptionally(query, prevQuery, options, prevOptions);
184
+ if (fetchOnMount || fetchOptionally) newState = {
185
+ ...newState,
186
+ ...fetchState(state.data, query.options)
187
+ };
188
+ if (options._optimisticResults === "isRestoring") newState.fetchStatus = "idle";
189
+ }
190
+ let { error, errorUpdatedAt, status } = newState;
191
+ data = newState.data;
192
+ let skipSelect = false;
193
+ if (options.placeholderData !== void 0 && data === void 0 && status === "pending") {
194
+ let placeholderData;
195
+ if (prevResult?.isPlaceholderData && options.placeholderData === prevResultOptions?.placeholderData) {
196
+ placeholderData = prevResult.data;
197
+ skipSelect = true;
198
+ } else placeholderData = typeof options.placeholderData === "function" ? options.placeholderData(this.#lastQueryWithDefinedData?.state.data, this.#lastQueryWithDefinedData) : options.placeholderData;
199
+ if (placeholderData !== void 0) {
200
+ status = "success";
201
+ data = replaceData(prevResult?.data, placeholderData, options);
202
+ isPlaceholderData = true;
203
+ }
204
+ }
205
+ if (options.select && data !== void 0 && !skipSelect) {
206
+ if (prevResult && data === prevResultState?.data && options.select === this.#selectFn) data = this.#selectResult;
207
+ else try {
208
+ this.#selectFn = options.select;
209
+ data = options.select(data);
210
+ data = replaceData(prevResult?.data, data, options);
211
+ this.#selectResult = data;
212
+ this.#selectError = null;
213
+ } catch (selectError) {
214
+ this.#selectError = selectError;
215
+ }
216
+ }
217
+ if (this.#selectError) {
218
+ error = this.#selectError;
219
+ data = this.#selectResult;
220
+ errorUpdatedAt = Date.now();
221
+ status = "error";
222
+ }
223
+ const isFetching = newState.fetchStatus === "fetching";
224
+ const isPending = status === "pending";
225
+ const isError = status === "error";
226
+ const isLoading = isPending && isFetching;
227
+ const hasData = data !== void 0;
228
+ const nextResult = {
229
+ status,
230
+ fetchStatus: newState.fetchStatus,
231
+ isPending,
232
+ isSuccess: status === "success",
233
+ isError,
234
+ isInitialLoading: isLoading,
235
+ isLoading,
236
+ data,
237
+ dataUpdatedAt: newState.dataUpdatedAt,
238
+ error,
239
+ errorUpdatedAt,
240
+ failureCount: newState.fetchFailureCount,
241
+ failureReason: newState.fetchFailureReason,
242
+ errorUpdateCount: newState.errorUpdateCount,
243
+ isFetched: newState.dataUpdateCount > 0 || newState.errorUpdateCount > 0,
244
+ isFetchedAfterMount: newState.dataUpdateCount > queryInitialState.dataUpdateCount || newState.errorUpdateCount > queryInitialState.errorUpdateCount,
245
+ isFetching,
246
+ isRefetching: isFetching && !isPending,
247
+ isLoadingError: isError && !hasData,
248
+ isPaused: newState.fetchStatus === "paused",
249
+ isPlaceholderData,
250
+ isRefetchError: isError && hasData,
251
+ isStale: isStale(query, options),
252
+ refetch: this.refetch,
253
+ promise: this.#currentThenable,
254
+ isEnabled: resolveEnabled(options.enabled, query) !== false
255
+ };
256
+ if (this.options.experimental_prefetchInRender) {
257
+ const hasResultData = nextResult.data !== void 0;
258
+ const isErrorWithoutData = nextResult.status === "error" && !hasResultData;
259
+ const finalizeThenableIfPossible = (thenable) => {
260
+ if (isErrorWithoutData) thenable.reject(nextResult.error);
261
+ else if (hasResultData) thenable.resolve(nextResult.data);
262
+ };
263
+ const recreateThenable = () => {
264
+ const pending = this.#currentThenable = nextResult.promise = pendingThenable();
265
+ finalizeThenableIfPossible(pending);
266
+ };
267
+ const prevThenable = this.#currentThenable;
268
+ switch (prevThenable.status) {
269
+ case "pending":
270
+ if (query.queryHash === prevQuery.queryHash) finalizeThenableIfPossible(prevThenable);
271
+ break;
272
+ case "fulfilled":
273
+ if (isErrorWithoutData || nextResult.data !== prevThenable.value) recreateThenable();
274
+ break;
275
+ case "rejected": if (!isErrorWithoutData || nextResult.error !== prevThenable.reason) recreateThenable();
276
+ }
277
+ }
278
+ return nextResult;
279
+ }
280
+ updateResult() {
281
+ const prevResult = this.#currentResult;
282
+ const nextResult = this.createResult(this.#currentQuery, this.options);
283
+ this.#currentResultState = this.#currentQuery.state;
284
+ this.#currentResultOptions = this.options;
285
+ if (this.#currentResultState.data !== void 0) this.#lastQueryWithDefinedData = this.#currentQuery;
286
+ if (shallowEqualObjects(nextResult, prevResult)) return;
287
+ this.#currentResult = nextResult;
288
+ const shouldNotifyListeners = () => {
289
+ if (!prevResult) return true;
290
+ const { notifyOnChangeProps } = this.options;
291
+ const notifyOnChangePropsValue = typeof notifyOnChangeProps === "function" ? notifyOnChangeProps() : notifyOnChangeProps;
292
+ if (notifyOnChangePropsValue === "all" || !notifyOnChangePropsValue && !this.#trackedProps.size) return true;
293
+ const includedProps = new Set(notifyOnChangePropsValue ?? this.#trackedProps);
294
+ if (this.options.throwOnError) includedProps.add("error");
295
+ return Object.keys(this.#currentResult).some((key) => {
296
+ const typedKey = key;
297
+ return this.#currentResult[typedKey] !== prevResult[typedKey] && includedProps.has(typedKey);
298
+ });
299
+ };
300
+ this.#notify({ listeners: shouldNotifyListeners() });
301
+ }
302
+ #updateQuery() {
303
+ const query = this.#client.getQueryCache().build(this.#client, this.options);
304
+ if (query === this.#currentQuery) return;
305
+ const prevQuery = this.#currentQuery;
306
+ this.#currentQuery = query;
307
+ this.#currentQueryInitialState = query.state;
308
+ if (this.hasListeners()) {
309
+ prevQuery?.removeObserver(this);
310
+ query.addObserver(this);
311
+ }
312
+ }
313
+ onQueryUpdate() {
314
+ this.updateResult();
315
+ if (this.hasListeners()) this.#updateTimers();
316
+ }
317
+ #notify(notifyOptions) {
318
+ notifyManager.batch(() => {
319
+ if (notifyOptions.listeners) this.listeners.forEach((listener) => {
320
+ listener(this.#currentResult);
321
+ });
322
+ this.#client.getQueryCache().notify({
323
+ query: this.#currentQuery,
324
+ type: "observerResultsUpdated"
325
+ });
326
+ });
327
+ }
328
+ };
329
+ function shouldLoadOnMount(query, options) {
330
+ return resolveEnabled(options.enabled, query) !== false && query.state.data === void 0 && !(query.state.status === "error" && options.retryOnMount === false);
331
+ }
332
+ function shouldFetchOnMount(query, options) {
333
+ return shouldLoadOnMount(query, options) || query.state.data !== void 0 && shouldFetchOn(query, options, options.refetchOnMount);
334
+ }
335
+ function shouldFetchOn(query, options, field) {
336
+ if (resolveEnabled(options.enabled, query) !== false && resolveStaleTime(options.staleTime, query) !== "static") {
337
+ const value = typeof field === "function" ? field(query) : field;
338
+ return value === "always" || value !== false && isStale(query, options);
339
+ }
340
+ return false;
341
+ }
342
+ function shouldFetchOptionally(query, prevQuery, options, prevOptions) {
343
+ return (query !== prevQuery || resolveEnabled(prevOptions.enabled, query) === false) && (!options.suspense || query.state.status !== "error") && isStale(query, options);
344
+ }
345
+ function isStale(query, options) {
346
+ return resolveEnabled(options.enabled, query) !== false && query.isStaleByTime(resolveStaleTime(options.staleTime, query));
347
+ }
348
+ function shouldAssignObserverCurrentProperties(observer, optimisticResult) {
349
+ if (!shallowEqualObjects(observer.getCurrentResult(), optimisticResult)) return true;
350
+ return false;
351
+ }
352
+ //#endregion
353
+ //#region ../../node_modules/.pnpm/@tanstack+query-core@5.90.20/node_modules/@tanstack/query-core/build/modern/infiniteQueryObserver.js
354
+ var InfiniteQueryObserver = class extends QueryObserver {
355
+ constructor(client, options) {
356
+ super(client, options);
357
+ }
358
+ bindMethods() {
359
+ super.bindMethods();
360
+ this.fetchNextPage = this.fetchNextPage.bind(this);
361
+ this.fetchPreviousPage = this.fetchPreviousPage.bind(this);
362
+ }
363
+ setOptions(options) {
364
+ super.setOptions({
365
+ ...options,
366
+ behavior: infiniteQueryBehavior()
367
+ });
368
+ }
369
+ getOptimisticResult(options) {
370
+ options.behavior = infiniteQueryBehavior();
371
+ return super.getOptimisticResult(options);
372
+ }
373
+ fetchNextPage(options) {
374
+ return this.fetch({
375
+ ...options,
376
+ meta: { fetchMore: { direction: "forward" } }
377
+ });
378
+ }
379
+ fetchPreviousPage(options) {
380
+ return this.fetch({
381
+ ...options,
382
+ meta: { fetchMore: { direction: "backward" } }
383
+ });
384
+ }
385
+ createResult(query, options) {
386
+ const { state } = query;
387
+ const parentResult = super.createResult(query, options);
388
+ const { isFetching, isRefetching, isError, isRefetchError } = parentResult;
389
+ const fetchDirection = state.fetchMeta?.fetchMore?.direction;
390
+ const isFetchNextPageError = isError && fetchDirection === "forward";
391
+ const isFetchingNextPage = isFetching && fetchDirection === "forward";
392
+ const isFetchPreviousPageError = isError && fetchDirection === "backward";
393
+ const isFetchingPreviousPage = isFetching && fetchDirection === "backward";
394
+ return {
395
+ ...parentResult,
396
+ fetchNextPage: this.fetchNextPage,
397
+ fetchPreviousPage: this.fetchPreviousPage,
398
+ hasNextPage: hasNextPage(options, state.data),
399
+ hasPreviousPage: hasPreviousPage(options, state.data),
400
+ isFetchNextPageError,
401
+ isFetchingNextPage,
402
+ isFetchPreviousPageError,
403
+ isFetchingPreviousPage,
404
+ isRefetchError: isRefetchError && !isFetchNextPageError && !isFetchPreviousPageError,
405
+ isRefetching: isRefetching && !isFetchingNextPage && !isFetchingPreviousPage
406
+ };
407
+ }
408
+ };
409
+ //#endregion
410
+ //#region ../../node_modules/.pnpm/@tanstack+query-core@5.90.20/node_modules/@tanstack/query-core/build/modern/queriesObserver.js
411
+ function difference(array1, array2) {
412
+ const excludeSet = new Set(array2);
413
+ return array1.filter((x) => !excludeSet.has(x));
414
+ }
415
+ function replaceAt(array, index, value) {
416
+ const copy = array.slice(0);
417
+ copy[index] = value;
418
+ return copy;
419
+ }
420
+ var QueriesObserver = class extends Subscribable {
421
+ #client;
422
+ #result;
423
+ #queries;
424
+ #options;
425
+ #observers;
426
+ #combinedResult;
427
+ #lastCombine;
428
+ #lastResult;
429
+ #lastQueryHashes;
430
+ #observerMatches = [];
431
+ constructor(client, queries, options) {
432
+ super();
433
+ this.#client = client;
434
+ this.#options = options;
435
+ this.#queries = [];
436
+ this.#observers = [];
437
+ this.#result = [];
438
+ this.setQueries(queries);
439
+ }
440
+ onSubscribe() {
441
+ if (this.listeners.size === 1) this.#observers.forEach((observer) => {
442
+ observer.subscribe((result) => {
443
+ this.#onUpdate(observer, result);
444
+ });
445
+ });
446
+ }
447
+ onUnsubscribe() {
448
+ if (!this.listeners.size) this.destroy();
449
+ }
450
+ destroy() {
451
+ this.listeners = /* @__PURE__ */ new Set();
452
+ this.#observers.forEach((observer) => {
453
+ observer.destroy();
454
+ });
455
+ }
456
+ setQueries(queries, options) {
457
+ this.#queries = queries;
458
+ this.#options = options;
459
+ {
460
+ const queryHashes = queries.map((query) => this.#client.defaultQueryOptions(query).queryHash);
461
+ if (new Set(queryHashes).size !== queryHashes.length) console.warn("[QueriesObserver]: Duplicate Queries found. This might result in unexpected behavior.");
462
+ }
463
+ notifyManager.batch(() => {
464
+ const prevObservers = this.#observers;
465
+ const newObserverMatches = this.#findMatchingObservers(this.#queries);
466
+ newObserverMatches.forEach((match) => match.observer.setOptions(match.defaultedQueryOptions));
467
+ const newObservers = newObserverMatches.map((match) => match.observer);
468
+ const newResult = newObservers.map((observer) => observer.getCurrentResult());
469
+ const hasLengthChange = prevObservers.length !== newObservers.length;
470
+ const hasIndexChange = newObservers.some((observer, index) => observer !== prevObservers[index]);
471
+ const hasStructuralChange = hasLengthChange || hasIndexChange;
472
+ const hasResultChange = hasStructuralChange ? true : newResult.some((result, index) => {
473
+ const prev = this.#result[index];
474
+ return !prev || !shallowEqualObjects(result, prev);
475
+ });
476
+ if (!hasStructuralChange && !hasResultChange) return;
477
+ if (hasStructuralChange) {
478
+ this.#observerMatches = newObserverMatches;
479
+ this.#observers = newObservers;
480
+ }
481
+ this.#result = newResult;
482
+ if (!this.hasListeners()) return;
483
+ if (hasStructuralChange) {
484
+ difference(prevObservers, newObservers).forEach((observer) => {
485
+ observer.destroy();
486
+ });
487
+ difference(newObservers, prevObservers).forEach((observer) => {
488
+ observer.subscribe((result) => {
489
+ this.#onUpdate(observer, result);
490
+ });
491
+ });
492
+ }
493
+ this.#notify();
494
+ });
495
+ }
496
+ getCurrentResult() {
497
+ return this.#result;
498
+ }
499
+ getQueries() {
500
+ return this.#observers.map((observer) => observer.getCurrentQuery());
501
+ }
502
+ getObservers() {
503
+ return this.#observers;
504
+ }
505
+ getOptimisticResult(queries, combine) {
506
+ const matches = this.#findMatchingObservers(queries);
507
+ const result = matches.map((match) => match.observer.getOptimisticResult(match.defaultedQueryOptions));
508
+ const queryHashes = matches.map((match) => match.defaultedQueryOptions.queryHash);
509
+ return [
510
+ result,
511
+ (r) => {
512
+ return this.#combineResult(r ?? result, combine, queryHashes);
513
+ },
514
+ () => {
515
+ return this.#trackResult(result, matches);
516
+ }
517
+ ];
518
+ }
519
+ #trackResult(result, matches) {
520
+ return matches.map((match, index) => {
521
+ const observerResult = result[index];
522
+ return !match.defaultedQueryOptions.notifyOnChangeProps ? match.observer.trackResult(observerResult, (accessedProp) => {
523
+ matches.forEach((m) => {
524
+ m.observer.trackProp(accessedProp);
525
+ });
526
+ }) : observerResult;
527
+ });
528
+ }
529
+ #combineResult(input, combine, queryHashes) {
530
+ if (combine) {
531
+ const lastHashes = this.#lastQueryHashes;
532
+ const queryHashesChanged = queryHashes !== void 0 && lastHashes !== void 0 && (lastHashes.length !== queryHashes.length || queryHashes.some((hash, i) => hash !== lastHashes[i]));
533
+ if (!this.#combinedResult || this.#result !== this.#lastResult || queryHashesChanged || combine !== this.#lastCombine) {
534
+ this.#lastCombine = combine;
535
+ this.#lastResult = this.#result;
536
+ if (queryHashes !== void 0) this.#lastQueryHashes = queryHashes;
537
+ this.#combinedResult = replaceEqualDeep(this.#combinedResult, combine(input));
538
+ }
539
+ return this.#combinedResult;
540
+ }
541
+ return input;
542
+ }
543
+ #findMatchingObservers(queries) {
544
+ const prevObserversMap = /* @__PURE__ */ new Map();
545
+ this.#observers.forEach((observer) => {
546
+ const key = observer.options.queryHash;
547
+ if (!key) return;
548
+ const previousObservers = prevObserversMap.get(key);
549
+ if (previousObservers) previousObservers.push(observer);
550
+ else prevObserversMap.set(key, [observer]);
551
+ });
552
+ const observers = [];
553
+ queries.forEach((options) => {
554
+ const defaultedOptions = this.#client.defaultQueryOptions(options);
555
+ const observer = prevObserversMap.get(defaultedOptions.queryHash)?.shift() ?? new QueryObserver(this.#client, defaultedOptions);
556
+ observers.push({
557
+ defaultedQueryOptions: defaultedOptions,
558
+ observer
559
+ });
560
+ });
561
+ return observers;
562
+ }
563
+ #onUpdate(observer, result) {
564
+ const index = this.#observers.indexOf(observer);
565
+ if (index !== -1) {
566
+ this.#result = replaceAt(this.#result, index, result);
567
+ this.#notify();
568
+ }
569
+ }
570
+ #notify() {
571
+ if (this.hasListeners()) {
572
+ const previousResult = this.#combinedResult;
573
+ const newTracked = this.#trackResult(this.#result, this.#observerMatches);
574
+ if (previousResult !== this.#combineResult(newTracked, this.#options?.combine)) notifyManager.batch(() => {
575
+ this.listeners.forEach((listener) => {
576
+ listener(this.#result);
577
+ });
578
+ });
579
+ }
580
+ }
581
+ };
582
+ //#endregion
583
+ //#region ../../node_modules/.pnpm/@tanstack+react-query@5.90.21_react@19.2.6/node_modules/@tanstack/react-query/build/modern/QueryClientProvider.js
584
+ var QueryClientContext = React$1.createContext(void 0);
585
+ var useQueryClient = (queryClient) => {
586
+ const client = React$1.useContext(QueryClientContext);
587
+ if (queryClient) return queryClient;
588
+ if (!client) throw new Error("No QueryClient set, use QueryClientProvider to set one");
589
+ return client;
590
+ };
591
+ //#endregion
592
+ //#region ../../node_modules/.pnpm/@tanstack+react-query@5.90.21_react@19.2.6/node_modules/@tanstack/react-query/build/modern/IsRestoringProvider.js
593
+ var IsRestoringContext = React$1.createContext(false);
594
+ var useIsRestoring = () => React$1.useContext(IsRestoringContext);
595
+ IsRestoringContext.Provider;
596
+ //#endregion
597
+ //#region ../../node_modules/.pnpm/@tanstack+react-query@5.90.21_react@19.2.6/node_modules/@tanstack/react-query/build/modern/QueryErrorResetBoundary.js
598
+ function createValue() {
599
+ let isReset = false;
600
+ return {
601
+ clearReset: () => {
602
+ isReset = false;
603
+ },
604
+ reset: () => {
605
+ isReset = true;
606
+ },
607
+ isReset: () => {
608
+ return isReset;
609
+ }
610
+ };
611
+ }
612
+ var QueryErrorResetBoundaryContext = React$1.createContext(createValue());
613
+ var useQueryErrorResetBoundary = () => React$1.useContext(QueryErrorResetBoundaryContext);
614
+ //#endregion
615
+ //#region ../../node_modules/.pnpm/@tanstack+react-query@5.90.21_react@19.2.6/node_modules/@tanstack/react-query/build/modern/errorBoundaryUtils.js
616
+ var ensurePreventErrorBoundaryRetry = (options, errorResetBoundary, query) => {
617
+ const throwOnError = query?.state.error && typeof options.throwOnError === "function" ? shouldThrowError(options.throwOnError, [query.state.error, query]) : options.throwOnError;
618
+ if (options.suspense || options.experimental_prefetchInRender || throwOnError) {
619
+ if (!errorResetBoundary.isReset()) options.retryOnMount = false;
620
+ }
621
+ };
622
+ var useClearResetErrorBoundary = (errorResetBoundary) => {
623
+ React$1.useEffect(() => {
624
+ errorResetBoundary.clearReset();
625
+ }, [errorResetBoundary]);
626
+ };
627
+ var getHasError = ({ result, errorResetBoundary, throwOnError, query, suspense }) => {
628
+ return result.isError && !errorResetBoundary.isReset() && !result.isFetching && query && (suspense && result.data === void 0 || shouldThrowError(throwOnError, [result.error, query]));
629
+ };
630
+ //#endregion
631
+ //#region ../../node_modules/.pnpm/@tanstack+react-query@5.90.21_react@19.2.6/node_modules/@tanstack/react-query/build/modern/suspense.js
632
+ var ensureSuspenseTimers = (defaultedOptions) => {
633
+ if (defaultedOptions.suspense) {
634
+ const MIN_SUSPENSE_TIME_MS = 1e3;
635
+ const clamp = (value) => value === "static" ? value : Math.max(value ?? MIN_SUSPENSE_TIME_MS, MIN_SUSPENSE_TIME_MS);
636
+ const originalStaleTime = defaultedOptions.staleTime;
637
+ defaultedOptions.staleTime = typeof originalStaleTime === "function" ? (...args) => clamp(originalStaleTime(...args)) : clamp(originalStaleTime);
638
+ if (typeof defaultedOptions.gcTime === "number") defaultedOptions.gcTime = Math.max(defaultedOptions.gcTime, MIN_SUSPENSE_TIME_MS);
639
+ }
640
+ };
641
+ var willFetch = (result, isRestoring) => result.isLoading && result.isFetching && !isRestoring;
642
+ var shouldSuspend = (defaultedOptions, result) => defaultedOptions?.suspense && result.isPending;
643
+ var fetchOptimistic = (defaultedOptions, observer, errorResetBoundary) => observer.fetchOptimistic(defaultedOptions).catch(() => {
644
+ errorResetBoundary.clearReset();
645
+ });
646
+ //#endregion
647
+ //#region ../../node_modules/.pnpm/@tanstack+react-query@5.90.21_react@19.2.6/node_modules/@tanstack/react-query/build/modern/useQueries.js
648
+ function useQueries({ queries, ...options }, queryClient) {
649
+ const client = useQueryClient(queryClient);
650
+ const isRestoring = useIsRestoring();
651
+ const errorResetBoundary = useQueryErrorResetBoundary();
652
+ const defaultedQueries = React$1.useMemo(() => queries.map((opts) => {
653
+ const defaultedOptions = client.defaultQueryOptions(opts);
654
+ defaultedOptions._optimisticResults = isRestoring ? "isRestoring" : "optimistic";
655
+ return defaultedOptions;
656
+ }), [
657
+ queries,
658
+ client,
659
+ isRestoring
660
+ ]);
661
+ defaultedQueries.forEach((queryOptions) => {
662
+ ensureSuspenseTimers(queryOptions);
663
+ const query = client.getQueryCache().get(queryOptions.queryHash);
664
+ ensurePreventErrorBoundaryRetry(queryOptions, errorResetBoundary, query);
665
+ });
666
+ useClearResetErrorBoundary(errorResetBoundary);
667
+ const [observer] = React$1.useState(() => new QueriesObserver(client, defaultedQueries, options));
668
+ const [optimisticResult, getCombinedResult, trackResult] = observer.getOptimisticResult(defaultedQueries, options.combine);
669
+ const shouldSubscribe = !isRestoring && options.subscribed !== false;
670
+ React$1.useSyncExternalStore(React$1.useCallback((onStoreChange) => shouldSubscribe ? observer.subscribe(notifyManager.batchCalls(onStoreChange)) : noop, [observer, shouldSubscribe]), () => observer.getCurrentResult(), () => observer.getCurrentResult());
671
+ React$1.useEffect(() => {
672
+ observer.setQueries(defaultedQueries, options);
673
+ }, [
674
+ defaultedQueries,
675
+ options,
676
+ observer
677
+ ]);
678
+ const suspensePromises = optimisticResult.some((result, index) => shouldSuspend(defaultedQueries[index], result)) ? optimisticResult.flatMap((result, index) => {
679
+ const opts = defaultedQueries[index];
680
+ if (opts && shouldSuspend(opts, result)) return fetchOptimistic(opts, new QueryObserver(client, opts), errorResetBoundary);
681
+ return [];
682
+ }) : [];
683
+ if (suspensePromises.length > 0) throw Promise.all(suspensePromises);
684
+ const firstSingleResultWhichShouldThrow = optimisticResult.find((result, index) => {
685
+ const query = defaultedQueries[index];
686
+ return query && getHasError({
687
+ result,
688
+ errorResetBoundary,
689
+ throwOnError: query.throwOnError,
690
+ query: client.getQueryCache().get(query.queryHash),
691
+ suspense: query.suspense
692
+ });
693
+ });
694
+ if (firstSingleResultWhichShouldThrow?.error) throw firstSingleResultWhichShouldThrow.error;
695
+ return getCombinedResult(trackResult());
696
+ }
697
+ //#endregion
698
+ //#region ../../node_modules/.pnpm/@tanstack+react-query@5.90.21_react@19.2.6/node_modules/@tanstack/react-query/build/modern/useBaseQuery.js
699
+ function useBaseQuery(options, Observer, queryClient) {
700
+ if (typeof options !== "object" || Array.isArray(options)) throw new Error("Bad argument type. Starting with v5, only the \"Object\" form is allowed when calling query related functions. Please use the error stack to find the culprit call. More info here: https://tanstack.com/query/latest/docs/react/guides/migrating-to-v5#supports-a-single-signature-one-object");
701
+ const isRestoring = useIsRestoring();
702
+ const errorResetBoundary = useQueryErrorResetBoundary();
703
+ const client = useQueryClient(queryClient);
704
+ const defaultedOptions = client.defaultQueryOptions(options);
705
+ client.getDefaultOptions().queries?._experimental_beforeQuery?.(defaultedOptions);
706
+ const query = client.getQueryCache().get(defaultedOptions.queryHash);
707
+ if (!defaultedOptions.queryFn) console.error(`[${defaultedOptions.queryHash}]: No queryFn was passed as an option, and no default queryFn was found. The queryFn parameter is only optional when using a default queryFn. More info here: https://tanstack.com/query/latest/docs/framework/react/guides/default-query-function`);
708
+ defaultedOptions._optimisticResults = isRestoring ? "isRestoring" : "optimistic";
709
+ ensureSuspenseTimers(defaultedOptions);
710
+ ensurePreventErrorBoundaryRetry(defaultedOptions, errorResetBoundary, query);
711
+ useClearResetErrorBoundary(errorResetBoundary);
712
+ const isNewCacheEntry = !client.getQueryCache().get(defaultedOptions.queryHash);
713
+ const [observer] = React$1.useState(() => new Observer(client, defaultedOptions));
714
+ const result = observer.getOptimisticResult(defaultedOptions);
715
+ const shouldSubscribe = !isRestoring && options.subscribed !== false;
716
+ React$1.useSyncExternalStore(React$1.useCallback((onStoreChange) => {
717
+ const unsubscribe = shouldSubscribe ? observer.subscribe(notifyManager.batchCalls(onStoreChange)) : noop;
718
+ observer.updateResult();
719
+ return unsubscribe;
720
+ }, [observer, shouldSubscribe]), () => observer.getCurrentResult(), () => observer.getCurrentResult());
721
+ React$1.useEffect(() => {
722
+ observer.setOptions(defaultedOptions);
723
+ }, [defaultedOptions, observer]);
724
+ if (shouldSuspend(defaultedOptions, result)) throw fetchOptimistic(defaultedOptions, observer, errorResetBoundary);
725
+ if (getHasError({
726
+ result,
727
+ errorResetBoundary,
728
+ throwOnError: defaultedOptions.throwOnError,
729
+ query,
730
+ suspense: defaultedOptions.suspense
731
+ })) throw result.error;
732
+ client.getDefaultOptions().queries?._experimental_afterQuery?.(defaultedOptions, result);
733
+ if (defaultedOptions.experimental_prefetchInRender && !isServer && willFetch(result, isRestoring)) (isNewCacheEntry ? fetchOptimistic(defaultedOptions, observer, errorResetBoundary) : query?.promise)?.catch(noop).finally(() => {
734
+ observer.updateResult();
735
+ });
736
+ return !defaultedOptions.notifyOnChangeProps ? observer.trackResult(result) : result;
737
+ }
738
+ //#endregion
739
+ //#region ../../node_modules/.pnpm/@tanstack+react-query@5.90.21_react@19.2.6/node_modules/@tanstack/react-query/build/modern/useQuery.js
740
+ function useQuery(options, queryClient) {
741
+ return useBaseQuery(options, QueryObserver, queryClient);
742
+ }
743
+ //#endregion
744
+ //#region ../../node_modules/.pnpm/@tanstack+react-query@5.90.21_react@19.2.6/node_modules/@tanstack/react-query/build/modern/useInfiniteQuery.js
745
+ function useInfiniteQuery(options, queryClient) {
746
+ return useBaseQuery(options, InfiniteQueryObserver, queryClient);
747
+ }
748
+ new Set([...DOCUMENT_SCOPE_ACTION_TYPES].filter((type) => type !== "CREATE_DOCUMENT"));
749
+ const DRIVE_COLLECTION_PREFIX = "drive.";
750
+ /**
751
+ * Identifies the collection a remote synchronizes. Collections are drive-level
752
+ * abstractions (document-drive and reactor-drive), so a collection id is the
753
+ * drive document id plus the branch it scopes to rather than an opaque string.
754
+ *
755
+ * The canonical string form (`drive.${branch}.${driveId}`) is produced only by
756
+ * `key` and parsed only by `fromKey`; that string is the wire and storage
757
+ * representation and is byte-for-byte identical to the legacy
758
+ * `driveCollectionId(branch, driveId)` output, so existing `document_collections`
759
+ * rows and persisted remotes remain valid without migration.
760
+ */
761
+ var DriveCollectionId = class DriveCollectionId {
762
+ driveId;
763
+ branch;
764
+ constructor(driveId, branch) {
765
+ this.driveId = driveId;
766
+ this.branch = branch;
767
+ }
768
+ static forDrive(driveId, branch = "main") {
769
+ return new DriveCollectionId(driveId, branch);
770
+ }
771
+ /**
772
+ * The single deserializer for the wire/storage form. `branch` may contain
773
+ * dots, while `driveId` is a dot-free document id, so the drive id is the
774
+ * final dot-delimited segment.
775
+ */
776
+ static fromKey(key) {
777
+ if (!key.startsWith(DRIVE_COLLECTION_PREFIX)) throw new Error(`Unsupported collection id: ${key}`);
778
+ const rest = key.slice(6);
779
+ const lastDot = rest.lastIndexOf(".");
780
+ if (lastDot === -1 || lastDot === rest.length - 1) throw new Error(`Malformed drive collection id: ${key}`);
781
+ return new DriveCollectionId(rest.slice(lastDot + 1), rest.slice(0, lastDot));
782
+ }
783
+ get key() {
784
+ return `${DRIVE_COLLECTION_PREFIX}${this.branch}.${this.driveId}`;
785
+ }
786
+ toString() {
787
+ return this.key;
788
+ }
789
+ equals(other) {
790
+ return this.driveId === other.driveId && this.branch === other.branch;
791
+ }
792
+ };
793
+ //#endregion
794
+ //#region editors/shared/DocumentErrorBoundary.tsx
795
+ /** Best-effort message for anything thrown, without stringifying an object. */
796
+ function errorMessage(error) {
797
+ if (error instanceof Error) return error.message;
798
+ if (typeof error === "string") return error;
799
+ return "Unknown error";
800
+ }
801
+ /** Inline "could not load" panel, also used for hook-level (non-thrown) failures. */
802
+ function DocumentLoadError(props) {
803
+ return /* @__PURE__ */ jsxs("div", {
804
+ className: "m-3 rounded border border-solid border-wf-fail/40 bg-wf-fail/10 p-3",
805
+ children: [
806
+ /* @__PURE__ */ jsx("p", {
807
+ className: "text-sm font-medium text-wf-fail",
808
+ children: props.title ?? "This document could not be loaded"
809
+ }),
810
+ props.label ? /* @__PURE__ */ jsx("p", {
811
+ className: "mt-0.5 text-xs text-wf-fail",
812
+ children: props.label
813
+ }) : null,
814
+ props.documentId ? /* @__PURE__ */ jsx("p", {
815
+ className: "mt-0.5 font-mono text-[11px] text-wf-fail",
816
+ children: props.documentId
817
+ }) : null,
818
+ /* @__PURE__ */ jsx("p", {
819
+ className: "mt-1 text-xs text-muted-foreground",
820
+ children: errorMessage(props.error)
821
+ }),
822
+ /* @__PURE__ */ jsxs("div", {
823
+ className: "mt-2 flex gap-2",
824
+ children: [props.onRetry ? /* @__PURE__ */ jsx("button", {
825
+ type: "button",
826
+ className: "rounded border border-solid border-wf-fail/40 px-2 py-0.5 text-xs font-medium text-wf-fail",
827
+ onClick: props.onRetry,
828
+ children: "Retry"
829
+ }) : null, props.onDismiss ? /* @__PURE__ */ jsx("button", {
830
+ type: "button",
831
+ className: "rounded border border-solid border-foreground/15 px-2 py-0.5 text-xs text-muted-foreground",
832
+ onClick: props.onDismiss,
833
+ children: "Dismiss"
834
+ }) : null]
835
+ })
836
+ ]
837
+ });
838
+ }
839
+ var DocumentErrorBoundary = class extends Component {
840
+ state = {
841
+ error: void 0,
842
+ attempt: 0
843
+ };
844
+ static getDerivedStateFromError(error) {
845
+ return { error };
846
+ }
847
+ componentDidCatch(error, info) {
848
+ console.error(`Failed to render document ${this.props.documentId ?? "(unknown id)"}:`, error, info.componentStack);
849
+ }
850
+ retry = () => {
851
+ this.setState((state) => ({
852
+ error: void 0,
853
+ attempt: state.attempt + 1
854
+ }));
855
+ };
856
+ dismiss = () => {
857
+ this.setState({ error: void 0 });
858
+ this.props.onDismiss?.();
859
+ };
860
+ render() {
861
+ if (this.state.error !== void 0) return /* @__PURE__ */ jsx(DocumentLoadError, {
862
+ label: this.props.label,
863
+ documentId: this.props.documentId,
864
+ error: this.state.error,
865
+ onRetry: this.retry,
866
+ onDismiss: this.props.onDismiss ? this.dismiss : void 0
867
+ });
868
+ return /* @__PURE__ */ jsx(Fragment, { children: this.props.children }, this.state.attempt);
869
+ }
870
+ };
871
+ //#endregion
872
+ //#region editors/shared/icons.tsx
873
+ const ICON_PATHS = {
874
+ pencil: "M4 20h4L19 9l-4-4L4 16v4zM14 6l4 4",
875
+ trash: "M5 7h14M10 11v6M14 11v6M6 7l1 13h10l1-13M9 7V4h6v3",
876
+ plus: "M12 5v14M5 12h14",
877
+ minus: "M5 12h14",
878
+ list: "M8 6h12M8 12h12M8 18h12M4 6h.01M4 12h.01M4 18h.01",
879
+ play: "M7 5v14l12-7z",
880
+ chevron: "M9 6l6 6-6 6",
881
+ chevronDown: "M6 9l6 6 6-6",
882
+ retry: "M4 12a8 8 0 1 0 2.3-5.7M4 4v4h4",
883
+ back: "M15 6l-6 6 6 6",
884
+ close: "M6 6l12 12M18 6L6 18",
885
+ check: "M5 12l5 5 9-10",
886
+ search: "M11 18a7 7 0 1 0 0-14 7 7 0 0 0 0 14zM20 20l-4-4",
887
+ braces: "M8 4c-2 0-3 1-3 3v2c0 1.5-1 3-2 3 1 0 2 1.5 2 3v2c0 2 1 3 3 3M16 4c2 0 3 1 3 3v2c0 1.5 1 3 2 3-1 0-2 1.5-2 3v2c0 2-1 3-3 3",
888
+ link: "M10 14a4 4 0 0 0 5.7 0l3-3a4 4 0 0 0-5.7-5.7l-1 1M14 10a4 4 0 0 0-5.7 0l-3 3a4 4 0 0 0 5.7 5.7l1-1",
889
+ arrowRight: "M5 12h14M13 6l6 6-6 6",
890
+ alert: "M12 8v5M12 16.5v.01M10.3 4l-7.6 13.2A2 2 0 0 0 4.4 20h15.2a2 2 0 0 0 1.7-2.8L13.7 4a2 2 0 0 0-3.4 0z",
891
+ copy: "M9 9h10v10H9zM5 15V5h10",
892
+ sliders: "M4 7h10M18 7h2M4 17h4M12 17h8M14 5v4M8 15v4",
893
+ eye: "M2.5 12s3.5-6.5 9.5-6.5 9.5 6.5 9.5 6.5-3.5 6.5-9.5 6.5S2.5 12 2.5 12zM12 14.5a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5z",
894
+ eyeOff: "M3 3l18 18M10.6 5.6A10 10 0 0 1 12 5.5c6 0 9.5 6.5 9.5 6.5a17 17 0 0 1-3 3.7M6.6 6.6C4 8.3 2.5 12 2.5 12s3.5 6.5 9.5 6.5a9.6 9.6 0 0 0 4.4-1M9.9 9.9a3 3 0 0 0 4.2 4.2",
895
+ undo: "M9 14L4 9l5-5M4 9h10a6 6 0 0 1 0 12h-3",
896
+ redo: "M15 14l5-5-5-5M20 9H10a6 6 0 0 0 0 12h3",
897
+ clock: "M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18zM12 7v5l3 2",
898
+ bolt: "M13 3L5 13h6l-1 8 8-10h-6l1-8z",
899
+ branch: "M6 4v10M6 14a3 3 0 1 0 0 6 3 3 0 0 0 0-6zM18 4a3 3 0 1 0 0 6 3 3 0 0 0 0-6zM18 10c0 4-6 3-11 6",
900
+ lock: "M6 11h12v9H6zM8.5 11V8a3.5 3.5 0 0 1 7 0v3M12 15v2",
901
+ more: "M5 11a1 1 0 1 0 0 2 1 1 0 0 0 0-2zM12 11a1 1 0 1 0 0 2 1 1 0 0 0 0-2zM19 11a1 1 0 1 0 0 2 1 1 0 0 0 0-2z",
902
+ archive: "M4 5h16v4H4zM6 9v10h12V9M10 13h4"
903
+ };
904
+ function isIconName(name) {
905
+ return typeof name === "string" && name in ICON_PATHS;
906
+ }
907
+ function Icon(props) {
908
+ return /* @__PURE__ */ jsx("svg", {
909
+ "aria-hidden": true,
910
+ viewBox: "0 0 24 24",
911
+ fill: "none",
912
+ stroke: "currentColor",
913
+ strokeWidth: 1.75,
914
+ strokeLinecap: "round",
915
+ strokeLinejoin: "round",
916
+ width: props.size,
917
+ height: props.size,
918
+ className: `shrink-0 ${props.size ? "" : "h-4 w-4"} ${props.className ?? ""}`,
919
+ children: /* @__PURE__ */ jsx("path", { d: ICON_PATHS[props.name] })
920
+ });
921
+ }
922
+ //#endregion
923
+ //#region editors/shared/controls.tsx
924
+ const FOCUS_RING = "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/40";
925
+ const BUTTON_SIZE = {
926
+ sm: "h-7 gap-1 rounded-md px-2 text-xs",
927
+ md: "h-8 gap-1.5 rounded-md px-3 text-[13px]"
928
+ };
929
+ const BUTTON_VARIANT = {
930
+ primary: "bg-primary text-primary-foreground hover:opacity-90",
931
+ secondary: "border border-solid border-foreground/15 bg-card text-foreground hover:bg-accent",
932
+ ghost: "text-muted-foreground hover:bg-accent hover:text-foreground",
933
+ danger: "text-wf-fail hover:bg-wf-fail/10",
934
+ destructive: "bg-wf-fail text-white hover:opacity-90"
935
+ };
936
+ function Button(props) {
937
+ const { variant = "secondary", size = "md", className = "", ...rest } = props;
938
+ return /* @__PURE__ */ jsx("button", {
939
+ type: "button",
940
+ className: `inline-flex shrink-0 items-center font-medium transition-colors disabled:pointer-events-none disabled:opacity-50 ${FOCUS_RING} ${BUTTON_SIZE[size]} ${BUTTON_VARIANT[variant]} ${className}`,
941
+ ...rest
942
+ });
943
+ }
944
+ function IconButton(props) {
945
+ const { icon, label, active, className = "", ...rest } = props;
946
+ return /* @__PURE__ */ jsx("button", {
947
+ type: "button",
948
+ title: label,
949
+ "aria-label": label,
950
+ className: `inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md transition-colors disabled:pointer-events-none disabled:opacity-50 ${FOCUS_RING} ${active ? "bg-wf-run/10 text-wf-run" : "text-muted-foreground hover:bg-accent hover:text-foreground"} ${className}`,
951
+ ...rest,
952
+ children: /* @__PURE__ */ jsx(Icon, {
953
+ name: icon,
954
+ className: "h-3.5 w-3.5"
955
+ })
956
+ });
957
+ }
958
+ const inputClass = "w-full rounded-md border border-solid border-foreground/15 bg-card px-2.5 text-[13px] text-foreground placeholder:text-muted-foreground/70 transition-colors hover:border-foreground/25 focus:border-ring focus:outline-none focus:ring-2 focus:ring-ring/25 disabled:cursor-not-allowed disabled:opacity-60";
959
+ const textInputClass = `${inputClass} h-9`;
960
+ const textAreaClass = `${inputClass} min-h-20 py-2 leading-relaxed`;
961
+ const invalidClass = "border-wf-warn/70 hover:border-wf-warn";
962
+ /** Label row above a control: name, optional marker, and a trailing action. */
963
+ function FieldLabel(props) {
964
+ const LabelTag = props.htmlFor ? "label" : "span";
965
+ return /* @__PURE__ */ jsxs("div", {
966
+ className: "mb-1.5 flex min-h-6 items-center justify-between gap-2",
967
+ children: [/* @__PURE__ */ jsxs(LabelTag, {
968
+ htmlFor: props.htmlFor,
969
+ className: "flex min-w-0 items-baseline gap-1.5 text-[13px] font-medium text-foreground",
970
+ children: [
971
+ /* @__PURE__ */ jsx("span", {
972
+ className: "truncate",
973
+ children: props.label
974
+ }),
975
+ props.optional ? /* @__PURE__ */ jsx("span", {
976
+ className: "shrink-0 text-xs font-normal text-muted-foreground",
977
+ children: "Optional"
978
+ }) : null,
979
+ props.needsValue ? /* @__PURE__ */ jsx("span", {
980
+ className: "shrink-0 text-xs font-normal text-wf-warn",
981
+ children: "Needs a value"
982
+ }) : null
983
+ ]
984
+ }), props.action ? /* @__PURE__ */ jsx("span", {
985
+ className: "flex shrink-0 items-center gap-0.5",
986
+ children: props.action
987
+ }) : null]
988
+ });
989
+ }
990
+ const LONG_HINT = 140;
991
+ /** Help text under a control; long piece descriptions fold to two lines. */
992
+ function Hint(props) {
993
+ const [open, setOpen] = useState(false);
994
+ const text = props.text;
995
+ if (text !== void 0) {
996
+ if (!text.trim()) return null;
997
+ const long = text.length > LONG_HINT;
998
+ return /* @__PURE__ */ jsxs("p", {
999
+ className: "mt-1.5 text-xs leading-relaxed text-muted-foreground",
1000
+ children: [/* @__PURE__ */ jsx("span", {
1001
+ className: long && !open ? "line-clamp-2" : void 0,
1002
+ children: text
1003
+ }), long ? /* @__PURE__ */ jsx("button", {
1004
+ type: "button",
1005
+ className: "mt-0.5 block font-medium text-foreground/70 hover:text-foreground",
1006
+ onClick: () => setOpen((value) => !value),
1007
+ children: open ? "Show less" : "Show more"
1008
+ }) : null]
1009
+ });
1010
+ }
1011
+ return /* @__PURE__ */ jsx("p", {
1012
+ className: "mt-1.5 text-xs leading-relaxed text-muted-foreground",
1013
+ children: props.children
1014
+ });
1015
+ }
1016
+ function FieldError(props) {
1017
+ if (!props.children) return null;
1018
+ return /* @__PURE__ */ jsx("p", {
1019
+ className: "mt-1.5 text-xs text-wf-fail",
1020
+ children: props.children
1021
+ });
1022
+ }
1023
+ function Switch(props) {
1024
+ const id = useId();
1025
+ return /* @__PURE__ */ jsxs("div", {
1026
+ className: "flex items-start justify-between gap-4",
1027
+ children: [/* @__PURE__ */ jsxs("label", {
1028
+ htmlFor: id,
1029
+ className: "min-w-0",
1030
+ children: [/* @__PURE__ */ jsx("span", {
1031
+ className: "block text-[13px] font-medium text-foreground",
1032
+ children: props.label
1033
+ }), props.description ? /* @__PURE__ */ jsx(Hint, { text: props.description }) : null]
1034
+ }), /* @__PURE__ */ jsx("button", {
1035
+ id,
1036
+ type: "button",
1037
+ role: "switch",
1038
+ "aria-checked": props.checked,
1039
+ disabled: props.disabled,
1040
+ className: `relative mt-0.5 inline-flex h-5 w-9 shrink-0 items-center rounded-full transition-colors disabled:opacity-50 ${FOCUS_RING} ${props.checked ? "bg-primary" : "bg-foreground/20"}`,
1041
+ onClick: () => props.onChange(!props.checked),
1042
+ children: /* @__PURE__ */ jsx("span", { className: `inline-block h-4 w-4 rounded-full bg-card shadow-sm transition-transform ${props.checked ? "translate-x-[18px]" : "translate-x-0.5"}` })
1043
+ })]
1044
+ });
1045
+ }
1046
+ function Toggle(props) {
1047
+ return /* @__PURE__ */ jsx("button", {
1048
+ type: "button",
1049
+ role: "switch",
1050
+ "aria-checked": props.checked,
1051
+ "aria-label": props.label,
1052
+ disabled: props.disabled,
1053
+ className: `relative inline-flex h-5 w-9 shrink-0 items-center rounded-full transition-colors disabled:cursor-not-allowed disabled:opacity-50 ${FOCUS_RING} ${props.checked ? "bg-wf-ok" : "bg-foreground/20"}`,
1054
+ onClick: (event) => {
1055
+ event.stopPropagation();
1056
+ props.onChange(!props.checked);
1057
+ },
1058
+ children: /* @__PURE__ */ jsx("span", { className: `inline-block h-4 w-4 rounded-full bg-card shadow-sm transition-transform ${props.checked ? "translate-x-[18px]" : "translate-x-0.5"}` })
1059
+ });
1060
+ }
1061
+ function Tooltip(props) {
1062
+ if (props.enabled === false) return /* @__PURE__ */ jsx(Fragment$1, { children: props.children });
1063
+ const place = props.side === "left" ? "right-full top-1/2 -translate-y-1/2 pr-1.5" : `top-full pt-1.5 ${props.align === "start" ? "left-0" : "right-0"}`;
1064
+ return /* @__PURE__ */ jsxs("span", {
1065
+ className: "group/tip relative inline-flex",
1066
+ children: [props.children, /* @__PURE__ */ jsx("span", {
1067
+ className: `invisible absolute z-50 opacity-0 transition-opacity group-focus-within/tip:visible group-focus-within/tip:opacity-100 group-hover/tip:visible group-hover/tip:opacity-100 ${place}`,
1068
+ children: /* @__PURE__ */ jsx("span", {
1069
+ role: "tooltip",
1070
+ className: "block w-max max-w-64 rounded-md border border-solid border-foreground/10 bg-card px-2.5 py-1.5 text-xs text-foreground shadow-lg",
1071
+ children: props.content
1072
+ })
1073
+ })]
1074
+ });
1075
+ }
1076
+ function Tabs(props) {
1077
+ return /* @__PURE__ */ jsx("div", {
1078
+ role: "tablist",
1079
+ className: "flex gap-4",
1080
+ children: props.tabs.map((tab) => {
1081
+ const selected = tab.value === props.value;
1082
+ return /* @__PURE__ */ jsxs("button", {
1083
+ type: "button",
1084
+ role: "tab",
1085
+ "aria-selected": selected,
1086
+ className: `-mb-px flex items-center gap-1.5 border-b-2 border-solid pb-2 text-[13px] font-medium transition-colors ${FOCUS_RING} ${selected ? "border-foreground text-foreground" : "border-transparent text-muted-foreground hover:text-foreground"}`,
1087
+ onClick: () => props.onChange(tab.value),
1088
+ children: [tab.label, tab.badge]
1089
+ }, tab.value);
1090
+ })
1091
+ });
1092
+ }
1093
+ /** Two or three short, mutually exclusive choices shown side by side. */
1094
+ function Segmented(props) {
1095
+ return /* @__PURE__ */ jsx("div", {
1096
+ role: "radiogroup",
1097
+ className: `flex h-9 w-full items-center gap-0.5 rounded-md bg-muted p-0.5 ${props.invalid ? "ring-1 ring-wf-warn/60" : ""}`,
1098
+ children: props.options.map((option) => {
1099
+ const selected = option.value === props.value;
1100
+ return /* @__PURE__ */ jsx("button", {
1101
+ type: "button",
1102
+ role: "radio",
1103
+ "aria-checked": selected,
1104
+ className: `h-8 min-w-0 flex-1 truncate rounded px-2 text-[13px] transition-colors ${FOCUS_RING} ${selected ? "bg-card font-medium text-foreground shadow-sm" : "text-muted-foreground hover:text-foreground"}`,
1105
+ onClick: () => props.onChange(option.value),
1106
+ children: option.label
1107
+ }, option.value);
1108
+ })
1109
+ });
1110
+ }
1111
+ const SEARCH_THRESHOLD = 7;
1112
+ function Select(props) {
1113
+ const [open, setOpen] = useState(false);
1114
+ const [query, setQuery] = useState("");
1115
+ const [active, setActive] = useState(0);
1116
+ const triggerRef = useRef(null);
1117
+ const popoverRef = useRef(null);
1118
+ const searchRef = useRef(null);
1119
+ const listId = useId();
1120
+ const [position, setPosition] = useState(null);
1121
+ const selected = props.multiple ? props.value : props.value ? [props.value] : [];
1122
+ const selectedSet = new Set(selected);
1123
+ const searchable = props.searchable || Boolean(props.onQueryChange) || props.options.length > SEARCH_THRESHOLD;
1124
+ const needle = query.trim().toLowerCase();
1125
+ const serverSide = Boolean(props.onQueryChange);
1126
+ const visible = useMemo(() => needle && !serverSide ? props.options.filter((option) => `${option.label} ${option.description ?? ""}`.toLowerCase().includes(needle)) : props.options, [
1127
+ needle,
1128
+ props.options,
1129
+ serverSide
1130
+ ]);
1131
+ const onQueryChange = props.onQueryChange;
1132
+ const dismiss = () => {
1133
+ setOpen(false);
1134
+ setQuery("");
1135
+ onQueryChange?.("");
1136
+ };
1137
+ const close = () => {
1138
+ dismiss();
1139
+ triggerRef.current?.focus();
1140
+ };
1141
+ const place = () => {
1142
+ const rect = triggerRef.current?.getBoundingClientRect();
1143
+ if (!rect) return;
1144
+ const below = window.innerHeight - rect.bottom - 8;
1145
+ const above = rect.top - 8;
1146
+ const flip = below < 240 && above > below;
1147
+ setPosition({
1148
+ left: rect.left,
1149
+ width: rect.width,
1150
+ top: flip ? void 0 : rect.bottom + 4,
1151
+ bottom: flip ? window.innerHeight - rect.top + 4 : void 0,
1152
+ maxHeight: Math.min(320, flip ? above : below)
1153
+ });
1154
+ };
1155
+ const openList = () => {
1156
+ const index = props.options.findIndex((option) => selectedSet.has(option.value));
1157
+ setActive(Math.max(0, index));
1158
+ setOpen(true);
1159
+ };
1160
+ useLayoutEffect(() => {
1161
+ if (!open) return;
1162
+ place();
1163
+ }, [open]);
1164
+ const placed = position !== null;
1165
+ useEffect(() => {
1166
+ if (open && placed && searchable) searchRef.current?.focus();
1167
+ }, [
1168
+ open,
1169
+ placed,
1170
+ searchable
1171
+ ]);
1172
+ useEffect(() => {
1173
+ if (!open) return;
1174
+ const onPointer = (event) => {
1175
+ const target = event.target;
1176
+ if (!popoverRef.current?.contains(target) && !triggerRef.current?.contains(target)) {
1177
+ setOpen(false);
1178
+ setQuery("");
1179
+ onQueryChange?.("");
1180
+ }
1181
+ };
1182
+ window.addEventListener("mousedown", onPointer);
1183
+ window.addEventListener("resize", place);
1184
+ window.addEventListener("scroll", place, true);
1185
+ return () => {
1186
+ window.removeEventListener("mousedown", onPointer);
1187
+ window.removeEventListener("resize", place);
1188
+ window.removeEventListener("scroll", place, true);
1189
+ };
1190
+ }, [
1191
+ open,
1192
+ searchable,
1193
+ onQueryChange
1194
+ ]);
1195
+ useEffect(() => {
1196
+ popoverRef.current?.querySelector(`[data-index="${active}"]`)?.scrollIntoView({ block: "nearest" });
1197
+ }, [active]);
1198
+ const choose = (option) => {
1199
+ if (option.disabled) return;
1200
+ if (props.multiple) {
1201
+ props.onChange(selectedSet.has(option.value) ? props.value.filter((value) => value !== option.value) : [...props.value, option.value]);
1202
+ return;
1203
+ }
1204
+ props.onChange(option.value);
1205
+ close();
1206
+ };
1207
+ const onListKey = (event) => {
1208
+ if (event.key === "ArrowDown") {
1209
+ event.preventDefault();
1210
+ setActive((index) => Math.min(visible.length - 1, index + 1));
1211
+ } else if (event.key === "ArrowUp") {
1212
+ event.preventDefault();
1213
+ setActive((index) => Math.max(0, index - 1));
1214
+ } else if (event.key === "Enter") {
1215
+ event.preventDefault();
1216
+ const option = visible[active];
1217
+ if (option) choose(option);
1218
+ } else if (event.key === "Escape") {
1219
+ event.preventDefault();
1220
+ close();
1221
+ } else if (event.key === "Tab") dismiss();
1222
+ };
1223
+ const labels = props.options.filter((option) => selectedSet.has(option.value)).map((option) => option.label);
1224
+ const unknown = selected.filter((value) => !props.options.some((option) => option.value === value));
1225
+ const shown = [...labels, ...unknown];
1226
+ const selectedIcon = props.multiple ? void 0 : props.options.find((option) => option.value === props.value)?.icon;
1227
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsxs("button", {
1228
+ ref: triggerRef,
1229
+ id: props.id,
1230
+ "aria-label": props.ariaLabel,
1231
+ type: "button",
1232
+ role: "combobox",
1233
+ "aria-expanded": open,
1234
+ "aria-controls": open ? listId : void 0,
1235
+ "aria-activedescendant": open && visible.length > 0 ? `${listId}-${active}` : void 0,
1236
+ "aria-haspopup": "listbox",
1237
+ disabled: props.disabled,
1238
+ className: `${textInputClass} flex items-center gap-2 text-left ${props.invalid ? invalidClass : ""} ${open ? "border-ring ring-2 ring-ring/25" : ""}`,
1239
+ onClick: () => open ? close() : openList(),
1240
+ onKeyDown: (event) => {
1241
+ if (open) {
1242
+ onListKey(event);
1243
+ return;
1244
+ }
1245
+ if (event.key === "ArrowDown" || event.key === "Enter" || event.key === " ") {
1246
+ event.preventDefault();
1247
+ openList();
1248
+ }
1249
+ },
1250
+ children: [
1251
+ selectedIcon,
1252
+ /* @__PURE__ */ jsx("span", {
1253
+ className: `min-w-0 flex-1 truncate ${shown.length ? "" : "text-muted-foreground/70"}`,
1254
+ children: shown.length > 0 ? shown.join(", ") : props.loading ? "Loading…" : props.placeholder ?? "Choose…"
1255
+ }),
1256
+ props.multiple && shown.length > 1 ? /* @__PURE__ */ jsx("span", {
1257
+ className: "shrink-0 rounded bg-muted px-1.5 text-[11px] tabular-nums text-muted-foreground",
1258
+ children: shown.length
1259
+ }) : null,
1260
+ /* @__PURE__ */ jsx(Icon, {
1261
+ name: "chevronDown",
1262
+ className: `h-3.5 w-3.5 text-muted-foreground transition-transform ${open ? "rotate-180" : ""}`
1263
+ })
1264
+ ]
1265
+ }), open && position ? createPortal(/* @__PURE__ */ jsxs("div", {
1266
+ ref: popoverRef,
1267
+ tabIndex: -1,
1268
+ className: "workflow-select-popover fixed flex flex-col overflow-hidden rounded-lg border border-solid border-foreground/10 bg-popover text-popover-foreground shadow-lg outline-none",
1269
+ style: {
1270
+ left: position.left,
1271
+ width: Math.max(position.width, 220),
1272
+ top: position.top,
1273
+ bottom: position.bottom,
1274
+ maxHeight: position.maxHeight
1275
+ },
1276
+ onKeyDown: onListKey,
1277
+ children: [
1278
+ searchable || props.onRefresh ? /* @__PURE__ */ jsxs("div", {
1279
+ className: "flex items-center gap-1 border-b border-solid border-foreground/10 px-2",
1280
+ children: [searchable ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(Icon, {
1281
+ name: "search",
1282
+ className: "h-3.5 w-3.5 text-muted-foreground"
1283
+ }), /* @__PURE__ */ jsx("input", {
1284
+ ref: searchRef,
1285
+ className: "h-9 min-w-0 flex-1 bg-transparent text-[13px] text-foreground placeholder:text-muted-foreground/70 focus:outline-none",
1286
+ placeholder: "Search",
1287
+ value: query,
1288
+ onChange: (event) => {
1289
+ setQuery(event.target.value);
1290
+ setActive(0);
1291
+ props.onQueryChange?.(event.target.value);
1292
+ }
1293
+ })] }) : /* @__PURE__ */ jsx("span", { className: "h-9 flex-1" }), props.onRefresh ? /* @__PURE__ */ jsx(IconButton, {
1294
+ icon: "retry",
1295
+ label: "Reload options",
1296
+ disabled: props.loading,
1297
+ onClick: props.onRefresh
1298
+ }) : null]
1299
+ }) : null,
1300
+ /* @__PURE__ */ jsx("div", {
1301
+ id: listId,
1302
+ role: "listbox",
1303
+ "aria-multiselectable": props.multiple || void 0,
1304
+ className: "min-h-0 flex-1 overflow-y-auto p-1",
1305
+ children: props.loading && props.options.length === 0 ? /* @__PURE__ */ jsx("p", {
1306
+ className: "px-2 py-2 text-[13px] text-muted-foreground",
1307
+ children: "Loading options…"
1308
+ }) : visible.length === 0 ? /* @__PURE__ */ jsx("p", {
1309
+ className: "px-2 py-2 text-[13px] text-muted-foreground",
1310
+ children: needle ? "Nothing matches." : props.emptyText ?? "No options."
1311
+ }) : visible.map((option, index) => {
1312
+ const isSelected = selectedSet.has(option.value);
1313
+ return /* @__PURE__ */ jsxs("div", {
1314
+ id: `${listId}-${index}`,
1315
+ role: "option",
1316
+ "aria-selected": isSelected,
1317
+ "aria-disabled": option.disabled || void 0,
1318
+ "data-index": index,
1319
+ className: `flex cursor-pointer items-center gap-2 rounded-md px-2 py-1.5 text-[13px] ${index === active ? "bg-accent" : ""} ${option.disabled ? "cursor-not-allowed opacity-50" : ""}`,
1320
+ onMouseEnter: () => setActive(index),
1321
+ onMouseDown: (event) => {
1322
+ event.preventDefault();
1323
+ choose(option);
1324
+ },
1325
+ children: [
1326
+ props.multiple ? /* @__PURE__ */ jsx("span", {
1327
+ className: `flex h-4 w-4 shrink-0 items-center justify-center rounded border border-solid ${isSelected ? "border-primary bg-primary text-primary-foreground" : "border-foreground/25"}`,
1328
+ children: isSelected ? /* @__PURE__ */ jsx(Icon, {
1329
+ name: "check",
1330
+ className: "h-3 w-3"
1331
+ }) : null
1332
+ }) : null,
1333
+ option.icon,
1334
+ /* @__PURE__ */ jsxs("span", {
1335
+ className: "min-w-0 flex-1",
1336
+ children: [/* @__PURE__ */ jsx("span", {
1337
+ className: "block truncate",
1338
+ children: option.label
1339
+ }), option.description ? /* @__PURE__ */ jsx("span", {
1340
+ className: "block truncate text-xs text-muted-foreground",
1341
+ children: option.description
1342
+ }) : null]
1343
+ }),
1344
+ !props.multiple && isSelected ? /* @__PURE__ */ jsx(Icon, {
1345
+ name: "check",
1346
+ className: "h-3.5 w-3.5 text-foreground"
1347
+ }) : null
1348
+ ]
1349
+ }, option.value);
1350
+ })
1351
+ }),
1352
+ props.actions?.length ? /* @__PURE__ */ jsx("div", {
1353
+ className: "border-t border-solid border-foreground/10 p-1",
1354
+ children: props.actions.map((action) => /* @__PURE__ */ jsxs("button", {
1355
+ type: "button",
1356
+ className: "flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-[13px] text-muted-foreground hover:bg-accent hover:text-foreground",
1357
+ onMouseDown: (event) => {
1358
+ event.preventDefault();
1359
+ dismiss();
1360
+ action.onSelect();
1361
+ },
1362
+ children: [action.icon ? /* @__PURE__ */ jsx(Icon, {
1363
+ name: action.icon,
1364
+ className: "h-3.5 w-3.5"
1365
+ }) : null, action.label]
1366
+ }, action.label))
1367
+ }) : null,
1368
+ !props.multiple && props.clearable && props.value ? /* @__PURE__ */ jsx("div", {
1369
+ className: "border-t border-solid border-foreground/10 p-1",
1370
+ children: /* @__PURE__ */ jsxs("button", {
1371
+ type: "button",
1372
+ className: "flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-[13px] text-muted-foreground hover:bg-accent hover:text-foreground",
1373
+ onMouseDown: (event) => {
1374
+ event.preventDefault();
1375
+ props.onChange("");
1376
+ close();
1377
+ },
1378
+ children: [/* @__PURE__ */ jsx(Icon, {
1379
+ name: "close",
1380
+ className: "h-3.5 w-3.5"
1381
+ }), "Clear selection"]
1382
+ })
1383
+ }) : null
1384
+ ]
1385
+ }), document.body) : null] });
1386
+ }
1387
+ function shouldPersistQuery(queryKey) {
1388
+ if (typeof queryKey[0] !== "string") return false;
1389
+ const kind = queryKind(queryKey);
1390
+ if (kind === "catalog") return queryKey.length === 2;
1391
+ if (kind === "form") {
1392
+ const block = queryKey[2];
1393
+ return Array.isArray(block) && block[0] !== "@powerhousedao/piece-core";
1394
+ }
1395
+ return false;
1396
+ }
1397
+ function persistRuntimeQueries(queryClient, url, store, now = Date.now) {
1398
+ if (!store) return {
1399
+ ready: Promise.resolve(),
1400
+ dispose: () => void 0
1401
+ };
1402
+ return {
1403
+ ready: hydrate(queryClient, url, store, now()),
1404
+ dispose: queryClient.getQueryCache().subscribe((event) => {
1405
+ if (event.type !== "updated" || event.action.type !== "success") return;
1406
+ if (event.action.manual) return;
1407
+ const { queryKey, state } = event.query;
1408
+ if (!shouldPersistQuery(queryKey) || state.data === void 0) return;
1409
+ store.save({
1410
+ id: JSON.stringify(queryKey),
1411
+ url: queryKey[0],
1412
+ queryKey,
1413
+ data: state.data,
1414
+ updatedAt: state.dataUpdatedAt,
1415
+ version: 1
1416
+ }).catch(() => void 0);
1417
+ })
1418
+ };
1419
+ }
1420
+ async function hydrate(queryClient, url, store, at) {
1421
+ let entries;
1422
+ try {
1423
+ entries = await store.load(url);
1424
+ } catch {
1425
+ return;
1426
+ }
1427
+ for (const entry of entries) {
1428
+ if (entry.version !== 1 || at - entry.updatedAt > 6048e5 || !shouldPersistQuery(entry.queryKey)) {
1429
+ store.remove(entry.id).catch(() => void 0);
1430
+ continue;
1431
+ }
1432
+ const current = queryClient.getQueryState(entry.queryKey);
1433
+ if (current && current.dataUpdatedAt >= entry.updatedAt) continue;
1434
+ queryClient.setQueryData(entry.queryKey, entry.data, { updatedAt: entry.updatedAt });
1435
+ }
1436
+ }
1437
+ const DB_NAME = "ph-workflow-runtime-cache";
1438
+ const STORE = "queries";
1439
+ function request(req) {
1440
+ return new Promise((resolve, reject) => {
1441
+ req.onsuccess = () => resolve(req.result);
1442
+ req.onerror = () => reject(req.error ?? /* @__PURE__ */ new Error("IndexedDB request failed"));
1443
+ });
1444
+ }
1445
+ function openIdbCacheStore() {
1446
+ const idb = globalThis.indexedDB;
1447
+ if (!idb) return null;
1448
+ let db;
1449
+ const open = () => {
1450
+ db ??= new Promise((resolve, reject) => {
1451
+ const req = idb.open(DB_NAME, 1);
1452
+ req.onupgradeneeded = () => {
1453
+ req.result.createObjectStore(STORE, { keyPath: "id" }).createIndex("url", "url");
1454
+ };
1455
+ req.onsuccess = () => resolve(req.result);
1456
+ req.onerror = () => reject(req.error ?? /* @__PURE__ */ new Error("IndexedDB unavailable"));
1457
+ req.onblocked = () => reject(/* @__PURE__ */ new Error("IndexedDB blocked"));
1458
+ });
1459
+ db.catch(() => db = void 0);
1460
+ return db;
1461
+ };
1462
+ const withStore = async (mode, run) => {
1463
+ return request(run((await open()).transaction(STORE, mode).objectStore(STORE)));
1464
+ };
1465
+ return {
1466
+ load: (url) => withStore("readonly", (store) => store.index("url").getAll(url)),
1467
+ save: (entry) => withStore("readwrite", (store) => store.put(entry)).then(() => void 0),
1468
+ remove: (id) => withStore("readwrite", (store) => store.delete(id)).then(() => void 0)
1469
+ };
1470
+ }
1471
+ //#endregion
1472
+ //#region editors/workflow-editor/ui/piece-source.ts
1473
+ function blockUnavailable(entry) {
1474
+ if (entry.unsupported) return entry.unsupported;
1475
+ if (entry.kind !== "trigger") return void 0;
1476
+ const strategy = checkTriggerStrategy(entry.strategy);
1477
+ return "issue" in strategy ? strategy.issue : void 0;
1478
+ }
1479
+ const PieceSourceContext = createContext(void 0);
1480
+ const PieceSourceProvider = PieceSourceContext.Provider;
1481
+ function usePieceSource() {
1482
+ return useContext(PieceSourceContext);
1483
+ }
1484
+ //#endregion
1485
+ //#region editors/workflow-editor/use-runtime-url.ts
1486
+ const SUBGRAPH_NAME = "workflow-runtime";
1487
+ function baseFromChannelUrl(channelUrl) {
1488
+ try {
1489
+ const url = new URL(channelUrl);
1490
+ url.search = "";
1491
+ url.hash = "";
1492
+ url.pathname = url.pathname.replace(/\/r\/?$/, "");
1493
+ return url.toString();
1494
+ } catch {
1495
+ return;
1496
+ }
1497
+ }
1498
+ function useWorkflowRuntimeUrl() {
1499
+ const [drive] = useSelectedDriveSafe();
1500
+ const remotes = useSyncList();
1501
+ const defaultDrivesUrl = useDefaultDrivesUrl();
1502
+ const driveId = drive?.header.id;
1503
+ return useMemo(() => {
1504
+ let base;
1505
+ if (driveId) {
1506
+ const channelUrl = (remotes.find((entry) => entry.meta.collectionId.equals(DriveCollectionId.forDrive(driveId)))?.channel)?.config.url;
1507
+ if (typeof channelUrl === "string") base = baseFromChannelUrl(channelUrl);
1508
+ }
1509
+ if (!base && defaultDrivesUrl) try {
1510
+ base = parseDriveUrl(defaultDrivesUrl).graphqlEndpoint.replace(/\/r$/, "");
1511
+ } catch {}
1512
+ return subgraphUrlFromGraphqlUrl(base ?? DEFAULT_SWITCHBOARD_URL, SUBGRAPH_NAME);
1513
+ }, [
1514
+ driveId,
1515
+ remotes,
1516
+ defaultDrivesUrl
1517
+ ]);
1518
+ }
1519
+ //#endregion
1520
+ //#region editors/workflow-editor/runtime-context.tsx
1521
+ const RuntimeContext = createContext(null);
1522
+ function runtimePieceSource(client, queryClient) {
1523
+ return {
1524
+ loadCatalog: () => queryClient.fetchQuery(catalogQuery(client)),
1525
+ reloadCatalog: () => queryClient.fetchQuery({
1526
+ ...catalogQuery(client),
1527
+ staleTime: 0
1528
+ }),
1529
+ loadActions: (packageName) => queryClient.fetchQuery(pieceActionsQuery(client, packageName)),
1530
+ loadTriggers: (packageName) => queryClient.fetchQuery(pieceTriggersQuery(client, packageName)),
1531
+ searchBlocks: (query, limit) => client.searchBlocks(query, limit)
1532
+ };
1533
+ }
1534
+ function RuntimeProvider(props) {
1535
+ const { url } = props;
1536
+ const [queryClient] = useState(createRuntimeQueryClient);
1537
+ const [store] = useState(() => props.store === void 0 ? openIdbCacheStore() : props.store);
1538
+ const client = useMemo(() => createRuntimeClient(url), [url]);
1539
+ useEffect(() => persistRuntimeQueries(queryClient, url, store).dispose, [
1540
+ queryClient,
1541
+ url,
1542
+ store
1543
+ ]);
1544
+ const value = useMemo(() => ({
1545
+ client,
1546
+ queryClient
1547
+ }), [client, queryClient]);
1548
+ const pieceSource = useMemo(() => runtimePieceSource(client, queryClient), [client, queryClient]);
1549
+ return /* @__PURE__ */ jsx(RuntimeContext.Provider, {
1550
+ value,
1551
+ children: /* @__PURE__ */ jsx(PieceSourceProvider, {
1552
+ value: pieceSource,
1553
+ children: props.children
1554
+ })
1555
+ });
1556
+ }
1557
+ function WorkflowRuntimeProvider(props) {
1558
+ const url = useWorkflowRuntimeUrl();
1559
+ return /* @__PURE__ */ jsx(RuntimeProvider, {
1560
+ url,
1561
+ children: props.children
1562
+ });
1563
+ }
1564
+ function useRuntime() {
1565
+ const context = useContext(RuntimeContext);
1566
+ if (!context) throw new Error("useRuntime needs a RuntimeProvider");
1567
+ return context;
1568
+ }
1569
+ function usePieceCatalog() {
1570
+ const { client, queryClient } = useRuntime();
1571
+ return useQuery(catalogQuery(client), queryClient);
1572
+ }
1573
+ function useRunsQuery(scope, options = {}) {
1574
+ const { client, queryClient } = useRuntime();
1575
+ return useQuery({
1576
+ ...runsQuery(client, scope),
1577
+ enabled: options.active ?? true,
1578
+ refetchInterval: options.pollMs ?? false
1579
+ }, queryClient);
1580
+ }
1581
+ function useRunPagesQuery(scope, options = {}) {
1582
+ const { client, queryClient } = useRuntime();
1583
+ return useInfiniteQuery({
1584
+ ...runPagesQuery(client, scope),
1585
+ enabled: options.active ?? true,
1586
+ refetchInterval: options.pollMs ?? false
1587
+ }, queryClient);
1588
+ }
1589
+ function useRunQuery(runId, options = {}) {
1590
+ const { client, queryClient } = useRuntime();
1591
+ return useQuery({
1592
+ ...runQuery(client, runId),
1593
+ refetchInterval: (query) => options.pollMs && query.state.data?.endedAt == null ? options.pollMs : false
1594
+ }, queryClient);
1595
+ }
1596
+ function useSecretStat(ref, enabled) {
1597
+ const { client, queryClient } = useRuntime();
1598
+ const query = useQuery({
1599
+ ...secretStatQuery(client, ref),
1600
+ enabled,
1601
+ gcTime: 0
1602
+ }, queryClient);
1603
+ if (!enabled) return null;
1604
+ if (query.status === "pending") return void 0;
1605
+ return query.status === "error" ? null : query.data;
1606
+ }
1607
+ function useOAuthRedirectUri() {
1608
+ const { client, queryClient } = useRuntime();
1609
+ return useQuery({
1610
+ queryKey: [client.url, "oauthRedirectUri"],
1611
+ queryFn: () => client.fetchOAuthRedirectUri(),
1612
+ staleTime: Infinity
1613
+ }, queryClient);
1614
+ }
1615
+ function useOAuthAttempt(state) {
1616
+ const { client, queryClient } = useRuntime();
1617
+ const query = useQuery({
1618
+ queryKey: [
1619
+ client.url,
1620
+ "oauthAttempt",
1621
+ state
1622
+ ],
1623
+ queryFn: () => client.fetchOAuthAttempt(state),
1624
+ enabled: state !== null,
1625
+ gcTime: 0,
1626
+ refetchInterval: (current) => {
1627
+ if (current.state.status === "error") return false;
1628
+ const data = current.state.data;
1629
+ if (data === null) return false;
1630
+ return data?.status === "OK" || data?.status === "ERROR" ? false : 1e3;
1631
+ }
1632
+ }, queryClient);
1633
+ if (state === null || query.isError) return null;
1634
+ return query.data;
1635
+ }
1636
+ function useRuntimeActions() {
1637
+ const { client, queryClient } = useRuntime();
1638
+ return useMemo(() => {
1639
+ const invalidate = (queryKey) => void queryClient.invalidateQueries({ queryKey });
1640
+ const runsChanged = () => {
1641
+ invalidate(runtimeKeys.allRuns(client.url));
1642
+ invalidate([client.url, "latestRun"]);
1643
+ };
1644
+ const secretSaved = (stat) => {
1645
+ queryClient.setQueryData(runtimeKeys.secret(client.url, stat.ref), stat);
1646
+ return stat;
1647
+ };
1648
+ return {
1649
+ fireWorkflow: (workflowId, payload) => client.fireWorkflow(workflowId, payload).finally(runsChanged),
1650
+ rerunRun: (runId) => client.rerunRun(runId).finally(runsChanged),
1651
+ createSecret: (value, label) => client.createSecret(value, label).then(secretSaved),
1652
+ rotateSecret: (ref, value) => client.rotateSecret(ref, value).then(secretSaved),
1653
+ checkConnection: (connectionId) => client.checkConnection(connectionId).finally(() => invalidate(runtimeKeys.connections(client.url))),
1654
+ connectionsChanged: () => invalidate(runtimeKeys.connections(client.url)),
1655
+ startOAuth: (connectionId, options) => client.startOAuth(connectionId, options)
1656
+ };
1657
+ }, [client, queryClient]);
1658
+ }
1659
+ //#endregion
1660
+ //#region editors/workflow-studio/components/run-format.ts
1661
+ const RUN_STATUSES = [
1662
+ "RUNNING",
1663
+ "SUCCEEDED",
1664
+ "FAILED"
1665
+ ];
1666
+ const TONE_TEXT = {
1667
+ ok: "text-wf-ok",
1668
+ fail: "text-wf-fail",
1669
+ warn: "text-wf-warn",
1670
+ run: "text-wf-run",
1671
+ idle: "text-muted-foreground"
1672
+ };
1673
+ const TONE_DOT = {
1674
+ ok: "bg-wf-ok",
1675
+ fail: "bg-wf-fail",
1676
+ warn: "bg-wf-warn",
1677
+ run: "bg-wf-run",
1678
+ idle: "bg-muted-foreground/40"
1679
+ };
1680
+ const RUN_TONE = {
1681
+ SUCCEEDED: "ok",
1682
+ FAILED: "fail",
1683
+ RUNNING: "run",
1684
+ WAITING: "run",
1685
+ PENDING: "idle",
1686
+ PARKED: "warn",
1687
+ CANCELLED: "idle"
1688
+ };
1689
+ const STEP_TONE = {
1690
+ ...RUN_TONE,
1691
+ SKIPPED: "idle",
1692
+ REPLAYED: "run"
1693
+ };
1694
+ function runTone(run) {
1695
+ if (run.status === "SUCCEEDED" && (run.warningNotes?.length ?? 0) > 0) return "warn";
1696
+ return toneOf(RUN_TONE, run.status);
1697
+ }
1698
+ function runStatusLabel(run) {
1699
+ const count = run.warningNotes?.length ?? 0;
1700
+ const label = statusLabel(run.status);
1701
+ if (run.status !== "SUCCEEDED" || count === 0) return label;
1702
+ return `${label}, ${count} ${count === 1 ? "warning" : "warnings"}`;
1703
+ }
1704
+ function workflowHealth(status, lastRunStatus, published) {
1705
+ if (!published) return {
1706
+ tone: "idle",
1707
+ hollow: true,
1708
+ label: "Not published yet"
1709
+ };
1710
+ const label = (status === "ENABLED" ? "" : `${statusLabel(status ?? "DISABLED")}, `) + (lastRunStatus ? `last run ${statusLabel(lastRunStatus).toLowerCase()}` : "not run yet");
1711
+ return {
1712
+ tone: toneOf(RUN_TONE, lastRunStatus),
1713
+ hollow: false,
1714
+ label: label.charAt(0).toUpperCase() + label.slice(1)
1715
+ };
1716
+ }
1717
+ const CONNECTION_TONE = {
1718
+ OK: "ok",
1719
+ ERROR: "fail",
1720
+ REVOKED: "fail",
1721
+ UNCONFIGURED: "warn"
1722
+ };
1723
+ function toneOf(map, status) {
1724
+ return (status ? map[status] : void 0) ?? "idle";
1725
+ }
1726
+ function statusLabel(status) {
1727
+ return status.charAt(0) + status.slice(1).toLowerCase();
1728
+ }
1729
+ function formatDuration(startedAt, endedAt) {
1730
+ if (!endedAt) return "…";
1731
+ return formatMs(new Date(endedAt).getTime() - new Date(startedAt).getTime());
1732
+ }
1733
+ function runTimeline(run) {
1734
+ const start = new Date(run.startedAt).getTime();
1735
+ const ends = run.steps.map((step) => step.endedAt ? new Date(step.endedAt).getTime() : 0).concat(run.endedAt ? new Date(run.endedAt).getTime() : 0);
1736
+ const total = Math.max(...ends) - start;
1737
+ const spans = /* @__PURE__ */ new Map();
1738
+ if (total <= 0) return spans;
1739
+ for (const step of run.steps) {
1740
+ if (!step.startedAt || !step.endedAt) continue;
1741
+ const from = new Date(step.startedAt).getTime() - start;
1742
+ const ms = new Date(step.endedAt).getTime() - new Date(step.startedAt).getTime();
1743
+ spans.set(step.stepId, {
1744
+ offset: Math.min(Math.max(from / total, 0), 1),
1745
+ width: Math.min(Math.max(ms / total, 0), 1),
1746
+ ms
1747
+ });
1748
+ }
1749
+ return spans;
1750
+ }
1751
+ function formatMs(ms) {
1752
+ if (ms < 1e3) return `${ms}ms`;
1753
+ const tenths = Math.round(ms / 100);
1754
+ if (tenths < 600) return `${(tenths / 10).toFixed(1)}s`;
1755
+ const seconds = Math.round(ms / 1e3);
1756
+ return `${Math.floor(seconds / 60)}m ${seconds % 60}s`;
1757
+ }
1758
+ function durationMs(startedAt, endedAt) {
1759
+ if (!endedAt) return null;
1760
+ return new Date(endedAt).getTime() - new Date(startedAt).getTime();
1761
+ }
1762
+ function formatWhen(startedAt) {
1763
+ const diff = Date.now() - new Date(startedAt).getTime();
1764
+ if (diff < 6e4) return "just now";
1765
+ if (diff < 36e5) return `${Math.floor(diff / 6e4)}m ago`;
1766
+ if (diff < 864e5) return `${Math.floor(diff / 36e5)}h ago`;
1767
+ return new Date(startedAt).toLocaleDateString();
1768
+ }
1769
+ function formatAbsolute(iso) {
1770
+ return new Date(iso).toLocaleString();
1771
+ }
1772
+ function formatTrigger(kind) {
1773
+ return kind.replace(/[-_]/g, " ").toLowerCase();
1774
+ }
1775
+ function runStats(runs) {
1776
+ const succeeded = runs.filter((run) => run.status === "SUCCEEDED").length;
1777
+ const failed = runs.filter((run) => run.status === "FAILED").length;
1778
+ const finished = succeeded + failed;
1779
+ return {
1780
+ total: runs.length,
1781
+ succeeded,
1782
+ failed,
1783
+ running: runs.filter((run) => run.status === "RUNNING").length,
1784
+ lastRun: runs[0],
1785
+ successRate: finished === 0 ? null : Math.round(succeeded / finished * 100)
1786
+ };
1787
+ }
1788
+ //#endregion
1789
+ //#region editors/workflow-editor/ui/block-meta.ts
1790
+ const CORE_META = {
1791
+ [blockKey(MANUAL_TRIGGER)]: {
1792
+ displayName: "Manual",
1793
+ subtitle: "Trigger",
1794
+ glyph: "▶"
1795
+ },
1796
+ [blockKey(SCHEDULE_TRIGGER)]: {
1797
+ displayName: "Schedule",
1798
+ subtitle: "Trigger",
1799
+ glyph: "◷"
1800
+ },
1801
+ [blockKey(WEBHOOK_TRIGGER)]: {
1802
+ displayName: "Webhook",
1803
+ subtitle: "Trigger",
1804
+ glyph: "⇲"
1805
+ },
1806
+ [blockKey(BRANCH_BLOCK)]: {
1807
+ displayName: "Branch",
1808
+ subtitle: "Core",
1809
+ glyph: "⑂"
1810
+ },
1811
+ [blockKey(ASSERT_BLOCK)]: {
1812
+ displayName: "Assert",
1813
+ subtitle: "Core",
1814
+ glyph: "!"
1815
+ }
1816
+ };
1817
+ function shortPieceName(packageName) {
1818
+ return packageName.split("/").pop()?.replace(/^piece-/, "") ?? "";
1819
+ }
1820
+ const pieceLogos = /* @__PURE__ */ new Map();
1821
+ const pieceNames = /* @__PURE__ */ new Map();
1822
+ const listeners = /* @__PURE__ */ new Set();
1823
+ let logoRevision = 0;
1824
+ function registerPieceLogos(entries) {
1825
+ let changed = false;
1826
+ for (const entry of entries) {
1827
+ if (!entry.name) continue;
1828
+ if (entry.displayName && pieceNames.get(entry.name) !== entry.displayName) {
1829
+ pieceNames.set(entry.name, entry.displayName);
1830
+ changed = true;
1831
+ }
1832
+ if (!entry.logoUrl || pieceLogos.get(entry.name) === entry.logoUrl) continue;
1833
+ pieceLogos.set(entry.name, entry.logoUrl);
1834
+ changed = true;
1835
+ }
1836
+ if (!changed) return;
1837
+ logoRevision += 1;
1838
+ for (const listener of listeners) listener();
1839
+ }
1840
+ function pieceLogo(packageName) {
1841
+ return pieceLogos.get(packageName);
1842
+ }
1843
+ function pieceDisplayName(packageName) {
1844
+ return pieceNames.get(packageName);
1845
+ }
1846
+ const blockNames = /* @__PURE__ */ new Map();
1847
+ const namesRequested = /* @__PURE__ */ new Set();
1848
+ const namesPending = /* @__PURE__ */ new Set();
1849
+ function registerBlockNames(entries) {
1850
+ let changed = false;
1851
+ for (const entry of entries) {
1852
+ const key = blockKey(entry);
1853
+ if (!entry.displayName || blockNames.get(key) === entry.displayName) continue;
1854
+ blockNames.set(key, entry.displayName);
1855
+ changed = true;
1856
+ }
1857
+ if (!changed) return;
1858
+ logoRevision += 1;
1859
+ for (const listener of listeners) listener();
1860
+ }
1861
+ function requestBlockNames(packageName) {
1862
+ if (!namesRequested.has(packageName)) namesPending.add(packageName);
1863
+ }
1864
+ function loadPendingBlockNames(source) {
1865
+ for (const packageName of namesPending) loadBlockNames(source, packageName);
1866
+ namesPending.clear();
1867
+ }
1868
+ function loadBlockNames(source, packageName) {
1869
+ if (namesRequested.has(packageName)) return;
1870
+ namesRequested.add(packageName);
1871
+ Promise.all([source.loadActions(packageName), source.loadTriggers(packageName)]).then(([actions, triggers]) => registerBlockNames([...actions.map((entry) => ({
1872
+ ...entry,
1873
+ kind: "action"
1874
+ })), ...triggers.map((entry) => ({
1875
+ ...entry,
1876
+ kind: "trigger"
1877
+ }))])).catch(() => namesRequested.delete(packageName));
1878
+ }
1879
+ function subscribePieceLogos(listener) {
1880
+ listeners.add(listener);
1881
+ return () => listeners.delete(listener);
1882
+ }
1883
+ function pieceLogoRevision() {
1884
+ return logoRevision;
1885
+ }
1886
+ const logoMisses = /* @__PURE__ */ new Set();
1887
+ let catalogLoads = /* @__PURE__ */ new WeakMap();
1888
+ const retryTimers = /* @__PURE__ */ new Set();
1889
+ const CATALOG_RETRY_MS = 2e3;
1890
+ function notify() {
1891
+ logoRevision += 1;
1892
+ for (const listener of listeners) listener();
1893
+ }
1894
+ function scheduleRetry(state) {
1895
+ if (state.attempts >= 5) return;
1896
+ const timer = setTimeout(() => {
1897
+ retryTimers.delete(timer);
1898
+ state.load = void 0;
1899
+ notify();
1900
+ }, CATALOG_RETRY_MS * 2 ** (state.attempts - 1));
1901
+ retryTimers.add(timer);
1902
+ }
1903
+ function ensurePieceLogos(source) {
1904
+ if (!source) return Promise.resolve();
1905
+ let state = catalogLoads.get(source);
1906
+ if (!state) {
1907
+ state = { attempts: 0 };
1908
+ catalogLoads.set(source, state);
1909
+ }
1910
+ if (state.load) return state.load;
1911
+ const current = state;
1912
+ const request = current.attempts > 0 && source.reloadCatalog ? source.reloadCatalog() : source.loadCatalog();
1913
+ current.attempts += 1;
1914
+ current.load = request.then((pieces) => {
1915
+ registerPieceLogos(pieces);
1916
+ const listed = new Set(pieces.map((piece) => piece.name));
1917
+ if ([...logoMisses].some((name) => !listed.has(name) && !pieceLogos.has(name))) scheduleRetry(current);
1918
+ }, () => scheduleRetry(current));
1919
+ return current.load;
1920
+ }
1921
+ function blockMeta(block) {
1922
+ const key = blockKey(block);
1923
+ const core = CORE_META[key];
1924
+ if (core) return core;
1925
+ if (isCoreBlock(block)) return {
1926
+ displayName: titleCase(block.name),
1927
+ subtitle: "Core",
1928
+ glyph: "?"
1929
+ };
1930
+ const packageName = block.pieceName;
1931
+ const short = shortPieceName(packageName);
1932
+ const pieceLabel = pieceNames.get(packageName) ?? titleCase(short);
1933
+ const known = blockNames.get(key);
1934
+ if (!known) requestBlockNames(packageName);
1935
+ const logoUrl = pieceLogo(packageName);
1936
+ if (!logoUrl) logoMisses.add(packageName);
1937
+ return {
1938
+ displayName: known ?? titleCase(block.name),
1939
+ subtitle: block.kind === "trigger" ? `${pieceLabel} · Trigger` : pieceLabel,
1940
+ logoUrl,
1941
+ glyph: short.slice(0, 1).toUpperCase() || "?"
1942
+ };
1943
+ }
1944
+ function titleCase(value) {
1945
+ return value.replaceAll(/[-_]/g, " ").replace(/^\w/, (char) => char.toUpperCase());
1946
+ }
1947
+ function usePieceLogos() {
1948
+ const source = usePieceSource();
1949
+ const revision = useSyncExternalStore(subscribePieceLogos, pieceLogoRevision, pieceLogoRevision);
1950
+ useEffect(() => {
1951
+ ensurePieceLogos(source);
1952
+ if (source && namesPending.size > 0) loadPendingBlockNames(source);
1953
+ });
1954
+ return revision;
1955
+ }
1956
+ function useBlockMeta(block) {
1957
+ usePieceLogos();
1958
+ return blockMeta(block);
1959
+ }
1960
+ //#endregion
1961
+ //#region editors/workflow-editor/ui/validation.ts
1962
+ function isEmptyValue(value) {
1963
+ if (value === void 0 || value === null) return true;
1964
+ if (typeof value === "string") return value.trim() === "";
1965
+ if (Array.isArray(value)) return value.length === 0;
1966
+ return false;
1967
+ }
1968
+ function isPropVisible(prop, config) {
1969
+ const rule = prop.showWhen;
1970
+ if (!rule) return true;
1971
+ return rule.oneOf.includes(config[rule.prop] ?? void 0);
1972
+ }
1973
+ function asRecord(config) {
1974
+ return config !== null && typeof config === "object" && !Array.isArray(config) ? config : {};
1975
+ }
1976
+ function missingRequired(props, config) {
1977
+ const record = asRecord(config);
1978
+ return props.filter((prop) => prop.required && prop.type !== "MARKDOWN" && isPropVisible(prop, record) && isEmptyValue(record[prop.name])).map((prop) => prop.displayName);
1979
+ }
1980
+ function resolverInputFor(block, prop, config, connectionId) {
1981
+ const refreshers = (prop.refreshers ?? []).filter((name) => name !== "auth");
1982
+ return {
1983
+ block,
1984
+ propName: prop.name,
1985
+ refreshers: refreshers.map((name) => config[name] ?? null),
1986
+ connectionId: connectionId ?? null
1987
+ };
1988
+ }
1989
+ function settingFor(settings, prop) {
1990
+ return settings?.find((setting) => setting.prop === prop);
1991
+ }
1992
+ function parsePropList(result) {
1993
+ if (!Array.isArray(result)) throw new Error("Unexpected properties result");
1994
+ return result.filter((entry) => entry !== null && typeof entry === "object" && typeof entry.name === "string");
1995
+ }
1996
+ function storedSchema(settings, prop) {
1997
+ const schema = settingFor(settings, prop)?.schema;
1998
+ if (!Array.isArray(schema)) return void 0;
1999
+ return schema.filter((entry) => entry !== null && typeof entry === "object" && typeof entry.name === "string");
2000
+ }
2001
+ function stripOptions(props) {
2002
+ return props.map((prop) => {
2003
+ const { staticOptions: _options, properties, ...rest } = prop;
2004
+ return properties ? {
2005
+ ...rest,
2006
+ properties: stripOptions(properties)
2007
+ } : rest;
2008
+ });
2009
+ }
2010
+ function withSetting(settings, prop, patch) {
2011
+ const list = [...settings ?? []];
2012
+ const index = list.findIndex((setting) => setting.prop === prop);
2013
+ const current = index >= 0 ? list[index] : {
2014
+ prop,
2015
+ mode: "MANUAL"
2016
+ };
2017
+ const next = {
2018
+ prop,
2019
+ mode: patch.mode ?? current.mode,
2020
+ schema: "schema" in patch ? patch.schema ?? null : current.schema ?? null
2021
+ };
2022
+ if (index >= 0) list[index] = next;
2023
+ else list.push(next);
2024
+ return list;
2025
+ }
2026
+ function blockMissing(input) {
2027
+ if (input.skip) return [];
2028
+ const { form } = input;
2029
+ if (!form || form === "loading") return null;
2030
+ const record = asRecord(input.config);
2031
+ const missing = [];
2032
+ let unknown = false;
2033
+ if (form.auth === "required" && !input.connectionId) missing.push("Connection");
2034
+ for (const prop of form.props) {
2035
+ if (prop.type === "MARKDOWN" || !isPropVisible(prop, record)) continue;
2036
+ const value = record[prop.name];
2037
+ const bound = settingFor(input.propertySettings, prop.name)?.mode === "EXPRESSION";
2038
+ if (prop.type !== "DYNAMIC" || bound) {
2039
+ if (prop.required && isEmptyValue(value)) missing.push(prop.displayName);
2040
+ continue;
2041
+ }
2042
+ const children = input.resolveDynamic?.(resolverInputFor(input.block, prop, record, input.connectionId)) ?? storedSchema(input.propertySettings, prop.name);
2043
+ if (children === void 0) {
2044
+ unknown = true;
2045
+ continue;
2046
+ }
2047
+ missing.push(...missingRequired(children, value));
2048
+ }
2049
+ if (missing.length > 0) return missing;
2050
+ if (form.display === "schedule") {
2051
+ const issue = scheduleConfigIssue(input.config);
2052
+ if (issue) return [issue.replace(/^Schedule: /, "")];
2053
+ }
2054
+ return unknown ? null : [];
2055
+ }
2056
+ function undeclaredPortIssues(form, outgoingPorts) {
2057
+ const ports = form && form !== "loading" ? form.ports : void 0;
2058
+ if (!ports || !outgoingPorts) return [];
2059
+ return [...new Set(outgoingPorts)].filter((port) => !ports.includes(port)).map((port) => `An edge leaves on "${port}", which this block never takes`);
2060
+ }
2061
+ function workflowReadiness(blocks, hasTrigger) {
2062
+ const firstIncomplete = blocks.find((block) => block.missing && block.missing.length > 0)?.id ?? null;
2063
+ const checking = blocks.some((block) => block.missing === null);
2064
+ return {
2065
+ ready: hasTrigger && !checking && firstIncomplete === null,
2066
+ hasTrigger,
2067
+ firstIncomplete,
2068
+ checking
2069
+ };
2070
+ }
2071
+ //#endregion
2072
+ //#region editors/workflow-editor/ui/design-time.tsx
2073
+ const DesignTimeContext = createContext(null);
2074
+ function DesignTimeProvider(props) {
2075
+ const { service, queryClient, scope } = props;
2076
+ const value = useMemo(() => ({
2077
+ service,
2078
+ queryClient,
2079
+ scope
2080
+ }), [
2081
+ service,
2082
+ queryClient,
2083
+ scope
2084
+ ]);
2085
+ return /* @__PURE__ */ jsx(DesignTimeContext.Provider, {
2086
+ value,
2087
+ children: props.children
2088
+ });
2089
+ }
2090
+ function useDesignTime() {
2091
+ return useContext(DesignTimeContext)?.service;
2092
+ }
2093
+ function useDesignTimeScope() {
2094
+ const context = useContext(DesignTimeContext);
2095
+ const [detached] = useState(() => context ? null : {
2096
+ queryClient: new QueryClient(),
2097
+ scope: ""
2098
+ });
2099
+ return context ?? detached;
2100
+ }
2101
+ function messageOf(error) {
2102
+ return error instanceof Error ? error.message : String(error);
2103
+ }
2104
+ function useBlockForm(block) {
2105
+ const { service, queryClient, scope } = useDesignTimeScope();
2106
+ const query = useQuery({
2107
+ queryKey: runtimeKeys.form(scope, block),
2108
+ queryFn: () => service.getBlockForm(block),
2109
+ enabled: Boolean(service),
2110
+ staleTime: SHARED_STALE_MS
2111
+ }, queryClient);
2112
+ if (!service) return { form: null };
2113
+ if (query.data !== void 0) return { form: query.data };
2114
+ if (query.status === "error") return {
2115
+ form: null,
2116
+ error: messageOf(query.error)
2117
+ };
2118
+ return { form: "loading" };
2119
+ }
2120
+ function formQuery(service, scope, block) {
2121
+ return {
2122
+ queryKey: runtimeKeys.form(scope, block),
2123
+ queryFn: () => service.getBlockForm(block),
2124
+ staleTime: SHARED_STALE_MS
2125
+ };
2126
+ }
2127
+ function useBlockFormLoader() {
2128
+ const { service, queryClient, scope } = useDesignTimeScope();
2129
+ return useMemo(() => async (block) => {
2130
+ if (!service) return null;
2131
+ try {
2132
+ return await queryClient.fetchQuery(formQuery(service, scope, block));
2133
+ } catch {
2134
+ return null;
2135
+ }
2136
+ }, [
2137
+ service,
2138
+ queryClient,
2139
+ scope
2140
+ ]);
2141
+ }
2142
+ function useCachedBlockForm() {
2143
+ const { queryClient, scope } = useDesignTimeScope();
2144
+ return useMemo(() => (block) => queryClient.getQueryData(runtimeKeys.form(scope, block)), [queryClient, scope]);
2145
+ }
2146
+ function useBlockFormPrefetch() {
2147
+ const { service, queryClient, scope } = useDesignTimeScope();
2148
+ return useMemo(() => (block) => {
2149
+ if (!service) return;
2150
+ queryClient.prefetchQuery(formQuery(service, scope, block));
2151
+ }, [
2152
+ service,
2153
+ queryClient,
2154
+ scope
2155
+ ]);
2156
+ }
2157
+ function useBlockForms(blocks) {
2158
+ const { service, queryClient, scope } = useDesignTimeScope();
2159
+ const unique = [...new Map(blocks.map((block) => [blockRefKey(block), block])).values()];
2160
+ const results = useQueries({ queries: unique.map((block) => ({
2161
+ queryKey: runtimeKeys.form(scope, block),
2162
+ queryFn: () => service.getBlockForm(block),
2163
+ enabled: Boolean(service),
2164
+ staleTime: SHARED_STALE_MS
2165
+ })) }, queryClient);
2166
+ const forms = /* @__PURE__ */ new Map();
2167
+ unique.forEach((block, index) => {
2168
+ const query = results[index];
2169
+ forms.set(blockRefKey(block), !service ? null : query.data !== void 0 ? query.data : query.status === "error" ? null : "loading");
2170
+ });
2171
+ return forms;
2172
+ }
2173
+ function useBlockPorts(blocks) {
2174
+ const forms = useBlockForms(blocks);
2175
+ return (block) => {
2176
+ const form = forms.get(blockRefKey(block));
2177
+ return form && form !== "loading" ? form.ports : void 0;
2178
+ };
2179
+ }
2180
+ function keyHash(value) {
2181
+ try {
2182
+ return JSON.stringify(value);
2183
+ } catch {
2184
+ return String(value);
2185
+ }
2186
+ }
2187
+ function useSettled(value, ms) {
2188
+ const hash = keyHash(value);
2189
+ const latest = useRef(value);
2190
+ useEffect(() => {
2191
+ latest.current = value;
2192
+ });
2193
+ const [settled, setSettled] = useState({
2194
+ hash,
2195
+ value
2196
+ });
2197
+ useEffect(() => {
2198
+ if (hash === settled.hash) return;
2199
+ const timer = setTimeout(() => setSettled({
2200
+ hash,
2201
+ value: latest.current
2202
+ }), ms);
2203
+ return () => clearTimeout(timer);
2204
+ }, [
2205
+ hash,
2206
+ settled.hash,
2207
+ ms
2208
+ ]);
2209
+ return settled.value;
2210
+ }
2211
+ function useResolvedProp(options) {
2212
+ const { queryClient, scope } = useDesignTimeScope();
2213
+ const input = useSettled(options.input, options.debounceMs);
2214
+ const loadRef = useRef(options);
2215
+ useEffect(() => {
2216
+ loadRef.current = options;
2217
+ });
2218
+ const enabled = Boolean(options.load);
2219
+ const query = useQuery({
2220
+ queryKey: runtimeKeys[options.kind](scope, input),
2221
+ queryFn: async () => {
2222
+ const current = loadRef.current;
2223
+ if (!current.load) throw new Error("No resolver");
2224
+ return current.parse(await current.load());
2225
+ },
2226
+ enabled,
2227
+ staleTime: RESOLVER_STALE_MS
2228
+ }, queryClient);
2229
+ const reload = () => void query.refetch();
2230
+ if (!enabled) return {
2231
+ state: { kind: "idle" },
2232
+ reload
2233
+ };
2234
+ if (query.isFetching) return {
2235
+ state: { kind: "loading" },
2236
+ reload
2237
+ };
2238
+ if (query.status === "error") return {
2239
+ state: {
2240
+ kind: "error",
2241
+ message: messageOf(query.error)
2242
+ },
2243
+ reload
2244
+ };
2245
+ if (query.status === "success") return {
2246
+ state: {
2247
+ kind: "ready",
2248
+ result: query.data
2249
+ },
2250
+ reload
2251
+ };
2252
+ return {
2253
+ state: { kind: "loading" },
2254
+ reload
2255
+ };
2256
+ }
2257
+ function useOptionSearch(options) {
2258
+ const { queryClient, scope } = useDesignTimeScope();
2259
+ const typed = options.query.trim() === "" ? "" : options.query;
2260
+ const settled = useSettled(typed, options.debounceMs);
2261
+ const loadRef = useRef(options);
2262
+ useEffect(() => {
2263
+ loadRef.current = options;
2264
+ });
2265
+ const query = useQuery({
2266
+ queryKey: runtimeKeys.options(scope, {
2267
+ ...options.input,
2268
+ searchValue: settled
2269
+ }),
2270
+ queryFn: async () => {
2271
+ const current = loadRef.current;
2272
+ if (!current.load) throw new Error("No resolver");
2273
+ return current.parse(await current.load(settled));
2274
+ },
2275
+ enabled: Boolean(options.load) && settled !== "" && typed !== "",
2276
+ staleTime: RESOLVER_STALE_MS,
2277
+ placeholderData: keepPreviousData
2278
+ }, queryClient);
2279
+ return typed === "" ? null : query.data ?? null;
2280
+ }
2281
+ function getResolvedDynamicProps(queryClient, scope, input) {
2282
+ return queryClient.getQueryData(runtimeKeys.dynamic(scope, input));
2283
+ }
2284
+ function useDynamicPrefetch() {
2285
+ const { service, queryClient, scope } = useDesignTimeScope();
2286
+ return useMemo(() => (input, config) => {
2287
+ if (!service) return;
2288
+ queryClient.prefetchQuery({
2289
+ queryKey: runtimeKeys.dynamic(scope, input),
2290
+ queryFn: () => service.loadOptions(input.block, input.propName, config, input.connectionId ?? void 0).then(parsePropList),
2291
+ staleTime: RESOLVER_STALE_MS
2292
+ });
2293
+ }, [
2294
+ service,
2295
+ queryClient,
2296
+ scope
2297
+ ]);
2298
+ }
2299
+ function useDynamicCache() {
2300
+ const { queryClient, scope } = useDesignTimeScope();
2301
+ return useMemo(() => (input) => getResolvedDynamicProps(queryClient, scope, input), [queryClient, scope]);
2302
+ }
2303
+ function useDynamicLookup() {
2304
+ const { queryClient, scope } = useDesignTimeScope();
2305
+ const [version, setVersion] = useState(0);
2306
+ useEffect(() => queryClient.getQueryCache().subscribe((event) => {
2307
+ if (event.type !== "updated") return;
2308
+ const key = event.query.queryKey;
2309
+ if (key[0] === scope && key[1] === "dynamic") setVersion((v) => v + 1);
2310
+ }), [queryClient, scope]);
2311
+ return useMemo(() => (input) => version >= 0 ? getResolvedDynamicProps(queryClient, scope, input) : void 0, [
2312
+ queryClient,
2313
+ scope,
2314
+ version
2315
+ ]);
2316
+ }
2317
+ function useRunById(runId) {
2318
+ const { service, queryClient, scope } = useDesignTimeScope();
2319
+ const fetchRun = service?.fetchRun;
2320
+ const query = useQuery({
2321
+ queryKey: runtimeKeys.run(scope, runId ?? ""),
2322
+ queryFn: () => fetchRun(runId),
2323
+ enabled: Boolean(fetchRun && runId),
2324
+ staleTime: Infinity
2325
+ }, queryClient);
2326
+ if (!runId) return null;
2327
+ return query.data;
2328
+ }
2329
+ function useLatestRun(enabled = true) {
2330
+ const { service, queryClient, scope } = useDesignTimeScope();
2331
+ const active = enabled && Boolean(service?.latestRun);
2332
+ const query = useQuery({
2333
+ queryKey: runtimeKeys.latestRun(scope, service?.workflowId ?? ""),
2334
+ queryFn: () => service.latestRun(),
2335
+ enabled: active,
2336
+ staleTime: 0
2337
+ }, queryClient);
2338
+ if (!active) return null;
2339
+ if (query.status === "pending") return { kind: "loading" };
2340
+ return {
2341
+ kind: "ready",
2342
+ run: query.data ?? null
2343
+ };
2344
+ }
2345
+ const SYNC_RETRIES = 5;
2346
+ const SYNC_RETRY_MS = 2e3;
2347
+ function useWebhookEndpoint(enabled) {
2348
+ const { service, queryClient, scope } = useDesignTimeScope();
2349
+ const active = enabled && Boolean(service?.webhookEndpoint);
2350
+ const query = useQuery({
2351
+ queryKey: runtimeKeys.webhook(scope, service?.workflowId ?? ""),
2352
+ queryFn: () => service.webhookEndpoint(),
2353
+ enabled: active,
2354
+ staleTime: 0,
2355
+ gcTime: 0,
2356
+ retry: (failures, error) => isSyncingError(error) && failures < SYNC_RETRIES,
2357
+ retryDelay: SYNC_RETRY_MS
2358
+ }, queryClient);
2359
+ if (query.status === "pending" && isSyncingError(query.failureReason)) return { kind: "syncing" };
2360
+ if (query.status === "error") return {
2361
+ kind: "error",
2362
+ message: messageOf(query.error)
2363
+ };
2364
+ if (query.status === "pending") return { kind: "loading" };
2365
+ return query.data ? {
2366
+ kind: "ready",
2367
+ endpoint: query.data
2368
+ } : { kind: "empty" };
2369
+ }
2370
+ function useConnectionList() {
2371
+ const { service, queryClient, scope } = useDesignTimeScope();
2372
+ const list = service?.listConnections;
2373
+ const options = {
2374
+ queryKey: runtimeKeys.connections(scope, service?.connectionScope ?? null),
2375
+ queryFn: () => list(),
2376
+ staleTime: 0,
2377
+ gcTime: 0
2378
+ };
2379
+ const query = useQuery({
2380
+ ...options,
2381
+ enabled: Boolean(list)
2382
+ }, queryClient);
2383
+ return {
2384
+ connections: query.data ?? [],
2385
+ refetch: () => {
2386
+ if (list) query.refetch();
2387
+ },
2388
+ invalidate: () => void queryClient.invalidateQueries({ queryKey: runtimeKeys.connections(scope) }),
2389
+ fetchNow: () => list ? queryClient.fetchQuery({
2390
+ ...options,
2391
+ staleTime: 0
2392
+ }) : Promise.resolve([])
2393
+ };
2394
+ }
2395
+ function useTestStepRunner() {
2396
+ const { service, queryClient, scope } = useDesignTimeScope();
2397
+ const test = service?.testStep;
2398
+ if (!test) return void 0;
2399
+ return (stepId) => test(stepId).finally(() => {
2400
+ for (const queryKey of [
2401
+ runtimeKeys.allRuns(scope),
2402
+ [scope, "latestRun"],
2403
+ runtimeKeys.outputTrees(scope)
2404
+ ]) queryClient.invalidateQueries({ queryKey });
2405
+ });
2406
+ }
2407
+ function useTestTrigger() {
2408
+ const { service, queryClient, scope } = useDesignTimeScope();
2409
+ const test = service?.testTrigger;
2410
+ if (!test) return void 0;
2411
+ return () => test().finally(() => void queryClient.invalidateQueries({ queryKey: runtimeKeys.outputTrees(scope) }));
2412
+ }
2413
+ var DraftNotSynced = class extends Error {};
2414
+ const DRAFT_SYNC_RETRIES = 10;
2415
+ /**
2416
+ * The piece version each draft block runs, trigger first; `blocks` is the
2417
+ * draft in that order. Empty outside a runtime, or until the runtime answers.
2418
+ */
2419
+ function useBlockResolutions(workflowId, blocks) {
2420
+ const { service, queryClient, scope } = useDesignTimeScope();
2421
+ const fetchResolutions = service?.blockResolutions;
2422
+ const expected = blocks.map((entry) => `${entry.id}=${blockRefKey(entry.block)}`);
2423
+ return useQuery({
2424
+ queryKey: runtimeKeys.blockResolutions(scope, workflowId, blocks.map((entry) => entry.block)),
2425
+ queryFn: async () => {
2426
+ const resolutions = await fetchResolutions();
2427
+ if (keyHash(resolutions.map((resolution) => `${resolution.stepId}=${blockRefKey(resolution)}`)) !== keyHash(expected)) throw new DraftNotSynced();
2428
+ return resolutions;
2429
+ },
2430
+ enabled: Boolean(fetchResolutions && workflowId),
2431
+ retry: (count, error) => error instanceof DraftNotSynced && count < DRAFT_SYNC_RETRIES,
2432
+ retryDelay: 300,
2433
+ placeholderData: keepPreviousData,
2434
+ staleTime: 0
2435
+ }, queryClient).data ?? EMPTY_RESOLUTIONS;
2436
+ }
2437
+ const EMPTY_RESOLUTIONS = [];
2438
+ //#endregion
2439
+ //#region editors/workflow-editor/ui/version-badge.tsx
2440
+ function resolutionText(resolution) {
2441
+ if (resolution.note) return resolution.note;
2442
+ if (!resolution.resolvedVersion) return `Nothing resolves ${resolution.pieceName} ${resolution.kind} "${resolution.name}"`;
2443
+ const from = resolution.source ? ` from ${resolution.source}` : "";
2444
+ return `Configured with v${resolution.pieceVersion}, runs v${resolution.resolvedVersion}${from}`;
2445
+ }
2446
+ function runsDifferentVersion(resolution) {
2447
+ switch (resolution.match) {
2448
+ case "exact": return false;
2449
+ case "installed": return resolution.resolvedVersion !== resolution.pieceVersion;
2450
+ default: return true;
2451
+ }
2452
+ }
2453
+ function versionBadge(resolution) {
2454
+ if (!resolution || !runsDifferentVersion(resolution)) return null;
2455
+ const title = resolutionText(resolution);
2456
+ if (resolution.match === "missing") return {
2457
+ tone: "fail",
2458
+ label: "Missing",
2459
+ title
2460
+ };
2461
+ return {
2462
+ tone: resolution.match === "fallback" ? "warn" : "neutral",
2463
+ label: `v${resolution.resolvedVersion}`,
2464
+ title
2465
+ };
2466
+ }
2467
+ /** The newer version to offer, when a source has one above the pin. */
2468
+ function updateVersion(resolution) {
2469
+ const { pieceVersion, latestVersion } = resolution ?? {};
2470
+ if (!pieceVersion || !latestVersion) return null;
2471
+ try {
2472
+ return compareVersions(latestVersion, pieceVersion) > 0 ? latestVersion : null;
2473
+ } catch {
2474
+ return null;
2475
+ }
2476
+ }
2477
+ const ResolutionsContext = createContext([]);
2478
+ const DraftBlocksContext = createContext([]);
2479
+ function BlockResolutionsProvider(props) {
2480
+ return /* @__PURE__ */ jsx(DraftBlocksContext.Provider, {
2481
+ value: props.blocks,
2482
+ children: /* @__PURE__ */ jsx(ResolutionsContext.Provider, {
2483
+ value: props.resolutions,
2484
+ children: props.children
2485
+ })
2486
+ });
2487
+ }
2488
+ function useDraftBlocks() {
2489
+ return useContext(DraftBlocksContext);
2490
+ }
2491
+ function useResolution(id, block) {
2492
+ return useContext(ResolutionsContext).find((entry) => entry.stepId === id && entry.pieceName === block.pieceName && entry.pieceVersion === block.pieceVersion && entry.kind === block.kind && entry.name === block.name);
2493
+ }
2494
+ const SUMMARY_TONE = {
2495
+ neutral: "text-muted-foreground hover:text-foreground",
2496
+ warn: "text-wf-warn"
2497
+ };
2498
+ function versionSummary(resolutions) {
2499
+ const differing = resolutions.filter(runsDifferentVersion);
2500
+ if (differing.length === 0) return null;
2501
+ const missing = differing.filter((entry) => entry.match === "missing");
2502
+ const count = missing.length > 0 ? missing.length : differing.length;
2503
+ const noun = count === 1 ? "step" : "steps";
2504
+ return {
2505
+ text: missing.length > 0 ? `${count} ${noun} can't find ${count === 1 ? "its" : "their"} piece` : `${count} ${noun} ${count === 1 ? "runs" : "run"} a different piece version`,
2506
+ tone: differing.some((entry) => entry.match === "fallback" || entry.match === "missing") ? "warn" : "neutral",
2507
+ title: differing.map(resolutionText).join("\n"),
2508
+ firstStepId: (missing.length > 0 ? missing : differing)[0].stepId
2509
+ };
2510
+ }
2511
+ function VersionSummary(props) {
2512
+ const summary = versionSummary(props.resolutions);
2513
+ if (!summary) return null;
2514
+ return /* @__PURE__ */ jsx("button", {
2515
+ type: "button",
2516
+ "data-tone": summary.tone,
2517
+ className: `truncate text-xs underline-offset-2 hover:underline ${SUMMARY_TONE[summary.tone]}`,
2518
+ title: summary.title,
2519
+ onClick: () => props.onSelect(summary.firstStepId),
2520
+ children: summary.text
2521
+ });
2522
+ }
2523
+ //#endregion
2524
+ //#region editors/workflow-editor/ui/BlockSelector.tsx
2525
+ const ROW_LOGO = 24;
2526
+ const CORE_TILE = {
2527
+ [blockKey(MANUAL_TRIGGER)]: {
2528
+ icon: "play",
2529
+ color: "#2563eb"
2530
+ },
2531
+ [blockKey(SCHEDULE_TRIGGER)]: {
2532
+ icon: "clock",
2533
+ color: "#7c3aed"
2534
+ },
2535
+ [blockKey(WEBHOOK_TRIGGER)]: {
2536
+ icon: "bolt",
2537
+ color: "#0891b2"
2538
+ },
2539
+ [blockKey(BRANCH_BLOCK)]: {
2540
+ icon: "branch",
2541
+ color: "#d97706"
2542
+ },
2543
+ [blockKey(ASSERT_BLOCK)]: {
2544
+ icon: "alert",
2545
+ color: "#dc2626"
2546
+ }
2547
+ };
2548
+ function CoreTile(props) {
2549
+ const tile = props.tile;
2550
+ const glyph = Math.round(props.size * (props.bare ? .9 : .55));
2551
+ if (props.bare) return /* @__PURE__ */ jsx("span", {
2552
+ className: "flex shrink-0 items-center justify-center",
2553
+ style: {
2554
+ width: props.size,
2555
+ height: props.size,
2556
+ color: tile.color
2557
+ },
2558
+ children: /* @__PURE__ */ jsx(Icon, {
2559
+ name: tile.icon,
2560
+ size: glyph
2561
+ })
2562
+ });
2563
+ return /* @__PURE__ */ jsx("span", {
2564
+ className: "flex shrink-0 items-center justify-center rounded-[22%] text-white",
2565
+ style: {
2566
+ width: props.size,
2567
+ height: props.size,
2568
+ backgroundColor: tile.color
2569
+ },
2570
+ children: /* @__PURE__ */ jsx(Icon, {
2571
+ name: tile.icon,
2572
+ size: glyph
2573
+ })
2574
+ });
2575
+ }
2576
+ function BlockLogo(props) {
2577
+ const meta = useBlockMeta(props.block);
2578
+ const tile = CORE_TILE[blockKey(props.block)];
2579
+ if (tile) return /* @__PURE__ */ jsx(CoreTile, {
2580
+ tile,
2581
+ size: props.size ?? 36,
2582
+ bare: props.bare
2583
+ });
2584
+ return /* @__PURE__ */ jsx(LogoFrame, {
2585
+ src: meta.logoUrl,
2586
+ alt: meta.displayName,
2587
+ size: props.size ?? 36,
2588
+ glyph: meta.glyph,
2589
+ bare: props.bare
2590
+ });
2591
+ }
2592
+ function GlyphBadge(props) {
2593
+ return /* @__PURE__ */ jsx("div", {
2594
+ className: "flex shrink-0 items-center justify-center rounded-sm border border-solid border-foreground/10 bg-muted/50 text-muted-foreground",
2595
+ style: {
2596
+ width: props.size,
2597
+ height: props.size,
2598
+ fontSize: props.size / 2
2599
+ },
2600
+ children: props.glyph ?? "?"
2601
+ });
2602
+ }
2603
+ function LogoFrame(props) {
2604
+ const [broken, setBroken] = useState(false);
2605
+ useEffect(() => {
2606
+ setBroken(false);
2607
+ }, [props.src]);
2608
+ if (!props.src || broken) return /* @__PURE__ */ jsx(GlyphBadge, {
2609
+ glyph: props.glyph,
2610
+ size: props.size
2611
+ });
2612
+ return /* @__PURE__ */ jsx("div", {
2613
+ className: `flex shrink-0 items-center justify-center ${props.bare ? "" : "dark:rounded-[22%] dark:bg-white dark:p-[var(--logo-pad)]"}`,
2614
+ style: {
2615
+ width: props.size,
2616
+ height: props.size,
2617
+ "--logo-pad": `${Math.round(props.size * .12)}px`
2618
+ },
2619
+ children: /* @__PURE__ */ jsx("img", {
2620
+ src: props.src,
2621
+ alt: props.alt,
2622
+ className: "h-full w-full object-contain drop-shadow-sm",
2623
+ onError: () => setBroken(true)
2624
+ })
2625
+ });
2626
+ }
2627
+ function Row(props) {
2628
+ return /* @__PURE__ */ jsxs("button", {
2629
+ type: "button",
2630
+ className: `group flex w-full items-center gap-2 px-3 py-1.5 text-left ${props.disabled ? "cursor-not-allowed opacity-50" : "hover:bg-muted/50"}`,
2631
+ disabled: props.disabled,
2632
+ onClick: props.onClick,
2633
+ onMouseEnter: props.onHover,
2634
+ onFocus: props.onHover,
2635
+ children: [
2636
+ props.logo,
2637
+ /* @__PURE__ */ jsxs("span", {
2638
+ className: "min-w-0",
2639
+ children: [/* @__PURE__ */ jsx("span", {
2640
+ className: "block truncate text-xs font-medium text-foreground",
2641
+ children: props.label
2642
+ }), /* @__PURE__ */ jsx("span", {
2643
+ className: "block truncate text-[11px] text-muted-foreground/80",
2644
+ children: props.description
2645
+ })]
2646
+ }),
2647
+ props.version ? /* @__PURE__ */ jsxs("span", {
2648
+ className: `ml-auto shrink-0 pl-2 text-[10px] tabular-nums text-muted-foreground/70 ${props.versionNote ? "" : "hidden group-hover:inline group-focus-visible:inline"}`,
2649
+ title: props.versionNote ?? `Pinned to version ${props.version}`,
2650
+ children: ["v", props.version]
2651
+ }) : null
2652
+ ]
2653
+ });
2654
+ }
2655
+ function shownVersion(pieceName, version) {
2656
+ return isCoreBlock({ pieceName }) ? void 0 : version;
2657
+ }
2658
+ function useVersionNote(catalog) {
2659
+ const draft = useDraftBlocks();
2660
+ return (piece, version) => {
2661
+ if (!piece || !version) return void 0;
2662
+ const others = [...new Set(draft.filter((block) => block.pieceName === piece && block.pieceVersion !== version).map((block) => `v${block.pieceVersion}`))];
2663
+ if (others.length > 0) return `Other steps of this workflow use ${others.join(", ")}`;
2664
+ const published = catalog?.find((entry) => entry.name === piece)?.publishedVersion;
2665
+ return published && published !== version ? `A local build; v${published} is published` : void 0;
2666
+ };
2667
+ }
2668
+ function SectionLabel(props) {
2669
+ return /* @__PURE__ */ jsx("div", {
2670
+ className: "px-3 pb-0.5 pt-2 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground/60",
2671
+ children: props.children
2672
+ });
2673
+ }
2674
+ const CATEGORY_LABELS = {
2675
+ ARTIFICIAL_INTELLIGENCE: "AI",
2676
+ UNIVERSAL_AI: "AI",
2677
+ PRODUCTIVITY: "Productivity",
2678
+ MARKETING: "Marketing",
2679
+ COMMUNICATION: "Communication",
2680
+ SALES_AND_CRM: "Sales & CRM",
2681
+ DEVELOPER_TOOLS: "Developer tools",
2682
+ CONTENT_AND_FILES: "Content & files",
2683
+ BUSINESS_INTELLIGENCE: "Business intelligence",
2684
+ CORE: "Utilities",
2685
+ FLOW_CONTROL: "Utilities",
2686
+ COMMERCE: "Commerce",
2687
+ FORMS_AND_SURVEYS: "Forms & surveys",
2688
+ ACCOUNTING: "Accounting",
2689
+ CUSTOMER_SUPPORT: "Customer support",
2690
+ PAYMENT_PROCESSING: "Payments",
2691
+ HUMAN_RESOURCES: "HR"
2692
+ };
2693
+ const CORE_CHIP = "Core";
2694
+ const POWERHOUSE_CHIP = "Powerhouse";
2695
+ const AI_CHIP = "AI";
2696
+ function categoryLabel(id) {
2697
+ return CATEGORY_LABELS[id] ?? id.toLowerCase().replaceAll("_", " ").replace(/^\w/, (char) => char.toUpperCase());
2698
+ }
2699
+ function chipsOf(piece) {
2700
+ return new Set(piece.categories.map(categoryLabel));
2701
+ }
2702
+ function orderChips(pieces) {
2703
+ const counts = /* @__PURE__ */ new Map();
2704
+ for (const piece of pieces) for (const chip of chipsOf(piece)) counts.set(chip, (counts.get(chip) ?? 0) + 1);
2705
+ const rest = [...counts.entries()].filter(([chip]) => chip !== AI_CHIP).sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).map(([chip]) => chip);
2706
+ return [
2707
+ CORE_CHIP,
2708
+ POWERHOUSE_CHIP,
2709
+ ...counts.has(AI_CHIP) ? [AI_CHIP] : [],
2710
+ ...rest
2711
+ ];
2712
+ }
2713
+ function PieceEntries(props) {
2714
+ const [entries, setEntries] = useState(null);
2715
+ const [error, setError] = useState(null);
2716
+ const pieceSource = usePieceSource();
2717
+ useEffect(() => {
2718
+ let cancelled = false;
2719
+ (props.mode === "triggers" ? pieceSource?.loadTriggers(props.piece.name) : pieceSource?.loadActions(props.piece.name))?.then((result) => {
2720
+ if (!cancelled) setEntries(result);
2721
+ }).catch((loadError) => {
2722
+ if (!cancelled) setError(loadError instanceof Error ? loadError.message : String(loadError));
2723
+ });
2724
+ return () => {
2725
+ cancelled = true;
2726
+ };
2727
+ }, [
2728
+ props.piece.name,
2729
+ props.mode,
2730
+ pieceSource
2731
+ ]);
2732
+ return /* @__PURE__ */ jsxs("div", {
2733
+ className: "max-h-80 overflow-y-auto py-1",
2734
+ children: [/* @__PURE__ */ jsxs("button", {
2735
+ type: "button",
2736
+ className: "flex w-full items-center gap-1 px-3 py-1 text-[11px] text-muted-foreground/80 hover:text-muted-foreground",
2737
+ onClick: props.onBack,
2738
+ children: ["← ", props.piece.displayName]
2739
+ }), error ? /* @__PURE__ */ jsx("div", {
2740
+ className: "px-3 py-2 text-xs text-wf-fail",
2741
+ children: error
2742
+ }) : entries === null ? /* @__PURE__ */ jsx("div", {
2743
+ className: "px-3 py-2 text-xs text-muted-foreground/80",
2744
+ children: "Loading…"
2745
+ }) : entries.map((entry) => {
2746
+ const kind = props.mode === "triggers" ? "trigger" : "action";
2747
+ const unavailable = blockUnavailable({
2748
+ ...entry,
2749
+ kind
2750
+ });
2751
+ const block = {
2752
+ pieceName: entry.pieceName,
2753
+ pieceVersion: entry.pieceVersion,
2754
+ kind,
2755
+ name: entry.name
2756
+ };
2757
+ return /* @__PURE__ */ jsx(Row, {
2758
+ logo: /* @__PURE__ */ jsx(LogoFrame, {
2759
+ src: props.piece.logoUrl,
2760
+ alt: props.piece.displayName,
2761
+ size: ROW_LOGO
2762
+ }),
2763
+ label: entry.displayName,
2764
+ description: unavailable ?? entry.description,
2765
+ disabled: unavailable !== void 0,
2766
+ version: shownVersion(entry.pieceName, entry.pieceVersion),
2767
+ versionNote: props.versionNote(props.piece.name, entry.pieceVersion),
2768
+ onHover: unavailable === void 0 ? () => props.onHover(block) : void 0,
2769
+ onClick: () => props.onPick({
2770
+ label: entry.displayName,
2771
+ block,
2772
+ description: entry.description,
2773
+ defaultConfig: {}
2774
+ })
2775
+ }, entry.name);
2776
+ })]
2777
+ });
2778
+ }
2779
+ const SEARCH_MIN_CHARS = 2;
2780
+ const SEARCH_DEBOUNCE_MS = 250;
2781
+ const INDEXING_RETRY_MS = 2e3;
2782
+ function useBlockSearch(query, enabled) {
2783
+ const [state, setState] = useState({ kind: "idle" });
2784
+ const [attempt, setAttempt] = useState(0);
2785
+ const trimmed = query.trim();
2786
+ const active = enabled && trimmed.length >= SEARCH_MIN_CHARS;
2787
+ const search = usePieceSource()?.searchBlocks;
2788
+ useEffect(() => {
2789
+ if (!active || !search) {
2790
+ setState({ kind: "idle" });
2791
+ return;
2792
+ }
2793
+ let alive = true;
2794
+ let retry;
2795
+ const timer = setTimeout(() => {
2796
+ setState((previous) => previous.kind === "done" ? previous : { kind: "loading" });
2797
+ search(trimmed).then((result) => {
2798
+ if (!alive) return;
2799
+ setState({
2800
+ kind: "done",
2801
+ result
2802
+ });
2803
+ if (result.status === "indexing") retry = setTimeout(() => setAttempt((value) => value + 1), INDEXING_RETRY_MS);
2804
+ }, (error) => {
2805
+ if (alive) setState({
2806
+ kind: "error",
2807
+ message: error instanceof Error ? error.message : String(error)
2808
+ });
2809
+ });
2810
+ }, SEARCH_DEBOUNCE_MS);
2811
+ return () => {
2812
+ alive = false;
2813
+ clearTimeout(timer);
2814
+ if (retry) clearTimeout(retry);
2815
+ };
2816
+ }, [
2817
+ active,
2818
+ trimmed,
2819
+ attempt,
2820
+ search
2821
+ ]);
2822
+ return active ? state : { kind: "idle" };
2823
+ }
2824
+ function Chip(props) {
2825
+ return /* @__PURE__ */ jsx("button", {
2826
+ type: "button",
2827
+ className: `rounded-full border px-2 py-0.5 text-[10px] font-medium ${props.active ? "border-primary bg-primary text-primary-foreground" : "border-foreground/10 text-muted-foreground hover:border-foreground/25"}`,
2828
+ onClick: props.onClick,
2829
+ children: props.label
2830
+ });
2831
+ }
2832
+ function BlockSelector(props) {
2833
+ const [query, setQuery] = useState("");
2834
+ const [chip, setChip] = useState(null);
2835
+ const [catalog, setCatalog] = useState(null);
2836
+ const [piece, setPiece] = useState(null);
2837
+ const containerRef = useRef(null);
2838
+ useEffect(() => {
2839
+ const handler = (event) => {
2840
+ if (!containerRef.current?.contains(event.target)) props.onClose();
2841
+ };
2842
+ window.addEventListener("mousedown", handler);
2843
+ return () => window.removeEventListener("mousedown", handler);
2844
+ }, [props]);
2845
+ const anySource = usePieceSource();
2846
+ const pieceSource = props.showPieces ? anySource : void 0;
2847
+ const [catalogRound, setCatalogRound] = useState(0);
2848
+ useEffect(() => {
2849
+ if (!anySource) return;
2850
+ let cancelled = false;
2851
+ let timer;
2852
+ const load = (attempt) => {
2853
+ (attempt > 0 && anySource.reloadCatalog ? anySource.reloadCatalog() : anySource.loadCatalog()).then((pieces) => {
2854
+ registerPieceLogos(pieces);
2855
+ if (!cancelled) setCatalog({ pieces });
2856
+ }).catch((error) => {
2857
+ if (cancelled) return;
2858
+ if (attempt + 1 < 5) {
2859
+ timer = setTimeout(() => load(attempt + 1), CATALOG_RETRY_MS * 2 ** attempt);
2860
+ return;
2861
+ }
2862
+ setCatalog({
2863
+ pieces: [],
2864
+ error: error instanceof Error ? error.message : String(error)
2865
+ });
2866
+ });
2867
+ };
2868
+ load(catalogRound > 0 ? 1 : 0);
2869
+ return () => {
2870
+ cancelled = true;
2871
+ clearTimeout(timer);
2872
+ };
2873
+ }, [anySource, catalogRound]);
2874
+ const installed = (name) => catalog?.pieces.find((entry) => entry.name === name)?.version;
2875
+ const versionNote = useVersionNote(catalog?.pieces);
2876
+ const pinned = (preset) => pinBlock(preset.block, installed);
2877
+ const pick = (preset) => {
2878
+ const block = pinned(preset);
2879
+ if (block) props.onPick({
2880
+ ...preset,
2881
+ block
2882
+ });
2883
+ };
2884
+ const prefetch = useBlockFormPrefetch();
2885
+ const mode = props.pieceMode ?? "actions";
2886
+ const lowered = query.toLowerCase();
2887
+ const modePieces = useMemo(() => (catalog?.pieces ?? []).filter((entry) => (mode === "triggers" ? entry.triggerCount : entry.actionCount) > 0), [catalog, mode]);
2888
+ const chips = useMemo(() => orderChips(modePieces), [modePieces]);
2889
+ const chipsByPiece = useMemo(() => new Map(modePieces.map((entry) => [entry.name, chipsOf(entry)])), [modePieces]);
2890
+ const inChip = (pieceName) => chip === null || chip === "Core" ? true : chipsByPiece.get(pieceName)?.has(chip) ?? false;
2891
+ const showCatalog = pieceSource !== void 0 && !(chip === "Core" || chip === "Powerhouse");
2892
+ const matching = props.presets.filter((preset) => `${preset.label} ${preset.block.pieceName} ${preset.block.name}`.toLowerCase().includes(lowered));
2893
+ const corePresets = chip === null || chip === "Core" ? matching.filter((preset) => preset.group !== "powerhouse") : [];
2894
+ const powerhousePresets = chip === null || chip === "Powerhouse" ? matching.filter((preset) => preset.group === "powerhouse") : [];
2895
+ const filteredAttach = (props.onAttach ? props.attachSteps ?? [] : []).filter((step) => `${step.name} ${step.key} ${step.pieceName} ${step.actionName}`.toLowerCase().includes(lowered));
2896
+ const filteredPieces = showCatalog ? modePieces.filter((entry) => inChip(entry.name) && `${entry.displayName} ${entry.name} ${entry.description}`.toLowerCase().includes(lowered)) : [];
2897
+ const search = useBlockSearch(query, showCatalog && !piece);
2898
+ const presetRow = (preset) => {
2899
+ const block = pinned(preset);
2900
+ return /* @__PURE__ */ jsx(Row, {
2901
+ logo: /* @__PURE__ */ jsx(BlockLogo, {
2902
+ block: preset.block,
2903
+ size: ROW_LOGO
2904
+ }),
2905
+ label: preset.label,
2906
+ description: block ? preset.description : catalog === null ? "Loading…" : "Not installed on this runtime",
2907
+ disabled: !block,
2908
+ version: shownVersion(preset.block.pieceName, block?.pieceVersion),
2909
+ versionNote: versionNote(preset.block.pieceName, block?.pieceVersion),
2910
+ onHover: block ? () => prefetch(block) : void 0,
2911
+ onClick: () => pick(preset)
2912
+ }, blockKey(preset.block) + preset.label);
2913
+ };
2914
+ const labelPresets = showCatalog || filteredAttach.length > 0 || corePresets.length > 0 && powerhousePresets.length > 0;
2915
+ const wantedKind = mode === "triggers" ? "trigger" : "action";
2916
+ const hits = search.kind === "done" ? search.result.hits.filter((hit) => hit.kind === wantedKind && inChip(hit.pieceName)) : [];
2917
+ const searchActive = search.kind !== "idle";
2918
+ return /* @__PURE__ */ jsxs("div", {
2919
+ ref: containerRef,
2920
+ className: "nodrag nopan nowheel w-80 rounded-md border border-solid border-foreground/10 bg-card shadow-lg",
2921
+ onClick: (event) => event.stopPropagation(),
2922
+ children: [/* @__PURE__ */ jsxs("div", {
2923
+ className: "border-b border-foreground/10 p-2",
2924
+ children: [/* @__PURE__ */ jsx("div", {
2925
+ className: "mb-1 px-1 text-[11px] font-semibold uppercase tracking-wide text-muted-foreground/80",
2926
+ children: props.title
2927
+ }), piece ? null : /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("input", {
2928
+ autoFocus: true,
2929
+ className: "w-full rounded border border-foreground/10 px-2 py-1 text-xs",
2930
+ placeholder: pieceSource ? "Search pieces, actions, triggers…" : "Search…",
2931
+ value: query,
2932
+ onChange: (event) => setQuery(event.target.value)
2933
+ }), pieceSource && catalog && !catalog.error ? /* @__PURE__ */ jsx("div", {
2934
+ className: "mt-1.5 flex flex-wrap gap-1 px-0.5",
2935
+ children: chips.map((label) => /* @__PURE__ */ jsx(Chip, {
2936
+ label,
2937
+ active: chip === label,
2938
+ onClick: () => setChip(chip === label ? null : label)
2939
+ }, label))
2940
+ }) : null] })]
2941
+ }), piece ? /* @__PURE__ */ jsx(PieceEntries, {
2942
+ piece,
2943
+ mode,
2944
+ onPick: pick,
2945
+ onHover: prefetch,
2946
+ onBack: () => setPiece(null),
2947
+ versionNote
2948
+ }) : /* @__PURE__ */ jsxs("div", {
2949
+ className: "max-h-80 overflow-y-auto py-1",
2950
+ children: [
2951
+ filteredAttach.length > 0 ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(SectionLabel, { children: "Attach existing step" }), filteredAttach.map((step) => /* @__PURE__ */ jsx(Row, {
2952
+ logo: /* @__PURE__ */ jsx(BlockLogo, {
2953
+ block: stepBlock(step),
2954
+ size: ROW_LOGO
2955
+ }),
2956
+ label: step.name,
2957
+ description: `{{steps.${step.key}}} · detached`,
2958
+ onClick: () => props.onAttach?.(step.id)
2959
+ }, step.id))] }) : null,
2960
+ corePresets.length > 0 && labelPresets ? /* @__PURE__ */ jsx(SectionLabel, { children: "Core" }) : null,
2961
+ corePresets.map(presetRow),
2962
+ powerhousePresets.length > 0 && labelPresets ? /* @__PURE__ */ jsx(SectionLabel, { children: "Powerhouse" }) : null,
2963
+ powerhousePresets.map(presetRow),
2964
+ searchActive ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(SectionLabel, { children: mode === "triggers" ? "Triggers" : "Actions & triggers" }), search.kind === "loading" ? /* @__PURE__ */ jsx("div", {
2965
+ className: "px-3 py-1 text-xs text-muted-foreground/80",
2966
+ children: "Searching…"
2967
+ }) : search.kind === "error" ? /* @__PURE__ */ jsx("div", {
2968
+ className: "px-3 py-1 text-xs text-wf-fail",
2969
+ children: search.message
2970
+ }) : /* @__PURE__ */ jsxs(Fragment$1, { children: [hits.map((hit) => {
2971
+ const unavailable = blockUnavailable(hit);
2972
+ const block = {
2973
+ pieceName: hit.pieceName,
2974
+ pieceVersion: hit.pieceVersion,
2975
+ kind: hit.kind,
2976
+ name: hit.name
2977
+ };
2978
+ return /* @__PURE__ */ jsx(Row, {
2979
+ logo: /* @__PURE__ */ jsx(LogoFrame, {
2980
+ src: hit.logoUrl,
2981
+ alt: hit.pieceDisplayName,
2982
+ size: ROW_LOGO
2983
+ }),
2984
+ label: `${hit.displayName} · ${hit.pieceDisplayName}`,
2985
+ description: unavailable ?? (hit.description || hit.pieceDisplayName),
2986
+ disabled: unavailable !== void 0,
2987
+ version: shownVersion(hit.pieceName, hit.pieceVersion),
2988
+ versionNote: versionNote(hit.pieceName, hit.pieceVersion),
2989
+ onHover: unavailable === void 0 ? () => prefetch(block) : void 0,
2990
+ onClick: () => pick({
2991
+ label: hit.displayName,
2992
+ block,
2993
+ description: hit.description,
2994
+ defaultConfig: {}
2995
+ })
2996
+ }, blockKey(block));
2997
+ }), search.result.status === "indexing" ? /* @__PURE__ */ jsx("div", {
2998
+ className: "px-3 py-1 text-xs text-muted-foreground/80",
2999
+ children: "Indexing the catalog… more results appear shortly."
3000
+ }) : search.result.status === "error" ? /* @__PURE__ */ jsx("div", {
3001
+ className: "px-3 py-1 text-xs text-wf-fail",
3002
+ children: search.result.error ?? "Search failed"
3003
+ }) : hits.length === 0 ? /* @__PURE__ */ jsxs("div", {
3004
+ className: "px-3 py-1 text-xs text-muted-foreground/80",
3005
+ children: [
3006
+ "No matching ",
3007
+ wantedKind,
3008
+ "s"
3009
+ ]
3010
+ }) : null] })] }) : null,
3011
+ showCatalog ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(SectionLabel, { children: "Pieces" }), catalog === null ? /* @__PURE__ */ jsx("div", {
3012
+ className: "px-3 py-2 text-xs text-muted-foreground/80",
3013
+ children: "Loading catalog…"
3014
+ }) : catalog.error ? /* @__PURE__ */ jsxs("div", {
3015
+ className: "flex items-center gap-2 px-3 py-2 text-xs text-wf-fail",
3016
+ children: [/* @__PURE__ */ jsx("span", {
3017
+ className: "min-w-0 flex-1",
3018
+ children: catalog.error
3019
+ }), /* @__PURE__ */ jsx("button", {
3020
+ type: "button",
3021
+ className: "shrink-0 cursor-pointer rounded border border-solid border-foreground/15 bg-card px-1.5 py-0.5 text-foreground hover:border-foreground/25",
3022
+ onClick: () => {
3023
+ setCatalog(null);
3024
+ setCatalogRound((round) => round + 1);
3025
+ },
3026
+ children: "Retry"
3027
+ })]
3028
+ }) : filteredPieces.map((entry) => /* @__PURE__ */ jsx(Row, {
3029
+ logo: /* @__PURE__ */ jsx(LogoFrame, {
3030
+ src: entry.logoUrl,
3031
+ alt: entry.displayName,
3032
+ size: ROW_LOGO
3033
+ }),
3034
+ label: entry.deprecated ? `${entry.displayName} (deprecated)` : entry.displayName,
3035
+ description: entry.unsupported ?? (mode === "triggers" ? `${entry.triggerCount} trigger${entry.triggerCount === 1 ? "" : "s"} · ${entry.description}` : `${entry.actionCount} action${entry.actionCount === 1 ? "" : "s"} · ${entry.description}`),
3036
+ version: shownVersion(entry.name, entry.version),
3037
+ versionNote: versionNote(entry.name, entry.version),
3038
+ onClick: () => setPiece(entry)
3039
+ }, entry.name))] }) : null,
3040
+ corePresets.length + powerhousePresets.length === 0 && filteredPieces.length === 0 && filteredAttach.length === 0 && !searchActive ? /* @__PURE__ */ jsx("div", {
3041
+ className: "px-3 py-2 text-xs text-muted-foreground/80",
3042
+ children: "No matches"
3043
+ }) : null
3044
+ ]
3045
+ })]
3046
+ });
3047
+ }
3048
+ //#endregion
3049
+ export { formatDuration as $, isEmptyValue as A, Tooltip as At, blockMeta as B, useOptionSearch as C, Hint as Ct, useTestTrigger as D, Switch as Dt, useTestStepRunner as E, Select as Et, storedSchema as F, isIconName as Ft, CONNECTION_TONE as G, pieceLogo as H, stripOptions as I, DocumentErrorBoundary as It, STEP_TONE as J, RUN_STATUSES as K, undeclaredPortIssues as L, DocumentLoadError as Lt, parsePropList as M, textAreaClass as Mt, resolverInputFor as N, textInputClass as Nt, useWebhookEndpoint as O, Tabs as Ot, settingFor as P, Icon as Pt, formatAbsolute as Q, withSetting as R, errorMessage as Rt, useLatestRun as S, FieldLabel as St, useRunById as T, Segmented as Tt, useBlockMeta as U, pieceDisplayName as V, usePieceLogos as W, TONE_TEXT as X, TONE_DOT as Y, durationMs as Z, useConnectionList as _, useRuntime as _t, resolutionText as a, runTimeline as at, useDynamicLookup as b, Button as bt, useResolution as c, toneOf as ct, useBlockForm as d, useOAuthAttempt as dt, formatMs as et, useBlockFormLoader as f, useOAuthRedirectUri as ft, useCachedBlockForm as g, useRunsQuery as gt, useBlockResolutions as h, useRunQuery as ht, VersionSummary as i, runStatusLabel as it, isPropVisible as j, invalidClass as jt, blockMissing as k, Toggle as kt, versionBadge as l, workflowHealth as lt, useBlockPorts as m, useRunPagesQuery as mt, BlockSelector as n, formatWhen as nt, runsDifferentVersion as o, runTone as ot, useBlockForms as p, usePieceCatalog as pt, RUN_TONE as q, BlockResolutionsProvider as r, runStats as rt, updateVersion as s, statusLabel as st, BlockLogo as t, formatTrigger as tt, DesignTimeProvider as u, WorkflowRuntimeProvider as ut, useDesignTime as v, useRuntimeActions as vt, useResolvedProp as w, IconButton as wt, useDynamicPrefetch as x, FieldError as xt, useDynamicCache as y, useSecretStat as yt, workflowReadiness as z };
3050
+
3051
+ //# sourceMappingURL=BlockSelector-BHJQOhie.js.map