@powerhousedao/workflow 6.2.3 → 6.3.0-dev.2

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 (536) hide show
  1. package/README.md +3 -1
  2. package/dist/{node/BlockSelector-C3XYZfPY.mjs → browser/BlockSelector-CEdYUqjx.js} +2006 -1692
  3. package/dist/browser/BlockSelector-CEdYUqjx.js.map +1 -0
  4. package/dist/browser/PieceMarkdown-DSdZd-Jc.js +92 -0
  5. package/dist/browser/PieceMarkdown-DSdZd-Jc.js.map +1 -0
  6. package/dist/browser/connection-form-Biksq2jW.js +1524 -0
  7. package/dist/browser/connection-form-Biksq2jW.js.map +1 -0
  8. package/dist/browser/{connection-BUum0hJI.js → connection-ilYFCRUK.js} +2 -2
  9. package/dist/browser/{connection-BUum0hJI.js.map → connection-ilYFCRUK.js.map} +1 -1
  10. package/dist/browser/data-tree-Cq-s6bJp.js +76 -0
  11. package/dist/browser/data-tree-Cq-s6bJp.js.map +1 -0
  12. package/dist/browser/document-models/connection/index.js +3 -3
  13. package/dist/browser/document-models/index.js +3 -3
  14. package/dist/browser/document-models/workflow/index.js +3 -3
  15. package/dist/browser/document-models-C2SAP1SX.js +164 -0
  16. package/dist/browser/{document-models-C1ZgIZyV.js.map → document-models-C2SAP1SX.js.map} +1 -1
  17. package/dist/browser/editor-CIqKi7XK.js +3219 -0
  18. package/dist/browser/editor-CIqKi7XK.js.map +1 -0
  19. package/dist/browser/editor-DYjoPfta.js +4669 -0
  20. package/dist/browser/editor-DYjoPfta.js.map +1 -0
  21. package/dist/browser/{editor-BCH8vdej.js → editor-GeRXGdie.js} +174 -48
  22. package/dist/browser/editor-GeRXGdie.js.map +1 -0
  23. package/dist/browser/editors/connection-editor/module.js +1 -1
  24. package/dist/browser/editors/connection-editor/module.js.map +1 -1
  25. package/dist/browser/editors/runtime/index.js +2 -0
  26. package/dist/browser/editors/workflow-editor/module.js +1 -1
  27. package/dist/browser/editors/workflow-editor/module.js.map +1 -1
  28. package/dist/browser/editors/workflow-studio/module.js +1 -1
  29. package/dist/browser/index.js +164 -88
  30. package/dist/browser/index.js.map +1 -1
  31. package/dist/browser/{module-jDZ4pq3W.js → module-DJz6oTX0.js} +237 -30
  32. package/dist/browser/module-DJz6oTX0.js.map +1 -0
  33. package/dist/browser/{module-DU2vb3FH.js → module-mFCt9WHJ.js} +267 -89
  34. package/dist/browser/module-mFCt9WHJ.js.map +1 -0
  35. package/dist/{node/piece-auth-BS5CtQOG.mjs → browser/piece-auth-63iuNFTs.js} +11 -3
  36. package/dist/browser/piece-auth-63iuNFTs.js.map +1 -0
  37. package/dist/browser/reactor/index.js +2 -2
  38. package/dist/browser/rolldown-runtime-D7D4PA-g.js +13 -0
  39. package/dist/browser/runtime-queries-FmEzElOY.js +993 -0
  40. package/dist/browser/runtime-queries-FmEzElOY.js.map +1 -0
  41. package/dist/browser/trigger-text-DH6HIeoa.js +3210 -0
  42. package/dist/browser/trigger-text-DH6HIeoa.js.map +1 -0
  43. package/dist/browser/upgrade-manifests-C2Qa6myy.js +8 -0
  44. package/dist/browser/{upgrade-manifests-BpakVE9l.js.map → upgrade-manifests-C2Qa6myy.js.map} +1 -1
  45. package/dist/{node/workflow-CGzYGZnr.mjs → browser/workflow-2gR2JXUS.js} +4 -3
  46. package/dist/browser/workflow-2gR2JXUS.js.map +1 -0
  47. package/dist/node/document-models/connection/index.mjs +67 -3
  48. package/dist/node/document-models/connection/index.mjs.map +1 -0
  49. package/dist/node/document-models/index.mjs +3 -3
  50. package/dist/node/document-models/workflow/index.mjs +86 -3
  51. package/dist/node/document-models/workflow/index.mjs.map +1 -0
  52. package/dist/node/editors/index.mjs +6 -4
  53. package/dist/node/editors/index.mjs.map +1 -0
  54. package/dist/node/index.mjs +69 -381
  55. package/dist/node/index.mjs.map +1 -1
  56. package/dist/node/{module-Dhe5E-VA.mjs → module-BXKUB58R.mjs} +273 -90
  57. package/dist/node/module-BXKUB58R.mjs.map +1 -0
  58. package/dist/node/{module-BMwJQh65.mjs → module-CaBtkQmd.mjs} +226 -19
  59. package/dist/node/module-CaBtkQmd.mjs.map +1 -0
  60. package/dist/node/pieces/ai/descriptor.json +857 -0
  61. package/dist/node/pieces/ai/index.mjs +624 -0
  62. package/dist/node/pieces/ai/package.json +9 -0
  63. package/dist/node/pieces/index.mjs +3 -0
  64. package/dist/node/pieces/index.mjs.map +1 -1
  65. package/dist/node/pieces/reactor/descriptor.json +104 -18
  66. package/dist/node/pieces/reactor/index.mjs +48 -17670
  67. package/dist/node/pieces/reactor/package.json +2 -2
  68. package/dist/node/rolldown-runtime-D7D4PA-g.mjs +13 -0
  69. package/dist/node/upgrade-manifests-BCCpSD1J.mjs +8 -0
  70. package/dist/node/{upgrade-manifests-CmNd742Y.mjs.map → upgrade-manifests-BCCpSD1J.mjs.map} +1 -1
  71. package/dist/powerhouse.manifest.json +72 -6
  72. package/dist/style.css +3 -2520
  73. package/dist/types/ai/runtime.d.ts +13 -0
  74. package/dist/types/ai/runtime.d.ts.map +1 -0
  75. package/dist/types/ai/tools.d.ts +10 -6
  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/connection/v1/actions.d.ts +3 -0
  79. package/dist/types/document-models/connection/v1/actions.d.ts.map +1 -1
  80. package/dist/types/document-models/connection/v1/gen/config/actions.d.ts +10 -2
  81. package/dist/types/document-models/connection/v1/gen/config/actions.d.ts.map +1 -1
  82. package/dist/types/document-models/connection/v1/gen/config/creators.d.ts +4 -2
  83. package/dist/types/document-models/connection/v1/gen/config/creators.d.ts.map +1 -1
  84. package/dist/types/document-models/connection/v1/gen/config/error.d.ts +29 -1
  85. package/dist/types/document-models/connection/v1/gen/config/error.d.ts.map +1 -1
  86. package/dist/types/document-models/connection/v1/gen/config/operations.d.ts +3 -1
  87. package/dist/types/document-models/connection/v1/gen/config/operations.d.ts.map +1 -1
  88. package/dist/types/document-models/connection/v1/gen/connection/error.d.ts +13 -1
  89. package/dist/types/document-models/connection/v1/gen/connection/error.d.ts.map +1 -1
  90. package/dist/types/document-models/connection/v1/gen/document-model.d.ts.map +1 -1
  91. package/dist/types/document-models/connection/v1/gen/reducer.d.ts.map +1 -1
  92. package/dist/types/document-models/connection/v1/gen/schema/types.d.ts +18 -2
  93. package/dist/types/document-models/connection/v1/gen/schema/types.d.ts.map +1 -1
  94. package/dist/types/document-models/connection/v1/gen/schema/zod.d.ts +5 -1
  95. package/dist/types/document-models/connection/v1/gen/schema/zod.d.ts.map +1 -1
  96. package/dist/types/document-models/connection/v1/module.d.ts +3 -0
  97. package/dist/types/document-models/connection/v1/module.d.ts.map +1 -1
  98. package/dist/types/document-models/connection/v1/src/reactor-connection.d.ts +17 -0
  99. package/dist/types/document-models/connection/v1/src/reactor-connection.d.ts.map +1 -0
  100. package/dist/types/document-models/connection/v1/src/reducers/config.d.ts.map +1 -1
  101. package/dist/types/document-models/connection/v1/src/reducers/connection.d.ts.map +1 -1
  102. package/dist/types/document-models/connection/v1/src/utils.d.ts +1 -1
  103. package/dist/types/document-models/connection/v1/src/utils.d.ts.map +1 -1
  104. package/dist/types/document-models/connection/v1/tests/config-values.test.d.ts +2 -0
  105. package/dist/types/document-models/connection/v1/tests/config-values.test.d.ts.map +1 -0
  106. package/dist/types/document-models/connection/v1/tests/reactor-connection.test.d.ts +2 -0
  107. package/dist/types/document-models/connection/v1/tests/reactor-connection.test.d.ts.map +1 -0
  108. package/dist/types/document-models/document-models.d.ts +8 -0
  109. package/dist/types/document-models/document-models.d.ts.map +1 -1
  110. package/dist/types/document-models/workflow/v1/actions.d.ts +5 -0
  111. package/dist/types/document-models/workflow/v1/actions.d.ts.map +1 -1
  112. package/dist/types/document-models/workflow/v1/gen/document-model.d.ts.map +1 -1
  113. package/dist/types/document-models/workflow/v1/gen/document-schema.d.ts +3 -0
  114. package/dist/types/document-models/workflow/v1/gen/document-schema.d.ts.map +1 -1
  115. package/dist/types/document-models/workflow/v1/gen/ph-factories.d.ts.map +1 -1
  116. package/dist/types/document-models/workflow/v1/gen/reducer.d.ts.map +1 -1
  117. package/dist/types/document-models/workflow/v1/gen/schema/types.d.ts +52 -6
  118. package/dist/types/document-models/workflow/v1/gen/schema/types.d.ts.map +1 -1
  119. package/dist/types/document-models/workflow/v1/gen/schema/zod.d.ts +7 -1
  120. package/dist/types/document-models/workflow/v1/gen/schema/zod.d.ts.map +1 -1
  121. package/dist/types/document-models/workflow/v1/gen/trigger/actions.d.ts +14 -2
  122. package/dist/types/document-models/workflow/v1/gen/trigger/actions.d.ts.map +1 -1
  123. package/dist/types/document-models/workflow/v1/gen/trigger/creators.d.ts +5 -2
  124. package/dist/types/document-models/workflow/v1/gen/trigger/creators.d.ts.map +1 -1
  125. package/dist/types/document-models/workflow/v1/gen/trigger/error.d.ts +32 -1
  126. package/dist/types/document-models/workflow/v1/gen/trigger/error.d.ts.map +1 -1
  127. package/dist/types/document-models/workflow/v1/gen/trigger/operations.d.ts +4 -1
  128. package/dist/types/document-models/workflow/v1/gen/trigger/operations.d.ts.map +1 -1
  129. package/dist/types/document-models/workflow/v1/gen/utils.d.ts.map +1 -1
  130. package/dist/types/document-models/workflow/v1/gen/workflow/actions.d.ts +6 -2
  131. package/dist/types/document-models/workflow/v1/gen/workflow/actions.d.ts.map +1 -1
  132. package/dist/types/document-models/workflow/v1/gen/workflow/creators.d.ts +3 -2
  133. package/dist/types/document-models/workflow/v1/gen/workflow/creators.d.ts.map +1 -1
  134. package/dist/types/document-models/workflow/v1/gen/workflow/operations.d.ts +2 -1
  135. package/dist/types/document-models/workflow/v1/gen/workflow/operations.d.ts.map +1 -1
  136. package/dist/types/document-models/workflow/v1/module.d.ts +5 -0
  137. package/dist/types/document-models/workflow/v1/module.d.ts.map +1 -1
  138. package/dist/types/document-models/workflow/v1/src/reducers/steps.d.ts.map +1 -1
  139. package/dist/types/document-models/workflow/v1/src/reducers/trigger.d.ts.map +1 -1
  140. package/dist/types/document-models/workflow/v1/src/reducers/workflow.d.ts.map +1 -1
  141. package/dist/types/document-models/workflow/v1/tests/managed-by.test.d.ts +2 -0
  142. package/dist/types/document-models/workflow/v1/tests/managed-by.test.d.ts.map +1 -0
  143. package/dist/types/document-models/workflow/v1/tests/reactor-connection.test.d.ts +2 -0
  144. package/dist/types/document-models/workflow/v1/tests/reactor-connection.test.d.ts.map +1 -0
  145. package/dist/types/document-models/workflow/v1/tests/trigger-fields.test.d.ts +2 -0
  146. package/dist/types/document-models/workflow/v1/tests/trigger-fields.test.d.ts.map +1 -0
  147. package/dist/types/editors/connection-editor/ConnectionToolbar.d.ts +1 -1
  148. package/dist/types/editors/connection-editor/ConnectionToolbar.d.ts.map +1 -1
  149. package/dist/types/editors/connection-editor/ReactorBindings.d.ts +6 -0
  150. package/dist/types/editors/connection-editor/ReactorBindings.d.ts.map +1 -0
  151. package/dist/types/editors/connection-editor/ReactorConnectionSettings.d.ts +7 -0
  152. package/dist/types/editors/connection-editor/ReactorConnectionSettings.d.ts.map +1 -0
  153. package/dist/types/editors/connection-editor/UsedBy.d.ts.map +1 -1
  154. package/dist/types/editors/connection-editor/connection-callbacks.d.ts.map +1 -1
  155. package/dist/types/editors/connection-editor/connection-form.d.ts +4 -1
  156. package/dist/types/editors/connection-editor/connection-form.d.ts.map +1 -1
  157. package/dist/types/editors/connection-editor/connection-usage.d.ts +13 -3
  158. package/dist/types/editors/connection-editor/connection-usage.d.ts.map +1 -1
  159. package/dist/types/editors/connection-editor/editor.d.ts +3 -1
  160. package/dist/types/editors/connection-editor/editor.d.ts.map +1 -1
  161. package/dist/types/editors/connection-editor/module.d.ts +2 -1
  162. package/dist/types/editors/connection-editor/module.d.ts.map +1 -1
  163. package/dist/types/editors/connection-editor/piece-auth.d.ts +6 -1
  164. package/dist/types/editors/connection-editor/piece-auth.d.ts.map +1 -1
  165. package/dist/types/editors/connection-editor/status.d.ts.map +1 -1
  166. package/dist/types/editors/runtime/index.d.ts +21 -0
  167. package/dist/types/editors/runtime/index.d.ts.map +1 -0
  168. package/dist/types/editors/runtime/runtime-export.test.d.ts +2 -0
  169. package/dist/types/editors/runtime/runtime-export.test.d.ts.map +1 -0
  170. package/dist/types/editors/shared/DocumentErrorBoundary.d.ts.map +1 -1
  171. package/dist/types/editors/shared/controls.d.ts +1 -0
  172. package/dist/types/editors/shared/controls.d.ts.map +1 -1
  173. package/dist/types/editors/shared/data-tree.d.ts.map +1 -1
  174. package/dist/types/editors/shared/data-viewer.d.ts.map +1 -1
  175. package/dist/types/editors/shared/document-ref.d.ts +5 -0
  176. package/dist/types/editors/shared/document-ref.d.ts.map +1 -0
  177. package/dist/types/editors/shared/editor-chrome.d.ts +6 -1
  178. package/dist/types/editors/shared/editor-chrome.d.ts.map +1 -1
  179. package/dist/types/editors/shared/editor-chrome.test.d.ts +2 -0
  180. package/dist/types/editors/shared/editor-chrome.test.d.ts.map +1 -0
  181. package/dist/types/editors/shared/icons.d.ts +5 -0
  182. package/dist/types/editors/shared/icons.d.ts.map +1 -1
  183. package/dist/types/editors/shared/pending-echo.d.ts +9 -0
  184. package/dist/types/editors/shared/pending-echo.d.ts.map +1 -0
  185. package/dist/types/editors/shared/undo-plan.d.ts +12 -5
  186. package/dist/types/editors/shared/undo-plan.d.ts.map +1 -1
  187. package/dist/types/editors/shared/url-param.d.ts +14 -0
  188. package/dist/types/editors/shared/url-param.d.ts.map +1 -0
  189. package/dist/types/editors/shared/url-param.test.d.ts +2 -0
  190. package/dist/types/editors/shared/url-param.test.d.ts.map +1 -0
  191. package/dist/types/editors/workflow-editor/document/useWorkflowModel.d.ts.map +1 -1
  192. package/dist/types/editors/workflow-editor/editor.d.ts +3 -1
  193. package/dist/types/editors/workflow-editor/editor.d.ts.map +1 -1
  194. package/dist/types/editors/workflow-editor/module.d.ts +2 -1
  195. package/dist/types/editors/workflow-editor/module.d.ts.map +1 -1
  196. package/dist/types/editors/workflow-editor/reactor-hooks.d.ts +25 -0
  197. package/dist/types/editors/workflow-editor/reactor-hooks.d.ts.map +1 -0
  198. package/dist/types/editors/workflow-editor/runtime-api.d.ts +13 -11
  199. package/dist/types/editors/workflow-editor/runtime-api.d.ts.map +1 -1
  200. package/dist/types/editors/workflow-editor/runtime-client.d.ts +96 -9
  201. package/dist/types/editors/workflow-editor/runtime-client.d.ts.map +1 -1
  202. package/dist/types/editors/workflow-editor/runtime-context.d.ts +12 -3
  203. package/dist/types/editors/workflow-editor/runtime-context.d.ts.map +1 -1
  204. package/dist/types/editors/workflow-editor/runtime-contract.test.d.ts +2 -0
  205. package/dist/types/editors/workflow-editor/runtime-contract.test.d.ts.map +1 -0
  206. package/dist/types/editors/workflow-editor/runtime-persist.d.ts +1 -1
  207. package/dist/types/editors/workflow-editor/runtime-queries.d.ts +21 -1
  208. package/dist/types/editors/workflow-editor/runtime-queries.d.ts.map +1 -1
  209. package/dist/types/editors/workflow-editor/ui/BlockSelector.d.ts +15 -2
  210. package/dist/types/editors/workflow-editor/ui/BlockSelector.d.ts.map +1 -1
  211. package/dist/types/editors/workflow-editor/ui/CanvasContextMenu.d.ts.map +1 -1
  212. package/dist/types/editors/workflow-editor/ui/ConnectionField.d.ts.map +1 -1
  213. package/dist/types/editors/workflow-editor/ui/ConnectionName.d.ts +8 -0
  214. package/dist/types/editors/workflow-editor/ui/ConnectionName.d.ts.map +1 -0
  215. package/dist/types/editors/workflow-editor/ui/CreateConnectionModal.d.ts.map +1 -1
  216. package/dist/types/editors/workflow-editor/ui/PanelResizer.d.ts +12 -0
  217. package/dist/types/editors/workflow-editor/ui/PanelResizer.d.ts.map +1 -0
  218. package/dist/types/editors/workflow-editor/ui/PickerPopover.d.ts +12 -0
  219. package/dist/types/editors/workflow-editor/ui/PickerPopover.d.ts.map +1 -0
  220. package/dist/types/editors/workflow-editor/ui/PieceMarkdown.d.ts +2 -1
  221. package/dist/types/editors/workflow-editor/ui/PieceMarkdown.d.ts.map +1 -1
  222. package/dist/types/editors/workflow-editor/ui/PropertyForm.d.ts +9 -0
  223. package/dist/types/editors/workflow-editor/ui/PropertyForm.d.ts.map +1 -1
  224. package/dist/types/editors/workflow-editor/ui/PublishControls.d.ts +17 -0
  225. package/dist/types/editors/workflow-editor/ui/PublishControls.d.ts.map +1 -1
  226. package/dist/types/editors/workflow-editor/ui/ReactorConnectionField.d.ts +9 -0
  227. package/dist/types/editors/workflow-editor/ui/ReactorConnectionField.d.ts.map +1 -0
  228. package/dist/types/editors/workflow-editor/ui/ScheduleBuilder.d.ts.map +1 -1
  229. package/dist/types/editors/workflow-editor/ui/SignInPrompt.d.ts +6 -0
  230. package/dist/types/editors/workflow-editor/ui/SignInPrompt.d.ts.map +1 -0
  231. package/dist/types/editors/workflow-editor/ui/StepError.d.ts +4 -0
  232. package/dist/types/editors/workflow-editor/ui/StepError.d.ts.map +1 -0
  233. package/dist/types/editors/workflow-editor/ui/StepPanel.d.ts +1 -0
  234. package/dist/types/editors/workflow-editor/ui/StepPanel.d.ts.map +1 -1
  235. package/dist/types/editors/workflow-editor/ui/StepTest.d.ts.map +1 -1
  236. package/dist/types/editors/workflow-editor/ui/SwitchboardGrants.d.ts +2 -0
  237. package/dist/types/editors/workflow-editor/ui/SwitchboardGrants.d.ts.map +1 -0
  238. package/dist/types/editors/workflow-editor/ui/VirtualList.d.ts +14 -0
  239. package/dist/types/editors/workflow-editor/ui/VirtualList.d.ts.map +1 -0
  240. package/dist/types/editors/workflow-editor/ui/WorkflowEditorApp.d.ts.map +1 -1
  241. package/dist/types/editors/workflow-editor/ui/ap-edge.d.ts +1 -0
  242. package/dist/types/editors/workflow-editor/ui/ap-edge.d.ts.map +1 -1
  243. package/dist/types/editors/workflow-editor/ui/ap-layout.d.ts.map +1 -1
  244. package/dist/types/editors/workflow-editor/ui/ap-nodes.d.ts +4 -0
  245. package/dist/types/editors/workflow-editor/ui/ap-nodes.d.ts.map +1 -1
  246. package/dist/types/editors/workflow-editor/ui/block-meta.d.ts +3 -0
  247. package/dist/types/editors/workflow-editor/ui/block-meta.d.ts.map +1 -1
  248. package/dist/types/editors/workflow-editor/ui/block-picker-layout.test.d.ts +2 -0
  249. package/dist/types/editors/workflow-editor/ui/block-picker-layout.test.d.ts.map +1 -0
  250. package/dist/types/editors/workflow-editor/ui/blocks.d.ts +12 -0
  251. package/dist/types/editors/workflow-editor/ui/blocks.d.ts.map +1 -1
  252. package/dist/types/editors/workflow-editor/ui/canvas-menu.d.ts.map +1 -1
  253. package/dist/types/editors/workflow-editor/ui/design-time.d.ts +1 -0
  254. package/dist/types/editors/workflow-editor/ui/design-time.d.ts.map +1 -1
  255. package/dist/types/editors/workflow-editor/ui/document-options.d.ts +24 -0
  256. package/dist/types/editors/workflow-editor/ui/document-options.d.ts.map +1 -0
  257. package/dist/types/editors/workflow-editor/ui/document-options.test.d.ts +2 -0
  258. package/dist/types/editors/workflow-editor/ui/document-options.test.d.ts.map +1 -0
  259. package/dist/types/editors/workflow-editor/ui/document-shape.d.ts +8 -0
  260. package/dist/types/editors/workflow-editor/ui/document-shape.d.ts.map +1 -0
  261. package/dist/types/editors/workflow-editor/ui/document-shape.test.d.ts +2 -0
  262. package/dist/types/editors/workflow-editor/ui/document-shape.test.d.ts.map +1 -0
  263. package/dist/types/editors/workflow-editor/ui/expression-scope.d.ts +2 -0
  264. package/dist/types/editors/workflow-editor/ui/expression-scope.d.ts.map +1 -1
  265. package/dist/types/editors/workflow-editor/ui/flow-control.test.d.ts +2 -0
  266. package/dist/types/editors/workflow-editor/ui/flow-control.test.d.ts.map +1 -0
  267. package/dist/types/editors/workflow-editor/ui/forms.d.ts +11 -2
  268. package/dist/types/editors/workflow-editor/ui/forms.d.ts.map +1 -1
  269. package/dist/types/editors/workflow-editor/ui/item-summary.test.d.ts +2 -0
  270. package/dist/types/editors/workflow-editor/ui/item-summary.test.d.ts.map +1 -0
  271. package/dist/types/editors/workflow-editor/ui/manual-inputs.d.ts +7 -0
  272. package/dist/types/editors/workflow-editor/ui/manual-inputs.d.ts.map +1 -0
  273. package/dist/types/editors/workflow-editor/ui/manual-inputs.test.d.ts +2 -0
  274. package/dist/types/editors/workflow-editor/ui/manual-inputs.test.d.ts.map +1 -0
  275. package/dist/types/editors/workflow-editor/ui/model.d.ts +31 -0
  276. package/dist/types/editors/workflow-editor/ui/model.d.ts.map +1 -1
  277. package/dist/types/editors/workflow-editor/ui/picker-placement.d.ts +19 -0
  278. package/dist/types/editors/workflow-editor/ui/picker-placement.d.ts.map +1 -0
  279. package/dist/types/editors/workflow-editor/ui/picker-recent.d.ts +4 -0
  280. package/dist/types/editors/workflow-editor/ui/picker-recent.d.ts.map +1 -0
  281. package/dist/types/editors/workflow-editor/ui/piece-source.d.ts +23 -3
  282. package/dist/types/editors/workflow-editor/ui/piece-source.d.ts.map +1 -1
  283. package/dist/types/editors/workflow-editor/ui/prop-layout.d.ts +1 -0
  284. package/dist/types/editors/workflow-editor/ui/prop-layout.d.ts.map +1 -1
  285. package/dist/types/editors/workflow-editor/ui/prop-layout.test.d.ts +2 -0
  286. package/dist/types/editors/workflow-editor/ui/prop-layout.test.d.ts.map +1 -0
  287. package/dist/types/editors/workflow-editor/ui/query-keys.d.ts +16 -4
  288. package/dist/types/editors/workflow-editor/ui/query-keys.d.ts.map +1 -1
  289. package/dist/types/editors/workflow-editor/ui/reactor-access.d.ts +43 -0
  290. package/dist/types/editors/workflow-editor/ui/reactor-access.d.ts.map +1 -0
  291. package/dist/types/editors/workflow-editor/ui/reactor-access.test.d.ts +2 -0
  292. package/dist/types/editors/workflow-editor/ui/reactor-access.test.d.ts.map +1 -0
  293. package/dist/types/editors/workflow-editor/ui/reactor-connection-create.d.ts +2 -0
  294. package/dist/types/editors/workflow-editor/ui/reactor-connection-create.d.ts.map +1 -0
  295. package/dist/types/editors/workflow-editor/ui/reactor-connection-create.test.d.ts +2 -0
  296. package/dist/types/editors/workflow-editor/ui/reactor-connection-create.test.d.ts.map +1 -0
  297. package/dist/types/editors/workflow-editor/ui/reactor-view.d.ts +25 -0
  298. package/dist/types/editors/workflow-editor/ui/reactor-view.d.ts.map +1 -0
  299. package/dist/types/editors/workflow-editor/ui/reactor-view.test.d.ts +2 -0
  300. package/dist/types/editors/workflow-editor/ui/reactor-view.test.d.ts.map +1 -0
  301. package/dist/types/editors/workflow-editor/ui/retry-policy.d.ts +8 -0
  302. package/dist/types/editors/workflow-editor/ui/retry-policy.d.ts.map +1 -0
  303. package/dist/types/editors/workflow-editor/ui/retry-policy.test.d.ts +2 -0
  304. package/dist/types/editors/workflow-editor/ui/retry-policy.test.d.ts.map +1 -0
  305. package/dist/types/editors/workflow-editor/ui/step-test.d.ts +2 -0
  306. package/dist/types/editors/workflow-editor/ui/step-test.d.ts.map +1 -1
  307. package/dist/types/editors/workflow-editor/ui/trigger-text.d.ts +2 -0
  308. package/dist/types/editors/workflow-editor/ui/trigger-text.d.ts.map +1 -1
  309. package/dist/types/editors/workflow-editor/ui/use-selected-block.d.ts +4 -0
  310. package/dist/types/editors/workflow-editor/ui/use-selected-block.d.ts.map +1 -0
  311. package/dist/types/editors/workflow-editor/ui/use-selected-block.test.d.ts +2 -0
  312. package/dist/types/editors/workflow-editor/ui/use-selected-block.test.d.ts.map +1 -0
  313. package/dist/types/editors/workflow-editor/ui/use-validity.d.ts +1 -0
  314. package/dist/types/editors/workflow-editor/ui/use-validity.d.ts.map +1 -1
  315. package/dist/types/editors/workflow-editor/ui/validation.d.ts +7 -2
  316. package/dist/types/editors/workflow-editor/ui/validation.d.ts.map +1 -1
  317. package/dist/types/editors/workflow-editor/use-workflow-runtime.d.ts +13 -0
  318. package/dist/types/editors/workflow-editor/use-workflow-runtime.d.ts.map +1 -0
  319. package/dist/types/editors/workflow-editor/use-workflow-runtime.test.d.ts +2 -0
  320. package/dist/types/editors/workflow-editor/use-workflow-runtime.test.d.ts.map +1 -0
  321. package/dist/types/editors/workflow-studio/components/RunDialog.d.ts +7 -0
  322. package/dist/types/editors/workflow-studio/components/RunDialog.d.ts.map +1 -0
  323. package/dist/types/editors/workflow-studio/components/RunsTable.d.ts +11 -1
  324. package/dist/types/editors/workflow-studio/components/RunsTable.d.ts.map +1 -1
  325. package/dist/types/editors/workflow-studio/components/RunsView.d.ts +3 -1
  326. package/dist/types/editors/workflow-studio/components/RunsView.d.ts.map +1 -1
  327. package/dist/types/editors/workflow-studio/components/ScrollFade.d.ts +7 -0
  328. package/dist/types/editors/workflow-studio/components/ScrollFade.d.ts.map +1 -0
  329. package/dist/types/editors/workflow-studio/components/Sidebar.d.ts +4 -0
  330. package/dist/types/editors/workflow-studio/components/Sidebar.d.ts.map +1 -1
  331. package/dist/types/editors/workflow-studio/components/Waitpoints.d.ts +57 -0
  332. package/dist/types/editors/workflow-studio/components/Waitpoints.d.ts.map +1 -0
  333. package/dist/types/editors/workflow-studio/components/WorkflowBoard.d.ts +4 -0
  334. package/dist/types/editors/workflow-studio/components/WorkflowBoard.d.ts.map +1 -1
  335. package/dist/types/editors/workflow-studio/components/WorkflowGraph.d.ts +41 -0
  336. package/dist/types/editors/workflow-studio/components/WorkflowGraph.d.ts.map +1 -0
  337. package/dist/types/editors/workflow-studio/components/WorkflowMenu.d.ts +2 -0
  338. package/dist/types/editors/workflow-studio/components/WorkflowMenu.d.ts.map +1 -1
  339. package/dist/types/editors/workflow-studio/components/WorkflowSteps.d.ts.map +1 -1
  340. package/dist/types/editors/workflow-studio/components/WorkflowStudio.d.ts.map +1 -1
  341. package/dist/types/editors/workflow-studio/components/chain.d.ts +6 -0
  342. package/dist/types/editors/workflow-studio/components/chain.d.ts.map +1 -1
  343. package/dist/types/editors/workflow-studio/components/fit-geometry.test.d.ts +2 -0
  344. package/dist/types/editors/workflow-studio/components/fit-geometry.test.d.ts.map +1 -0
  345. package/dist/types/editors/workflow-studio/components/graph-layout.d.ts +30 -0
  346. package/dist/types/editors/workflow-studio/components/graph-layout.d.ts.map +1 -0
  347. package/dist/types/editors/workflow-studio/components/graph-layout.test.d.ts +2 -0
  348. package/dist/types/editors/workflow-studio/components/graph-layout.test.d.ts.map +1 -0
  349. package/dist/types/editors/workflow-studio/components/run-dialog.test.d.ts +2 -0
  350. package/dist/types/editors/workflow-studio/components/run-dialog.test.d.ts.map +1 -0
  351. package/dist/types/editors/workflow-studio/components/run-format.d.ts +6 -1
  352. package/dist/types/editors/workflow-studio/components/run-format.d.ts.map +1 -1
  353. package/dist/types/editors/workflow-studio/components/tips.d.ts +23 -0
  354. package/dist/types/editors/workflow-studio/components/tips.d.ts.map +1 -0
  355. package/dist/types/editors/workflow-studio/components/use-collapsed.d.ts +5 -0
  356. package/dist/types/editors/workflow-studio/components/use-collapsed.d.ts.map +1 -0
  357. package/dist/types/editors/workflow-studio/components/use-item-selection.d.ts +10 -0
  358. package/dist/types/editors/workflow-studio/components/use-item-selection.d.ts.map +1 -0
  359. package/dist/types/editors/workflow-studio/components/use-item-selection.test.d.ts +2 -0
  360. package/dist/types/editors/workflow-studio/components/use-item-selection.test.d.ts.map +1 -0
  361. package/dist/types/editors/workflow-studio/components/waitpoints-view.test.d.ts +2 -0
  362. package/dist/types/editors/workflow-studio/components/waitpoints-view.test.d.ts.map +1 -0
  363. package/dist/types/editors/workflow-studio/components/waitpoints.test.d.ts +2 -0
  364. package/dist/types/editors/workflow-studio/components/waitpoints.test.d.ts.map +1 -0
  365. package/dist/types/editors/workflow-studio/components/workflow-order.d.ts +19 -0
  366. package/dist/types/editors/workflow-studio/components/workflow-order.d.ts.map +1 -0
  367. package/dist/types/editors/workflow-studio/components/workflow-order.test.d.ts +2 -0
  368. package/dist/types/editors/workflow-studio/components/workflow-order.test.d.ts.map +1 -0
  369. package/dist/types/pieces/ai/ai-actions.test.d.ts +2 -0
  370. package/dist/types/pieces/ai/ai-actions.test.d.ts.map +1 -0
  371. package/dist/types/pieces/ai/ai-documents.test.d.ts +2 -0
  372. package/dist/types/pieces/ai/ai-documents.test.d.ts.map +1 -0
  373. package/dist/types/pieces/ai/ai.test.d.ts +2 -0
  374. package/dist/types/pieces/ai/ai.test.d.ts.map +1 -0
  375. package/dist/types/pieces/ai/index.d.ts +7 -0
  376. package/dist/types/pieces/ai/index.d.ts.map +1 -0
  377. package/dist/types/pieces/ai/lib/action-schema.d.ts +11 -0
  378. package/dist/types/pieces/ai/lib/action-schema.d.ts.map +1 -0
  379. package/dist/types/pieces/ai/lib/actions/ask-ai.d.ts +38 -0
  380. package/dist/types/pieces/ai/lib/actions/ask-ai.d.ts.map +1 -0
  381. package/dist/types/pieces/ai/lib/actions/decide-on-documents.d.ts +45 -0
  382. package/dist/types/pieces/ai/lib/actions/decide-on-documents.d.ts.map +1 -0
  383. package/dist/types/pieces/ai/lib/actions/decide.d.ts +39 -0
  384. package/dist/types/pieces/ai/lib/actions/decide.d.ts.map +1 -0
  385. package/dist/types/pieces/ai/lib/actions/extract.d.ts +41 -0
  386. package/dist/types/pieces/ai/lib/actions/extract.d.ts.map +1 -0
  387. package/dist/types/pieces/ai/lib/actions/propose-actions.d.ts +55 -0
  388. package/dist/types/pieces/ai/lib/actions/propose-actions.d.ts.map +1 -0
  389. package/dist/types/pieces/ai/lib/actions/summarize.d.ts +38 -0
  390. package/dist/types/pieces/ai/lib/actions/summarize.d.ts.map +1 -0
  391. package/dist/types/pieces/ai/lib/auth.d.ts +16 -0
  392. package/dist/types/pieces/ai/lib/auth.d.ts.map +1 -0
  393. package/dist/types/pieces/ai/lib/decision-model.d.ts +17 -0
  394. package/dist/types/pieces/ai/lib/decision-model.d.ts.map +1 -0
  395. package/dist/types/pieces/ai/lib/documents.d.ts +11 -0
  396. package/dist/types/pieces/ai/lib/documents.d.ts.map +1 -0
  397. package/dist/types/pieces/ai/lib/model-list.d.ts +8 -0
  398. package/dist/types/pieces/ai/lib/model-list.d.ts.map +1 -0
  399. package/dist/types/pieces/ai/lib/models.d.ts +19 -0
  400. package/dist/types/pieces/ai/lib/models.d.ts.map +1 -0
  401. package/dist/types/pieces/ai/lib/props.d.ts +16 -0
  402. package/dist/types/pieces/ai/lib/props.d.ts.map +1 -0
  403. package/dist/types/pieces/ai/lib/providers.d.ts +9 -0
  404. package/dist/types/pieces/ai/lib/providers.d.ts.map +1 -0
  405. package/dist/types/pieces/ai/lib/questions.d.ts +7 -0
  406. package/dist/types/pieces/ai/lib/questions.d.ts.map +1 -0
  407. package/dist/types/pieces/index.d.ts.map +1 -1
  408. package/dist/types/pieces/reactor/index.d.ts.map +1 -1
  409. package/dist/types/pieces/reactor/lib/actions/document-create.d.ts +5 -2
  410. package/dist/types/pieces/reactor/lib/actions/document-create.d.ts.map +1 -1
  411. package/dist/types/pieces/reactor/lib/actions/document-dispatch.d.ts +3 -1
  412. package/dist/types/pieces/reactor/lib/actions/document-dispatch.d.ts.map +1 -1
  413. package/dist/types/pieces/reactor/lib/actions/document-find.d.ts +4 -1
  414. package/dist/types/pieces/reactor/lib/actions/document-find.d.ts.map +1 -1
  415. package/dist/types/pieces/reactor/lib/actions/document-get.d.ts +3 -1
  416. package/dist/types/pieces/reactor/lib/actions/document-get.d.ts.map +1 -1
  417. package/dist/types/pieces/reactor/lib/actions/document-schema.d.ts +3 -1
  418. package/dist/types/pieces/reactor/lib/actions/document-schema.d.ts.map +1 -1
  419. package/dist/types/pieces/reactor/lib/actions/document-types.d.ts +3 -1
  420. package/dist/types/pieces/reactor/lib/actions/document-types.d.ts.map +1 -1
  421. package/dist/types/pieces/reactor/lib/actions/index-query.d.ts +14 -0
  422. package/dist/types/pieces/reactor/lib/actions/index-query.d.ts.map +1 -0
  423. package/dist/types/pieces/reactor/lib/documents.d.ts +33 -0
  424. package/dist/types/pieces/reactor/lib/documents.d.ts.map +1 -0
  425. package/dist/types/pieces/reactor/lib/documents.test.d.ts +2 -0
  426. package/dist/types/pieces/reactor/lib/documents.test.d.ts.map +1 -0
  427. package/dist/types/pieces/reactor/lib/input-props.d.ts.map +1 -1
  428. package/dist/types/pieces/reactor/lib/input-schema.d.ts.map +1 -1
  429. package/dist/types/pieces/reactor/lib/parse.d.ts.map +1 -1
  430. package/dist/types/pieces/reactor/lib/reactor.d.ts +27 -4
  431. package/dist/types/pieces/reactor/lib/reactor.d.ts.map +1 -1
  432. package/dist/types/pieces/reactor/lib/triggers/document-event.d.ts +6 -6
  433. package/dist/types/pieces/reactor/lib/triggers/document-event.d.ts.map +1 -1
  434. package/dist/types/pieces/reactor/lib/writes.d.ts +7 -0
  435. package/dist/types/pieces/reactor/lib/writes.d.ts.map +1 -0
  436. package/dist/types/pieces/reactor/reactor.test.d.ts +2 -0
  437. package/dist/types/pieces/reactor/reactor.test.d.ts.map +1 -0
  438. package/dist/types/pieces/reactor/test-signer.d.ts +3 -0
  439. package/dist/types/pieces/reactor/test-signer.d.ts.map +1 -0
  440. package/dist/types/scripts/ui-stack.d.ts +21 -6
  441. package/dist/types/scripts/ui-stack.d.ts.map +1 -1
  442. package/dist/types/test/graphql-server.d.ts +9 -0
  443. package/dist/types/test/graphql-server.d.ts.map +1 -0
  444. package/dist/types/test/runtime-schema.d.ts +17 -0
  445. package/dist/types/test/runtime-schema.d.ts.map +1 -0
  446. package/dist/types/test/switchboards.d.ts +20 -0
  447. package/dist/types/test/switchboards.d.ts.map +1 -0
  448. package/dist/types/test/ui/flow-control.spec.d.ts +2 -0
  449. package/dist/types/test/ui/flow-control.spec.d.ts.map +1 -0
  450. package/dist/types/test/ui/harness/property-form-echo.d.ts +12 -0
  451. package/dist/types/test/ui/harness/property-form-echo.d.ts.map +1 -0
  452. package/dist/types/test/ui/harness/schedule-builder.d.ts +8 -0
  453. package/dist/types/test/ui/harness/schedule-builder.d.ts.map +1 -0
  454. package/dist/types/test/ui/manual-inputs.spec.d.ts +2 -0
  455. package/dist/types/test/ui/manual-inputs.spec.d.ts.map +1 -0
  456. package/dist/types/test/ui/property-form-echo.spec.d.ts +2 -0
  457. package/dist/types/test/ui/property-form-echo.spec.d.ts.map +1 -0
  458. package/dist/types/test/ui/reactor-connection.spec.d.ts +2 -0
  459. package/dist/types/test/ui/reactor-connection.spec.d.ts.map +1 -0
  460. package/dist/types/test/ui/schedule-builder.spec.d.ts +2 -0
  461. package/dist/types/test/ui/schedule-builder.spec.d.ts.map +1 -0
  462. package/dist/types/test/waitpoint-record.d.ts +3 -0
  463. package/dist/types/test/waitpoint-record.d.ts.map +1 -0
  464. package/dist/workflow.css +68 -0
  465. package/package.json +40 -11
  466. package/dist/browser/BlockSelector-BQDqIbRZ.js +0 -3053
  467. package/dist/browser/BlockSelector-BQDqIbRZ.js.map +0 -1
  468. package/dist/browser/PieceMarkdown-B8EEaQgT.js +0 -21435
  469. package/dist/browser/PieceMarkdown-B8EEaQgT.js.map +0 -1
  470. package/dist/browser/assets/entry-D62sYiFV.js +0 -318
  471. package/dist/browser/assets/projection-entry-BGcu_9-p.js +0 -446
  472. package/dist/browser/connection-form-BCxGD8Zk.js +0 -831
  473. package/dist/browser/connection-form-BCxGD8Zk.js.map +0 -1
  474. package/dist/browser/data-tree-CZZkfzSH.js +0 -1896
  475. package/dist/browser/data-tree-CZZkfzSH.js.map +0 -1
  476. package/dist/browser/document-models-C1ZgIZyV.js +0 -103
  477. package/dist/browser/editor-BCH8vdej.js.map +0 -1
  478. package/dist/browser/editor-Bd2Cu8Mx.js +0 -1793
  479. package/dist/browser/editor-Bd2Cu8Mx.js.map +0 -1
  480. package/dist/browser/editor-Bl1Xp7N8.js +0 -17234
  481. package/dist/browser/editor-Bl1Xp7N8.js.map +0 -1
  482. package/dist/browser/module-DU2vb3FH.js.map +0 -1
  483. package/dist/browser/module-jDZ4pq3W.js.map +0 -1
  484. package/dist/browser/piece-auth-BS5CtQOG.js +0 -146
  485. package/dist/browser/piece-auth-BS5CtQOG.js.map +0 -1
  486. package/dist/browser/rolldown-runtime-DC62tzP2.js +0 -33
  487. package/dist/browser/runtime-queries-Ds2kk-Ow.js +0 -2535
  488. package/dist/browser/runtime-queries-Ds2kk-Ow.js.map +0 -1
  489. package/dist/browser/trigger-text-Ld2uv0Cf.js +0 -5569
  490. package/dist/browser/trigger-text-Ld2uv0Cf.js.map +0 -1
  491. package/dist/browser/upgrade-manifests-BpakVE9l.js +0 -8
  492. package/dist/browser/workflow-BxShRhVy.js +0 -108
  493. package/dist/browser/workflow-BxShRhVy.js.map +0 -1
  494. package/dist/node/BlockSelector-C3XYZfPY.mjs.map +0 -1
  495. package/dist/node/PieceMarkdown-BMhBGa4t.mjs +0 -23281
  496. package/dist/node/PieceMarkdown-BMhBGa4t.mjs.map +0 -1
  497. package/dist/node/connection-D544oqVW.mjs +0 -90
  498. package/dist/node/connection-D544oqVW.mjs.map +0 -1
  499. package/dist/node/connection-form-CjUay_qz.mjs +0 -831
  500. package/dist/node/connection-form-CjUay_qz.mjs.map +0 -1
  501. package/dist/node/data-tree-CGfeCLr7.mjs +0 -1903
  502. package/dist/node/data-tree-CGfeCLr7.mjs.map +0 -1
  503. package/dist/node/editor-BXtXOryt.mjs +0 -247
  504. package/dist/node/editor-BXtXOryt.mjs.map +0 -1
  505. package/dist/node/editor-CXGHkwd9.mjs +0 -1793
  506. package/dist/node/editor-CXGHkwd9.mjs.map +0 -1
  507. package/dist/node/editor-D0FCvyPb.mjs +0 -17365
  508. package/dist/node/editor-D0FCvyPb.mjs.map +0 -1
  509. package/dist/node/editors/connection-editor/module.mjs +0 -15
  510. package/dist/node/editors/connection-editor/module.mjs.map +0 -1
  511. package/dist/node/editors/workflow-editor/module.mjs +0 -15
  512. package/dist/node/editors/workflow-editor/module.mjs.map +0 -1
  513. package/dist/node/editors/workflow-studio/module.mjs +0 -15
  514. package/dist/node/editors/workflow-studio/module.mjs.map +0 -1
  515. package/dist/node/module-BMwJQh65.mjs.map +0 -1
  516. package/dist/node/module-Dhe5E-VA.mjs.map +0 -1
  517. package/dist/node/piece-auth-BS5CtQOG.mjs.map +0 -1
  518. package/dist/node/pieces/reactor/index.mjs.map +0 -1
  519. package/dist/node/rolldown-runtime-BMI-E3GI.mjs +0 -44
  520. package/dist/node/runtime-queries-D5EGaCrH.mjs +0 -2544
  521. package/dist/node/runtime-queries-D5EGaCrH.mjs.map +0 -1
  522. package/dist/node/style.css +0 -667
  523. package/dist/node/trigger-text-CMWxL7t_.mjs +0 -6765
  524. package/dist/node/trigger-text-CMWxL7t_.mjs.map +0 -1
  525. package/dist/node/upgrade-manifests-CmNd742Y.mjs +0 -8
  526. package/dist/node/workflow-CGzYGZnr.mjs.map +0 -1
  527. package/dist/types/ai/runtime-url.d.ts +0 -2
  528. package/dist/types/ai/runtime-url.d.ts.map +0 -1
  529. package/dist/types/ai/runtime-url.test.d.ts +0 -2
  530. package/dist/types/ai/runtime-url.test.d.ts.map +0 -1
  531. package/dist/types/editors/workflow-editor/use-runtime-url.d.ts +0 -2
  532. package/dist/types/editors/workflow-editor/use-runtime-url.d.ts.map +0 -1
  533. package/dist/types/editors/workflow-studio/components/use-hash-selection.d.ts +0 -5
  534. package/dist/types/editors/workflow-studio/components/use-hash-selection.d.ts.map +0 -1
  535. package/dist/types/pieces/reactor/lib/actions/dispatch-outcome.test.d.ts +0 -2
  536. package/dist/types/pieces/reactor/lib/actions/dispatch-outcome.test.d.ts.map +0 -1
@@ -0,0 +1,3219 @@
1
+ import { I as MANUAL_TRIGGER, M as CALL_FLOW_BLOCK, N as CORE_PIECE, Q as triggerBlock, U as SUBFLOWS_PIECE, X as stepBlock, Y as sameBlock, l as runsOfPages } from "./runtime-queries-FmEzElOY.js";
2
+ import { y as actions } from "./module-mFCt9WHJ.js";
3
+ import { r as useWorkflowDocumentsInSelectedDrive } from "./workflow-2gR2JXUS.js";
4
+ import { A as formatTrigger, At as Button, C as TONE_DOT, D as formatAbsolute, Dt as ITEM_PARAM, E as durationMs, Et as useWaitingRunsQuery, F as runTimeline, Ht as textAreaClass, I as runTone, It as Select, Jt as errorMessage, Kt as DocumentErrorBoundary, L as statusLabel, Lt as Switch, M as formatWhen, N as runStats, O as formatDuration, Ot as useSearchParam, P as runStatusLabel, R as toneOf, S as STEP_TONE, T as canRerun, Ut as textInputClass, Wt as Icon, b as RUN_STATUSES, bt as useRunPagesQuery, f as blockMeta, gt as WorkflowRuntimeProvider, j as formatUntil, k as formatMs, kt as useSearchParamDraft, qt as DocumentLoadError, t as BlockLogo, v as usePieceLogos, w as TONE_TEXT, wt as useRuntimeActions, x as RUN_TONE, xt as useRunQuery, y as CONNECTION_TONE, z as workflowHealth } from "./BlockSelector-CEdYUqjx.js";
5
+ import { C as PropertyForm, a as StepError, c as stepOutline, f as PublishState, h as StatusToggle, i as DataViewer, r as describeTrigger, s as graphLayout } from "./trigger-text-DH6HIeoa.js";
6
+ import { generateId } from "document-model";
7
+ import { addDocument, addFolder, deleteNode, getPHStore, showDeleteNodeModal, useDispatch, useDocumentSafe, useFileNodesInSelectedDrive, useNodesInSelectedDrive, usePHToast, useSearchParams, useSelectedDrive, useSelectedNode, useSetPHAppConfig, useSetSearchParams, useSetSelectedNode } from "@powerhousedao/reactor-browser";
8
+ import { ManualPayloadError, coerceManualPayload, manualDefault, parseManualInputs, stepPortLabel } from "@powerhousedao/pieces-framework/workflow";
9
+ import { Fragment, Suspense, lazy, useCallback, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
10
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
11
+ import { ConnectTooltip, ConnectTooltipProvider, Modal } from "@powerhousedao/design-system/connect";
12
+ import { addFolder as addFolder$1, moveNode, updateNode } from "@powerhousedao/shared/document-drive";
13
+ //#region editors/workflow-editor/ui/manual-inputs.ts
14
+ const PROPERTY_TYPES = {
15
+ text: "SHORT_TEXT",
16
+ text_area: "LONG_TEXT",
17
+ number: "NUMBER",
18
+ toggle: "CHECKBOX",
19
+ date: "DATE_TIME",
20
+ dropdown: "STATIC_DROPDOWN",
21
+ json: "JSON"
22
+ };
23
+ function manualInputProp(input) {
24
+ const defaultValue = manualDefault(input);
25
+ return {
26
+ name: input.name,
27
+ displayName: input.displayName,
28
+ type: PROPERTY_TYPES[input.type],
29
+ required: input.type === "toggle" ? false : input.required,
30
+ ...input.description ? { description: input.description } : {},
31
+ ...defaultValue !== void 0 ? { defaultValue } : {},
32
+ ...input.type === "dropdown" ? { staticOptions: (input.options ?? []).map(({ value, label }) => ({
33
+ value,
34
+ label
35
+ })) } : {}
36
+ };
37
+ }
38
+ function manualRunPayload(inputs, values) {
39
+ try {
40
+ return coerceManualPayload(inputs, values);
41
+ } catch (error) {
42
+ if (!(error instanceof ManualPayloadError)) throw error;
43
+ const label = (name) => inputs.find((input) => input.name === name)?.displayName ?? name;
44
+ throw new Error(error.fields.map((entry) => `${label(entry.field)} ${entry.message}`).join("; "), { cause: error });
45
+ }
46
+ }
47
+ function manualInputValues(inputs) {
48
+ const values = {};
49
+ for (const input of inputs) {
50
+ const value = manualDefault(input);
51
+ if (value !== void 0) values[input.name] = value;
52
+ else if (input.type === "toggle") values[input.name] = false;
53
+ }
54
+ return values;
55
+ }
56
+ //#endregion
57
+ //#region editors/workflow-studio/components/ui.tsx
58
+ function StatusDot(props) {
59
+ const hollow = props.hollow ?? props.tone === "idle";
60
+ return /* @__PURE__ */ jsx("span", {
61
+ "aria-hidden": true,
62
+ className: `inline-block h-2 w-2 shrink-0 rounded-full ${hollow ? "border border-solid border-muted-foreground/60" : TONE_DOT[props.tone]} ${props.className ?? ""}`
63
+ });
64
+ }
65
+ function StatusText(props) {
66
+ return /* @__PURE__ */ jsxs("span", {
67
+ className: `inline-flex items-center gap-1.5 font-medium ${TONE_TEXT[props.tone]} ${props.className ?? ""}`,
68
+ children: [/* @__PURE__ */ jsx(StatusDot, { tone: props.tone }), props.label ?? statusLabel(props.status)]
69
+ });
70
+ }
71
+ /** A label/value pair for a header's facts line. */
72
+ function Fact(props) {
73
+ return /* @__PURE__ */ jsxs("div", {
74
+ className: "flex min-w-0 flex-col gap-0.5",
75
+ title: props.title,
76
+ children: [/* @__PURE__ */ jsx("dt", {
77
+ className: "text-xs text-muted-foreground",
78
+ children: props.label
79
+ }), /* @__PURE__ */ jsx("dd", {
80
+ className: "truncate text-[13px] tabular-nums text-foreground",
81
+ children: props.children
82
+ })]
83
+ });
84
+ }
85
+ //#endregion
86
+ //#region editors/workflow-studio/components/RunDialog.tsx
87
+ function RunDialog(props) {
88
+ const fields = useMemo(() => props.inputs.map(manualInputProp), [props.inputs]);
89
+ const [values, setValues] = useState(() => manualInputValues(props.inputs));
90
+ const latest = useRef(values);
91
+ const [raw, setRaw] = useState(null);
92
+ const [error, setError] = useState(null);
93
+ const [firing, setFiring] = useState(false);
94
+ const rawId = useId();
95
+ const payload = () => {
96
+ if (raw === null) return manualRunPayload(props.inputs, latest.current);
97
+ try {
98
+ return JSON.parse(raw === "" ? "{}" : raw);
99
+ } catch {
100
+ throw new Error("The payload is not valid JSON.");
101
+ }
102
+ };
103
+ return /* @__PURE__ */ jsx(Modal, {
104
+ open: true,
105
+ title: "Run workflow",
106
+ onOpenChange: (open) => {
107
+ if (!open) props.onCancel();
108
+ },
109
+ contentProps: {
110
+ className: "max-h-[85vh] w-[32rem] max-w-[92vw] overflow-y-auto rounded-xl border border-solid border-foreground/10",
111
+ "aria-label": "Run workflow"
112
+ },
113
+ children: /* @__PURE__ */ jsxs("form", {
114
+ className: "flex flex-col gap-4 p-6",
115
+ noValidate: true,
116
+ onSubmit: (event) => {
117
+ event.preventDefault();
118
+ if (firing) return;
119
+ document.activeElement?.blur();
120
+ let body;
121
+ try {
122
+ body = payload();
123
+ } catch (cause) {
124
+ setError(cause instanceof Error ? cause.message : String(cause));
125
+ return;
126
+ }
127
+ setFiring(true);
128
+ setError(null);
129
+ props.onFire(body).then((fireError) => fireError, (cause) => cause instanceof Error ? cause.message : String(cause)).then((fireError) => {
130
+ setFiring(false);
131
+ if (fireError) setError(fireError);
132
+ else props.onCancel();
133
+ });
134
+ },
135
+ children: [
136
+ /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("h2", {
137
+ className: "text-[15px] font-semibold text-foreground",
138
+ children: "Run workflow"
139
+ }), /* @__PURE__ */ jsxs("p", {
140
+ className: "mt-1 text-[13px] text-muted-foreground",
141
+ children: [
142
+ "The run reads these as ",
143
+ "{{trigger.payload.<key>}}",
144
+ "."
145
+ ]
146
+ })] }),
147
+ /* @__PURE__ */ jsx(Switch, {
148
+ label: "Raw JSON",
149
+ checked: raw !== null,
150
+ onChange: (on) => {
151
+ setError(null);
152
+ if (!on) return setRaw(null);
153
+ setRaw(JSON.stringify(latest.current, null, 2));
154
+ }
155
+ }),
156
+ raw === null ? /* @__PURE__ */ jsx(PropertyForm, {
157
+ props: fields,
158
+ value: values,
159
+ onChange: (next) => {
160
+ latest.current = next;
161
+ setValues(next);
162
+ }
163
+ }) : /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("label", {
164
+ htmlFor: rawId,
165
+ className: "mb-1.5 block text-[13px] font-medium text-foreground",
166
+ children: "Payload"
167
+ }), /* @__PURE__ */ jsx("textarea", {
168
+ id: rawId,
169
+ className: `${textAreaClass} min-h-40 font-mono text-xs`,
170
+ value: raw,
171
+ spellCheck: false,
172
+ onChange: (event) => setRaw(event.target.value)
173
+ })] }),
174
+ error ? /* @__PURE__ */ jsx("p", {
175
+ role: "alert",
176
+ className: "rounded-md bg-wf-fail/10 px-3 py-2 text-[13px] text-wf-fail",
177
+ children: error
178
+ }) : null,
179
+ /* @__PURE__ */ jsxs("div", {
180
+ className: "flex justify-end gap-2",
181
+ children: [/* @__PURE__ */ jsx(Button, {
182
+ onClick: props.onCancel,
183
+ children: "Cancel"
184
+ }), /* @__PURE__ */ jsxs(Button, {
185
+ type: "submit",
186
+ variant: "primary",
187
+ disabled: firing,
188
+ children: [/* @__PURE__ */ jsx(Icon, {
189
+ name: "play",
190
+ className: "h-3.5 w-3.5"
191
+ }), firing ? "Running…" : "Run"]
192
+ })]
193
+ })
194
+ ]
195
+ })
196
+ });
197
+ }
198
+ //#endregion
199
+ //#region editors/workflow-studio/components/tips.tsx
200
+ function TipProvider(props) {
201
+ return /* @__PURE__ */ jsx(ConnectTooltipProvider, {
202
+ disableHoverableContent: true,
203
+ children: props.children
204
+ });
205
+ }
206
+ function Tip(props) {
207
+ return /* @__PURE__ */ jsx(ConnectTooltip, {
208
+ content: props.content,
209
+ side: "bottom",
210
+ delayDuration: 100,
211
+ className: "max-w-64 rounded-md border-solid border-foreground/10 bg-card px-2.5 py-1.5 text-foreground shadow-lg",
212
+ children: props.children
213
+ });
214
+ }
215
+ const PORT_TEXT = {
216
+ true: "Runs when the condition is true",
217
+ false: "Runs when the condition is false",
218
+ error: "Runs when the step before it fails",
219
+ each: "Runs once for each item of the loop before it",
220
+ otherwise: "Runs when no branch of the router before it holds"
221
+ };
222
+ function stepSummary(record, ran) {
223
+ if (!ran) return "Not run yet";
224
+ if (!record) return "Not reached in the latest run";
225
+ const took = record.startedAt && record.endedAt ? ` · ${formatDuration(record.startedAt, record.endedAt)}` : "";
226
+ return `${statusLabel(record.status)} in the latest run${took}`;
227
+ }
228
+ function StepTip(props) {
229
+ const { step } = props;
230
+ const meta = blockMeta(stepBlock(step));
231
+ return /* @__PURE__ */ jsxs("span", {
232
+ className: "flex flex-col gap-0.5",
233
+ children: [
234
+ /* @__PURE__ */ jsx("span", {
235
+ className: "font-medium",
236
+ children: step.name || step.key
237
+ }),
238
+ /* @__PURE__ */ jsxs("span", {
239
+ className: "text-muted-foreground",
240
+ children: [
241
+ meta.displayName,
242
+ " · ",
243
+ meta.subtitle
244
+ ]
245
+ }),
246
+ props.port ? /* @__PURE__ */ jsx("span", {
247
+ className: "text-muted-foreground",
248
+ children: PORT_TEXT[props.port] ?? (/^branch_\d+$/.test(props.port) ? "Runs when its router branch holds" : `Runs on "${props.port}"`)
249
+ }) : null,
250
+ /* @__PURE__ */ jsx("span", {
251
+ className: "mt-1",
252
+ children: stepSummary(props.record, props.ran)
253
+ }),
254
+ props.record?.error ? /* @__PURE__ */ jsx("span", {
255
+ className: "line-clamp-3 text-wf-fail",
256
+ children: props.record.error
257
+ }) : null
258
+ ]
259
+ });
260
+ }
261
+ function TriggerTip(props) {
262
+ const meta = props.trigger ? blockMeta(props.trigger) : null;
263
+ return /* @__PURE__ */ jsxs("span", {
264
+ className: "flex flex-col gap-0.5",
265
+ children: [
266
+ /* @__PURE__ */ jsx("span", {
267
+ className: "font-medium",
268
+ children: meta?.displayName ?? "No trigger"
269
+ }),
270
+ props.text && props.text !== meta?.displayName ? /* @__PURE__ */ jsx("span", { children: props.text }) : null,
271
+ meta ? /* @__PURE__ */ jsx("span", {
272
+ className: "text-muted-foreground",
273
+ children: meta.subtitle
274
+ }) : null,
275
+ /* @__PURE__ */ jsx("span", {
276
+ className: "mt-1",
277
+ children: props.latest ? `Last fired ${formatWhen(props.latest.startedAt)}` : "Not fired yet"
278
+ })
279
+ ]
280
+ });
281
+ }
282
+ //#endregion
283
+ //#region editors/workflow-studio/components/chain.tsx
284
+ const RING$2 = {
285
+ ok: "ring-wf-ok",
286
+ fail: "ring-wf-fail",
287
+ warn: "ring-wf-warn",
288
+ run: "ring-wf-run",
289
+ idle: "ring-foreground/15 dark:ring-foreground/30"
290
+ };
291
+ const RAIL$1 = {
292
+ ok: "bg-wf-ok",
293
+ fail: "bg-wf-fail",
294
+ warn: "bg-wf-warn",
295
+ run: "bg-wf-run",
296
+ idle: "bg-foreground/15 dark:bg-foreground/30"
297
+ };
298
+ const MAX_STOPS = 6;
299
+ function MiniChain(props) {
300
+ const md = props.size === "md";
301
+ const overflow = props.links.length > MAX_STOPS;
302
+ const shown = overflow ? props.links.slice(0, 5) : props.links;
303
+ const hidden = props.links.length - shown.length;
304
+ const tones = shown.map((link) => link.status ? toneOf(STEP_TONE, link.status) : "idle");
305
+ return /* @__PURE__ */ jsx(TipProvider, { children: /* @__PURE__ */ jsxs("ol", {
306
+ className: "flex items-center",
307
+ "aria-label": props.links.map((link) => `${link.label}${link.status ? `: ${link.status.toLowerCase()}` : ""}`).join(", "),
308
+ children: [shown.map((link, index) => /* @__PURE__ */ jsxs("li", {
309
+ className: "flex items-center",
310
+ children: [index > 0 ? /* @__PURE__ */ jsx("span", {
311
+ "aria-hidden": true,
312
+ className: `h-0.5 ${md ? "w-5" : "w-3"} ${RAIL$1[tones[index]]}`
313
+ }) : null, /* @__PURE__ */ jsx(Tip, {
314
+ content: link.tip ?? (link.status ? `${link.label}: ${link.status.toLowerCase()}` : link.label),
315
+ children: /* @__PURE__ */ jsx("span", {
316
+ className: `flex shrink-0 items-center justify-center rounded-full bg-card ${md ? "h-8 w-8" : "h-6 w-6"} ${link.status === "SKIPPED" ? "border-[1.5px] border-dashed border-foreground/40" : `ring-[1.5px] dark:bg-white ${RING$2[tones[index]]}`}`,
317
+ children: /* @__PURE__ */ jsx("span", {
318
+ className: link.status === "SKIPPED" ? "flex opacity-40" : "flex",
319
+ children: /* @__PURE__ */ jsx(BlockLogo, {
320
+ bare: true,
321
+ block: link.block,
322
+ size: md ? 16 : 14
323
+ })
324
+ })
325
+ })
326
+ })]
327
+ }, link.id)), overflow ? /* @__PURE__ */ jsxs("li", {
328
+ "aria-hidden": true,
329
+ className: "flex items-center",
330
+ children: [/* @__PURE__ */ jsx("span", { className: `h-0.5 ${md ? "w-5" : "w-3"} bg-foreground/15` }), /* @__PURE__ */ jsx(Tip, {
331
+ content: props.links.slice(shown.length).map((link) => link.label).join(", "),
332
+ children: /* @__PURE__ */ jsxs("span", {
333
+ className: `flex shrink-0 items-center justify-center rounded-full bg-muted px-1.5 text-[11px] font-medium tabular-nums text-muted-foreground ${md ? "h-8" : "h-6"}`,
334
+ children: ["+", hidden]
335
+ })
336
+ })]
337
+ }) : null]
338
+ }) });
339
+ }
340
+ function triggerOfKind(kind) {
341
+ if (kind.startsWith("piece:")) {
342
+ const rest = kind.slice(6);
343
+ const colon = rest.indexOf(":");
344
+ if (colon > 0) return {
345
+ pieceName: rest.slice(0, colon),
346
+ kind: "trigger",
347
+ name: rest.slice(colon + 1)
348
+ };
349
+ }
350
+ return {
351
+ pieceName: CORE_PIECE,
352
+ kind: "trigger",
353
+ name: kind
354
+ };
355
+ }
356
+ /** A workflow's steps in the order a run reaches them, coloured by a run. */
357
+ function workflowLinks(workflow, latest) {
358
+ const records = new Map((latest?.steps ?? []).map((record) => [record.stepKey, record]));
359
+ return graphLayout(workflow).nodes.map(({ step, port }) => {
360
+ const record = records.get(step.key);
361
+ return {
362
+ id: step.id,
363
+ block: stepBlock(step),
364
+ label: step.name || step.key,
365
+ status: record?.status,
366
+ tip: /* @__PURE__ */ jsx(StepTip, {
367
+ step,
368
+ port,
369
+ record,
370
+ ran: Boolean(latest)
371
+ })
372
+ };
373
+ });
374
+ }
375
+ /** A run's own chain: the trigger, then every step it recorded. */
376
+ function runLinks(run, trigger) {
377
+ return [{
378
+ id: "trigger",
379
+ block: trigger ?? triggerOfKind(run.triggerKind),
380
+ label: "Trigger",
381
+ status: "SUCCEEDED"
382
+ }, ...run.steps.map((step) => ({
383
+ id: step.stepId + step.stepKey,
384
+ block: {
385
+ pieceName: step.pieceName,
386
+ kind: "action",
387
+ name: step.blockName
388
+ },
389
+ label: step.stepKey,
390
+ status: step.status
391
+ }))];
392
+ }
393
+ const STRIP_LENGTH = 14;
394
+ const TICK = {
395
+ ok: "bg-wf-ok",
396
+ fail: "bg-wf-fail",
397
+ warn: "bg-wf-warn",
398
+ run: "bg-wf-run animate-pulse",
399
+ idle: "bg-foreground/25"
400
+ };
401
+ /** Recent runs as ticks, oldest to newest, padded so strips line up. */
402
+ function RunStrip(props) {
403
+ const recent = props.runs.slice(0, STRIP_LENGTH).reverse();
404
+ const padding = STRIP_LENGTH - recent.length;
405
+ return /* @__PURE__ */ jsx(TipProvider, { children: /* @__PURE__ */ jsxs("span", {
406
+ className: `flex h-5 gap-[3px] ${props.centered ? "items-center" : "items-end"}`,
407
+ "aria-label": recent.length === 0 ? "No runs yet" : `Last ${recent.length} runs: ${recent.map((run) => run.status.toLowerCase()).join(", ")}`,
408
+ children: [Array.from({ length: padding }, (_, index) => /* @__PURE__ */ jsx("span", {
409
+ "aria-hidden": true,
410
+ className: "h-1.5 w-1.5 rounded-full bg-foreground/10"
411
+ }, `pad-${index}`)), recent.map((run) => /* @__PURE__ */ jsx(Tip, {
412
+ content: `${statusLabel(run.status)}, ${formatAbsolute(run.startedAt)}`,
413
+ children: /* @__PURE__ */ jsx("span", {
414
+ "aria-hidden": true,
415
+ className: `h-5 w-1.5 rounded-full ${TICK[toneOf(RUN_TONE, run.status)]}`
416
+ })
417
+ }, run.id))]
418
+ }) });
419
+ }
420
+ //#endregion
421
+ //#region editors/workflow-studio/components/Waitpoints.tsx
422
+ const PieceMarkdown = lazy(() => import("./PieceMarkdown-DSdZd-Jc.js"));
423
+ const WAITING_POLL_MS = 3e4;
424
+ function isOpenApproval(waitpoint) {
425
+ return waitpoint.status === "PENDING" && waitpoint.kind === "approval";
426
+ }
427
+ function waitDescription(waitpoint, stepName, step) {
428
+ if (waitpoint.kind === "delay") return waitpoint.resumeAt ? `${stepName} is waiting until ${formatAbsolute(waitpoint.resumeAt)}` : `${stepName} is waiting for its delay`;
429
+ const expiry = waitpoint.expiresAt ? `, until ${formatAbsolute(waitpoint.expiresAt)}` : "";
430
+ if (step?.pieceName === SUBFLOWS_PIECE && step.blockName === CALL_FLOW_BLOCK.name) return `${stepName} is waiting for the called workflow to respond${expiry}`;
431
+ return `${stepName} is waiting for a webhook callback${expiry}`;
432
+ }
433
+ function cancelFailure(result) {
434
+ if (!result) return "The run was not found";
435
+ if (result.status === "CANCELLED") return null;
436
+ return result.error ?? `The run is ${result.status}`;
437
+ }
438
+ function countPendingApprovals(runs, limit) {
439
+ const byWorkflow = /* @__PURE__ */ new Map();
440
+ let total = 0;
441
+ for (const run of runs ?? []) {
442
+ const open = (run.waitpoints ?? []).filter(isOpenApproval).length;
443
+ if (open === 0) continue;
444
+ total += open;
445
+ byWorkflow.set(run.workflowId, (byWorkflow.get(run.workflowId) ?? 0) + open);
446
+ }
447
+ return {
448
+ total,
449
+ byWorkflow,
450
+ capped: (runs?.length ?? 0) >= limit
451
+ };
452
+ }
453
+ function approvalCountText(count, capped) {
454
+ return capped ? `${count}+` : String(count);
455
+ }
456
+ function approvalCountLabel(count, capped) {
457
+ const noun = count === 1 && !capped ? "approval" : "approvals";
458
+ return `${approvalCountText(count, capped)} ${noun} waiting`;
459
+ }
460
+ function usePendingApprovals(driveId) {
461
+ return countPendingApprovals(useWaitingRunsQuery({
462
+ driveId,
463
+ first: 100
464
+ }, { pollMs: WAITING_POLL_MS }).data, 100);
465
+ }
466
+ function ApprovalBadge(props) {
467
+ if (props.count === 0) return null;
468
+ const label = approvalCountLabel(props.count, props.capped);
469
+ const className = `inline-flex h-5 shrink-0 items-center gap-1 rounded-full bg-wf-warn/12 px-1.5 text-[11px] font-medium tabular-nums text-wf-warn ${props.className ?? ""}`;
470
+ const content = /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(Icon, {
471
+ name: "clock",
472
+ className: "h-3 w-3"
473
+ }), approvalCountText(props.count, props.capped)] });
474
+ return props.onClick ? /* @__PURE__ */ jsx("button", {
475
+ type: "button",
476
+ title: label,
477
+ "aria-label": label,
478
+ className: `${className} hover:bg-wf-warn/20 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,
479
+ onClick: (event) => {
480
+ event.stopPropagation();
481
+ props.onClick();
482
+ },
483
+ children: content
484
+ }) : /* @__PURE__ */ jsx("span", {
485
+ role: "img",
486
+ title: label,
487
+ "aria-label": label,
488
+ className,
489
+ children: content
490
+ });
491
+ }
492
+ function reasonRequired(waitpoint, approved) {
493
+ const policy = waitpoint.approval?.reasonRequiredOn ?? "none";
494
+ return policy === "both" || policy === "reject" && !approved;
495
+ }
496
+ function errorText(error) {
497
+ return error instanceof Error ? error.message : String(error);
498
+ }
499
+ function ApprovalCard(props) {
500
+ const { waitpoint } = props;
501
+ const { resolveWaitpoint } = useRuntimeActions();
502
+ const reasonId = useId();
503
+ const [reason, setReason] = useState("");
504
+ const [busy, setBusy] = useState(null);
505
+ const [error, setError] = useState(null);
506
+ const approval = waitpoint.approval;
507
+ const stepName = props.stepName ?? waitpoint.stepKey;
508
+ const policy = approval?.reasonRequiredOn ?? "none";
509
+ const expiresIn = waitpoint.expiresAt ? formatUntil(waitpoint.expiresAt) : null;
510
+ const decide = (approved) => {
511
+ const trimmed = reason.trim();
512
+ if (reasonRequired(waitpoint, approved) && !trimmed) {
513
+ setError(`Give a reason to ${approved ? "approve" : "disapprove"} this request.`);
514
+ return;
515
+ }
516
+ setBusy(approved);
517
+ setError(null);
518
+ resolveWaitpoint(waitpoint, approved, trimmed || void 0).then(() => props.onResolved?.()).catch((resolveError) => setError(errorText(resolveError))).finally(() => setBusy(null));
519
+ };
520
+ return /* @__PURE__ */ jsxs("section", {
521
+ "aria-label": `Approval for ${stepName}`,
522
+ className: "overflow-hidden rounded-xl border border-solid border-foreground/10 bg-card",
523
+ children: [/* @__PURE__ */ jsxs("div", {
524
+ className: "flex items-start gap-3 px-4 py-3.5",
525
+ children: [/* @__PURE__ */ jsx("span", {
526
+ "aria-hidden": true,
527
+ className: "flex h-7 w-7 shrink-0 items-center justify-center rounded-full bg-wf-warn/12 text-wf-warn",
528
+ children: /* @__PURE__ */ jsx(Icon, {
529
+ name: "clock",
530
+ className: "h-3.5 w-3.5"
531
+ })
532
+ }), /* @__PURE__ */ jsxs("div", {
533
+ className: "min-w-0 grow space-y-3",
534
+ children: [
535
+ /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("h3", {
536
+ className: "text-[13px] font-semibold text-foreground",
537
+ children: approval?.title || `Waiting at ${stepName}`
538
+ }), /* @__PURE__ */ jsxs("p", {
539
+ className: "mt-0.5 flex flex-wrap items-center gap-x-3 gap-y-0.5 text-xs text-muted-foreground",
540
+ children: [
541
+ props.meta,
542
+ /* @__PURE__ */ jsxs("span", {
543
+ title: formatAbsolute(waitpoint.createdAt),
544
+ children: ["Asked ", formatWhen(waitpoint.createdAt)]
545
+ }),
546
+ waitpoint.expiresAt ? /* @__PURE__ */ jsx("span", {
547
+ title: formatAbsolute(waitpoint.expiresAt),
548
+ className: expiresIn ? void 0 : "text-wf-warn",
549
+ children: expiresIn ? `Expires ${expiresIn}` : "Expired"
550
+ }) : null
551
+ ]
552
+ })] }),
553
+ approval?.body ? /* @__PURE__ */ jsx(Suspense, {
554
+ fallback: /* @__PURE__ */ jsx("p", {
555
+ className: "whitespace-pre-wrap text-[13px] text-foreground",
556
+ children: approval.body
557
+ }),
558
+ children: /* @__PURE__ */ jsx(PieceMarkdown, {
559
+ text: approval.body,
560
+ className: "max-w-prose text-[13px] text-foreground"
561
+ })
562
+ }) : null,
563
+ approval && approval.approvers.length > 0 ? /* @__PURE__ */ jsxs("p", {
564
+ className: "text-xs text-muted-foreground",
565
+ title: approval.approvers.join("\n"),
566
+ children: [
567
+ "Only ",
568
+ approval.approvers.length,
569
+ " listed",
570
+ " ",
571
+ approval.approvers.length === 1 ? "approver" : "approvers",
572
+ " can decide."
573
+ ]
574
+ }) : null
575
+ ]
576
+ })]
577
+ }), /* @__PURE__ */ jsxs("div", {
578
+ className: "border-t border-solid border-border bg-muted/40 px-4 py-3",
579
+ children: [
580
+ /* @__PURE__ */ jsxs("label", {
581
+ htmlFor: reasonId,
582
+ className: "mb-1.5 flex items-baseline gap-1.5 text-[13px] font-medium text-foreground",
583
+ children: ["Reason", /* @__PURE__ */ jsx("span", {
584
+ className: "text-xs font-normal text-muted-foreground",
585
+ children: policy === "none" ? "Optional" : policy === "reject" ? "Required to disapprove" : "Required"
586
+ })]
587
+ }),
588
+ /* @__PURE__ */ jsx("textarea", {
589
+ id: reasonId,
590
+ className: `${textAreaClass} min-h-16 resize-y`,
591
+ rows: 2,
592
+ value: reason,
593
+ onChange: (event) => setReason(event.target.value)
594
+ }),
595
+ /* @__PURE__ */ jsxs("div", {
596
+ className: "mt-3 flex flex-wrap items-center justify-end gap-2",
597
+ children: [
598
+ error ? /* @__PURE__ */ jsx("span", {
599
+ role: "alert",
600
+ className: "mr-auto text-xs text-wf-fail",
601
+ children: error
602
+ }) : null,
603
+ /* @__PURE__ */ jsxs(Button, {
604
+ variant: "destructive",
605
+ disabled: busy !== null,
606
+ onClick: () => decide(false),
607
+ children: [/* @__PURE__ */ jsx(Icon, {
608
+ name: "close",
609
+ className: "h-3.5 w-3.5"
610
+ }), busy === false ? "Disapproving…" : approval?.rejectLabel || "Disapprove"]
611
+ }),
612
+ /* @__PURE__ */ jsxs(Button, {
613
+ variant: "primary",
614
+ disabled: busy !== null,
615
+ onClick: () => decide(true),
616
+ children: [/* @__PURE__ */ jsx(Icon, {
617
+ name: "check",
618
+ className: "h-3.5 w-3.5"
619
+ }), busy === true ? "Approving…" : approval?.approveLabel || "Approve"]
620
+ })
621
+ ]
622
+ })
623
+ ]
624
+ })]
625
+ });
626
+ }
627
+ function RunWaitpoints(props) {
628
+ const open = props.waitpoints.filter((waitpoint) => waitpoint.status === "PENDING");
629
+ if (open.length === 0) return null;
630
+ return /* @__PURE__ */ jsx("div", {
631
+ className: "space-y-2",
632
+ children: open.map((waitpoint) => waitpoint.kind === "approval" ? /* @__PURE__ */ jsx(ApprovalCard, {
633
+ waitpoint,
634
+ stepName: props.names.get(waitpoint.stepKey),
635
+ onResolved: props.onChanged
636
+ }, waitpoint.id) : /* @__PURE__ */ jsxs("p", {
637
+ className: "flex items-center gap-2 rounded-md bg-wf-warn/10 px-3 py-2 text-[13px] text-wf-warn",
638
+ children: [/* @__PURE__ */ jsx(Icon, {
639
+ name: "clock",
640
+ className: "h-3.5 w-3.5"
641
+ }), waitDescription(waitpoint, props.names.get(waitpoint.stepKey) ?? waitpoint.stepKey, props.steps?.find((step) => step.stepKey === waitpoint.stepKey))]
642
+ }, waitpoint.id))
643
+ });
644
+ }
645
+ function CancelRunButton(props) {
646
+ const { cancelRun } = useRuntimeActions();
647
+ const [cancelling, setCancelling] = useState(false);
648
+ const [error, setError] = useState(null);
649
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsxs(Button, {
650
+ variant: "danger",
651
+ disabled: cancelling,
652
+ onClick: () => {
653
+ setCancelling(true);
654
+ setError(null);
655
+ cancelRun(props.run.id).then((result) => setError(cancelFailure(result))).catch((cancelError) => setError(errorText(cancelError))).finally(() => {
656
+ setCancelling(false);
657
+ props.onChanged();
658
+ });
659
+ },
660
+ children: [/* @__PURE__ */ jsx(Icon, {
661
+ name: "close",
662
+ className: "h-3.5 w-3.5"
663
+ }), cancelling ? "Cancelling…" : "Cancel run"]
664
+ }), error ? /* @__PURE__ */ jsx("span", {
665
+ className: "text-wf-fail",
666
+ children: error
667
+ }) : null] });
668
+ }
669
+ function WaitingApprovals(props) {
670
+ const query = useWaitingRunsQuery({
671
+ driveId: props.driveId,
672
+ workflowId: props.workflowId,
673
+ first: 100
674
+ }, { pollMs: WAITING_POLL_MS });
675
+ const entries = (query.data ?? []).flatMap((run) => (run.waitpoints ?? []).filter(isOpenApproval).map((waitpoint) => ({
676
+ run,
677
+ waitpoint
678
+ })));
679
+ const capped = (query.data?.length ?? 0) >= 100;
680
+ const sectionRef = useRef(null);
681
+ const handled = useRef(0);
682
+ const shown = entries.length > 0;
683
+ useEffect(() => {
684
+ const request = props.focusRequest ?? 0;
685
+ if (!shown || request === handled.current) return;
686
+ handled.current = request;
687
+ sectionRef.current?.scrollIntoView({
688
+ behavior: "smooth",
689
+ block: "start"
690
+ });
691
+ sectionRef.current?.focus({ preventScroll: true });
692
+ }, [props.focusRequest, shown]);
693
+ if (!shown) return null;
694
+ return /* @__PURE__ */ jsxs("section", {
695
+ ref: sectionRef,
696
+ tabIndex: -1,
697
+ "aria-label": "Waiting for approval",
698
+ className: "mb-8 scroll-mt-4 focus:outline-none",
699
+ children: [/* @__PURE__ */ jsxs("h2", {
700
+ className: "mb-4 flex items-center gap-2 text-[15px] font-semibold text-foreground",
701
+ children: ["Waiting for approval", /* @__PURE__ */ jsx(ApprovalBadge, {
702
+ count: entries.length,
703
+ capped
704
+ })]
705
+ }), /* @__PURE__ */ jsx("div", {
706
+ className: "space-y-3",
707
+ children: entries.map(({ run, waitpoint }) => {
708
+ const names = props.stepNames.get(run.workflowId);
709
+ return /* @__PURE__ */ jsx(ApprovalCard, {
710
+ waitpoint,
711
+ stepName: names?.get(waitpoint.stepKey),
712
+ onResolved: props.onChanged,
713
+ meta: /* @__PURE__ */ jsxs(Fragment$1, { children: [props.showWorkflow ? /* @__PURE__ */ jsx("span", {
714
+ className: "font-medium text-foreground",
715
+ children: run.workflowName
716
+ }) : null, /* @__PURE__ */ jsxs("span", {
717
+ title: formatAbsolute(run.startedAt),
718
+ children: [
719
+ "Run ",
720
+ /* @__PURE__ */ jsx("span", {
721
+ className: "font-mono",
722
+ children: run.id.slice(0, 8)
723
+ }),
724
+ " ",
725
+ "started ",
726
+ formatWhen(run.startedAt)
727
+ ]
728
+ })] })
729
+ }, waitpoint.id);
730
+ })
731
+ })]
732
+ });
733
+ }
734
+ //#endregion
735
+ //#region editors/workflow-studio/components/RunsTable.tsx
736
+ const STATUS_FILTERS = ["ALL", ...RUN_STATUSES];
737
+ /** The runs table's query params. */
738
+ const RUNS_PARAMS = {
739
+ status: "runs.status",
740
+ query: "runs.q",
741
+ workflow: "runs.workflow",
742
+ trigger: "runs.trigger"
743
+ };
744
+ const DETAIL_POLL_MS = 5e3;
745
+ const CONTROL = "h-8 rounded-md border border-solid border-border bg-card px-2.5 text-[13px] text-foreground placeholder:text-muted-foreground focus:outline-none focus-visible:ring-2 focus-visible:ring-ring";
746
+ function stringify(value) {
747
+ if (value === void 0) return "";
748
+ try {
749
+ return JSON.stringify(value, null, 2);
750
+ } catch {
751
+ return String(value);
752
+ }
753
+ }
754
+ function TimelineBar(props) {
755
+ return /* @__PURE__ */ jsxs("span", {
756
+ className: "ml-auto flex shrink-0 items-center gap-2",
757
+ children: [/* @__PURE__ */ jsx("span", {
758
+ "aria-hidden": true,
759
+ className: "relative hidden h-1.5 w-40 overflow-hidden rounded-full bg-muted sm:block",
760
+ children: props.span ? /* @__PURE__ */ jsx("span", {
761
+ className: `absolute inset-y-0 rounded-full ${TONE_DOT[props.tone]}`,
762
+ style: {
763
+ left: `${props.span.offset * 100}%`,
764
+ width: `max(${props.span.width * 100}%, 4px)`
765
+ }
766
+ }) : null
767
+ }), /* @__PURE__ */ jsx("span", {
768
+ className: "w-14 text-right text-[11px] tabular-nums text-muted-foreground",
769
+ children: props.span ? formatMs(props.span.ms) : "–"
770
+ })]
771
+ });
772
+ }
773
+ function iterationLabel(path) {
774
+ return `#${[...path.matchAll(/\[(\d+)\]/g)].map((match) => match[1]).join(".")}`;
775
+ }
776
+ function cappedIterationsNote(run) {
777
+ if (!run.iterationsTotal) return null;
778
+ return `Showing ${run.iterations?.length ?? 0} of ${run.iterationsTotal} loop iteration steps.`;
779
+ }
780
+ function loopIterations(run, loopId) {
781
+ return (run.iterations ?? []).filter((step) => step.path?.startsWith(`${loopId}[`));
782
+ }
783
+ function StepRow(props) {
784
+ const { step } = props;
785
+ const meta = blockMeta({
786
+ pieceName: step.pieceName,
787
+ kind: "action",
788
+ name: step.blockName
789
+ });
790
+ const [open, setOpen] = useState(false);
791
+ return /* @__PURE__ */ jsxs("div", {
792
+ role: "listitem",
793
+ className: `border-t border-solid border-border ${props.iteration ? "pl-6" : ""}`,
794
+ children: [/* @__PURE__ */ jsxs("button", {
795
+ type: "button",
796
+ "aria-expanded": open,
797
+ className: "flex w-full items-center gap-3 px-3 py-2 text-left text-[13px] hover:bg-accent/60 focus-visible:bg-accent/60 focus-visible:outline-none",
798
+ onClick: () => setOpen((value) => !value),
799
+ children: [
800
+ /* @__PURE__ */ jsx(Icon, {
801
+ name: "chevron",
802
+ className: `h-3.5 w-3.5 text-muted-foreground transition-transform ${open ? "rotate-90" : ""}`
803
+ }),
804
+ /* @__PURE__ */ jsx(StatusText, {
805
+ tone: toneOf(STEP_TONE, step.status),
806
+ status: step.status,
807
+ className: "w-24 shrink-0 text-xs"
808
+ }),
809
+ /* @__PURE__ */ jsxs("span", {
810
+ className: "shrink-0 font-medium text-foreground",
811
+ title: `Key: ${step.stepKey}`,
812
+ children: [props.name ?? step.stepKey, props.iteration ? /* @__PURE__ */ jsx("span", {
813
+ className: "ml-1.5 font-normal text-muted-foreground",
814
+ children: props.iteration
815
+ }) : null]
816
+ }),
817
+ /* @__PURE__ */ jsxs("span", {
818
+ className: "flex min-w-0 items-center gap-1.5 text-xs text-muted-foreground",
819
+ children: [meta.logoUrl ? /* @__PURE__ */ jsx("img", {
820
+ src: meta.logoUrl,
821
+ alt: "",
822
+ title: meta.subtitle,
823
+ className: "h-3.5 w-3.5"
824
+ }) : null, /* @__PURE__ */ jsx("span", {
825
+ className: "truncate",
826
+ children: meta.logoUrl ? meta.displayName : `${meta.subtitle}: ${meta.displayName}`
827
+ })]
828
+ }),
829
+ step.port && step.port !== "next" ? /* @__PURE__ */ jsxs("span", {
830
+ className: "shrink-0 rounded bg-muted px-1.5 text-[11px] text-muted-foreground",
831
+ children: ["took ", step.port]
832
+ }) : null,
833
+ /* @__PURE__ */ jsx(TimelineBar, {
834
+ span: props.span,
835
+ tone: toneOf(STEP_TONE, step.status)
836
+ })
837
+ ]
838
+ }), open ? /* @__PURE__ */ jsxs("div", {
839
+ className: "space-y-2 pb-3 pl-10 pr-3",
840
+ children: [step.error ? /* @__PURE__ */ jsx(StepError, { error: step.error }) : null, step.status === "SKIPPED" ? /* @__PURE__ */ jsx("p", {
841
+ className: "text-xs text-muted-foreground",
842
+ children: "The run never reached this step."
843
+ }) : props.dataError ? /* @__PURE__ */ jsxs("p", {
844
+ className: "text-xs text-wf-warn",
845
+ children: ["Couldn't load what this step received and produced.", /* @__PURE__ */ jsx("span", {
846
+ className: "mt-0.5 block opacity-80",
847
+ children: props.dataError
848
+ })]
849
+ }) : props.dataPending ? /* @__PURE__ */ jsx("p", {
850
+ className: "text-xs text-muted-foreground",
851
+ children: "Loading step data…"
852
+ }) : /* @__PURE__ */ jsxs("div", {
853
+ className: "grid items-start gap-2 md:grid-cols-2",
854
+ children: [/* @__PURE__ */ jsx(DataViewer, {
855
+ label: "Received",
856
+ value: step.input
857
+ }), /* @__PURE__ */ jsx(DataViewer, {
858
+ label: "Produced",
859
+ value: step.output,
860
+ root: `steps.${step.stepKey}.output`,
861
+ emptyText: step.status === "FAILED" ? "Nothing, the step failed" : void 0
862
+ })]
863
+ })]
864
+ }) : null]
865
+ });
866
+ }
867
+ const TRIGGER_LABEL = {
868
+ manual: "Manual",
869
+ schedule: "Schedule",
870
+ webhook: "Webhook",
871
+ "document-event": "Document change",
872
+ piece: "Piece trigger",
873
+ rerun: "Rerun"
874
+ };
875
+ function triggerLabel(kind) {
876
+ if (kind.startsWith("piece:")) {
877
+ const trigger = triggerOfKind(kind);
878
+ return describeTrigger({
879
+ pieceName: trigger.pieceName,
880
+ triggerName: trigger.name,
881
+ config: null
882
+ });
883
+ }
884
+ return TRIGGER_LABEL[kind] ?? formatTrigger(kind);
885
+ }
886
+ function describeRunError(error, names) {
887
+ return error.replace(/^Step "([^"]+)" failed: /, (whole, key) => {
888
+ const name = names.get(key);
889
+ return name ? `${name} failed: ` : whole;
890
+ });
891
+ }
892
+ function TriggerRow(props) {
893
+ const { run } = props;
894
+ const [open, setOpen] = useState(false);
895
+ const payload = stringify(run.triggerPayload);
896
+ const hasPayload = payload !== "" && payload !== "null" && payload !== "{}";
897
+ return /* @__PURE__ */ jsxs("div", {
898
+ role: "listitem",
899
+ children: [/* @__PURE__ */ jsxs("button", {
900
+ type: "button",
901
+ "aria-expanded": hasPayload ? open : void 0,
902
+ disabled: !hasPayload,
903
+ className: "flex w-full items-center gap-3 px-3 py-2 text-left text-[13px] enabled:hover:bg-accent/60 focus-visible:bg-accent/60 focus-visible:outline-none",
904
+ onClick: () => setOpen((value) => !value),
905
+ children: [
906
+ /* @__PURE__ */ jsx(Icon, {
907
+ name: "chevron",
908
+ className: `h-3.5 w-3.5 text-muted-foreground transition-transform ${open ? "rotate-90" : ""} ${hasPayload ? "" : "invisible"}`
909
+ }),
910
+ /* @__PURE__ */ jsx(StatusText, {
911
+ tone: "ok",
912
+ status: "FIRED",
913
+ className: "w-24 shrink-0 text-xs"
914
+ }),
915
+ /* @__PURE__ */ jsx("span", {
916
+ className: "shrink-0 font-medium text-foreground",
917
+ children: "Trigger"
918
+ }),
919
+ /* @__PURE__ */ jsx("span", {
920
+ className: "truncate text-xs text-muted-foreground",
921
+ children: triggerLabel(run.triggerKind)
922
+ }),
923
+ !hasPayload ? /* @__PURE__ */ jsx("span", {
924
+ className: "shrink-0 text-[11px] text-muted-foreground",
925
+ children: "No payload"
926
+ }) : null,
927
+ /* @__PURE__ */ jsxs("span", {
928
+ className: "ml-auto flex shrink-0 items-center gap-2",
929
+ children: [/* @__PURE__ */ jsx("span", {
930
+ "aria-hidden": true,
931
+ className: "relative hidden h-1.5 w-40 sm:block",
932
+ children: /* @__PURE__ */ jsx("span", { className: "absolute inset-y-0 left-0 w-1 rounded-full bg-wf-ok" })
933
+ }), /* @__PURE__ */ jsx("span", {
934
+ className: "w-14 text-right text-[11px] tabular-nums text-muted-foreground",
935
+ children: new Date(run.startedAt).toLocaleTimeString([], {
936
+ hour: "2-digit",
937
+ minute: "2-digit",
938
+ second: "2-digit",
939
+ hour12: false
940
+ })
941
+ })]
942
+ })
943
+ ]
944
+ }), open ? /* @__PURE__ */ jsx("div", {
945
+ className: "pb-3 pl-10 pr-3",
946
+ children: /* @__PURE__ */ jsx(DataViewer, {
947
+ label: "Payload",
948
+ value: run.triggerPayload,
949
+ root: "trigger.payload"
950
+ })
951
+ }) : null]
952
+ });
953
+ }
954
+ function RunDetail(props) {
955
+ const { names } = props;
956
+ const { rerunRun } = useRuntimeActions();
957
+ const full = useRunQuery(props.run.id, { pollMs: DETAIL_POLL_MS });
958
+ const run = full.data ?? props.run;
959
+ const dataPending = full.data === void 0 && full.status === "pending";
960
+ const dataError = full.status === "error" ? full.error instanceof Error ? full.error.message : String(full.error) : null;
961
+ const timeline = runTimeline({
962
+ ...run,
963
+ steps: [...run.steps, ...(run.iterations ?? []).map((step) => ({
964
+ ...step,
965
+ stepId: step.path
966
+ }))]
967
+ });
968
+ const iterated = new Set((run.iterations ?? []).map((step) => step.stepId));
969
+ const [rerunning, setRerunning] = useState(false);
970
+ const [rerunError, setRerunError] = useState(null);
971
+ return /* @__PURE__ */ jsxs("div", {
972
+ className: "space-y-3 bg-muted/40 px-4 py-4",
973
+ children: [
974
+ run.error ? /* @__PURE__ */ jsx("p", {
975
+ className: "rounded-md bg-wf-fail/10 px-3 py-2 text-[13px] text-wf-fail",
976
+ children: describeRunError(run.error, names)
977
+ }) : null,
978
+ run.waitpoints ? /* @__PURE__ */ jsx(RunWaitpoints, {
979
+ waitpoints: run.waitpoints,
980
+ names,
981
+ steps: run.steps,
982
+ onChanged: props.onChanged
983
+ }) : null,
984
+ run.warningNotes.length > 0 ? /* @__PURE__ */ jsx("ul", {
985
+ "aria-label": "Run warnings",
986
+ className: "space-y-1 rounded-md bg-wf-warn/10 px-3 py-2 text-[13px] text-wf-warn",
987
+ children: run.warningNotes.map((note) => /* @__PURE__ */ jsx("li", { children: note }, note))
988
+ }) : null,
989
+ /* @__PURE__ */ jsxs("div", {
990
+ className: "flex flex-wrap items-center gap-x-5 gap-y-1 text-xs text-muted-foreground",
991
+ children: [
992
+ /* @__PURE__ */ jsxs("span", { children: ["Run ", /* @__PURE__ */ jsx("span", {
993
+ className: "font-mono",
994
+ children: run.id.slice(0, 8)
995
+ })] }),
996
+ /* @__PURE__ */ jsxs("span", { children: ["Started ", formatAbsolute(run.startedAt)] }),
997
+ run.rerunOf ? /* @__PURE__ */ jsxs("span", { children: ["Resumes ", /* @__PURE__ */ jsx("span", {
998
+ className: "font-mono",
999
+ children: run.rerunOf.slice(0, 8)
1000
+ })] }) : null,
1001
+ canRerun(run) ? /* @__PURE__ */ jsxs(Button, {
1002
+ className: "ml-auto",
1003
+ disabled: rerunning,
1004
+ onClick: () => {
1005
+ setRerunning(true);
1006
+ setRerunError(null);
1007
+ rerunRun(run.id).then((result) => setRerunError(result.error)).catch((error) => setRerunError(error instanceof Error ? error.message : String(error))).finally(() => {
1008
+ setRerunning(false);
1009
+ props.onChanged();
1010
+ });
1011
+ },
1012
+ children: [/* @__PURE__ */ jsx(Icon, {
1013
+ name: "retry",
1014
+ className: "h-3.5 w-3.5"
1015
+ }), rerunning ? "Rerunning…" : "Rerun from failed step"]
1016
+ }) : null,
1017
+ rerunError ? /* @__PURE__ */ jsx("span", {
1018
+ className: "text-wf-fail",
1019
+ children: rerunError
1020
+ }) : null,
1021
+ run.status === "WAITING" ? /* @__PURE__ */ jsx("span", {
1022
+ className: "ml-auto flex items-center gap-2",
1023
+ children: /* @__PURE__ */ jsx(CancelRunButton, {
1024
+ run,
1025
+ onChanged: props.onChanged
1026
+ })
1027
+ }) : null
1028
+ ]
1029
+ }),
1030
+ /* @__PURE__ */ jsxs("div", {
1031
+ role: "list",
1032
+ "aria-label": "Steps of this run",
1033
+ className: "overflow-hidden rounded-md border border-solid border-border bg-card",
1034
+ children: [
1035
+ /* @__PURE__ */ jsx(TriggerRow, { run }),
1036
+ run.steps.map((step) => /* @__PURE__ */ jsxs(Fragment, { children: [iterated.has(step.stepId) ? null : /* @__PURE__ */ jsx(StepRow, {
1037
+ step,
1038
+ name: names.get(step.stepKey),
1039
+ span: timeline.get(step.stepId),
1040
+ dataPending,
1041
+ dataError
1042
+ }), loopIterations(run, step.stepId).map((iteration) => /* @__PURE__ */ jsx(StepRow, {
1043
+ step: iteration,
1044
+ name: names.get(iteration.stepKey),
1045
+ iteration: iterationLabel(iteration.path),
1046
+ span: timeline.get(iteration.path),
1047
+ dataPending,
1048
+ dataError
1049
+ }, iteration.path))] }, step.stepId + step.stepKey)),
1050
+ run.steps.length === 0 ? /* @__PURE__ */ jsx("p", {
1051
+ className: "border-t border-solid border-border px-3 py-2 pl-10 text-xs text-muted-foreground",
1052
+ children: "No steps ran."
1053
+ }) : null,
1054
+ cappedIterationsNote(run) ? /* @__PURE__ */ jsx("p", {
1055
+ className: "border-t border-solid border-border px-3 py-2 pl-10 text-xs text-muted-foreground",
1056
+ children: cappedIterationsNote(run)
1057
+ }) : null
1058
+ ]
1059
+ })
1060
+ ]
1061
+ });
1062
+ }
1063
+ function SortHeader(props) {
1064
+ return /* @__PURE__ */ jsx("th", {
1065
+ scope: "col",
1066
+ className: props.className,
1067
+ children: /* @__PURE__ */ jsxs("button", {
1068
+ type: "button",
1069
+ className: `flex items-center gap-1 hover:text-foreground ${props.active ? "text-foreground" : ""}`,
1070
+ onClick: props.onClick,
1071
+ children: [props.label, /* @__PURE__ */ jsx("span", {
1072
+ "aria-hidden": true,
1073
+ className: props.active ? "" : "opacity-0",
1074
+ children: props.descending ? "↓" : "↑"
1075
+ })]
1076
+ })
1077
+ });
1078
+ }
1079
+ function RunsTable(props) {
1080
+ const [query, setQuery] = useSearchParamDraft(RUNS_PARAMS.query);
1081
+ const [status, setStatusParam] = useSearchParam(RUNS_PARAMS.status, "ALL", STATUS_FILTERS);
1082
+ const setStatus = (value) => setStatusParam(value, { replace: true });
1083
+ const [workflow, setWorkflowParam] = useSearchParam(RUNS_PARAMS.workflow, "ALL");
1084
+ const setWorkflow = (value) => setWorkflowParam(value, { replace: true });
1085
+ const [trigger, setTriggerParam] = useSearchParam(RUNS_PARAMS.trigger, "ALL");
1086
+ const setTrigger = (value) => setTriggerParam(value, { replace: true });
1087
+ const setParams = useSetSearchParams();
1088
+ const [sort, setSort] = useState("startedAt");
1089
+ const [descending, setDescending] = useState(true);
1090
+ const [expanded, setExpanded] = useState(null);
1091
+ const documents = useWorkflowDocumentsInSelectedDrive() ?? [];
1092
+ const triggerBlocks = new Map(documents.map((document) => {
1093
+ const trigger = document.state.global.trigger;
1094
+ return [document.header.id, trigger ? triggerBlock(trigger) : void 0];
1095
+ }));
1096
+ const stepNames = new Map(documents.map((document) => [document.header.id, new Map(document.state.global.steps.map((step) => [step.key, step.name || step.key]))]));
1097
+ usePieceLogos();
1098
+ const workflowOptions = useMemo(() => [...new Map(props.runs.map((run) => [run.workflowId, run.workflowName]))].map(([id, name]) => ({
1099
+ id,
1100
+ name
1101
+ })).sort((a, b) => a.name.localeCompare(b.name)), [props.runs]);
1102
+ const triggerOptions = useMemo(() => [...new Set(props.runs.map((run) => run.triggerKind))].sort(), [props.runs]);
1103
+ const scoped = useMemo(() => {
1104
+ const needle = query.trim().toLowerCase();
1105
+ return props.runs.filter((run) => {
1106
+ if (workflow !== "ALL" && run.workflowId !== workflow) return false;
1107
+ if (trigger !== "ALL" && run.triggerKind !== trigger) return false;
1108
+ if (!needle) return true;
1109
+ return run.workflowName.toLowerCase().includes(needle) || run.id.toLowerCase().includes(needle) || (run.error?.toLowerCase().includes(needle) ?? false) || run.steps.some((step) => step.stepKey.toLowerCase().includes(needle));
1110
+ });
1111
+ }, [
1112
+ props.runs,
1113
+ query,
1114
+ workflow,
1115
+ trigger
1116
+ ]);
1117
+ const counts = useMemo(() => ({
1118
+ ALL: scoped.length,
1119
+ RUNNING: scoped.filter((run) => run.status === "RUNNING").length,
1120
+ WAITING: scoped.filter((run) => run.status === "WAITING").length,
1121
+ SUCCEEDED: scoped.filter((run) => run.status === "SUCCEEDED").length,
1122
+ FAILED: scoped.filter((run) => run.status === "FAILED").length
1123
+ }), [scoped]);
1124
+ const visible = useMemo(() => {
1125
+ const rows = scoped.filter((run) => status === "ALL" || run.status === status);
1126
+ const direction = descending ? -1 : 1;
1127
+ return [...rows].sort((a, b) => {
1128
+ if (sort === "duration") return ((durationMs(a.startedAt, a.endedAt) ?? Infinity) - (durationMs(b.startedAt, b.endedAt) ?? Infinity)) * direction;
1129
+ return (new Date(a.startedAt).getTime() - new Date(b.startedAt).getTime()) * direction;
1130
+ });
1131
+ }, [
1132
+ scoped,
1133
+ status,
1134
+ sort,
1135
+ descending
1136
+ ]);
1137
+ const filtered = query.trim() || workflow !== "ALL" || trigger !== "ALL";
1138
+ const sortBy = (key) => {
1139
+ if (key === sort) {
1140
+ setDescending((value) => !value);
1141
+ return;
1142
+ }
1143
+ setSort(key);
1144
+ setDescending(true);
1145
+ };
1146
+ return /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsxs("div", {
1147
+ className: "mb-3 flex flex-wrap items-center gap-2",
1148
+ children: [
1149
+ /* @__PURE__ */ jsx("div", {
1150
+ className: "flex h-8 items-center gap-0.5 rounded-md bg-muted p-0.5",
1151
+ children: STATUS_FILTERS.map((option) => /* @__PURE__ */ jsxs("button", {
1152
+ type: "button",
1153
+ "aria-pressed": status === option,
1154
+ className: `h-7 rounded px-2.5 text-[13px] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring ${status === option ? "bg-card font-medium text-foreground shadow-sm" : "text-muted-foreground hover:text-foreground"}`,
1155
+ onClick: () => setStatus(option),
1156
+ children: [option === "ALL" ? "All" : statusLabel(option), /* @__PURE__ */ jsx("span", {
1157
+ className: "ml-1.5 tabular-nums text-muted-foreground",
1158
+ children: counts[option]
1159
+ })]
1160
+ }, option))
1161
+ }),
1162
+ /* @__PURE__ */ jsx("input", {
1163
+ type: "search",
1164
+ className: `${CONTROL} w-48`,
1165
+ placeholder: "Search runs",
1166
+ value: query,
1167
+ onChange: (event) => setQuery(event.target.value)
1168
+ }),
1169
+ props.showWorkflow && workflowOptions.length > 1 ? /* @__PURE__ */ jsx("div", {
1170
+ className: "w-44",
1171
+ children: /* @__PURE__ */ jsx(Select, {
1172
+ value: workflow,
1173
+ options: [{
1174
+ value: "ALL",
1175
+ label: "Every workflow"
1176
+ }, ...workflowOptions.map((option) => ({
1177
+ value: option.id,
1178
+ label: option.name
1179
+ }))],
1180
+ onChange: setWorkflow
1181
+ })
1182
+ }) : null,
1183
+ triggerOptions.length > 1 ? /* @__PURE__ */ jsx("div", {
1184
+ className: "w-40",
1185
+ children: /* @__PURE__ */ jsx(Select, {
1186
+ value: trigger,
1187
+ options: [{
1188
+ value: "ALL",
1189
+ label: "Every trigger"
1190
+ }, ...triggerOptions.map((option) => ({
1191
+ value: option,
1192
+ label: triggerLabel(option)
1193
+ }))],
1194
+ onChange: setTrigger
1195
+ })
1196
+ }) : null,
1197
+ filtered ? /* @__PURE__ */ jsx("button", {
1198
+ type: "button",
1199
+ className: "text-[13px] text-muted-foreground underline underline-offset-2 hover:text-foreground",
1200
+ onClick: () => {
1201
+ setParams({
1202
+ [RUNS_PARAMS.query]: void 0,
1203
+ [RUNS_PARAMS.workflow]: void 0,
1204
+ [RUNS_PARAMS.trigger]: void 0
1205
+ }, { replace: true });
1206
+ },
1207
+ children: "Clear filters"
1208
+ }) : null,
1209
+ /* @__PURE__ */ jsxs("span", {
1210
+ className: "ml-auto text-xs tabular-nums text-muted-foreground",
1211
+ children: [
1212
+ visible.length,
1213
+ " of ",
1214
+ props.runs.length,
1215
+ " runs"
1216
+ ]
1217
+ })
1218
+ ]
1219
+ }), /* @__PURE__ */ jsx("div", {
1220
+ className: "overflow-x-auto rounded-lg border border-solid border-border bg-card",
1221
+ children: /* @__PURE__ */ jsxs("table", {
1222
+ className: "w-full border-collapse text-left",
1223
+ children: [/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", {
1224
+ className: "border-b border-solid border-border text-xs font-medium text-muted-foreground",
1225
+ children: [
1226
+ /* @__PURE__ */ jsx("th", {
1227
+ scope: "col",
1228
+ className: "px-3 py-2.5 font-medium",
1229
+ children: "Status"
1230
+ }),
1231
+ props.showWorkflow ? /* @__PURE__ */ jsx("th", {
1232
+ scope: "col",
1233
+ className: "px-3 py-2.5 font-medium",
1234
+ children: "Workflow"
1235
+ }) : null,
1236
+ /* @__PURE__ */ jsx("th", {
1237
+ scope: "col",
1238
+ className: "px-3 py-2.5 font-medium",
1239
+ children: "Trigger"
1240
+ }),
1241
+ /* @__PURE__ */ jsx(SortHeader, {
1242
+ label: "Started",
1243
+ className: "px-3 py-2.5 font-medium",
1244
+ active: sort === "startedAt",
1245
+ descending,
1246
+ onClick: () => sortBy("startedAt")
1247
+ }),
1248
+ /* @__PURE__ */ jsx(SortHeader, {
1249
+ label: "Duration",
1250
+ className: "px-3 py-2.5 font-medium",
1251
+ active: sort === "duration",
1252
+ descending,
1253
+ onClick: () => sortBy("duration")
1254
+ }),
1255
+ /* @__PURE__ */ jsx("th", {
1256
+ scope: "col",
1257
+ className: "px-3 py-2.5 font-medium",
1258
+ children: "Steps"
1259
+ }),
1260
+ /* @__PURE__ */ jsx("th", {
1261
+ scope: "col",
1262
+ className: "w-8 px-3 py-2",
1263
+ children: /* @__PURE__ */ jsx("span", {
1264
+ className: "sr-only",
1265
+ children: "Details"
1266
+ })
1267
+ })
1268
+ ]
1269
+ }) }), /* @__PURE__ */ jsx("tbody", { children: visible.length === 0 ? /* @__PURE__ */ jsx("tr", { children: /* @__PURE__ */ jsx("td", {
1270
+ colSpan: props.showWorkflow ? 7 : 6,
1271
+ className: "px-3 py-8 text-center text-[13px] text-muted-foreground",
1272
+ children: "No runs match these filters."
1273
+ }) }) : visible.map((run) => {
1274
+ const open = expanded === run.id;
1275
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("tr", {
1276
+ className: `cursor-pointer border-b border-solid border-border text-[13px] last:border-b-0 ${open ? "bg-muted/40" : "hover:bg-accent/60"}`,
1277
+ onClick: () => setExpanded(open ? null : run.id),
1278
+ children: [
1279
+ /* @__PURE__ */ jsx("td", {
1280
+ className: "px-3 py-2.5",
1281
+ children: /* @__PURE__ */ jsx(StatusText, {
1282
+ tone: runTone(run),
1283
+ status: run.status,
1284
+ label: runStatusLabel(run)
1285
+ })
1286
+ }),
1287
+ props.showWorkflow ? /* @__PURE__ */ jsx("td", {
1288
+ className: "max-w-48 truncate px-3 py-2.5 font-medium text-foreground",
1289
+ children: run.workflowName
1290
+ }) : null,
1291
+ /* @__PURE__ */ jsxs("td", {
1292
+ className: "px-3 py-2.5 text-muted-foreground",
1293
+ children: [triggerLabel(run.triggerKind), /* @__PURE__ */ jsxs("span", {
1294
+ className: "ml-1.5 text-xs text-muted-foreground/70",
1295
+ children: ["v", run.workflowVersion]
1296
+ })]
1297
+ }),
1298
+ /* @__PURE__ */ jsx("td", {
1299
+ className: "whitespace-nowrap px-3 py-2.5 tabular-nums text-muted-foreground",
1300
+ title: formatAbsolute(run.startedAt),
1301
+ children: formatWhen(run.startedAt)
1302
+ }),
1303
+ /* @__PURE__ */ jsx("td", {
1304
+ className: "whitespace-nowrap px-3 py-2.5 tabular-nums text-muted-foreground",
1305
+ children: formatDuration(run.startedAt, run.endedAt)
1306
+ }),
1307
+ /* @__PURE__ */ jsx("td", {
1308
+ className: "px-3 py-2",
1309
+ children: /* @__PURE__ */ jsx(MiniChain, { links: runLinks(run, triggerBlocks.get(run.workflowId)) })
1310
+ }),
1311
+ /* @__PURE__ */ jsx("td", {
1312
+ className: "px-3 py-2.5",
1313
+ children: /* @__PURE__ */ jsx("button", {
1314
+ type: "button",
1315
+ "aria-expanded": open,
1316
+ "aria-label": `${open ? "Hide" : "Show"} steps of the run started ${formatAbsolute(run.startedAt)}`,
1317
+ className: "flex h-6 w-6 items-center justify-center rounded text-muted-foreground hover:bg-accent hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
1318
+ onClick: (event) => {
1319
+ event.stopPropagation();
1320
+ setExpanded(open ? null : run.id);
1321
+ },
1322
+ children: /* @__PURE__ */ jsx(Icon, {
1323
+ name: "chevron",
1324
+ className: `h-3.5 w-3.5 transition-transform ${open ? "rotate-90" : ""}`
1325
+ })
1326
+ })
1327
+ })
1328
+ ]
1329
+ }), open ? /* @__PURE__ */ jsx("tr", { children: /* @__PURE__ */ jsx("td", {
1330
+ colSpan: props.showWorkflow ? 7 : 6,
1331
+ className: "border-b border-solid border-border p-0",
1332
+ children: /* @__PURE__ */ jsx(RunDetail, {
1333
+ run,
1334
+ names: stepNames.get(run.workflowId) ?? /* @__PURE__ */ new Map(),
1335
+ onChanged: props.onChanged
1336
+ })
1337
+ }) }) : null] }, run.id);
1338
+ }) })]
1339
+ })
1340
+ })] });
1341
+ }
1342
+ //#endregion
1343
+ //#region editors/workflow-studio/components/RunsView.tsx
1344
+ function RunsView(props) {
1345
+ const [firing, setFiring] = useState(false);
1346
+ const [fireError, setFireError] = useState(null);
1347
+ const [asking, setAsking] = useState(false);
1348
+ const { runs } = props;
1349
+ const inputs = props.fireInputs ?? [];
1350
+ return /* @__PURE__ */ jsxs("div", {
1351
+ className: "w-full",
1352
+ children: [
1353
+ /* @__PURE__ */ jsxs("div", {
1354
+ className: "mb-4 flex items-center gap-3",
1355
+ children: [
1356
+ /* @__PURE__ */ jsx("h2", {
1357
+ className: "text-[15px] font-semibold text-foreground",
1358
+ children: props.title
1359
+ }),
1360
+ /* @__PURE__ */ jsx("span", { className: "grow" }),
1361
+ props.onFire ? /* @__PURE__ */ jsxs(Button, {
1362
+ variant: "primary",
1363
+ disabled: firing,
1364
+ onClick: () => {
1365
+ if (inputs.length > 0) {
1366
+ setFireError(null);
1367
+ setAsking(true);
1368
+ return;
1369
+ }
1370
+ setFiring(true);
1371
+ setFireError(null);
1372
+ props.onFire().then((fireResultError) => setFireError(fireResultError)).catch((fireCallError) => setFireError(fireCallError instanceof Error ? fireCallError.message : String(fireCallError))).finally(() => {
1373
+ setFiring(false);
1374
+ props.reload();
1375
+ });
1376
+ },
1377
+ children: [/* @__PURE__ */ jsx(Icon, {
1378
+ name: "play",
1379
+ className: "h-3.5 w-3.5"
1380
+ }), firing ? "Running…" : "Run now"]
1381
+ }) : null
1382
+ ]
1383
+ }),
1384
+ asking && props.onFire && inputs.length > 0 ? /* @__PURE__ */ jsx(RunDialog, {
1385
+ inputs,
1386
+ onCancel: () => setAsking(false),
1387
+ onFire: (payload) => props.onFire(payload).finally(() => props.reload())
1388
+ }) : null,
1389
+ fireError ? /* @__PURE__ */ jsx("p", {
1390
+ className: "mb-3 rounded-md bg-wf-fail/10 px-3 py-2 text-[13px] text-wf-fail",
1391
+ children: fireError
1392
+ }) : null,
1393
+ props.error ? /* @__PURE__ */ jsxs("p", {
1394
+ className: "rounded-md bg-wf-warn/10 px-3 py-2 text-[13px] text-wf-warn",
1395
+ children: ["Runs can't be listed because the workflow runtime is unreachable.", /* @__PURE__ */ jsx("span", {
1396
+ className: "mt-0.5 block text-xs opacity-80",
1397
+ children: props.error
1398
+ })]
1399
+ }) : runs === null ? /* @__PURE__ */ jsx("p", {
1400
+ className: "text-[13px] text-muted-foreground",
1401
+ children: "Loading runs…"
1402
+ }) : runs.length === 0 ? /* @__PURE__ */ jsxs("div", {
1403
+ className: "rounded-lg border border-dashed border-border px-4 py-10 text-center",
1404
+ children: [/* @__PURE__ */ jsx("p", {
1405
+ className: "text-[13px] font-medium text-foreground",
1406
+ children: "No runs yet"
1407
+ }), /* @__PURE__ */ jsx("p", {
1408
+ className: "mt-1 text-xs text-muted-foreground",
1409
+ children: props.onFire ? "Use Run now to record the first one." : "Runs appear here once the trigger fires."
1410
+ })]
1411
+ }) : /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(RunsTable, {
1412
+ runs,
1413
+ showWorkflow: props.showWorkflow,
1414
+ onChanged: props.reload
1415
+ }), props.hasMore && props.onLoadMore ? /* @__PURE__ */ jsx("div", {
1416
+ className: "mt-3 flex justify-center",
1417
+ children: /* @__PURE__ */ jsx(Button, {
1418
+ disabled: props.loadingMore,
1419
+ onClick: () => props.onLoadMore(),
1420
+ children: props.loadingMore ? "Loading…" : "Load older runs"
1421
+ })
1422
+ }) : null] })
1423
+ ]
1424
+ });
1425
+ }
1426
+ //#endregion
1427
+ //#region editors/workflow-studio/components/workflow-order.ts
1428
+ const DIGITS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
1429
+ const HOME_FOLDER = /^([0-9A-Za-z]+) · (.*)$/s;
1430
+ function compareKeys(a, b) {
1431
+ return a < b ? -1 : a > b ? 1 : 0;
1432
+ }
1433
+ function midpoint(a, b) {
1434
+ if (b !== null) {
1435
+ let n = 0;
1436
+ while ((a[n] ?? "0") === b[n]) n++;
1437
+ if (n > 0) return b.slice(0, n) + midpoint(a.slice(n), b.slice(n));
1438
+ }
1439
+ const digitA = a ? DIGITS.indexOf(a[0]) : 0;
1440
+ const digitB = b !== null ? DIGITS.indexOf(b[0]) : 62;
1441
+ if (digitB - digitA > 1) return DIGITS[Math.round((digitA + digitB) / 2)];
1442
+ if (b !== null && b.length > 1) return b.slice(0, 1);
1443
+ return DIGITS[digitA] + midpoint(a.slice(1), null);
1444
+ }
1445
+ /** A key that sorts after `before` and before `after`. */
1446
+ function keyBetween(before, after) {
1447
+ return midpoint(before ?? "", after ?? null);
1448
+ }
1449
+ /** `count` ascending keys, evenly spread. */
1450
+ function spreadKeys(count) {
1451
+ let width = 1;
1452
+ while (62 ** width <= count) width++;
1453
+ const span = 62 ** width;
1454
+ return Array.from({ length: count }, (_, i) => {
1455
+ let value = Math.floor((i + 1) * span / (count + 1));
1456
+ let key = "";
1457
+ for (let d = 0; d < width; d++) {
1458
+ key = DIGITS[value % 62] + key;
1459
+ value = Math.floor(value / 62);
1460
+ }
1461
+ return key.replace(/0+$/, "");
1462
+ });
1463
+ }
1464
+ function homeFolderName(key, name) {
1465
+ return `${key} · ${name || "Workflow"}`;
1466
+ }
1467
+ function orderWorkflows(workflows, nodes) {
1468
+ const byId = new Map(nodes.map((node) => [node.id, node]));
1469
+ const childCount = /* @__PURE__ */ new Map();
1470
+ for (const node of nodes) if (node.parentFolder) childCount.set(node.parentFolder, (childCount.get(node.parentFolder) ?? 0) + 1);
1471
+ return workflows.map((node) => {
1472
+ const parent = node.parentFolder ? byId.get(node.parentFolder) : void 0;
1473
+ if (parent?.kind !== "folder" || parent.parentFolder || childCount.get(parent.id) !== 1) return { node };
1474
+ const match = HOME_FOLDER.exec(parent.name);
1475
+ return match ? {
1476
+ node,
1477
+ folder: parent,
1478
+ key: match[1]
1479
+ } : { node };
1480
+ }).sort((a, b) => {
1481
+ if (a.key === void 0 || b.key === void 0) {
1482
+ if (a.key !== b.key) return a.key === void 0 ? -1 : 1;
1483
+ } else {
1484
+ const byKey = compareKeys(a.key, b.key);
1485
+ if (byKey !== 0) return byKey;
1486
+ }
1487
+ return compareKeys(a.node.id, b.node.id);
1488
+ });
1489
+ }
1490
+ /** The key for a new workflow, after every other one. */
1491
+ function nextKey(ordered) {
1492
+ return keyBetween(ordered.at(-1)?.key, null);
1493
+ }
1494
+ /** The node to delete to remove a workflow: its home folder, if it has one. */
1495
+ function deletionTarget(workflowId, nodes) {
1496
+ const node = nodes.find((n) => n.id === workflowId);
1497
+ if (node?.kind !== "file") return node;
1498
+ return orderWorkflows([node], nodes)[0].folder ?? node;
1499
+ }
1500
+ function folderTail(item, names) {
1501
+ const name = names.get(item.node.id) || item.node.name;
1502
+ return item.folder ? HOME_FOLDER.exec(item.folder.name)?.[2] ?? name : name;
1503
+ }
1504
+ function reorderActions(ordered, from, to, names = /* @__PURE__ */ new Map()) {
1505
+ if (from === to || !ordered[from]) return [];
1506
+ const next = [...ordered];
1507
+ const [moved] = next.splice(from, 1);
1508
+ next.splice(to, 0, moved);
1509
+ const before = to > 0 ? next[to - 1] : void 0;
1510
+ const after = to < next.length - 1 ? next[to + 1] : void 0;
1511
+ if (moved.folder && (!before || before.key !== void 0) && (!after || after.key !== void 0) && (!before || !after || compareKeys(before.key, after.key) < 0)) {
1512
+ const key = keyBetween(before?.key, after?.key);
1513
+ return [updateNode({
1514
+ id: moved.folder.id,
1515
+ name: homeFolderName(key, folderTail(moved, names))
1516
+ })];
1517
+ }
1518
+ const keys = spreadKeys(next.length);
1519
+ return next.flatMap((item, i) => {
1520
+ const name = homeFolderName(keys[i], folderTail(item, names));
1521
+ if (item.folder) return item.folder.name === name ? [] : [updateNode({
1522
+ id: item.folder.id,
1523
+ name
1524
+ })];
1525
+ const folderId = generateId();
1526
+ return [addFolder$1({
1527
+ id: folderId,
1528
+ name,
1529
+ parentFolder: null
1530
+ }), moveNode({
1531
+ srcFolder: item.node.id,
1532
+ targetParentFolder: folderId
1533
+ })];
1534
+ });
1535
+ }
1536
+ //#endregion
1537
+ //#region editors/workflow-studio/components/WorkflowMenu.tsx
1538
+ /** Deletes a workflow with its home folder, reading the drive's nodes now. */
1539
+ async function deleteWorkflow(workflowId) {
1540
+ const store = getPHStore();
1541
+ const driveId = store?.selectedDriveId;
1542
+ if (!driveId) throw new Error("No drive is selected");
1543
+ const nodes = store?.drives?.find((drive) => drive.header.id === driveId)?.state.global.nodes ?? [];
1544
+ await deleteNode(driveId, deletionTarget(workflowId, nodes)?.id ?? workflowId);
1545
+ }
1546
+ function DeleteWorkflowDialog(props) {
1547
+ const [typed, setTyped] = useState("");
1548
+ const [error, setError] = useState(null);
1549
+ const [deleting, setDeleting] = useState(false);
1550
+ const inputId = useId();
1551
+ const cancelRef = useRef(null);
1552
+ const matches = typed === props.name;
1553
+ return /* @__PURE__ */ jsx(Modal, {
1554
+ open: true,
1555
+ title: "Delete workflow",
1556
+ onOpenChange: (open) => {
1557
+ if (!open) props.onCancel();
1558
+ },
1559
+ contentProps: {
1560
+ className: "w-[28rem] max-w-[92vw] rounded-xl border border-solid border-foreground/10",
1561
+ role: "alertdialog",
1562
+ "aria-label": "Delete workflow",
1563
+ onOpenAutoFocus: (event) => {
1564
+ event.preventDefault();
1565
+ cancelRef.current?.focus();
1566
+ }
1567
+ },
1568
+ children: /* @__PURE__ */ jsxs("form", {
1569
+ className: "flex flex-col gap-4 p-6",
1570
+ onSubmit: (event) => {
1571
+ event.preventDefault();
1572
+ if (!matches || deleting) return;
1573
+ setDeleting(true);
1574
+ props.onConfirm().catch((cause) => {
1575
+ setDeleting(false);
1576
+ setError(cause instanceof Error ? cause.message : String(cause));
1577
+ });
1578
+ },
1579
+ children: [
1580
+ /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("h2", {
1581
+ className: "text-[15px] font-semibold text-foreground",
1582
+ children: "Delete workflow"
1583
+ }), /* @__PURE__ */ jsx("p", {
1584
+ className: "mt-1 text-[13px] text-muted-foreground",
1585
+ children: "This removes the workflow from the drive and can't be undone. To archive it instead, use Archive."
1586
+ })] }),
1587
+ /* @__PURE__ */ jsxs("label", {
1588
+ htmlFor: inputId,
1589
+ className: "flex flex-col gap-1.5",
1590
+ children: [/* @__PURE__ */ jsxs("span", {
1591
+ className: "text-[13px] text-foreground",
1592
+ children: [
1593
+ "Type ",
1594
+ /* @__PURE__ */ jsx("strong", {
1595
+ className: "font-semibold",
1596
+ children: props.name
1597
+ }),
1598
+ " to confirm"
1599
+ ]
1600
+ }), /* @__PURE__ */ jsx("input", {
1601
+ id: inputId,
1602
+ className: textInputClass,
1603
+ value: typed,
1604
+ spellCheck: false,
1605
+ autoComplete: "off",
1606
+ onChange: (event) => setTyped(event.target.value)
1607
+ })]
1608
+ }),
1609
+ error ? /* @__PURE__ */ jsx("p", {
1610
+ className: "text-xs text-wf-fail",
1611
+ children: error
1612
+ }) : null,
1613
+ /* @__PURE__ */ jsxs("div", {
1614
+ className: "flex justify-end gap-2",
1615
+ children: [/* @__PURE__ */ jsx(Button, {
1616
+ ref: cancelRef,
1617
+ onClick: props.onCancel,
1618
+ children: "Cancel"
1619
+ }), /* @__PURE__ */ jsx(Button, {
1620
+ type: "submit",
1621
+ variant: "destructive",
1622
+ disabled: !matches || deleting,
1623
+ children: deleting ? "Deleting…" : "Delete workflow"
1624
+ })]
1625
+ })
1626
+ ]
1627
+ })
1628
+ });
1629
+ }
1630
+ function MenuItem(props) {
1631
+ return /* @__PURE__ */ jsxs("button", {
1632
+ type: "button",
1633
+ role: "menuitem",
1634
+ className: `flex w-full items-center gap-2 rounded px-2 py-1.5 text-left text-[13px] hover:bg-accent focus-visible:bg-accent focus-visible:outline-none ${props.danger ? "text-wf-fail" : "text-foreground"}`,
1635
+ onClick: props.onSelect,
1636
+ children: [/* @__PURE__ */ jsx(Icon, {
1637
+ name: props.icon,
1638
+ className: "h-3.5 w-3.5"
1639
+ }), props.label]
1640
+ });
1641
+ }
1642
+ function WorkflowMenu(props) {
1643
+ const [open, setOpen] = useState(false);
1644
+ const [confirming, setConfirming] = useState(false);
1645
+ const [, dispatch] = useDispatch(props.document);
1646
+ const ref = useRef(null);
1647
+ const state = props.document.state.global;
1648
+ const name = state.name || props.nodeName || "Untitled workflow";
1649
+ const archived = state.status === "ARCHIVED";
1650
+ useEffect(() => {
1651
+ if (!open) return;
1652
+ const close = (event) => {
1653
+ if (!ref.current?.contains(event.target)) setOpen(false);
1654
+ };
1655
+ const escape = (event) => {
1656
+ if (event.key === "Escape") setOpen(false);
1657
+ };
1658
+ window.addEventListener("mousedown", close);
1659
+ window.addEventListener("keydown", escape);
1660
+ return () => {
1661
+ window.removeEventListener("mousedown", close);
1662
+ window.removeEventListener("keydown", escape);
1663
+ };
1664
+ }, [open]);
1665
+ return /* @__PURE__ */ jsxs("div", {
1666
+ ref,
1667
+ className: "relative",
1668
+ children: [
1669
+ /* @__PURE__ */ jsx("button", {
1670
+ type: "button",
1671
+ "aria-label": `More actions for ${name}`,
1672
+ "aria-haspopup": "menu",
1673
+ "aria-expanded": open,
1674
+ className: `flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:bg-accent hover:text-foreground focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring ${props.subtle && !open ? "opacity-0 group-hover:opacity-100" : ""}`,
1675
+ onClick: (event) => {
1676
+ event.stopPropagation();
1677
+ setOpen((value) => !value);
1678
+ },
1679
+ children: /* @__PURE__ */ jsx(Icon, {
1680
+ name: "more",
1681
+ className: "h-4 w-4"
1682
+ })
1683
+ }),
1684
+ open ? /* @__PURE__ */ jsxs("div", {
1685
+ role: "menu",
1686
+ className: "absolute right-0 top-full z-50 mt-1 w-44 rounded-md border border-solid border-foreground/10 bg-card p-1 shadow-lg",
1687
+ children: [/* @__PURE__ */ jsx(MenuItem, {
1688
+ label: archived ? "Restore" : "Archive",
1689
+ icon: archived ? "retry" : "archive",
1690
+ onSelect: () => {
1691
+ setOpen(false);
1692
+ const status = archived ? state.published ? "DISABLED" : "DRAFT" : "ARCHIVED";
1693
+ dispatch(actions.setWorkflowStatus({ status }));
1694
+ }
1695
+ }), /* @__PURE__ */ jsx(MenuItem, {
1696
+ label: "Delete…",
1697
+ icon: "trash",
1698
+ danger: true,
1699
+ onSelect: () => {
1700
+ setOpen(false);
1701
+ setConfirming(true);
1702
+ }
1703
+ })]
1704
+ }) : null,
1705
+ confirming ? /* @__PURE__ */ jsx(DeleteWorkflowDialog, {
1706
+ name,
1707
+ onCancel: () => setConfirming(false),
1708
+ onConfirm: async () => {
1709
+ await deleteWorkflow(props.document.header.id);
1710
+ setConfirming(false);
1711
+ props.onDeleted?.();
1712
+ }
1713
+ }) : null
1714
+ ]
1715
+ });
1716
+ }
1717
+ //#endregion
1718
+ //#region editors/workflow-studio/components/Sidebar.tsx
1719
+ const WORKFLOW_TYPE$2 = "powerhouse/workflow";
1720
+ function documentName(document, fallback) {
1721
+ return (document?.state?.global)?.name || fallback || "(unnamed)";
1722
+ }
1723
+ function documentStatus(document) {
1724
+ const state = document?.state?.global;
1725
+ return {
1726
+ status: state?.status,
1727
+ published: Boolean(state?.published)
1728
+ };
1729
+ }
1730
+ function Row(props) {
1731
+ return /* @__PURE__ */ jsxs("div", {
1732
+ className: `group mx-2 flex items-center rounded-md ${props.active ? "bg-accent" : "hover:bg-accent/60"}`,
1733
+ children: [/* @__PURE__ */ jsx("button", {
1734
+ type: "button",
1735
+ "aria-current": props.active ? "true" : void 0,
1736
+ className: `flex min-w-0 grow items-center gap-2.5 rounded-md px-2 py-1.5 text-left text-[13px] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring ${props.active ? "font-medium text-foreground" : "text-foreground/80"}`,
1737
+ onClick: props.onClick,
1738
+ onKeyDown: props.onKeyDown,
1739
+ "aria-keyshortcuts": props.keyShortcuts,
1740
+ children: props.children
1741
+ }), props.trailing]
1742
+ });
1743
+ }
1744
+ const ROW_ACTION = "flex h-6 w-6 shrink-0 items-center justify-center rounded text-muted-foreground opacity-0 hover:bg-background hover:text-foreground focus-visible:opacity-100 group-hover:opacity-100";
1745
+ const DELETE_ACTION = `${ROW_ACTION} hover:text-wf-fail`;
1746
+ function DeleteButton(props) {
1747
+ const [confirming, setConfirming] = useState(false);
1748
+ const isWorkflow = props.node.documentType === WORKFLOW_TYPE$2;
1749
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("button", {
1750
+ type: "button",
1751
+ title: "Delete",
1752
+ "aria-label": `Delete ${props.label}`,
1753
+ className: DELETE_ACTION,
1754
+ onClick: () => isWorkflow ? setConfirming(true) : showDeleteNodeModal(props.node),
1755
+ children: /* @__PURE__ */ jsx(Icon, {
1756
+ name: "trash",
1757
+ className: "h-3.5 w-3.5"
1758
+ })
1759
+ }), confirming ? /* @__PURE__ */ jsx(DeleteWorkflowDialog, {
1760
+ name: props.label,
1761
+ onCancel: () => setConfirming(false),
1762
+ onConfirm: async () => {
1763
+ await deleteWorkflow(props.node.id);
1764
+ setConfirming(false);
1765
+ }
1766
+ }) : null] });
1767
+ }
1768
+ function NodeRow(props) {
1769
+ const { node } = props;
1770
+ const { data: document, error } = useDocumentSafe(node.id);
1771
+ useEffect(() => {
1772
+ if (error !== void 0) console.error(`Failed to load document ${node.id}:`, error);
1773
+ }, [error, node.id]);
1774
+ if (error !== void 0) return /* @__PURE__ */ jsxs(Row, {
1775
+ active: props.active,
1776
+ onClick: props.onOpen,
1777
+ onKeyDown: props.onKeyDown,
1778
+ keyShortcuts: props.keyShortcuts,
1779
+ trailing: /* @__PURE__ */ jsx("span", {
1780
+ className: "mr-1.5 flex shrink-0 items-center",
1781
+ children: /* @__PURE__ */ jsx(DeleteButton, {
1782
+ node,
1783
+ label: node.name || node.id
1784
+ })
1785
+ }),
1786
+ children: [/* @__PURE__ */ jsx("span", {
1787
+ className: "shrink-0 text-xs text-wf-fail",
1788
+ title: `Could not load ${node.id}: ${errorMessage(error)}`,
1789
+ "aria-hidden": true,
1790
+ children: "⚠"
1791
+ }), /* @__PURE__ */ jsx("span", {
1792
+ className: "min-w-0 truncate text-wf-fail",
1793
+ children: node.name || "(unnamed)"
1794
+ })]
1795
+ });
1796
+ const { status, published } = documentStatus(document);
1797
+ const isWorkflow = node.documentType === WORKFLOW_TYPE$2;
1798
+ const { tone, label, hollow } = isWorkflow ? workflowHealth(status, props.lastRunStatus, published) : {
1799
+ tone: toneOf(CONNECTION_TONE, status),
1800
+ label: status,
1801
+ hollow: void 0
1802
+ };
1803
+ return /* @__PURE__ */ jsxs(Row, {
1804
+ active: props.active,
1805
+ onClick: props.onOpen,
1806
+ onKeyDown: props.onKeyDown,
1807
+ keyShortcuts: props.keyShortcuts,
1808
+ trailing: /* @__PURE__ */ jsxs("span", {
1809
+ className: "mr-1.5 flex shrink-0 items-center",
1810
+ children: [
1811
+ /* @__PURE__ */ jsx(ApprovalBadge, {
1812
+ count: props.approvals ?? 0,
1813
+ capped: props.approvalsCapped ?? false,
1814
+ onClick: props.onShowApprovals,
1815
+ className: "mr-0.5"
1816
+ }),
1817
+ props.onEdit ? /* @__PURE__ */ jsx("button", {
1818
+ type: "button",
1819
+ title: "Open in editor",
1820
+ "aria-label": `Open ${documentName(document, node.name)} in the editor`,
1821
+ className: ROW_ACTION,
1822
+ onClick: props.onEdit,
1823
+ children: /* @__PURE__ */ jsx(Icon, {
1824
+ name: "pencil",
1825
+ className: "h-3.5 w-3.5"
1826
+ })
1827
+ }) : null,
1828
+ isWorkflow && document ? /* @__PURE__ */ jsx(WorkflowMenu, {
1829
+ subtle: true,
1830
+ document,
1831
+ nodeName: node.name
1832
+ }) : /* @__PURE__ */ jsx(DeleteButton, {
1833
+ node,
1834
+ label: documentName(document, node.name)
1835
+ })
1836
+ ]
1837
+ }),
1838
+ children: [/* @__PURE__ */ jsx("span", {
1839
+ title: label,
1840
+ className: "flex",
1841
+ children: /* @__PURE__ */ jsx(StatusDot, {
1842
+ tone,
1843
+ hollow
1844
+ })
1845
+ }), /* @__PURE__ */ jsx("span", {
1846
+ className: "min-w-0 truncate",
1847
+ children: documentName(document, node.name)
1848
+ })]
1849
+ });
1850
+ }
1851
+ function DropLine(props) {
1852
+ return /* @__PURE__ */ jsx("span", {
1853
+ "aria-hidden": true,
1854
+ className: `pointer-events-none absolute inset-x-3 z-10 h-0.5 rounded-full bg-primary ${props.edge === "top" ? "-top-px" : "-bottom-px"}`
1855
+ });
1856
+ }
1857
+ function Section(props) {
1858
+ const { onReorder } = props;
1859
+ const headingId = useId();
1860
+ const [drag, setDrag] = useState(null);
1861
+ const count = props.nodes.length;
1862
+ const drop = (from, at) => {
1863
+ const to = at > from ? at - 1 : at;
1864
+ if (to !== from) onReorder?.(from, to);
1865
+ };
1866
+ const showLine = (at) => drag !== null && drag.at === at && at !== drag.from && at !== drag.from + 1;
1867
+ return /* @__PURE__ */ jsxs("div", {
1868
+ className: "mt-5",
1869
+ role: "group",
1870
+ "aria-labelledby": headingId,
1871
+ children: [/* @__PURE__ */ jsxs("div", {
1872
+ className: "mb-1 flex items-center justify-between pl-4 pr-3",
1873
+ children: [/* @__PURE__ */ jsx("h3", {
1874
+ id: headingId,
1875
+ className: "text-xs font-medium text-muted-foreground",
1876
+ children: props.title
1877
+ }), /* @__PURE__ */ jsx("button", {
1878
+ type: "button",
1879
+ disabled: props.creating,
1880
+ className: "flex h-6 w-6 items-center justify-center rounded text-muted-foreground hover:bg-accent hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50",
1881
+ title: props.addLabel,
1882
+ "aria-label": props.addLabel,
1883
+ onClick: props.onCreate,
1884
+ children: /* @__PURE__ */ jsx(Icon, {
1885
+ name: "plus",
1886
+ className: "h-3.5 w-3.5"
1887
+ })
1888
+ })]
1889
+ }), props.nodes.length === 0 ? /* @__PURE__ */ jsx("p", {
1890
+ className: "px-4 py-1 text-xs text-muted-foreground",
1891
+ children: props.empty
1892
+ }) : /* @__PURE__ */ jsx("div", {
1893
+ className: "flex flex-col gap-0.5",
1894
+ children: props.nodes.map((node, i) => /* @__PURE__ */ jsxs("div", {
1895
+ className: `relative ${drag?.from === i ? "opacity-50" : ""}`,
1896
+ draggable: Boolean(onReorder),
1897
+ onDragStart: (event) => {
1898
+ event.dataTransfer.effectAllowed = "move";
1899
+ event.dataTransfer.setData("text/plain", node.id);
1900
+ setDrag({
1901
+ from: i,
1902
+ at: i
1903
+ });
1904
+ },
1905
+ onDragOver: (event) => {
1906
+ if (!drag) return;
1907
+ event.preventDefault();
1908
+ event.dataTransfer.dropEffect = "move";
1909
+ const box = event.currentTarget.getBoundingClientRect();
1910
+ const at = event.clientY < box.top + box.height / 2 ? i : i + 1;
1911
+ if (at !== drag.at) setDrag({
1912
+ ...drag,
1913
+ at
1914
+ });
1915
+ },
1916
+ onDrop: (event) => {
1917
+ event.preventDefault();
1918
+ if (drag) drop(drag.from, drag.at);
1919
+ setDrag(null);
1920
+ },
1921
+ onDragEnd: () => setDrag(null),
1922
+ children: [
1923
+ showLine(i) ? /* @__PURE__ */ jsx(DropLine, { edge: "top" }) : null,
1924
+ /* @__PURE__ */ jsx(NodeRow, {
1925
+ node,
1926
+ lastRunStatus: props.lastRuns?.get(node.id),
1927
+ approvals: props.approvals?.byWorkflow.get(node.id),
1928
+ approvalsCapped: props.approvals?.capped,
1929
+ onShowApprovals: props.onShowApprovals ? () => props.onShowApprovals(node) : void 0,
1930
+ active: props.activeId === node.id,
1931
+ onOpen: () => props.onOpen(node),
1932
+ onEdit: props.onEdit ? () => props.onEdit(node) : void 0,
1933
+ keyShortcuts: onReorder ? "Alt+ArrowUp Alt+ArrowDown" : void 0,
1934
+ onKeyDown: onReorder ? (event) => {
1935
+ if (!event.altKey) return;
1936
+ if (event.key === "ArrowUp" && i > 0) {
1937
+ event.preventDefault();
1938
+ onReorder(i, i - 1);
1939
+ } else if (event.key === "ArrowDown" && i < count - 1) {
1940
+ event.preventDefault();
1941
+ onReorder(i, i + 1);
1942
+ }
1943
+ } : void 0
1944
+ }),
1945
+ i === count - 1 && showLine(count) ? /* @__PURE__ */ jsx(DropLine, { edge: "bottom" }) : null
1946
+ ]
1947
+ }, node.id))
1948
+ })]
1949
+ });
1950
+ }
1951
+ function Sidebar(props) {
1952
+ return /* @__PURE__ */ jsxs("aside", {
1953
+ className: "max-h-56 w-full shrink-0 overflow-y-auto border-b border-solid border-border bg-muted/50 py-3 md:max-h-none md:w-60 md:border-r md:border-b-0",
1954
+ children: [
1955
+ /* @__PURE__ */ jsxs(Row, {
1956
+ active: props.allRunsActive,
1957
+ onClick: props.onShowAllRuns,
1958
+ trailing: /* @__PURE__ */ jsx(ApprovalBadge, {
1959
+ count: props.approvals.total,
1960
+ capped: props.approvals.capped,
1961
+ onClick: () => props.onShowApprovals(),
1962
+ className: "mr-2"
1963
+ }),
1964
+ children: [/* @__PURE__ */ jsx(Icon, {
1965
+ name: "list",
1966
+ className: "text-muted-foreground"
1967
+ }), /* @__PURE__ */ jsx("span", { children: "Overview" })]
1968
+ }),
1969
+ /* @__PURE__ */ jsx(Section, {
1970
+ title: "Workflows",
1971
+ addLabel: "New workflow",
1972
+ empty: "No workflows yet.",
1973
+ nodes: props.workflows,
1974
+ lastRuns: props.lastRuns,
1975
+ approvals: props.approvals,
1976
+ onShowApprovals: (node) => props.onShowApprovals(node.id),
1977
+ activeId: props.activeId,
1978
+ onOpen: props.onOpenWorkflow,
1979
+ onEdit: props.onEditWorkflow,
1980
+ onCreate: props.onCreateWorkflow,
1981
+ onReorder: props.onReorderWorkflow,
1982
+ creating: props.creating
1983
+ }),
1984
+ /* @__PURE__ */ jsx(Section, {
1985
+ title: "Connections",
1986
+ addLabel: "New connection",
1987
+ empty: "No connections yet.",
1988
+ nodes: props.connections,
1989
+ activeId: props.activeId,
1990
+ onOpen: props.onOpenConnection,
1991
+ onCreate: props.onCreateConnection,
1992
+ creating: props.creating
1993
+ })
1994
+ ]
1995
+ });
1996
+ }
1997
+ //#endregion
1998
+ //#region editors/workflow-studio/components/use-item-selection.ts
1999
+ function readLegacyHash() {
2000
+ if (typeof window === "undefined") return void 0;
2001
+ return window.location.hash.replace(/^#/, "") || void 0;
2002
+ }
2003
+ /** The selected item, a setter, and `go`, which also opens or closes the item's
2004
+ * editor; each is one history entry, so back and forward walk the studio. */
2005
+ function useItemSelection(openEditorId) {
2006
+ const params = useSearchParams();
2007
+ const setParams = useSetSearchParams();
2008
+ const setSelectedNode = useSetSelectedNode();
2009
+ const selected = params["item"] || void 0;
2010
+ const select = useCallback((id, options) => {
2011
+ if (id === selected) return;
2012
+ setParams({ [ITEM_PARAM]: id }, options);
2013
+ }, [selected, setParams]);
2014
+ const go = useCallback((id, editor) => {
2015
+ if ((editor ?? null) === (openEditorId ?? null)) {
2016
+ select(id);
2017
+ return;
2018
+ }
2019
+ setSelectedNode(editor, { search: { [ITEM_PARAM]: id } });
2020
+ }, [
2021
+ openEditorId,
2022
+ select,
2023
+ setSelectedNode
2024
+ ]);
2025
+ useEffect(() => {
2026
+ const legacy = readLegacyHash();
2027
+ if (legacy && !selected) setParams({ [ITEM_PARAM]: legacy }, { replace: true });
2028
+ }, []);
2029
+ return [
2030
+ selected,
2031
+ select,
2032
+ go
2033
+ ];
2034
+ }
2035
+ //#endregion
2036
+ //#region editors/workflow-studio/components/useRuns.ts
2037
+ const POLL_MS = 5e3;
2038
+ function useRuns(scope, active = true) {
2039
+ const { workflowId, driveId, limit } = scope;
2040
+ const query = useRunPagesQuery({
2041
+ workflowId,
2042
+ driveId,
2043
+ limit
2044
+ }, {
2045
+ active,
2046
+ pollMs: POLL_MS
2047
+ });
2048
+ const { refetch, fetchNextPage } = query;
2049
+ return {
2050
+ runs: query.data ? runsOfPages(query.data.pages) : null,
2051
+ error: query.status === "error" ? query.error instanceof Error ? query.error.message : String(query.error) : null,
2052
+ reload: () => void refetch(),
2053
+ hasMore: query.hasNextPage,
2054
+ loadingMore: query.isFetchingNextPage,
2055
+ loadMore: () => void fetchNextPage()
2056
+ };
2057
+ }
2058
+ //#endregion
2059
+ //#region editors/workflow-studio/components/ScrollFade.tsx
2060
+ const FADE = 40;
2061
+ function fadeMask(start, end) {
2062
+ if (!start && !end) return void 0;
2063
+ return `linear-gradient(to right, ${start ? `transparent, black ${FADE}px` : "black"}, ${end ? `black calc(100% - ${FADE}px), transparent` : "black"})`;
2064
+ }
2065
+ function ScrollFade(props) {
2066
+ const ref = useRef(null);
2067
+ const [edges, setEdges] = useState({
2068
+ start: false,
2069
+ end: false
2070
+ });
2071
+ useEffect(() => {
2072
+ const element = ref.current;
2073
+ if (!element) return;
2074
+ const measure = () => {
2075
+ const start = element.scrollLeft > 1;
2076
+ const end = element.scrollLeft + element.clientWidth < element.scrollWidth - 1;
2077
+ setEdges((prev) => prev.start === start && prev.end === end ? prev : {
2078
+ start,
2079
+ end
2080
+ });
2081
+ };
2082
+ measure();
2083
+ const resize = new ResizeObserver(measure);
2084
+ resize.observe(element);
2085
+ if (element.firstElementChild) resize.observe(element.firstElementChild);
2086
+ element.addEventListener("scroll", measure, { passive: true });
2087
+ return () => {
2088
+ resize.disconnect();
2089
+ element.removeEventListener("scroll", measure);
2090
+ };
2091
+ }, []);
2092
+ const mask = fadeMask(edges.start, edges.end);
2093
+ return /* @__PURE__ */ jsx("span", {
2094
+ ref,
2095
+ className: `block ${props.clip ? "overflow-hidden" : "overflow-x-auto"} ${props.className ?? ""}`,
2096
+ style: {
2097
+ maskImage: mask,
2098
+ WebkitMaskImage: mask
2099
+ },
2100
+ children: props.children
2101
+ });
2102
+ }
2103
+ //#endregion
2104
+ //#region editors/workflow-studio/components/use-collapsed.ts
2105
+ const KEY = "workflow-studio:collapsed";
2106
+ function read() {
2107
+ try {
2108
+ const parsed = JSON.parse(localStorage.getItem(KEY) ?? "[]");
2109
+ return new Set(Array.isArray(parsed) ? parsed.filter((id) => typeof id === "string") : []);
2110
+ } catch {
2111
+ return /* @__PURE__ */ new Set();
2112
+ }
2113
+ }
2114
+ function write(ids) {
2115
+ try {
2116
+ localStorage.setItem(KEY, JSON.stringify([...ids]));
2117
+ } catch {}
2118
+ }
2119
+ function useCollapsed() {
2120
+ const [collapsed, setCollapsed] = useState(read);
2121
+ return {
2122
+ isCollapsed: (id) => collapsed.has(id),
2123
+ toggle: useCallback((id) => {
2124
+ setCollapsed((previous) => {
2125
+ const next = new Set(previous);
2126
+ if (!next.delete(id)) next.add(id);
2127
+ write(next);
2128
+ return next;
2129
+ });
2130
+ }, [])
2131
+ };
2132
+ }
2133
+ //#endregion
2134
+ //#region editors/workflow-studio/components/WorkflowGraph.tsx
2135
+ const STACK_GAP = 16;
2136
+ const MAX_STRETCH = 1.5;
2137
+ function fitGraph(base, cols, room) {
2138
+ if (!room || room.width <= 0 || cols === 0) return {
2139
+ g: base,
2140
+ stacked: false,
2141
+ perRow: Math.max(cols, 1)
2142
+ };
2143
+ const tailOf = (col) => base.label ? col / 2 : base.r;
2144
+ const span = (n, lead) => lead + (n - 1) * base.col + base.r + tailOf(base.col);
2145
+ const beside = room.width - room.pill;
2146
+ const stacked = span(cols, base.lead) > beside;
2147
+ const lead = stacked ? base.pillLogoX * 2 : base.lead;
2148
+ const space = stacked ? room.width : beside;
2149
+ const fits = Math.floor((space - lead - base.r - tailOf(base.col)) / base.col) + 1;
2150
+ const perRow = stacked ? Math.min(cols, Math.max(2, fits)) : cols;
2151
+ const fill = base.label ? (space - lead - base.r) / (perRow - .5) : perRow > 1 ? (space - lead - 2 * base.r) / (perRow - 1) : base.col;
2152
+ const col = Math.floor(Math.min(base.col * MAX_STRETCH, Math.max(base.col, fill)));
2153
+ return {
2154
+ g: {
2155
+ ...base,
2156
+ col,
2157
+ lead
2158
+ },
2159
+ stacked,
2160
+ perRow
2161
+ };
2162
+ }
2163
+ const GEOMETRY = {
2164
+ sm: {
2165
+ r: 12,
2166
+ col: 144,
2167
+ lane: 80,
2168
+ lead: 40,
2169
+ top: 14,
2170
+ dip: 60,
2171
+ label: 34,
2172
+ subtitle: false,
2173
+ nameText: "text-xs leading-4",
2174
+ logo: 14,
2175
+ circle: "h-6 w-6",
2176
+ pill: "h-7 pl-1 pr-2.5 text-[12px]",
2177
+ pillLogo: "h-5 w-5",
2178
+ pillLogoX: 14,
2179
+ portText: "text-[10px]"
2180
+ },
2181
+ md: {
2182
+ r: 18,
2183
+ col: 168,
2184
+ lane: 112,
2185
+ lead: 48,
2186
+ top: 18,
2187
+ dip: 86,
2188
+ label: 54,
2189
+ subtitle: true,
2190
+ nameText: "text-[13px] leading-[18px]",
2191
+ logo: 20,
2192
+ circle: "h-9 w-9",
2193
+ pill: "h-9 pl-1.5 pr-3 text-[13px]",
2194
+ pillLogo: "h-6 w-6",
2195
+ pillLogoX: 18,
2196
+ portText: "text-[11px]"
2197
+ }
2198
+ };
2199
+ const RING$1 = {
2200
+ ok: "ring-wf-ok",
2201
+ fail: "ring-wf-fail",
2202
+ warn: "ring-wf-warn",
2203
+ run: "ring-wf-run",
2204
+ idle: "ring-foreground/15 dark:ring-foreground/30"
2205
+ };
2206
+ const STROKE = {
2207
+ ok: "text-wf-ok",
2208
+ fail: "text-wf-fail",
2209
+ warn: "text-wf-warn",
2210
+ run: "text-wf-run",
2211
+ idle: "text-foreground/15 dark:text-foreground/30"
2212
+ };
2213
+ const PORT_PILL = {
2214
+ true: "bg-wf-ok/10 text-wf-ok ring-wf-ok/30",
2215
+ false: "bg-foreground/5 text-muted-foreground ring-foreground/15",
2216
+ error: "bg-wf-fail/10 text-wf-fail ring-wf-fail/30",
2217
+ each: "bg-violet-500/10 text-violet-500 ring-violet-500/30",
2218
+ otherwise: "bg-foreground/5 text-muted-foreground ring-foreground/15"
2219
+ };
2220
+ const pillOf = (port) => PORT_PILL[port] ?? (/^branch_\d+$/.test(port) ? "bg-wf-run/10 text-wf-run ring-wf-run/30" : void 0);
2221
+ function roundedPath(points, radius = 6) {
2222
+ let d = `M ${points[0][0]} ${points[0][1]}`;
2223
+ for (let i = 1; i < points.length - 1; i++) {
2224
+ const [px, py] = points[i - 1];
2225
+ const [x, y] = points[i];
2226
+ const [nx, ny] = points[i + 1];
2227
+ const r = Math.min(radius, Math.hypot(x - px, y - py) / 2, Math.hypot(nx - x, ny - y) / 2);
2228
+ const inX = x - Math.sign(x - px) * r;
2229
+ const inY = y - Math.sign(y - py) * r;
2230
+ const outX = x + Math.sign(nx - x) * r;
2231
+ const outY = y + Math.sign(ny - y) * r;
2232
+ d += ` L ${inX} ${inY} Q ${x} ${y} ${outX} ${outY}`;
2233
+ }
2234
+ const [lx, ly] = points[points.length - 1];
2235
+ return `${d} L ${lx} ${ly}`;
2236
+ }
2237
+ function simplify(route) {
2238
+ const points = [];
2239
+ for (const point of route) {
2240
+ const last = points.at(-1);
2241
+ if (last && last[0] === point[0] && last[1] === point[1]) continue;
2242
+ const prev = points.at(-2);
2243
+ if (prev && last && (prev[0] === last[0] && last[0] === point[0] || prev[1] === last[1] && last[1] === point[1])) points.pop();
2244
+ points.push(point);
2245
+ }
2246
+ return points;
2247
+ }
2248
+ function edgeRoute(g, source, target, trackY, stacked) {
2249
+ const dir = target.dir;
2250
+ const after = source ? source.x + dir * g.col / 2 : g.lead / 2;
2251
+ const fromAbove = !source && stacked;
2252
+ const x1 = source ? source.x + dir * g.r : fromAbove ? after : 0;
2253
+ const y1 = source ? source.y : fromAbove ? -16 : g.top;
2254
+ const x2 = target.x - dir * g.r;
2255
+ const y2 = target.y;
2256
+ const before = target.x - dir * g.col / 2;
2257
+ return {
2258
+ points: simplify([
2259
+ [x1, y1],
2260
+ [after, y1],
2261
+ [after, trackY],
2262
+ [before, trackY],
2263
+ [before, y2],
2264
+ [x2, y2]
2265
+ ]),
2266
+ label: {
2267
+ x: ((trackY === y1 ? x1 : after) + (trackY === y2 ? x2 : before)) / 2,
2268
+ y: trackY
2269
+ }
2270
+ };
2271
+ }
2272
+ function wrapRoute(g, source, target, ends) {
2273
+ const turn = source.dir > 0 ? ends.right : ends.left;
2274
+ const x1 = source.x + source.dir * g.r;
2275
+ const before = target.x - target.dir * g.col / 2;
2276
+ const y = (target.row - source.row) % 2 === 1 ? target.y : target.y - g.lane / 2;
2277
+ return {
2278
+ points: simplify([
2279
+ [x1, source.y],
2280
+ [turn, source.y],
2281
+ [turn, y],
2282
+ [before, y],
2283
+ [before, target.y],
2284
+ [target.x - target.dir * g.r, target.y]
2285
+ ]),
2286
+ label: {
2287
+ x: (x1 + turn) / 2,
2288
+ y: source.y
2289
+ }
2290
+ };
2291
+ }
2292
+ function Mark({ label, className, onOpen, children, ref, onClick, ...rest }) {
2293
+ return onOpen ? /* @__PURE__ */ jsx("button", {
2294
+ ...rest,
2295
+ ref,
2296
+ type: "button",
2297
+ "aria-label": label,
2298
+ className: `${className} focus-visible:outline-none focus-visible:ring-[3px]`,
2299
+ onClick: (event) => {
2300
+ onClick?.(event);
2301
+ onOpen();
2302
+ },
2303
+ children
2304
+ }) : /* @__PURE__ */ jsx("span", {
2305
+ ...rest,
2306
+ ref,
2307
+ onClick,
2308
+ className,
2309
+ children
2310
+ });
2311
+ }
2312
+ function WorkflowGraph(props) {
2313
+ const { state, latest } = props;
2314
+ const frame = useRef(null);
2315
+ const pill = useRef(null);
2316
+ const [room, setRoom] = useState(null);
2317
+ useLayoutEffect(() => {
2318
+ const element = frame.current;
2319
+ if (!props.fit || !element) return;
2320
+ const measure = () => {
2321
+ const next = {
2322
+ width: element.clientWidth,
2323
+ pill: pill.current?.offsetWidth ?? 0
2324
+ };
2325
+ setRoom((prev) => prev?.width === next.width && prev.pill === next.pill ? prev : next);
2326
+ };
2327
+ measure();
2328
+ const observer = new ResizeObserver(measure);
2329
+ observer.observe(element);
2330
+ if (pill.current) observer.observe(pill.current);
2331
+ return () => observer.disconnect();
2332
+ }, [props.fit]);
2333
+ const layout = graphLayout({
2334
+ triggerId: state.trigger?.id,
2335
+ steps: state.steps,
2336
+ edges: state.edges
2337
+ });
2338
+ const portText = (edge) => {
2339
+ const step = state.steps.find((entry) => entry.id === edge.from);
2340
+ return (step && stepPortLabel(stepBlock(step), step.config, edge.port)) ?? edge.port;
2341
+ };
2342
+ const { g, stacked, perRow } = fitGraph(GEOMETRY[props.size ?? "sm"], layout.cols, props.fit ? room : null);
2343
+ const rowOf = (col) => Math.floor((col - 1) / perRow);
2344
+ const rows = Math.max(1, Math.ceil(layout.cols / perRow));
2345
+ const rowLanes = Array.from({ length: rows }, () => 1);
2346
+ for (const node of layout.nodes) {
2347
+ const row = rowOf(node.col);
2348
+ rowLanes[row] = Math.max(rowLanes[row], node.lane + 1);
2349
+ }
2350
+ const rowTop = [];
2351
+ for (let row = 0, y = g.top; row < rows; y += rowLanes[row] * g.lane, row++) rowTop.push(y);
2352
+ const spot = (col, lane) => {
2353
+ const row = rowOf(col);
2354
+ const slot = (col - 1) % perRow;
2355
+ const back = row % 2 === 1;
2356
+ return {
2357
+ x: g.lead + (back ? perRow - 1 - slot : slot) * g.col + g.r,
2358
+ y: rowTop[row] + lane * g.lane,
2359
+ row,
2360
+ dir: back ? -1 : 1
2361
+ };
2362
+ };
2363
+ const records = new Map((latest?.steps ?? []).map((record) => [record.stepKey, record]));
2364
+ const toneOfStep = (key) => {
2365
+ const status = records.get(key)?.status;
2366
+ return status ? toneOf(STEP_TONE, status) : "idle";
2367
+ };
2368
+ const at = new Map(layout.nodes.map((node) => [node.step.id, node]));
2369
+ const lastX = g.lead + (Math.min(perRow, layout.cols) - 1) * g.col + g.r;
2370
+ const width = layout.cols > 0 ? lastX + (g.label ? g.col / 2 : g.r) : 0;
2371
+ const ends = {
2372
+ left: g.lead / 2,
2373
+ right: lastX + g.col / 2
2374
+ };
2375
+ const trackY = (edge, row) => rowTop[row] + edge.track.lane * g.lane + (edge.track.under ? g.dip : 0);
2376
+ const routes = layout.edges.map((edge) => {
2377
+ const from = edge.from === "trigger" ? null : at.get(edge.from);
2378
+ const to = at.get(edge.to);
2379
+ const source = from ? spot(from.col, from.lane) : null;
2380
+ const target = spot(to.col, to.lane);
2381
+ const wraps = source !== null && source.row !== target.row;
2382
+ return {
2383
+ key: `${edge.from}-${edge.port}-${edge.to}`,
2384
+ edge,
2385
+ tone: toneOfStep(to.step.key),
2386
+ under: !wraps && edge.track.under,
2387
+ route: wraps ? wrapRoute(g, source, target, ends) : edgeRoute(g, source, target, trackY(edge, target.row), stacked)
2388
+ };
2389
+ });
2390
+ const dips = routes.filter((route) => route.under).map(({ route, edge }) => route.label.y + (pillOf(edge.port) ? 10 : 4));
2391
+ const height = Math.max(...layout.nodes.map((node) => spot(node.col, node.lane).y + (g.label ? g.r + 6 + g.label : g.top)), ...dips);
2392
+ const labelBox = (x) => {
2393
+ let w = Math.min(g.col - 16, 2 * (width - x));
2394
+ let left = x - w / 2;
2395
+ if (stacked && left < -12) {
2396
+ left += Math.min(-12 - left, 16);
2397
+ if (left < -12) {
2398
+ w -= -12 - left;
2399
+ left = -12;
2400
+ }
2401
+ }
2402
+ return {
2403
+ left,
2404
+ width: w
2405
+ };
2406
+ };
2407
+ const trigger = state.trigger ? triggerBlock(state.trigger) : null;
2408
+ return /* @__PURE__ */ jsx(TipProvider, { children: /* @__PURE__ */ jsxs("div", {
2409
+ ref: frame,
2410
+ className: stacked ? "flex flex-col items-start" : "flex items-start",
2411
+ children: [/* @__PURE__ */ jsx("span", {
2412
+ ref: pill,
2413
+ className: "flex shrink-0",
2414
+ children: /* @__PURE__ */ jsx(Tip, {
2415
+ content: /* @__PURE__ */ jsx(TriggerTip, {
2416
+ trigger,
2417
+ latest
2418
+ }),
2419
+ children: /* @__PURE__ */ jsxs(Mark, {
2420
+ label: `Trigger: ${props.triggerText}`,
2421
+ onOpen: props.onOpen,
2422
+ className: `flex shrink-0 items-center gap-1.5 rounded-full bg-card font-medium text-foreground ring-[1.5px] ${g.pill} ${latest ? RING$1.ok : RING$1.idle}`,
2423
+ children: [/* @__PURE__ */ jsx("span", {
2424
+ className: `flex items-center justify-center rounded-full dark:bg-white ${g.pillLogo}`,
2425
+ children: trigger ? /* @__PURE__ */ jsx(BlockLogo, {
2426
+ bare: true,
2427
+ block: trigger,
2428
+ size: g.logo - 2
2429
+ }) : null
2430
+ }), props.triggerText]
2431
+ })
2432
+ })
2433
+ }), layout.nodes.length > 0 ? /* @__PURE__ */ jsxs("ol", {
2434
+ className: `relative shrink-0 ${stacked ? "" : "-ml-px"}`,
2435
+ style: {
2436
+ width,
2437
+ height,
2438
+ marginTop: stacked ? STACK_GAP : 0
2439
+ },
2440
+ "aria-label": layout.nodes.map((node) => {
2441
+ const status = records.get(node.step.key)?.status;
2442
+ const label = node.step.name || node.step.key;
2443
+ return status ? `${label}: ${status.toLowerCase()}` : label;
2444
+ }).join(", "),
2445
+ children: [
2446
+ /* @__PURE__ */ jsx("svg", {
2447
+ "aria-hidden": true,
2448
+ className: "absolute inset-0 overflow-visible",
2449
+ width,
2450
+ height,
2451
+ children: routes.map(({ key, edge, route, tone }) => /* @__PURE__ */ jsx("path", {
2452
+ d: roundedPath(route.points),
2453
+ fill: "none",
2454
+ stroke: "currentColor",
2455
+ strokeWidth: 2,
2456
+ strokeDasharray: edge.port === "error" ? "3 3" : void 0,
2457
+ className: STROKE[tone]
2458
+ }, key))
2459
+ }),
2460
+ routes.map(({ key, edge, route }) => pillOf(edge.port) ? /* @__PURE__ */ jsx("span", {
2461
+ "aria-hidden": true,
2462
+ className: "pointer-events-none absolute z-[1] -translate-x-1/2 -translate-y-1/2 rounded-full bg-card",
2463
+ style: {
2464
+ left: route.label.x,
2465
+ top: route.label.y
2466
+ },
2467
+ children: /* @__PURE__ */ jsx("span", {
2468
+ className: `block rounded-full px-1.5 font-medium leading-4 ring-1 ring-inset ${g.portText} ${pillOf(edge.port)}`,
2469
+ children: portText(edge)
2470
+ })
2471
+ }, key) : null),
2472
+ layout.nodes.map((node) => {
2473
+ const record = records.get(node.step.key);
2474
+ const skipped = record?.status === "SKIPPED";
2475
+ const name = node.step.name || node.step.key;
2476
+ const { x, y } = spot(node.col, node.lane);
2477
+ const tip = /* @__PURE__ */ jsx(StepTip, {
2478
+ step: node.step,
2479
+ port: node.port,
2480
+ record,
2481
+ ran: Boolean(latest)
2482
+ });
2483
+ return /* @__PURE__ */ jsxs("li", { children: [/* @__PURE__ */ jsx("span", {
2484
+ className: "absolute",
2485
+ style: {
2486
+ left: x - g.r,
2487
+ top: y - g.r
2488
+ },
2489
+ children: /* @__PURE__ */ jsx(Tip, {
2490
+ content: tip,
2491
+ children: /* @__PURE__ */ jsx(Mark, {
2492
+ label: `${name}: ${record ? record.status.toLowerCase() : "not run"}`,
2493
+ onOpen: props.onOpen,
2494
+ className: `flex items-center justify-center rounded-full bg-card transition-shadow ${g.circle} ${skipped ? "border-[1.5px] border-dashed border-foreground/40" : `ring-[1.5px] hover:ring-[3px] dark:bg-white ${RING$1[toneOfStep(node.step.key)]}`}`,
2495
+ children: /* @__PURE__ */ jsx("span", {
2496
+ className: skipped ? "flex opacity-40" : "flex",
2497
+ children: /* @__PURE__ */ jsx(BlockLogo, {
2498
+ bare: true,
2499
+ block: stepBlock(node.step),
2500
+ size: g.logo
2501
+ })
2502
+ })
2503
+ })
2504
+ })
2505
+ }), g.label ? /* @__PURE__ */ jsxs("span", {
2506
+ "aria-hidden": true,
2507
+ className: "pointer-events-none absolute flex flex-col items-center text-center",
2508
+ style: {
2509
+ ...labelBox(x),
2510
+ top: y + g.r + 6
2511
+ },
2512
+ children: [/* @__PURE__ */ jsx(Tip, {
2513
+ content: tip,
2514
+ children: /* @__PURE__ */ jsx("span", {
2515
+ className: `pointer-events-auto line-clamp-2 max-w-full font-medium text-foreground [overflow-wrap:anywhere] ${g.nameText}`,
2516
+ children: name
2517
+ })
2518
+ }), g.subtitle ? /* @__PURE__ */ jsx("span", {
2519
+ className: "max-w-full truncate text-xs text-muted-foreground",
2520
+ children: blockMeta(stepBlock(node.step)).displayName
2521
+ }) : null]
2522
+ }) : null] }, node.step.id);
2523
+ })
2524
+ ]
2525
+ }) : null]
2526
+ }) });
2527
+ }
2528
+ //#endregion
2529
+ //#region editors/workflow-studio/components/WorkflowBoard.tsx
2530
+ function CollapsedChain(props) {
2531
+ const trigger = props.state.trigger ? triggerBlock(props.state.trigger) : null;
2532
+ const links = workflowLinks({
2533
+ triggerId: props.state.trigger?.id,
2534
+ steps: props.state.steps,
2535
+ edges: props.state.edges
2536
+ }, props.latest);
2537
+ return /* @__PURE__ */ jsxs("span", {
2538
+ className: "flex min-w-0 items-center",
2539
+ children: [/* @__PURE__ */ jsx(Tip, {
2540
+ content: /* @__PURE__ */ jsx(TriggerTip, {
2541
+ trigger,
2542
+ latest: props.latest,
2543
+ text: props.triggerText
2544
+ }),
2545
+ children: /* @__PURE__ */ jsx("span", {
2546
+ className: "flex min-w-6 shrink-[100]",
2547
+ children: /* @__PURE__ */ jsxs("span", {
2548
+ className: `flex h-6 min-w-0 max-w-full items-center gap-1.5 overflow-hidden rounded-full bg-card px-0.5 text-[12px] font-medium text-foreground ring-[1.5px] @[26rem]:pr-2.5 ${props.latest ? "ring-wf-ok" : "ring-foreground/15 dark:ring-foreground/30"}`,
2549
+ children: [/* @__PURE__ */ jsx("span", {
2550
+ className: "flex h-5 w-5 shrink-0 items-center justify-center rounded-full dark:bg-white",
2551
+ children: trigger ? /* @__PURE__ */ jsx(BlockLogo, {
2552
+ bare: true,
2553
+ block: trigger,
2554
+ size: 12
2555
+ }) : null
2556
+ }), /* @__PURE__ */ jsx("span", {
2557
+ className: "hidden truncate @[26rem]:inline",
2558
+ children: props.triggerText
2559
+ })]
2560
+ })
2561
+ })
2562
+ }), links.length > 0 ? /* @__PURE__ */ jsxs("span", {
2563
+ className: "hidden min-w-0 items-center @[26rem]:flex",
2564
+ children: [/* @__PURE__ */ jsx("span", {
2565
+ "aria-hidden": true,
2566
+ className: "h-0.5 w-3 shrink-0 bg-foreground/15 dark:bg-foreground/30"
2567
+ }), /* @__PURE__ */ jsx(ScrollFade, {
2568
+ clip: true,
2569
+ className: "-my-1 min-w-0 px-0.5 py-1",
2570
+ children: /* @__PURE__ */ jsx(MiniChain, { links })
2571
+ })]
2572
+ }) : null]
2573
+ });
2574
+ }
2575
+ function RowToggle(props) {
2576
+ const [, dispatch] = useDispatch(props.document);
2577
+ const state = props.document.state.global;
2578
+ return /* @__PURE__ */ jsx(StatusToggle, {
2579
+ tooltipSide: "left",
2580
+ published: Boolean(state.published),
2581
+ status: state.status,
2582
+ onChange: (status) => dispatch(actions.setWorkflowStatus({ status }))
2583
+ });
2584
+ }
2585
+ function summary(rows) {
2586
+ const count = `${rows.length} ${rows.length === 1 ? "workflow" : "workflows"}`;
2587
+ const failing = rows.filter((row) => row.runs[0]?.status === "FAILED").length;
2588
+ const parts = [count, `${rows.filter((row) => row.status === "ENABLED").length} enabled`];
2589
+ if (failing > 0) parts.push(`${failing} failed on the last run`);
2590
+ return parts.join(", ");
2591
+ }
2592
+ function WorkflowBoard(props) {
2593
+ const { approvals, onShowApprovals } = props;
2594
+ usePieceLogos();
2595
+ const { isCollapsed, toggle } = useCollapsed();
2596
+ const documents = useWorkflowDocumentsInSelectedDrive() ?? [];
2597
+ const runs = props.runs ?? [];
2598
+ const positions = new Map(props.order.map((id, i) => [id, i]));
2599
+ const position = (id) => positions.get(id) ?? positions.size;
2600
+ const rows = documents.map((document) => {
2601
+ const state = document.state.global;
2602
+ const workflowRuns = runs.filter((run) => run.workflowId === document.header.id);
2603
+ return {
2604
+ document,
2605
+ id: document.header.id,
2606
+ name: state.name || document.header.name || "Untitled workflow",
2607
+ description: state.description,
2608
+ status: state.status,
2609
+ trigger: describeTrigger(state.trigger),
2610
+ runs: workflowRuns
2611
+ };
2612
+ }).sort((a, b) => position(a.id) - position(b.id));
2613
+ return /* @__PURE__ */ jsxs("section", {
2614
+ className: "mb-10",
2615
+ children: [/* @__PURE__ */ jsxs("div", {
2616
+ className: "mb-4 flex flex-wrap items-end justify-between gap-3",
2617
+ children: [/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("h2", {
2618
+ className: "text-2xl font-semibold tracking-tight text-foreground",
2619
+ children: "Workflows"
2620
+ }), /* @__PURE__ */ jsxs("p", {
2621
+ className: "mt-1 flex flex-wrap items-center gap-2 text-[13px] text-muted-foreground",
2622
+ children: [rows.length === 0 ? "Automations in this drive" : summary(rows), approvals && approvals.total > 0 ? /* @__PURE__ */ jsxs("button", {
2623
+ type: "button",
2624
+ className: "inline-flex items-center gap-1 rounded-full bg-wf-warn/12 px-2 py-0.5 text-xs font-medium text-wf-warn hover:bg-wf-warn/20 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
2625
+ onClick: () => onShowApprovals?.(),
2626
+ children: [/* @__PURE__ */ jsx(Icon, {
2627
+ name: "clock",
2628
+ className: "h-3 w-3"
2629
+ }), approvalCountLabel(approvals.total, approvals.capped)]
2630
+ }) : null]
2631
+ })] }), /* @__PURE__ */ jsxs(Button, {
2632
+ variant: "primary",
2633
+ disabled: props.creating,
2634
+ onClick: props.onCreate,
2635
+ children: [/* @__PURE__ */ jsx(Icon, {
2636
+ name: "plus",
2637
+ className: "h-3.5 w-3.5"
2638
+ }), "New workflow"]
2639
+ })]
2640
+ }), rows.length === 0 ? /* @__PURE__ */ jsxs("div", {
2641
+ className: "rounded-xl border border-dashed border-foreground/15 px-6 py-12 text-center",
2642
+ children: [/* @__PURE__ */ jsx("p", {
2643
+ className: "text-[15px] font-medium text-foreground",
2644
+ children: "No workflows yet"
2645
+ }), /* @__PURE__ */ jsx("p", {
2646
+ className: "mx-auto mt-1 max-w-sm text-[13px] text-muted-foreground",
2647
+ children: "A workflow starts on a trigger, like a schedule or a webhook, and runs a chain of steps across your services."
2648
+ })]
2649
+ }) : /* @__PURE__ */ jsx(TipProvider, { children: /* @__PURE__ */ jsx("ul", {
2650
+ "aria-label": "Workflows",
2651
+ className: "rounded-xl border border-solid border-foreground/10 bg-card",
2652
+ children: rows.map((row) => {
2653
+ const latest = row.runs.at(0);
2654
+ const latestTone = toneOf(RUN_TONE, latest?.status);
2655
+ const health = workflowHealth(row.status, latest?.status, Boolean(row.document.state.global.published));
2656
+ const collapsed = isCollapsed(row.id);
2657
+ return /* @__PURE__ */ jsxs("li", {
2658
+ className: "group/row border-b border-solid border-foreground/10 first:rounded-t-xl last:rounded-b-xl last:border-b-0",
2659
+ children: [/* @__PURE__ */ jsxs("div", {
2660
+ className: `flex items-start transition-colors group-first/row:rounded-t-xl has-[[data-row-header]:hover]:bg-accent/40 has-[[data-row-header]:focus-visible]:bg-accent/40 ${collapsed ? "group-last/row:rounded-b-xl" : ""}`,
2661
+ children: [/* @__PURE__ */ jsxs("button", {
2662
+ type: "button",
2663
+ "data-row-header": true,
2664
+ "aria-expanded": !collapsed,
2665
+ "aria-label": `${collapsed ? "Expand" : "Collapse"} ${row.name}`,
2666
+ className: "group/header @container flex min-w-0 flex-1 cursor-pointer items-start gap-1 py-4 pl-2 pr-5 text-left focus-visible:outline-none",
2667
+ onClick: () => toggle(row.id),
2668
+ children: [/* @__PURE__ */ jsx("span", {
2669
+ "aria-hidden": true,
2670
+ className: "flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors group-hover/header:bg-accent group-hover/header:text-foreground group-focus-visible/header:bg-accent group-focus-visible/header:text-foreground",
2671
+ children: /* @__PURE__ */ jsx(Icon, {
2672
+ name: "chevron",
2673
+ className: `h-3.5 w-3.5 transition-transform ${collapsed ? "" : "rotate-90"}`
2674
+ })
2675
+ }), /* @__PURE__ */ jsxs("span", {
2676
+ className: `grid w-full grid-rows-[1.5rem] items-center gap-x-6 ${collapsed ? "grid-cols-[minmax(10rem,1fr)_minmax(0,2fr)] @[44rem]:grid-cols-[minmax(10rem,1fr)_minmax(0,2fr)_auto] @[60rem]:grid-cols-[minmax(10rem,1fr)_minmax(0,2fr)_minmax(0,10rem)_auto]" : "grid-cols-[minmax(0,1fr)_auto] md:grid-cols-[minmax(0,1fr)_minmax(0,10rem)_auto]"}`,
2677
+ children: [
2678
+ /* @__PURE__ */ jsxs("span", {
2679
+ className: "flex min-w-0 items-center gap-2",
2680
+ children: [
2681
+ /* @__PURE__ */ jsx(Tip, {
2682
+ content: health.label,
2683
+ children: /* @__PURE__ */ jsx("span", {
2684
+ className: "flex",
2685
+ children: /* @__PURE__ */ jsx(StatusDot, {
2686
+ tone: health.tone,
2687
+ hollow: health.hollow
2688
+ })
2689
+ })
2690
+ }),
2691
+ /* @__PURE__ */ jsx("span", {
2692
+ className: "min-w-0 truncate text-[15px] font-semibold text-foreground",
2693
+ children: row.name
2694
+ }),
2695
+ row.status !== "ENABLED" ? /* @__PURE__ */ jsx("span", {
2696
+ className: "shrink-0 rounded-full bg-muted px-2 py-0.5 text-[11px] text-muted-foreground",
2697
+ children: statusLabel(row.status)
2698
+ }) : null
2699
+ ]
2700
+ }),
2701
+ collapsed ? /* @__PURE__ */ jsx(CollapsedChain, {
2702
+ state: row.document.state.global,
2703
+ triggerText: row.trigger,
2704
+ latest
2705
+ }) : null,
2706
+ /* @__PURE__ */ jsx("span", {
2707
+ className: `hidden text-[13px] ${collapsed ? "@[60rem]:block" : "md:block"}`,
2708
+ children: latest ? /* @__PURE__ */ jsx(Tip, {
2709
+ content: formatAbsolute(latest.startedAt),
2710
+ children: /* @__PURE__ */ jsxs("span", { children: [/* @__PURE__ */ jsx("span", {
2711
+ className: `font-medium ${latestTone === "fail" ? "text-wf-fail" : latestTone === "ok" ? "text-wf-ok" : "text-foreground"}`,
2712
+ children: statusLabel(latest.status)
2713
+ }), /* @__PURE__ */ jsx("span", {
2714
+ className: "ml-1.5 text-xs text-muted-foreground",
2715
+ children: formatWhen(latest.startedAt)
2716
+ })] })
2717
+ }) : /* @__PURE__ */ jsx("span", {
2718
+ className: "text-muted-foreground",
2719
+ children: "Not run yet"
2720
+ })
2721
+ }),
2722
+ collapsed ? /* @__PURE__ */ jsx("span", {
2723
+ className: "hidden @[44rem]:block",
2724
+ children: /* @__PURE__ */ jsx(RunStrip, {
2725
+ centered: true,
2726
+ runs: row.runs
2727
+ })
2728
+ }) : /* @__PURE__ */ jsx(RunStrip, {
2729
+ centered: true,
2730
+ runs: row.runs
2731
+ })
2732
+ ]
2733
+ })]
2734
+ }), /* @__PURE__ */ jsxs("span", {
2735
+ className: "mt-4 flex h-6 shrink-0 items-center gap-1 pr-3",
2736
+ children: [
2737
+ /* @__PURE__ */ jsx(ApprovalBadge, {
2738
+ count: approvals?.byWorkflow.get(row.id) ?? 0,
2739
+ capped: approvals?.capped ?? false,
2740
+ onClick: onShowApprovals ? () => onShowApprovals(row.id) : void 0
2741
+ }),
2742
+ /* @__PURE__ */ jsx(RowToggle, { document: row.document }),
2743
+ /* @__PURE__ */ jsx(WorkflowMenu, { document: row.document })
2744
+ ]
2745
+ })]
2746
+ }), collapsed ? null : /* @__PURE__ */ jsxs("button", {
2747
+ type: "button",
2748
+ "aria-label": `Open ${row.name}`,
2749
+ className: "group/content relative flex w-full cursor-pointer flex-col gap-3 pb-4 pl-9 pr-5 pt-1 text-left transition-colors hover:bg-accent/50 focus-visible:bg-accent/50 focus-visible:outline-none group-last/row:rounded-b-xl",
2750
+ onClick: () => props.onOpen(row.id),
2751
+ children: [
2752
+ /* @__PURE__ */ jsxs("span", {
2753
+ "aria-hidden": true,
2754
+ className: "pointer-events-none absolute right-4 top-2.5 z-10 flex items-center gap-1 rounded-md bg-card px-1.5 py-0.5 text-xs font-medium text-muted-foreground opacity-0 shadow-sm transition-opacity group-hover/content:opacity-100 group-focus-visible/content:opacity-100",
2755
+ children: ["Open workflow", /* @__PURE__ */ jsx(Icon, {
2756
+ name: "arrowRight",
2757
+ className: "h-3.5 w-3.5"
2758
+ })]
2759
+ }),
2760
+ row.description ? /* @__PURE__ */ jsx("span", {
2761
+ className: "max-w-prose pl-4 text-[13px] leading-5 text-muted-foreground",
2762
+ children: row.description
2763
+ }) : null,
2764
+ /* @__PURE__ */ jsx(ScrollFade, {
2765
+ className: "max-w-full py-1 pl-4 pr-1",
2766
+ children: /* @__PURE__ */ jsx(WorkflowGraph, {
2767
+ fit: true,
2768
+ state: row.document.state.global,
2769
+ triggerText: row.trigger,
2770
+ latest
2771
+ })
2772
+ })
2773
+ ]
2774
+ })]
2775
+ }, row.id);
2776
+ })
2777
+ }) })]
2778
+ });
2779
+ }
2780
+ //#endregion
2781
+ //#region editors/workflow-studio/components/WorkflowSteps.tsx
2782
+ const RAIL = {
2783
+ ok: "bg-wf-ok",
2784
+ fail: "bg-wf-fail",
2785
+ warn: "bg-wf-warn",
2786
+ run: "bg-wf-run",
2787
+ idle: "bg-border"
2788
+ };
2789
+ const RING = {
2790
+ ok: "ring-wf-ok",
2791
+ fail: "ring-wf-fail",
2792
+ warn: "ring-wf-warn",
2793
+ run: "ring-wf-run",
2794
+ idle: "ring-border"
2795
+ };
2796
+ function TrackStop(props) {
2797
+ const { stop } = props;
2798
+ const tone = stop.status ? toneOf(STEP_TONE, stop.status) : "idle";
2799
+ return /* @__PURE__ */ jsxs("li", {
2800
+ className: "relative flex w-40 shrink-0 flex-col items-center",
2801
+ children: [
2802
+ /* @__PURE__ */ jsx("span", {
2803
+ "aria-hidden": true,
2804
+ className: `absolute left-0 top-[19px] h-0.5 w-1/2 ${props.first ? "invisible" : RAIL[props.inbound]}`
2805
+ }),
2806
+ /* @__PURE__ */ jsx("span", {
2807
+ "aria-hidden": true,
2808
+ className: `absolute right-0 top-[19px] h-0.5 w-1/2 ${props.last ? "invisible" : RAIL[props.outbound]}`
2809
+ }),
2810
+ stop.port ? /* @__PURE__ */ jsx("span", {
2811
+ className: "absolute -left-4 top-0 rounded bg-background px-1 text-[11px] text-muted-foreground",
2812
+ children: stop.port
2813
+ }) : null,
2814
+ /* @__PURE__ */ jsx("button", {
2815
+ type: "button",
2816
+ title: stop.status ? `${stop.title}: ${stop.status.toLowerCase()}` : stop.title,
2817
+ "aria-label": `${stop.title}: ${stop.status ? stop.status.toLowerCase() : "not run"}`,
2818
+ className: `relative z-10 flex h-10 w-10 items-center justify-center rounded-full bg-card ring-2 transition-shadow dark:bg-white hover:ring-4 focus-visible:outline-none focus-visible:ring-4 ${RING[tone]}`,
2819
+ onClick: props.onClick,
2820
+ children: /* @__PURE__ */ jsx(BlockLogo, {
2821
+ bare: true,
2822
+ block: stop.block,
2823
+ size: 20
2824
+ })
2825
+ }),
2826
+ /* @__PURE__ */ jsx("span", {
2827
+ className: "mt-2 max-w-full truncate px-2 text-[13px] font-medium text-foreground",
2828
+ children: stop.title
2829
+ }),
2830
+ /* @__PURE__ */ jsx("span", {
2831
+ className: "max-w-full truncate px-2 text-xs text-muted-foreground",
2832
+ title: stop.subtitle,
2833
+ children: stop.subtitle
2834
+ })
2835
+ ]
2836
+ });
2837
+ }
2838
+ function WorkflowSteps(props) {
2839
+ const { state } = props;
2840
+ usePieceLogos();
2841
+ const outline = stepOutline({
2842
+ triggerId: state.trigger?.id,
2843
+ steps: state.steps,
2844
+ edges: state.edges
2845
+ });
2846
+ const statusByKey = new Map((props.latestRun?.steps ?? []).map((step) => [step.stepKey, step.status]));
2847
+ const stopFor = (step, port) => {
2848
+ const block = stepBlock(step);
2849
+ const meta = blockMeta(block);
2850
+ return {
2851
+ id: step.id,
2852
+ title: step.name || step.key,
2853
+ subtitle: meta.displayName,
2854
+ block,
2855
+ status: statusByKey.get(step.key),
2856
+ port
2857
+ };
2858
+ };
2859
+ if (!state.trigger && state.steps.length === 0) return /* @__PURE__ */ jsx("section", {
2860
+ className: "mt-8 border-t border-solid border-border pt-6",
2861
+ children: /* @__PURE__ */ jsxs("p", {
2862
+ className: "text-[13px] text-muted-foreground",
2863
+ children: [
2864
+ "This workflow has no trigger or steps yet.",
2865
+ " ",
2866
+ /* @__PURE__ */ jsx("button", {
2867
+ type: "button",
2868
+ className: "font-medium text-foreground underline underline-offset-2",
2869
+ onClick: props.onOpenEditor,
2870
+ children: "Open the editor"
2871
+ }),
2872
+ " ",
2873
+ "to build it."
2874
+ ]
2875
+ })
2876
+ });
2877
+ return /* @__PURE__ */ jsxs("section", {
2878
+ className: "mt-8 border-t border-solid border-border pt-6",
2879
+ children: [
2880
+ /* @__PURE__ */ jsxs("div", {
2881
+ className: "mb-4 flex items-baseline gap-2",
2882
+ children: [/* @__PURE__ */ jsx("h3", {
2883
+ className: "text-[13px] font-medium text-foreground",
2884
+ children: "Steps"
2885
+ }), /* @__PURE__ */ jsx("span", {
2886
+ className: "text-xs text-muted-foreground",
2887
+ children: props.latestRun ? "Coloured by the latest run" : "Not run yet"
2888
+ })]
2889
+ }),
2890
+ !state.trigger ? /* @__PURE__ */ jsx("p", {
2891
+ className: "mb-3 text-xs text-wf-warn",
2892
+ children: "No trigger set, so this workflow never starts on its own."
2893
+ }) : null,
2894
+ /* @__PURE__ */ jsx(ScrollFade, {
2895
+ className: "-mx-1 px-1 py-1.5",
2896
+ children: /* @__PURE__ */ jsx(WorkflowGraph, {
2897
+ state,
2898
+ triggerText: describeTrigger(state.trigger),
2899
+ latest: props.latestRun,
2900
+ onOpen: props.onOpenEditor,
2901
+ size: "md",
2902
+ fit: true
2903
+ })
2904
+ }),
2905
+ outline.orphans.length > 0 ? /* @__PURE__ */ jsxs("div", {
2906
+ className: "mt-5",
2907
+ children: [/* @__PURE__ */ jsx("p", {
2908
+ className: "mb-3 text-xs text-muted-foreground",
2909
+ children: "Not connected to the trigger, so runs never reach these:"
2910
+ }), /* @__PURE__ */ jsx("ol", {
2911
+ className: "-mx-6 flex overflow-x-auto px-6 py-1.5 opacity-60",
2912
+ children: outline.orphans.map((step) => /* @__PURE__ */ jsx(TrackStop, {
2913
+ stop: stopFor(step, null),
2914
+ first: true,
2915
+ last: true,
2916
+ inbound: "idle",
2917
+ outbound: "idle",
2918
+ onClick: props.onOpenEditor
2919
+ }, step.id))
2920
+ })]
2921
+ }) : null
2922
+ ]
2923
+ });
2924
+ }
2925
+ //#endregion
2926
+ //#region editors/workflow-studio/components/WorkflowHeader.tsx
2927
+ const WORKFLOW_TYPE$1 = "powerhouse/workflow";
2928
+ function WorkflowHeader(props) {
2929
+ const workflowId = props.node.id;
2930
+ const { data: document, error, reload } = useDocumentSafe(workflowId);
2931
+ const [, dispatch] = useDispatch(document);
2932
+ if (error !== void 0) return /* @__PURE__ */ jsx(DocumentLoadError, {
2933
+ title: "This workflow could not be loaded",
2934
+ documentId: workflowId,
2935
+ error,
2936
+ onRetry: () => {
2937
+ reload();
2938
+ }
2939
+ });
2940
+ if (document?.header.documentType !== WORKFLOW_TYPE$1) return null;
2941
+ const workflow = document;
2942
+ const state = workflow.state.global;
2943
+ const stats = runStats(props.runs ?? []);
2944
+ const lastTone = toneOf(RUN_TONE, stats.lastRun?.status);
2945
+ return /* @__PURE__ */ jsxs("header", {
2946
+ className: "mb-8",
2947
+ children: [
2948
+ /* @__PURE__ */ jsxs("div", {
2949
+ className: "flex flex-wrap items-start gap-3",
2950
+ children: [/* @__PURE__ */ jsxs("div", {
2951
+ className: "min-w-0 grow",
2952
+ children: [/* @__PURE__ */ jsxs("div", {
2953
+ className: "flex items-center gap-2.5",
2954
+ children: [
2955
+ /* @__PURE__ */ jsx("h2", {
2956
+ className: "min-w-0 truncate text-xl font-semibold tracking-tight text-foreground",
2957
+ children: state.name || props.node.name || "Untitled workflow"
2958
+ }),
2959
+ /* @__PURE__ */ jsx(PublishState, { model: state }),
2960
+ state.status === "ARCHIVED" ? /* @__PURE__ */ jsx("span", {
2961
+ className: "rounded-full bg-muted px-2 py-0.5 text-xs font-medium text-muted-foreground",
2962
+ children: "Archived"
2963
+ }) : null
2964
+ ]
2965
+ }), state.description ? /* @__PURE__ */ jsx("p", {
2966
+ className: "mt-1 max-w-prose text-[13px] text-muted-foreground",
2967
+ children: state.description
2968
+ }) : null]
2969
+ }), /* @__PURE__ */ jsxs("div", {
2970
+ className: "flex items-center gap-2",
2971
+ children: [
2972
+ /* @__PURE__ */ jsx(StatusToggle, {
2973
+ published: Boolean(state.published),
2974
+ status: state.status,
2975
+ onChange: (status) => dispatch(actions.setWorkflowStatus({ status }))
2976
+ }),
2977
+ /* @__PURE__ */ jsx(Button, {
2978
+ variant: "primary",
2979
+ onClick: props.onEdit,
2980
+ children: "Edit workflow"
2981
+ }),
2982
+ /* @__PURE__ */ jsx(WorkflowMenu, {
2983
+ document: workflow,
2984
+ nodeName: props.node.name,
2985
+ onDeleted: props.onDeleted
2986
+ })
2987
+ ]
2988
+ })]
2989
+ }),
2990
+ /* @__PURE__ */ jsxs("dl", {
2991
+ className: "mt-5 flex flex-wrap gap-x-10 gap-y-3",
2992
+ children: [
2993
+ /* @__PURE__ */ jsx(Fact, {
2994
+ label: "Starts",
2995
+ children: state.trigger ? describeTrigger(state.trigger) : /* @__PURE__ */ jsx("span", {
2996
+ className: "text-wf-warn",
2997
+ children: "Never: no trigger"
2998
+ })
2999
+ }),
3000
+ /* @__PURE__ */ jsx(Fact, {
3001
+ label: "Last run",
3002
+ title: stats.lastRun ? formatAbsolute(stats.lastRun.startedAt) : void 0,
3003
+ children: stats.lastRun ? /* @__PURE__ */ jsxs("span", {
3004
+ className: `inline-flex items-center gap-1.5 ${TONE_TEXT[lastTone]}`,
3005
+ children: [/* @__PURE__ */ jsx(StatusDot, { tone: lastTone }), formatWhen(stats.lastRun.startedAt)]
3006
+ }) : /* @__PURE__ */ jsx("span", {
3007
+ className: "text-muted-foreground",
3008
+ children: "Never"
3009
+ })
3010
+ }),
3011
+ /* @__PURE__ */ jsx(Fact, {
3012
+ label: "Recent runs",
3013
+ children: stats.total > 0 ? /* @__PURE__ */ jsx(RunStrip, {
3014
+ centered: true,
3015
+ runs: props.runs ?? []
3016
+ }) : /* @__PURE__ */ jsx("span", {
3017
+ className: "text-muted-foreground",
3018
+ children: "None yet"
3019
+ })
3020
+ }),
3021
+ /* @__PURE__ */ jsx(Fact, {
3022
+ label: "Success rate",
3023
+ children: stats.successRate === null ? /* @__PURE__ */ jsx("span", {
3024
+ className: "text-muted-foreground",
3025
+ children: "No finished runs"
3026
+ }) : `${stats.successRate}%`
3027
+ }),
3028
+ /* @__PURE__ */ jsxs(Fact, {
3029
+ label: "Version",
3030
+ children: ["v", state.version]
3031
+ })
3032
+ ]
3033
+ }),
3034
+ /* @__PURE__ */ jsx(WorkflowSteps, {
3035
+ state,
3036
+ latestRun: stats.lastRun,
3037
+ onOpenEditor: props.onEdit
3038
+ })
3039
+ ]
3040
+ });
3041
+ }
3042
+ //#endregion
3043
+ //#region editors/workflow-studio/components/WorkflowStudio.tsx
3044
+ const WORKFLOW_TYPE = "powerhouse/workflow";
3045
+ const CONNECTION_TYPE = "powerhouse/connection";
3046
+ function WorkflowStudio(props) {
3047
+ return /* @__PURE__ */ jsx(WorkflowRuntimeProvider, { children: /* @__PURE__ */ jsx(Studio, { children: props.children }) });
3048
+ }
3049
+ function Studio(props) {
3050
+ const { fireWorkflow } = useRuntimeActions();
3051
+ const [drive, dispatchDrive] = useSelectedDrive();
3052
+ const nodes = useNodesInSelectedDrive() ?? [];
3053
+ const fileNodes = useFileNodesInSelectedDrive() ?? [];
3054
+ const workflowDocuments = useWorkflowDocumentsInSelectedDrive() ?? [];
3055
+ const selectedNode = useSelectedNode();
3056
+ const selectedNodeId = selectedNode?.id;
3057
+ const toast = usePHToast();
3058
+ const [selectedId, select, go] = useItemSelection(selectedNodeId);
3059
+ const [creating, setCreating] = useState(false);
3060
+ const driveId = drive.header.id;
3061
+ const orderedWorkflows = orderWorkflows(fileNodes.filter((node) => node.documentType === WORKFLOW_TYPE), nodes);
3062
+ const workflows = orderedWorkflows.map((item) => item.node);
3063
+ const connections = fileNodes.filter((node) => node.documentType === CONNECTION_TYPE);
3064
+ const editorOpen = Boolean(props.children && selectedNodeId);
3065
+ const create = (documentType, baseName, count) => {
3066
+ if (creating) return;
3067
+ setCreating(true);
3068
+ const name = `${baseName} ${count + 1}`;
3069
+ (documentType === WORKFLOW_TYPE ? addFolder(driveId, homeFolderName(nextKey(orderedWorkflows), name)).then((folder) => addDocument(driveId, name, documentType, folder.id).catch(async (error) => {
3070
+ await deleteNode(driveId, folder.id).catch(() => void 0);
3071
+ throw error;
3072
+ })) : addDocument(driveId, name, documentType)).then((node) => go(node.id, node.id)).catch((error) => {
3073
+ toast?.(error instanceof Error ? error.message : `Failed to create ${baseName}`, { type: "error" });
3074
+ }).finally(() => setCreating(false));
3075
+ };
3076
+ const reorder = (from, to) => {
3077
+ const names = new Map(workflowDocuments.map((doc) => [doc.header.id, doc.state.global.name]));
3078
+ const actions = reorderActions(orderedWorkflows, from, to, names);
3079
+ if (actions.length === 0) return;
3080
+ dispatchDrive(actions, (errors) => toast?.(errors[0]?.message ?? "Failed to reorder workflows", { type: "error" }));
3081
+ };
3082
+ const showRuns = (node) => go(node?.id);
3083
+ const liveTarget = workflows.find((node) => node.id === selectedId) ?? null;
3084
+ const connectionSelected = connections.some((node) => node.id === selectedId);
3085
+ const wasEditing = useRef(editorOpen);
3086
+ useEffect(() => {
3087
+ if (wasEditing.current && !editorOpen && connectionSelected) select(void 0, { replace: true });
3088
+ wasEditing.current = editorOpen;
3089
+ }, [
3090
+ editorOpen,
3091
+ connectionSelected,
3092
+ select
3093
+ ]);
3094
+ const selectionExists = fileNodes.some((node) => node.id === selectedId);
3095
+ useEffect(() => {
3096
+ if (selectedId && fileNodes.length > 0 && !selectionExists) select(void 0, { replace: true });
3097
+ }, [
3098
+ fileNodes.length,
3099
+ select,
3100
+ selectedId,
3101
+ selectionExists
3102
+ ]);
3103
+ const focusedWorkflow = liveTarget;
3104
+ const driveFeed = useRuns({ driveId });
3105
+ const approvals = usePendingApprovals(driveId);
3106
+ const [waitingFocus, setWaitingFocus] = useState(0);
3107
+ const showApprovals = (workflowId) => {
3108
+ go(workflowId);
3109
+ setWaitingFocus((request) => request + 1);
3110
+ };
3111
+ const workflowFeed = useRuns({ workflowId: focusedWorkflow?.id }, Boolean(focusedWorkflow));
3112
+ const feed = focusedWorkflow ? workflowFeed : driveFeed;
3113
+ const { runs, error: runsError, reload: reloadRuns } = feed;
3114
+ const lastRuns = /* @__PURE__ */ new Map();
3115
+ for (const run of driveFeed.runs ?? []) if (!lastRuns.has(run.workflowId)) lastRuns.set(run.workflowId, run.status);
3116
+ const stepNames = new Map(workflowDocuments.map((document) => [document.header.id, new Map(document.state.global.steps.map((step) => [step.key, step.name || step.key]))]));
3117
+ const { data: targetDocument } = useDocumentSafe(liveTarget?.id ?? null);
3118
+ const targetTrigger = targetDocument?.header.documentType === WORKFLOW_TYPE ? targetDocument.state.global.trigger : null;
3119
+ const manualTrigger = Boolean(targetTrigger && sameBlock(triggerBlock(targetTrigger), MANUAL_TRIGGER));
3120
+ const published = targetDocument?.header.documentType === WORKFLOW_TYPE ? targetDocument.state.global.published : null;
3121
+ const firedTrigger = published ? published.trigger : targetTrigger;
3122
+ const fireInputs = useMemo(() => firedTrigger && sameBlock(triggerBlock(firedTrigger), MANUAL_TRIGGER) ? parseManualInputs(firedTrigger.config) : [], [firedTrigger]);
3123
+ return /* @__PURE__ */ jsxs("div", {
3124
+ className: "flex h-full min-h-0 flex-col md:flex-row",
3125
+ children: [/* @__PURE__ */ jsx(Sidebar, {
3126
+ workflows,
3127
+ connections,
3128
+ lastRuns,
3129
+ approvals,
3130
+ onShowApprovals: showApprovals,
3131
+ activeId: selectedId,
3132
+ allRunsActive: !selectedId,
3133
+ creating,
3134
+ onReorderWorkflow: reorder,
3135
+ onShowAllRuns: () => showRuns(null),
3136
+ onOpenWorkflow: (node) => showRuns(node),
3137
+ onEditWorkflow: (node) => go(node.id, node.id),
3138
+ onOpenConnection: (node) => go(node.id, node.id),
3139
+ onCreateWorkflow: () => create(WORKFLOW_TYPE, "Workflow", workflows.length),
3140
+ onCreateConnection: () => create(CONNECTION_TYPE, "Connection", connections.length)
3141
+ }), /* @__PURE__ */ jsx("main", {
3142
+ className: "relative min-h-0 min-w-0 flex-1 overflow-y-auto",
3143
+ children: editorOpen ? /* @__PURE__ */ jsx("div", {
3144
+ className: "flex h-full min-h-0 flex-col",
3145
+ children: /* @__PURE__ */ jsx("div", {
3146
+ className: "flex min-h-0 flex-1 flex-col [&>#document-editor-container]:min-h-0",
3147
+ children: /* @__PURE__ */ jsx(DocumentErrorBoundary, {
3148
+ documentId: selectedNodeId,
3149
+ label: selectedNode?.name,
3150
+ onDismiss: () => go(selectedId),
3151
+ children: props.children
3152
+ }, selectedNodeId)
3153
+ })
3154
+ }) : /* @__PURE__ */ jsxs("div", {
3155
+ className: "mx-auto w-full max-w-6xl px-4 py-6 md:px-8 md:py-10",
3156
+ children: [
3157
+ liveTarget ? /* @__PURE__ */ jsx(WorkflowHeader, {
3158
+ node: liveTarget,
3159
+ runs,
3160
+ onEdit: () => go(liveTarget.id, liveTarget.id),
3161
+ onDeleted: () => select(void 0, { replace: true })
3162
+ }, liveTarget.id) : /* @__PURE__ */ jsx(WorkflowBoard, {
3163
+ runs,
3164
+ order: workflows.map((node) => node.id),
3165
+ creating,
3166
+ onOpen: (workflowId) => go(workflowId),
3167
+ approvals,
3168
+ onShowApprovals: showApprovals,
3169
+ onCreate: () => create(WORKFLOW_TYPE, "Workflow", workflows.length)
3170
+ }),
3171
+ /* @__PURE__ */ jsx(WaitingApprovals, {
3172
+ driveId: liveTarget ? void 0 : driveId,
3173
+ workflowId: liveTarget?.id,
3174
+ showWorkflow: liveTarget === null,
3175
+ stepNames,
3176
+ onChanged: reloadRuns,
3177
+ focusRequest: waitingFocus
3178
+ }),
3179
+ /* @__PURE__ */ jsx(RunsView, {
3180
+ title: liveTarget ? "Runs" : "Recent runs",
3181
+ runs,
3182
+ error: runsError,
3183
+ reload: reloadRuns,
3184
+ showWorkflow: liveTarget === null,
3185
+ hasMore: feed.hasMore,
3186
+ loadingMore: feed.loadingMore,
3187
+ onLoadMore: feed.loadMore,
3188
+ onFire: liveTarget && manualTrigger ? (payload) => fireWorkflow(liveTarget.id, payload).then((result) => result.error) : void 0,
3189
+ fireInputs
3190
+ })
3191
+ ]
3192
+ })
3193
+ })]
3194
+ });
3195
+ }
3196
+ //#endregion
3197
+ //#region editors/workflow-studio/config.ts
3198
+ const editorConfig = {
3199
+ isDragAndDropEnabled: true,
3200
+ allowedDocumentTypes: ["powerhouse/workflow", "powerhouse/connection"]
3201
+ };
3202
+ //#endregion
3203
+ //#region editors/workflow-studio/editor.tsx
3204
+ /**
3205
+ * WARNING: DO NOT EDIT
3206
+ * This file is auto-generated and updated by codegen
3207
+ */
3208
+ /** Editor component for the app */
3209
+ function Editor(props) {
3210
+ useSetPHAppConfig(editorConfig);
3211
+ return /* @__PURE__ */ jsx("div", {
3212
+ className: "h-full min-h-0 bg-background",
3213
+ children: /* @__PURE__ */ jsx(WorkflowStudio, { children: props.children })
3214
+ });
3215
+ }
3216
+ //#endregion
3217
+ export { Editor as default };
3218
+
3219
+ //# sourceMappingURL=editor-CIqKi7XK.js.map