@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,74 @@
1
+ import type { GraphIssue } from "../../types/editor";
2
+
3
+ export interface SaveRefusal {
4
+ data?: {
5
+ issues?: Array<
6
+ | {
7
+ severity?: string;
8
+ message?: string;
9
+ code?: string;
10
+ params?: Record<string, unknown>;
11
+ nodeId?: string;
12
+ path?: unknown[];
13
+ }
14
+ | string
15
+ >;
16
+ };
17
+ }
18
+
19
+ export function issuesOf(error: unknown): GraphIssue[] | null {
20
+ const raw = (error as SaveRefusal)?.data?.issues;
21
+ if (!Array.isArray(raw)) return null;
22
+ // A field of the body other than the graph (zod issues carry its path) is
23
+ // not a problem of the graph.
24
+ if (
25
+ raw.some(
26
+ (issue) =>
27
+ typeof issue === "object" &&
28
+ Array.isArray(issue.path) &&
29
+ issue.path[0] !== "graph",
30
+ )
31
+ )
32
+ return null;
33
+ return raw.map((issue) =>
34
+ typeof issue === "string"
35
+ ? { severity: "error" as const, message: issue }
36
+ : {
37
+ severity: issue.severity === "warning" ? "warning" : "error",
38
+ message: issue.message ?? "",
39
+ code: issue.code,
40
+ params: issue.params,
41
+ nodeId: issue.nodeId,
42
+ },
43
+ );
44
+ }
45
+
46
+ /** Formats structured template validation issues and reference cycles. */
47
+ export function formatTemplateError(err: unknown): string | null {
48
+ const data = (err as { data?: unknown; message?: string } | undefined)
49
+ ?.data as
50
+ | {
51
+ error?: string;
52
+ issues?: Array<
53
+ { path?: Array<string | number>; message?: string } | string
54
+ >;
55
+ cycle?: string[];
56
+ }
57
+ | undefined;
58
+ if (data && typeof data === "object") {
59
+ const head = data.error ?? "Request failed";
60
+ if (Array.isArray(data.issues) && data.issues.length > 0) {
61
+ const lines = data.issues.map((iss) => {
62
+ if (typeof iss === "string") return iss;
63
+ const path = Array.isArray(iss.path) ? iss.path.join(".") : "";
64
+ const msg = iss.message ?? "invalid";
65
+ return path ? `${path}: ${msg}` : msg;
66
+ });
67
+ return `${head}\n${lines.join("\n")}`;
68
+ }
69
+ if (Array.isArray(data.cycle) && data.cycle.length > 0) {
70
+ return `${head}: ${data.cycle.join(" → ")}`;
71
+ }
72
+ }
73
+ return null;
74
+ }
@@ -0,0 +1,68 @@
1
+ import type {
2
+ GraphNode,
3
+ ProcedureGraph,
4
+ } from "../../../composables/useGraphConnect";
5
+
6
+ export function cloneGraph(g: ProcedureGraph): ProcedureGraph {
7
+ return JSON.parse(JSON.stringify(g));
8
+ }
9
+
10
+ // Strip per-node position: a drag is told apart from a structural change.
11
+ export function structuralKey(g: ProcedureGraph): string {
12
+ return JSON.stringify({
13
+ nodes: g.nodes.map(({ position: _pos, ...rest }) => rest),
14
+ triggerEdges: g.triggerEdges,
15
+ dataEdges: g.dataEdges,
16
+ });
17
+ }
18
+
19
+ /**
20
+ * What a change does, when it is one a burst of changes repeats: the same
21
+ * nodes moved ("move:a,b"), or the same settings of one node edited
22
+ * ("edit:a:url"), at any depth of groups. `null` for anything else.
23
+ */
24
+ export function repeatableChangeKey(
25
+ before: ProcedureGraph,
26
+ after: ProcedureGraph,
27
+ ): string | null {
28
+ if (
29
+ JSON.stringify([before.triggerEdges, before.dataEdges]) !==
30
+ JSON.stringify([after.triggerEdges, after.dataEdges])
31
+ )
32
+ return null;
33
+ if (before.nodes.length !== after.nodes.length) return null;
34
+ const moved: string[] = [];
35
+ let edited: string | null = null;
36
+ for (let i = 0; i < after.nodes.length; i++) {
37
+ const a = before.nodes[i]! as GraphNode & Record<string, unknown>;
38
+ const b = after.nodes[i]! as GraphNode & Record<string, unknown>;
39
+ if (a.id !== b.id) return null;
40
+ const keys = [...new Set([...Object.keys(a), ...Object.keys(b)])].filter(
41
+ (k) => JSON.stringify(a[k]) !== JSON.stringify(b[k]),
42
+ );
43
+ if (keys.length === 0) continue;
44
+ if (keys.length === 1 && keys[0] === "position") {
45
+ moved.push(a.id);
46
+ continue;
47
+ }
48
+ if (edited) return null;
49
+ if (
50
+ keys.length === 1 &&
51
+ keys[0] === "subgraph" &&
52
+ a.subgraph &&
53
+ b.subgraph
54
+ ) {
55
+ const inner = repeatableChangeKey(a.subgraph, b.subgraph);
56
+ if (!inner) return null;
57
+ edited = `${a.id}/${inner}`;
58
+ continue;
59
+ }
60
+ if (!keys.every((k) => k === "config" || k === "label")) return null;
61
+ const fields = Object.keys({ ...a.config, ...b.config }).filter(
62
+ (k) => JSON.stringify(a.config?.[k]) !== JSON.stringify(b.config?.[k]),
63
+ );
64
+ edited = `${a.id}:${[...fields, ...(keys.includes("label") ? ["label"] : [])].join(",")}`;
65
+ }
66
+ if (edited) return moved.length ? null : `edit:${edited}`;
67
+ return moved.length ? `move:${moved.join(",")}` : null;
68
+ }
@@ -0,0 +1,322 @@
1
+ import type { NodeKindEntry } from "../../../composables/useAutomationNodeKinds";
2
+ import type {
3
+ ActionType,
4
+ DataEdge,
5
+ DataNodeType,
6
+ GroupPort,
7
+ JsonSchema,
8
+ JsonSchemaProperty,
9
+ ProcedureGraph,
10
+ TriggerEdge,
11
+ TriggerType,
12
+ } from "../../../composables/useGraphConnect";
13
+ import { newId } from "../../../utils/automation";
14
+
15
+ /** What the schema lookups read, each as the editor's computed holds it. */
16
+ export interface SchemaSources {
17
+ readonly currentGraph: { readonly value: ProcedureGraph | null };
18
+ readonly nodeKinds: { readonly value: NodeKindEntry[] };
19
+ readonly triggerTypes: { readonly value: TriggerType[] };
20
+ readonly actionTypes: { readonly value: ActionType[] };
21
+ readonly dataNodeTypes: { readonly value: DataNodeType[] };
22
+ }
23
+
24
+ // Friendly default port names. Each cut edge maps to a desired name based on
25
+ // the user-facing label on the cut side; if two edges land on the same name
26
+ // (e.g. two inside actions both have an `input` field), we suffix `-2`, `-3`
27
+ // per (kind, direction). The user can rename later in the GroupPortEditor.
28
+ //
29
+ // Port name picks:
30
+ // data-in → target node's input field name
31
+ // data-out → source node's output port name
32
+ // trigger-in → source branch label if present, else 'main'
33
+ // trigger-out → source branch label if present, else 'main'
34
+ //
35
+ // The "main" default for non-branching trigger cuts is intentional: the
36
+ // GroupNode / sentinel renderers place a trigger port named "main" on the
37
+ // title bar (mirroring ordinary trigger/action nodes), so a typical group
38
+ // wrapping linear flow looks just like a single action — title-bar in/out.
39
+ // Branch-labeled ports (if.then, switch.<case>, …) render in the body.
40
+ export function desiredPortNameForTrigger(branch: string | undefined): string {
41
+ return branch && branch.length > 0 ? branch : "main";
42
+ }
43
+
44
+ // Dedup against an already-declared set scoped to (kind, direction). The set
45
+ // is mutated as new names are reserved.
46
+ export function uniqueName(desired: string, taken: Set<string>): string {
47
+ if (!taken.has(desired)) {
48
+ taken.add(desired);
49
+ return desired;
50
+ }
51
+ let i = 2;
52
+ while (taken.has(`${desired}-${i}`)) i++;
53
+ const final = `${desired}-${i}`;
54
+ taken.add(final);
55
+ return final;
56
+ }
57
+
58
+ export interface NewGroupPlan {
59
+ groupId: string;
60
+ groupPorts: GroupPort[];
61
+ // Sentinel node ids — the planner generates them up front so its inner
62
+ // edges reference real ids; the caller installs the sentinel nodes
63
+ // under these ids.
64
+ groupInputId: string;
65
+ groupOutputId: string;
66
+ // Edges to add to the outer graph (replacements for cut edges).
67
+ outerTriggerEdges: TriggerEdge[];
68
+ outerDataEdges: DataEdge[];
69
+ // Edges to add inside the new subgraph (connecting sentinels to the
70
+ // inner endpoints of the cut edges).
71
+ innerTriggerEdges: TriggerEdge[];
72
+ innerDataEdges: DataEdge[];
73
+ }
74
+
75
+ // Build a JsonSchema property bag from a kind's declared static port
76
+ // list — used as the fallback when no type-registry schema applies.
77
+ export function staticPortsToSchema(
78
+ ports: ReadonlyArray<{ name: string; type?: string }>,
79
+ ): JsonSchema {
80
+ const properties: Record<string, JsonSchemaProperty> = {};
81
+ for (const p of ports) {
82
+ properties[p.name] = p.type ? { type: p.type } : {};
83
+ }
84
+ return { properties };
85
+ }
86
+
87
+ export function findSchemaForDataSourcePort(
88
+ sources: SchemaSources,
89
+ nodeId: string,
90
+ port: string,
91
+ ): JsonSchema | undefined {
92
+ const { currentGraph, nodeKinds, triggerTypes, actionTypes, dataNodeTypes } =
93
+ sources;
94
+ const g = currentGraph.value;
95
+ if (!g) return undefined;
96
+ const node = g.nodes.find((n) => n.id === nodeId);
97
+ if (!node) return undefined;
98
+ // `group` carries its ports on the node itself, not in the kind registry.
99
+ if (node.kind === "group") {
100
+ const p = (node.ports ?? []).find(
101
+ (pp) => pp.kind === "data" && pp.direction === "out" && pp.name === port,
102
+ );
103
+ return p?.schema as JsonSchema | undefined;
104
+ }
105
+ const ui = nodeKinds.value.find((k) => k.kind === node.kind)?.meta.ui;
106
+ if (!ui) return undefined;
107
+ let outputSchema: JsonSchema | undefined;
108
+ if (ui.typeRegistry && ui.dataOutsFromTypeSchema) {
109
+ const key = ui.dataOutsFromTypeSchema;
110
+ if (ui.typeRegistry === "triggers") {
111
+ const t = triggerTypes.value.find((tt) => tt.id === node.typeId) as
112
+ | Record<string, JsonSchema | undefined>
113
+ | undefined;
114
+ outputSchema = t?.[key];
115
+ } else if (ui.typeRegistry === "actions") {
116
+ const a = actionTypes.value.find((aa) => aa.id === node.typeId) as
117
+ | Record<string, JsonSchema | undefined>
118
+ | undefined;
119
+ outputSchema = a?.[key];
120
+ } else {
121
+ const d = dataNodeTypes.value.find((dd) => dd.id === node.typeId) as
122
+ | Record<string, JsonSchema | undefined>
123
+ | undefined;
124
+ outputSchema = d?.[key];
125
+ }
126
+ }
127
+ if (!outputSchema && ui.staticDataOuts.length > 0) {
128
+ outputSchema = staticPortsToSchema(ui.staticDataOuts);
129
+ }
130
+ const prop = outputSchema?.properties?.[port];
131
+ if (!prop) return undefined;
132
+ return prop as JsonSchema;
133
+ }
134
+
135
+ export function findSchemaForDataTargetField(
136
+ sources: SchemaSources,
137
+ nodeId: string,
138
+ field: string,
139
+ ): JsonSchema | undefined {
140
+ const { currentGraph, nodeKinds, triggerTypes, actionTypes, dataNodeTypes } =
141
+ sources;
142
+ const g = currentGraph.value;
143
+ if (!g) return undefined;
144
+ const node = g.nodes.find((n) => n.id === nodeId);
145
+ if (!node) return undefined;
146
+ if (node.kind === "group") {
147
+ const p = (node.ports ?? []).find(
148
+ (pp) => pp.kind === "data" && pp.direction === "in" && pp.name === field,
149
+ );
150
+ return p?.schema as JsonSchema | undefined;
151
+ }
152
+ const ui = nodeKinds.value.find((k) => k.kind === node.kind)?.meta.ui;
153
+ if (!ui) return undefined;
154
+ let inputSchema: JsonSchema | undefined;
155
+ if (ui.typeRegistry && ui.dataInsFromTypeSchema) {
156
+ const key = ui.dataInsFromTypeSchema;
157
+ if (ui.typeRegistry === "actions") {
158
+ const a = actionTypes.value.find((aa) => aa.id === node.typeId) as
159
+ | Record<string, JsonSchema | undefined>
160
+ | undefined;
161
+ inputSchema = a?.[key];
162
+ } else if (ui.typeRegistry === "dataNodes") {
163
+ const d = dataNodeTypes.value.find((dd) => dd.id === node.typeId) as
164
+ | Record<string, JsonSchema | undefined>
165
+ | undefined;
166
+ inputSchema = d?.[key];
167
+ } else {
168
+ const t = triggerTypes.value.find((tt) => tt.id === node.typeId) as
169
+ | Record<string, JsonSchema | undefined>
170
+ | undefined;
171
+ inputSchema = t?.[key];
172
+ }
173
+ }
174
+ if (!inputSchema && ui.staticDataIns.length > 0) {
175
+ inputSchema = staticPortsToSchema(ui.staticDataIns);
176
+ }
177
+ const prop = inputSchema?.properties?.[field];
178
+ if (!prop) return undefined;
179
+ return prop as JsonSchema;
180
+ }
181
+
182
+ export function planNewGroup(
183
+ g: ProcedureGraph,
184
+ selection: Set<string>,
185
+ groupId: string,
186
+ sources: SchemaSources,
187
+ ): NewGroupPlan {
188
+ const ports: GroupPort[] = [];
189
+ const outerTriggerEdges: TriggerEdge[] = [];
190
+ const outerDataEdges: DataEdge[] = [];
191
+ const innerTriggerEdges: TriggerEdge[] = [];
192
+ const innerDataEdges: DataEdge[] = [];
193
+
194
+ // Per (kind, direction) name reservations — keeps dedup scoped so a
195
+ // data-in "input" and a data-out "output" can coexist even if a
196
+ // hypothetical trigger-in shared the same desired label.
197
+ const takenDataIn = new Set<string>();
198
+ const takenDataOut = new Set<string>();
199
+ const takenTriggerIn = new Set<string>();
200
+ const takenTriggerOut = new Set<string>();
201
+
202
+ // We need sentinel ids that match the ones syncSentinels will (re)use.
203
+ // Generate them up front so the inner edges below can reference them;
204
+ // then we splat them into the subgraph and let syncSentinels see them
205
+ // already in place.
206
+ const groupInputId = newId();
207
+ const groupOutputId = newId();
208
+
209
+ for (const e of g.triggerEdges) {
210
+ const fromIn = selection.has(e.from.node);
211
+ const toIn = selection.has(e.to.node);
212
+ if (fromIn === toIn) continue; // both inside or both outside → not cut
213
+ if (fromIn && !toIn) {
214
+ // Cut: source inside, target outside → declare trigger-out port.
215
+ const name = uniqueName(
216
+ desiredPortNameForTrigger(e.from.branch),
217
+ takenTriggerOut,
218
+ );
219
+ ports.push({ kind: "trigger", direction: "out", name });
220
+ // Outer: new edge from the OUTER group node's trigger-out handle
221
+ // to the original target node. `from.branch` IS the port name —
222
+ // matches how connect parses `group-trigger-out-<port>`.
223
+ outerTriggerEdges.push({
224
+ id: newId(),
225
+ from: { node: groupId, branch: name },
226
+ to: { node: e.to.node },
227
+ });
228
+ // Inner: original source node fires into groupOutput. Source-side
229
+ // branch is preserved verbatim (for if/switch routing); target
230
+ // port name lives on `to.branch` so the renderer can pick the
231
+ // right `groupOutput-trigger-in-<port>` handle.
232
+ innerTriggerEdges.push({
233
+ id: newId(),
234
+ from: { node: e.from.node, branch: e.from.branch },
235
+ to: { node: groupOutputId, branch: name },
236
+ });
237
+ } else {
238
+ // Cut: source outside, target inside → declare trigger-in port.
239
+ const name = uniqueName(
240
+ desiredPortNameForTrigger(e.from.branch),
241
+ takenTriggerIn,
242
+ );
243
+ ports.push({ kind: "trigger", direction: "in", name });
244
+ // Outer: original source node fires into OUTER group node's
245
+ // trigger-in handle. Port name lives on `to.branch` (rendered as
246
+ // `group-trigger-in-<port>` via the renderer).
247
+ outerTriggerEdges.push({
248
+ id: newId(),
249
+ from: { node: e.from.node, branch: e.from.branch },
250
+ to: { node: groupId, branch: name },
251
+ });
252
+ // Inner: groupInput fires into original target. Port name lives
253
+ // on `from.branch` — matches the syncSentinels filter for
254
+ // trigger edges out of groupInput.
255
+ innerTriggerEdges.push({
256
+ id: newId(),
257
+ from: { node: groupInputId, branch: name },
258
+ to: { node: e.to.node },
259
+ });
260
+ }
261
+ }
262
+
263
+ for (const e of g.dataEdges) {
264
+ const fromIn = selection.has(e.from.node);
265
+ const toIn = selection.has(e.to.node);
266
+ if (fromIn === toIn) continue;
267
+ if (fromIn && !toIn) {
268
+ // Cut: source inside, target outside → declare data-out port.
269
+ const name = uniqueName(e.from.port, takenDataOut);
270
+ ports.push({
271
+ kind: "data",
272
+ direction: "out",
273
+ name,
274
+ schema: findSchemaForDataSourcePort(sources, e.from.node, e.from.port),
275
+ });
276
+ // Outer: group node's data-out → original target field.
277
+ outerDataEdges.push({
278
+ id: newId(),
279
+ from: { node: groupId, port: name },
280
+ to: { node: e.to.node, field: e.to.field },
281
+ });
282
+ // Inner: original source → groupOutput's data-in port (name).
283
+ innerDataEdges.push({
284
+ id: newId(),
285
+ from: { node: e.from.node, port: e.from.port },
286
+ to: { node: groupOutputId, field: name },
287
+ });
288
+ } else {
289
+ // Cut: source outside, target inside → declare data-in port.
290
+ const name = uniqueName(e.to.field, takenDataIn);
291
+ ports.push({
292
+ kind: "data",
293
+ direction: "in",
294
+ name,
295
+ schema: findSchemaForDataTargetField(sources, e.to.node, e.to.field),
296
+ });
297
+ // Outer: original source → group node's data-in port.
298
+ outerDataEdges.push({
299
+ id: newId(),
300
+ from: { node: e.from.node, port: e.from.port },
301
+ to: { node: groupId, field: name },
302
+ });
303
+ // Inner: groupInput's data-out → original target field.
304
+ innerDataEdges.push({
305
+ id: newId(),
306
+ from: { node: groupInputId, port: name },
307
+ to: { node: e.to.node, field: e.to.field },
308
+ });
309
+ }
310
+ }
311
+
312
+ return {
313
+ groupId,
314
+ groupPorts: ports,
315
+ groupInputId,
316
+ groupOutputId,
317
+ outerTriggerEdges,
318
+ outerDataEdges,
319
+ innerTriggerEdges,
320
+ innerDataEdges,
321
+ };
322
+ }
@@ -0,0 +1,210 @@
1
+ import type {
2
+ DataEdge,
3
+ GraphNode,
4
+ GroupPort,
5
+ TriggerEdge,
6
+ } from "../../../composables/useGraphConnect";
7
+ import { newId } from "../../../utils/automation";
8
+
9
+ // Detect port renames between two port arrays of the same group node.
10
+ //
11
+ // Two-pass matching, scoped per (kind, direction):
12
+ // 1. Ports present in BOTH arrays under the same (kind, direction, name) are
13
+ // considered identical — no rename.
14
+ // 2. Of the remaining old/new ports, pair them positionally within each
15
+ // (kind, direction) bucket. Each pair is a rename (old.name → new.name).
16
+ // Unpaired old-only ports are true deletions; unpaired new-only ports are
17
+ // true additions.
18
+ //
19
+ // This is heuristic but the GroupPortEditor emits one mutation per UX action,
20
+ // so each ports:update typically carries a single delta and the positional
21
+ // pairing is unambiguous.
22
+ export interface PortRename {
23
+ kind: "data" | "trigger";
24
+ direction: "in" | "out";
25
+ oldName: string;
26
+ newName: string;
27
+ }
28
+
29
+ export function detectPortRenames(
30
+ oldPorts: GroupPort[],
31
+ newPorts: GroupPort[],
32
+ ): PortRename[] {
33
+ const renames: PortRename[] = [];
34
+ const buckets: Array<{ kind: "data" | "trigger"; direction: "in" | "out" }> =
35
+ [
36
+ { kind: "data", direction: "in" },
37
+ { kind: "data", direction: "out" },
38
+ { kind: "trigger", direction: "in" },
39
+ { kind: "trigger", direction: "out" },
40
+ ];
41
+ for (const b of buckets) {
42
+ const oldInBucket = oldPorts.filter(
43
+ (p) => p.kind === b.kind && p.direction === b.direction,
44
+ );
45
+ const newInBucket = newPorts.filter(
46
+ (p) => p.kind === b.kind && p.direction === b.direction,
47
+ );
48
+ const newNames = new Set(newInBucket.map((p) => p.name));
49
+ const oldNames = new Set(oldInBucket.map((p) => p.name));
50
+ // Ports that exist in both arrays with the same name didn't change.
51
+ const oldOnly = oldInBucket.filter((p) => !newNames.has(p.name));
52
+ const newOnly = newInBucket.filter((p) => !oldNames.has(p.name));
53
+ const pairCount = Math.min(oldOnly.length, newOnly.length);
54
+ for (let i = 0; i < pairCount; i++) {
55
+ renames.push({
56
+ kind: b.kind,
57
+ direction: b.direction,
58
+ oldName: oldOnly[i]!.name,
59
+ newName: newOnly[i]!.name,
60
+ });
61
+ }
62
+ }
63
+ return renames;
64
+ }
65
+
66
+ // Rewrite edge endpoints that referenced the renamed port names. Mutates the
67
+ // provided edge arrays in place.
68
+ //
69
+ // `nodeId` is the node owning the renamed ports — either the outer group node
70
+ // (for the outer graph's edges) or a sentinel node id inside the subgraph (for
71
+ // the inner edges). The direction of the rename determines which edge end is
72
+ // affected:
73
+ // • data/in → edge.to.field when edge.to.node === nodeId
74
+ // • data/out → edge.from.port when edge.from.node === nodeId
75
+ // • trigger/in → edge.to.branch when edge.to.node === nodeId
76
+ // • trigger/out → edge.from.branch when edge.from.node === nodeId
77
+ //
78
+ // For the inner subgraph, the sentinels invert the direction (an inbound port
79
+ // on the group is an OUTBOUND handle on the groupInput sentinel and vice
80
+ // versa). Callers pass `invertDirection: true` so a group-level "in" rename is
81
+ // applied to the sentinel's "out" handles, etc.
82
+ export function applyPortRenamesToEdges(
83
+ triggerEdges: TriggerEdge[],
84
+ dataEdges: DataEdge[],
85
+ nodeId: string,
86
+ renames: PortRename[],
87
+ invertDirection: boolean,
88
+ ): void {
89
+ for (const r of renames) {
90
+ const effectiveDirection = invertDirection
91
+ ? r.direction === "in"
92
+ ? "out"
93
+ : "in"
94
+ : r.direction;
95
+ if (r.kind === "data") {
96
+ if (effectiveDirection === "out") {
97
+ for (const e of dataEdges) {
98
+ if (e.from.node === nodeId && e.from.port === r.oldName) {
99
+ e.from.port = r.newName;
100
+ }
101
+ }
102
+ } else {
103
+ for (const e of dataEdges) {
104
+ if (e.to.node === nodeId && e.to.field === r.oldName) {
105
+ e.to.field = r.newName;
106
+ }
107
+ }
108
+ }
109
+ } else {
110
+ if (effectiveDirection === "out") {
111
+ for (const e of triggerEdges) {
112
+ if (e.from.node === nodeId && e.from.branch === r.oldName) {
113
+ e.from.branch = r.newName;
114
+ }
115
+ }
116
+ } else {
117
+ for (const e of triggerEdges) {
118
+ if (e.to.node === nodeId && e.to.branch === r.oldName) {
119
+ e.to.branch = r.newName;
120
+ }
121
+ }
122
+ }
123
+ }
124
+ }
125
+ }
126
+
127
+ // Make sure the group node's local subgraph has the sentinels and that no
128
+ // inner edge references a port that was just removed. The sentinels are
129
+ // auto-managed (the user never creates them by hand); their handle set is
130
+ // derived at render time from the parent group's `ports` array (see
131
+ // GraphCanvas.vue `parent-group-ports` prop plumbing), so this
132
+ // function only owns four responsibilities:
133
+ // 1. Ensure a single groupInput and a single groupOutput exist.
134
+ // 2. Drop data edges whose source/target port no longer exists.
135
+ // 3. Drop trigger edges whose source branch (originating at groupInput)
136
+ // no longer exists.
137
+ // 4. Drop trigger edges into groupOutput whose target port (`to.branch`)
138
+ // no longer exists.
139
+ export function syncSentinels(group: GraphNode): void {
140
+ if (!group.subgraph) return;
141
+
142
+ let gi = group.subgraph.nodes.find((n) => n.kind === "groupInput");
143
+ let go = group.subgraph.nodes.find((n) => n.kind === "groupOutput");
144
+
145
+ if (!gi) {
146
+ gi = {
147
+ id: newId(),
148
+ kind: "groupInput",
149
+ config: {},
150
+ position: { x: 0, y: 0 },
151
+ };
152
+ group.subgraph.nodes.push(gi);
153
+ }
154
+ if (!go) {
155
+ go = {
156
+ id: newId(),
157
+ kind: "groupOutput",
158
+ config: {},
159
+ position: { x: 600, y: 0 },
160
+ };
161
+ group.subgraph.nodes.push(go);
162
+ }
163
+
164
+ const ports = Array.isArray(group.ports) ? group.ports : [];
165
+ const validDataIn = new Set(
166
+ ports
167
+ .filter((p) => p.kind === "data" && p.direction === "in")
168
+ .map((p) => p.name),
169
+ );
170
+ const validDataOut = new Set(
171
+ ports
172
+ .filter((p) => p.kind === "data" && p.direction === "out")
173
+ .map((p) => p.name),
174
+ );
175
+ const validTriggerIn = new Set(
176
+ ports
177
+ .filter((p) => p.kind === "trigger" && p.direction === "in")
178
+ .map((p) => p.name),
179
+ );
180
+ const validTriggerOut = new Set(
181
+ ports
182
+ .filter((p) => p.kind === "trigger" && p.direction === "out")
183
+ .map((p) => p.name),
184
+ );
185
+
186
+ const giId = gi.id;
187
+ const goId = go.id;
188
+
189
+ group.subgraph.dataEdges = group.subgraph.dataEdges.filter((e) => {
190
+ if (e.from.node === giId && !validDataIn.has(e.from.port)) return false;
191
+ if (e.to.node === goId && !validDataOut.has(e.to.field)) return false;
192
+ return true;
193
+ });
194
+
195
+ group.subgraph.triggerEdges = group.subgraph.triggerEdges.filter((e) => {
196
+ // trigger edges OUT OF groupInput carry the port name as `from.branch`
197
+ // (the same convention if/switch use for named branches).
198
+ if (e.from.node === giId) {
199
+ const branch = e.from.branch ?? "main";
200
+ if (!validTriggerIn.has(branch)) return false;
201
+ }
202
+ // trigger edges INTO groupOutput carry the target port name on
203
+ // `to.branch`. If the port has been removed from the group's
204
+ // declarations, drop the edge.
205
+ if (e.to.node === goId && e.to.branch !== undefined) {
206
+ if (!validTriggerOut.has(e.to.branch)) return false;
207
+ }
208
+ return true;
209
+ });
210
+ }
@@ -0,0 +1,22 @@
1
+ export function isEditableTarget(target: EventTarget | null): boolean {
2
+ if (!(target instanceof HTMLElement)) return false;
3
+ const tag = target.tagName;
4
+ if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT") return true;
5
+ if (target.isContentEditable) return true;
6
+ return false;
7
+ }
8
+
9
+ // Open overlays only: a closing dialog stays in the page while it animates
10
+ // out, and a non-modal card (the DMS star prompt) has no state at all.
11
+ export const OVERLAY_SELECTOR =
12
+ ':is([role="dialog"], [role="alertdialog"], [role="menu"], [role="listbox"])[data-state="open"]';
13
+
14
+ /** Enter belongs to a focused button or link; elsewhere it enters a group. */
15
+ export function isActivatable(target: EventTarget | null): boolean {
16
+ return (
17
+ target instanceof Element &&
18
+ target.closest(
19
+ 'button, a[href], [role="button"], [role="tab"], [role="menuitem"], [role="option"]',
20
+ ) !== null
21
+ );
22
+ }