@dxos/plugin-automation 0.8.4-main.f9ba587 → 0.8.4-main.fcfe5033a5

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 (268) hide show
  1. package/dist/lib/browser/chunk-J5LGTIGS.mjs +10 -0
  2. package/dist/lib/browser/chunk-LEN2XWRB.mjs +44 -0
  3. package/dist/lib/browser/chunk-LEN2XWRB.mjs.map +7 -0
  4. package/dist/lib/browser/chunk-VKSAIOAL.mjs +54 -0
  5. package/dist/lib/browser/chunk-VKSAIOAL.mjs.map +7 -0
  6. package/dist/lib/browser/cli/index.mjs +1110 -0
  7. package/dist/lib/browser/cli/index.mjs.map +7 -0
  8. package/dist/lib/browser/create-trigger-from-template-NH5EL6LB.mjs +71 -0
  9. package/dist/lib/browser/create-trigger-from-template-NH5EL6LB.mjs.map +7 -0
  10. package/dist/lib/browser/hooks/index.mjs +87 -0
  11. package/dist/lib/browser/hooks/index.mjs.map +7 -0
  12. package/dist/lib/browser/index.mjs +72 -83
  13. package/dist/lib/browser/index.mjs.map +4 -4
  14. package/dist/lib/browser/meta.json +1 -1
  15. package/dist/lib/browser/operations/index.mjs +14 -0
  16. package/dist/lib/browser/operations/index.mjs.map +7 -0
  17. package/dist/lib/browser/types/index.mjs +14 -0
  18. package/dist/lib/node-esm/chunk-45PS7CQD.mjs +56 -0
  19. package/dist/lib/node-esm/chunk-45PS7CQD.mjs.map +7 -0
  20. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +11 -0
  21. package/dist/lib/node-esm/chunk-V2SSR4MK.mjs +45 -0
  22. package/dist/lib/node-esm/chunk-V2SSR4MK.mjs.map +7 -0
  23. package/dist/lib/node-esm/cli/index.mjs +1111 -0
  24. package/dist/lib/node-esm/cli/index.mjs.map +7 -0
  25. package/dist/lib/node-esm/create-trigger-from-template-C7UPU2VL.mjs +72 -0
  26. package/dist/lib/node-esm/create-trigger-from-template-C7UPU2VL.mjs.map +7 -0
  27. package/dist/lib/node-esm/hooks/index.mjs +88 -0
  28. package/dist/lib/node-esm/hooks/index.mjs.map +7 -0
  29. package/dist/lib/node-esm/index.mjs +72 -83
  30. package/dist/lib/node-esm/index.mjs.map +4 -4
  31. package/dist/lib/node-esm/meta.json +1 -1
  32. package/dist/lib/node-esm/operations/index.mjs +15 -0
  33. package/dist/lib/node-esm/operations/index.mjs.map +7 -0
  34. package/dist/lib/node-esm/types/index.mjs +15 -0
  35. package/dist/types/src/AutomationPlugin.d.ts +2 -1
  36. package/dist/types/src/AutomationPlugin.d.ts.map +1 -1
  37. package/dist/types/src/capabilities/app-graph-builder.d.ts +4 -2
  38. package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -1
  39. package/dist/types/src/capabilities/compute-runtime.d.ts +14 -0
  40. package/dist/types/src/capabilities/compute-runtime.d.ts.map +1 -0
  41. package/dist/types/src/capabilities/index.d.ts +6 -3
  42. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  43. package/dist/types/src/capabilities/node.d.ts +3 -0
  44. package/dist/types/src/capabilities/node.d.ts.map +1 -0
  45. package/dist/types/src/capabilities/operation-handler.d.ts +6 -0
  46. package/dist/types/src/capabilities/operation-handler.d.ts.map +1 -0
  47. package/dist/types/src/capabilities/react-surface.d.ts +3 -2
  48. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
  49. package/dist/types/src/cli/commands/index.d.ts +2 -0
  50. package/dist/types/src/cli/commands/index.d.ts.map +1 -0
  51. package/dist/types/src/cli/commands/trigger/create/index.d.ts +25 -0
  52. package/dist/types/src/cli/commands/trigger/create/index.d.ts.map +1 -0
  53. package/dist/types/src/cli/commands/trigger/create/queue.d.ts +13 -0
  54. package/dist/types/src/cli/commands/trigger/create/queue.d.ts.map +1 -0
  55. package/dist/types/src/cli/commands/trigger/create/subscription.d.ts +15 -0
  56. package/dist/types/src/cli/commands/trigger/create/subscription.d.ts.map +1 -0
  57. package/dist/types/src/cli/commands/trigger/create/timer.d.ts +13 -0
  58. package/dist/types/src/cli/commands/trigger/create/timer.d.ts.map +1 -0
  59. package/dist/types/src/cli/commands/trigger/index.d.ts +57 -0
  60. package/dist/types/src/cli/commands/trigger/index.d.ts.map +1 -0
  61. package/dist/types/src/cli/commands/trigger/list.d.ts +7 -0
  62. package/dist/types/src/cli/commands/trigger/list.d.ts.map +1 -0
  63. package/dist/types/src/cli/commands/trigger/options.d.ts +11 -0
  64. package/dist/types/src/cli/commands/trigger/options.d.ts.map +1 -0
  65. package/dist/types/src/cli/commands/trigger/remove.d.ts +8 -0
  66. package/dist/types/src/cli/commands/trigger/remove.d.ts.map +1 -0
  67. package/dist/types/src/cli/commands/trigger/update/index.d.ts +28 -0
  68. package/dist/types/src/cli/commands/trigger/update/index.d.ts.map +1 -0
  69. package/dist/types/src/cli/commands/trigger/update/queue.d.ts +12 -0
  70. package/dist/types/src/cli/commands/trigger/update/queue.d.ts.map +1 -0
  71. package/dist/types/src/cli/commands/trigger/update/subscription.d.ts +13 -0
  72. package/dist/types/src/cli/commands/trigger/update/subscription.d.ts.map +1 -0
  73. package/dist/types/src/cli/commands/trigger/update/timer.d.ts +11 -0
  74. package/dist/types/src/cli/commands/trigger/update/timer.d.ts.map +1 -0
  75. package/dist/types/src/cli/commands/trigger/util.d.ts +46 -0
  76. package/dist/types/src/cli/commands/trigger/util.d.ts.map +1 -0
  77. package/dist/types/src/cli/index.d.ts +2 -0
  78. package/dist/types/src/cli/index.d.ts.map +1 -0
  79. package/dist/types/src/cli/plugin.d.ts +3 -0
  80. package/dist/types/src/cli/plugin.d.ts.map +1 -0
  81. package/dist/types/src/components/AutomationPanel/AutomationPanel.d.ts +3 -3
  82. package/dist/types/src/components/AutomationPanel/AutomationPanel.d.ts.map +1 -1
  83. package/dist/types/src/components/AutomationPanel/AutomationPanel.stories.d.ts +47 -4
  84. package/dist/types/src/components/AutomationPanel/AutomationPanel.stories.d.ts.map +1 -1
  85. package/dist/types/src/components/FunctionsPanel/FunctionsPanel.d.ts.map +1 -1
  86. package/dist/types/src/components/FunctionsRegistry/FunctionsRegistry.d.ts +8 -0
  87. package/dist/types/src/components/FunctionsRegistry/FunctionsRegistry.d.ts.map +1 -0
  88. package/dist/types/src/components/FunctionsRegistry/index.d.ts +4 -0
  89. package/dist/types/src/components/FunctionsRegistry/index.d.ts.map +1 -0
  90. package/dist/types/src/components/TriggerEditor/FunctionInputEditor.d.ts +12 -9
  91. package/dist/types/src/components/TriggerEditor/FunctionInputEditor.d.ts.map +1 -1
  92. package/dist/types/src/components/TriggerEditor/SpecSelector.d.ts +6 -3
  93. package/dist/types/src/components/TriggerEditor/SpecSelector.d.ts.map +1 -1
  94. package/dist/types/src/components/TriggerEditor/TriggerEditor.d.ts +11 -8
  95. package/dist/types/src/components/TriggerEditor/TriggerEditor.d.ts.map +1 -1
  96. package/dist/types/src/components/TriggerEditor/TriggerEditor.stories.d.ts +117 -4
  97. package/dist/types/src/components/TriggerEditor/TriggerEditor.stories.d.ts.map +1 -1
  98. package/dist/types/src/components/index.d.ts +2 -3
  99. package/dist/types/src/components/index.d.ts.map +1 -1
  100. package/dist/types/src/containers/AutomationSettings/AutomationSettings.d.ts +4 -0
  101. package/dist/types/src/containers/AutomationSettings/AutomationSettings.d.ts.map +1 -0
  102. package/dist/types/src/containers/AutomationSettings/index.d.ts +2 -0
  103. package/dist/types/src/containers/AutomationSettings/index.d.ts.map +1 -0
  104. package/dist/types/src/{components → containers/FunctionsContainer}/FunctionsContainer.d.ts +0 -1
  105. package/dist/types/src/containers/FunctionsContainer/FunctionsContainer.d.ts.map +1 -0
  106. package/dist/types/src/containers/FunctionsContainer/index.d.ts +2 -0
  107. package/dist/types/src/containers/FunctionsContainer/index.d.ts.map +1 -0
  108. package/dist/types/src/containers/TriggerSettings/TriggerSettings.d.ts +6 -0
  109. package/dist/types/src/containers/TriggerSettings/TriggerSettings.d.ts.map +1 -0
  110. package/dist/types/src/containers/TriggerSettings/index.d.ts +3 -0
  111. package/dist/types/src/containers/TriggerSettings/index.d.ts.map +1 -0
  112. package/dist/types/src/containers/index.d.ts +5 -0
  113. package/dist/types/src/containers/index.d.ts.map +1 -0
  114. package/dist/types/src/hooks/index.d.ts +5 -0
  115. package/dist/types/src/hooks/index.d.ts.map +1 -0
  116. package/dist/types/src/hooks/useComputeRuntime.d.ts +8 -0
  117. package/dist/types/src/hooks/useComputeRuntime.d.ts.map +1 -0
  118. package/dist/types/src/hooks/useComputeRuntimeCallback.d.ts +9 -0
  119. package/dist/types/src/hooks/useComputeRuntimeCallback.d.ts.map +1 -0
  120. package/dist/types/src/hooks/useComputeRuntimeService.d.ts +5 -0
  121. package/dist/types/src/hooks/useComputeRuntimeService.d.ts.map +1 -0
  122. package/dist/types/src/hooks/useTriggerRuntimeControls.d.ts +12 -0
  123. package/dist/types/src/hooks/useTriggerRuntimeControls.d.ts.map +1 -0
  124. package/dist/types/src/index.d.ts +2 -3
  125. package/dist/types/src/index.d.ts.map +1 -1
  126. package/dist/types/src/meta.d.ts +2 -3
  127. package/dist/types/src/meta.d.ts.map +1 -1
  128. package/dist/types/src/operations/create-trigger-from-template.d.ts +5 -0
  129. package/dist/types/src/operations/create-trigger-from-template.d.ts.map +1 -0
  130. package/dist/types/src/operations/definitions.d.ts +19 -0
  131. package/dist/types/src/operations/definitions.d.ts.map +1 -0
  132. package/dist/types/src/operations/index.d.ts +4 -0
  133. package/dist/types/src/operations/index.d.ts.map +1 -0
  134. package/dist/types/src/testing/test-functions.d.ts +204 -3
  135. package/dist/types/src/testing/test-functions.d.ts.map +1 -1
  136. package/dist/types/src/translations.d.ts +29 -25
  137. package/dist/types/src/translations.d.ts.map +1 -1
  138. package/dist/types/src/types/capabilities.d.ts +25 -0
  139. package/dist/types/src/types/capabilities.d.ts.map +1 -0
  140. package/dist/types/src/types/events.d.ts +5 -0
  141. package/dist/types/src/types/events.d.ts.map +1 -0
  142. package/dist/types/src/types/index.d.ts +4 -0
  143. package/dist/types/src/types/index.d.ts.map +1 -0
  144. package/dist/types/src/{types.d.ts → types/schema.d.ts} +13 -5
  145. package/dist/types/src/types/schema.d.ts.map +1 -0
  146. package/dist/types/tsconfig.tsbuildinfo +1 -1
  147. package/package.json +109 -44
  148. package/src/AutomationPlugin.tsx +22 -33
  149. package/src/capabilities/app-graph-builder.ts +55 -79
  150. package/src/capabilities/compute-runtime.ts +267 -0
  151. package/src/capabilities/index.ts +9 -4
  152. package/src/capabilities/node.ts +7 -0
  153. package/src/capabilities/operation-handler.ts +16 -0
  154. package/src/capabilities/react-surface.tsx +49 -46
  155. package/src/cli/commands/index.ts +5 -0
  156. package/src/cli/commands/trigger/create/index.ts +14 -0
  157. package/src/cli/commands/trigger/create/queue.ts +87 -0
  158. package/src/cli/commands/trigger/create/subscription.ts +126 -0
  159. package/src/cli/commands/trigger/create/timer.ts +91 -0
  160. package/src/cli/commands/trigger/index.ts +16 -0
  161. package/src/cli/commands/trigger/list.ts +68 -0
  162. package/src/cli/commands/trigger/options.ts +59 -0
  163. package/src/cli/commands/trigger/remove.ts +45 -0
  164. package/src/cli/commands/trigger/update/index.ts +14 -0
  165. package/src/cli/commands/trigger/update/queue.ts +195 -0
  166. package/src/cli/commands/trigger/update/subscription.ts +279 -0
  167. package/src/cli/commands/trigger/update/timer.ts +194 -0
  168. package/src/cli/commands/trigger/util.ts +409 -0
  169. package/src/cli/index.ts +5 -0
  170. package/src/cli/plugin.ts +23 -0
  171. package/src/components/AutomationPanel/AutomationPanel.stories.tsx +18 -17
  172. package/src/components/AutomationPanel/AutomationPanel.tsx +247 -94
  173. package/src/components/FunctionsPanel/FunctionsPanel.tsx +52 -32
  174. package/src/components/FunctionsRegistry/FunctionsRegistry.tsx +114 -0
  175. package/src/components/FunctionsRegistry/index.ts +8 -0
  176. package/src/components/TriggerEditor/FunctionInputEditor.tsx +42 -35
  177. package/src/components/TriggerEditor/SpecSelector.tsx +34 -22
  178. package/src/components/TriggerEditor/TriggerEditor.stories.tsx +124 -35
  179. package/src/components/TriggerEditor/TriggerEditor.tsx +110 -48
  180. package/src/components/index.ts +1 -2
  181. package/src/containers/AutomationSettings/AutomationSettings.tsx +28 -0
  182. package/src/containers/AutomationSettings/index.ts +5 -0
  183. package/src/containers/FunctionsContainer/FunctionsContainer.tsx +34 -0
  184. package/src/containers/FunctionsContainer/index.ts +5 -0
  185. package/src/containers/TriggerSettings/TriggerSettings.tsx +26 -0
  186. package/src/containers/TriggerSettings/index.ts +6 -0
  187. package/src/containers/index.ts +9 -0
  188. package/src/hooks/index.ts +9 -0
  189. package/src/hooks/useComputeRuntime.ts +21 -0
  190. package/src/hooks/useComputeRuntimeCallback.ts +32 -0
  191. package/src/hooks/useComputeRuntimeService.ts +25 -0
  192. package/src/hooks/useTriggerRuntimeControls.ts +67 -0
  193. package/src/index.ts +2 -4
  194. package/src/meta.ts +9 -8
  195. package/src/operations/create-trigger-from-template.ts +72 -0
  196. package/src/operations/definitions.ts +28 -0
  197. package/src/operations/index.ts +9 -0
  198. package/src/testing/test-functions.ts +10 -7
  199. package/src/translations.ts +37 -29
  200. package/src/types/capabilities.ts +47 -0
  201. package/src/types/events.ts +11 -0
  202. package/src/types/index.ts +7 -0
  203. package/src/{types.ts → types/schema.ts} +6 -8
  204. package/dist/lib/browser/AutomationContainer-VZNV2ZQF.mjs +0 -38
  205. package/dist/lib/browser/AutomationContainer-VZNV2ZQF.mjs.map +0 -7
  206. package/dist/lib/browser/AutomationPanel-ZWA6GOFY.mjs +0 -11
  207. package/dist/lib/browser/FunctionsContainer-IOB333TX.mjs +0 -39
  208. package/dist/lib/browser/FunctionsContainer-IOB333TX.mjs.map +0 -7
  209. package/dist/lib/browser/FunctionsPanel-56ZKRVM5.mjs +0 -10
  210. package/dist/lib/browser/app-graph-builder-ZTAUTFI4.mjs +0 -80
  211. package/dist/lib/browser/app-graph-builder-ZTAUTFI4.mjs.map +0 -7
  212. package/dist/lib/browser/chunk-ECSTS2UI.mjs +0 -14
  213. package/dist/lib/browser/chunk-ECSTS2UI.mjs.map +0 -7
  214. package/dist/lib/browser/chunk-ERTIGJYE.mjs +0 -147
  215. package/dist/lib/browser/chunk-ERTIGJYE.mjs.map +0 -7
  216. package/dist/lib/browser/chunk-FSJZXTS2.mjs +0 -230
  217. package/dist/lib/browser/chunk-FSJZXTS2.mjs.map +0 -7
  218. package/dist/lib/browser/chunk-GW5U2DGT.mjs +0 -15
  219. package/dist/lib/browser/chunk-GW5U2DGT.mjs.map +0 -7
  220. package/dist/lib/browser/chunk-LYJVTIVD.mjs +0 -94
  221. package/dist/lib/browser/chunk-LYJVTIVD.mjs.map +0 -7
  222. package/dist/lib/browser/chunk-S2LE7SYB.mjs +0 -39
  223. package/dist/lib/browser/chunk-S2LE7SYB.mjs.map +0 -7
  224. package/dist/lib/browser/intent-resolver-YLRSMLH4.mjs +0 -76
  225. package/dist/lib/browser/intent-resolver-YLRSMLH4.mjs.map +0 -7
  226. package/dist/lib/browser/react-surface-4DFSM7OX.mjs +0 -64
  227. package/dist/lib/browser/react-surface-4DFSM7OX.mjs.map +0 -7
  228. package/dist/lib/browser/types.mjs +0 -8
  229. package/dist/lib/node-esm/AutomationContainer-WMIH3F4V.mjs +0 -39
  230. package/dist/lib/node-esm/AutomationContainer-WMIH3F4V.mjs.map +0 -7
  231. package/dist/lib/node-esm/AutomationPanel-YYUMSK2W.mjs +0 -12
  232. package/dist/lib/node-esm/FunctionsContainer-DJWB6WFH.mjs +0 -40
  233. package/dist/lib/node-esm/FunctionsContainer-DJWB6WFH.mjs.map +0 -7
  234. package/dist/lib/node-esm/FunctionsPanel-KGIOZSPZ.mjs +0 -11
  235. package/dist/lib/node-esm/FunctionsPanel-KGIOZSPZ.mjs.map +0 -7
  236. package/dist/lib/node-esm/app-graph-builder-3FP63ZSG.mjs +0 -81
  237. package/dist/lib/node-esm/app-graph-builder-3FP63ZSG.mjs.map +0 -7
  238. package/dist/lib/node-esm/chunk-AZH66CED.mjs +0 -231
  239. package/dist/lib/node-esm/chunk-AZH66CED.mjs.map +0 -7
  240. package/dist/lib/node-esm/chunk-HIMYPGHF.mjs +0 -148
  241. package/dist/lib/node-esm/chunk-HIMYPGHF.mjs.map +0 -7
  242. package/dist/lib/node-esm/chunk-NK5N3QKD.mjs +0 -17
  243. package/dist/lib/node-esm/chunk-NK5N3QKD.mjs.map +0 -7
  244. package/dist/lib/node-esm/chunk-SGZPTJ47.mjs +0 -16
  245. package/dist/lib/node-esm/chunk-SGZPTJ47.mjs.map +0 -7
  246. package/dist/lib/node-esm/chunk-UKATFY3R.mjs +0 -40
  247. package/dist/lib/node-esm/chunk-UKATFY3R.mjs.map +0 -7
  248. package/dist/lib/node-esm/chunk-ZGPUV5VS.mjs +0 -95
  249. package/dist/lib/node-esm/chunk-ZGPUV5VS.mjs.map +0 -7
  250. package/dist/lib/node-esm/intent-resolver-LU7EYWEO.mjs +0 -77
  251. package/dist/lib/node-esm/intent-resolver-LU7EYWEO.mjs.map +0 -7
  252. package/dist/lib/node-esm/react-surface-3PNW7NDW.mjs +0 -65
  253. package/dist/lib/node-esm/react-surface-3PNW7NDW.mjs.map +0 -7
  254. package/dist/lib/node-esm/types.mjs +0 -9
  255. package/dist/lib/node-esm/types.mjs.map +0 -7
  256. package/dist/types/src/capabilities/intent-resolver.d.ts +0 -4
  257. package/dist/types/src/capabilities/intent-resolver.d.ts.map +0 -1
  258. package/dist/types/src/components/AutomationContainer.d.ts +0 -5
  259. package/dist/types/src/components/AutomationContainer.d.ts.map +0 -1
  260. package/dist/types/src/components/FunctionsContainer.d.ts.map +0 -1
  261. package/dist/types/src/types.d.ts.map +0 -1
  262. package/src/capabilities/intent-resolver.ts +0 -72
  263. package/src/components/AutomationContainer.tsx +0 -30
  264. package/src/components/FunctionsContainer.tsx +0 -31
  265. /package/dist/lib/browser/{AutomationPanel-ZWA6GOFY.mjs.map → chunk-J5LGTIGS.mjs.map} +0 -0
  266. /package/dist/lib/browser/{FunctionsPanel-56ZKRVM5.mjs.map → types/index.mjs.map} +0 -0
  267. /package/dist/lib/{browser/types.mjs.map → node-esm/chunk-HSLMI22Q.mjs.map} +0 -0
  268. /package/dist/lib/node-esm/{AutomationPanel-YYUMSK2W.mjs.map → types/index.mjs.map} +0 -0
@@ -0,0 +1,409 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import * as Prompt from '@effect/cli/Prompt';
6
+ import * as Ansi from '@effect/printer-ansi/Ansi';
7
+ import * as Console from 'effect/Console';
8
+ import * as Effect from 'effect/Effect';
9
+ import * as Match from 'effect/Match';
10
+ import * as Option from 'effect/Option';
11
+ import type * as Schema from 'effect/Schema';
12
+ import * as SchemaAST from 'effect/SchemaAST';
13
+
14
+ import { FormBuilder } from '@dxos/cli-util';
15
+ import { Annotation, Database, Entity, Feed, Filter, Obj, Ref, Type } from '@dxos/echo';
16
+ import { getProperties } from '@dxos/effect';
17
+ import { Trigger } from '@dxos/functions';
18
+ import { Operation } from '@dxos/operation';
19
+ import { FeedAnnotation } from '@dxos/schema';
20
+
21
+ export type TriggerRemoteStatus = 'available' | 'not available' | 'n/a';
22
+
23
+ /**
24
+ * Determines the remote status of a trigger.
25
+ * Only timer/cron triggers can be checked for remote availability.
26
+ */
27
+ export const getTriggerRemoteStatus = (trigger: Trigger.Trigger, remoteCronIds: string[]): TriggerRemoteStatus => {
28
+ if (trigger.spec?.kind !== 'timer') {
29
+ return 'n/a';
30
+ }
31
+ return remoteCronIds.includes(trigger.id) ? 'available' : 'not available';
32
+ };
33
+
34
+ /**
35
+ * Pretty prints a trigger with ANSI colors.
36
+ */
37
+ export const printTrigger = Effect.fn(function* (trigger: Trigger.Trigger, remoteStatus?: TriggerRemoteStatus) {
38
+ const fn = trigger.function && (yield* Database.load(trigger.function));
39
+
40
+ return FormBuilder.make({
41
+ title: trigger.id,
42
+ }).pipe(
43
+ FormBuilder.set(
44
+ 'status',
45
+ trigger.enabled ? 'enabled' : 'disabled',
46
+ trigger.enabled ? Ansi.green : Ansi.blackBright,
47
+ ),
48
+ FormBuilder.option('kind', Option.fromNullable(trigger.spec?.kind)),
49
+ FormBuilder.option(
50
+ 'remote',
51
+ Option.fromNullable(remoteStatus),
52
+ Match.type<TriggerRemoteStatus>().pipe(
53
+ Match.withReturnType<Ansi.Ansi>(),
54
+ Match.when('available', () => Ansi.green),
55
+ Match.when('not available', () => Ansi.yellow),
56
+ Match.when('n/a', () => Ansi.blackBright),
57
+ Match.exhaustive,
58
+ ),
59
+ ),
60
+ FormBuilder.when(
61
+ fn,
62
+ FormBuilder.nest(
63
+ 'function',
64
+ FormBuilder.make().pipe(
65
+ FormBuilder.set('key', (fn as Operation.PersistentOperation).key),
66
+ FormBuilder.set('dxn', Obj.getDXN(fn as Obj.Unknown).toString()),
67
+ ),
68
+ ),
69
+ ),
70
+ FormBuilder.nestedOption('spec', Option.fromNullable(trigger.spec).pipe(Option.map(printSpec))),
71
+ FormBuilder.build,
72
+ );
73
+ });
74
+
75
+ const printSpec = <T extends Trigger.Spec>(spec: T): FormBuilder.FormBuilder => {
76
+ switch (spec.kind) {
77
+ case 'timer':
78
+ return printTimer(spec);
79
+ case 'subscription':
80
+ return printSubscription(spec);
81
+ case 'webhook':
82
+ return printWebhook(spec);
83
+ case 'queue':
84
+ return printQueue(spec);
85
+ default:
86
+ return FormBuilder.make({}).pipe(FormBuilder.set('unknown', 'Unknown spec type'));
87
+ }
88
+ };
89
+
90
+ const printTimer = (spec: Trigger.TimerSpec) => FormBuilder.make({}).pipe(FormBuilder.set('cron', spec.cron));
91
+
92
+ const printSubscription = (spec: Trigger.SubscriptionSpec) =>
93
+ FormBuilder.make({}).pipe(FormBuilder.set('query', spec.query?.raw ?? '[Query AST]'));
94
+
95
+ const printWebhook = (spec: Trigger.WebhookSpec) =>
96
+ FormBuilder.make({}).pipe(FormBuilder.set('method', spec.method), FormBuilder.set('port', spec.port));
97
+
98
+ const printQueue = (spec: Trigger.QueueSpec) => FormBuilder.make({}).pipe(FormBuilder.set('queue', spec.queue));
99
+
100
+ /**
101
+ * Prompts for input values based on an Effect schema.
102
+ * First shows a multi-select to choose which properties to specify,
103
+ * then prompts for values of the selected properties.
104
+ * Required properties are automatically included and cannot be unselected.
105
+ * @param schema - The Effect schema to prompt for
106
+ * @param defaults - Optional default values to use as initial values and pre-select optional properties
107
+ */
108
+ export const promptForSchemaInput = Effect.fn(function* (
109
+ schema: Schema.Schema.AnyNoContext | undefined,
110
+ defaults?: Record<string, any> | undefined,
111
+ ) {
112
+ if (!schema) {
113
+ return {};
114
+ }
115
+
116
+ const ast = schema.ast;
117
+
118
+ // Check if it's a struct/object type
119
+ if (!SchemaAST.isTypeLiteral(ast)) {
120
+ return {};
121
+ }
122
+
123
+ const properties = getProperties(ast);
124
+ if (properties.length === 0) {
125
+ return {};
126
+ }
127
+
128
+ // Separate required and optional properties
129
+ const requiredProperties: typeof properties = [];
130
+ const optionalProperties: typeof properties = [];
131
+
132
+ for (const prop of properties) {
133
+ if (prop.isOptional) {
134
+ optionalProperties.push(prop);
135
+ } else {
136
+ requiredProperties.push(prop);
137
+ }
138
+ }
139
+
140
+ // Build property info
141
+ const propertyInfo = properties.map((prop) => {
142
+ const key = prop.name.toString();
143
+ return {
144
+ prop,
145
+ key,
146
+ isRequired: !prop.isOptional,
147
+ };
148
+ });
149
+
150
+ // Multi-select: show all properties and let user select which optional ones to include
151
+ const selectedKeys = new Set<string>();
152
+
153
+ // Required properties are automatically selected
154
+ for (const info of propertyInfo) {
155
+ if (info.isRequired) {
156
+ selectedKeys.add(info.key);
157
+ }
158
+ }
159
+
160
+ // Show required properties that will be automatically included
161
+ if (requiredProperties.length > 0) {
162
+ const requiredNames = requiredProperties.map((p) => {
163
+ const info = propertyInfo.find((i) => i.prop === p);
164
+ return info?.key ?? p.name.toString();
165
+ });
166
+ yield* Console.log(`Required properties (will be included): ${requiredNames.join(', ')}`);
167
+ }
168
+
169
+ // For optional properties, use multi-select to choose which ones to include
170
+ if (optionalProperties.length > 0) {
171
+ const optionalInfo = propertyInfo.filter((info) => !info.isRequired);
172
+ const choices = optionalInfo.map((info) => {
173
+ const hasDefault = defaults?.[info.key] !== undefined;
174
+ const defaultText = hasDefault ? ` (current: ${JSON.stringify(defaults[info.key])})` : '';
175
+ return {
176
+ title: `${info.key}${defaultText}`,
177
+ value: info.key,
178
+ description: hasDefault ? 'Has default value' : undefined,
179
+ };
180
+ });
181
+
182
+ const selected = yield* Prompt.multiSelect({
183
+ message: 'Select optional properties to include:',
184
+ choices,
185
+ });
186
+
187
+ // Add selected optional properties to selectedKeys
188
+ for (const key of selected) {
189
+ selectedKeys.add(String(key));
190
+ }
191
+ }
192
+
193
+ // If no properties selected (shouldn't happen if there are required ones), return empty
194
+ if (selectedKeys.size === 0) {
195
+ return {};
196
+ }
197
+
198
+ // Prompt for values of selected properties
199
+ const inputObj: Record<string, any> = {};
200
+
201
+ for (const info of propertyInfo) {
202
+ if (!selectedKeys.has(info.key)) {
203
+ continue;
204
+ }
205
+
206
+ const key = info.key;
207
+ const propType = info.prop.type;
208
+ const schemaDefault = Option.getOrUndefined(SchemaAST.getDefaultAnnotation(propType));
209
+ const defaultValue = defaults?.[key] ?? schemaDefault;
210
+
211
+ if (SchemaAST.isBooleanKeyword(propType)) {
212
+ const initialValue =
213
+ typeof defaultValue === 'boolean' ? defaultValue : typeof schemaDefault === 'boolean' ? schemaDefault : false;
214
+ const value = yield* Prompt.confirm({
215
+ message: `${info.key}${defaults?.[key] !== undefined ? ` (current: ${defaults[key]})` : ''}:`,
216
+ initial: initialValue,
217
+ });
218
+ inputObj[key] = value;
219
+ } else if (SchemaAST.isNumberKeyword(propType)) {
220
+ const currentValue = typeof defaultValue === 'number' ? String(defaultValue) : '';
221
+ const valueStr = yield* Prompt.text({
222
+ message: `${info.key}${currentValue ? ` (current: ${currentValue}, press Enter to keep)` : ''}:`,
223
+ }).pipe(Prompt.run);
224
+ inputObj[key] = valueStr === '' && defaultValue !== undefined ? defaultValue : parseFloat(valueStr) || 0;
225
+ } else if (SchemaAST.isStringKeyword(propType)) {
226
+ const currentValue = typeof defaultValue === 'string' ? defaultValue : '';
227
+ const valueStr = yield* Prompt.text({
228
+ message: `${info.key}${currentValue ? ` (current: ${currentValue}, press Enter to keep)` : ''}:`,
229
+ }).pipe(Prompt.run);
230
+ inputObj[key] = valueStr === '' && defaultValue !== undefined ? defaultValue : valueStr;
231
+ } else if (Ref.isRefType(propType)) {
232
+ const isDefaultTemplate =
233
+ typeof defaultValue === 'string' && defaultValue.startsWith('{{') && defaultValue.endsWith('}}');
234
+ const useTemplate = yield* Prompt.confirm({
235
+ message: `Use a template to specify ${info.key}?${isDefaultTemplate ? ' (current: template)' : ''}`,
236
+ initial: isDefaultTemplate,
237
+ });
238
+ if (useTemplate) {
239
+ const currentValue = typeof defaultValue === 'string' ? defaultValue : '';
240
+ const templateStr = yield* Prompt.text({
241
+ message: `${info.key} template${currentValue ? ` (current: ${currentValue}, press Enter to keep)` : ''}:`,
242
+ }).pipe(Prompt.run);
243
+ inputObj[key] = templateStr === '' && defaultValue !== undefined ? defaultValue : templateStr;
244
+ } else {
245
+ const annotation = Annotation.ReferenceAnnotation.getFromAst(propType).pipe(Option.getOrThrow);
246
+ const objects = yield* Database.runQuery(Filter.typename(annotation.typename));
247
+ if (objects.length === 0) {
248
+ inputObj[key] = undefined;
249
+ } else {
250
+ const selected = yield* Prompt.select({
251
+ message: `Select ${info.key}:`,
252
+ choices: objects.map((obj: Entity.Any) => ({
253
+ title: Entity.getLabel(obj) ?? obj.id,
254
+ value: Ref.make(obj),
255
+ description: Entity.getDescription(obj),
256
+ })),
257
+ });
258
+ inputObj[key] = selected;
259
+ }
260
+ }
261
+ } else {
262
+ // For other types, prompt as string and let validation handle it
263
+ const currentValue = defaultValue !== undefined ? String(defaultValue) : '';
264
+ const valueStr = yield* Prompt.text({
265
+ message: `${info.key}${currentValue ? ` (current: ${currentValue}, press Enter to keep)` : ''}:`,
266
+ }).pipe(Prompt.run);
267
+ inputObj[key] = valueStr === '' && defaultValue !== undefined ? defaultValue : valueStr;
268
+ }
269
+ }
270
+
271
+ return inputObj;
272
+ });
273
+
274
+ /**
275
+ * Selects a function interactively from available functions in the database.
276
+ * Queries the database for functions and prompts the user to select one.
277
+ */
278
+ export const selectFunction = Effect.fn(function* () {
279
+ const functions = yield* Database.runQuery(Filter.type(Operation.PersistentOperation));
280
+
281
+ if (functions.length === 0) {
282
+ return yield* Effect.fail(new Error('No functions available'));
283
+ }
284
+
285
+ const selected = yield* Prompt.select({
286
+ message: 'Select a function:',
287
+ choices: functions.map((fn: Operation.PersistentOperation) => ({
288
+ title: fn.name ?? fn.id,
289
+ value: fn.id,
290
+ description: fn.description,
291
+ })),
292
+ });
293
+
294
+ return String(selected);
295
+ });
296
+
297
+ /**
298
+ * Selects a trigger interactively from available triggers.
299
+ * If kind is provided, filters triggers by that kind.
300
+ * Queries the database for triggers and prompts the user to select one.
301
+ */
302
+ export const selectTrigger = Effect.fn(function* (kind?: Trigger.Kind) {
303
+ const triggers = yield* Database.runQuery(Filter.type(Trigger.Trigger));
304
+ const filteredTriggers = kind ? triggers.filter((trigger) => trigger.spec?.kind === kind) : triggers;
305
+
306
+ if (filteredTriggers.length === 0) {
307
+ return yield* Effect.fail(new Error(kind ? `No ${kind} triggers available` : 'No triggers available'));
308
+ }
309
+
310
+ const choices = yield* Effect.all(
311
+ filteredTriggers.map((trigger) =>
312
+ Effect.gen(function* () {
313
+ const fn = trigger.function ? yield* Database.load(trigger.function) : undefined;
314
+ const functionName =
315
+ fn && Obj.instanceOf(Operation.PersistentOperation, fn) ? (fn.name ?? fn.key ?? fn.id) : undefined;
316
+ const title = functionName ?? trigger.id;
317
+ const description = `${trigger.enabled ? 'enabled' : 'disabled'} - ${trigger.spec?.kind ?? 'unknown'}`;
318
+
319
+ return {
320
+ title,
321
+ value: trigger.id,
322
+ description,
323
+ };
324
+ }),
325
+ ),
326
+ );
327
+
328
+ const selected = yield* Prompt.select({
329
+ message: kind ? `Select a ${kind} trigger:` : 'Select a trigger:',
330
+ choices,
331
+ });
332
+
333
+ return String(selected);
334
+ });
335
+
336
+ /**
337
+ * Selects a queue interactively from available queues in the database.
338
+ * Queries schemas with FeedAnnotation, then queries objects of those types,
339
+ * and extracts queue DXNs from the objects' feed properties.
340
+ */
341
+ export const selectQueue = Effect.fn(function* () {
342
+ // Query schema registry for schemas with FeedAnnotation.
343
+ const schemas = yield* Database.runSchemaQuery({ location: ['database', 'runtime'] });
344
+
345
+ // Filter schemas that have FeedAnnotation.
346
+ const feedSchemas = schemas.filter((schema) => {
347
+ const annotation = FeedAnnotation.get(schema);
348
+ return Option.isSome(annotation) && annotation.value === true;
349
+ });
350
+
351
+ if (feedSchemas.length === 0) {
352
+ return yield* Effect.fail(new Error('No schemas with Feed annotation found'));
353
+ }
354
+
355
+ // Collect all objects with queues.
356
+ const queueChoices: Array<{ title: string; value: string; description?: string }> = [];
357
+
358
+ // Process each feed schema, loading the Feed object to extract queue DXN.
359
+ for (const schema of feedSchemas) {
360
+ yield* Effect.gen(function* () {
361
+ const typename = Type.getTypename(schema);
362
+ const objects = yield* Database.runQuery(Filter.type(typename));
363
+
364
+ for (const obj of objects) {
365
+ // Access the feed property (which is a Ref<Feed>).
366
+ const feedRef = (obj as any).feed as Ref.Ref<any> | undefined;
367
+ if (!feedRef) {
368
+ continue;
369
+ }
370
+
371
+ const feedObj = yield* Effect.promise(() => feedRef.tryLoad());
372
+ if (!feedObj || !Obj.instanceOf(Feed.Feed, feedObj)) {
373
+ continue;
374
+ }
375
+
376
+ const queueDxn = Feed.getQueueDxn(feedObj);
377
+ if (!queueDxn) {
378
+ continue;
379
+ }
380
+
381
+ const label = Obj.getLabel(obj) ?? obj.id;
382
+ const description = Obj.getTypename(obj);
383
+
384
+ queueChoices.push({
385
+ title: label,
386
+ value: queueDxn.toString(),
387
+ description,
388
+ });
389
+ }
390
+ }).pipe(Effect.catchAll(() => Effect.void));
391
+ }
392
+
393
+ if (queueChoices.length === 0) {
394
+ return yield* Effect.fail(new Error('No objects with queue properties found'));
395
+ }
396
+
397
+ const selected = yield* Prompt.select({
398
+ message: 'Select a queue:',
399
+ choices: queueChoices,
400
+ });
401
+
402
+ return String(selected);
403
+ });
404
+
405
+ /**
406
+ * Pretty prints trigger removal result with ANSI colors.
407
+ */
408
+ export const printTriggerRemoved = (id: string) =>
409
+ FormBuilder.make({ title: 'Trigger removed' }).pipe(FormBuilder.set('id', id), FormBuilder.build);
@@ -0,0 +1,5 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ export * from './plugin';
@@ -0,0 +1,23 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { Plugin } from '@dxos/app-framework';
6
+ import { AppPlugin } from '@dxos/app-toolkit';
7
+ import { ClientEvents } from '@dxos/plugin-client/types';
8
+
9
+ import { ComputeRuntime } from '#capabilities';
10
+ import { meta } from '#meta';
11
+ import { AutomationEvents } from '#types';
12
+
13
+ import { trigger } from './commands';
14
+
15
+ export const AutomationPlugin = Plugin.define(meta).pipe(
16
+ AppPlugin.addCommandModule({ commands: [trigger] }),
17
+ Plugin.addModule({
18
+ activatesOn: ClientEvents.ClientReady,
19
+ firesAfterActivation: [AutomationEvents.ComputeRuntimeReady],
20
+ activate: ComputeRuntime,
21
+ }),
22
+ Plugin.make,
23
+ );
@@ -2,20 +2,20 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import '@dxos-theme';
6
-
7
- import { type Meta } from '@storybook/react-vite';
5
+ import { type Meta, type StoryObj } from '@storybook/react-vite';
8
6
  import React from 'react';
9
7
 
10
8
  import { Obj } from '@dxos/echo';
11
- import { FunctionType, FunctionTrigger } from '@dxos/functions';
9
+ import { Trigger } from '@dxos/functions';
10
+ import { Operation } from '@dxos/operation';
12
11
  import { useSpaces } from '@dxos/react-client/echo';
13
12
  import { withClientProvider } from '@dxos/react-client/testing';
14
- import { withLayout, withTheme } from '@dxos/storybook-utils';
13
+ import { withTheme } from '@dxos/react-ui/testing';
14
+
15
+ import { functions } from '#testing';
15
16
 
16
- import { AutomationPanel } from './AutomationPanel';
17
- import { functions } from '../../testing';
18
17
  import { translations } from '../../translations';
18
+ import { AutomationPanel } from './AutomationPanel';
19
19
 
20
20
  const DefaultStory = () => {
21
21
  const spaces = useSpaces();
@@ -28,30 +28,31 @@ const DefaultStory = () => {
28
28
  );
29
29
  };
30
30
 
31
- const meta: Meta = {
32
- title: 'plugins/plugin-automation/AutomationPanel',
33
- component: AutomationPanel,
31
+ const meta = {
32
+ title: 'plugins/plugin-automation/components/AutomationPanel',
33
+ component: AutomationPanel as any,
34
34
  render: DefaultStory,
35
35
  decorators: [
36
+ withTheme(),
36
37
  withClientProvider({
37
38
  createIdentity: true,
38
39
  createSpace: true,
39
- types: [FunctionType, FunctionTrigger],
40
- onSpaceCreated: ({ space }) => {
40
+ types: [Operation.PersistentOperation, Trigger.Trigger],
41
+ onCreateSpace: ({ space }) => {
41
42
  for (const fn of functions) {
42
- space.db.add(Obj.make(FunctionType, fn));
43
+ space.db.add(Obj.make(Operation.PersistentOperation, { ...fn, version: fn.version ?? '0.1.0' }));
43
44
  }
44
45
  },
45
46
  }),
46
- withLayout(),
47
- withTheme,
48
47
  ],
49
48
  parameters: {
50
49
  layout: 'centered',
51
50
  translations,
52
51
  },
53
- };
52
+ } satisfies Meta<typeof DefaultStory>;
54
53
 
55
54
  export default meta;
56
55
 
57
- export const Default = {};
56
+ type Story = StoryObj<typeof meta>;
57
+
58
+ export const Default: Story = {};