@antelopejs/dms-automation 0.7.0 → 0.9.0

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 (275) hide show
  1. package/README.md +33 -22
  2. package/dist/cluster/bus.js +8 -6
  3. package/dist/cluster/bus.js.map +1 -1
  4. package/dist/cluster/leader.js.map +1 -1
  5. package/dist/data/procedures-query.d.ts +19 -0
  6. package/dist/data/procedures-query.js +105 -0
  7. package/dist/data/procedures-query.js.map +1 -0
  8. package/dist/data/procedures-table.d.ts +5 -20
  9. package/dist/data/procedures-table.js +10 -106
  10. package/dist/data/procedures-table.js.map +1 -1
  11. package/dist/data/runs-table.d.ts +3 -3
  12. package/dist/data/runs-table.js.map +1 -1
  13. package/dist/db/models/automation_template.model.d.ts +13 -13
  14. package/dist/db/models/automation_template.model.js +13 -14
  15. package/dist/db/models/automation_template.model.js.map +1 -1
  16. package/dist/db/models/procedure.model.d.ts +7 -5
  17. package/dist/db/models/procedure_run.model.d.ts +9 -6
  18. package/dist/db/models/procedure_run.model.js +8 -8
  19. package/dist/db/models/procedure_run.model.js.map +1 -1
  20. package/dist/db/models/stats.model.js.map +1 -1
  21. package/dist/db/models/type_switch.model.d.ts +7 -5
  22. package/dist/db/tables/procedure_run.table.d.ts +2 -1
  23. package/dist/db/tables/procedure_run.table.js.map +1 -1
  24. package/dist/implementations/dms-automation/index.d.ts +2 -2
  25. package/dist/implementations/dms-automation/index.js.map +1 -1
  26. package/dist/index.js.map +1 -1
  27. package/dist/pages/category.js.map +1 -1
  28. package/dist/pages/index.js.map +1 -1
  29. package/dist/pages/overview.js.map +1 -1
  30. package/dist/pages/procedures.js.map +1 -1
  31. package/dist/pages/runs.js.map +1 -1
  32. package/dist/pages/shared.js +1 -1
  33. package/dist/pages/shared.js.map +1 -1
  34. package/dist/realtime.d.ts +2 -1
  35. package/dist/realtime.js.map +1 -1
  36. package/dist/routes/action-types.d.ts +3 -2
  37. package/dist/routes/action-types.js.map +1 -1
  38. package/dist/routes/data-node-types.d.ts +1 -1
  39. package/dist/routes/deleteConfirm.js +4 -3
  40. package/dist/routes/deleteConfirm.js.map +1 -1
  41. package/dist/routes/graphSchema.d.ts +2 -1
  42. package/dist/routes/graphSchema.js +13 -10
  43. package/dist/routes/graphSchema.js.map +1 -1
  44. package/dist/routes/library.d.ts +12 -1
  45. package/dist/routes/library.js +38 -34
  46. package/dist/routes/library.js.map +1 -1
  47. package/dist/routes/procedureChecks.js +5 -5
  48. package/dist/routes/procedureChecks.js.map +1 -1
  49. package/dist/routes/procedureRuns.d.ts +3 -3
  50. package/dist/routes/procedureRuns.js +1 -1
  51. package/dist/routes/procedureRuns.js.map +1 -1
  52. package/dist/routes/procedureSchemas.d.ts +7 -6
  53. package/dist/routes/procedureSchemas.js +4 -2
  54. package/dist/routes/procedureSchemas.js.map +1 -1
  55. package/dist/routes/procedures.d.ts +15 -14
  56. package/dist/routes/procedures.js +2 -1
  57. package/dist/routes/procedures.js.map +1 -1
  58. package/dist/routes/requests.d.ts +12 -6
  59. package/dist/routes/requests.js +2 -1
  60. package/dist/routes/requests.js.map +1 -1
  61. package/dist/routes/runs.d.ts +9 -8
  62. package/dist/routes/runs.js +5 -3
  63. package/dist/routes/runs.js.map +1 -1
  64. package/dist/routes/stats.js.map +1 -1
  65. package/dist/routes/templates.d.ts +5 -4
  66. package/dist/routes/templates.js +2 -1
  67. package/dist/routes/templates.js.map +1 -1
  68. package/dist/routes/trigger-types.d.ts +3 -2
  69. package/dist/routes/trigger-types.js.map +1 -1
  70. package/dist/routes/typeConfigShared.d.ts +2 -1
  71. package/dist/routes/typeConfigShared.js.map +1 -1
  72. package/dist/routes/zodJson.d.ts +3 -0
  73. package/dist/routes/zodJson.js +21 -0
  74. package/dist/routes/zodJson.js.map +1 -0
  75. package/dist/runtime/armErrors.d.ts +0 -1
  76. package/dist/runtime/armErrors.js +5 -12
  77. package/dist/runtime/armErrors.js.map +1 -1
  78. package/dist/runtime/boundRunLog.d.ts +7 -5
  79. package/dist/runtime/boundRunLog.js +24 -20
  80. package/dist/runtime/boundRunLog.js.map +1 -1
  81. package/dist/runtime/builtins/actions/http.d.ts +7 -3
  82. package/dist/runtime/builtins/actions/http.js +33 -22
  83. package/dist/runtime/builtins/actions/http.js.map +1 -1
  84. package/dist/runtime/builtins/actions/log.d.ts +5 -4
  85. package/dist/runtime/builtins/actions/log.js.map +1 -1
  86. package/dist/runtime/builtins/data/boolean.d.ts +2 -1
  87. package/dist/runtime/builtins/data/boolean.js +4 -5
  88. package/dist/runtime/builtins/data/boolean.js.map +1 -1
  89. package/dist/runtime/builtins/data/compare.js +8 -10
  90. package/dist/runtime/builtins/data/compare.js.map +1 -1
  91. package/dist/runtime/builtins/data/constant.js +1 -1
  92. package/dist/runtime/builtins/data/constant.js.map +1 -1
  93. package/dist/runtime/builtins/data/json.js +4 -5
  94. package/dist/runtime/builtins/data/json.js.map +1 -1
  95. package/dist/runtime/builtins/data/math.js +4 -4
  96. package/dist/runtime/builtins/data/math.js.map +1 -1
  97. package/dist/runtime/builtins/data/object.js +27 -27
  98. package/dist/runtime/builtins/data/object.js.map +1 -1
  99. package/dist/runtime/builtins/data/string.js +13 -18
  100. package/dist/runtime/builtins/data/string.js.map +1 -1
  101. package/dist/runtime/builtins/nodes/action.js +16 -5
  102. package/dist/runtime/builtins/nodes/action.js.map +1 -1
  103. package/dist/runtime/builtins/nodes/data.js +2 -2
  104. package/dist/runtime/builtins/nodes/data.js.map +1 -1
  105. package/dist/runtime/builtins/nodes/delay.js +2 -2
  106. package/dist/runtime/builtins/nodes/delay.js.map +1 -1
  107. package/dist/runtime/builtins/nodes/forRange.js +2 -2
  108. package/dist/runtime/builtins/nodes/forRange.js.map +1 -1
  109. package/dist/runtime/builtins/nodes/foreach.js +2 -2
  110. package/dist/runtime/builtins/nodes/foreach.js.map +1 -1
  111. package/dist/runtime/builtins/nodes/groupInput.js +2 -2
  112. package/dist/runtime/builtins/nodes/groupInput.js.map +1 -1
  113. package/dist/runtime/builtins/nodes/groupOutput.js +2 -2
  114. package/dist/runtime/builtins/nodes/groupOutput.js.map +1 -1
  115. package/dist/runtime/builtins/nodes/if.js +2 -2
  116. package/dist/runtime/builtins/nodes/if.js.map +1 -1
  117. package/dist/runtime/builtins/nodes/parallel.js +2 -2
  118. package/dist/runtime/builtins/nodes/parallel.js.map +1 -1
  119. package/dist/runtime/builtins/nodes/retry.js +13 -5
  120. package/dist/runtime/builtins/nodes/retry.js.map +1 -1
  121. package/dist/runtime/builtins/nodes/setVariable.js +2 -2
  122. package/dist/runtime/builtins/nodes/setVariable.js.map +1 -1
  123. package/dist/runtime/builtins/nodes/switch.js +8 -3
  124. package/dist/runtime/builtins/nodes/switch.js.map +1 -1
  125. package/dist/runtime/builtins/nodes/trigger.js +2 -2
  126. package/dist/runtime/builtins/nodes/trigger.js.map +1 -1
  127. package/dist/runtime/builtins/nodes/tryCatch.js +2 -2
  128. package/dist/runtime/builtins/nodes/tryCatch.js.map +1 -1
  129. package/dist/runtime/builtins/triggers/cron.d.ts +4 -3
  130. package/dist/runtime/builtins/triggers/cron.js +5 -7
  131. package/dist/runtime/builtins/triggers/cron.js.map +1 -1
  132. package/dist/runtime/builtins/triggers/webhook.d.ts +11 -7
  133. package/dist/runtime/builtins/triggers/webhook.js +15 -12
  134. package/dist/runtime/builtins/triggers/webhook.js.map +1 -1
  135. package/dist/runtime/declaredProcedures.d.ts +2 -2
  136. package/dist/runtime/declaredProcedures.js +3 -2
  137. package/dist/runtime/declaredProcedures.js.map +1 -1
  138. package/dist/runtime/describe.d.ts +3 -1
  139. package/dist/runtime/describe.js +14 -13
  140. package/dist/runtime/describe.js.map +1 -1
  141. package/dist/runtime/executor.d.ts +2 -1
  142. package/dist/runtime/executor.js +18 -13
  143. package/dist/runtime/executor.js.map +1 -1
  144. package/dist/runtime/flatten.d.ts +1 -1
  145. package/dist/runtime/flatten.js +1 -1
  146. package/dist/runtime/flatten.js.map +1 -1
  147. package/dist/runtime/graphIssues.d.ts +2 -2
  148. package/dist/runtime/graphIssues.js +39 -32
  149. package/dist/runtime/graphIssues.js.map +1 -1
  150. package/dist/runtime/graphVersion.d.ts +1 -1
  151. package/dist/runtime/graphVersion.js +4 -3
  152. package/dist/runtime/graphVersion.js.map +1 -1
  153. package/dist/runtime/nodeKinds.d.ts +6 -5
  154. package/dist/runtime/nodeKinds.js.map +1 -1
  155. package/dist/runtime/reconcile.d.ts +3 -0
  156. package/dist/runtime/reconcile.js +178 -0
  157. package/dist/runtime/reconcile.js.map +1 -0
  158. package/dist/runtime/registry.d.ts +3 -3
  159. package/dist/runtime/resolveInputs.d.ts +13 -8
  160. package/dist/runtime/resolveInputs.js +18 -18
  161. package/dist/runtime/resolveInputs.js.map +1 -1
  162. package/dist/runtime/resolveSubgraph.js +4 -5
  163. package/dist/runtime/resolveSubgraph.js.map +1 -1
  164. package/dist/runtime/retention.js.map +1 -1
  165. package/dist/runtime/runProcedure.d.ts +3 -2
  166. package/dist/runtime/runProcedure.js +2 -1
  167. package/dist/runtime/runProcedure.js.map +1 -1
  168. package/dist/runtime/schedule.js +3 -0
  169. package/dist/runtime/schedule.js.map +1 -1
  170. package/dist/runtime/schemaProperties.d.ts +3 -0
  171. package/dist/runtime/schemaProperties.js +7 -0
  172. package/dist/runtime/schemaProperties.js.map +1 -0
  173. package/dist/runtime/serialQueue.d.ts +1 -1
  174. package/dist/runtime/serialQueue.js +4 -4
  175. package/dist/runtime/serialQueue.js.map +1 -1
  176. package/dist/runtime/sideEffects.d.ts +2 -2
  177. package/dist/runtime/subscriptions.d.ts +6 -4
  178. package/dist/runtime/subscriptions.js +21 -180
  179. package/dist/runtime/subscriptions.js.map +1 -1
  180. package/dist/runtime/subwalk.js.map +1 -1
  181. package/dist/runtime/templateCacheState.d.ts +6 -0
  182. package/dist/runtime/templateCacheState.js +10 -0
  183. package/dist/runtime/templateCacheState.js.map +1 -0
  184. package/dist/runtime/templateUsages.js +4 -5
  185. package/dist/runtime/templateUsages.js.map +1 -1
  186. package/dist/runtime/topo.js +2 -4
  187. package/dist/runtime/topo.js.map +1 -1
  188. package/dist/runtime/trace.d.ts +5 -2
  189. package/dist/runtime/trace.js +27 -17
  190. package/dist/runtime/trace.js.map +1 -1
  191. package/dist/runtime/triggerHandles.d.ts +4 -3
  192. package/dist/runtime/triggerHandles.js +9 -1
  193. package/dist/runtime/triggerHandles.js.map +1 -1
  194. package/dist/runtime/typeOrigin.js +12 -1
  195. package/dist/runtime/typeOrigin.js.map +1 -1
  196. package/dist/runtime/validate.js.map +1 -1
  197. package/dist/runtime/validateTemplate.js.map +1 -1
  198. package/dist/runtime/withTimeout.js.map +1 -1
  199. package/dist/runtime/wording.js +12 -8
  200. package/dist/runtime/wording.js.map +1 -1
  201. package/dist/stats/health-banner.js.map +1 -1
  202. package/dist/stats/health.js.map +1 -1
  203. package/dist/stats/kpi.js +1 -1
  204. package/dist/stats/kpi.js.map +1 -1
  205. package/dist/stats/overview.js +2 -1
  206. package/dist/stats/overview.js.map +1 -1
  207. package/dist/types/dataValue.d.ts +7 -0
  208. package/dist/types/dataValue.js +56 -0
  209. package/dist/types/dataValue.js.map +1 -0
  210. package/dist/types/graph.d.ts +19 -13
  211. package/dist/types/graph.js +8 -0
  212. package/dist/types/graph.js.map +1 -1
  213. package/dist/types/guards.d.ts +8 -0
  214. package/dist/types/guards.js +35 -0
  215. package/dist/types/guards.js.map +1 -0
  216. package/dist/types/runLog.d.ts +8 -7
  217. package/dist/types/runLog.js.map +1 -1
  218. package/frontend-vue/app/build/components/editor/EditorBanners.vue +120 -0
  219. package/frontend-vue/app/build/components/editor/EditorChoiceModal.vue +44 -0
  220. package/frontend-vue/app/build/components/editor/EditorForkModal.vue +51 -0
  221. package/frontend-vue/app/build/components/editor/EditorHeader.vue +146 -0
  222. package/frontend-vue/app/build/components/editor/EditorSaveTemplateModal.vue +105 -0
  223. package/frontend-vue/app/build/components/editor/NodeInspectorDocs.vue +28 -0
  224. package/frontend-vue/app/build/components/editor/NodeInspectorRun.vue +48 -0
  225. package/frontend-vue/app/build/composables/editor/useBuilderMount.ts +129 -0
  226. package/frontend-vue/app/build/composables/editor/useBuilderSave.ts +256 -0
  227. package/frontend-vue/app/build/composables/editor/useBuilderShortcuts.ts +270 -0
  228. package/frontend-vue/app/build/composables/editor/useDraftProblems.ts +288 -0
  229. package/frontend-vue/app/build/composables/editor/useEditorContext.ts +388 -0
  230. package/frontend-vue/app/build/composables/editor/useEditorLoad.ts +158 -0
  231. package/frontend-vue/app/build/composables/editor/useForkToLocal.ts +193 -0
  232. package/frontend-vue/app/build/composables/editor/useGraphHistory.ts +113 -0
  233. package/frontend-vue/app/build/composables/editor/useGroupEditing.ts +445 -0
  234. package/frontend-vue/app/build/composables/editor/usePalette.ts +41 -0
  235. package/frontend-vue/app/build/composables/editor/useProcedureActions.ts +96 -0
  236. package/frontend-vue/app/build/composables/editor/useRunOverlay.ts +466 -0
  237. package/frontend-vue/app/build/composables/editor/useSaveAsTemplate.ts +172 -0
  238. package/frontend-vue/app/build/composables/editor/useSavedTriggers.ts +100 -0
  239. package/frontend-vue/app/build/composables/editor/useSubgraphNavigation.ts +270 -0
  240. package/frontend-vue/app/build/composables/editor/useUnsavedGuards.ts +233 -0
  241. package/frontend-vue/app/build/composables/graphCanvas/connect.ts +273 -0
  242. package/frontend-vue/app/build/composables/graphCanvas/edgeEvents.ts +172 -0
  243. package/frontend-vue/app/build/composables/graphCanvas/edges.ts +55 -0
  244. package/frontend-vue/app/build/composables/graphCanvas/handles.ts +181 -0
  245. package/frontend-vue/app/build/composables/graphCanvas/linkMenu.ts +123 -0
  246. package/frontend-vue/app/build/composables/graphCanvas/nodeData.ts +222 -0
  247. package/frontend-vue/app/build/composables/graphCanvas/placement.ts +248 -0
  248. package/frontend-vue/app/build/composables/graphCanvas/selection.ts +150 -0
  249. package/frontend-vue/app/build/composables/graphCanvas/types.ts +188 -0
  250. package/frontend-vue/app/build/composables/graphCanvas/view.ts +230 -0
  251. package/frontend-vue/app/build/types/editor.ts +94 -0
  252. package/frontend-vue/app/build/utils/editor/apiErrors.ts +74 -0
  253. package/frontend-vue/app/build/utils/editor/graphShape.ts +68 -0
  254. package/frontend-vue/app/build/utils/editor/groupPlan.ts +322 -0
  255. package/frontend-vue/app/build/utils/editor/groupPorts.ts +210 -0
  256. package/frontend-vue/app/build/utils/editor/keyboard.ts +22 -0
  257. package/frontend-vue/app/build/utils/inspectorFields.ts +117 -0
  258. package/frontend-vue/app/build/utils/templates.ts +88 -0
  259. package/frontend-vue/app/components/AttentionList.vue +2 -6
  260. package/frontend-vue/app/components/Catalog.vue +2 -1
  261. package/frontend-vue/app/components/Editor/GraphCanvas.vue +78 -1337
  262. package/frontend-vue/app/components/Editor/NodeInspector.vue +31 -123
  263. package/frontend-vue/app/components/Editor.vue +134 -3484
  264. package/frontend-vue/app/components/Templates.vue +14 -84
  265. package/frontend-vue/build/backend-boundary.ts +122 -0
  266. package/frontend-vue/dms.frontend.build.ts +2 -0
  267. package/frontend-vue/eslint-rules/index.mjs +103 -0
  268. package/frontend-vue/eslint.config.mjs +15 -0
  269. package/frontend-vue/package.json +8 -5
  270. package/frontend-vue/pnpm-lock.yaml +168 -139
  271. package/frontend-vue/tests/api-error-presentation.test.cjs +254 -0
  272. package/frontend-vue/tests/helpers/setup.cjs +44 -0
  273. package/package.json +18 -15
  274. package/skills/dms-automation/SKILL.md +2 -2
  275. package/skills/dms-automation/cases.json +58 -0
@@ -0,0 +1,288 @@
1
+ import { computed, onBeforeUnmount, onMounted, watch } from "vue";
2
+ import type { EditorContext } from "./useEditorContext";
3
+ import type { DockIssue } from "../../../components/Editor/BottomDock.vue";
4
+ import type { ProcedureSummaryRow } from "../../../components/Editor/ProcedureSwitcher.vue";
5
+ import type {
6
+ GraphNode,
7
+ ProcedureGraph,
8
+ } from "../../../composables/useGraphConnect";
9
+ import type { WordedTrigger } from "../../../utils/describe";
10
+ import { cloneGraph, structuralKey } from "../../utils/editor/graphShape";
11
+ import type { GraphIssue } from "../../types/editor";
12
+ import type { GraphHistory } from "./useGraphHistory";
13
+ import type { SubgraphNavigation } from "./useSubgraphNavigation";
14
+
15
+ /** The draft's name, state and problems: the bar's figures and what the server says of the draft. */
16
+ export function useDraftProblems(
17
+ ctx: EditorContext,
18
+ history: GraphHistory,
19
+ nav: SubgraphNavigation,
20
+ ) {
21
+ const {
22
+ $authFetch,
23
+ actionTypes,
24
+ dataNodeTypes,
25
+ dockCollapsed,
26
+ dockTab,
27
+ draftTriggers,
28
+ editorMode,
29
+ issues,
30
+ nodeKinds,
31
+ processI18n,
32
+ props,
33
+ saveBlocked,
34
+ savedSnapshot,
35
+ selected,
36
+ selectedId,
37
+ selectedNodeId,
38
+ subgraphPath,
39
+ t,
40
+ te,
41
+ templatePorts,
42
+ triggerTypes,
43
+ } = ctx;
44
+ const { pushHistory } = history;
45
+ const { groupName } = nav;
46
+
47
+ const procedureName = computed<string>({
48
+ get: () => selected.value?.name ?? "",
49
+ set: (v: string) => {
50
+ if (selected.value) selected.value.name = v;
51
+ },
52
+ });
53
+
54
+ // Titles and toasts about what is stored name it as stored, not as the
55
+ // draft spells it (possibly blank) at that moment.
56
+ const savedName = computed<string>(
57
+ () => savedSnapshot.value?.name || selected.value?.name || "",
58
+ );
59
+
60
+ // The name is the one field outside the graph a save checks: a blank one is
61
+ // said under the name, and Save waits for it.
62
+ const NAME_INPUT_ID = "builder-procedure-name";
63
+ const nameMissing = computed<boolean>(
64
+ () => !!selected.value && !selected.value.name.trim(),
65
+ );
66
+
67
+ const procedureEnabled = computed<boolean>({
68
+ get: () => selected.value?.enabled ?? false,
69
+ set: (v: boolean) => {
70
+ if (selected.value) selected.value.enabled = v;
71
+ },
72
+ });
73
+
74
+ const summariesRead = useApiData<ProcedureSummaryRow[]>(() =>
75
+ editorMode.value === "procedure"
76
+ ? `${props.apiUrl}/procedures/summary`
77
+ : null,
78
+ );
79
+ const summaries = computed(() => summariesRead.data.value ?? []);
80
+
81
+ const currentSummary = computed(
82
+ () =>
83
+ summaries.value.find((s) => s.procedureId === selectedId.value) ?? null,
84
+ );
85
+
86
+ /** How many things changed since the last save, for "2 unsaved changes". */
87
+ const changeCount = computed<number>(() => {
88
+ const current = selected.value;
89
+ const saved = savedSnapshot.value;
90
+ if (!current || !saved) return 0;
91
+ let count = 0;
92
+ if (current.name !== saved.name) count++;
93
+ if (current.enabled !== saved.enabled) count++;
94
+ if (
95
+ saved.ports &&
96
+ JSON.stringify(saved.ports) !== JSON.stringify(templatePorts.value)
97
+ )
98
+ count++;
99
+ const before = new Map(
100
+ saved.graph.nodes.map((n) => [n.id, JSON.stringify(n)]),
101
+ );
102
+ const after = new Map(
103
+ current.graph.nodes.map((n) => [n.id, JSON.stringify(n)]),
104
+ );
105
+ for (const [id, value] of after) if (before.get(id) !== value) count++;
106
+ for (const id of before.keys()) if (!after.has(id)) count++;
107
+ const edges = (g: ProcedureGraph) =>
108
+ JSON.stringify([g.triggerEdges, g.dataEdges]);
109
+ if (edges(current.graph) !== edges(saved.graph)) count++;
110
+ return count;
111
+ });
112
+
113
+ let validateTimer: ReturnType<typeof setTimeout> | undefined;
114
+ const VALIDATE_DELAY_MS = 500;
115
+
116
+ async function validateDraft() {
117
+ const current = selected.value;
118
+ if (!current || editorMode.value !== "procedure") {
119
+ issues.value = [];
120
+ draftTriggers.value = [];
121
+ return;
122
+ }
123
+ try {
124
+ const res = await $authFetch<{
125
+ issues: typeof issues.value;
126
+ triggers?: WordedTrigger[];
127
+ }>(`${props.apiUrl}/procedures/validate`, {
128
+ method: "POST",
129
+ // With the procedure and its name, the server also checks what other
130
+ // procedures hold (a webhook path, a name).
131
+ body: {
132
+ graph: current.graph,
133
+ enabled: current.enabled,
134
+ procedureId: current._id,
135
+ name: current.name,
136
+ },
137
+ });
138
+ issues.value = res.issues ?? [];
139
+ draftTriggers.value = res.triggers ?? [];
140
+ } catch {
141
+ // A graph the schema refuses is reported on save.
142
+ }
143
+ }
144
+
145
+ function scheduleValidation() {
146
+ clearTimeout(validateTimer);
147
+ validateTimer = setTimeout(() => void validateDraft(), VALIDATE_DELAY_MS);
148
+ }
149
+ watch(
150
+ () =>
151
+ selected.value
152
+ ? [
153
+ structuralKey(selected.value.graph),
154
+ selected.value.name,
155
+ selected.value.enabled,
156
+ ].join("|")
157
+ : "",
158
+ scheduleValidation,
159
+ );
160
+ // The draft as opened is checked in the browser: a server render has no
161
+ // draft to check, and its timer would outlive the render.
162
+ onMounted(scheduleValidation);
163
+ onBeforeUnmount(() => clearTimeout(validateTimer));
164
+
165
+ const blockingIssues = computed(() =>
166
+ issues.value.filter((i) => i.severity === "error"),
167
+ );
168
+
169
+ /** How the builder names a node: its label, else its type's name. */
170
+ function nodeDisplayName(id: string): string {
171
+ const node = walkAll(selected.value?.graph).find((n) => n.id === id);
172
+ if (!node) return id;
173
+ if (node.kind === "group") return groupName(node);
174
+ if (node.label) return node.label;
175
+ const typeName =
176
+ node.kind === "trigger"
177
+ ? triggerTypes.value.find((x) => x.id === node.typeId)?.name
178
+ : node.kind === "action"
179
+ ? actionTypes.value.find((x) => x.id === node.typeId)?.name
180
+ : node.kind === "data"
181
+ ? dataNodeTypes.value.find((x) => x.id === node.typeId)?.name
182
+ : nodeKinds.value.find((k) => k.kind === node.kind)?.meta.ui?.label;
183
+ return typeName
184
+ ? processI18n(typeName)
185
+ : ((node.config?.name as string | undefined) ?? node.kind);
186
+ }
187
+
188
+ function walkAll(graph: ProcedureGraph | undefined): GraphNode[] {
189
+ if (!graph) return [];
190
+ return graph.nodes.flatMap((n) => [n, ...walkAll(n.subgraph)]);
191
+ }
192
+
193
+ /** An issue in the user's language. */
194
+ function issueText(issue: GraphIssue): string {
195
+ const key = `dms_automation.editor.problems.codes.${issue.code}`;
196
+ return issue.code && te(key) ? t(key, issue.params ?? {}) : issue.message;
197
+ }
198
+
199
+ const dockIssues = computed<DockIssue[]>(() =>
200
+ issues.value.map((issue) => ({
201
+ ...issue,
202
+ message: issueText(issue),
203
+ nodeName: issue.nodeId ? nodeDisplayName(issue.nodeId) : undefined,
204
+ })),
205
+ );
206
+
207
+ // Code and params travel along: the inspector names a setting as its form does.
208
+ const issuesByNode = computed<Record<string, Omit<GraphIssue, "nodeId">>>(
209
+ () => {
210
+ const out: Record<string, Omit<GraphIssue, "nodeId">> = {};
211
+ for (const issue of issues.value) {
212
+ if (!issue.nodeId) continue;
213
+ if (!out[issue.nodeId] || issue.severity === "error")
214
+ out[issue.nodeId] = {
215
+ severity: issue.severity,
216
+ message: issueText(issue),
217
+ code: issue.code,
218
+ params: issue.params,
219
+ };
220
+ }
221
+ return out;
222
+ },
223
+ );
224
+
225
+ let dockOpenedForProblems = false;
226
+ watch(
227
+ () => blockingIssues.value.length,
228
+ (count, before) => {
229
+ if (count > 0 && !before) {
230
+ dockTab.value = "problems";
231
+ dockCollapsed.value = false;
232
+ dockOpenedForProblems = true;
233
+ } else if (
234
+ count === 0 &&
235
+ dockOpenedForProblems &&
236
+ dockTab.value === "problems"
237
+ ) {
238
+ dockCollapsed.value = true;
239
+ }
240
+ },
241
+ );
242
+ watch([dockTab, dockCollapsed], () => {
243
+ if (dockCollapsed.value || dockTab.value !== "problems")
244
+ dockOpenedForProblems = false;
245
+ });
246
+
247
+ function selectNode(id: string) {
248
+ // A node inside a group is named by its top-level group in the issues.
249
+ subgraphPath.value = subgraphPath.value.slice(0, 1);
250
+ selectedNodeId.value = id;
251
+ }
252
+
253
+ function onCancel() {
254
+ if (!selected.value || !savedSnapshot.value) return;
255
+ const snap = savedSnapshot.value;
256
+ selected.value.name = snap.name;
257
+ selected.value.enabled = snap.enabled;
258
+ selected.value.graph = cloneGraph(snap.graph);
259
+ if (snap.ports)
260
+ templatePorts.value = snap.ports.map((port) => ({ ...port }));
261
+ pushHistory(selected.value.graph);
262
+ // A refused save is answered by the draft it refused: discarding it
263
+ // clears the banner, and the name, outside the graph, is checked again.
264
+ saveBlocked.value = false;
265
+ void validateDraft();
266
+ }
267
+
268
+ return {
269
+ procedureName,
270
+ savedName,
271
+ NAME_INPUT_ID,
272
+ nameMissing,
273
+ procedureEnabled,
274
+ summariesRead,
275
+ summaries,
276
+ currentSummary,
277
+ changeCount,
278
+ blockingIssues,
279
+ nodeDisplayName,
280
+ dockIssues,
281
+ issuesByNode,
282
+ selectNode,
283
+ onCancel,
284
+ validateDraft,
285
+ };
286
+ }
287
+
288
+ export type DraftProblems = ReturnType<typeof useDraftProblems>;
@@ -0,0 +1,388 @@
1
+ import { computed, ref } from "vue";
2
+ import type { DockTab } from "../../../components/Editor/BottomDock.vue";
3
+ import {
4
+ type RunDetail,
5
+ useAutomationRuns,
6
+ } from "../../../composables/useAutomationRuns";
7
+ import type { TemplateSummary } from "../../../composables/useAutomationNodeKinds";
8
+ import type {
9
+ ActionType,
10
+ DataNodeType,
11
+ GraphNode,
12
+ GroupPort,
13
+ ProcedureGraph,
14
+ TriggerType,
15
+ } from "../../../composables/useGraphConnect";
16
+ import { queryString } from "../../../utils/automation";
17
+ import type { WordedTrigger } from "../../../utils/describe";
18
+ import type {
19
+ GraphIssue,
20
+ ProcedureRecord,
21
+ ProcedureSnapshot,
22
+ SubgraphFrame,
23
+ SubgraphPathSegment,
24
+ } from "../../types/editor";
25
+
26
+ /** What the builder takes from its props. */
27
+ export interface EditorProps {
28
+ readonly apiUrl: string;
29
+ readonly runsUrl: string;
30
+ readonly traceUrl: string;
31
+ }
32
+
33
+ /**
34
+ * The state the builder's parts share: the host composables it calls before
35
+ * its first `await`, the reads of the palette's catalogs, the open
36
+ * procedure, and what is derived from them.
37
+ */
38
+ export function createEditorContext(props: EditorProps) {
39
+ const route = useDmsRoute();
40
+ const router = useDmsRouter();
41
+ const { t, te, locale } = useI18n();
42
+ const { dateTimeFormat } = useRegionalFormat();
43
+ const { processI18n } = useTranslation();
44
+ const { processText } = useComposedText();
45
+ // Shortcut hints print ⌘ on macOS and Ctrl elsewhere, like the rest of the DMS.
46
+ const { formatShortcut } = useKeyboardPlatform();
47
+
48
+ /** The builder's own path, without the query its URL may carry. */
49
+ function builderPath(): string {
50
+ return route.path.split("?")[0] ?? route.path;
51
+ }
52
+
53
+ function queryValue(key: string): string | null {
54
+ return queryString(route.query[key]);
55
+ }
56
+
57
+ const templateQueryId = computed(() => queryValue("template"));
58
+
59
+ const editorMode = computed<"procedure" | "template">(() =>
60
+ templateQueryId.value ? "template" : "procedure",
61
+ );
62
+
63
+ const editorTemplateId = computed<string | null>(() =>
64
+ editorMode.value === "template" ? templateQueryId.value : null,
65
+ );
66
+
67
+ const { $authFetch } = useAuthFetch();
68
+ const toast = useToast();
69
+ // Composables are called before the first `await` of this setup: after it,
70
+ // the component instance they inject from is gone.
71
+ const { confirm } = useConfirm();
72
+ const { confirmFrom } = useConfirmFrom();
73
+ const runsApi = useAutomationRuns(props.apiUrl);
74
+ // Leaving the page with unsaved changes goes through the DMS leave guard.
75
+ const unsavedDraft = ref(false);
76
+ useUnsavedChanges({ dirty: unsavedDraft });
77
+
78
+ const procedures = ref<ProcedureRecord[]>([]);
79
+ const selectedId = ref<string | null>(null);
80
+ const switcherOpen = ref(false);
81
+ const newProcedureOpen = ref(false);
82
+ const runNowOpen = ref(false);
83
+ const loading = ref(false);
84
+ const loadError = ref<string | null>(null);
85
+ // The `?selected=` of a procedure that no longer exists: the builder says so
86
+ // instead of opening another one.
87
+ const missingProcedureId = ref<string | null>(null);
88
+ // `?template=` names a template that no longer exists.
89
+ const templateNotFound = ref(false);
90
+ const saving = ref(false);
91
+
92
+ // Template-mode state. `templatePorts` holds the OUTER-face ports of the
93
+ // edited template — they're not part of the editable subgraph but they ARE
94
+ // the source of truth for the root-level groupInput/groupOutput sentinels'
95
+ // handle sets. We pipe them through `currentParentGroupPorts` so GraphCanvas
96
+ // renders them identically to how it renders a nested group's sentinels.
97
+ const templatePorts = ref<GroupPort[]>([]);
98
+ // Kept as loaded: saving the template from the editor must not reset its icon.
99
+ const templateIcon = ref<string>("i-ph-package");
100
+
101
+ // The palette's catalogs, read with the page. They are optional for
102
+ // editing: one the server cannot answer is an empty list.
103
+ const triggerTypesRead = useApiData<TriggerType[]>(
104
+ "/api/automation/trigger-types",
105
+ );
106
+ const actionTypesRead = useApiData<ActionType[]>(
107
+ "/api/automation/action-types",
108
+ );
109
+ const dataNodeTypesRead = useApiData<DataNodeType[]>(
110
+ "/api/automation/data-node-types",
111
+ );
112
+ // Per-NodeKind UI metadata served by the backend
113
+ // (`/api/automation/node-kinds`). Drives the editor's GenericNode renderer
114
+ // so the frontend doesn't need to know about specific kinds.
115
+ const nodeKindsRead = useAutomationNodeKinds();
116
+ const triggerTypes = computed(() => triggerTypesRead.data.value ?? []);
117
+ const actionTypes = computed(() => actionTypesRead.data.value ?? []);
118
+ const dataNodeTypes = computed(() => dataNodeTypesRead.data.value ?? []);
119
+ const nodeKinds = computed(() => nodeKindsRead.data.value ?? []);
120
+
121
+ // Workspace-global templates surfaced in the canvas's node palette. Empty
122
+ // list → palette section hidden (handled inside BuilderPalette).
123
+ //
124
+ // Only the fields the palette + template-instance creation need are kept,
125
+ // and handed over with the page: the list endpoint also returns the
126
+ // description, the usage count and the hydrated subgraph. Under a key of its
127
+ // own, apart from the library's full rows of the same URL.
128
+ const templatesRead = useApiData<TemplateSummary[]>(
129
+ "/api/automation/templates",
130
+ {
131
+ key: "dms-automation-palette-templates",
132
+ transform: (value) =>
133
+ (value as { results: TemplateSummary[] }).results.map((t) => ({
134
+ _id: t._id,
135
+ name: t.name,
136
+ icon: t.icon,
137
+ ports: Array.isArray(t.ports) ? t.ports : [],
138
+ })),
139
+ },
140
+ );
141
+ const templates = computed(() => templatesRead.data.value ?? []);
142
+
143
+ // Hide the palette section while editing a template (self-edit). The
144
+ // server's cycle check would still catch any reference cycle, but blocking
145
+ // it at the UI level keeps the UX cleaner — the user can't even attempt
146
+ // to drop a template (including the one currently open) into itself.
147
+ const palettesTemplates = computed<TemplateSummary[] | undefined>(() =>
148
+ editorMode.value === "template" ? undefined : templates.value,
149
+ );
150
+
151
+ // Triggers live at the top level of a procedure: the palette offers none
152
+ // inside a group or a template.
153
+ const paletteTriggerTypes = computed<TriggerType[]>(() =>
154
+ editorMode.value === "template" || subgraphPath.value.length > 1
155
+ ? []
156
+ : triggerTypes.value,
157
+ );
158
+
159
+ // Which graph the canvas shows (procedure or template, then the groups
160
+ // entered): the canvas fits a new one into view.
161
+ const canvasViewKey = computed(() =>
162
+ [
163
+ selectedId.value ?? "",
164
+ ...subgraphPath.value.slice(1).map((segment) => segment.id),
165
+ ].join("/"),
166
+ );
167
+
168
+ // Back to the Library's Templates tab, on the template being edited.
169
+ const libraryBackUrl = computed(() =>
170
+ editorTemplateId.value && !templateNotFound.value
171
+ ? `/modules/automation/library?tab=templates&template=${editorTemplateId.value}`
172
+ : "/modules/automation/library?tab=templates",
173
+ );
174
+
175
+ const selectedNodeId = ref<string | null>(null);
176
+ // Mirrors GraphCanvas's @selection-change — full set of currently selected
177
+ // node ids in the canvas, sentinel-filtered. Drives the "Group selection"
178
+ // toolbar button (see canGroupSelection / createGroupFromSelection).
179
+ const selectedNodeIds = ref<string[]>([]);
180
+
181
+ function onSelectionChange(payload: { ids: string[] }) {
182
+ selectedNodeIds.value = payload.ids;
183
+ }
184
+
185
+ const subgraphPath = ref<SubgraphPathSegment[]>([]);
186
+
187
+ const savedSnapshot = ref<ProcedureSnapshot | null>(null);
188
+
189
+ const selected = computed<ProcedureRecord | null>(
190
+ () => procedures.value.find((p) => p._id === selectedId.value) ?? null,
191
+ );
192
+
193
+ const subgraphFrames = computed<SubgraphFrame[]>(() => {
194
+ const p = selected.value;
195
+ if (!p) return [];
196
+ const path = subgraphPath.value;
197
+ if (path.length === 0) return [];
198
+ const frames: SubgraphFrame[] = [
199
+ { segment: path[0]!, graph: p.graph, groupNode: null },
200
+ ];
201
+ for (let i = 1; i < path.length; i++) {
202
+ const seg = path[i]!;
203
+ const parent = frames[i - 1]!;
204
+ const node = parent.graph.nodes.find(
205
+ (n) => n.id === seg.id && n.kind === "group",
206
+ );
207
+ if (!node) break;
208
+ // Local group → inline subgraph. Template instance → no inline
209
+ // subgraph on the client, so we can't navigate in. The
210
+ // double-click handler guards against pushing a template-instance
211
+ // segment in the first place; this is a safety net.
212
+ const sub = node.subgraph;
213
+ if (!sub) break;
214
+ frames.push({ segment: seg, graph: sub, groupNode: node });
215
+ }
216
+ return frames;
217
+ });
218
+
219
+ const currentGraph = computed<ProcedureGraph | null>(() => {
220
+ const frames = subgraphFrames.value;
221
+ if (frames.length === 0) return null;
222
+ return frames[frames.length - 1]!.graph;
223
+ });
224
+
225
+ // The parent group node whose subgraph we're currently viewing — null at
226
+ // the procedure root.
227
+ const currentParentGroup = computed<GraphNode | null>(() => {
228
+ const frames = subgraphFrames.value;
229
+ if (frames.length <= 1) return null;
230
+ return frames[frames.length - 1]!.groupNode;
231
+ });
232
+
233
+ const currentParentGroupPorts = computed<GroupPort[] | undefined>(() => {
234
+ const g = currentParentGroup.value;
235
+ if (g) return Array.isArray(g.ports) ? g.ports : [];
236
+ // Root level in template mode: the template's own `ports` are the
237
+ // outer-face of the edited subgraph. Inject them so the root-level
238
+ // groupInput / groupOutput sentinels render the right handles.
239
+ if (editorMode.value === "template") return templatePorts.value;
240
+ return undefined;
241
+ });
242
+
243
+ // Read-only mode kicks in when viewing the inner subgraph of a template
244
+ // instance (a group node carrying `templateId`). The fork action lets
245
+ // the user promote it to a local group; until then we just show a
246
+ // banner and disable mutations.
247
+ const isCurrentGraphReadOnly = computed<boolean>(() => {
248
+ const g = currentParentGroup.value;
249
+ if (!g) return false;
250
+ return Boolean(g.templateId);
251
+ });
252
+
253
+ const selectedNode = computed<GraphNode | null>(() => {
254
+ const id = selectedNodeId.value;
255
+ if (!id) return null;
256
+ // Lookup is scoped to whichever graph the canvas is currently
257
+ // bound to, not always the procedure root — otherwise selecting a
258
+ // node inside a subgraph would resolve to null.
259
+ const g = currentGraph.value;
260
+ if (!g) return null;
261
+ return g.nodes.find((n) => n.id === id) ?? null;
262
+ });
263
+
264
+ const selectedNodeTriggerType = computed<TriggerType | null>(() => {
265
+ const n = selectedNode.value;
266
+ if (!n || n.kind !== "trigger") return null;
267
+ return triggerTypes.value.find((t) => t.id === n.typeId) ?? null;
268
+ });
269
+
270
+ const selectedNodeActionType = computed<ActionType | null>(() => {
271
+ const n = selectedNode.value;
272
+ if (!n || n.kind !== "action") return null;
273
+ return actionTypes.value.find((a) => a.id === n.typeId) ?? null;
274
+ });
275
+
276
+ // The node palette lives in the left BuilderPalette sidebar; its add events are
277
+ // forwarded to the canvas' exposed helpers via this template ref.
278
+ const graphCanvasRef = ref<{
279
+ addNode: (kind: string, typeId?: string) => void;
280
+ addTemplateInstance: (template: {
281
+ _id: string;
282
+ name: string;
283
+ icon?: string;
284
+ ports: GroupPort[];
285
+ }) => void;
286
+ } | null>(null);
287
+
288
+ const inspectorRef = ref<HTMLElement | null>(null);
289
+
290
+ const issues = ref<GraphIssue[]>([]);
291
+ // The draft's triggers, worded by the server with its problems: the canvas
292
+ // and the test dock name them.
293
+ const draftTriggers = ref<WordedTrigger[]>([]);
294
+
295
+ const dockTab = ref<DockTab>("problems");
296
+ // The dock stays out of the canvas's way until it has something to say: it
297
+ // opens on its own for a problem that blocks enabling (a warning only counts
298
+ // on its tab), and closes again once that is fixed, unless the user has
299
+ // taken it over in between.
300
+ const dockCollapsed = ref(true);
301
+
302
+ /** Set when a save was refused for problems: the banner offers the way out. */
303
+ const saveBlocked = ref(false);
304
+
305
+ /** The run shown over the canvas, and whether it is a test of the draft. */
306
+ const overlayRun = ref<RunDetail | null>(null);
307
+ const overlayIsTest = ref(false);
308
+ const testing = ref(false);
309
+ const testPayload = ref("{}");
310
+ const testPayloadSource = ref<string | null>(null);
311
+ // The trigger a Test run starts from, chosen in the dock (see the watch on
312
+ // the draft's triggers at the end).
313
+ const testTriggerNodeId = ref<string | undefined>(undefined);
314
+
315
+ return {
316
+ props,
317
+ route,
318
+ router,
319
+ t,
320
+ te,
321
+ locale,
322
+ dateTimeFormat,
323
+ processI18n,
324
+ processText,
325
+ formatShortcut,
326
+ builderPath,
327
+ queryValue,
328
+ editorMode,
329
+ editorTemplateId,
330
+ $authFetch,
331
+ toast,
332
+ confirm,
333
+ confirmFrom,
334
+ runsApi,
335
+ unsavedDraft,
336
+ procedures,
337
+ selectedId,
338
+ switcherOpen,
339
+ newProcedureOpen,
340
+ runNowOpen,
341
+ loading,
342
+ loadError,
343
+ missingProcedureId,
344
+ templateNotFound,
345
+ saving,
346
+ templatePorts,
347
+ templateIcon,
348
+ triggerTypes,
349
+ actionTypes,
350
+ dataNodeTypes,
351
+ nodeKinds,
352
+ templatesRead,
353
+ templates,
354
+ palettesTemplates,
355
+ paletteTriggerTypes,
356
+ canvasViewKey,
357
+ libraryBackUrl,
358
+ selectedNodeId,
359
+ selectedNodeIds,
360
+ onSelectionChange,
361
+ subgraphPath,
362
+ savedSnapshot,
363
+ selected,
364
+ subgraphFrames,
365
+ currentGraph,
366
+ currentParentGroup,
367
+ currentParentGroupPorts,
368
+ isCurrentGraphReadOnly,
369
+ selectedNode,
370
+ selectedNodeTriggerType,
371
+ selectedNodeActionType,
372
+ graphCanvasRef,
373
+ inspectorRef,
374
+ issues,
375
+ draftTriggers,
376
+ dockTab,
377
+ dockCollapsed,
378
+ saveBlocked,
379
+ overlayRun,
380
+ overlayIsTest,
381
+ testing,
382
+ testPayload,
383
+ testPayloadSource,
384
+ testTriggerNodeId,
385
+ };
386
+ }
387
+
388
+ export type EditorContext = ReturnType<typeof createEditorContext>;