@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,123 @@
1
+ import type { Connection } from "@vue-flow/core";
2
+ import { computed, ref, type Ref } from "vue";
3
+ import type { GraphNode as AppGraphNode } from "../../../composables/useGraphConnect";
4
+ import type { ConnectionCheck } from "./connect";
5
+ import type { CanvasProps, CanvasText, LinkItem, NodeHandles } from "./types";
6
+
7
+ export function useLinkMenu({
8
+ props,
9
+ t,
10
+ canvasSelection,
11
+ check,
12
+ handlesOf,
13
+ menuName,
14
+ onConnect,
15
+ }: {
16
+ props: Readonly<CanvasProps>;
17
+ t: CanvasText["t"];
18
+ canvasSelection: Ref<string[]>;
19
+ check: ConnectionCheck;
20
+ handlesOf: (node: AppGraphNode) => NodeHandles;
21
+ menuName: (id: string) => string;
22
+ onConnect: (conn: Connection) => void;
23
+ }) {
24
+ // Without a mouse: every link the selected step can make, from the canvas
25
+ // toolbar (WCAG 2.5.7).
26
+
27
+ const linkGroups = computed(() => {
28
+ const id =
29
+ canvasSelection.value.length === 1 ? canvasSelection.value[0] : undefined;
30
+ const node = props.graph.nodes.find((n) => n.id === id);
31
+ if (!node || props.readOnly) return [];
32
+ const mine = handlesOf(node);
33
+ const next: LinkItem[] = [];
34
+ const send: LinkItem[] = [];
35
+ const read: LinkItem[] = [];
36
+ const wired = (target: string, field: string) =>
37
+ props.graph.dataEdges.some(
38
+ (e) => e.to.node === target && e.to.field === field,
39
+ );
40
+ const add = (into: LinkItem[], label: string, connection: Connection) => {
41
+ if (check(props.graph, connection).ok) into.push({ label, connection });
42
+ };
43
+ for (const other of props.graph.nodes) {
44
+ if (other.id === node.id) continue;
45
+ const theirs = handlesOf(other);
46
+ const name = menuName(other.id);
47
+ for (const out of mine.triggerOuts) {
48
+ const current = props.graph.triggerEdges.find(
49
+ (e) =>
50
+ e.from.node === node.id && (e.from.branch ?? "main") === out.name,
51
+ );
52
+ if (current?.to.node === other.id) continue;
53
+ // The output already leads somewhere: the menu says what goes.
54
+ const replaces = current
55
+ ? ` (${t("dms_automation.editor.canvas.link.replaces", { name: menuName(current.to.node) })})`
56
+ : "";
57
+ for (const into of theirs.triggerIns) {
58
+ const branch = out.name === "main" ? "" : `${out.name} `;
59
+ const port =
60
+ into.name && into.name !== "main" ? ` · ${into.name}` : "";
61
+ add(next, `${branch}→ ${name}${port}${replaces}`, {
62
+ source: node.id,
63
+ sourceHandle: out.id,
64
+ target: other.id,
65
+ targetHandle: into.id,
66
+ });
67
+ }
68
+ }
69
+ for (const out of mine.dataOuts) {
70
+ for (const into of theirs.dataIns) {
71
+ if (wired(other.id, into.name)) continue;
72
+ add(send, `${out.name} → ${name} · ${into.name}`, {
73
+ source: node.id,
74
+ sourceHandle: out.id,
75
+ target: other.id,
76
+ targetHandle: into.id,
77
+ });
78
+ }
79
+ }
80
+ for (const out of theirs.dataOuts) {
81
+ for (const into of mine.dataIns) {
82
+ if (wired(node.id, into.name)) continue;
83
+ add(read, `${name} · ${out.name} → ${into.name}`, {
84
+ source: other.id,
85
+ sourceHandle: out.id,
86
+ target: node.id,
87
+ targetHandle: into.id,
88
+ });
89
+ }
90
+ }
91
+ }
92
+ const group = (key: string, items: LinkItem[]) =>
93
+ items.length
94
+ ? [
95
+ {
96
+ type: "label" as const,
97
+ label: t(`dms_automation.editor.canvas.link.${key}`),
98
+ },
99
+ ...items,
100
+ ]
101
+ : [];
102
+ return [
103
+ group("next", next),
104
+ group("send", send),
105
+ group("read", read),
106
+ ].filter((g) => g.length > 0);
107
+ });
108
+
109
+ // The link menu is offered for a single selected step of an editable graph.
110
+ const canLink = computed(
111
+ () => !props.readOnly && canvasSelection.value.length === 1,
112
+ );
113
+
114
+ // The menu is an action, not a field: it never keeps a value.
115
+ const linkChoice = ref<LinkItem | null>(null);
116
+
117
+ function onLink(item: LinkItem | null) {
118
+ if (item?.connection) onConnect(item.connection);
119
+ linkChoice.value = null;
120
+ }
121
+
122
+ return { linkGroups, canLink, linkChoice, onLink };
123
+ }
@@ -0,0 +1,222 @@
1
+ import { Position } from "@vue-flow/core";
2
+ import { computed } from "vue";
3
+ import type {
4
+ GraphNode as AppGraphNode,
5
+ JsonSchema,
6
+ } from "../../../composables/useGraphConnect";
7
+ import type { NodeKindUI } from "../../../composables/useAutomationNodeKinds";
8
+ import { roleOf, summarizeNode } from "../../../utils/describe";
9
+ import {
10
+ ariaLabelOf,
11
+ handlesOf as handlesOfNode,
12
+ propsOf,
13
+ vfTypeFor,
14
+ } from "./handles";
15
+ import type { CanvasProps, CanvasText, NodeIssue } from "./types";
16
+ import { SENTINEL_KINDS } from "./types";
17
+
18
+ export function useCanvasNodes(props: Readonly<CanvasProps>, text: CanvasText) {
19
+ const { t, te, processI18n, processText } = text;
20
+
21
+ // Index node-kind metadata by kind for O(1) lookup.
22
+ const nodeKindUiByKind = computed<Map<string, NodeKindUI>>(() => {
23
+ const m = new Map<string, NodeKindUI>();
24
+ for (const entry of props.nodeKinds ?? []) {
25
+ if (entry.meta?.ui) m.set(entry.kind, entry.meta.ui);
26
+ }
27
+ return m;
28
+ });
29
+
30
+ // Pull a registered TriggerType / ActionType / DataNodeType from the
31
+ // type-registry prop indicated by a NodeKindUI.typeRegistry hint.
32
+ function lookupTypeBySpec(spec: NodeKindUI, typeId: string | undefined) {
33
+ if (!spec.typeRegistry || !typeId) return null;
34
+ if (spec.typeRegistry === "triggers")
35
+ return props.triggerTypes.find((t) => t.id === typeId) ?? null;
36
+ if (spec.typeRegistry === "actions")
37
+ return props.actionTypes.find((a) => a.id === typeId) ?? null;
38
+ if (spec.typeRegistry === "dataNodes")
39
+ return props.dataNodeTypes.find((d) => d.id === typeId) ?? null;
40
+ return null;
41
+ }
42
+
43
+ // A schedule in words, once the server has worded its current expression.
44
+ function scheduleTextOf(node: AppGraphNode): string | undefined {
45
+ const cron = node.config?.cron;
46
+ const worded = props.triggers?.find(
47
+ (tr) => tr.nodeId === node.id && tr.cron === cron,
48
+ );
49
+ return worded ? processText(worded.text) : undefined;
50
+ }
51
+
52
+ // The validator's problem on a node, in the reader's language (its English
53
+ // message when this version has no text for the code).
54
+ function issueOf(id: string): NodeIssue | null {
55
+ const issue = props.issues?.[id];
56
+ if (!issue) return null;
57
+ const key = `dms_automation.editor.problems.codes.${issue.code}`;
58
+ return issue.code && te(key)
59
+ ? { ...issue, message: t(key, issue.params ?? {}) }
60
+ : issue;
61
+ }
62
+
63
+ // Build the GenericNode `data` payload from a graph node. For every kind
64
+ // with `ui` metadata (every kind except group + sentinels), one
65
+ // data-driven resolver applies: combine `spec` from the backend with the
66
+ // node's `typeId` (for type-registered kinds) and `config` (for dynamic
67
+ // trigger-out ports).
68
+ function dataFor(node: AppGraphNode) {
69
+ const spec = nodeKindUiByKind.value.get(node.kind);
70
+ if (spec) {
71
+ // Kind labels may be `$`-prefixed i18n keys too.
72
+ let label = processI18n(spec.label);
73
+ let icon = spec.icon;
74
+ let category: string | undefined;
75
+ let dataIns = [...spec.staticDataIns];
76
+ let dataOuts = [...spec.staticDataOuts];
77
+
78
+ const type = lookupTypeBySpec(spec, node.typeId) as {
79
+ name?: string;
80
+ icon?: string;
81
+ category?: string;
82
+ inputSchema?: JsonSchema;
83
+ outputSchema?: JsonSchema;
84
+ configSchema?: JsonSchema;
85
+ } | null;
86
+ if (type) {
87
+ // Type names may be `$`-prefixed DMS i18n keys; plain text passes through.
88
+ if (spec.labelFromType && type.name !== undefined)
89
+ label = processI18n(type.name);
90
+ if (spec.iconFromType) icon = type.icon ?? icon;
91
+ if (spec.categoryFromType) category = type.category;
92
+ if (spec.dataInsFromTypeSchema)
93
+ dataIns = propsOf(type[spec.dataInsFromTypeSchema]);
94
+ if (spec.dataOutsFromTypeSchema)
95
+ dataOuts = propsOf(type[spec.dataOutsFromTypeSchema]);
96
+ }
97
+
98
+ const dynPorts = spec.dynamicTriggerOutsFromConfig
99
+ ? ((node.config?.[spec.dynamicTriggerOutsFromConfig] as
100
+ | string[]
101
+ | undefined) ?? [])
102
+ : [];
103
+ const triggerOuts = [...dynPorts, ...spec.staticTriggerOuts];
104
+
105
+ const own = (node as AppGraphNode & { label?: string }).label;
106
+ const module = (type as { module?: string } | null)?.module;
107
+ return {
108
+ label: own || label,
109
+ typeName: label,
110
+ role: roleOf(node.kind, spec.category),
111
+ module,
112
+ summary: summarizeNode(
113
+ node.kind,
114
+ node.typeId,
115
+ node.config,
116
+ processI18n,
117
+ scheduleTextOf(node),
118
+ ),
119
+ run: props.runStates?.[node.id] ?? null,
120
+ issue: issueOf(node.id),
121
+ icon,
122
+ category,
123
+ typeId: node.typeId,
124
+ config: node.config,
125
+ hasTriggerIn: spec.hasTriggerIn,
126
+ hasMainTriggerOut: spec.hasMainTriggerOut,
127
+ triggerOuts,
128
+ dataIns,
129
+ dataOuts,
130
+ };
131
+ }
132
+
133
+ if (node.kind === "group") {
134
+ // Group node carries its own port list + (optional) inline subgraph
135
+ // or templateId. The fields live on the node itself (per backend
136
+ // GroupNode interface) — surface them so the renderer can display
137
+ // handles, linked badges, etc.
138
+ const g = node as AppGraphNode & {
139
+ label?: string;
140
+ ports?: unknown;
141
+ templateId?: string;
142
+ subgraph?: unknown;
143
+ };
144
+ // Step name (`label`) first, as for any node; `config.name` is the name
145
+ // the group or its template was created with.
146
+ return {
147
+ label:
148
+ g.label ||
149
+ (node.config?.name as string | undefined) ||
150
+ t("dms_automation.nodes.role.group"),
151
+ run: props.runStates?.[node.id] ?? null,
152
+ issue: issueOf(node.id),
153
+ ports: Array.isArray(g.ports) ? g.ports : [],
154
+ templateId: g.templateId,
155
+ subgraph: g.subgraph,
156
+ config: node.config,
157
+ };
158
+ }
159
+ if (node.kind === "groupInput" || node.kind === "groupOutput") {
160
+ // Sentinels render the parent group's ports. In subgraph-editor
161
+ // mode (C5.3) Editor.vue passes `parentGroupPorts` so both
162
+ // sentinels share one source of truth — the outer group node.
163
+ // At the procedure-graph root there's no parent group, so we
164
+ // fall back to whatever ports the sentinel carries (which
165
+ // should normally be none — a stray sentinel renders empty).
166
+ if (Array.isArray(props.parentGroupPorts)) {
167
+ return { ports: props.parentGroupPorts };
168
+ }
169
+ const s = node as AppGraphNode & { ports?: unknown };
170
+ return { ports: Array.isArray(s.ports) ? s.ports : [] };
171
+ }
172
+ return {};
173
+ }
174
+
175
+ const vfNodes = computed(() =>
176
+ props.graph.nodes.map((n) => {
177
+ const data = dataFor(n);
178
+ return {
179
+ id: n.id,
180
+ type: vfTypeFor(n.kind),
181
+ position: n.position,
182
+ data,
183
+ ariaLabel: SENTINEL_KINDS.has(n.kind)
184
+ ? t(
185
+ n.kind === "groupInput"
186
+ ? "dms_automation.nodes.groupInput"
187
+ : "dms_automation.nodes.groupOutput",
188
+ )
189
+ : ariaLabelOf(data),
190
+ sourcePosition: Position.Bottom,
191
+ targetPosition: Position.Top,
192
+ };
193
+ }),
194
+ );
195
+
196
+ // How the canvas names a node in its messages: its label, else (a group's
197
+ // sentinels) the group role.
198
+ const nodeNames = computed(
199
+ () =>
200
+ new Map(
201
+ vfNodes.value.map((n) => [n.id, (n.data as { label?: string }).label]),
202
+ ),
203
+ );
204
+ function nodeName(id: string): string {
205
+ return nodeNames.value.get(id) || t("dms_automation.nodes.role.group");
206
+ }
207
+
208
+ // Two steps with the same name are told apart by the end of their id (link
209
+ // menu, replacement toast, links read aloud).
210
+ function menuName(id: string): string {
211
+ const name = nodeName(id);
212
+ const twins = props.graph.nodes.filter(
213
+ (n) => nodeName(n.id) === name,
214
+ ).length;
215
+ return twins > 1 ? `${name} #${id.slice(-4)}` : name;
216
+ }
217
+
218
+ const handlesOf = (node: AppGraphNode) =>
219
+ handlesOfNode(node, props.parentGroupPorts, dataFor);
220
+
221
+ return { nodeKindUiByKind, handlesOf, vfNodes, menuName };
222
+ }
@@ -0,0 +1,248 @@
1
+ import type { ComputedRef, Ref } from "vue";
2
+ import { newId } from "../../../utils/automation";
3
+ import {
4
+ PALETTE_DRAG_TYPE,
5
+ type NodeKindUI,
6
+ type PaletteBlock,
7
+ type TemplateSummary,
8
+ } from "../../../composables/useAutomationNodeKinds";
9
+ import type {
10
+ GraphNode as AppGraphNode,
11
+ GroupPort,
12
+ JsonSchema,
13
+ NodeKind,
14
+ ProcedureGraph,
15
+ } from "../../../composables/useGraphConnect";
16
+ import {
17
+ nextStepConnection,
18
+ withConnection,
19
+ type ConnectionCheck,
20
+ } from "./connect";
21
+ import { NEW_NODE_SIZE, NODE_GAP } from "./types";
22
+ import type {
23
+ CanvasProps,
24
+ FlowController,
25
+ NodeHandles,
26
+ Rect,
27
+ Reveal,
28
+ XY,
29
+ } from "./types";
30
+
31
+ function defaultsFromSchema(
32
+ schema: JsonSchema | undefined,
33
+ ): Record<string, unknown> {
34
+ if (!schema?.properties) return {};
35
+ const out: Record<string, unknown> = {};
36
+ for (const [name, prop] of Object.entries(schema.properties)) {
37
+ if (prop && prop.default !== undefined) out[name] = prop.default;
38
+ }
39
+ return out;
40
+ }
41
+
42
+ export function useNodePlacement({
43
+ props,
44
+ flowRef,
45
+ canvasSelection,
46
+ nodeKindUiByKind,
47
+ emitGraph,
48
+ reveal,
49
+ check,
50
+ handlesOf,
51
+ }: {
52
+ props: Readonly<CanvasProps>;
53
+ flowRef: Ref<FlowController | null>;
54
+ canvasSelection: Ref<string[]>;
55
+ nodeKindUiByKind: ComputedRef<Map<string, NodeKindUI>>;
56
+ emitGraph: (graph: ProcedureGraph) => void;
57
+ reveal: Reveal;
58
+ check: ConnectionCheck;
59
+ handlesOf: (node: AppGraphNode) => NodeHandles;
60
+ }) {
61
+ function nodeRects(): Rect[] {
62
+ return props.graph.nodes.map((n) => {
63
+ const size = flowRef.value?.findNode(n.id)?.dimensions;
64
+ return {
65
+ ...n.position,
66
+ width: size?.width || NEW_NODE_SIZE.width,
67
+ height: size?.height || NEW_NODE_SIZE.height,
68
+ };
69
+ });
70
+ }
71
+
72
+ function overlaps(a: Rect, b: Rect): boolean {
73
+ const gap = NODE_GAP / 2;
74
+ return (
75
+ a.x < b.x + b.width + gap &&
76
+ b.x < a.x + a.width + gap &&
77
+ a.y < b.y + b.height + gap &&
78
+ b.y < a.y + a.height + gap
79
+ );
80
+ }
81
+
82
+ // The first place at or below `pos` where a new node covers no other one.
83
+ function freeSpot(pos: XY): XY {
84
+ const rects = nodeRects();
85
+ const spot: Rect = { ...pos, ...NEW_NODE_SIZE };
86
+ for (
87
+ let hit = rects.find((r) => overlaps(spot, r));
88
+ hit;
89
+ hit = rects.find((r) => overlaps(spot, r))
90
+ ) {
91
+ spot.y = hit.y + hit.height + NODE_GAP;
92
+ }
93
+ return { x: Math.round(spot.x), y: Math.round(spot.y) };
94
+ }
95
+
96
+ // A new step goes right of the selected one, else in the middle of what the
97
+ // canvas shows.
98
+ function newNodePosition(anchor: AppGraphNode | undefined): XY {
99
+ const flow = flowRef.value;
100
+ if (anchor) {
101
+ const width =
102
+ flow?.findNode(anchor.id)?.dimensions.width || NEW_NODE_SIZE.width;
103
+ return freeSpot({
104
+ x: anchor.position.x + width + NODE_GAP,
105
+ y: anchor.position.y,
106
+ });
107
+ }
108
+ if (!flow) return freeSpot({ x: 0, y: 0 });
109
+ const { x, y, zoom } = flow.viewport;
110
+ return freeSpot({
111
+ x: (flow.dimensions.width / 2 - x) / zoom - NEW_NODE_SIZE.width / 2,
112
+ y: (flow.dimensions.height / 2 - y) / zoom - NEW_NODE_SIZE.height / 2,
113
+ });
114
+ }
115
+
116
+ // The node a new step follows: the one selected last on this canvas.
117
+ function anchorNode(): AppGraphNode | undefined {
118
+ const id =
119
+ props.selectedNodeId ??
120
+ canvasSelection.value[canvasSelection.value.length - 1];
121
+ return props.graph.nodes.find((n) => n.id === id);
122
+ }
123
+
124
+ // Add a node where it was dropped, or next to the selected node and linked
125
+ // from it (one undo step for both).
126
+ function insertNode(node: AppGraphNode, at?: XY) {
127
+ const anchor = at ? undefined : anchorNode();
128
+ const placed = {
129
+ ...node,
130
+ position: at ? freeSpot(at) : newNodePosition(anchor),
131
+ };
132
+ const graph = { ...props.graph, nodes: [...props.graph.nodes, placed] };
133
+ const link = anchor
134
+ ? nextStepConnection(graph, anchor, placed, handlesOf, check)
135
+ : null;
136
+ emitGraph(link ? (withConnection(graph, link)?.graph ?? graph) : graph);
137
+ reveal.pending = { id: placed.id, readable: false };
138
+ }
139
+
140
+ function defaultConfigFor(
141
+ kind: NodeKind,
142
+ typeId?: string,
143
+ ): Record<string, unknown> {
144
+ const ui = nodeKindUiByKind.value.get(kind);
145
+ if (ui?.typeRegistry === "triggers") {
146
+ const t = props.triggerTypes.find((tt) => tt.id === typeId);
147
+ return defaultsFromSchema(t?.configSchema);
148
+ }
149
+ if (ui?.typeRegistry === "actions") {
150
+ const a = props.actionTypes.find((aa) => aa.id === typeId);
151
+ return defaultsFromSchema(a?.inputSchema);
152
+ }
153
+ if (ui?.typeRegistry === "dataNodes") {
154
+ const d = props.dataNodeTypes.find((dd) => dd.id === typeId);
155
+ // Constant nodes seed from `configSchema` (their value lives there);
156
+ // wired-port data nodes seed any `inputSchema` field defaults.
157
+ return {
158
+ ...defaultsFromSchema(d?.inputSchema),
159
+ ...defaultsFromSchema(d?.configSchema),
160
+ };
161
+ }
162
+ // Static-config kinds carry their seed config in metadata; deep-clone
163
+ // so each instance gets its own mutable copy. JSON round-trip strips
164
+ // the Vue reactive proxy that wraps `props.nodeKinds` — structuredClone
165
+ // would throw on the proxy.
166
+ return ui?.defaultConfig
167
+ ? (JSON.parse(JSON.stringify(ui.defaultConfig)) as Record<
168
+ string,
169
+ unknown
170
+ >)
171
+ : {};
172
+ }
173
+
174
+ function addNode(kind: NodeKind, typeId?: string, at?: XY) {
175
+ insertNode(
176
+ {
177
+ id: newId(),
178
+ kind,
179
+ typeId,
180
+ config: defaultConfigFor(kind, typeId),
181
+ position: { x: 0, y: 0 },
182
+ },
183
+ at,
184
+ );
185
+ }
186
+
187
+ // A template's `ports` are deep-cloned (JSON round-trip) onto each new
188
+ // template-instance group node so future template edits don't retroactively
189
+ // mutate the instance's port list (the resolved subgraph still updates live —
190
+ // that's the live-link model).
191
+
192
+ // Drop a template-instance group node into the current graph. The instance
193
+ // carries `templateId` and a deep clone (JSON round-trip) of the template's
194
+ // port list;
195
+ // it has NO inline `subgraph` — the executor resolves the live subgraph
196
+ // from the template cache at run time (C3.2 / C4.4). Editing the source
197
+ // template later will retroactively change what this instance executes
198
+ // (the "live link" model); the port list is cloned so a port rename on
199
+ // the template doesn't silently invalidate the outer wiring on this
200
+ // instance (the user can manually re-sync by forking + re-saving).
201
+ function addTemplateInstance(template: TemplateSummary, at?: XY) {
202
+ const node: AppGraphNode & {
203
+ ports: GroupPort[];
204
+ templateId: string;
205
+ } = {
206
+ id: newId(),
207
+ kind: "group",
208
+ config: { name: template.name },
209
+ position: { x: 0, y: 0 },
210
+ templateId: template._id,
211
+ // JSON round-trip strips Vue's reactive proxy that wraps the template
212
+ // passed from the palette; structuredClone throws on proxies.
213
+ ports: JSON.parse(JSON.stringify(template.ports ?? [])) as GroupPort[],
214
+ };
215
+ insertNode(node, at);
216
+ }
217
+
218
+ // A block dragged from the palette lands where it is dropped.
219
+ function onDragOver(event: DragEvent) {
220
+ if (
221
+ props.readOnly ||
222
+ !event.dataTransfer?.types.includes(PALETTE_DRAG_TYPE)
223
+ )
224
+ return;
225
+ event.preventDefault();
226
+ event.dataTransfer.dropEffect = "copy";
227
+ }
228
+
229
+ function onDrop(event: DragEvent) {
230
+ const raw = event.dataTransfer?.getData(PALETTE_DRAG_TYPE);
231
+ const flow = flowRef.value;
232
+ if (props.readOnly || !raw || !flow) return;
233
+ event.preventDefault();
234
+ const point = flow.screenToFlowCoordinate({
235
+ x: event.clientX,
236
+ y: event.clientY,
237
+ });
238
+ const at = {
239
+ x: point.x - NEW_NODE_SIZE.width / 2,
240
+ y: point.y - NEW_NODE_SIZE.height / 2,
241
+ };
242
+ const block = JSON.parse(raw) as PaletteBlock;
243
+ if (block.template) addTemplateInstance(block.template, at);
244
+ else if (block.kind) addNode(block.kind, block.typeId, at);
245
+ }
246
+
247
+ return { addNode, addTemplateInstance, onDragOver, onDrop };
248
+ }