@antelopejs/dms-automation 0.6.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 (262) hide show
  1. package/README.md +21 -7
  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 -16
  9. package/dist/data/procedures-table.js +12 -101
  10. package/dist/data/procedures-table.js.map +1 -1
  11. package/dist/data/runs-table.js +0 -5
  12. package/dist/data/runs-table.js.map +1 -1
  13. package/dist/db/models/automation_template.model.d.ts +2 -4
  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_run.model.js.map +1 -1
  17. package/dist/db/models/stats.model.js.map +1 -1
  18. package/dist/db/tables/procedure.table.d.ts +0 -1
  19. package/dist/db/tables/procedure.table.js +0 -4
  20. package/dist/db/tables/procedure.table.js.map +1 -1
  21. package/dist/db/tables/procedure_run.table.d.ts +2 -1
  22. package/dist/db/tables/procedure_run.table.js.map +1 -1
  23. package/dist/implementations/dms-automation/index.js.map +1 -1
  24. package/dist/index.js.map +1 -1
  25. package/dist/pages/category.js.map +1 -1
  26. package/dist/pages/index.js.map +1 -1
  27. package/dist/pages/overview.js.map +1 -1
  28. package/dist/pages/procedures.js.map +1 -1
  29. package/dist/pages/runs.js.map +1 -1
  30. package/dist/pages/shared.js +1 -1
  31. package/dist/pages/shared.js.map +1 -1
  32. package/dist/realtime.d.ts +2 -1
  33. package/dist/realtime.js.map +1 -1
  34. package/dist/routes/action-types.d.ts +2 -1
  35. package/dist/routes/action-types.js.map +1 -1
  36. package/dist/routes/deleteConfirm.js +4 -3
  37. package/dist/routes/deleteConfirm.js.map +1 -1
  38. package/dist/routes/graphSchema.d.ts +2 -1
  39. package/dist/routes/graphSchema.js +8 -7
  40. package/dist/routes/graphSchema.js.map +1 -1
  41. package/dist/routes/procedureChecks.js +5 -5
  42. package/dist/routes/procedureChecks.js.map +1 -1
  43. package/dist/routes/procedureRuns.d.ts +2 -2
  44. package/dist/routes/procedureRuns.js +1 -1
  45. package/dist/routes/procedureRuns.js.map +1 -1
  46. package/dist/routes/procedures.d.ts +14 -15
  47. package/dist/routes/procedures.js +2 -1
  48. package/dist/routes/procedures.js.map +1 -1
  49. package/dist/routes/requests.d.ts +11 -5
  50. package/dist/routes/requests.js.map +1 -1
  51. package/dist/routes/runs.d.ts +7 -7
  52. package/dist/routes/runs.js +5 -3
  53. package/dist/routes/runs.js.map +1 -1
  54. package/dist/routes/stats.js.map +1 -1
  55. package/dist/routes/templates.d.ts +3 -2
  56. package/dist/routes/templates.js +2 -1
  57. package/dist/routes/templates.js.map +1 -1
  58. package/dist/routes/trigger-types.d.ts +2 -1
  59. package/dist/routes/trigger-types.js.map +1 -1
  60. package/dist/routes/typeConfigShared.d.ts +2 -1
  61. package/dist/routes/typeConfigShared.js.map +1 -1
  62. package/dist/runtime/armErrors.d.ts +0 -1
  63. package/dist/runtime/armErrors.js +0 -7
  64. package/dist/runtime/armErrors.js.map +1 -1
  65. package/dist/runtime/boundRunLog.d.ts +1 -0
  66. package/dist/runtime/boundRunLog.js +11 -11
  67. package/dist/runtime/boundRunLog.js.map +1 -1
  68. package/dist/runtime/builtins/actions/http.js +16 -9
  69. package/dist/runtime/builtins/actions/http.js.map +1 -1
  70. package/dist/runtime/builtins/actions/log.js.map +1 -1
  71. package/dist/runtime/builtins/data/boolean.js +4 -5
  72. package/dist/runtime/builtins/data/boolean.js.map +1 -1
  73. package/dist/runtime/builtins/data/compare.js +8 -10
  74. package/dist/runtime/builtins/data/compare.js.map +1 -1
  75. package/dist/runtime/builtins/data/constant.js +1 -1
  76. package/dist/runtime/builtins/data/constant.js.map +1 -1
  77. package/dist/runtime/builtins/data/json.js +4 -5
  78. package/dist/runtime/builtins/data/json.js.map +1 -1
  79. package/dist/runtime/builtins/data/math.js +4 -4
  80. package/dist/runtime/builtins/data/math.js.map +1 -1
  81. package/dist/runtime/builtins/data/object.js +12 -17
  82. package/dist/runtime/builtins/data/object.js.map +1 -1
  83. package/dist/runtime/builtins/data/string.js +13 -18
  84. package/dist/runtime/builtins/data/string.js.map +1 -1
  85. package/dist/runtime/builtins/nodes/action.js +5 -2
  86. package/dist/runtime/builtins/nodes/action.js.map +1 -1
  87. package/dist/runtime/builtins/nodes/data.js +2 -2
  88. package/dist/runtime/builtins/nodes/data.js.map +1 -1
  89. package/dist/runtime/builtins/nodes/delay.js +2 -2
  90. package/dist/runtime/builtins/nodes/delay.js.map +1 -1
  91. package/dist/runtime/builtins/nodes/forRange.js +2 -2
  92. package/dist/runtime/builtins/nodes/forRange.js.map +1 -1
  93. package/dist/runtime/builtins/nodes/foreach.js +2 -2
  94. package/dist/runtime/builtins/nodes/foreach.js.map +1 -1
  95. package/dist/runtime/builtins/nodes/groupInput.js +2 -2
  96. package/dist/runtime/builtins/nodes/groupInput.js.map +1 -1
  97. package/dist/runtime/builtins/nodes/groupOutput.js +2 -2
  98. package/dist/runtime/builtins/nodes/groupOutput.js.map +1 -1
  99. package/dist/runtime/builtins/nodes/if.js +2 -2
  100. package/dist/runtime/builtins/nodes/if.js.map +1 -1
  101. package/dist/runtime/builtins/nodes/parallel.js +2 -2
  102. package/dist/runtime/builtins/nodes/parallel.js.map +1 -1
  103. package/dist/runtime/builtins/nodes/retry.js +5 -6
  104. package/dist/runtime/builtins/nodes/retry.js.map +1 -1
  105. package/dist/runtime/builtins/nodes/setVariable.js +2 -2
  106. package/dist/runtime/builtins/nodes/setVariable.js.map +1 -1
  107. package/dist/runtime/builtins/nodes/switch.js +2 -2
  108. package/dist/runtime/builtins/nodes/switch.js.map +1 -1
  109. package/dist/runtime/builtins/nodes/trigger.js +2 -2
  110. package/dist/runtime/builtins/nodes/trigger.js.map +1 -1
  111. package/dist/runtime/builtins/nodes/tryCatch.js +2 -4
  112. package/dist/runtime/builtins/nodes/tryCatch.js.map +1 -1
  113. package/dist/runtime/builtins/triggers/cron.d.ts +2 -1
  114. package/dist/runtime/builtins/triggers/cron.js +5 -7
  115. package/dist/runtime/builtins/triggers/cron.js.map +1 -1
  116. package/dist/runtime/builtins/triggers/webhook.d.ts +6 -5
  117. package/dist/runtime/builtins/triggers/webhook.js +9 -6
  118. package/dist/runtime/builtins/triggers/webhook.js.map +1 -1
  119. package/dist/runtime/declaredProcedures.d.ts +2 -2
  120. package/dist/runtime/declaredProcedures.js +17 -92
  121. package/dist/runtime/declaredProcedures.js.map +1 -1
  122. package/dist/runtime/describe.js +11 -10
  123. package/dist/runtime/describe.js.map +1 -1
  124. package/dist/runtime/executionResult.d.ts +1 -1
  125. package/dist/runtime/executor.js +12 -38
  126. package/dist/runtime/executor.js.map +1 -1
  127. package/dist/runtime/flatten.d.ts +1 -1
  128. package/dist/runtime/flatten.js +1 -1
  129. package/dist/runtime/flatten.js.map +1 -1
  130. package/dist/runtime/graphIssues.js +24 -22
  131. package/dist/runtime/graphIssues.js.map +1 -1
  132. package/dist/runtime/graphVersion.d.ts +1 -1
  133. package/dist/runtime/graphVersion.js +2 -1
  134. package/dist/runtime/graphVersion.js.map +1 -1
  135. package/dist/runtime/nodeKinds.d.ts +3 -2
  136. package/dist/runtime/nodeKinds.js.map +1 -1
  137. package/dist/runtime/reconcile.d.ts +3 -0
  138. package/dist/runtime/reconcile.js +178 -0
  139. package/dist/runtime/reconcile.js.map +1 -0
  140. package/dist/runtime/registry.d.ts +0 -7
  141. package/dist/runtime/registry.js +3 -24
  142. package/dist/runtime/registry.js.map +1 -1
  143. package/dist/runtime/resolveInputs.d.ts +4 -2
  144. package/dist/runtime/resolveInputs.js +13 -12
  145. package/dist/runtime/resolveInputs.js.map +1 -1
  146. package/dist/runtime/resolveSubgraph.js +4 -5
  147. package/dist/runtime/resolveSubgraph.js.map +1 -1
  148. package/dist/runtime/retention.js.map +1 -1
  149. package/dist/runtime/runProcedure.d.ts +1 -1
  150. package/dist/runtime/runProcedure.js +2 -1
  151. package/dist/runtime/runProcedure.js.map +1 -1
  152. package/dist/runtime/schedule.js +3 -0
  153. package/dist/runtime/schedule.js.map +1 -1
  154. package/dist/runtime/schemaProperties.d.ts +11 -0
  155. package/dist/runtime/schemaProperties.js +7 -0
  156. package/dist/runtime/schemaProperties.js.map +1 -0
  157. package/dist/runtime/serialQueue.d.ts +1 -1
  158. package/dist/runtime/serialQueue.js +4 -4
  159. package/dist/runtime/serialQueue.js.map +1 -1
  160. package/dist/runtime/subscriptions.js +21 -183
  161. package/dist/runtime/subscriptions.js.map +1 -1
  162. package/dist/runtime/subwalk.js.map +1 -1
  163. package/dist/runtime/templateCacheState.d.ts +6 -0
  164. package/dist/runtime/templateCacheState.js +10 -0
  165. package/dist/runtime/templateCacheState.js.map +1 -0
  166. package/dist/runtime/templateUsages.js +4 -5
  167. package/dist/runtime/templateUsages.js.map +1 -1
  168. package/dist/runtime/topo.js +2 -4
  169. package/dist/runtime/topo.js.map +1 -1
  170. package/dist/runtime/trace.js +12 -9
  171. package/dist/runtime/trace.js.map +1 -1
  172. package/dist/runtime/triggerHandles.d.ts +3 -0
  173. package/dist/runtime/triggerHandles.js +8 -3
  174. package/dist/runtime/triggerHandles.js.map +1 -1
  175. package/dist/runtime/typeOrigin.js +12 -1
  176. package/dist/runtime/typeOrigin.js.map +1 -1
  177. package/dist/runtime/validate.js.map +1 -1
  178. package/dist/runtime/validateTemplate.js.map +1 -1
  179. package/dist/runtime/withTimeout.js.map +1 -1
  180. package/dist/runtime/wording.js +12 -8
  181. package/dist/runtime/wording.js.map +1 -1
  182. package/dist/stats/health-banner.js.map +1 -1
  183. package/dist/stats/health.js +2 -3
  184. package/dist/stats/health.js.map +1 -1
  185. package/dist/stats/kpi.js +1 -1
  186. package/dist/stats/kpi.js.map +1 -1
  187. package/dist/stats/overview.js +2 -1
  188. package/dist/stats/overview.js.map +1 -1
  189. package/dist/types/dataValue.d.ts +8 -0
  190. package/dist/types/dataValue.js +36 -0
  191. package/dist/types/dataValue.js.map +1 -0
  192. package/dist/types/graph.d.ts +8 -1
  193. package/dist/types/graph.js +8 -0
  194. package/dist/types/graph.js.map +1 -1
  195. package/dist/types/guards.d.ts +8 -0
  196. package/dist/types/guards.js +35 -0
  197. package/dist/types/guards.js.map +1 -0
  198. package/frontend-vue/app/build/components/editor/EditorBanners.vue +120 -0
  199. package/frontend-vue/app/build/components/editor/EditorChoiceModal.vue +44 -0
  200. package/frontend-vue/app/build/components/editor/EditorForkModal.vue +51 -0
  201. package/frontend-vue/app/build/components/editor/EditorHeader.vue +146 -0
  202. package/frontend-vue/app/build/components/editor/EditorSaveTemplateModal.vue +105 -0
  203. package/frontend-vue/app/build/components/editor/NodeInspectorDocs.vue +28 -0
  204. package/frontend-vue/app/build/components/editor/NodeInspectorRun.vue +48 -0
  205. package/frontend-vue/app/build/composables/editor/useBuilderMount.ts +129 -0
  206. package/frontend-vue/app/build/composables/editor/useBuilderSave.ts +256 -0
  207. package/frontend-vue/app/build/composables/editor/useBuilderShortcuts.ts +270 -0
  208. package/frontend-vue/app/build/composables/editor/useDraftProblems.ts +288 -0
  209. package/frontend-vue/app/build/composables/editor/useEditorContext.ts +388 -0
  210. package/frontend-vue/app/build/composables/editor/useEditorLoad.ts +158 -0
  211. package/frontend-vue/app/build/composables/editor/useForkToLocal.ts +193 -0
  212. package/frontend-vue/app/build/composables/editor/useGraphHistory.ts +113 -0
  213. package/frontend-vue/app/build/composables/editor/useGroupEditing.ts +445 -0
  214. package/frontend-vue/app/build/composables/editor/usePalette.ts +41 -0
  215. package/frontend-vue/app/build/composables/editor/useProcedureActions.ts +96 -0
  216. package/frontend-vue/app/build/composables/editor/useRunOverlay.ts +466 -0
  217. package/frontend-vue/app/build/composables/editor/useSaveAsTemplate.ts +172 -0
  218. package/frontend-vue/app/build/composables/editor/useSavedTriggers.ts +100 -0
  219. package/frontend-vue/app/build/composables/editor/useSubgraphNavigation.ts +270 -0
  220. package/frontend-vue/app/build/composables/editor/useUnsavedGuards.ts +233 -0
  221. package/frontend-vue/app/build/composables/graphCanvas/connect.ts +273 -0
  222. package/frontend-vue/app/build/composables/graphCanvas/edgeEvents.ts +172 -0
  223. package/frontend-vue/app/build/composables/graphCanvas/edges.ts +55 -0
  224. package/frontend-vue/app/build/composables/graphCanvas/handles.ts +181 -0
  225. package/frontend-vue/app/build/composables/graphCanvas/linkMenu.ts +123 -0
  226. package/frontend-vue/app/build/composables/graphCanvas/nodeData.ts +222 -0
  227. package/frontend-vue/app/build/composables/graphCanvas/placement.ts +248 -0
  228. package/frontend-vue/app/build/composables/graphCanvas/selection.ts +150 -0
  229. package/frontend-vue/app/build/composables/graphCanvas/types.ts +188 -0
  230. package/frontend-vue/app/build/composables/graphCanvas/view.ts +230 -0
  231. package/frontend-vue/app/build/types/editor.ts +94 -0
  232. package/frontend-vue/app/build/utils/editor/apiErrors.ts +74 -0
  233. package/frontend-vue/app/build/utils/editor/graphShape.ts +68 -0
  234. package/frontend-vue/app/build/utils/editor/groupPlan.ts +322 -0
  235. package/frontend-vue/app/build/utils/editor/groupPorts.ts +210 -0
  236. package/frontend-vue/app/build/utils/editor/keyboard.ts +22 -0
  237. package/frontend-vue/app/build/utils/inspectorFields.ts +117 -0
  238. package/frontend-vue/app/build/utils/templates.ts +88 -0
  239. package/frontend-vue/app/components/AttentionList.vue +2 -6
  240. package/frontend-vue/app/components/Catalog.vue +2 -1
  241. package/frontend-vue/app/components/Editor/BottomDock.vue +0 -3
  242. package/frontend-vue/app/components/Editor/GraphCanvas.vue +78 -1337
  243. package/frontend-vue/app/components/Editor/NodeInspector.vue +31 -123
  244. package/frontend-vue/app/components/Editor.vue +134 -3490
  245. package/frontend-vue/app/components/Templates.vue +14 -84
  246. package/frontend-vue/app/composables/useAutomationRuns.ts +2 -2
  247. package/frontend-vue/build/backend-boundary.ts +122 -0
  248. package/frontend-vue/dms.frontend.build.ts +2 -0
  249. package/frontend-vue/eslint-rules/index.mjs +103 -0
  250. package/frontend-vue/eslint.config.mjs +15 -0
  251. package/frontend-vue/i18n/locales/dms-automation-en-GB.json +0 -3
  252. package/frontend-vue/i18n/locales/dms-automation-fr-FR.json +0 -3
  253. package/frontend-vue/package.json +7 -4
  254. package/frontend-vue/pnpm-lock.yaml +98 -68
  255. package/frontend-vue/tests/api-error-presentation.test.cjs +257 -0
  256. package/frontend-vue/tests/helpers/setup.cjs +44 -0
  257. package/package.json +10 -10
  258. package/skills/dms-automation/SKILL.md +4 -4
  259. package/skills/dms-automation/cases.json +58 -0
  260. package/dist/runtime/departed.d.ts +0 -6
  261. package/dist/runtime/departed.js +0 -38
  262. package/dist/runtime/departed.js.map +0 -1
@@ -0,0 +1,445 @@
1
+ import { computed, nextTick } from "vue";
2
+ import type { EditorContext } from "./useEditorContext";
3
+ import type {
4
+ GraphNode,
5
+ GroupPort,
6
+ ProcedureGraph,
7
+ } from "../../../composables/useGraphConnect";
8
+ import { newId } from "../../../utils/automation";
9
+ import { cloneGraph } from "../../utils/editor/graphShape";
10
+ import {
11
+ applyPortRenamesToEdges,
12
+ detectPortRenames,
13
+ syncSentinels,
14
+ } from "../../utils/editor/groupPorts";
15
+ import { planNewGroup } from "../../utils/editor/groupPlan";
16
+ import type { SubgraphNavigation } from "./useSubgraphNavigation";
17
+
18
+ /** The edits the builder makes to the groups and the steps of the open graph. */
19
+ export function useGroupEditing(ctx: EditorContext, nav: SubgraphNavigation) {
20
+ const {
21
+ actionTypes,
22
+ currentGraph,
23
+ dataNodeTypes,
24
+ editorMode,
25
+ inspectorRef,
26
+ isCurrentGraphReadOnly,
27
+ nodeKinds,
28
+ selected,
29
+ selectedNode,
30
+ selectedNodeId,
31
+ selectedNodeIds,
32
+ subgraphPath,
33
+ t,
34
+ templatePorts,
35
+ triggerTypes,
36
+ } = ctx;
37
+ const { onGraphUpdate, onUpdateNode } = nav;
38
+
39
+ const schemaSources = {
40
+ currentGraph,
41
+ nodeKinds,
42
+ triggerTypes,
43
+ actionTypes,
44
+ dataNodeTypes,
45
+ };
46
+
47
+ function onPortsUpdate(payload: { nodeId: string; ports: GroupPort[] }) {
48
+ const g = currentGraph.value;
49
+ if (!g) return;
50
+ const idx = g.nodes.findIndex(
51
+ (n) => n.id === payload.nodeId && n.kind === "group",
52
+ );
53
+ if (idx === -1) return;
54
+ const existing = g.nodes[idx]!;
55
+ // Template instances don't own a local subgraph — their `ports` come from
56
+ // the template definition and are read-only on the instance. Defensive:
57
+ // silently no-op if someone managed to invoke the editor on one.
58
+ if (existing.templateId) return;
59
+
60
+ // Detect renames against the PREVIOUS ports array BEFORE we replace it.
61
+ // Pure additions and pure deletions yield no renames; syncSentinels still
62
+ // handles deletions by dropping orphaned inner edges, and the outer graph
63
+ // has no edges for added ports yet, so neither needs port-name rewrites.
64
+ const oldPorts = Array.isArray(existing.ports) ? existing.ports : [];
65
+ const renames = detectPortRenames(oldPorts, payload.ports);
66
+
67
+ // Build a deep-cloned group node so syncSentinels can mutate its subgraph
68
+ // freely without aliasing into the current graph's state. The outer
69
+ // onUpdateNode/onGraphUpdate path expects a fresh node reference.
70
+ const clonedGroup: GraphNode = {
71
+ ...existing,
72
+ ports: payload.ports.map((p) => ({ ...p })),
73
+ subgraph: existing.subgraph
74
+ ? (JSON.parse(JSON.stringify(existing.subgraph)) as ProcedureGraph)
75
+ : undefined,
76
+ };
77
+
78
+ // Cascade renames into the INNER subgraph before syncSentinels runs — if
79
+ // we waited until after, syncSentinels would treat the old port names
80
+ // still on inner edges as references to deleted ports and drop them.
81
+ if (renames.length > 0 && clonedGroup.subgraph) {
82
+ const gi = clonedGroup.subgraph.nodes.find(
83
+ (n) => n.kind === "groupInput",
84
+ );
85
+ const go = clonedGroup.subgraph.nodes.find(
86
+ (n) => n.kind === "groupOutput",
87
+ );
88
+ // Group-level "in" ports surface as groupInput's OUT handles, and
89
+ // group-level "out" ports surface as groupOutput's IN handles. We pass
90
+ // invertDirection=true and target the right sentinel per direction.
91
+ const inRenames = renames.filter((r) => r.direction === "in");
92
+ const outRenames = renames.filter((r) => r.direction === "out");
93
+ if (gi && inRenames.length > 0) {
94
+ applyPortRenamesToEdges(
95
+ clonedGroup.subgraph.triggerEdges,
96
+ clonedGroup.subgraph.dataEdges,
97
+ gi.id,
98
+ inRenames,
99
+ true,
100
+ );
101
+ }
102
+ if (go && outRenames.length > 0) {
103
+ applyPortRenamesToEdges(
104
+ clonedGroup.subgraph.triggerEdges,
105
+ clonedGroup.subgraph.dataEdges,
106
+ go.id,
107
+ outRenames,
108
+ true,
109
+ );
110
+ }
111
+ }
112
+
113
+ syncSentinels(clonedGroup);
114
+
115
+ // Cascade renames into the OUTER graph's edges (where this group node is
116
+ // an endpoint). We do this by walking the current graph, cloning the
117
+ // triggerEdges / dataEdges arrays, applying the renames, then going
118
+ // through onGraphUpdate so history + dirty tracking pick it up. We can't
119
+ // rely on onUpdateNode for outer-edge changes because it only replaces
120
+ // the node, not the edges.
121
+ if (renames.length > 0) {
122
+ const nextOuter: ProcedureGraph = {
123
+ ...g,
124
+ nodes: g.nodes.map((n, i) => (i === idx ? clonedGroup : n)),
125
+ triggerEdges: g.triggerEdges.map((e) => ({
126
+ ...e,
127
+ from: { ...e.from },
128
+ to: { ...e.to },
129
+ })),
130
+ dataEdges: g.dataEdges.map((e) => ({
131
+ ...e,
132
+ from: { ...e.from },
133
+ to: { ...e.to },
134
+ })),
135
+ };
136
+ applyPortRenamesToEdges(
137
+ nextOuter.triggerEdges,
138
+ nextOuter.dataEdges,
139
+ payload.nodeId,
140
+ renames,
141
+ false,
142
+ );
143
+ onGraphUpdate(nextOuter);
144
+ return;
145
+ }
146
+
147
+ onUpdateNode(clonedGroup);
148
+ }
149
+
150
+ function onUnwireField(payload: { field: string }) {
151
+ const g = currentGraph.value;
152
+ if (!g || !selectedNode.value) return;
153
+ const nodeId = selectedNode.value.id;
154
+ const nextGraph: ProcedureGraph = {
155
+ ...g,
156
+ dataEdges: g.dataEdges.filter(
157
+ (e) => !(e.to.node === nodeId && e.to.field === payload.field),
158
+ ),
159
+ };
160
+ onGraphUpdate(nextGraph);
161
+ }
162
+
163
+ // Inspector "Delete node" button — same outcome as pressing Delete/Backspace
164
+ // on the canvas: drop the node plus every trigger/data edge that touches it.
165
+ function onDeleteNode(payload: { id: string }) {
166
+ const g = currentGraph.value;
167
+ if (!g || isCurrentGraphReadOnly.value) return;
168
+ const id = payload.id;
169
+ const nextGraph: ProcedureGraph = {
170
+ ...g,
171
+ nodes: g.nodes.filter((n) => n.id !== id),
172
+ triggerEdges: g.triggerEdges.filter(
173
+ (e) => e.from.node !== id && e.to.node !== id,
174
+ ),
175
+ dataEdges: g.dataEdges.filter(
176
+ (e) => e.from.node !== id && e.to.node !== id,
177
+ ),
178
+ };
179
+ if (selectedNodeId.value === id) selectedNodeId.value = null;
180
+ onGraphUpdate(nextGraph);
181
+ }
182
+
183
+ // ---------------------------------------------------------------------------
184
+ // Create-group-from-selection
185
+ // ---------------------------------------------------------------------------
186
+ // Visible when the user has selected one or more eligible nodes in the
187
+ // current canvas. "Eligible" rules out kinds that can't legally live inside
188
+ // a group's subgraph in v1:
189
+ // • `trigger` — triggers must live at the top level of a procedure.
190
+ // • `groupInput` / `groupOutput` — sentinels are auto-managed and only
191
+ // valid inside their owning group.
192
+ // Selection containing multiple groups IS allowed: nesting an existing
193
+ // group inside a new one is just a regular subgraph node move; the v1
194
+ // validator doesn't forbid it, and the executor's depth cap catches
195
+ // runaway recursion.
196
+ //
197
+ // Also gated on:
198
+ // • An editable graph (not the read-only template-instance view).
199
+ // • A real procedure being open (selected.value).
200
+ const canGroupSelection = computed<boolean>(() => {
201
+ if (!selected.value) return false;
202
+ if (isCurrentGraphReadOnly.value) return false;
203
+ const ids = selectedNodeIds.value;
204
+ if (ids.length === 0) return false;
205
+ const g = currentGraph.value;
206
+ if (!g) return false;
207
+ const idSet = new Set(ids);
208
+ for (const n of g.nodes) {
209
+ if (!idSet.has(n.id)) continue;
210
+ if (n.kind === "trigger") return false;
211
+ if (n.kind === "groupInput" || n.kind === "groupOutput") return false;
212
+ }
213
+ return true;
214
+ });
215
+
216
+ function createGroupFromSelection() {
217
+ if (!canGroupSelection.value) return;
218
+ const g = currentGraph.value;
219
+ if (!g) return;
220
+ const ids = selectedNodeIds.value.slice();
221
+ if (ids.length === 0) return;
222
+
223
+ // The group gets a default name, then the inspector opens on it with its
224
+ // name field focused: renaming is one keystroke away, nothing blocks.
225
+ const inputName = t("dms_automation.editor.groupDefaultName");
226
+
227
+ const selection = new Set(ids);
228
+ const groupId = newId();
229
+
230
+ const plan = planNewGroup(g, selection, groupId, schemaSources);
231
+
232
+ // Position the new group at the centroid of the selection. We also
233
+ // shift the selected nodes' positions into the subgraph's coordinate
234
+ // space: subtract the selection min, then add a left-margin so the
235
+ // groupInput sentinel can sit at x ≈ 0.
236
+ const SUBGRAPH_LEFT_MARGIN = 220; // groupInput sits at x = 0 with room
237
+ const SUBGRAPH_RIGHT_MARGIN = 220;
238
+ const selectedNodes = g.nodes.filter((n) => selection.has(n.id));
239
+ const xs = selectedNodes.map((n) => n.position.x);
240
+ const ys = selectedNodes.map((n) => n.position.y);
241
+ const minX = xs.length ? Math.min(...xs) : 0;
242
+ const maxX = xs.length ? Math.max(...xs) : 0;
243
+ const minY = ys.length ? Math.min(...ys) : 0;
244
+ const maxY = ys.length ? Math.max(...ys) : 0;
245
+ const centerX = xs.length ? (minX + maxX) / 2 : 200;
246
+ const centerY = ys.length ? (minY + maxY) / 2 : 200;
247
+
248
+ const innerNodes: GraphNode[] = selectedNodes.map((n) => ({
249
+ ...JSON.parse(JSON.stringify(n)),
250
+ position: {
251
+ x: n.position.x - minX + SUBGRAPH_LEFT_MARGIN,
252
+ y: n.position.y - minY,
253
+ },
254
+ }));
255
+
256
+ const innerHeight = Math.max(maxY - minY, 0);
257
+ const innerWidth = Math.max(maxX - minX, 0);
258
+
259
+ const groupInputNode: GraphNode = {
260
+ id: plan.groupInputId,
261
+ kind: "groupInput",
262
+ config: {},
263
+ position: { x: 0, y: innerHeight / 2 },
264
+ };
265
+ const groupOutputNode: GraphNode = {
266
+ id: plan.groupOutputId,
267
+ kind: "groupOutput",
268
+ config: {},
269
+ position: {
270
+ x: innerWidth + SUBGRAPH_LEFT_MARGIN + SUBGRAPH_RIGHT_MARGIN,
271
+ y: innerHeight / 2,
272
+ },
273
+ };
274
+
275
+ // Inner edges fully inside the selection — keep them verbatim (re-id
276
+ // not required since we keep node ids stable; ids only need to be
277
+ // unique within their containing graph and these are all from the
278
+ // outer graph we just stripped them from).
279
+ const innerOriginalTriggerEdges = g.triggerEdges.filter(
280
+ (e) => selection.has(e.from.node) && selection.has(e.to.node),
281
+ );
282
+ const innerOriginalDataEdges = g.dataEdges.filter(
283
+ (e) => selection.has(e.from.node) && selection.has(e.to.node),
284
+ );
285
+
286
+ const newGroupNode: GraphNode = {
287
+ id: groupId,
288
+ kind: "group",
289
+ config: { name: inputName },
290
+ position: { x: centerX, y: centerY },
291
+ ports: plan.groupPorts,
292
+ subgraph: {
293
+ nodes: [...innerNodes, groupInputNode, groupOutputNode],
294
+ triggerEdges: [...innerOriginalTriggerEdges, ...plan.innerTriggerEdges],
295
+ dataEdges: [...innerOriginalDataEdges, ...plan.innerDataEdges],
296
+ },
297
+ };
298
+
299
+ // Build the new outer graph: drop the selected nodes + every edge that
300
+ // touches them (cut OR fully-inside), then add the new group + the
301
+ // replacement outer edges.
302
+ const remainingOuterNodes = g.nodes.filter((n) => !selection.has(n.id));
303
+ const remainingOuterTriggerEdges = g.triggerEdges.filter(
304
+ (e) => !selection.has(e.from.node) && !selection.has(e.to.node),
305
+ );
306
+ const remainingOuterDataEdges = g.dataEdges.filter(
307
+ (e) => !selection.has(e.from.node) && !selection.has(e.to.node),
308
+ );
309
+
310
+ const nextGraph: ProcedureGraph = {
311
+ nodes: [...remainingOuterNodes, newGroupNode],
312
+ triggerEdges: [...remainingOuterTriggerEdges, ...plan.outerTriggerEdges],
313
+ dataEdges: [...remainingOuterDataEdges, ...plan.outerDataEdges],
314
+ };
315
+
316
+ // Clear stale selection — the original ids no longer exist in the
317
+ // outer graph. Select the newly-created group.
318
+ selectedNodeIds.value = [];
319
+ selectedNodeId.value = groupId;
320
+
321
+ onGraphUpdate(nextGraph);
322
+ void focusInspectorName();
323
+ }
324
+
325
+ /** Focuses the inspector's first field, the step name, and selects its text. */
326
+ async function focusInspectorName() {
327
+ await nextTick();
328
+ const input = inspectorRef.value?.querySelector("input");
329
+ input?.focus();
330
+ input?.select();
331
+ }
332
+
333
+ function onDuplicateNode(payload: { id: string }) {
334
+ const g = currentGraph.value;
335
+ if (!g || isCurrentGraphReadOnly.value) return;
336
+ const node = g.nodes.find((n) => n.id === payload.id);
337
+ if (!node) return;
338
+ const copy: GraphNode = {
339
+ ...cloneGraph({ nodes: [node], triggerEdges: [], dataEdges: [] })
340
+ .nodes[0]!,
341
+ id: newId(),
342
+ position: { x: node.position.x + 40, y: node.position.y + 60 },
343
+ };
344
+ onGraphUpdate({ ...g, nodes: [...g.nodes, copy] });
345
+ selectedNodeId.value = copy.id;
346
+ }
347
+
348
+ /** Put a Retry in front of a step: it now runs inside the Retry's body. */
349
+ function onWrapInRetry(payload: { id: string }) {
350
+ const g = currentGraph.value;
351
+ if (!g || isCurrentGraphReadOnly.value) return;
352
+ const node = g.nodes.find((n) => n.id === payload.id);
353
+ if (!node) return;
354
+ const retry: GraphNode = {
355
+ id: newId(),
356
+ kind: "retry",
357
+ config: { maxAttempts: 3 },
358
+ position: { x: node.position.x - 40, y: node.position.y - 140 },
359
+ };
360
+ const triggerEdges = g.triggerEdges.map((e) => {
361
+ if (e.to.node === node.id)
362
+ return { ...e, to: { ...e.to, node: retry.id } };
363
+ if (
364
+ e.from.node === node.id &&
365
+ (!e.from.branch || e.from.branch === "main")
366
+ ) {
367
+ return { ...e, from: { node: retry.id, branch: "main" } };
368
+ }
369
+ return e;
370
+ });
371
+ triggerEdges.push({
372
+ id: newId(),
373
+ from: { node: retry.id, branch: "body" },
374
+ to: { node: node.id },
375
+ });
376
+ onGraphUpdate({ ...g, nodes: [...g.nodes, retry], triggerEdges });
377
+ selectedNodeId.value = retry.id;
378
+ }
379
+
380
+ // Template mode: the template's own ports are edited at its root, where its
381
+ // Group input / Group output steps show them. Shown when no step, or
382
+ // one of those two, is selected.
383
+ const showTemplatePorts = computed<boolean>(
384
+ () =>
385
+ editorMode.value === "template" &&
386
+ subgraphPath.value.length <= 1 &&
387
+ (!selectedNode.value ||
388
+ selectedNode.value.kind === "groupInput" ||
389
+ selectedNode.value.kind === "groupOutput"),
390
+ );
391
+
392
+ function onTemplatePortsUpdate(next: GroupPort[]) {
393
+ const root = selected.value?.graph;
394
+ if (!root) return;
395
+ // The root graph is the template's subgraph: renames and removals go
396
+ // through the same path as a group's ports.
397
+ const template: GraphNode = {
398
+ id: "",
399
+ kind: "group",
400
+ config: {},
401
+ position: { x: 0, y: 0 },
402
+ ports: next.map((p) => ({ ...p })),
403
+ subgraph: cloneGraph(root),
404
+ };
405
+ const renames = detectPortRenames(templatePorts.value, next);
406
+ const gi = template.subgraph!.nodes.find((n) => n.kind === "groupInput");
407
+ const go = template.subgraph!.nodes.find((n) => n.kind === "groupOutput");
408
+ const inRenames = renames.filter((r) => r.direction === "in");
409
+ const outRenames = renames.filter((r) => r.direction === "out");
410
+ if (gi && inRenames.length > 0)
411
+ applyPortRenamesToEdges(
412
+ template.subgraph!.triggerEdges,
413
+ template.subgraph!.dataEdges,
414
+ gi.id,
415
+ inRenames,
416
+ true,
417
+ );
418
+ if (go && outRenames.length > 0)
419
+ applyPortRenamesToEdges(
420
+ template.subgraph!.triggerEdges,
421
+ template.subgraph!.dataEdges,
422
+ go.id,
423
+ outRenames,
424
+ true,
425
+ );
426
+ syncSentinels(template);
427
+ templatePorts.value = template.ports!;
428
+ onGraphUpdate(template.subgraph!);
429
+ }
430
+
431
+ return {
432
+ onPortsUpdate,
433
+ onUnwireField,
434
+ onDeleteNode,
435
+ canGroupSelection,
436
+ createGroupFromSelection,
437
+ focusInspectorName,
438
+ onDuplicateNode,
439
+ onWrapInRetry,
440
+ showTemplatePorts,
441
+ onTemplatePortsUpdate,
442
+ };
443
+ }
444
+
445
+ export type GroupEditing = ReturnType<typeof useGroupEditing>;
@@ -0,0 +1,41 @@
1
+ import { onMounted, ref } from "vue";
2
+
3
+ /** Whether the node palette is put away, remembered per browser. */
4
+ export function usePalette() {
5
+ // Below xl the inspector floats over the canvas instead of narrowing it; the
6
+ // palette can be put away. Remembered per browser.
7
+ const PALETTE_HIDDEN_KEY = "dms-automation:builder-palette-hidden";
8
+ const PALETTE_FOLDED_BELOW_PX = 1280;
9
+ const paletteHidden = ref(false);
10
+ onMounted(() => {
11
+ // Folded by default below xl, where it would leave the canvas too little.
12
+ let stored: string | null = null;
13
+ try {
14
+ stored = window.localStorage.getItem(PALETTE_HIDDEN_KEY);
15
+ } catch {
16
+ // Storage blocked: the default for the width applies.
17
+ }
18
+ paletteHidden.value =
19
+ stored === null
20
+ ? window.innerWidth < PALETTE_FOLDED_BELOW_PX
21
+ : stored === "1";
22
+ });
23
+ function togglePalette() {
24
+ paletteHidden.value = !paletteHidden.value;
25
+ try {
26
+ window.localStorage.setItem(
27
+ PALETTE_HIDDEN_KEY,
28
+ paletteHidden.value ? "1" : "0",
29
+ );
30
+ } catch {
31
+ // Storage blocked: the choice lasts until the page is left.
32
+ }
33
+ }
34
+
35
+ return {
36
+ paletteHidden,
37
+ togglePalette,
38
+ };
39
+ }
40
+
41
+ export type Palette = ReturnType<typeof usePalette>;
@@ -0,0 +1,96 @@
1
+ import type { EditorContext } from "./useEditorContext";
2
+ import type { EditorLoad } from "./useEditorLoad";
3
+ import type { DraftProblems } from "./useDraftProblems";
4
+ import type { UnsavedGuards } from "./useUnsavedGuards";
5
+
6
+ /** Creating, deleting and exporting a procedure. */
7
+ export function useProcedureActions(
8
+ ctx: EditorContext,
9
+ load: EditorLoad,
10
+ problems: DraftProblems,
11
+ guards: UnsavedGuards,
12
+ ) {
13
+ const {
14
+ $authFetch,
15
+ builderPath,
16
+ confirmFrom,
17
+ newProcedureOpen,
18
+ procedures,
19
+ props,
20
+ router,
21
+ selected,
22
+ selectedId,
23
+ t,
24
+ toast,
25
+ } = ctx;
26
+ const { loadList } = load;
27
+ const { savedName, summariesRead } = problems;
28
+ const { confirmDiscard } = guards;
29
+
30
+ async function onCreated(id: string) {
31
+ await Promise.all([loadList(), summariesRead.refresh()]);
32
+ selectedId.value = id;
33
+ void router.replace(`${builderPath()}?selected=${id}`);
34
+ }
35
+
36
+ async function onCreate() {
37
+ if (!(await confirmDiscard())) return;
38
+ newProcedureOpen.value = true;
39
+ }
40
+
41
+ async function onDelete() {
42
+ const current = selected.value;
43
+ if (!current) return;
44
+ const name = savedName.value;
45
+ // The server words the dialog, as the procedures table's delete does.
46
+ await confirmFrom(`${props.apiUrl}/procedures/{{row.id}}/delete-confirm`, {
47
+ params: { id: current._id },
48
+ onConfirm: async () => {
49
+ await $authFetch(`${props.apiUrl}/procedures/${current._id}`, {
50
+ method: "DELETE",
51
+ });
52
+ procedures.value = procedures.value.filter(
53
+ (p) => p._id !== current._id,
54
+ );
55
+ selectedId.value = procedures.value[0]?._id ?? null;
56
+ void router.replace(
57
+ selectedId.value
58
+ ? `${builderPath()}?selected=${selectedId.value}`
59
+ : builderPath(),
60
+ );
61
+ toast.add({
62
+ title: t("dms_automation.editor.deleted", { name }),
63
+ color: "success",
64
+ icon: "i-ph-check-circle",
65
+ });
66
+ void summariesRead.refresh();
67
+ },
68
+ });
69
+ }
70
+
71
+ async function onExport() {
72
+ const current = selected.value;
73
+ if (!current) return;
74
+ const data = await $authFetch<unknown>(
75
+ `${props.apiUrl}/procedures/${current._id}/export`,
76
+ );
77
+ const blob = new Blob([JSON.stringify(data, null, 2)], {
78
+ type: "application/json",
79
+ });
80
+ const url = URL.createObjectURL(blob);
81
+ const link = document.createElement("a");
82
+ link.href = url;
83
+ link.download = `${current.name.replace(/[^\w-]+/g, "-").toLowerCase() || "procedure"}.json`;
84
+ link.click();
85
+ URL.revokeObjectURL(url);
86
+ }
87
+
88
+ return {
89
+ onCreated,
90
+ onCreate,
91
+ onDelete,
92
+ onExport,
93
+ };
94
+ }
95
+
96
+ export type ProcedureActions = ReturnType<typeof useProcedureActions>;