@powerhousedao/workflow 6.2.3-dev.29 → 6.2.3-dev.31

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,3055 @@
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-D5EGaCrH.mjs";
2
+ import { Rt as blockKey, zt as compareVersions } from "./module-Dhe5E-VA.mjs";
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
+ if (process.env.NODE_ENV !== "production") {
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 (process.env.NODE_ENV !== "production") {
701
+ 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");
702
+ }
703
+ const isRestoring = useIsRestoring();
704
+ const errorResetBoundary = useQueryErrorResetBoundary();
705
+ const client = useQueryClient(queryClient);
706
+ const defaultedOptions = client.defaultQueryOptions(options);
707
+ client.getDefaultOptions().queries?._experimental_beforeQuery?.(defaultedOptions);
708
+ const query = client.getQueryCache().get(defaultedOptions.queryHash);
709
+ if (process.env.NODE_ENV !== "production") {
710
+ 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`);
711
+ }
712
+ defaultedOptions._optimisticResults = isRestoring ? "isRestoring" : "optimistic";
713
+ ensureSuspenseTimers(defaultedOptions);
714
+ ensurePreventErrorBoundaryRetry(defaultedOptions, errorResetBoundary, query);
715
+ useClearResetErrorBoundary(errorResetBoundary);
716
+ const isNewCacheEntry = !client.getQueryCache().get(defaultedOptions.queryHash);
717
+ const [observer] = React$1.useState(() => new Observer(client, defaultedOptions));
718
+ const result = observer.getOptimisticResult(defaultedOptions);
719
+ const shouldSubscribe = !isRestoring && options.subscribed !== false;
720
+ React$1.useSyncExternalStore(React$1.useCallback((onStoreChange) => {
721
+ const unsubscribe = shouldSubscribe ? observer.subscribe(notifyManager.batchCalls(onStoreChange)) : noop;
722
+ observer.updateResult();
723
+ return unsubscribe;
724
+ }, [observer, shouldSubscribe]), () => observer.getCurrentResult(), () => observer.getCurrentResult());
725
+ React$1.useEffect(() => {
726
+ observer.setOptions(defaultedOptions);
727
+ }, [defaultedOptions, observer]);
728
+ if (shouldSuspend(defaultedOptions, result)) throw fetchOptimistic(defaultedOptions, observer, errorResetBoundary);
729
+ if (getHasError({
730
+ result,
731
+ errorResetBoundary,
732
+ throwOnError: defaultedOptions.throwOnError,
733
+ query,
734
+ suspense: defaultedOptions.suspense
735
+ })) throw result.error;
736
+ client.getDefaultOptions().queries?._experimental_afterQuery?.(defaultedOptions, result);
737
+ if (defaultedOptions.experimental_prefetchInRender && !isServer && willFetch(result, isRestoring)) (isNewCacheEntry ? fetchOptimistic(defaultedOptions, observer, errorResetBoundary) : query?.promise)?.catch(noop).finally(() => {
738
+ observer.updateResult();
739
+ });
740
+ return !defaultedOptions.notifyOnChangeProps ? observer.trackResult(result) : result;
741
+ }
742
+ //#endregion
743
+ //#region ../../node_modules/.pnpm/@tanstack+react-query@5.90.21_react@19.2.6/node_modules/@tanstack/react-query/build/modern/useQuery.js
744
+ function useQuery(options, queryClient) {
745
+ return useBaseQuery(options, QueryObserver, queryClient);
746
+ }
747
+ //#endregion
748
+ //#region ../../node_modules/.pnpm/@tanstack+react-query@5.90.21_react@19.2.6/node_modules/@tanstack/react-query/build/modern/useInfiniteQuery.js
749
+ function useInfiniteQuery(options, queryClient) {
750
+ return useBaseQuery(options, InfiniteQueryObserver, queryClient);
751
+ }
752
+ new Set([...DOCUMENT_SCOPE_ACTION_TYPES].filter((type) => type !== "CREATE_DOCUMENT"));
753
+ const DRIVE_COLLECTION_PREFIX = "drive.";
754
+ /**
755
+ * Identifies the collection a remote synchronizes. Collections are drive-level
756
+ * abstractions (document-drive and reactor-drive), so a collection id is the
757
+ * drive document id plus the branch it scopes to rather than an opaque string.
758
+ *
759
+ * The canonical string form (`drive.${branch}.${driveId}`) is produced only by
760
+ * `key` and parsed only by `fromKey`; that string is the wire and storage
761
+ * representation and is byte-for-byte identical to the legacy
762
+ * `driveCollectionId(branch, driveId)` output, so existing `document_collections`
763
+ * rows and persisted remotes remain valid without migration.
764
+ */
765
+ var DriveCollectionId = class DriveCollectionId {
766
+ driveId;
767
+ branch;
768
+ constructor(driveId, branch) {
769
+ this.driveId = driveId;
770
+ this.branch = branch;
771
+ }
772
+ static forDrive(driveId, branch = "main") {
773
+ return new DriveCollectionId(driveId, branch);
774
+ }
775
+ /**
776
+ * The single deserializer for the wire/storage form. `branch` may contain
777
+ * dots, while `driveId` is a dot-free document id, so the drive id is the
778
+ * final dot-delimited segment.
779
+ */
780
+ static fromKey(key) {
781
+ if (!key.startsWith(DRIVE_COLLECTION_PREFIX)) throw new Error(`Unsupported collection id: ${key}`);
782
+ const rest = key.slice(6);
783
+ const lastDot = rest.lastIndexOf(".");
784
+ if (lastDot === -1 || lastDot === rest.length - 1) throw new Error(`Malformed drive collection id: ${key}`);
785
+ return new DriveCollectionId(rest.slice(lastDot + 1), rest.slice(0, lastDot));
786
+ }
787
+ get key() {
788
+ return `${DRIVE_COLLECTION_PREFIX}${this.branch}.${this.driveId}`;
789
+ }
790
+ toString() {
791
+ return this.key;
792
+ }
793
+ equals(other) {
794
+ return this.driveId === other.driveId && this.branch === other.branch;
795
+ }
796
+ };
797
+ //#endregion
798
+ //#region editors/shared/DocumentErrorBoundary.tsx
799
+ /** Best-effort message for anything thrown, without stringifying an object. */
800
+ function errorMessage(error) {
801
+ if (error instanceof Error) return error.message;
802
+ if (typeof error === "string") return error;
803
+ return "Unknown error";
804
+ }
805
+ /** Inline "could not load" panel, also used for hook-level (non-thrown) failures. */
806
+ function DocumentLoadError(props) {
807
+ return /* @__PURE__ */ jsxs("div", {
808
+ className: "m-3 rounded border border-solid border-wf-fail/40 bg-wf-fail/10 p-3",
809
+ children: [
810
+ /* @__PURE__ */ jsx("p", {
811
+ className: "text-sm font-medium text-wf-fail",
812
+ children: props.title ?? "This document could not be loaded"
813
+ }),
814
+ props.label ? /* @__PURE__ */ jsx("p", {
815
+ className: "mt-0.5 text-xs text-wf-fail",
816
+ children: props.label
817
+ }) : null,
818
+ props.documentId ? /* @__PURE__ */ jsx("p", {
819
+ className: "mt-0.5 font-mono text-[11px] text-wf-fail",
820
+ children: props.documentId
821
+ }) : null,
822
+ /* @__PURE__ */ jsx("p", {
823
+ className: "mt-1 text-xs text-muted-foreground",
824
+ children: errorMessage(props.error)
825
+ }),
826
+ /* @__PURE__ */ jsxs("div", {
827
+ className: "mt-2 flex gap-2",
828
+ children: [props.onRetry ? /* @__PURE__ */ jsx("button", {
829
+ type: "button",
830
+ className: "rounded border border-solid border-wf-fail/40 px-2 py-0.5 text-xs font-medium text-wf-fail",
831
+ onClick: props.onRetry,
832
+ children: "Retry"
833
+ }) : null, props.onDismiss ? /* @__PURE__ */ jsx("button", {
834
+ type: "button",
835
+ className: "rounded border border-solid border-foreground/15 px-2 py-0.5 text-xs text-muted-foreground",
836
+ onClick: props.onDismiss,
837
+ children: "Dismiss"
838
+ }) : null]
839
+ })
840
+ ]
841
+ });
842
+ }
843
+ var DocumentErrorBoundary = class extends Component {
844
+ state = {
845
+ error: void 0,
846
+ attempt: 0
847
+ };
848
+ static getDerivedStateFromError(error) {
849
+ return { error };
850
+ }
851
+ componentDidCatch(error, info) {
852
+ console.error(`Failed to render document ${this.props.documentId ?? "(unknown id)"}:`, error, info.componentStack);
853
+ }
854
+ retry = () => {
855
+ this.setState((state) => ({
856
+ error: void 0,
857
+ attempt: state.attempt + 1
858
+ }));
859
+ };
860
+ dismiss = () => {
861
+ this.setState({ error: void 0 });
862
+ this.props.onDismiss?.();
863
+ };
864
+ render() {
865
+ if (this.state.error !== void 0) return /* @__PURE__ */ jsx(DocumentLoadError, {
866
+ label: this.props.label,
867
+ documentId: this.props.documentId,
868
+ error: this.state.error,
869
+ onRetry: this.retry,
870
+ onDismiss: this.props.onDismiss ? this.dismiss : void 0
871
+ });
872
+ return /* @__PURE__ */ jsx(Fragment, { children: this.props.children }, this.state.attempt);
873
+ }
874
+ };
875
+ //#endregion
876
+ //#region editors/shared/icons.tsx
877
+ const ICON_PATHS = {
878
+ pencil: "M4 20h4L19 9l-4-4L4 16v4zM14 6l4 4",
879
+ trash: "M5 7h14M10 11v6M14 11v6M6 7l1 13h10l1-13M9 7V4h6v3",
880
+ plus: "M12 5v14M5 12h14",
881
+ minus: "M5 12h14",
882
+ list: "M8 6h12M8 12h12M8 18h12M4 6h.01M4 12h.01M4 18h.01",
883
+ play: "M7 5v14l12-7z",
884
+ chevron: "M9 6l6 6-6 6",
885
+ chevronDown: "M6 9l6 6 6-6",
886
+ retry: "M4 12a8 8 0 1 0 2.3-5.7M4 4v4h4",
887
+ back: "M15 6l-6 6 6 6",
888
+ close: "M6 6l12 12M18 6L6 18",
889
+ check: "M5 12l5 5 9-10",
890
+ search: "M11 18a7 7 0 1 0 0-14 7 7 0 0 0 0 14zM20 20l-4-4",
891
+ 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",
892
+ 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",
893
+ arrowRight: "M5 12h14M13 6l6 6-6 6",
894
+ 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",
895
+ copy: "M9 9h10v10H9zM5 15V5h10",
896
+ sliders: "M4 7h10M18 7h2M4 17h4M12 17h8M14 5v4M8 15v4",
897
+ 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",
898
+ 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",
899
+ undo: "M9 14L4 9l5-5M4 9h10a6 6 0 0 1 0 12h-3",
900
+ redo: "M15 14l5-5-5-5M20 9H10a6 6 0 0 0 0 12h3",
901
+ clock: "M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18zM12 7v5l3 2",
902
+ bolt: "M13 3L5 13h6l-1 8 8-10h-6l1-8z",
903
+ 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",
904
+ lock: "M6 11h12v9H6zM8.5 11V8a3.5 3.5 0 0 1 7 0v3M12 15v2",
905
+ 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",
906
+ archive: "M4 5h16v4H4zM6 9v10h12V9M10 13h4"
907
+ };
908
+ function isIconName(name) {
909
+ return typeof name === "string" && name in ICON_PATHS;
910
+ }
911
+ function Icon(props) {
912
+ return /* @__PURE__ */ jsx("svg", {
913
+ "aria-hidden": true,
914
+ viewBox: "0 0 24 24",
915
+ fill: "none",
916
+ stroke: "currentColor",
917
+ strokeWidth: 1.75,
918
+ strokeLinecap: "round",
919
+ strokeLinejoin: "round",
920
+ width: props.size,
921
+ height: props.size,
922
+ className: `shrink-0 ${props.size ? "" : "h-4 w-4"} ${props.className ?? ""}`,
923
+ children: /* @__PURE__ */ jsx("path", { d: ICON_PATHS[props.name] })
924
+ });
925
+ }
926
+ //#endregion
927
+ //#region editors/shared/controls.tsx
928
+ const FOCUS_RING = "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/40";
929
+ const BUTTON_SIZE = {
930
+ sm: "h-7 gap-1 rounded-md px-2 text-xs",
931
+ md: "h-8 gap-1.5 rounded-md px-3 text-[13px]"
932
+ };
933
+ const BUTTON_VARIANT = {
934
+ primary: "bg-primary text-primary-foreground hover:opacity-90",
935
+ secondary: "border border-solid border-foreground/15 bg-card text-foreground hover:bg-accent",
936
+ ghost: "text-muted-foreground hover:bg-accent hover:text-foreground",
937
+ danger: "text-wf-fail hover:bg-wf-fail/10",
938
+ destructive: "bg-wf-fail text-white hover:opacity-90"
939
+ };
940
+ function Button(props) {
941
+ const { variant = "secondary", size = "md", className = "", ...rest } = props;
942
+ return /* @__PURE__ */ jsx("button", {
943
+ type: "button",
944
+ 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}`,
945
+ ...rest
946
+ });
947
+ }
948
+ function IconButton(props) {
949
+ const { icon, label, active, className = "", ...rest } = props;
950
+ return /* @__PURE__ */ jsx("button", {
951
+ type: "button",
952
+ title: label,
953
+ "aria-label": label,
954
+ 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}`,
955
+ ...rest,
956
+ children: /* @__PURE__ */ jsx(Icon, {
957
+ name: icon,
958
+ className: "h-3.5 w-3.5"
959
+ })
960
+ });
961
+ }
962
+ 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";
963
+ const textInputClass = `${inputClass} h-9`;
964
+ const textAreaClass = `${inputClass} min-h-20 py-2 leading-relaxed`;
965
+ const invalidClass = "border-wf-warn/70 hover:border-wf-warn";
966
+ /** Label row above a control: name, optional marker, and a trailing action. */
967
+ function FieldLabel(props) {
968
+ const LabelTag = props.htmlFor ? "label" : "span";
969
+ return /* @__PURE__ */ jsxs("div", {
970
+ className: "mb-1.5 flex min-h-6 items-center justify-between gap-2",
971
+ children: [/* @__PURE__ */ jsxs(LabelTag, {
972
+ htmlFor: props.htmlFor,
973
+ className: "flex min-w-0 items-baseline gap-1.5 text-[13px] font-medium text-foreground",
974
+ children: [
975
+ /* @__PURE__ */ jsx("span", {
976
+ className: "truncate",
977
+ children: props.label
978
+ }),
979
+ props.optional ? /* @__PURE__ */ jsx("span", {
980
+ className: "shrink-0 text-xs font-normal text-muted-foreground",
981
+ children: "Optional"
982
+ }) : null,
983
+ props.needsValue ? /* @__PURE__ */ jsx("span", {
984
+ className: "shrink-0 text-xs font-normal text-wf-warn",
985
+ children: "Needs a value"
986
+ }) : null
987
+ ]
988
+ }), props.action ? /* @__PURE__ */ jsx("span", {
989
+ className: "flex shrink-0 items-center gap-0.5",
990
+ children: props.action
991
+ }) : null]
992
+ });
993
+ }
994
+ const LONG_HINT = 140;
995
+ /** Help text under a control; long piece descriptions fold to two lines. */
996
+ function Hint(props) {
997
+ const [open, setOpen] = useState(false);
998
+ const text = props.text;
999
+ if (text !== void 0) {
1000
+ if (!text.trim()) return null;
1001
+ const long = text.length > LONG_HINT;
1002
+ return /* @__PURE__ */ jsxs("p", {
1003
+ className: "mt-1.5 text-xs leading-relaxed text-muted-foreground",
1004
+ children: [/* @__PURE__ */ jsx("span", {
1005
+ className: long && !open ? "line-clamp-2" : void 0,
1006
+ children: text
1007
+ }), long ? /* @__PURE__ */ jsx("button", {
1008
+ type: "button",
1009
+ className: "mt-0.5 block font-medium text-foreground/70 hover:text-foreground",
1010
+ onClick: () => setOpen((value) => !value),
1011
+ children: open ? "Show less" : "Show more"
1012
+ }) : null]
1013
+ });
1014
+ }
1015
+ return /* @__PURE__ */ jsx("p", {
1016
+ className: "mt-1.5 text-xs leading-relaxed text-muted-foreground",
1017
+ children: props.children
1018
+ });
1019
+ }
1020
+ function FieldError(props) {
1021
+ if (!props.children) return null;
1022
+ return /* @__PURE__ */ jsx("p", {
1023
+ className: "mt-1.5 text-xs text-wf-fail",
1024
+ children: props.children
1025
+ });
1026
+ }
1027
+ function Switch(props) {
1028
+ const id = useId();
1029
+ return /* @__PURE__ */ jsxs("div", {
1030
+ className: "flex items-start justify-between gap-4",
1031
+ children: [/* @__PURE__ */ jsxs("label", {
1032
+ htmlFor: id,
1033
+ className: "min-w-0",
1034
+ children: [/* @__PURE__ */ jsx("span", {
1035
+ className: "block text-[13px] font-medium text-foreground",
1036
+ children: props.label
1037
+ }), props.description ? /* @__PURE__ */ jsx(Hint, { text: props.description }) : null]
1038
+ }), /* @__PURE__ */ jsx("button", {
1039
+ id,
1040
+ type: "button",
1041
+ role: "switch",
1042
+ "aria-checked": props.checked,
1043
+ disabled: props.disabled,
1044
+ 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"}`,
1045
+ onClick: () => props.onChange(!props.checked),
1046
+ 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"}` })
1047
+ })]
1048
+ });
1049
+ }
1050
+ function Toggle(props) {
1051
+ return /* @__PURE__ */ jsx("button", {
1052
+ type: "button",
1053
+ role: "switch",
1054
+ "aria-checked": props.checked,
1055
+ "aria-label": props.label,
1056
+ disabled: props.disabled,
1057
+ 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"}`,
1058
+ onClick: (event) => {
1059
+ event.stopPropagation();
1060
+ props.onChange(!props.checked);
1061
+ },
1062
+ 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"}` })
1063
+ });
1064
+ }
1065
+ function Tooltip(props) {
1066
+ if (props.enabled === false) return /* @__PURE__ */ jsx(Fragment$1, { children: props.children });
1067
+ 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"}`;
1068
+ return /* @__PURE__ */ jsxs("span", {
1069
+ className: "group/tip relative inline-flex",
1070
+ children: [props.children, /* @__PURE__ */ jsx("span", {
1071
+ 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}`,
1072
+ children: /* @__PURE__ */ jsx("span", {
1073
+ role: "tooltip",
1074
+ 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",
1075
+ children: props.content
1076
+ })
1077
+ })]
1078
+ });
1079
+ }
1080
+ function Tabs(props) {
1081
+ return /* @__PURE__ */ jsx("div", {
1082
+ role: "tablist",
1083
+ className: "flex gap-4",
1084
+ children: props.tabs.map((tab) => {
1085
+ const selected = tab.value === props.value;
1086
+ return /* @__PURE__ */ jsxs("button", {
1087
+ type: "button",
1088
+ role: "tab",
1089
+ "aria-selected": selected,
1090
+ 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"}`,
1091
+ onClick: () => props.onChange(tab.value),
1092
+ children: [tab.label, tab.badge]
1093
+ }, tab.value);
1094
+ })
1095
+ });
1096
+ }
1097
+ /** Two or three short, mutually exclusive choices shown side by side. */
1098
+ function Segmented(props) {
1099
+ return /* @__PURE__ */ jsx("div", {
1100
+ role: "radiogroup",
1101
+ 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" : ""}`,
1102
+ children: props.options.map((option) => {
1103
+ const selected = option.value === props.value;
1104
+ return /* @__PURE__ */ jsx("button", {
1105
+ type: "button",
1106
+ role: "radio",
1107
+ "aria-checked": selected,
1108
+ 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"}`,
1109
+ onClick: () => props.onChange(option.value),
1110
+ children: option.label
1111
+ }, option.value);
1112
+ })
1113
+ });
1114
+ }
1115
+ const SEARCH_THRESHOLD = 7;
1116
+ function Select(props) {
1117
+ const [open, setOpen] = useState(false);
1118
+ const [query, setQuery] = useState("");
1119
+ const [active, setActive] = useState(0);
1120
+ const triggerRef = useRef(null);
1121
+ const popoverRef = useRef(null);
1122
+ const searchRef = useRef(null);
1123
+ const listId = useId();
1124
+ const [position, setPosition] = useState(null);
1125
+ const selected = props.multiple ? props.value : props.value ? [props.value] : [];
1126
+ const selectedSet = new Set(selected);
1127
+ const searchable = props.searchable || Boolean(props.onQueryChange) || props.options.length > SEARCH_THRESHOLD;
1128
+ const needle = query.trim().toLowerCase();
1129
+ const serverSide = Boolean(props.onQueryChange);
1130
+ const visible = useMemo(() => needle && !serverSide ? props.options.filter((option) => `${option.label} ${option.description ?? ""}`.toLowerCase().includes(needle)) : props.options, [
1131
+ needle,
1132
+ props.options,
1133
+ serverSide
1134
+ ]);
1135
+ const onQueryChange = props.onQueryChange;
1136
+ const dismiss = () => {
1137
+ setOpen(false);
1138
+ setQuery("");
1139
+ onQueryChange?.("");
1140
+ };
1141
+ const close = () => {
1142
+ dismiss();
1143
+ triggerRef.current?.focus();
1144
+ };
1145
+ const place = () => {
1146
+ const rect = triggerRef.current?.getBoundingClientRect();
1147
+ if (!rect) return;
1148
+ const below = window.innerHeight - rect.bottom - 8;
1149
+ const above = rect.top - 8;
1150
+ const flip = below < 240 && above > below;
1151
+ setPosition({
1152
+ left: rect.left,
1153
+ width: rect.width,
1154
+ top: flip ? void 0 : rect.bottom + 4,
1155
+ bottom: flip ? window.innerHeight - rect.top + 4 : void 0,
1156
+ maxHeight: Math.min(320, flip ? above : below)
1157
+ });
1158
+ };
1159
+ const openList = () => {
1160
+ const index = props.options.findIndex((option) => selectedSet.has(option.value));
1161
+ setActive(Math.max(0, index));
1162
+ setOpen(true);
1163
+ };
1164
+ useLayoutEffect(() => {
1165
+ if (!open) return;
1166
+ place();
1167
+ }, [open]);
1168
+ const placed = position !== null;
1169
+ useEffect(() => {
1170
+ if (open && placed && searchable) searchRef.current?.focus();
1171
+ }, [
1172
+ open,
1173
+ placed,
1174
+ searchable
1175
+ ]);
1176
+ useEffect(() => {
1177
+ if (!open) return;
1178
+ const onPointer = (event) => {
1179
+ const target = event.target;
1180
+ if (!popoverRef.current?.contains(target) && !triggerRef.current?.contains(target)) {
1181
+ setOpen(false);
1182
+ setQuery("");
1183
+ onQueryChange?.("");
1184
+ }
1185
+ };
1186
+ window.addEventListener("mousedown", onPointer);
1187
+ window.addEventListener("resize", place);
1188
+ window.addEventListener("scroll", place, true);
1189
+ return () => {
1190
+ window.removeEventListener("mousedown", onPointer);
1191
+ window.removeEventListener("resize", place);
1192
+ window.removeEventListener("scroll", place, true);
1193
+ };
1194
+ }, [
1195
+ open,
1196
+ searchable,
1197
+ onQueryChange
1198
+ ]);
1199
+ useEffect(() => {
1200
+ popoverRef.current?.querySelector(`[data-index="${active}"]`)?.scrollIntoView({ block: "nearest" });
1201
+ }, [active]);
1202
+ const choose = (option) => {
1203
+ if (option.disabled) return;
1204
+ if (props.multiple) {
1205
+ props.onChange(selectedSet.has(option.value) ? props.value.filter((value) => value !== option.value) : [...props.value, option.value]);
1206
+ return;
1207
+ }
1208
+ props.onChange(option.value);
1209
+ close();
1210
+ };
1211
+ const onListKey = (event) => {
1212
+ if (event.key === "ArrowDown") {
1213
+ event.preventDefault();
1214
+ setActive((index) => Math.min(visible.length - 1, index + 1));
1215
+ } else if (event.key === "ArrowUp") {
1216
+ event.preventDefault();
1217
+ setActive((index) => Math.max(0, index - 1));
1218
+ } else if (event.key === "Enter") {
1219
+ event.preventDefault();
1220
+ const option = visible[active];
1221
+ if (option) choose(option);
1222
+ } else if (event.key === "Escape") {
1223
+ event.preventDefault();
1224
+ close();
1225
+ } else if (event.key === "Tab") dismiss();
1226
+ };
1227
+ const labels = props.options.filter((option) => selectedSet.has(option.value)).map((option) => option.label);
1228
+ const unknown = selected.filter((value) => !props.options.some((option) => option.value === value));
1229
+ const shown = [...labels, ...unknown];
1230
+ const selectedIcon = props.multiple ? void 0 : props.options.find((option) => option.value === props.value)?.icon;
1231
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsxs("button", {
1232
+ ref: triggerRef,
1233
+ id: props.id,
1234
+ "aria-label": props.ariaLabel,
1235
+ type: "button",
1236
+ role: "combobox",
1237
+ "aria-expanded": open,
1238
+ "aria-controls": open ? listId : void 0,
1239
+ "aria-activedescendant": open && visible.length > 0 ? `${listId}-${active}` : void 0,
1240
+ "aria-haspopup": "listbox",
1241
+ disabled: props.disabled,
1242
+ className: `${textInputClass} flex items-center gap-2 text-left ${props.invalid ? invalidClass : ""} ${open ? "border-ring ring-2 ring-ring/25" : ""}`,
1243
+ onClick: () => open ? close() : openList(),
1244
+ onKeyDown: (event) => {
1245
+ if (open) {
1246
+ onListKey(event);
1247
+ return;
1248
+ }
1249
+ if (event.key === "ArrowDown" || event.key === "Enter" || event.key === " ") {
1250
+ event.preventDefault();
1251
+ openList();
1252
+ }
1253
+ },
1254
+ children: [
1255
+ selectedIcon,
1256
+ /* @__PURE__ */ jsx("span", {
1257
+ className: `min-w-0 flex-1 truncate ${shown.length ? "" : "text-muted-foreground/70"}`,
1258
+ children: shown.length > 0 ? shown.join(", ") : props.loading ? "Loading…" : props.placeholder ?? "Choose…"
1259
+ }),
1260
+ props.multiple && shown.length > 1 ? /* @__PURE__ */ jsx("span", {
1261
+ className: "shrink-0 rounded bg-muted px-1.5 text-[11px] tabular-nums text-muted-foreground",
1262
+ children: shown.length
1263
+ }) : null,
1264
+ /* @__PURE__ */ jsx(Icon, {
1265
+ name: "chevronDown",
1266
+ className: `h-3.5 w-3.5 text-muted-foreground transition-transform ${open ? "rotate-180" : ""}`
1267
+ })
1268
+ ]
1269
+ }), open && position ? createPortal(/* @__PURE__ */ jsxs("div", {
1270
+ ref: popoverRef,
1271
+ tabIndex: -1,
1272
+ 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",
1273
+ style: {
1274
+ left: position.left,
1275
+ width: Math.max(position.width, 220),
1276
+ top: position.top,
1277
+ bottom: position.bottom,
1278
+ maxHeight: position.maxHeight
1279
+ },
1280
+ onKeyDown: onListKey,
1281
+ children: [
1282
+ searchable || props.onRefresh ? /* @__PURE__ */ jsxs("div", {
1283
+ className: "flex items-center gap-1 border-b border-solid border-foreground/10 px-2",
1284
+ children: [searchable ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(Icon, {
1285
+ name: "search",
1286
+ className: "h-3.5 w-3.5 text-muted-foreground"
1287
+ }), /* @__PURE__ */ jsx("input", {
1288
+ ref: searchRef,
1289
+ className: "h-9 min-w-0 flex-1 bg-transparent text-[13px] text-foreground placeholder:text-muted-foreground/70 focus:outline-none",
1290
+ placeholder: "Search",
1291
+ value: query,
1292
+ onChange: (event) => {
1293
+ setQuery(event.target.value);
1294
+ setActive(0);
1295
+ props.onQueryChange?.(event.target.value);
1296
+ }
1297
+ })] }) : /* @__PURE__ */ jsx("span", { className: "h-9 flex-1" }), props.onRefresh ? /* @__PURE__ */ jsx(IconButton, {
1298
+ icon: "retry",
1299
+ label: "Reload options",
1300
+ disabled: props.loading,
1301
+ onClick: props.onRefresh
1302
+ }) : null]
1303
+ }) : null,
1304
+ /* @__PURE__ */ jsx("div", {
1305
+ id: listId,
1306
+ role: "listbox",
1307
+ "aria-multiselectable": props.multiple || void 0,
1308
+ className: "min-h-0 flex-1 overflow-y-auto p-1",
1309
+ children: props.loading && props.options.length === 0 ? /* @__PURE__ */ jsx("p", {
1310
+ className: "px-2 py-2 text-[13px] text-muted-foreground",
1311
+ children: "Loading options…"
1312
+ }) : visible.length === 0 ? /* @__PURE__ */ jsx("p", {
1313
+ className: "px-2 py-2 text-[13px] text-muted-foreground",
1314
+ children: needle ? "Nothing matches." : props.emptyText ?? "No options."
1315
+ }) : visible.map((option, index) => {
1316
+ const isSelected = selectedSet.has(option.value);
1317
+ return /* @__PURE__ */ jsxs("div", {
1318
+ id: `${listId}-${index}`,
1319
+ role: "option",
1320
+ "aria-selected": isSelected,
1321
+ "aria-disabled": option.disabled || void 0,
1322
+ "data-index": index,
1323
+ 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" : ""}`,
1324
+ onMouseEnter: () => setActive(index),
1325
+ onMouseDown: (event) => {
1326
+ event.preventDefault();
1327
+ choose(option);
1328
+ },
1329
+ children: [
1330
+ props.multiple ? /* @__PURE__ */ jsx("span", {
1331
+ 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"}`,
1332
+ children: isSelected ? /* @__PURE__ */ jsx(Icon, {
1333
+ name: "check",
1334
+ className: "h-3 w-3"
1335
+ }) : null
1336
+ }) : null,
1337
+ option.icon,
1338
+ /* @__PURE__ */ jsxs("span", {
1339
+ className: "min-w-0 flex-1",
1340
+ children: [/* @__PURE__ */ jsx("span", {
1341
+ className: "block truncate",
1342
+ children: option.label
1343
+ }), option.description ? /* @__PURE__ */ jsx("span", {
1344
+ className: "block truncate text-xs text-muted-foreground",
1345
+ children: option.description
1346
+ }) : null]
1347
+ }),
1348
+ !props.multiple && isSelected ? /* @__PURE__ */ jsx(Icon, {
1349
+ name: "check",
1350
+ className: "h-3.5 w-3.5 text-foreground"
1351
+ }) : null
1352
+ ]
1353
+ }, option.value);
1354
+ })
1355
+ }),
1356
+ props.actions?.length ? /* @__PURE__ */ jsx("div", {
1357
+ className: "border-t border-solid border-foreground/10 p-1",
1358
+ children: props.actions.map((action) => /* @__PURE__ */ jsxs("button", {
1359
+ type: "button",
1360
+ 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",
1361
+ onMouseDown: (event) => {
1362
+ event.preventDefault();
1363
+ dismiss();
1364
+ action.onSelect();
1365
+ },
1366
+ children: [action.icon ? /* @__PURE__ */ jsx(Icon, {
1367
+ name: action.icon,
1368
+ className: "h-3.5 w-3.5"
1369
+ }) : null, action.label]
1370
+ }, action.label))
1371
+ }) : null,
1372
+ !props.multiple && props.clearable && props.value ? /* @__PURE__ */ jsx("div", {
1373
+ className: "border-t border-solid border-foreground/10 p-1",
1374
+ children: /* @__PURE__ */ jsxs("button", {
1375
+ type: "button",
1376
+ 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",
1377
+ onMouseDown: (event) => {
1378
+ event.preventDefault();
1379
+ props.onChange("");
1380
+ close();
1381
+ },
1382
+ children: [/* @__PURE__ */ jsx(Icon, {
1383
+ name: "close",
1384
+ className: "h-3.5 w-3.5"
1385
+ }), "Clear selection"]
1386
+ })
1387
+ }) : null
1388
+ ]
1389
+ }), document.body) : null] });
1390
+ }
1391
+ function shouldPersistQuery(queryKey) {
1392
+ if (typeof queryKey[0] !== "string") return false;
1393
+ const kind = queryKind(queryKey);
1394
+ if (kind === "catalog") return queryKey.length === 2;
1395
+ if (kind === "form") {
1396
+ const block = queryKey[2];
1397
+ return Array.isArray(block) && block[0] !== "@powerhousedao/piece-core";
1398
+ }
1399
+ return false;
1400
+ }
1401
+ function persistRuntimeQueries(queryClient, url, store, now = Date.now) {
1402
+ if (!store) return {
1403
+ ready: Promise.resolve(),
1404
+ dispose: () => void 0
1405
+ };
1406
+ return {
1407
+ ready: hydrate(queryClient, url, store, now()),
1408
+ dispose: queryClient.getQueryCache().subscribe((event) => {
1409
+ if (event.type !== "updated" || event.action.type !== "success") return;
1410
+ if (event.action.manual) return;
1411
+ const { queryKey, state } = event.query;
1412
+ if (!shouldPersistQuery(queryKey) || state.data === void 0) return;
1413
+ store.save({
1414
+ id: JSON.stringify(queryKey),
1415
+ url: queryKey[0],
1416
+ queryKey,
1417
+ data: state.data,
1418
+ updatedAt: state.dataUpdatedAt,
1419
+ version: 1
1420
+ }).catch(() => void 0);
1421
+ })
1422
+ };
1423
+ }
1424
+ async function hydrate(queryClient, url, store, at) {
1425
+ let entries;
1426
+ try {
1427
+ entries = await store.load(url);
1428
+ } catch {
1429
+ return;
1430
+ }
1431
+ for (const entry of entries) {
1432
+ if (entry.version !== 1 || at - entry.updatedAt > 6048e5 || !shouldPersistQuery(entry.queryKey)) {
1433
+ store.remove(entry.id).catch(() => void 0);
1434
+ continue;
1435
+ }
1436
+ const current = queryClient.getQueryState(entry.queryKey);
1437
+ if (current && current.dataUpdatedAt >= entry.updatedAt) continue;
1438
+ queryClient.setQueryData(entry.queryKey, entry.data, { updatedAt: entry.updatedAt });
1439
+ }
1440
+ }
1441
+ const DB_NAME = "ph-workflow-runtime-cache";
1442
+ const STORE = "queries";
1443
+ function request(req) {
1444
+ return new Promise((resolve, reject) => {
1445
+ req.onsuccess = () => resolve(req.result);
1446
+ req.onerror = () => reject(req.error ?? /* @__PURE__ */ new Error("IndexedDB request failed"));
1447
+ });
1448
+ }
1449
+ function openIdbCacheStore() {
1450
+ const idb = globalThis.indexedDB;
1451
+ if (!idb) return null;
1452
+ let db;
1453
+ const open = () => {
1454
+ db ??= new Promise((resolve, reject) => {
1455
+ const req = idb.open(DB_NAME, 1);
1456
+ req.onupgradeneeded = () => {
1457
+ req.result.createObjectStore(STORE, { keyPath: "id" }).createIndex("url", "url");
1458
+ };
1459
+ req.onsuccess = () => resolve(req.result);
1460
+ req.onerror = () => reject(req.error ?? /* @__PURE__ */ new Error("IndexedDB unavailable"));
1461
+ req.onblocked = () => reject(/* @__PURE__ */ new Error("IndexedDB blocked"));
1462
+ });
1463
+ db.catch(() => db = void 0);
1464
+ return db;
1465
+ };
1466
+ const withStore = async (mode, run) => {
1467
+ return request(run((await open()).transaction(STORE, mode).objectStore(STORE)));
1468
+ };
1469
+ return {
1470
+ load: (url) => withStore("readonly", (store) => store.index("url").getAll(url)),
1471
+ save: (entry) => withStore("readwrite", (store) => store.put(entry)).then(() => void 0),
1472
+ remove: (id) => withStore("readwrite", (store) => store.delete(id)).then(() => void 0)
1473
+ };
1474
+ }
1475
+ //#endregion
1476
+ //#region editors/workflow-editor/ui/piece-source.ts
1477
+ function blockUnavailable(entry) {
1478
+ if (entry.unsupported) return entry.unsupported;
1479
+ if (entry.kind !== "trigger") return void 0;
1480
+ const strategy = checkTriggerStrategy(entry.strategy);
1481
+ return "issue" in strategy ? strategy.issue : void 0;
1482
+ }
1483
+ const PieceSourceContext = createContext(void 0);
1484
+ const PieceSourceProvider = PieceSourceContext.Provider;
1485
+ function usePieceSource() {
1486
+ return useContext(PieceSourceContext);
1487
+ }
1488
+ //#endregion
1489
+ //#region editors/workflow-editor/use-runtime-url.ts
1490
+ const SUBGRAPH_NAME = "workflow-runtime";
1491
+ function baseFromChannelUrl(channelUrl) {
1492
+ try {
1493
+ const url = new URL(channelUrl);
1494
+ url.search = "";
1495
+ url.hash = "";
1496
+ url.pathname = url.pathname.replace(/\/r\/?$/, "");
1497
+ return url.toString();
1498
+ } catch {
1499
+ return;
1500
+ }
1501
+ }
1502
+ function useWorkflowRuntimeUrl() {
1503
+ const [drive] = useSelectedDriveSafe();
1504
+ const remotes = useSyncList();
1505
+ const defaultDrivesUrl = useDefaultDrivesUrl();
1506
+ const driveId = drive?.header.id;
1507
+ return useMemo(() => {
1508
+ let base;
1509
+ if (driveId) {
1510
+ const channelUrl = (remotes.find((entry) => entry.meta.collectionId.equals(DriveCollectionId.forDrive(driveId)))?.channel)?.config.url;
1511
+ if (typeof channelUrl === "string") base = baseFromChannelUrl(channelUrl);
1512
+ }
1513
+ if (!base && defaultDrivesUrl) try {
1514
+ base = parseDriveUrl(defaultDrivesUrl).graphqlEndpoint.replace(/\/r$/, "");
1515
+ } catch {}
1516
+ return subgraphUrlFromGraphqlUrl(base ?? DEFAULT_SWITCHBOARD_URL, SUBGRAPH_NAME);
1517
+ }, [
1518
+ driveId,
1519
+ remotes,
1520
+ defaultDrivesUrl
1521
+ ]);
1522
+ }
1523
+ //#endregion
1524
+ //#region editors/workflow-editor/runtime-context.tsx
1525
+ const RuntimeContext = createContext(null);
1526
+ function runtimePieceSource(client, queryClient) {
1527
+ return {
1528
+ loadCatalog: () => queryClient.fetchQuery(catalogQuery(client)),
1529
+ reloadCatalog: () => queryClient.fetchQuery({
1530
+ ...catalogQuery(client),
1531
+ staleTime: 0
1532
+ }),
1533
+ loadActions: (packageName) => queryClient.fetchQuery(pieceActionsQuery(client, packageName)),
1534
+ loadTriggers: (packageName) => queryClient.fetchQuery(pieceTriggersQuery(client, packageName)),
1535
+ searchBlocks: (query, limit) => client.searchBlocks(query, limit)
1536
+ };
1537
+ }
1538
+ function RuntimeProvider(props) {
1539
+ const { url } = props;
1540
+ const [queryClient] = useState(createRuntimeQueryClient);
1541
+ const [store] = useState(() => props.store === void 0 ? openIdbCacheStore() : props.store);
1542
+ const client = useMemo(() => createRuntimeClient(url), [url]);
1543
+ useEffect(() => persistRuntimeQueries(queryClient, url, store).dispose, [
1544
+ queryClient,
1545
+ url,
1546
+ store
1547
+ ]);
1548
+ const value = useMemo(() => ({
1549
+ client,
1550
+ queryClient
1551
+ }), [client, queryClient]);
1552
+ const pieceSource = useMemo(() => runtimePieceSource(client, queryClient), [client, queryClient]);
1553
+ return /* @__PURE__ */ jsx(RuntimeContext.Provider, {
1554
+ value,
1555
+ children: /* @__PURE__ */ jsx(PieceSourceProvider, {
1556
+ value: pieceSource,
1557
+ children: props.children
1558
+ })
1559
+ });
1560
+ }
1561
+ function WorkflowRuntimeProvider(props) {
1562
+ const url = useWorkflowRuntimeUrl();
1563
+ return /* @__PURE__ */ jsx(RuntimeProvider, {
1564
+ url,
1565
+ children: props.children
1566
+ });
1567
+ }
1568
+ function useRuntime() {
1569
+ const context = useContext(RuntimeContext);
1570
+ if (!context) throw new Error("useRuntime needs a RuntimeProvider");
1571
+ return context;
1572
+ }
1573
+ function usePieceCatalog() {
1574
+ const { client, queryClient } = useRuntime();
1575
+ return useQuery(catalogQuery(client), queryClient);
1576
+ }
1577
+ function useRunsQuery(scope, options = {}) {
1578
+ const { client, queryClient } = useRuntime();
1579
+ return useQuery({
1580
+ ...runsQuery(client, scope),
1581
+ enabled: options.active ?? true,
1582
+ refetchInterval: options.pollMs ?? false
1583
+ }, queryClient);
1584
+ }
1585
+ function useRunPagesQuery(scope, options = {}) {
1586
+ const { client, queryClient } = useRuntime();
1587
+ return useInfiniteQuery({
1588
+ ...runPagesQuery(client, scope),
1589
+ enabled: options.active ?? true,
1590
+ refetchInterval: options.pollMs ?? false
1591
+ }, queryClient);
1592
+ }
1593
+ function useRunQuery(runId, options = {}) {
1594
+ const { client, queryClient } = useRuntime();
1595
+ return useQuery({
1596
+ ...runQuery(client, runId),
1597
+ refetchInterval: (query) => options.pollMs && query.state.data?.endedAt == null ? options.pollMs : false
1598
+ }, queryClient);
1599
+ }
1600
+ function useSecretStat(ref, enabled) {
1601
+ const { client, queryClient } = useRuntime();
1602
+ const query = useQuery({
1603
+ ...secretStatQuery(client, ref),
1604
+ enabled,
1605
+ gcTime: 0
1606
+ }, queryClient);
1607
+ if (!enabled) return null;
1608
+ if (query.status === "pending") return void 0;
1609
+ return query.status === "error" ? null : query.data;
1610
+ }
1611
+ function useOAuthRedirectUri() {
1612
+ const { client, queryClient } = useRuntime();
1613
+ return useQuery({
1614
+ queryKey: [client.url, "oauthRedirectUri"],
1615
+ queryFn: () => client.fetchOAuthRedirectUri(),
1616
+ staleTime: Infinity
1617
+ }, queryClient);
1618
+ }
1619
+ function useOAuthAttempt(state) {
1620
+ const { client, queryClient } = useRuntime();
1621
+ const query = useQuery({
1622
+ queryKey: [
1623
+ client.url,
1624
+ "oauthAttempt",
1625
+ state
1626
+ ],
1627
+ queryFn: () => client.fetchOAuthAttempt(state),
1628
+ enabled: state !== null,
1629
+ gcTime: 0,
1630
+ refetchInterval: (current) => {
1631
+ if (current.state.status === "error") return false;
1632
+ const data = current.state.data;
1633
+ if (data === null) return false;
1634
+ return data?.status === "OK" || data?.status === "ERROR" ? false : 1e3;
1635
+ }
1636
+ }, queryClient);
1637
+ if (state === null || query.isError) return null;
1638
+ return query.data;
1639
+ }
1640
+ function useRuntimeActions() {
1641
+ const { client, queryClient } = useRuntime();
1642
+ return useMemo(() => {
1643
+ const invalidate = (queryKey) => void queryClient.invalidateQueries({ queryKey });
1644
+ const runsChanged = () => {
1645
+ invalidate(runtimeKeys.allRuns(client.url));
1646
+ invalidate([client.url, "latestRun"]);
1647
+ };
1648
+ const secretSaved = (stat) => {
1649
+ queryClient.setQueryData(runtimeKeys.secret(client.url, stat.ref), stat);
1650
+ return stat;
1651
+ };
1652
+ return {
1653
+ fireWorkflow: (workflowId, payload) => client.fireWorkflow(workflowId, payload).finally(runsChanged),
1654
+ rerunRun: (runId) => client.rerunRun(runId).finally(runsChanged),
1655
+ createSecret: (value, label) => client.createSecret(value, label).then(secretSaved),
1656
+ rotateSecret: (ref, value) => client.rotateSecret(ref, value).then(secretSaved),
1657
+ checkConnection: (connectionId) => client.checkConnection(connectionId).finally(() => invalidate(runtimeKeys.connections(client.url))),
1658
+ connectionsChanged: () => invalidate(runtimeKeys.connections(client.url)),
1659
+ startOAuth: (connectionId, options) => client.startOAuth(connectionId, options)
1660
+ };
1661
+ }, [client, queryClient]);
1662
+ }
1663
+ //#endregion
1664
+ //#region editors/workflow-studio/components/run-format.ts
1665
+ const RUN_STATUSES = [
1666
+ "RUNNING",
1667
+ "SUCCEEDED",
1668
+ "FAILED"
1669
+ ];
1670
+ const TONE_TEXT = {
1671
+ ok: "text-wf-ok",
1672
+ fail: "text-wf-fail",
1673
+ warn: "text-wf-warn",
1674
+ run: "text-wf-run",
1675
+ idle: "text-muted-foreground"
1676
+ };
1677
+ const TONE_DOT = {
1678
+ ok: "bg-wf-ok",
1679
+ fail: "bg-wf-fail",
1680
+ warn: "bg-wf-warn",
1681
+ run: "bg-wf-run",
1682
+ idle: "bg-muted-foreground/40"
1683
+ };
1684
+ const RUN_TONE = {
1685
+ SUCCEEDED: "ok",
1686
+ FAILED: "fail",
1687
+ RUNNING: "run",
1688
+ WAITING: "run",
1689
+ PENDING: "idle",
1690
+ PARKED: "warn",
1691
+ CANCELLED: "idle"
1692
+ };
1693
+ const STEP_TONE = {
1694
+ ...RUN_TONE,
1695
+ SKIPPED: "idle",
1696
+ REPLAYED: "run"
1697
+ };
1698
+ function runTone(run) {
1699
+ if (run.status === "SUCCEEDED" && (run.warningNotes?.length ?? 0) > 0) return "warn";
1700
+ return toneOf(RUN_TONE, run.status);
1701
+ }
1702
+ function runStatusLabel(run) {
1703
+ const count = run.warningNotes?.length ?? 0;
1704
+ const label = statusLabel(run.status);
1705
+ if (run.status !== "SUCCEEDED" || count === 0) return label;
1706
+ return `${label}, ${count} ${count === 1 ? "warning" : "warnings"}`;
1707
+ }
1708
+ function workflowHealth(status, lastRunStatus, published) {
1709
+ if (!published) return {
1710
+ tone: "idle",
1711
+ hollow: true,
1712
+ label: "Not published yet"
1713
+ };
1714
+ const label = (status === "ENABLED" ? "" : `${statusLabel(status ?? "DISABLED")}, `) + (lastRunStatus ? `last run ${statusLabel(lastRunStatus).toLowerCase()}` : "not run yet");
1715
+ return {
1716
+ tone: toneOf(RUN_TONE, lastRunStatus),
1717
+ hollow: false,
1718
+ label: label.charAt(0).toUpperCase() + label.slice(1)
1719
+ };
1720
+ }
1721
+ const CONNECTION_TONE = {
1722
+ OK: "ok",
1723
+ ERROR: "fail",
1724
+ REVOKED: "fail",
1725
+ UNCONFIGURED: "warn"
1726
+ };
1727
+ function toneOf(map, status) {
1728
+ return (status ? map[status] : void 0) ?? "idle";
1729
+ }
1730
+ function statusLabel(status) {
1731
+ return status.charAt(0) + status.slice(1).toLowerCase();
1732
+ }
1733
+ function formatDuration(startedAt, endedAt) {
1734
+ if (!endedAt) return "…";
1735
+ return formatMs(new Date(endedAt).getTime() - new Date(startedAt).getTime());
1736
+ }
1737
+ function runTimeline(run) {
1738
+ const start = new Date(run.startedAt).getTime();
1739
+ const ends = run.steps.map((step) => step.endedAt ? new Date(step.endedAt).getTime() : 0).concat(run.endedAt ? new Date(run.endedAt).getTime() : 0);
1740
+ const total = Math.max(...ends) - start;
1741
+ const spans = /* @__PURE__ */ new Map();
1742
+ if (total <= 0) return spans;
1743
+ for (const step of run.steps) {
1744
+ if (!step.startedAt || !step.endedAt) continue;
1745
+ const from = new Date(step.startedAt).getTime() - start;
1746
+ const ms = new Date(step.endedAt).getTime() - new Date(step.startedAt).getTime();
1747
+ spans.set(step.stepId, {
1748
+ offset: Math.min(Math.max(from / total, 0), 1),
1749
+ width: Math.min(Math.max(ms / total, 0), 1),
1750
+ ms
1751
+ });
1752
+ }
1753
+ return spans;
1754
+ }
1755
+ function formatMs(ms) {
1756
+ if (ms < 1e3) return `${ms}ms`;
1757
+ const tenths = Math.round(ms / 100);
1758
+ if (tenths < 600) return `${(tenths / 10).toFixed(1)}s`;
1759
+ const seconds = Math.round(ms / 1e3);
1760
+ return `${Math.floor(seconds / 60)}m ${seconds % 60}s`;
1761
+ }
1762
+ function durationMs(startedAt, endedAt) {
1763
+ if (!endedAt) return null;
1764
+ return new Date(endedAt).getTime() - new Date(startedAt).getTime();
1765
+ }
1766
+ function formatWhen(startedAt) {
1767
+ const diff = Date.now() - new Date(startedAt).getTime();
1768
+ if (diff < 6e4) return "just now";
1769
+ if (diff < 36e5) return `${Math.floor(diff / 6e4)}m ago`;
1770
+ if (diff < 864e5) return `${Math.floor(diff / 36e5)}h ago`;
1771
+ return new Date(startedAt).toLocaleDateString();
1772
+ }
1773
+ function formatAbsolute(iso) {
1774
+ return new Date(iso).toLocaleString();
1775
+ }
1776
+ function formatTrigger(kind) {
1777
+ return kind.replace(/[-_]/g, " ").toLowerCase();
1778
+ }
1779
+ function runStats(runs) {
1780
+ const succeeded = runs.filter((run) => run.status === "SUCCEEDED").length;
1781
+ const failed = runs.filter((run) => run.status === "FAILED").length;
1782
+ const finished = succeeded + failed;
1783
+ return {
1784
+ total: runs.length,
1785
+ succeeded,
1786
+ failed,
1787
+ running: runs.filter((run) => run.status === "RUNNING").length,
1788
+ lastRun: runs[0],
1789
+ successRate: finished === 0 ? null : Math.round(succeeded / finished * 100)
1790
+ };
1791
+ }
1792
+ //#endregion
1793
+ //#region editors/workflow-editor/ui/block-meta.ts
1794
+ const CORE_META = {
1795
+ [blockKey(MANUAL_TRIGGER)]: {
1796
+ displayName: "Manual",
1797
+ subtitle: "Trigger",
1798
+ glyph: "▶"
1799
+ },
1800
+ [blockKey(SCHEDULE_TRIGGER)]: {
1801
+ displayName: "Schedule",
1802
+ subtitle: "Trigger",
1803
+ glyph: "◷"
1804
+ },
1805
+ [blockKey(WEBHOOK_TRIGGER)]: {
1806
+ displayName: "Webhook",
1807
+ subtitle: "Trigger",
1808
+ glyph: "⇲"
1809
+ },
1810
+ [blockKey(BRANCH_BLOCK)]: {
1811
+ displayName: "Branch",
1812
+ subtitle: "Core",
1813
+ glyph: "⑂"
1814
+ },
1815
+ [blockKey(ASSERT_BLOCK)]: {
1816
+ displayName: "Assert",
1817
+ subtitle: "Core",
1818
+ glyph: "!"
1819
+ }
1820
+ };
1821
+ function shortPieceName(packageName) {
1822
+ return packageName.split("/").pop()?.replace(/^piece-/, "") ?? "";
1823
+ }
1824
+ const pieceLogos = /* @__PURE__ */ new Map();
1825
+ const pieceNames = /* @__PURE__ */ new Map();
1826
+ const listeners = /* @__PURE__ */ new Set();
1827
+ let logoRevision = 0;
1828
+ function registerPieceLogos(entries) {
1829
+ let changed = false;
1830
+ for (const entry of entries) {
1831
+ if (!entry.name) continue;
1832
+ if (entry.displayName && pieceNames.get(entry.name) !== entry.displayName) {
1833
+ pieceNames.set(entry.name, entry.displayName);
1834
+ changed = true;
1835
+ }
1836
+ if (!entry.logoUrl || pieceLogos.get(entry.name) === entry.logoUrl) continue;
1837
+ pieceLogos.set(entry.name, entry.logoUrl);
1838
+ changed = true;
1839
+ }
1840
+ if (!changed) return;
1841
+ logoRevision += 1;
1842
+ for (const listener of listeners) listener();
1843
+ }
1844
+ function pieceLogo(packageName) {
1845
+ return pieceLogos.get(packageName);
1846
+ }
1847
+ function pieceDisplayName(packageName) {
1848
+ return pieceNames.get(packageName);
1849
+ }
1850
+ const blockNames = /* @__PURE__ */ new Map();
1851
+ const namesRequested = /* @__PURE__ */ new Set();
1852
+ const namesPending = /* @__PURE__ */ new Set();
1853
+ function registerBlockNames(entries) {
1854
+ let changed = false;
1855
+ for (const entry of entries) {
1856
+ const key = blockKey(entry);
1857
+ if (!entry.displayName || blockNames.get(key) === entry.displayName) continue;
1858
+ blockNames.set(key, entry.displayName);
1859
+ changed = true;
1860
+ }
1861
+ if (!changed) return;
1862
+ logoRevision += 1;
1863
+ for (const listener of listeners) listener();
1864
+ }
1865
+ function requestBlockNames(packageName) {
1866
+ if (!namesRequested.has(packageName)) namesPending.add(packageName);
1867
+ }
1868
+ function loadPendingBlockNames(source) {
1869
+ for (const packageName of namesPending) loadBlockNames(source, packageName);
1870
+ namesPending.clear();
1871
+ }
1872
+ function loadBlockNames(source, packageName) {
1873
+ if (namesRequested.has(packageName)) return;
1874
+ namesRequested.add(packageName);
1875
+ Promise.all([source.loadActions(packageName), source.loadTriggers(packageName)]).then(([actions, triggers]) => registerBlockNames([...actions.map((entry) => ({
1876
+ ...entry,
1877
+ kind: "action"
1878
+ })), ...triggers.map((entry) => ({
1879
+ ...entry,
1880
+ kind: "trigger"
1881
+ }))])).catch(() => namesRequested.delete(packageName));
1882
+ }
1883
+ function subscribePieceLogos(listener) {
1884
+ listeners.add(listener);
1885
+ return () => listeners.delete(listener);
1886
+ }
1887
+ function pieceLogoRevision() {
1888
+ return logoRevision;
1889
+ }
1890
+ const logoMisses = /* @__PURE__ */ new Set();
1891
+ let catalogLoads = /* @__PURE__ */ new WeakMap();
1892
+ const retryTimers = /* @__PURE__ */ new Set();
1893
+ const CATALOG_RETRY_MS = 2e3;
1894
+ function notify() {
1895
+ logoRevision += 1;
1896
+ for (const listener of listeners) listener();
1897
+ }
1898
+ function scheduleRetry(state) {
1899
+ if (state.attempts >= 5) return;
1900
+ const timer = setTimeout(() => {
1901
+ retryTimers.delete(timer);
1902
+ state.load = void 0;
1903
+ notify();
1904
+ }, CATALOG_RETRY_MS * 2 ** (state.attempts - 1));
1905
+ retryTimers.add(timer);
1906
+ }
1907
+ function ensurePieceLogos(source) {
1908
+ if (!source) return Promise.resolve();
1909
+ let state = catalogLoads.get(source);
1910
+ if (!state) {
1911
+ state = { attempts: 0 };
1912
+ catalogLoads.set(source, state);
1913
+ }
1914
+ if (state.load) return state.load;
1915
+ const current = state;
1916
+ const request = current.attempts > 0 && source.reloadCatalog ? source.reloadCatalog() : source.loadCatalog();
1917
+ current.attempts += 1;
1918
+ current.load = request.then((pieces) => {
1919
+ registerPieceLogos(pieces);
1920
+ const listed = new Set(pieces.map((piece) => piece.name));
1921
+ if ([...logoMisses].some((name) => !listed.has(name) && !pieceLogos.has(name))) scheduleRetry(current);
1922
+ }, () => scheduleRetry(current));
1923
+ return current.load;
1924
+ }
1925
+ function blockMeta(block) {
1926
+ const key = blockKey(block);
1927
+ const core = CORE_META[key];
1928
+ if (core) return core;
1929
+ if (isCoreBlock(block)) return {
1930
+ displayName: titleCase(block.name),
1931
+ subtitle: "Core",
1932
+ glyph: "?"
1933
+ };
1934
+ const packageName = block.pieceName;
1935
+ const short = shortPieceName(packageName);
1936
+ const pieceLabel = pieceNames.get(packageName) ?? titleCase(short);
1937
+ const known = blockNames.get(key);
1938
+ if (!known) requestBlockNames(packageName);
1939
+ const logoUrl = pieceLogo(packageName);
1940
+ if (!logoUrl) logoMisses.add(packageName);
1941
+ return {
1942
+ displayName: known ?? titleCase(block.name),
1943
+ subtitle: block.kind === "trigger" ? `${pieceLabel} · Trigger` : pieceLabel,
1944
+ logoUrl,
1945
+ glyph: short.slice(0, 1).toUpperCase() || "?"
1946
+ };
1947
+ }
1948
+ function titleCase(value) {
1949
+ return value.replaceAll(/[-_]/g, " ").replace(/^\w/, (char) => char.toUpperCase());
1950
+ }
1951
+ function usePieceLogos() {
1952
+ const source = usePieceSource();
1953
+ const revision = useSyncExternalStore(subscribePieceLogos, pieceLogoRevision, pieceLogoRevision);
1954
+ useEffect(() => {
1955
+ ensurePieceLogos(source);
1956
+ if (source && namesPending.size > 0) loadPendingBlockNames(source);
1957
+ });
1958
+ return revision;
1959
+ }
1960
+ function useBlockMeta(block) {
1961
+ usePieceLogos();
1962
+ return blockMeta(block);
1963
+ }
1964
+ //#endregion
1965
+ //#region editors/workflow-editor/ui/validation.ts
1966
+ function isEmptyValue(value) {
1967
+ if (value === void 0 || value === null) return true;
1968
+ if (typeof value === "string") return value.trim() === "";
1969
+ if (Array.isArray(value)) return value.length === 0;
1970
+ return false;
1971
+ }
1972
+ function isPropVisible(prop, config) {
1973
+ const rule = prop.showWhen;
1974
+ if (!rule) return true;
1975
+ return rule.oneOf.includes(config[rule.prop] ?? void 0);
1976
+ }
1977
+ function asRecord(config) {
1978
+ return config !== null && typeof config === "object" && !Array.isArray(config) ? config : {};
1979
+ }
1980
+ function missingRequired(props, config) {
1981
+ const record = asRecord(config);
1982
+ return props.filter((prop) => prop.required && prop.type !== "MARKDOWN" && isPropVisible(prop, record) && isEmptyValue(record[prop.name])).map((prop) => prop.displayName);
1983
+ }
1984
+ function resolverInputFor(block, prop, config, connectionId) {
1985
+ const refreshers = (prop.refreshers ?? []).filter((name) => name !== "auth");
1986
+ return {
1987
+ block,
1988
+ propName: prop.name,
1989
+ refreshers: refreshers.map((name) => config[name] ?? null),
1990
+ connectionId: connectionId ?? null
1991
+ };
1992
+ }
1993
+ function settingFor(settings, prop) {
1994
+ return settings?.find((setting) => setting.prop === prop);
1995
+ }
1996
+ function parsePropList(result) {
1997
+ if (!Array.isArray(result)) throw new Error("Unexpected properties result");
1998
+ return result.filter((entry) => entry !== null && typeof entry === "object" && typeof entry.name === "string");
1999
+ }
2000
+ function storedSchema(settings, prop) {
2001
+ const schema = settingFor(settings, prop)?.schema;
2002
+ if (!Array.isArray(schema)) return void 0;
2003
+ return schema.filter((entry) => entry !== null && typeof entry === "object" && typeof entry.name === "string");
2004
+ }
2005
+ function stripOptions(props) {
2006
+ return props.map((prop) => {
2007
+ const { staticOptions: _options, properties, ...rest } = prop;
2008
+ return properties ? {
2009
+ ...rest,
2010
+ properties: stripOptions(properties)
2011
+ } : rest;
2012
+ });
2013
+ }
2014
+ function withSetting(settings, prop, patch) {
2015
+ const list = [...settings ?? []];
2016
+ const index = list.findIndex((setting) => setting.prop === prop);
2017
+ const current = index >= 0 ? list[index] : {
2018
+ prop,
2019
+ mode: "MANUAL"
2020
+ };
2021
+ const next = {
2022
+ prop,
2023
+ mode: patch.mode ?? current.mode,
2024
+ schema: "schema" in patch ? patch.schema ?? null : current.schema ?? null
2025
+ };
2026
+ if (index >= 0) list[index] = next;
2027
+ else list.push(next);
2028
+ return list;
2029
+ }
2030
+ function blockMissing(input) {
2031
+ if (input.skip) return [];
2032
+ const { form } = input;
2033
+ if (!form || form === "loading") return null;
2034
+ const record = asRecord(input.config);
2035
+ const missing = [];
2036
+ let unknown = false;
2037
+ if (form.auth === "required" && !input.connectionId) missing.push("Connection");
2038
+ for (const prop of form.props) {
2039
+ if (prop.type === "MARKDOWN" || !isPropVisible(prop, record)) continue;
2040
+ const value = record[prop.name];
2041
+ const bound = settingFor(input.propertySettings, prop.name)?.mode === "EXPRESSION";
2042
+ if (prop.type !== "DYNAMIC" || bound) {
2043
+ if (prop.required && isEmptyValue(value)) missing.push(prop.displayName);
2044
+ continue;
2045
+ }
2046
+ const children = input.resolveDynamic?.(resolverInputFor(input.block, prop, record, input.connectionId)) ?? storedSchema(input.propertySettings, prop.name);
2047
+ if (children === void 0) {
2048
+ unknown = true;
2049
+ continue;
2050
+ }
2051
+ missing.push(...missingRequired(children, value));
2052
+ }
2053
+ if (missing.length > 0) return missing;
2054
+ if (form.display === "schedule") {
2055
+ const issue = scheduleConfigIssue(input.config);
2056
+ if (issue) return [issue.replace(/^Schedule: /, "")];
2057
+ }
2058
+ return unknown ? null : [];
2059
+ }
2060
+ function undeclaredPortIssues(form, outgoingPorts) {
2061
+ const ports = form && form !== "loading" ? form.ports : void 0;
2062
+ if (!ports || !outgoingPorts) return [];
2063
+ return [...new Set(outgoingPorts)].filter((port) => !ports.includes(port)).map((port) => `An edge leaves on "${port}", which this block never takes`);
2064
+ }
2065
+ function workflowReadiness(blocks, hasTrigger) {
2066
+ const firstIncomplete = blocks.find((block) => block.missing && block.missing.length > 0)?.id ?? null;
2067
+ const checking = blocks.some((block) => block.missing === null);
2068
+ return {
2069
+ ready: hasTrigger && !checking && firstIncomplete === null,
2070
+ hasTrigger,
2071
+ firstIncomplete,
2072
+ checking
2073
+ };
2074
+ }
2075
+ //#endregion
2076
+ //#region editors/workflow-editor/ui/design-time.tsx
2077
+ const DesignTimeContext = createContext(null);
2078
+ function DesignTimeProvider(props) {
2079
+ const { service, queryClient, scope } = props;
2080
+ const value = useMemo(() => ({
2081
+ service,
2082
+ queryClient,
2083
+ scope
2084
+ }), [
2085
+ service,
2086
+ queryClient,
2087
+ scope
2088
+ ]);
2089
+ return /* @__PURE__ */ jsx(DesignTimeContext.Provider, {
2090
+ value,
2091
+ children: props.children
2092
+ });
2093
+ }
2094
+ function useDesignTime() {
2095
+ return useContext(DesignTimeContext)?.service;
2096
+ }
2097
+ function useDesignTimeScope() {
2098
+ const context = useContext(DesignTimeContext);
2099
+ const [detached] = useState(() => context ? null : {
2100
+ queryClient: new QueryClient(),
2101
+ scope: ""
2102
+ });
2103
+ return context ?? detached;
2104
+ }
2105
+ function messageOf(error) {
2106
+ return error instanceof Error ? error.message : String(error);
2107
+ }
2108
+ function useBlockForm(block) {
2109
+ const { service, queryClient, scope } = useDesignTimeScope();
2110
+ const query = useQuery({
2111
+ queryKey: runtimeKeys.form(scope, block),
2112
+ queryFn: () => service.getBlockForm(block),
2113
+ enabled: Boolean(service),
2114
+ staleTime: SHARED_STALE_MS
2115
+ }, queryClient);
2116
+ if (!service) return { form: null };
2117
+ if (query.data !== void 0) return { form: query.data };
2118
+ if (query.status === "error") return {
2119
+ form: null,
2120
+ error: messageOf(query.error)
2121
+ };
2122
+ return { form: "loading" };
2123
+ }
2124
+ function formQuery(service, scope, block) {
2125
+ return {
2126
+ queryKey: runtimeKeys.form(scope, block),
2127
+ queryFn: () => service.getBlockForm(block),
2128
+ staleTime: SHARED_STALE_MS
2129
+ };
2130
+ }
2131
+ function useBlockFormLoader() {
2132
+ const { service, queryClient, scope } = useDesignTimeScope();
2133
+ return useMemo(() => async (block) => {
2134
+ if (!service) return null;
2135
+ try {
2136
+ return await queryClient.fetchQuery(formQuery(service, scope, block));
2137
+ } catch {
2138
+ return null;
2139
+ }
2140
+ }, [
2141
+ service,
2142
+ queryClient,
2143
+ scope
2144
+ ]);
2145
+ }
2146
+ function useCachedBlockForm() {
2147
+ const { queryClient, scope } = useDesignTimeScope();
2148
+ return useMemo(() => (block) => queryClient.getQueryData(runtimeKeys.form(scope, block)), [queryClient, scope]);
2149
+ }
2150
+ function useBlockFormPrefetch() {
2151
+ const { service, queryClient, scope } = useDesignTimeScope();
2152
+ return useMemo(() => (block) => {
2153
+ if (!service) return;
2154
+ queryClient.prefetchQuery(formQuery(service, scope, block));
2155
+ }, [
2156
+ service,
2157
+ queryClient,
2158
+ scope
2159
+ ]);
2160
+ }
2161
+ function useBlockForms(blocks) {
2162
+ const { service, queryClient, scope } = useDesignTimeScope();
2163
+ const unique = [...new Map(blocks.map((block) => [blockRefKey(block), block])).values()];
2164
+ const results = useQueries({ queries: unique.map((block) => ({
2165
+ queryKey: runtimeKeys.form(scope, block),
2166
+ queryFn: () => service.getBlockForm(block),
2167
+ enabled: Boolean(service),
2168
+ staleTime: SHARED_STALE_MS
2169
+ })) }, queryClient);
2170
+ const forms = /* @__PURE__ */ new Map();
2171
+ unique.forEach((block, index) => {
2172
+ const query = results[index];
2173
+ forms.set(blockRefKey(block), !service ? null : query.data !== void 0 ? query.data : query.status === "error" ? null : "loading");
2174
+ });
2175
+ return forms;
2176
+ }
2177
+ function useBlockPorts(blocks) {
2178
+ const forms = useBlockForms(blocks);
2179
+ return (block) => {
2180
+ const form = forms.get(blockRefKey(block));
2181
+ return form && form !== "loading" ? form.ports : void 0;
2182
+ };
2183
+ }
2184
+ function keyHash(value) {
2185
+ try {
2186
+ return JSON.stringify(value);
2187
+ } catch {
2188
+ return String(value);
2189
+ }
2190
+ }
2191
+ function useSettled(value, ms) {
2192
+ const hash = keyHash(value);
2193
+ const latest = useRef(value);
2194
+ useEffect(() => {
2195
+ latest.current = value;
2196
+ });
2197
+ const [settled, setSettled] = useState({
2198
+ hash,
2199
+ value
2200
+ });
2201
+ useEffect(() => {
2202
+ if (hash === settled.hash) return;
2203
+ const timer = setTimeout(() => setSettled({
2204
+ hash,
2205
+ value: latest.current
2206
+ }), ms);
2207
+ return () => clearTimeout(timer);
2208
+ }, [
2209
+ hash,
2210
+ settled.hash,
2211
+ ms
2212
+ ]);
2213
+ return settled.value;
2214
+ }
2215
+ function useResolvedProp(options) {
2216
+ const { queryClient, scope } = useDesignTimeScope();
2217
+ const input = useSettled(options.input, options.debounceMs);
2218
+ const loadRef = useRef(options);
2219
+ useEffect(() => {
2220
+ loadRef.current = options;
2221
+ });
2222
+ const enabled = Boolean(options.load);
2223
+ const query = useQuery({
2224
+ queryKey: runtimeKeys[options.kind](scope, input),
2225
+ queryFn: async () => {
2226
+ const current = loadRef.current;
2227
+ if (!current.load) throw new Error("No resolver");
2228
+ return current.parse(await current.load());
2229
+ },
2230
+ enabled,
2231
+ staleTime: RESOLVER_STALE_MS
2232
+ }, queryClient);
2233
+ const reload = () => void query.refetch();
2234
+ if (!enabled) return {
2235
+ state: { kind: "idle" },
2236
+ reload
2237
+ };
2238
+ if (query.isFetching) return {
2239
+ state: { kind: "loading" },
2240
+ reload
2241
+ };
2242
+ if (query.status === "error") return {
2243
+ state: {
2244
+ kind: "error",
2245
+ message: messageOf(query.error)
2246
+ },
2247
+ reload
2248
+ };
2249
+ if (query.status === "success") return {
2250
+ state: {
2251
+ kind: "ready",
2252
+ result: query.data
2253
+ },
2254
+ reload
2255
+ };
2256
+ return {
2257
+ state: { kind: "loading" },
2258
+ reload
2259
+ };
2260
+ }
2261
+ function useOptionSearch(options) {
2262
+ const { queryClient, scope } = useDesignTimeScope();
2263
+ const typed = options.query.trim() === "" ? "" : options.query;
2264
+ const settled = useSettled(typed, options.debounceMs);
2265
+ const loadRef = useRef(options);
2266
+ useEffect(() => {
2267
+ loadRef.current = options;
2268
+ });
2269
+ const query = useQuery({
2270
+ queryKey: runtimeKeys.options(scope, {
2271
+ ...options.input,
2272
+ searchValue: settled
2273
+ }),
2274
+ queryFn: async () => {
2275
+ const current = loadRef.current;
2276
+ if (!current.load) throw new Error("No resolver");
2277
+ return current.parse(await current.load(settled));
2278
+ },
2279
+ enabled: Boolean(options.load) && settled !== "" && typed !== "",
2280
+ staleTime: RESOLVER_STALE_MS,
2281
+ placeholderData: keepPreviousData
2282
+ }, queryClient);
2283
+ return typed === "" ? null : query.data ?? null;
2284
+ }
2285
+ function getResolvedDynamicProps(queryClient, scope, input) {
2286
+ return queryClient.getQueryData(runtimeKeys.dynamic(scope, input));
2287
+ }
2288
+ function useDynamicPrefetch() {
2289
+ const { service, queryClient, scope } = useDesignTimeScope();
2290
+ return useMemo(() => (input, config) => {
2291
+ if (!service) return;
2292
+ queryClient.prefetchQuery({
2293
+ queryKey: runtimeKeys.dynamic(scope, input),
2294
+ queryFn: () => service.loadOptions(input.block, input.propName, config, input.connectionId ?? void 0).then(parsePropList),
2295
+ staleTime: RESOLVER_STALE_MS
2296
+ });
2297
+ }, [
2298
+ service,
2299
+ queryClient,
2300
+ scope
2301
+ ]);
2302
+ }
2303
+ function useDynamicCache() {
2304
+ const { queryClient, scope } = useDesignTimeScope();
2305
+ return useMemo(() => (input) => getResolvedDynamicProps(queryClient, scope, input), [queryClient, scope]);
2306
+ }
2307
+ function useDynamicLookup() {
2308
+ const { queryClient, scope } = useDesignTimeScope();
2309
+ const [version, setVersion] = useState(0);
2310
+ useEffect(() => queryClient.getQueryCache().subscribe((event) => {
2311
+ if (event.type !== "updated") return;
2312
+ const key = event.query.queryKey;
2313
+ if (key[0] === scope && key[1] === "dynamic") setVersion((v) => v + 1);
2314
+ }), [queryClient, scope]);
2315
+ return useMemo(() => (input) => version >= 0 ? getResolvedDynamicProps(queryClient, scope, input) : void 0, [
2316
+ queryClient,
2317
+ scope,
2318
+ version
2319
+ ]);
2320
+ }
2321
+ function useRunById(runId) {
2322
+ const { service, queryClient, scope } = useDesignTimeScope();
2323
+ const fetchRun = service?.fetchRun;
2324
+ const query = useQuery({
2325
+ queryKey: runtimeKeys.run(scope, runId ?? ""),
2326
+ queryFn: () => fetchRun(runId),
2327
+ enabled: Boolean(fetchRun && runId),
2328
+ staleTime: Infinity
2329
+ }, queryClient);
2330
+ if (!runId) return null;
2331
+ return query.data;
2332
+ }
2333
+ function useLatestRun(enabled = true) {
2334
+ const { service, queryClient, scope } = useDesignTimeScope();
2335
+ const active = enabled && Boolean(service?.latestRun);
2336
+ const query = useQuery({
2337
+ queryKey: runtimeKeys.latestRun(scope, service?.workflowId ?? ""),
2338
+ queryFn: () => service.latestRun(),
2339
+ enabled: active,
2340
+ staleTime: 0
2341
+ }, queryClient);
2342
+ if (!active) return null;
2343
+ if (query.status === "pending") return { kind: "loading" };
2344
+ return {
2345
+ kind: "ready",
2346
+ run: query.data ?? null
2347
+ };
2348
+ }
2349
+ const SYNC_RETRIES = 5;
2350
+ const SYNC_RETRY_MS = 2e3;
2351
+ function useWebhookEndpoint(enabled) {
2352
+ const { service, queryClient, scope } = useDesignTimeScope();
2353
+ const active = enabled && Boolean(service?.webhookEndpoint);
2354
+ const query = useQuery({
2355
+ queryKey: runtimeKeys.webhook(scope, service?.workflowId ?? ""),
2356
+ queryFn: () => service.webhookEndpoint(),
2357
+ enabled: active,
2358
+ staleTime: 0,
2359
+ gcTime: 0,
2360
+ retry: (failures, error) => isSyncingError(error) && failures < SYNC_RETRIES,
2361
+ retryDelay: SYNC_RETRY_MS
2362
+ }, queryClient);
2363
+ if (query.status === "pending" && isSyncingError(query.failureReason)) return { kind: "syncing" };
2364
+ if (query.status === "error") return {
2365
+ kind: "error",
2366
+ message: messageOf(query.error)
2367
+ };
2368
+ if (query.status === "pending") return { kind: "loading" };
2369
+ return query.data ? {
2370
+ kind: "ready",
2371
+ endpoint: query.data
2372
+ } : { kind: "empty" };
2373
+ }
2374
+ function useConnectionList() {
2375
+ const { service, queryClient, scope } = useDesignTimeScope();
2376
+ const list = service?.listConnections;
2377
+ const options = {
2378
+ queryKey: runtimeKeys.connections(scope, service?.connectionScope ?? null),
2379
+ queryFn: () => list(),
2380
+ staleTime: 0,
2381
+ gcTime: 0
2382
+ };
2383
+ const query = useQuery({
2384
+ ...options,
2385
+ enabled: Boolean(list)
2386
+ }, queryClient);
2387
+ return {
2388
+ connections: query.data ?? [],
2389
+ refetch: () => {
2390
+ if (list) query.refetch();
2391
+ },
2392
+ invalidate: () => void queryClient.invalidateQueries({ queryKey: runtimeKeys.connections(scope) }),
2393
+ fetchNow: () => list ? queryClient.fetchQuery({
2394
+ ...options,
2395
+ staleTime: 0
2396
+ }) : Promise.resolve([])
2397
+ };
2398
+ }
2399
+ function useTestStepRunner() {
2400
+ const { service, queryClient, scope } = useDesignTimeScope();
2401
+ const test = service?.testStep;
2402
+ if (!test) return void 0;
2403
+ return (stepId) => test(stepId).finally(() => {
2404
+ for (const queryKey of [
2405
+ runtimeKeys.allRuns(scope),
2406
+ [scope, "latestRun"],
2407
+ runtimeKeys.outputTrees(scope)
2408
+ ]) queryClient.invalidateQueries({ queryKey });
2409
+ });
2410
+ }
2411
+ function useTestTrigger() {
2412
+ const { service, queryClient, scope } = useDesignTimeScope();
2413
+ const test = service?.testTrigger;
2414
+ if (!test) return void 0;
2415
+ return () => test().finally(() => void queryClient.invalidateQueries({ queryKey: runtimeKeys.outputTrees(scope) }));
2416
+ }
2417
+ var DraftNotSynced = class extends Error {};
2418
+ const DRAFT_SYNC_RETRIES = 10;
2419
+ /**
2420
+ * The piece version each draft block runs, trigger first; `blocks` is the
2421
+ * draft in that order. Empty outside a runtime, or until the runtime answers.
2422
+ */
2423
+ function useBlockResolutions(workflowId, blocks) {
2424
+ const { service, queryClient, scope } = useDesignTimeScope();
2425
+ const fetchResolutions = service?.blockResolutions;
2426
+ const expected = blocks.map((entry) => `${entry.id}=${blockRefKey(entry.block)}`);
2427
+ return useQuery({
2428
+ queryKey: runtimeKeys.blockResolutions(scope, workflowId, blocks.map((entry) => entry.block)),
2429
+ queryFn: async () => {
2430
+ const resolutions = await fetchResolutions();
2431
+ if (keyHash(resolutions.map((resolution) => `${resolution.stepId}=${blockRefKey(resolution)}`)) !== keyHash(expected)) throw new DraftNotSynced();
2432
+ return resolutions;
2433
+ },
2434
+ enabled: Boolean(fetchResolutions && workflowId),
2435
+ retry: (count, error) => error instanceof DraftNotSynced && count < DRAFT_SYNC_RETRIES,
2436
+ retryDelay: 300,
2437
+ placeholderData: keepPreviousData,
2438
+ staleTime: 0
2439
+ }, queryClient).data ?? EMPTY_RESOLUTIONS;
2440
+ }
2441
+ const EMPTY_RESOLUTIONS = [];
2442
+ //#endregion
2443
+ //#region editors/workflow-editor/ui/version-badge.tsx
2444
+ function resolutionText(resolution) {
2445
+ if (resolution.note) return resolution.note;
2446
+ if (!resolution.resolvedVersion) return `Nothing resolves ${resolution.pieceName} ${resolution.kind} "${resolution.name}"`;
2447
+ const from = resolution.source ? ` from ${resolution.source}` : "";
2448
+ return `Configured with v${resolution.pieceVersion}, runs v${resolution.resolvedVersion}${from}`;
2449
+ }
2450
+ function runsDifferentVersion(resolution) {
2451
+ switch (resolution.match) {
2452
+ case "exact": return false;
2453
+ case "installed": return resolution.resolvedVersion !== resolution.pieceVersion;
2454
+ default: return true;
2455
+ }
2456
+ }
2457
+ function versionBadge(resolution) {
2458
+ if (!resolution || !runsDifferentVersion(resolution)) return null;
2459
+ const title = resolutionText(resolution);
2460
+ if (resolution.match === "missing") return {
2461
+ tone: "fail",
2462
+ label: "Missing",
2463
+ title
2464
+ };
2465
+ return {
2466
+ tone: resolution.match === "fallback" ? "warn" : "neutral",
2467
+ label: `v${resolution.resolvedVersion}`,
2468
+ title
2469
+ };
2470
+ }
2471
+ /** The newer version to offer, when a source has one above the pin. */
2472
+ function updateVersion(resolution) {
2473
+ const { pieceVersion, latestVersion } = resolution ?? {};
2474
+ if (!pieceVersion || !latestVersion) return null;
2475
+ try {
2476
+ return compareVersions(latestVersion, pieceVersion) > 0 ? latestVersion : null;
2477
+ } catch {
2478
+ return null;
2479
+ }
2480
+ }
2481
+ const ResolutionsContext = createContext([]);
2482
+ const DraftBlocksContext = createContext([]);
2483
+ function BlockResolutionsProvider(props) {
2484
+ return /* @__PURE__ */ jsx(DraftBlocksContext.Provider, {
2485
+ value: props.blocks,
2486
+ children: /* @__PURE__ */ jsx(ResolutionsContext.Provider, {
2487
+ value: props.resolutions,
2488
+ children: props.children
2489
+ })
2490
+ });
2491
+ }
2492
+ function useDraftBlocks() {
2493
+ return useContext(DraftBlocksContext);
2494
+ }
2495
+ function useResolution(id, block) {
2496
+ return useContext(ResolutionsContext).find((entry) => entry.stepId === id && entry.pieceName === block.pieceName && entry.pieceVersion === block.pieceVersion && entry.kind === block.kind && entry.name === block.name);
2497
+ }
2498
+ const SUMMARY_TONE = {
2499
+ neutral: "text-muted-foreground hover:text-foreground",
2500
+ warn: "text-wf-warn"
2501
+ };
2502
+ function versionSummary(resolutions) {
2503
+ const differing = resolutions.filter(runsDifferentVersion);
2504
+ if (differing.length === 0) return null;
2505
+ const missing = differing.filter((entry) => entry.match === "missing");
2506
+ const count = missing.length > 0 ? missing.length : differing.length;
2507
+ const noun = count === 1 ? "step" : "steps";
2508
+ return {
2509
+ text: missing.length > 0 ? `${count} ${noun} can't find ${count === 1 ? "its" : "their"} piece` : `${count} ${noun} ${count === 1 ? "runs" : "run"} a different piece version`,
2510
+ tone: differing.some((entry) => entry.match === "fallback" || entry.match === "missing") ? "warn" : "neutral",
2511
+ title: differing.map(resolutionText).join("\n"),
2512
+ firstStepId: (missing.length > 0 ? missing : differing)[0].stepId
2513
+ };
2514
+ }
2515
+ function VersionSummary(props) {
2516
+ const summary = versionSummary(props.resolutions);
2517
+ if (!summary) return null;
2518
+ return /* @__PURE__ */ jsx("button", {
2519
+ type: "button",
2520
+ "data-tone": summary.tone,
2521
+ className: `truncate text-xs underline-offset-2 hover:underline ${SUMMARY_TONE[summary.tone]}`,
2522
+ title: summary.title,
2523
+ onClick: () => props.onSelect(summary.firstStepId),
2524
+ children: summary.text
2525
+ });
2526
+ }
2527
+ //#endregion
2528
+ //#region editors/workflow-editor/ui/BlockSelector.tsx
2529
+ const ROW_LOGO = 24;
2530
+ const CORE_TILE = {
2531
+ [blockKey(MANUAL_TRIGGER)]: {
2532
+ icon: "play",
2533
+ color: "#2563eb"
2534
+ },
2535
+ [blockKey(SCHEDULE_TRIGGER)]: {
2536
+ icon: "clock",
2537
+ color: "#7c3aed"
2538
+ },
2539
+ [blockKey(WEBHOOK_TRIGGER)]: {
2540
+ icon: "bolt",
2541
+ color: "#0891b2"
2542
+ },
2543
+ [blockKey(BRANCH_BLOCK)]: {
2544
+ icon: "branch",
2545
+ color: "#d97706"
2546
+ },
2547
+ [blockKey(ASSERT_BLOCK)]: {
2548
+ icon: "alert",
2549
+ color: "#dc2626"
2550
+ }
2551
+ };
2552
+ function CoreTile(props) {
2553
+ const tile = props.tile;
2554
+ const glyph = Math.round(props.size * (props.bare ? .9 : .55));
2555
+ if (props.bare) return /* @__PURE__ */ jsx("span", {
2556
+ className: "flex shrink-0 items-center justify-center",
2557
+ style: {
2558
+ width: props.size,
2559
+ height: props.size,
2560
+ color: tile.color
2561
+ },
2562
+ children: /* @__PURE__ */ jsx(Icon, {
2563
+ name: tile.icon,
2564
+ size: glyph
2565
+ })
2566
+ });
2567
+ return /* @__PURE__ */ jsx("span", {
2568
+ className: "flex shrink-0 items-center justify-center rounded-[22%] text-white",
2569
+ style: {
2570
+ width: props.size,
2571
+ height: props.size,
2572
+ backgroundColor: tile.color
2573
+ },
2574
+ children: /* @__PURE__ */ jsx(Icon, {
2575
+ name: tile.icon,
2576
+ size: glyph
2577
+ })
2578
+ });
2579
+ }
2580
+ function BlockLogo(props) {
2581
+ const meta = useBlockMeta(props.block);
2582
+ const tile = CORE_TILE[blockKey(props.block)];
2583
+ if (tile) return /* @__PURE__ */ jsx(CoreTile, {
2584
+ tile,
2585
+ size: props.size ?? 36,
2586
+ bare: props.bare
2587
+ });
2588
+ return /* @__PURE__ */ jsx(LogoFrame, {
2589
+ src: meta.logoUrl,
2590
+ alt: meta.displayName,
2591
+ size: props.size ?? 36,
2592
+ glyph: meta.glyph,
2593
+ bare: props.bare
2594
+ });
2595
+ }
2596
+ function GlyphBadge(props) {
2597
+ return /* @__PURE__ */ jsx("div", {
2598
+ className: "flex shrink-0 items-center justify-center rounded-sm border border-solid border-foreground/10 bg-muted/50 text-muted-foreground",
2599
+ style: {
2600
+ width: props.size,
2601
+ height: props.size,
2602
+ fontSize: props.size / 2
2603
+ },
2604
+ children: props.glyph ?? "?"
2605
+ });
2606
+ }
2607
+ function LogoFrame(props) {
2608
+ const [broken, setBroken] = useState(false);
2609
+ useEffect(() => {
2610
+ setBroken(false);
2611
+ }, [props.src]);
2612
+ if (!props.src || broken) return /* @__PURE__ */ jsx(GlyphBadge, {
2613
+ glyph: props.glyph,
2614
+ size: props.size
2615
+ });
2616
+ return /* @__PURE__ */ jsx("div", {
2617
+ className: `flex shrink-0 items-center justify-center ${props.bare ? "" : "dark:rounded-[22%] dark:bg-white dark:p-[var(--logo-pad)]"}`,
2618
+ style: {
2619
+ width: props.size,
2620
+ height: props.size,
2621
+ "--logo-pad": `${Math.round(props.size * .12)}px`
2622
+ },
2623
+ children: /* @__PURE__ */ jsx("img", {
2624
+ src: props.src,
2625
+ alt: props.alt,
2626
+ className: "h-full w-full object-contain drop-shadow-sm",
2627
+ onError: () => setBroken(true)
2628
+ })
2629
+ });
2630
+ }
2631
+ function Row(props) {
2632
+ return /* @__PURE__ */ jsxs("button", {
2633
+ type: "button",
2634
+ 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"}`,
2635
+ disabled: props.disabled,
2636
+ onClick: props.onClick,
2637
+ onMouseEnter: props.onHover,
2638
+ onFocus: props.onHover,
2639
+ children: [
2640
+ props.logo,
2641
+ /* @__PURE__ */ jsxs("span", {
2642
+ className: "min-w-0",
2643
+ children: [/* @__PURE__ */ jsx("span", {
2644
+ className: "block truncate text-xs font-medium text-foreground",
2645
+ children: props.label
2646
+ }), /* @__PURE__ */ jsx("span", {
2647
+ className: "block truncate text-[11px] text-muted-foreground/80",
2648
+ children: props.description
2649
+ })]
2650
+ }),
2651
+ props.version ? /* @__PURE__ */ jsxs("span", {
2652
+ 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"}`,
2653
+ title: props.versionNote ?? `Pinned to version ${props.version}`,
2654
+ children: ["v", props.version]
2655
+ }) : null
2656
+ ]
2657
+ });
2658
+ }
2659
+ function shownVersion(pieceName, version) {
2660
+ return isCoreBlock({ pieceName }) ? void 0 : version;
2661
+ }
2662
+ function useVersionNote(catalog) {
2663
+ const draft = useDraftBlocks();
2664
+ return (piece, version) => {
2665
+ if (!piece || !version) return void 0;
2666
+ const others = [...new Set(draft.filter((block) => block.pieceName === piece && block.pieceVersion !== version).map((block) => `v${block.pieceVersion}`))];
2667
+ if (others.length > 0) return `Other steps of this workflow use ${others.join(", ")}`;
2668
+ const published = catalog?.find((entry) => entry.name === piece)?.publishedVersion;
2669
+ return published && published !== version ? `A local build; v${published} is published` : void 0;
2670
+ };
2671
+ }
2672
+ function SectionLabel(props) {
2673
+ return /* @__PURE__ */ jsx("div", {
2674
+ className: "px-3 pb-0.5 pt-2 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground/60",
2675
+ children: props.children
2676
+ });
2677
+ }
2678
+ const CATEGORY_LABELS = {
2679
+ ARTIFICIAL_INTELLIGENCE: "AI",
2680
+ UNIVERSAL_AI: "AI",
2681
+ PRODUCTIVITY: "Productivity",
2682
+ MARKETING: "Marketing",
2683
+ COMMUNICATION: "Communication",
2684
+ SALES_AND_CRM: "Sales & CRM",
2685
+ DEVELOPER_TOOLS: "Developer tools",
2686
+ CONTENT_AND_FILES: "Content & files",
2687
+ BUSINESS_INTELLIGENCE: "Business intelligence",
2688
+ CORE: "Utilities",
2689
+ FLOW_CONTROL: "Utilities",
2690
+ COMMERCE: "Commerce",
2691
+ FORMS_AND_SURVEYS: "Forms & surveys",
2692
+ ACCOUNTING: "Accounting",
2693
+ CUSTOMER_SUPPORT: "Customer support",
2694
+ PAYMENT_PROCESSING: "Payments",
2695
+ HUMAN_RESOURCES: "HR"
2696
+ };
2697
+ const CORE_CHIP = "Core";
2698
+ const POWERHOUSE_CHIP = "Powerhouse";
2699
+ const AI_CHIP = "AI";
2700
+ function categoryLabel(id) {
2701
+ return CATEGORY_LABELS[id] ?? id.toLowerCase().replaceAll("_", " ").replace(/^\w/, (char) => char.toUpperCase());
2702
+ }
2703
+ function chipsOf(piece) {
2704
+ return new Set(piece.categories.map(categoryLabel));
2705
+ }
2706
+ function orderChips(pieces) {
2707
+ const counts = /* @__PURE__ */ new Map();
2708
+ for (const piece of pieces) for (const chip of chipsOf(piece)) counts.set(chip, (counts.get(chip) ?? 0) + 1);
2709
+ const rest = [...counts.entries()].filter(([chip]) => chip !== AI_CHIP).sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).map(([chip]) => chip);
2710
+ return [
2711
+ CORE_CHIP,
2712
+ POWERHOUSE_CHIP,
2713
+ ...counts.has(AI_CHIP) ? [AI_CHIP] : [],
2714
+ ...rest
2715
+ ];
2716
+ }
2717
+ function PieceEntries(props) {
2718
+ const [entries, setEntries] = useState(null);
2719
+ const [error, setError] = useState(null);
2720
+ const pieceSource = usePieceSource();
2721
+ useEffect(() => {
2722
+ let cancelled = false;
2723
+ (props.mode === "triggers" ? pieceSource?.loadTriggers(props.piece.name) : pieceSource?.loadActions(props.piece.name))?.then((result) => {
2724
+ if (!cancelled) setEntries(result);
2725
+ }).catch((loadError) => {
2726
+ if (!cancelled) setError(loadError instanceof Error ? loadError.message : String(loadError));
2727
+ });
2728
+ return () => {
2729
+ cancelled = true;
2730
+ };
2731
+ }, [
2732
+ props.piece.name,
2733
+ props.mode,
2734
+ pieceSource
2735
+ ]);
2736
+ return /* @__PURE__ */ jsxs("div", {
2737
+ className: "max-h-80 overflow-y-auto py-1",
2738
+ children: [/* @__PURE__ */ jsxs("button", {
2739
+ type: "button",
2740
+ className: "flex w-full items-center gap-1 px-3 py-1 text-[11px] text-muted-foreground/80 hover:text-muted-foreground",
2741
+ onClick: props.onBack,
2742
+ children: ["← ", props.piece.displayName]
2743
+ }), error ? /* @__PURE__ */ jsx("div", {
2744
+ className: "px-3 py-2 text-xs text-wf-fail",
2745
+ children: error
2746
+ }) : entries === null ? /* @__PURE__ */ jsx("div", {
2747
+ className: "px-3 py-2 text-xs text-muted-foreground/80",
2748
+ children: "Loading…"
2749
+ }) : entries.map((entry) => {
2750
+ const kind = props.mode === "triggers" ? "trigger" : "action";
2751
+ const unavailable = blockUnavailable({
2752
+ ...entry,
2753
+ kind
2754
+ });
2755
+ const block = {
2756
+ pieceName: entry.pieceName,
2757
+ pieceVersion: entry.pieceVersion,
2758
+ kind,
2759
+ name: entry.name
2760
+ };
2761
+ return /* @__PURE__ */ jsx(Row, {
2762
+ logo: /* @__PURE__ */ jsx(LogoFrame, {
2763
+ src: props.piece.logoUrl,
2764
+ alt: props.piece.displayName,
2765
+ size: ROW_LOGO
2766
+ }),
2767
+ label: entry.displayName,
2768
+ description: unavailable ?? entry.description,
2769
+ disabled: unavailable !== void 0,
2770
+ version: shownVersion(entry.pieceName, entry.pieceVersion),
2771
+ versionNote: props.versionNote(props.piece.name, entry.pieceVersion),
2772
+ onHover: unavailable === void 0 ? () => props.onHover(block) : void 0,
2773
+ onClick: () => props.onPick({
2774
+ label: entry.displayName,
2775
+ block,
2776
+ description: entry.description,
2777
+ defaultConfig: {}
2778
+ })
2779
+ }, entry.name);
2780
+ })]
2781
+ });
2782
+ }
2783
+ const SEARCH_MIN_CHARS = 2;
2784
+ const SEARCH_DEBOUNCE_MS = 250;
2785
+ const INDEXING_RETRY_MS = 2e3;
2786
+ function useBlockSearch(query, enabled) {
2787
+ const [state, setState] = useState({ kind: "idle" });
2788
+ const [attempt, setAttempt] = useState(0);
2789
+ const trimmed = query.trim();
2790
+ const active = enabled && trimmed.length >= SEARCH_MIN_CHARS;
2791
+ const search = usePieceSource()?.searchBlocks;
2792
+ useEffect(() => {
2793
+ if (!active || !search) {
2794
+ setState({ kind: "idle" });
2795
+ return;
2796
+ }
2797
+ let alive = true;
2798
+ let retry;
2799
+ const timer = setTimeout(() => {
2800
+ setState((previous) => previous.kind === "done" ? previous : { kind: "loading" });
2801
+ search(trimmed).then((result) => {
2802
+ if (!alive) return;
2803
+ setState({
2804
+ kind: "done",
2805
+ result
2806
+ });
2807
+ if (result.status === "indexing") retry = setTimeout(() => setAttempt((value) => value + 1), INDEXING_RETRY_MS);
2808
+ }, (error) => {
2809
+ if (alive) setState({
2810
+ kind: "error",
2811
+ message: error instanceof Error ? error.message : String(error)
2812
+ });
2813
+ });
2814
+ }, SEARCH_DEBOUNCE_MS);
2815
+ return () => {
2816
+ alive = false;
2817
+ clearTimeout(timer);
2818
+ if (retry) clearTimeout(retry);
2819
+ };
2820
+ }, [
2821
+ active,
2822
+ trimmed,
2823
+ attempt,
2824
+ search
2825
+ ]);
2826
+ return active ? state : { kind: "idle" };
2827
+ }
2828
+ function Chip(props) {
2829
+ return /* @__PURE__ */ jsx("button", {
2830
+ type: "button",
2831
+ 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"}`,
2832
+ onClick: props.onClick,
2833
+ children: props.label
2834
+ });
2835
+ }
2836
+ function BlockSelector(props) {
2837
+ const [query, setQuery] = useState("");
2838
+ const [chip, setChip] = useState(null);
2839
+ const [catalog, setCatalog] = useState(null);
2840
+ const [piece, setPiece] = useState(null);
2841
+ const containerRef = useRef(null);
2842
+ useEffect(() => {
2843
+ const handler = (event) => {
2844
+ if (!containerRef.current?.contains(event.target)) props.onClose();
2845
+ };
2846
+ window.addEventListener("mousedown", handler);
2847
+ return () => window.removeEventListener("mousedown", handler);
2848
+ }, [props]);
2849
+ const anySource = usePieceSource();
2850
+ const pieceSource = props.showPieces ? anySource : void 0;
2851
+ const [catalogRound, setCatalogRound] = useState(0);
2852
+ useEffect(() => {
2853
+ if (!anySource) return;
2854
+ let cancelled = false;
2855
+ let timer;
2856
+ const load = (attempt) => {
2857
+ (attempt > 0 && anySource.reloadCatalog ? anySource.reloadCatalog() : anySource.loadCatalog()).then((pieces) => {
2858
+ registerPieceLogos(pieces);
2859
+ if (!cancelled) setCatalog({ pieces });
2860
+ }).catch((error) => {
2861
+ if (cancelled) return;
2862
+ if (attempt + 1 < 5) {
2863
+ timer = setTimeout(() => load(attempt + 1), CATALOG_RETRY_MS * 2 ** attempt);
2864
+ return;
2865
+ }
2866
+ setCatalog({
2867
+ pieces: [],
2868
+ error: error instanceof Error ? error.message : String(error)
2869
+ });
2870
+ });
2871
+ };
2872
+ load(catalogRound > 0 ? 1 : 0);
2873
+ return () => {
2874
+ cancelled = true;
2875
+ clearTimeout(timer);
2876
+ };
2877
+ }, [anySource, catalogRound]);
2878
+ const installed = (name) => catalog?.pieces.find((entry) => entry.name === name)?.version;
2879
+ const versionNote = useVersionNote(catalog?.pieces);
2880
+ const pinned = (preset) => pinBlock(preset.block, installed);
2881
+ const pick = (preset) => {
2882
+ const block = pinned(preset);
2883
+ if (block) props.onPick({
2884
+ ...preset,
2885
+ block
2886
+ });
2887
+ };
2888
+ const prefetch = useBlockFormPrefetch();
2889
+ const mode = props.pieceMode ?? "actions";
2890
+ const lowered = query.toLowerCase();
2891
+ const modePieces = useMemo(() => (catalog?.pieces ?? []).filter((entry) => (mode === "triggers" ? entry.triggerCount : entry.actionCount) > 0), [catalog, mode]);
2892
+ const chips = useMemo(() => orderChips(modePieces), [modePieces]);
2893
+ const chipsByPiece = useMemo(() => new Map(modePieces.map((entry) => [entry.name, chipsOf(entry)])), [modePieces]);
2894
+ const inChip = (pieceName) => chip === null || chip === "Core" ? true : chipsByPiece.get(pieceName)?.has(chip) ?? false;
2895
+ const showCatalog = pieceSource !== void 0 && !(chip === "Core" || chip === "Powerhouse");
2896
+ const matching = props.presets.filter((preset) => `${preset.label} ${preset.block.pieceName} ${preset.block.name}`.toLowerCase().includes(lowered));
2897
+ const corePresets = chip === null || chip === "Core" ? matching.filter((preset) => preset.group !== "powerhouse") : [];
2898
+ const powerhousePresets = chip === null || chip === "Powerhouse" ? matching.filter((preset) => preset.group === "powerhouse") : [];
2899
+ const filteredAttach = (props.onAttach ? props.attachSteps ?? [] : []).filter((step) => `${step.name} ${step.key} ${step.pieceName} ${step.actionName}`.toLowerCase().includes(lowered));
2900
+ const filteredPieces = showCatalog ? modePieces.filter((entry) => inChip(entry.name) && `${entry.displayName} ${entry.name} ${entry.description}`.toLowerCase().includes(lowered)) : [];
2901
+ const search = useBlockSearch(query, showCatalog && !piece);
2902
+ const presetRow = (preset) => {
2903
+ const block = pinned(preset);
2904
+ return /* @__PURE__ */ jsx(Row, {
2905
+ logo: /* @__PURE__ */ jsx(BlockLogo, {
2906
+ block: preset.block,
2907
+ size: ROW_LOGO
2908
+ }),
2909
+ label: preset.label,
2910
+ description: block ? preset.description : catalog === null ? "Loading…" : "Not installed on this runtime",
2911
+ disabled: !block,
2912
+ version: shownVersion(preset.block.pieceName, block?.pieceVersion),
2913
+ versionNote: versionNote(preset.block.pieceName, block?.pieceVersion),
2914
+ onHover: block ? () => prefetch(block) : void 0,
2915
+ onClick: () => pick(preset)
2916
+ }, blockKey(preset.block) + preset.label);
2917
+ };
2918
+ const labelPresets = showCatalog || filteredAttach.length > 0 || corePresets.length > 0 && powerhousePresets.length > 0;
2919
+ const wantedKind = mode === "triggers" ? "trigger" : "action";
2920
+ const hits = search.kind === "done" ? search.result.hits.filter((hit) => hit.kind === wantedKind && inChip(hit.pieceName)) : [];
2921
+ const searchActive = search.kind !== "idle";
2922
+ return /* @__PURE__ */ jsxs("div", {
2923
+ ref: containerRef,
2924
+ className: "nodrag nopan nowheel w-80 rounded-md border border-solid border-foreground/10 bg-card shadow-lg",
2925
+ onClick: (event) => event.stopPropagation(),
2926
+ children: [/* @__PURE__ */ jsxs("div", {
2927
+ className: "border-b border-foreground/10 p-2",
2928
+ children: [/* @__PURE__ */ jsx("div", {
2929
+ className: "mb-1 px-1 text-[11px] font-semibold uppercase tracking-wide text-muted-foreground/80",
2930
+ children: props.title
2931
+ }), piece ? null : /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("input", {
2932
+ autoFocus: true,
2933
+ className: "w-full rounded border border-foreground/10 px-2 py-1 text-xs",
2934
+ placeholder: pieceSource ? "Search pieces, actions, triggers…" : "Search…",
2935
+ value: query,
2936
+ onChange: (event) => setQuery(event.target.value)
2937
+ }), pieceSource && catalog && !catalog.error ? /* @__PURE__ */ jsx("div", {
2938
+ className: "mt-1.5 flex flex-wrap gap-1 px-0.5",
2939
+ children: chips.map((label) => /* @__PURE__ */ jsx(Chip, {
2940
+ label,
2941
+ active: chip === label,
2942
+ onClick: () => setChip(chip === label ? null : label)
2943
+ }, label))
2944
+ }) : null] })]
2945
+ }), piece ? /* @__PURE__ */ jsx(PieceEntries, {
2946
+ piece,
2947
+ mode,
2948
+ onPick: pick,
2949
+ onHover: prefetch,
2950
+ onBack: () => setPiece(null),
2951
+ versionNote
2952
+ }) : /* @__PURE__ */ jsxs("div", {
2953
+ className: "max-h-80 overflow-y-auto py-1",
2954
+ children: [
2955
+ filteredAttach.length > 0 ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(SectionLabel, { children: "Attach existing step" }), filteredAttach.map((step) => /* @__PURE__ */ jsx(Row, {
2956
+ logo: /* @__PURE__ */ jsx(BlockLogo, {
2957
+ block: stepBlock(step),
2958
+ size: ROW_LOGO
2959
+ }),
2960
+ label: step.name,
2961
+ description: `{{steps.${step.key}}} · detached`,
2962
+ onClick: () => props.onAttach?.(step.id)
2963
+ }, step.id))] }) : null,
2964
+ corePresets.length > 0 && labelPresets ? /* @__PURE__ */ jsx(SectionLabel, { children: "Core" }) : null,
2965
+ corePresets.map(presetRow),
2966
+ powerhousePresets.length > 0 && labelPresets ? /* @__PURE__ */ jsx(SectionLabel, { children: "Powerhouse" }) : null,
2967
+ powerhousePresets.map(presetRow),
2968
+ searchActive ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(SectionLabel, { children: mode === "triggers" ? "Triggers" : "Actions & triggers" }), search.kind === "loading" ? /* @__PURE__ */ jsx("div", {
2969
+ className: "px-3 py-1 text-xs text-muted-foreground/80",
2970
+ children: "Searching…"
2971
+ }) : search.kind === "error" ? /* @__PURE__ */ jsx("div", {
2972
+ className: "px-3 py-1 text-xs text-wf-fail",
2973
+ children: search.message
2974
+ }) : /* @__PURE__ */ jsxs(Fragment$1, { children: [hits.map((hit) => {
2975
+ const unavailable = blockUnavailable(hit);
2976
+ const block = {
2977
+ pieceName: hit.pieceName,
2978
+ pieceVersion: hit.pieceVersion,
2979
+ kind: hit.kind,
2980
+ name: hit.name
2981
+ };
2982
+ return /* @__PURE__ */ jsx(Row, {
2983
+ logo: /* @__PURE__ */ jsx(LogoFrame, {
2984
+ src: hit.logoUrl,
2985
+ alt: hit.pieceDisplayName,
2986
+ size: ROW_LOGO
2987
+ }),
2988
+ label: `${hit.displayName} · ${hit.pieceDisplayName}`,
2989
+ description: unavailable ?? (hit.description || hit.pieceDisplayName),
2990
+ disabled: unavailable !== void 0,
2991
+ version: shownVersion(hit.pieceName, hit.pieceVersion),
2992
+ versionNote: versionNote(hit.pieceName, hit.pieceVersion),
2993
+ onHover: unavailable === void 0 ? () => prefetch(block) : void 0,
2994
+ onClick: () => pick({
2995
+ label: hit.displayName,
2996
+ block,
2997
+ description: hit.description,
2998
+ defaultConfig: {}
2999
+ })
3000
+ }, blockKey(block));
3001
+ }), search.result.status === "indexing" ? /* @__PURE__ */ jsx("div", {
3002
+ className: "px-3 py-1 text-xs text-muted-foreground/80",
3003
+ children: "Indexing the catalog… more results appear shortly."
3004
+ }) : search.result.status === "error" ? /* @__PURE__ */ jsx("div", {
3005
+ className: "px-3 py-1 text-xs text-wf-fail",
3006
+ children: search.result.error ?? "Search failed"
3007
+ }) : hits.length === 0 ? /* @__PURE__ */ jsxs("div", {
3008
+ className: "px-3 py-1 text-xs text-muted-foreground/80",
3009
+ children: [
3010
+ "No matching ",
3011
+ wantedKind,
3012
+ "s"
3013
+ ]
3014
+ }) : null] })] }) : null,
3015
+ showCatalog ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(SectionLabel, { children: "Pieces" }), catalog === null ? /* @__PURE__ */ jsx("div", {
3016
+ className: "px-3 py-2 text-xs text-muted-foreground/80",
3017
+ children: "Loading catalog…"
3018
+ }) : catalog.error ? /* @__PURE__ */ jsxs("div", {
3019
+ className: "flex items-center gap-2 px-3 py-2 text-xs text-wf-fail",
3020
+ children: [/* @__PURE__ */ jsx("span", {
3021
+ className: "min-w-0 flex-1",
3022
+ children: catalog.error
3023
+ }), /* @__PURE__ */ jsx("button", {
3024
+ type: "button",
3025
+ 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",
3026
+ onClick: () => {
3027
+ setCatalog(null);
3028
+ setCatalogRound((round) => round + 1);
3029
+ },
3030
+ children: "Retry"
3031
+ })]
3032
+ }) : filteredPieces.map((entry) => /* @__PURE__ */ jsx(Row, {
3033
+ logo: /* @__PURE__ */ jsx(LogoFrame, {
3034
+ src: entry.logoUrl,
3035
+ alt: entry.displayName,
3036
+ size: ROW_LOGO
3037
+ }),
3038
+ label: entry.deprecated ? `${entry.displayName} (deprecated)` : entry.displayName,
3039
+ description: entry.unsupported ?? (mode === "triggers" ? `${entry.triggerCount} trigger${entry.triggerCount === 1 ? "" : "s"} · ${entry.description}` : `${entry.actionCount} action${entry.actionCount === 1 ? "" : "s"} · ${entry.description}`),
3040
+ version: shownVersion(entry.name, entry.version),
3041
+ versionNote: versionNote(entry.name, entry.version),
3042
+ onClick: () => setPiece(entry)
3043
+ }, entry.name))] }) : null,
3044
+ corePresets.length + powerhousePresets.length === 0 && filteredPieces.length === 0 && filteredAttach.length === 0 && !searchActive ? /* @__PURE__ */ jsx("div", {
3045
+ className: "px-3 py-2 text-xs text-muted-foreground/80",
3046
+ children: "No matches"
3047
+ }) : null
3048
+ ]
3049
+ })]
3050
+ });
3051
+ }
3052
+ //#endregion
3053
+ 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 };
3054
+
3055
+ //# sourceMappingURL=BlockSelector-lOcIiaqt.mjs.map