@antelopejs/dms-automation 0.7.0 → 0.8.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 (246) hide show
  1. package/README.md +19 -5
  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 +4 -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.js.map +1 -1
  12. package/dist/db/models/automation_template.model.d.ts +2 -4
  13. package/dist/db/models/automation_template.model.js +13 -14
  14. package/dist/db/models/automation_template.model.js.map +1 -1
  15. package/dist/db/models/procedure_run.model.js.map +1 -1
  16. package/dist/db/models/stats.model.js.map +1 -1
  17. package/dist/db/tables/procedure_run.table.d.ts +2 -1
  18. package/dist/db/tables/procedure_run.table.js.map +1 -1
  19. package/dist/implementations/dms-automation/index.js.map +1 -1
  20. package/dist/index.js.map +1 -1
  21. package/dist/pages/category.js.map +1 -1
  22. package/dist/pages/index.js.map +1 -1
  23. package/dist/pages/overview.js.map +1 -1
  24. package/dist/pages/procedures.js.map +1 -1
  25. package/dist/pages/runs.js.map +1 -1
  26. package/dist/pages/shared.js +1 -1
  27. package/dist/pages/shared.js.map +1 -1
  28. package/dist/realtime.d.ts +2 -1
  29. package/dist/realtime.js.map +1 -1
  30. package/dist/routes/action-types.d.ts +2 -1
  31. package/dist/routes/action-types.js.map +1 -1
  32. package/dist/routes/deleteConfirm.js +4 -3
  33. package/dist/routes/deleteConfirm.js.map +1 -1
  34. package/dist/routes/graphSchema.d.ts +2 -1
  35. package/dist/routes/graphSchema.js +8 -7
  36. package/dist/routes/graphSchema.js.map +1 -1
  37. package/dist/routes/procedureChecks.js +5 -5
  38. package/dist/routes/procedureChecks.js.map +1 -1
  39. package/dist/routes/procedureRuns.d.ts +2 -2
  40. package/dist/routes/procedureRuns.js +1 -1
  41. package/dist/routes/procedureRuns.js.map +1 -1
  42. package/dist/routes/procedures.d.ts +14 -13
  43. package/dist/routes/procedures.js +2 -1
  44. package/dist/routes/procedures.js.map +1 -1
  45. package/dist/routes/requests.d.ts +11 -5
  46. package/dist/routes/requests.js.map +1 -1
  47. package/dist/routes/runs.d.ts +7 -7
  48. package/dist/routes/runs.js +5 -3
  49. package/dist/routes/runs.js.map +1 -1
  50. package/dist/routes/stats.js.map +1 -1
  51. package/dist/routes/templates.d.ts +3 -2
  52. package/dist/routes/templates.js +2 -1
  53. package/dist/routes/templates.js.map +1 -1
  54. package/dist/routes/trigger-types.d.ts +2 -1
  55. package/dist/routes/trigger-types.js.map +1 -1
  56. package/dist/routes/typeConfigShared.d.ts +2 -1
  57. package/dist/routes/typeConfigShared.js.map +1 -1
  58. package/dist/runtime/armErrors.d.ts +0 -1
  59. package/dist/runtime/armErrors.js +0 -7
  60. package/dist/runtime/armErrors.js.map +1 -1
  61. package/dist/runtime/boundRunLog.d.ts +1 -0
  62. package/dist/runtime/boundRunLog.js +11 -11
  63. package/dist/runtime/boundRunLog.js.map +1 -1
  64. package/dist/runtime/builtins/actions/http.js +16 -9
  65. package/dist/runtime/builtins/actions/http.js.map +1 -1
  66. package/dist/runtime/builtins/actions/log.js.map +1 -1
  67. package/dist/runtime/builtins/data/boolean.js +4 -5
  68. package/dist/runtime/builtins/data/boolean.js.map +1 -1
  69. package/dist/runtime/builtins/data/compare.js +8 -10
  70. package/dist/runtime/builtins/data/compare.js.map +1 -1
  71. package/dist/runtime/builtins/data/constant.js +1 -1
  72. package/dist/runtime/builtins/data/constant.js.map +1 -1
  73. package/dist/runtime/builtins/data/json.js +4 -5
  74. package/dist/runtime/builtins/data/json.js.map +1 -1
  75. package/dist/runtime/builtins/data/math.js +4 -4
  76. package/dist/runtime/builtins/data/math.js.map +1 -1
  77. package/dist/runtime/builtins/data/object.js +12 -17
  78. package/dist/runtime/builtins/data/object.js.map +1 -1
  79. package/dist/runtime/builtins/data/string.js +13 -18
  80. package/dist/runtime/builtins/data/string.js.map +1 -1
  81. package/dist/runtime/builtins/nodes/action.js +5 -2
  82. package/dist/runtime/builtins/nodes/action.js.map +1 -1
  83. package/dist/runtime/builtins/nodes/data.js +2 -2
  84. package/dist/runtime/builtins/nodes/data.js.map +1 -1
  85. package/dist/runtime/builtins/nodes/delay.js +2 -2
  86. package/dist/runtime/builtins/nodes/delay.js.map +1 -1
  87. package/dist/runtime/builtins/nodes/forRange.js +2 -2
  88. package/dist/runtime/builtins/nodes/forRange.js.map +1 -1
  89. package/dist/runtime/builtins/nodes/foreach.js +2 -2
  90. package/dist/runtime/builtins/nodes/foreach.js.map +1 -1
  91. package/dist/runtime/builtins/nodes/groupInput.js +2 -2
  92. package/dist/runtime/builtins/nodes/groupInput.js.map +1 -1
  93. package/dist/runtime/builtins/nodes/groupOutput.js +2 -2
  94. package/dist/runtime/builtins/nodes/groupOutput.js.map +1 -1
  95. package/dist/runtime/builtins/nodes/if.js +2 -2
  96. package/dist/runtime/builtins/nodes/if.js.map +1 -1
  97. package/dist/runtime/builtins/nodes/parallel.js +2 -2
  98. package/dist/runtime/builtins/nodes/parallel.js.map +1 -1
  99. package/dist/runtime/builtins/nodes/retry.js +5 -4
  100. package/dist/runtime/builtins/nodes/retry.js.map +1 -1
  101. package/dist/runtime/builtins/nodes/setVariable.js +2 -2
  102. package/dist/runtime/builtins/nodes/setVariable.js.map +1 -1
  103. package/dist/runtime/builtins/nodes/switch.js +2 -2
  104. package/dist/runtime/builtins/nodes/switch.js.map +1 -1
  105. package/dist/runtime/builtins/nodes/trigger.js +2 -2
  106. package/dist/runtime/builtins/nodes/trigger.js.map +1 -1
  107. package/dist/runtime/builtins/nodes/tryCatch.js +2 -2
  108. package/dist/runtime/builtins/nodes/tryCatch.js.map +1 -1
  109. package/dist/runtime/builtins/triggers/cron.d.ts +2 -1
  110. package/dist/runtime/builtins/triggers/cron.js +5 -7
  111. package/dist/runtime/builtins/triggers/cron.js.map +1 -1
  112. package/dist/runtime/builtins/triggers/webhook.d.ts +6 -5
  113. package/dist/runtime/builtins/triggers/webhook.js +9 -6
  114. package/dist/runtime/builtins/triggers/webhook.js.map +1 -1
  115. package/dist/runtime/declaredProcedures.d.ts +2 -2
  116. package/dist/runtime/declaredProcedures.js +3 -2
  117. package/dist/runtime/declaredProcedures.js.map +1 -1
  118. package/dist/runtime/describe.js +11 -10
  119. package/dist/runtime/describe.js.map +1 -1
  120. package/dist/runtime/executor.js +10 -7
  121. package/dist/runtime/executor.js.map +1 -1
  122. package/dist/runtime/flatten.d.ts +1 -1
  123. package/dist/runtime/flatten.js +1 -1
  124. package/dist/runtime/flatten.js.map +1 -1
  125. package/dist/runtime/graphIssues.js +24 -22
  126. package/dist/runtime/graphIssues.js.map +1 -1
  127. package/dist/runtime/graphVersion.d.ts +1 -1
  128. package/dist/runtime/graphVersion.js +2 -1
  129. package/dist/runtime/graphVersion.js.map +1 -1
  130. package/dist/runtime/nodeKinds.d.ts +3 -2
  131. package/dist/runtime/nodeKinds.js.map +1 -1
  132. package/dist/runtime/reconcile.d.ts +3 -0
  133. package/dist/runtime/reconcile.js +178 -0
  134. package/dist/runtime/reconcile.js.map +1 -0
  135. package/dist/runtime/resolveInputs.d.ts +4 -2
  136. package/dist/runtime/resolveInputs.js +13 -12
  137. package/dist/runtime/resolveInputs.js.map +1 -1
  138. package/dist/runtime/resolveSubgraph.js +4 -5
  139. package/dist/runtime/resolveSubgraph.js.map +1 -1
  140. package/dist/runtime/retention.js.map +1 -1
  141. package/dist/runtime/runProcedure.d.ts +1 -1
  142. package/dist/runtime/runProcedure.js +2 -1
  143. package/dist/runtime/runProcedure.js.map +1 -1
  144. package/dist/runtime/schedule.js +3 -0
  145. package/dist/runtime/schedule.js.map +1 -1
  146. package/dist/runtime/schemaProperties.d.ts +11 -0
  147. package/dist/runtime/schemaProperties.js +7 -0
  148. package/dist/runtime/schemaProperties.js.map +1 -0
  149. package/dist/runtime/serialQueue.d.ts +1 -1
  150. package/dist/runtime/serialQueue.js +4 -4
  151. package/dist/runtime/serialQueue.js.map +1 -1
  152. package/dist/runtime/subscriptions.js +21 -180
  153. package/dist/runtime/subscriptions.js.map +1 -1
  154. package/dist/runtime/subwalk.js.map +1 -1
  155. package/dist/runtime/templateCacheState.d.ts +6 -0
  156. package/dist/runtime/templateCacheState.js +10 -0
  157. package/dist/runtime/templateCacheState.js.map +1 -0
  158. package/dist/runtime/templateUsages.js +4 -5
  159. package/dist/runtime/templateUsages.js.map +1 -1
  160. package/dist/runtime/topo.js +2 -4
  161. package/dist/runtime/topo.js.map +1 -1
  162. package/dist/runtime/trace.js +12 -9
  163. package/dist/runtime/trace.js.map +1 -1
  164. package/dist/runtime/triggerHandles.d.ts +3 -0
  165. package/dist/runtime/triggerHandles.js +8 -0
  166. package/dist/runtime/triggerHandles.js.map +1 -1
  167. package/dist/runtime/typeOrigin.js +12 -1
  168. package/dist/runtime/typeOrigin.js.map +1 -1
  169. package/dist/runtime/validate.js.map +1 -1
  170. package/dist/runtime/validateTemplate.js.map +1 -1
  171. package/dist/runtime/withTimeout.js.map +1 -1
  172. package/dist/runtime/wording.js +12 -8
  173. package/dist/runtime/wording.js.map +1 -1
  174. package/dist/stats/health-banner.js.map +1 -1
  175. package/dist/stats/health.js.map +1 -1
  176. package/dist/stats/kpi.js +1 -1
  177. package/dist/stats/kpi.js.map +1 -1
  178. package/dist/stats/overview.js +2 -1
  179. package/dist/stats/overview.js.map +1 -1
  180. package/dist/types/dataValue.d.ts +8 -0
  181. package/dist/types/dataValue.js +36 -0
  182. package/dist/types/dataValue.js.map +1 -0
  183. package/dist/types/graph.d.ts +8 -1
  184. package/dist/types/graph.js +8 -0
  185. package/dist/types/graph.js.map +1 -1
  186. package/dist/types/guards.d.ts +8 -0
  187. package/dist/types/guards.js +35 -0
  188. package/dist/types/guards.js.map +1 -0
  189. package/frontend-vue/app/build/components/editor/EditorBanners.vue +120 -0
  190. package/frontend-vue/app/build/components/editor/EditorChoiceModal.vue +44 -0
  191. package/frontend-vue/app/build/components/editor/EditorForkModal.vue +51 -0
  192. package/frontend-vue/app/build/components/editor/EditorHeader.vue +146 -0
  193. package/frontend-vue/app/build/components/editor/EditorSaveTemplateModal.vue +105 -0
  194. package/frontend-vue/app/build/components/editor/NodeInspectorDocs.vue +28 -0
  195. package/frontend-vue/app/build/components/editor/NodeInspectorRun.vue +48 -0
  196. package/frontend-vue/app/build/composables/editor/useBuilderMount.ts +129 -0
  197. package/frontend-vue/app/build/composables/editor/useBuilderSave.ts +256 -0
  198. package/frontend-vue/app/build/composables/editor/useBuilderShortcuts.ts +270 -0
  199. package/frontend-vue/app/build/composables/editor/useDraftProblems.ts +288 -0
  200. package/frontend-vue/app/build/composables/editor/useEditorContext.ts +388 -0
  201. package/frontend-vue/app/build/composables/editor/useEditorLoad.ts +158 -0
  202. package/frontend-vue/app/build/composables/editor/useForkToLocal.ts +193 -0
  203. package/frontend-vue/app/build/composables/editor/useGraphHistory.ts +113 -0
  204. package/frontend-vue/app/build/composables/editor/useGroupEditing.ts +445 -0
  205. package/frontend-vue/app/build/composables/editor/usePalette.ts +41 -0
  206. package/frontend-vue/app/build/composables/editor/useProcedureActions.ts +96 -0
  207. package/frontend-vue/app/build/composables/editor/useRunOverlay.ts +466 -0
  208. package/frontend-vue/app/build/composables/editor/useSaveAsTemplate.ts +172 -0
  209. package/frontend-vue/app/build/composables/editor/useSavedTriggers.ts +100 -0
  210. package/frontend-vue/app/build/composables/editor/useSubgraphNavigation.ts +270 -0
  211. package/frontend-vue/app/build/composables/editor/useUnsavedGuards.ts +233 -0
  212. package/frontend-vue/app/build/composables/graphCanvas/connect.ts +273 -0
  213. package/frontend-vue/app/build/composables/graphCanvas/edgeEvents.ts +172 -0
  214. package/frontend-vue/app/build/composables/graphCanvas/edges.ts +55 -0
  215. package/frontend-vue/app/build/composables/graphCanvas/handles.ts +181 -0
  216. package/frontend-vue/app/build/composables/graphCanvas/linkMenu.ts +123 -0
  217. package/frontend-vue/app/build/composables/graphCanvas/nodeData.ts +222 -0
  218. package/frontend-vue/app/build/composables/graphCanvas/placement.ts +248 -0
  219. package/frontend-vue/app/build/composables/graphCanvas/selection.ts +150 -0
  220. package/frontend-vue/app/build/composables/graphCanvas/types.ts +188 -0
  221. package/frontend-vue/app/build/composables/graphCanvas/view.ts +230 -0
  222. package/frontend-vue/app/build/types/editor.ts +94 -0
  223. package/frontend-vue/app/build/utils/editor/apiErrors.ts +74 -0
  224. package/frontend-vue/app/build/utils/editor/graphShape.ts +68 -0
  225. package/frontend-vue/app/build/utils/editor/groupPlan.ts +322 -0
  226. package/frontend-vue/app/build/utils/editor/groupPorts.ts +210 -0
  227. package/frontend-vue/app/build/utils/editor/keyboard.ts +22 -0
  228. package/frontend-vue/app/build/utils/inspectorFields.ts +117 -0
  229. package/frontend-vue/app/build/utils/templates.ts +88 -0
  230. package/frontend-vue/app/components/AttentionList.vue +2 -6
  231. package/frontend-vue/app/components/Catalog.vue +2 -1
  232. package/frontend-vue/app/components/Editor/GraphCanvas.vue +78 -1337
  233. package/frontend-vue/app/components/Editor/NodeInspector.vue +31 -123
  234. package/frontend-vue/app/components/Editor.vue +134 -3484
  235. package/frontend-vue/app/components/Templates.vue +14 -84
  236. package/frontend-vue/build/backend-boundary.ts +122 -0
  237. package/frontend-vue/dms.frontend.build.ts +2 -0
  238. package/frontend-vue/eslint-rules/index.mjs +103 -0
  239. package/frontend-vue/eslint.config.mjs +15 -0
  240. package/frontend-vue/package.json +7 -4
  241. package/frontend-vue/pnpm-lock.yaml +73 -59
  242. package/frontend-vue/tests/api-error-presentation.test.cjs +257 -0
  243. package/frontend-vue/tests/helpers/setup.cjs +44 -0
  244. package/package.json +4 -4
  245. package/skills/dms-automation/SKILL.md +2 -2
  246. package/skills/dms-automation/cases.json +58 -0
@@ -0,0 +1,150 @@
1
+ import type { NodeChange } from "@vue-flow/core";
2
+ import { watch, type Ref } from "vue";
3
+ import type { ProcedureGraph } from "../../../composables/useGraphConnect";
4
+ import { SENTINEL_KINDS } from "./types";
5
+ import type { CanvasEmits, CanvasProps } from "./types";
6
+
7
+ export function useCanvasSelection({
8
+ props,
9
+ emit,
10
+ canvasSelection,
11
+ emitGraph,
12
+ }: {
13
+ props: Readonly<CanvasProps>;
14
+ emit: CanvasEmits;
15
+ canvasSelection: Ref<string[]>;
16
+ emitGraph: (graph: ProcedureGraph) => void;
17
+ }) {
18
+ // Multi-selection tracking — Vue Flow emits one NodeSelectionChange per
19
+ // affected node when the user box-selects or shift-clicks. We accumulate
20
+ // the current set here and emit a single `selection-change` event with
21
+ // the full list (sentinels filtered out — the user shouldn't be able to
22
+ // fold a sentinel into a new group). The single-node `select:node` event
23
+ // is preserved for the inspector (it expects exactly one node id).
24
+ const selectedNodeIds = new Set<string>();
25
+
26
+ // Drop any tracked ids that no longer exist in the current graph (e.g.
27
+ // after navigating to a different procedure / subgraph, or after the
28
+ // "Group selection" action removes the selected nodes). Re-emit if the
29
+ // set shrank. We can't `watch(() => props.graph, ...)` because that
30
+ // fires on every node drag (each emitGraph returns a fresh object).
31
+ watch(
32
+ () => props.graph.nodes,
33
+ (nodes) => {
34
+ if (selectedNodeIds.size === 0) return;
35
+ const valid = new Set(nodes.map((n) => n.id));
36
+ let pruned = false;
37
+ for (const id of [...selectedNodeIds]) {
38
+ if (!valid.has(id)) {
39
+ selectedNodeIds.delete(id);
40
+ pruned = true;
41
+ }
42
+ }
43
+ if (pruned) {
44
+ const ids = [...selectedNodeIds].filter((id) => {
45
+ const n = nodes.find((nn) => nn.id === id);
46
+ return n ? !SENTINEL_KINDS.has(n.kind) : false;
47
+ });
48
+ canvasSelection.value = [...selectedNodeIds];
49
+ emit("selection-change", { ids });
50
+ }
51
+ },
52
+ );
53
+
54
+ function onNodesChange(changes: NodeChange[]) {
55
+ let nextNodes = props.graph.nodes;
56
+ let nextTrigger = props.graph.triggerEdges;
57
+ let nextData = props.graph.dataEdges;
58
+ let changed = false;
59
+ let selectionChanged = false;
60
+
61
+ for (const c of changes) {
62
+ // In read-only mode, still surface selection so the inspector
63
+ // can show node details; suppress position drag and delete.
64
+ if (props.readOnly && c.type !== "select") continue;
65
+ if (c.type === "position" && c.position) {
66
+ // Positions are stored as whole pixels, and a click that moves a
67
+ // node by less than one (a select, not a drag) changes nothing:
68
+ // otherwise selecting a node would count as an unsaved change.
69
+ const pos = {
70
+ x: Math.round(c.position.x),
71
+ y: Math.round(c.position.y),
72
+ };
73
+ const current = nextNodes.find((n) => n.id === c.id);
74
+ if (
75
+ current &&
76
+ current.position.x === pos.x &&
77
+ current.position.y === pos.y
78
+ )
79
+ continue;
80
+ nextNodes = nextNodes.map((n) =>
81
+ n.id === c.id ? { ...n, position: pos } : n,
82
+ );
83
+ changed = true;
84
+ } else if (c.type === "remove") {
85
+ // Sentinel nodes (groupInput / groupOutput) are auto-managed by
86
+ // the editor and never user-deletable. Drop the change silently
87
+ // so keyboard delete + right-click delete both no-op on them.
88
+ const victim = nextNodes.find((n) => n.id === c.id);
89
+ if (victim && SENTINEL_KINDS.has(victim.kind)) continue;
90
+ nextNodes = nextNodes.filter((n) => n.id !== c.id);
91
+ nextTrigger = nextTrigger.filter(
92
+ (e) => e.from.node !== c.id && e.to.node !== c.id,
93
+ );
94
+ nextData = nextData.filter(
95
+ (e) => e.from.node !== c.id && e.to.node !== c.id,
96
+ );
97
+ if (selectedNodeIds.delete(c.id)) selectionChanged = true;
98
+ changed = true;
99
+ } else if (c.type === "select") {
100
+ if (c.selected) {
101
+ if (!selectedNodeIds.has(c.id)) {
102
+ selectedNodeIds.add(c.id);
103
+ selectionChanged = true;
104
+ }
105
+ emit("select:node", c.id);
106
+ } else {
107
+ if (selectedNodeIds.delete(c.id)) selectionChanged = true;
108
+ // Re-point the single-node inspector on deselect: fall back to a
109
+ // still-selected node (most-recent), or clear it once the
110
+ // selection is empty. A click-swap fires `select: true` above in
111
+ // the same batch, which then overrides this.
112
+ const remaining = [...selectedNodeIds];
113
+ emit("select:node", remaining[remaining.length - 1] ?? null);
114
+ }
115
+ }
116
+ }
117
+
118
+ if (selectionChanged) {
119
+ // Filter out sentinels — folding them into a new group makes no
120
+ // sense and the toolbar gating depends on a clean set.
121
+ const ids = [...selectedNodeIds].filter((id) => {
122
+ const n = props.graph.nodes.find((nn) => nn.id === id);
123
+ return n ? !SENTINEL_KINDS.has(n.kind) : false;
124
+ });
125
+ canvasSelection.value = [...selectedNodeIds];
126
+ emit("selection-change", { ids });
127
+ }
128
+
129
+ if (changed) {
130
+ emitGraph({
131
+ ...props.graph,
132
+ nodes: nextNodes,
133
+ triggerEdges: nextTrigger,
134
+ dataEdges: nextData,
135
+ });
136
+ }
137
+ }
138
+
139
+ // DmsFlowCanvas's delete affordance (trash badge on the selected node + the
140
+ // Delete/Backspace key path it now owns) is emit-only: it hands us the ids and
141
+ // we perform the mutation. Route them through onNodesChange's `remove` path so
142
+ // sentinel filtering, edge cleanup, selection sync and emitGraph stay in one
143
+ // place.
144
+ function onDeleteNodes(ids: string[]) {
145
+ if (props.readOnly) return;
146
+ onNodesChange(ids.map((id) => ({ type: "remove", id }) as NodeChange));
147
+ }
148
+
149
+ return { onNodesChange, onDeleteNodes };
150
+ }
@@ -0,0 +1,188 @@
1
+ import type { Connection } from "@vue-flow/core";
2
+ import type { NodeRunState } from "../../../components/Editor/nodes/GenericNode.vue";
3
+ import type { NodeKindEntry } from "../../../composables/useAutomationNodeKinds";
4
+ import type {
5
+ ActionType,
6
+ DataNodeType,
7
+ GroupPort,
8
+ NodeKind,
9
+ ProcedureGraph,
10
+ TriggerType,
11
+ } from "../../../composables/useGraphConnect";
12
+ import type { WordedTrigger } from "../../../utils/describe";
13
+
14
+ /** The props of the graph canvas. */
15
+ export interface CanvasProps {
16
+ graph: ProcedureGraph;
17
+ triggerTypes: TriggerType[];
18
+ actionTypes: ActionType[];
19
+ dataNodeTypes: DataNodeType[];
20
+ /**
21
+ * Per-NodeKind metadata served by `/api/automation/node-kinds`. The
22
+ * `ui` block on each entry tells `dataFor` how to render the node —
23
+ * label, icon, port lists, type-registry / dynamic-config hooks. The
24
+ * frontend has zero kind-specific code beyond group + sentinels.
25
+ */
26
+ nodeKinds: NodeKindEntry[];
27
+ canUndo?: boolean;
28
+ canRedo?: boolean;
29
+ // When the canvas is showing a group's inner subgraph, these are the
30
+ // parent group's declared ports — the sentinel nodes (groupInput /
31
+ // groupOutput) render handles derived from this list rather than
32
+ // reading from their own node data. (Sentinel nodes themselves don't
33
+ // carry ports; their parent group does.) Undefined at the procedure
34
+ // root.
35
+ parentGroupPorts?: GroupPort[];
36
+ // When true, the canvas suppresses graph mutations from user input —
37
+ // used for the read-only view of template-instance inner subgraphs.
38
+ // User can still pan / zoom / select / inspect, just not connect,
39
+ // move, delete, or edit. The "Apply / Cancel" buttons are hidden too.
40
+ readOnly?: boolean;
41
+ /** Outcome of each node in the run shown over the canvas (a test run, a debugged run). */
42
+ runStates?: Record<string, NodeRunState>;
43
+ /** The problem of each node the validator named. */
44
+ issues?: Record<string, NodeIssue>;
45
+ /**
46
+ * The node the editor has selected (inspector, dock "Select node", a
47
+ * `?node=` link): the canvas selects it too and brings it into view.
48
+ */
49
+ selectedNodeId?: string | null;
50
+ /**
51
+ * Names the graph shown (the procedure, the group entered): a new key
52
+ * fits the new graph into view.
53
+ */
54
+ viewKey?: string;
55
+ /**
56
+ * An element drawn over the canvas's right edge (the inspector on narrow
57
+ * screens): fitting and centring keep the nodes out from under it.
58
+ */
59
+ coveredBy?: HTMLElement | null;
60
+ /** The draft's triggers, worded by the server: a schedule reads in words. */
61
+ triggers?: WordedTrigger[];
62
+ }
63
+
64
+ export interface NodeIssue {
65
+ severity: "error" | "warning";
66
+ message: string;
67
+ /** Problem code, translated as `dms_automation.editor.problems.codes.<code>`. */
68
+ code?: string;
69
+ params?: Record<string, unknown>;
70
+ }
71
+
72
+ /** The events of the graph canvas. */
73
+ export interface CanvasEmits {
74
+ (e: "update:graph", g: ProcedureGraph): void;
75
+ (e: "select:node", id: string | null): void;
76
+ // Fires whenever the selection set changes (single or multi). `ids` is
77
+ // the full set of currently selected node ids in this canvas — used by
78
+ // Editor.vue to drive the "Group selection" toolbar action. Sentinel
79
+ // nodes (groupInput / groupOutput) are filtered out before emitting.
80
+ (e: "selection-change", payload: { ids: string[] }): void;
81
+ (e: "undo"): void;
82
+ (e: "redo"): void;
83
+ // Bubbles up GroupNode's @dblclick — Editor.vue uses this to push the
84
+ // group onto the subgraph navigation path. Filtered by kind here so
85
+ // the parent doesn't need to look the node up itself.
86
+ (e: "group:enter", payload: { id: string }): void;
87
+ }
88
+
89
+ /** The translators the canvas gets from the host, handed to its helpers. */
90
+ export interface CanvasText {
91
+ t: ReturnType<typeof useI18n>["t"];
92
+ te: ReturnType<typeof useI18n>["te"];
93
+ processI18n: ReturnType<typeof useTranslation>["processI18n"];
94
+ processText: ReturnType<typeof useComposedText>["processText"];
95
+ }
96
+
97
+ // The node to select and bring into view once drawn: one just added, or one
98
+ // the editor points at (`readable`).
99
+ export interface Reveal {
100
+ pending: { id: string; readable: boolean } | null;
101
+ }
102
+
103
+ // Fit view never zooms past 100% (a lone trigger would fill the canvas) and
104
+ // may go down to 10% so a large graph fits whole.
105
+ export const FIT_PADDING = 0.15;
106
+ export const FIT_MAX_ZOOM = 1;
107
+ export const MIN_ZOOM = 0.1;
108
+ export const MAX_ZOOM = 1.5;
109
+ // Room left around a new node, and the size assumed for a node not drawn
110
+ // yet (GenericNode's width, a typical height).
111
+ export const NODE_GAP = 60;
112
+ export const NEW_NODE_SIZE = { width: 230, height: 90 };
113
+
114
+ // Sentinel node kinds — only valid inside a group's subgraph and never
115
+ // user-deletable. We filter them out of keyboard/right-click delete in
116
+ // onNodesChange below.
117
+ export const SENTINEL_KINDS: ReadonlySet<NodeKind> = new Set<NodeKind>([
118
+ "groupInput",
119
+ "groupOutput",
120
+ ]);
121
+
122
+ export interface XY {
123
+ x: number;
124
+ y: number;
125
+ }
126
+
127
+ export interface Rect extends XY {
128
+ width: number;
129
+ height: number;
130
+ }
131
+
132
+ export interface Port {
133
+ /** Vue Flow handle id. */
134
+ id: string;
135
+ /** Port name ('' for the single trigger input of a step). */
136
+ name: string;
137
+ }
138
+
139
+ export interface NodeHandles {
140
+ triggerIns: Port[];
141
+ triggerOuts: Port[];
142
+ dataIns: Port[];
143
+ dataOuts: Port[];
144
+ }
145
+
146
+ export interface LinkItem {
147
+ label: string;
148
+ connection: Connection;
149
+ }
150
+
151
+ // DmsFlowCanvas owns the VueFlow store (it calls `useVueFlow(flowId)` with a
152
+ // private id and `defineExpose`s the resulting controller). We grab that
153
+ // controller through a template ref instead of calling `useVueFlow()` here —
154
+ // a bare `useVueFlow()` would resolve to the DEFAULT store, which is NOT the
155
+ // one DmsFlowCanvas drives, so zoom/fit/updateNodeInternals would silently
156
+ // no-op. Only the handful of imperative methods we actually use are typed.
157
+ export interface FlowNodeState {
158
+ id: string;
159
+ selected?: boolean;
160
+ computedPosition: XY;
161
+ dimensions: { width: number; height: number };
162
+ }
163
+
164
+ export interface FlowController {
165
+ zoomIn: () => void;
166
+ zoomOut: () => void;
167
+ zoomTo: (zoom: number) => void;
168
+ setViewport: (
169
+ viewport: XY & { zoom: number },
170
+ options?: { duration?: number },
171
+ ) => Promise<boolean>;
172
+ screenToFlowCoordinate: (position: XY) => XY;
173
+ findNode: (id: string) => FlowNodeState | undefined;
174
+ addSelectedNodes: (nodes: FlowNodeState[]) => void;
175
+ removeSelectedNodes: (nodes: FlowNodeState[]) => void;
176
+ updateNodeInternals: (ids?: string | string[]) => void;
177
+ // DmsFlowCanvas `defineExpose`s the VueFlow controller; Vue's expose proxy
178
+ // unwraps the `viewport` ref, so consumers read `.viewport.zoom` directly
179
+ // (NOT `.viewport.value.zoom` — that extra `.value` is undefined and pinned
180
+ // the zoom readout at 100%). Same for the refs below.
181
+ viewport: XY & { zoom: number };
182
+ /** Size of the canvas on screen. */
183
+ dimensions: { width: number; height: number };
184
+ getSelectedNodes: FlowNodeState[];
185
+ getSelectedEdges: Array<{ id: string }>;
186
+ /** 'invalid' while the link being drawn hovers a port that refuses it. */
187
+ connectionStatus: "valid" | "invalid" | null;
188
+ }
@@ -0,0 +1,230 @@
1
+ import { computed, nextTick, watch, type Ref } from "vue";
2
+ import type { GraphNode as AppGraphNode } from "../../../composables/useGraphConnect";
3
+ import { FIT_MAX_ZOOM, FIT_PADDING, MIN_ZOOM } from "./types";
4
+ import type {
5
+ CanvasProps,
6
+ FlowController,
7
+ FlowNodeState,
8
+ Reveal,
9
+ } from "./types";
10
+
11
+ export function useCanvasView({
12
+ props,
13
+ flowRef,
14
+ wrapRef,
15
+ reveal,
16
+ }: {
17
+ props: Readonly<CanvasProps>;
18
+ flowRef: Ref<FlowController | null>;
19
+ wrapRef: Ref<HTMLElement | null>;
20
+ reveal: Reveal;
21
+ }) {
22
+ // The width of the canvas the inspector covers when it is drawn over it.
23
+ function coveredRight(): number {
24
+ const cover = props.coveredBy?.getBoundingClientRect();
25
+ const own = wrapRef.value?.getBoundingClientRect();
26
+ if (!cover?.width || !own) return 0;
27
+ return Math.max(
28
+ 0,
29
+ Math.min(own.right, cover.right) - Math.max(own.left, cover.left),
30
+ );
31
+ }
32
+
33
+ // Fit every node into the part of the canvas left visible.
34
+ function fitView() {
35
+ const flow = flowRef.value;
36
+ if (!flow) return;
37
+ const nodes = props.graph.nodes
38
+ .map((n) => flow.findNode(n.id))
39
+ .filter((n): n is FlowNodeState => !!n?.dimensions.width);
40
+ if (nodes.length === 0) return;
41
+ const left = Math.min(...nodes.map((n) => n.computedPosition.x));
42
+ const top = Math.min(...nodes.map((n) => n.computedPosition.y));
43
+ const width =
44
+ Math.max(...nodes.map((n) => n.computedPosition.x + n.dimensions.width)) -
45
+ left;
46
+ const height =
47
+ Math.max(
48
+ ...nodes.map((n) => n.computedPosition.y + n.dimensions.height),
49
+ ) - top;
50
+ const visible = flow.dimensions.width - coveredRight();
51
+ const room = 1 + FIT_PADDING;
52
+ const fit = Math.min(
53
+ visible / (width * room),
54
+ flow.dimensions.height / (height * room),
55
+ );
56
+ const zoom = Math.min(Math.max(fit, MIN_ZOOM), FIT_MAX_ZOOM);
57
+ flow.setViewport({
58
+ x: (visible - width * zoom) / 2 - left * zoom,
59
+ y: (flow.dimensions.height - height * zoom) / 2 - top * zoom,
60
+ zoom,
61
+ });
62
+ }
63
+
64
+ // Select a node and bring it into the visible part of the canvas. A node the
65
+ // editor points at (a link, a problem) is also shown at a readable zoom; a
66
+ // new node keeps the zoom.
67
+ function focusNode(id: string, readable = false) {
68
+ const flow = flowRef.value;
69
+ const node = flow?.findNode(id);
70
+ if (!flow || !node) return;
71
+ if (!node.selected) flow.addSelectedNodes([node]);
72
+ // Selecting opens the inspector, which narrows or covers the canvas:
73
+ // look once it is drawn (two frames).
74
+ requestAnimationFrame(() =>
75
+ requestAnimationFrame(() => panTo(id, readable)),
76
+ );
77
+ }
78
+
79
+ function panTo(id: string, readable: boolean) {
80
+ const flow = flowRef.value;
81
+ const node = flow?.findNode(id);
82
+ if (!flow || !node) return;
83
+ const visible = flow.dimensions.width - coveredRight();
84
+ const zoom = readable
85
+ ? Math.max(flow.viewport.zoom, 1)
86
+ : flow.viewport.zoom;
87
+ const left = node.computedPosition.x * zoom + flow.viewport.x;
88
+ const top = node.computedPosition.y * zoom + flow.viewport.y;
89
+ const inSight =
90
+ left >= 0 &&
91
+ top >= 0 &&
92
+ left + node.dimensions.width * zoom <= visible &&
93
+ top + node.dimensions.height * zoom <= flow.dimensions.height;
94
+ if (inSight && zoom === flow.viewport.zoom) return;
95
+ flow.setViewport(
96
+ {
97
+ x:
98
+ visible / 2 -
99
+ (node.computedPosition.x + node.dimensions.width / 2) * zoom,
100
+ y:
101
+ flow.dimensions.height / 2 -
102
+ (node.computedPosition.y + node.dimensions.height / 2) * zoom,
103
+ zoom,
104
+ },
105
+ // A node pointed at is shown at once; a new one slides into view.
106
+ { duration: readable ? 0 : 200 },
107
+ );
108
+ }
109
+
110
+ // A new graph on the canvas (first load, another procedure, a group entered
111
+ // or left) is fitted into view; a node just added or pointed at is shown.
112
+ // Both wait until every node is measured and the panels around the canvas
113
+ // have settled (two frames): Vue Flow keeps the measures of nodes whose id
114
+ // the previous graph shared, so it does not always report them again.
115
+ let fitPending = true;
116
+ let settleQueued = false;
117
+
118
+ function settleView() {
119
+ if (settleQueued) return;
120
+ settleQueued = true;
121
+ requestAnimationFrame(() =>
122
+ requestAnimationFrame(() => {
123
+ settleQueued = false;
124
+ const flow = flowRef.value;
125
+ if (
126
+ !flow ||
127
+ !props.graph.nodes.every((n) => flow.findNode(n.id)?.dimensions.width)
128
+ )
129
+ return;
130
+ if (fitPending) {
131
+ fitPending = false;
132
+ fitView();
133
+ // The node the editor points at stays the one shown.
134
+ if (props.selectedNodeId)
135
+ reveal.pending ??= { id: props.selectedNodeId, readable: true };
136
+ }
137
+ if (reveal.pending) {
138
+ const { id, readable } = reveal.pending;
139
+ reveal.pending = null;
140
+ focusNode(id, readable);
141
+ }
142
+ }),
143
+ );
144
+ }
145
+
146
+ // Vue Flow emits this once every node on the canvas has been measured.
147
+ function onNodesInitialized() {
148
+ settleView();
149
+ }
150
+
151
+ watch(
152
+ () => props.viewKey,
153
+ () => {
154
+ fitPending = true;
155
+ nextTick(settleView);
156
+ },
157
+ );
158
+
159
+ watch(
160
+ () => props.selectedNodeId,
161
+ (id) => {
162
+ const flow = flowRef.value;
163
+ // The editor closed its inspector: the canvas lets go of the node too.
164
+ if (!id) {
165
+ if (flow?.getSelectedNodes.length)
166
+ flow.removeSelectedNodes(flow.getSelectedNodes);
167
+ return;
168
+ }
169
+ // A node selected on the canvas itself is already where the user looks.
170
+ if (flow?.findNode(id)?.selected) return;
171
+ reveal.pending = { id, readable: true };
172
+ nextTick(settleView);
173
+ },
174
+ // The editor may name a node (a `?node=` link) before the canvas exists.
175
+ { immediate: true },
176
+ );
177
+
178
+ // Vue Flow caches each node's handle bounding boxes in its internal store and
179
+ // only re-measures when `updateNodeInternals(id)` is called. When a port is
180
+ // renamed or moved between the title bar and body (e.g. renaming a port to
181
+ // "main" moves the handle from a body row into the header), the Handle DOM
182
+ // element ends up in a different on-screen position but the cached bbox stays
183
+ // stale — connected edges keep drawing to the OLD coordinates until the next
184
+ // re-measure.
185
+ //
186
+ // To keep edges glued to handles, watch a signature derived from the per-node
187
+ // port lists / kinds and force a re-measure of every node after the DOM has
188
+ // applied the new template. Watching the full `props.graph` would fire on
189
+ // every drag (each emitGraph returns a fresh object) — costly and pointless,
190
+ // since node positions trigger their own internal updates already. The
191
+ // signature only changes when port shape changes, which is exactly when we
192
+ // need to re-measure.
193
+ const portsSignature = computed(() => {
194
+ const own = props.graph.nodes
195
+ .map((n) => {
196
+ const ports = (n as AppGraphNode & { ports?: unknown }).ports;
197
+ const portsKey = Array.isArray(ports) ? JSON.stringify(ports) : "";
198
+ return `${n.id}:${n.kind}:${portsKey}`;
199
+ })
200
+ .join("|");
201
+ // Sentinel nodes (groupInput / groupOutput) inside this canvas render
202
+ // handles derived from `parentGroupPorts`, not from their own node data.
203
+ // A rename on the outer group's port list re-renders the sentinel but
204
+ // doesn't show up in `props.graph.nodes` above, so we must also fold
205
+ // the parent ports into the signature.
206
+ const parent = Array.isArray(props.parentGroupPorts)
207
+ ? JSON.stringify(props.parentGroupPorts)
208
+ : "";
209
+ return `${own}#${parent}`;
210
+ });
211
+
212
+ watch(portsSignature, () => {
213
+ nextTick(() => {
214
+ for (const node of props.graph.nodes) {
215
+ flowRef.value?.updateNodeInternals(node.id);
216
+ }
217
+ });
218
+ });
219
+
220
+ const zoomPercent = computed(() => {
221
+ const zoom = flowRef.value?.viewport.zoom ?? 1;
222
+ return `${Math.round(zoom * 100)}%`;
223
+ });
224
+
225
+ function resetZoom() {
226
+ flowRef.value?.zoomTo(1);
227
+ }
228
+
229
+ return { fitView, onNodesInitialized, zoomPercent, resetZoom };
230
+ }
@@ -0,0 +1,94 @@
1
+ import type { WordedTrigger } from "../../utils/describe";
2
+ import type {
3
+ GroupPort,
4
+ GraphNode,
5
+ ProcedureGraph,
6
+ } from "../../composables/useGraphConnect";
7
+
8
+ export interface ProcedureRecord {
9
+ _id: string;
10
+ name: string;
11
+ description: string;
12
+ enabled: boolean;
13
+ graph: ProcedureGraph;
14
+ // The graph's version (it moves with the graph only), and the revision
15
+ // (it moves with every write: a save, a pause from the list). A save sends
16
+ // the revision it started from back, so the server refuses to overwrite
17
+ // what was written elsewhere in the meantime.
18
+ version?: number;
19
+ revision?: number;
20
+ }
21
+
22
+ // Subgraph navigation stack. The first entry is always the procedure root;
23
+ // each subsequent entry is a group / template segment the user has entered.
24
+ // Cleared and re-seeded whenever the selected procedure changes (see the
25
+ // watch on selectedId below).
26
+ //
27
+ // kind === 'procedure' — id is the procedure _id, name is its display name.
28
+ // kind === 'group' — id is the group node's id within its parent graph.
29
+ // kind === 'template' — reserved for the dedicated template editor view.
30
+ // Navigation into local groups pushes as 'group';
31
+ // template instances likewise push as 'group' with
32
+ // the read-only signal taken from the node having a
33
+ // templateId, not from the path kind.
34
+ export interface SubgraphPathSegment {
35
+ kind: "procedure" | "group" | "template";
36
+ id: string;
37
+ name: string;
38
+ }
39
+
40
+ export interface ProcedureSnapshot {
41
+ name: string;
42
+ enabled: boolean;
43
+ graph: ProcedureGraph;
44
+ // Template mode only: the template's outer ports, edited at its root.
45
+ ports?: GroupPort[];
46
+ }
47
+
48
+ // Walk the procedure graph following subgraphPath. Returns the full chain
49
+ // of (segment, containerGraph, groupNode|null) so currentGraph and
50
+ // currentParentGroupPorts can be derived from one traversal without
51
+ // re-walking.
52
+ //
53
+ // If a path segment can't be resolved (e.g. the group node was deleted in
54
+ // the outer graph), traversal stops at the last valid level — the caller
55
+ // is expected to also watch the stale path and trim it (see the watch on
56
+ // `selected.graph`).
57
+ export interface SubgraphFrame {
58
+ segment: SubgraphPathSegment;
59
+ graph: ProcedureGraph;
60
+ // The group node that owns `graph` (i.e. graph === groupNode.subgraph).
61
+ // Null for the procedure root.
62
+ groupNode: GraphNode | null;
63
+ }
64
+
65
+ // Problems of the draft, asked of the server (the same validator a save
66
+ // runs) a moment after each change.
67
+ // Each issue carries a `code` (and its `params`) the locale words; its English
68
+ // `message` is the fallback for a code the locale does not know.
69
+ export interface GraphIssue {
70
+ severity: "error" | "warning";
71
+ message: string;
72
+ code?: string;
73
+ params?: Record<string, unknown>;
74
+ nodeId?: string;
75
+ }
76
+
77
+ export interface ProcedureTriggers {
78
+ triggers: Array<WordedTrigger & { nextAt: string | null }>;
79
+ }
80
+
81
+ export interface Choice<C extends string> {
82
+ value: C;
83
+ label: string;
84
+ color?: "primary" | "neutral" | "error" | "warning";
85
+ variant?: "solid" | "outline" | "ghost" | "soft";
86
+ }
87
+
88
+ export interface ChoiceQuestion<C extends string> {
89
+ title: string;
90
+ description: string;
91
+ choices: Choice<C>[];
92
+ /** The answer of a dialog closed without choosing (Escape, ✕, a click outside). */
93
+ dismiss: C;
94
+ }