@decaf-ts/ui-decorators 0.20.9 → 0.21.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 (215) hide show
  1. package/dist/ui-decorators.cjs +1 -1
  2. package/lib/cjs/graph/catalog/GraphManifestCompiler.cjs +19 -0
  3. package/lib/cjs/graph/catalog/GraphManifestCompiler.cjs.map +1 -1
  4. package/lib/cjs/graph/catalog/GraphPortManifestElement.cjs +15 -0
  5. package/lib/cjs/graph/catalog/GraphPortManifestElement.cjs.map +1 -0
  6. package/lib/cjs/graph/catalog/index.cjs +1 -0
  7. package/lib/cjs/graph/catalog/index.cjs.map +1 -1
  8. package/lib/cjs/graph/{nodes/category-styles.cjs → category-styles.cjs} +2 -2
  9. package/lib/cjs/graph/category-styles.cjs.map +1 -0
  10. package/lib/cjs/graph/index.cjs +1 -1
  11. package/lib/cjs/graph/index.cjs.map +1 -1
  12. package/lib/cjs/graph/reader.cjs +26 -0
  13. package/lib/cjs/graph/reader.cjs.map +1 -1
  14. package/lib/cjs/graph/snapshot.cjs +0 -691
  15. package/lib/cjs/graph/snapshot.cjs.map +1 -1
  16. package/lib/cjs/index.cjs +3 -3
  17. package/lib/esm/graph/catalog/GraphManifestCompiler.js +20 -1
  18. package/lib/esm/graph/catalog/GraphManifestCompiler.js.map +1 -1
  19. package/lib/esm/graph/catalog/GraphPortManifest.js.map +1 -1
  20. package/lib/esm/graph/catalog/GraphPortManifestElement.js +11 -0
  21. package/lib/esm/graph/catalog/GraphPortManifestElement.js.map +1 -0
  22. package/lib/esm/graph/catalog/index.js +1 -0
  23. package/lib/esm/graph/catalog/index.js.map +1 -1
  24. package/lib/esm/graph/{nodes/category-styles.js → category-styles.js} +2 -2
  25. package/lib/esm/graph/category-styles.js.map +1 -0
  26. package/lib/esm/graph/index.js +1 -1
  27. package/lib/esm/graph/index.js.map +1 -1
  28. package/lib/esm/graph/reader.js +25 -0
  29. package/lib/esm/graph/reader.js.map +1 -1
  30. package/lib/esm/graph/snapshot.js +1 -679
  31. package/lib/esm/graph/snapshot.js.map +1 -1
  32. package/lib/esm/index.js +3 -3
  33. package/lib/types/graph/catalog/GraphPortManifest.d.cts +2 -0
  34. package/lib/types/graph/catalog/GraphPortManifest.d.mts +2 -0
  35. package/lib/types/graph/catalog/GraphPortManifestElement.d.cts +7 -0
  36. package/lib/types/graph/catalog/GraphPortManifestElement.d.mts +7 -0
  37. package/lib/types/graph/catalog/index.d.cts +1 -0
  38. package/lib/types/graph/catalog/index.d.mts +1 -0
  39. package/lib/types/graph/index.d.cts +1 -1
  40. package/lib/types/graph/index.d.mts +1 -1
  41. package/lib/types/graph/reader.d.cts +12 -0
  42. package/lib/types/graph/reader.d.mts +12 -0
  43. package/lib/types/graph/snapshot.d.cts +4 -144
  44. package/lib/types/graph/snapshot.d.mts +4 -144
  45. package/lib/types/graph/types.d.cts +1 -1
  46. package/lib/types/graph/types.d.mts +1 -1
  47. package/lib/types/index.d.cts +3 -3
  48. package/lib/types/index.d.mts +3 -3
  49. package/package.json +1 -1
  50. package/lib/cjs/graph/nodes/agents/agent.cjs +0 -110
  51. package/lib/cjs/graph/nodes/agents/agent.cjs.map +0 -1
  52. package/lib/cjs/graph/nodes/base.cjs +0 -36
  53. package/lib/cjs/graph/nodes/base.cjs.map +0 -1
  54. package/lib/cjs/graph/nodes/boundary/input-value.cjs +0 -57
  55. package/lib/cjs/graph/nodes/boundary/input-value.cjs.map +0 -1
  56. package/lib/cjs/graph/nodes/category-styles.cjs.map +0 -1
  57. package/lib/cjs/graph/nodes/flow-control/break.cjs +0 -63
  58. package/lib/cjs/graph/nodes/flow-control/break.cjs.map +0 -1
  59. package/lib/cjs/graph/nodes/flow-control/error-boundary.cjs +0 -67
  60. package/lib/cjs/graph/nodes/flow-control/error-boundary.cjs.map +0 -1
  61. package/lib/cjs/graph/nodes/flow-control/human-approval.cjs +0 -69
  62. package/lib/cjs/graph/nodes/flow-control/human-approval.cjs.map +0 -1
  63. package/lib/cjs/graph/nodes/flow-control/if.cjs +0 -71
  64. package/lib/cjs/graph/nodes/flow-control/if.cjs.map +0 -1
  65. package/lib/cjs/graph/nodes/flow-control/parallel.cjs +0 -61
  66. package/lib/cjs/graph/nodes/flow-control/parallel.cjs.map +0 -1
  67. package/lib/cjs/graph/nodes/flow-control/switch.cjs +0 -126
  68. package/lib/cjs/graph/nodes/flow-control/switch.cjs.map +0 -1
  69. package/lib/cjs/graph/nodes/index.cjs +0 -123
  70. package/lib/cjs/graph/nodes/index.cjs.map +0 -1
  71. package/lib/cjs/graph/nodes/loops/foreach.cjs +0 -86
  72. package/lib/cjs/graph/nodes/loops/foreach.cjs.map +0 -1
  73. package/lib/cjs/graph/nodes/loops/until.cjs +0 -74
  74. package/lib/cjs/graph/nodes/loops/until.cjs.map +0 -1
  75. package/lib/cjs/graph/nodes/loops/while.cjs +0 -74
  76. package/lib/cjs/graph/nodes/loops/while.cjs.map +0 -1
  77. package/lib/cjs/graph/nodes/manifests.cjs +0 -342
  78. package/lib/cjs/graph/nodes/manifests.cjs.map +0 -1
  79. package/lib/cjs/graph/nodes/triggers/chat.cjs +0 -70
  80. package/lib/cjs/graph/nodes/triggers/chat.cjs.map +0 -1
  81. package/lib/cjs/graph/nodes/triggers/event.cjs +0 -58
  82. package/lib/cjs/graph/nodes/triggers/event.cjs.map +0 -1
  83. package/lib/cjs/graph/nodes/triggers/form.cjs +0 -59
  84. package/lib/cjs/graph/nodes/triggers/form.cjs.map +0 -1
  85. package/lib/cjs/graph/nodes/triggers/manual.cjs +0 -60
  86. package/lib/cjs/graph/nodes/triggers/manual.cjs.map +0 -1
  87. package/lib/cjs/graph/nodes/triggers/schedule.cjs +0 -60
  88. package/lib/cjs/graph/nodes/triggers/schedule.cjs.map +0 -1
  89. package/lib/cjs/graph/nodes/triggers/webhook.cjs +0 -62
  90. package/lib/cjs/graph/nodes/triggers/webhook.cjs.map +0 -1
  91. package/lib/cjs/graph/nodes/utility/code.cjs +0 -99
  92. package/lib/cjs/graph/nodes/utility/code.cjs.map +0 -1
  93. package/lib/cjs/graph/nodes/utility/delay.cjs +0 -61
  94. package/lib/cjs/graph/nodes/utility/delay.cjs.map +0 -1
  95. package/lib/cjs/graph/nodes/utility/log.cjs +0 -62
  96. package/lib/cjs/graph/nodes/utility/log.cjs.map +0 -1
  97. package/lib/cjs/graph/nodes/utility/map.cjs +0 -61
  98. package/lib/cjs/graph/nodes/utility/map.cjs.map +0 -1
  99. package/lib/cjs/graph/nodes/utility/merge.cjs +0 -62
  100. package/lib/cjs/graph/nodes/utility/merge.cjs.map +0 -1
  101. package/lib/cjs/graph/nodes/utility/return.cjs +0 -61
  102. package/lib/cjs/graph/nodes/utility/return.cjs.map +0 -1
  103. package/lib/cjs/graph/nodes/utility/utility-log.cjs +0 -66
  104. package/lib/cjs/graph/nodes/utility/utility-log.cjs.map +0 -1
  105. package/lib/esm/graph/nodes/agents/agent.js +0 -101
  106. package/lib/esm/graph/nodes/agents/agent.js.map +0 -1
  107. package/lib/esm/graph/nodes/base.js +0 -31
  108. package/lib/esm/graph/nodes/base.js.map +0 -1
  109. package/lib/esm/graph/nodes/boundary/input-value.js +0 -48
  110. package/lib/esm/graph/nodes/boundary/input-value.js.map +0 -1
  111. package/lib/esm/graph/nodes/category-styles.js.map +0 -1
  112. package/lib/esm/graph/nodes/flow-control/break.js +0 -54
  113. package/lib/esm/graph/nodes/flow-control/break.js.map +0 -1
  114. package/lib/esm/graph/nodes/flow-control/error-boundary.js +0 -58
  115. package/lib/esm/graph/nodes/flow-control/error-boundary.js.map +0 -1
  116. package/lib/esm/graph/nodes/flow-control/human-approval.js +0 -60
  117. package/lib/esm/graph/nodes/flow-control/human-approval.js.map +0 -1
  118. package/lib/esm/graph/nodes/flow-control/if.js +0 -62
  119. package/lib/esm/graph/nodes/flow-control/if.js.map +0 -1
  120. package/lib/esm/graph/nodes/flow-control/parallel.js +0 -52
  121. package/lib/esm/graph/nodes/flow-control/parallel.js.map +0 -1
  122. package/lib/esm/graph/nodes/flow-control/switch.js +0 -117
  123. package/lib/esm/graph/nodes/flow-control/switch.js.map +0 -1
  124. package/lib/esm/graph/nodes/index.js +0 -105
  125. package/lib/esm/graph/nodes/index.js.map +0 -1
  126. package/lib/esm/graph/nodes/loops/foreach.js +0 -77
  127. package/lib/esm/graph/nodes/loops/foreach.js.map +0 -1
  128. package/lib/esm/graph/nodes/loops/until.js +0 -65
  129. package/lib/esm/graph/nodes/loops/until.js.map +0 -1
  130. package/lib/esm/graph/nodes/loops/while.js +0 -65
  131. package/lib/esm/graph/nodes/loops/while.js.map +0 -1
  132. package/lib/esm/graph/nodes/manifests.js +0 -338
  133. package/lib/esm/graph/nodes/manifests.js.map +0 -1
  134. package/lib/esm/graph/nodes/triggers/chat.js +0 -61
  135. package/lib/esm/graph/nodes/triggers/chat.js.map +0 -1
  136. package/lib/esm/graph/nodes/triggers/event.js +0 -49
  137. package/lib/esm/graph/nodes/triggers/event.js.map +0 -1
  138. package/lib/esm/graph/nodes/triggers/form.js +0 -50
  139. package/lib/esm/graph/nodes/triggers/form.js.map +0 -1
  140. package/lib/esm/graph/nodes/triggers/manual.js +0 -51
  141. package/lib/esm/graph/nodes/triggers/manual.js.map +0 -1
  142. package/lib/esm/graph/nodes/triggers/schedule.js +0 -51
  143. package/lib/esm/graph/nodes/triggers/schedule.js.map +0 -1
  144. package/lib/esm/graph/nodes/triggers/webhook.js +0 -53
  145. package/lib/esm/graph/nodes/triggers/webhook.js.map +0 -1
  146. package/lib/esm/graph/nodes/utility/code.js +0 -90
  147. package/lib/esm/graph/nodes/utility/code.js.map +0 -1
  148. package/lib/esm/graph/nodes/utility/delay.js +0 -52
  149. package/lib/esm/graph/nodes/utility/delay.js.map +0 -1
  150. package/lib/esm/graph/nodes/utility/log.js +0 -53
  151. package/lib/esm/graph/nodes/utility/log.js.map +0 -1
  152. package/lib/esm/graph/nodes/utility/map.js +0 -52
  153. package/lib/esm/graph/nodes/utility/map.js.map +0 -1
  154. package/lib/esm/graph/nodes/utility/merge.js +0 -53
  155. package/lib/esm/graph/nodes/utility/merge.js.map +0 -1
  156. package/lib/esm/graph/nodes/utility/return.js +0 -52
  157. package/lib/esm/graph/nodes/utility/return.js.map +0 -1
  158. package/lib/esm/graph/nodes/utility/utility-log.js +0 -57
  159. package/lib/esm/graph/nodes/utility/utility-log.js.map +0 -1
  160. package/lib/types/graph/nodes/agents/agent.d.cts +0 -44
  161. package/lib/types/graph/nodes/agents/agent.d.mts +0 -44
  162. package/lib/types/graph/nodes/base.d.cts +0 -28
  163. package/lib/types/graph/nodes/base.d.mts +0 -28
  164. package/lib/types/graph/nodes/boundary/input-value.d.cts +0 -13
  165. package/lib/types/graph/nodes/boundary/input-value.d.mts +0 -13
  166. package/lib/types/graph/nodes/flow-control/break.d.cts +0 -15
  167. package/lib/types/graph/nodes/flow-control/break.d.mts +0 -15
  168. package/lib/types/graph/nodes/flow-control/error-boundary.d.cts +0 -12
  169. package/lib/types/graph/nodes/flow-control/error-boundary.d.mts +0 -12
  170. package/lib/types/graph/nodes/flow-control/human-approval.d.cts +0 -13
  171. package/lib/types/graph/nodes/flow-control/human-approval.d.mts +0 -13
  172. package/lib/types/graph/nodes/flow-control/if.d.cts +0 -16
  173. package/lib/types/graph/nodes/flow-control/if.d.mts +0 -16
  174. package/lib/types/graph/nodes/flow-control/parallel.d.cts +0 -11
  175. package/lib/types/graph/nodes/flow-control/parallel.d.mts +0 -11
  176. package/lib/types/graph/nodes/flow-control/switch.d.cts +0 -21
  177. package/lib/types/graph/nodes/flow-control/switch.d.mts +0 -21
  178. package/lib/types/graph/nodes/index.d.cts +0 -79
  179. package/lib/types/graph/nodes/index.d.mts +0 -79
  180. package/lib/types/graph/nodes/loops/foreach.d.cts +0 -19
  181. package/lib/types/graph/nodes/loops/foreach.d.mts +0 -19
  182. package/lib/types/graph/nodes/loops/until.d.cts +0 -16
  183. package/lib/types/graph/nodes/loops/until.d.mts +0 -16
  184. package/lib/types/graph/nodes/loops/while.d.cts +0 -16
  185. package/lib/types/graph/nodes/loops/while.d.mts +0 -16
  186. package/lib/types/graph/nodes/manifests.d.cts +0 -62
  187. package/lib/types/graph/nodes/manifests.d.mts +0 -62
  188. package/lib/types/graph/nodes/triggers/chat.d.cts +0 -13
  189. package/lib/types/graph/nodes/triggers/chat.d.mts +0 -13
  190. package/lib/types/graph/nodes/triggers/event.d.cts +0 -10
  191. package/lib/types/graph/nodes/triggers/event.d.mts +0 -10
  192. package/lib/types/graph/nodes/triggers/form.d.cts +0 -11
  193. package/lib/types/graph/nodes/triggers/form.d.mts +0 -11
  194. package/lib/types/graph/nodes/triggers/manual.d.cts +0 -12
  195. package/lib/types/graph/nodes/triggers/manual.d.mts +0 -12
  196. package/lib/types/graph/nodes/triggers/schedule.d.cts +0 -11
  197. package/lib/types/graph/nodes/triggers/schedule.d.mts +0 -11
  198. package/lib/types/graph/nodes/triggers/webhook.d.cts +0 -11
  199. package/lib/types/graph/nodes/triggers/webhook.d.mts +0 -11
  200. package/lib/types/graph/nodes/utility/code.d.cts +0 -31
  201. package/lib/types/graph/nodes/utility/code.d.mts +0 -31
  202. package/lib/types/graph/nodes/utility/delay.d.cts +0 -11
  203. package/lib/types/graph/nodes/utility/delay.d.mts +0 -11
  204. package/lib/types/graph/nodes/utility/log.d.cts +0 -13
  205. package/lib/types/graph/nodes/utility/log.d.mts +0 -13
  206. package/lib/types/graph/nodes/utility/map.d.cts +0 -11
  207. package/lib/types/graph/nodes/utility/map.d.mts +0 -11
  208. package/lib/types/graph/nodes/utility/merge.d.cts +0 -12
  209. package/lib/types/graph/nodes/utility/merge.d.mts +0 -12
  210. package/lib/types/graph/nodes/utility/return.d.cts +0 -11
  211. package/lib/types/graph/nodes/utility/return.d.mts +0 -11
  212. package/lib/types/graph/nodes/utility/utility-log.d.cts +0 -15
  213. package/lib/types/graph/nodes/utility/utility-log.d.mts +0 -15
  214. /package/lib/types/graph/{nodes/category-styles.d.cts → category-styles.d.cts} +0 -0
  215. /package/lib/types/graph/{nodes/category-styles.d.mts → category-styles.d.mts} +0 -0
@@ -1,695 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GRAPH_WORKFLOW_SNAPSHOT_VERSION = void 0;
4
- exports.graphWorkflowSnapshotDefinitionOf = graphWorkflowSnapshotDefinitionOf;
5
- exports.graphWorkflowSnapshotOf = graphWorkflowSnapshotOf;
6
- exports.graphWorkflowSnapshotRestore = graphWorkflowSnapshotRestore;
7
- exports.graphWorkflowSnapshotToJSON = graphWorkflowSnapshotToJSON;
8
- exports.graphWorkflowSnapshotFromJSON = graphWorkflowSnapshotFromJSON;
9
- exports.graphWorkflowSnapshotInputValuesOf = graphWorkflowSnapshotInputValuesOf;
10
- exports.graphWorkflowSnapshotOutputValuesOf = graphWorkflowSnapshotOutputValuesOf;
11
- exports.graphWorkflowDocumentFromLegacySnapshot = graphWorkflowDocumentFromLegacySnapshot;
12
- exports.graphWorkflowSnapshotFromLegacy = graphWorkflowSnapshotFromLegacy;
13
- exports.graphWorkflowSnapshotToLegacy = graphWorkflowSnapshotToLegacy;
14
- exports.graphWorkflowSnapshotLikeToCanonical = graphWorkflowSnapshotLikeToCanonical;
15
- const reader_js_1 = require("./reader.cjs");
16
- const GraphJsonValue_js_1 = require("./document/GraphJsonValue.cjs");
17
- const GraphValueSchemaDerivation_js_1 = require("./catalog/GraphValueSchemaDerivation.cjs");
18
- const GRAPH_LEGACY_BOUNDARY_ALIASES = ["$workflow", "workflow", "graph"];
19
- const GRAPH_CONSTRUCTOR_DATA_KEYS = [
20
- "node",
21
- "modelClass",
22
- "sourceClass",
23
- "constructor",
24
- "definition",
25
- "executor",
26
- ];
27
- exports.GRAPH_WORKFLOW_SNAPSHOT_VERSION = 1;
28
- function isPlainObject(value) {
29
- return (!!value &&
30
- typeof value === "object" &&
31
- !Array.isArray(value) &&
32
- !(value instanceof Date));
33
- }
34
- function cloneValue(value) {
35
- if (Array.isArray(value)) {
36
- return value.map((entry) => cloneValue(entry));
37
- }
38
- if (value instanceof Date) {
39
- return new Date(value.getTime());
40
- }
41
- if (isPlainObject(value)) {
42
- const cloned = {};
43
- for (const [key, entry] of Object.entries(value)) {
44
- cloned[key] = cloneValue(entry);
45
- }
46
- return cloned;
47
- }
48
- return value;
49
- }
50
- function asString(value) {
51
- if (value === undefined || value === null)
52
- return undefined;
53
- return typeof value === "string" ? value : String(value);
54
- }
55
- function isWorkflowDefinitionLike(value) {
56
- return (isPlainObject(value) &&
57
- typeof value.name === "string" &&
58
- typeof value.tag === "string" &&
59
- typeof value.kind === "string" &&
60
- Array.isArray(value.inputs) &&
61
- Array.isArray(value.outputs) &&
62
- Array.isArray(value.nodes) &&
63
- Array.isArray(value.relations));
64
- }
65
- function snapshotNodeKey(node) {
66
- return node.ref?.id ?? node.id ?? node.ref?.path ?? node.ref?.property;
67
- }
68
- function snapshotEdgeKey(edge) {
69
- return (edge.id ??
70
- [edge.sourceRef ?? edge.source, edge.sourcePort, edge.targetRef ?? edge.target, edge.targetPort]
71
- .filter(Boolean)
72
- .join("::"));
73
- }
74
- function normalizeValueEntries(entries, definitions) {
75
- const byPath = new Map();
76
- if (Array.isArray(entries)) {
77
- for (const entry of entries) {
78
- if (!entry?.path)
79
- continue;
80
- byPath.set(entry.path, cloneValue(entry));
81
- }
82
- }
83
- else if (isPlainObject(entries)) {
84
- for (const [path, value] of Object.entries(entries)) {
85
- byPath.set(path, { path, value: cloneValue(value) });
86
- }
87
- }
88
- const normalized = definitions.map((definition) => {
89
- const path = definition.path ?? definition.property;
90
- const current = byPath.get(path);
91
- const entry = {
92
- label: definition.label,
93
- type: definition.type,
94
- required: definition.required,
95
- model: definition.model,
96
- metadata: cloneValue(definition.graph?.metadata ??
97
- definition.element?.props ??
98
- definition.prop?.props ??
99
- {}),
100
- ...current,
101
- path,
102
- };
103
- if (!Object.keys(entry.metadata || {}).length) {
104
- delete entry.metadata;
105
- }
106
- return entry;
107
- });
108
- for (const entry of byPath.values()) {
109
- if (normalized.some((current) => current.path === entry.path))
110
- continue;
111
- normalized.push(cloneValue(entry));
112
- }
113
- return normalized;
114
- }
115
- function normalizeNodes(nodes, definitions) {
116
- const byKey = new Map();
117
- const result = [];
118
- for (const definition of definitions) {
119
- const node = {
120
- id: definition.id,
121
- ref: {
122
- id: definition.id,
123
- kind: definition.kind,
124
- },
125
- label: definition.label,
126
- kind: definition.kind,
127
- data: definition.node !== undefined ? { node: cloneValue(definition.node) } : undefined,
128
- metadata: cloneValue(definition.metadata),
129
- };
130
- result.push(node);
131
- byKey.set(definition.id, node);
132
- }
133
- for (const entry of nodes || []) {
134
- const key = snapshotNodeKey(entry);
135
- const current = key ? byKey.get(key) : undefined;
136
- if (current) {
137
- const merged = {
138
- ...current,
139
- ...cloneValue(entry),
140
- id: entry.id || current.id,
141
- ref: {
142
- ...current.ref,
143
- ...entry.ref,
144
- id: entry.ref?.id ?? current.ref?.id ?? current.id,
145
- },
146
- position: entry.position ? cloneValue(entry.position) : current.position,
147
- size: entry.size ? cloneValue(entry.size) : current.size,
148
- ports: {
149
- ...(current.ports || {}),
150
- ...(entry.ports || {}),
151
- },
152
- data: {
153
- ...(current.data || {}),
154
- ...(entry.data || {}),
155
- },
156
- metadata: {
157
- ...(current.metadata || {}),
158
- ...(entry.metadata || {}),
159
- },
160
- };
161
- if (key)
162
- byKey.set(key, merged);
163
- const index = result.findIndex((value) => value.id === current.id);
164
- if (index >= 0)
165
- result[index] = merged;
166
- continue;
167
- }
168
- const cloned = cloneValue(entry);
169
- result.push(cloned);
170
- if (key)
171
- byKey.set(key, cloned);
172
- }
173
- return result;
174
- }
175
- function normalizeEdges(edges, relations) {
176
- const byKey = new Map();
177
- const result = [];
178
- for (const [index, relation] of relations.entries()) {
179
- const source = asString(relation.source) ?? `source-${index}`;
180
- const target = asString(relation.target) ?? `target-${index}`;
181
- const edge = {
182
- id: relation.label || `${source}:${relation.sourcePort ?? "*"}->${target}:${relation.targetPort ?? "*"}`,
183
- source,
184
- sourceRef: source,
185
- sourcePort: relation.sourcePort,
186
- target,
187
- targetRef: target,
188
- targetPort: relation.targetPort,
189
- label: relation.label,
190
- metadata: cloneValue(relation.metadata),
191
- };
192
- result.push(edge);
193
- byKey.set(edge.id, edge);
194
- }
195
- for (const entry of edges || []) {
196
- const key = snapshotEdgeKey(entry);
197
- const current = key ? byKey.get(key) : undefined;
198
- if (current) {
199
- const merged = {
200
- ...current,
201
- ...cloneValue(entry),
202
- id: entry.id || current.id,
203
- source: entry.source || current.source,
204
- sourceRef: entry.sourceRef ?? current.sourceRef ?? entry.source ?? current.source,
205
- target: entry.target || current.target,
206
- targetRef: entry.targetRef ?? current.targetRef ?? entry.target ?? current.target,
207
- // Labels are document-carried display semantics (§4.4.7): a row merged
208
- // from a canvas clone that never carried its own label must not erase
209
- // the relation row's label.
210
- label: entry.label ?? current.label,
211
- metadata: {
212
- ...(current.metadata || {}),
213
- ...(entry.metadata || {}),
214
- },
215
- };
216
- if (key)
217
- byKey.set(key, merged);
218
- const index = result.findIndex((value) => value.id === current.id);
219
- if (index >= 0)
220
- result[index] = merged;
221
- continue;
222
- }
223
- const cloned = cloneValue(entry);
224
- result.push(cloned);
225
- if (key)
226
- byKey.set(key, cloned);
227
- }
228
- return result;
229
- }
230
- function normalizeWorkflowDefinition(definition, overrides = {}) {
231
- return {
232
- name: overrides.name ?? definition.name,
233
- tag: overrides.tag ?? definition.tag,
234
- kind: overrides.kind ?? definition.kind,
235
- category: overrides.category ?? definition.category,
236
- color: overrides.color ?? definition.color,
237
- group: overrides.group ?? definition.group,
238
- height: overrides.height ?? definition.height,
239
- icon: overrides.icon ?? definition.icon,
240
- labels: cloneValue(overrides.labels ?? definition.labels ?? []),
241
- maxChildren: overrides.maxChildren ?? definition.maxChildren,
242
- minWidth: overrides.minWidth ?? definition.minWidth,
243
- width: overrides.width ?? definition.width,
244
- metadata: cloneValue(overrides.metadata ??
245
- ("workflow" in definition ? definition.workflow : definition.metadata)),
246
- inputs: cloneValue(overrides.inputs ?? definition.inputs ?? []),
247
- outputs: cloneValue(overrides.outputs ?? definition.outputs ?? []),
248
- nodes: cloneValue(overrides.nodes ?? definition.nodes ?? []),
249
- relations: cloneValue(overrides.relations ?? definition.relations ?? []),
250
- };
251
- }
252
- function graphWorkflowSnapshotDefinitionOf(model) {
253
- const definition = isWorkflowDefinitionLike(model)
254
- ? model
255
- : (0, reader_js_1.graphWorkflowDefinitionOf)(model);
256
- return normalizeWorkflowDefinition(definition);
257
- }
258
- function graphWorkflowSnapshotOf(model, input) {
259
- const normalizedDefinition = normalizeWorkflowDefinition(graphWorkflowSnapshotDefinitionOf(model), input?.definition);
260
- const inputPorts = (0, reader_js_1.graphLeafPortsOf)(normalizedDefinition.inputs);
261
- const outputPorts = (0, reader_js_1.graphLeafPortsOf)(normalizedDefinition.outputs);
262
- return {
263
- version: exports.GRAPH_WORKFLOW_SNAPSHOT_VERSION,
264
- definition: normalizedDefinition,
265
- state: {
266
- inputs: normalizeValueEntries(input?.inputs, inputPorts),
267
- outputs: normalizeValueEntries(input?.outputs, outputPorts),
268
- nodes: normalizeNodes(input?.nodes, normalizedDefinition.nodes),
269
- edges: normalizeEdges(input?.edges, normalizedDefinition.relations),
270
- ui: cloneValue(input?.ui || {}),
271
- metadata: cloneValue(input?.metadata || {}),
272
- },
273
- };
274
- }
275
- function graphWorkflowSnapshotRestore(snapshot, model) {
276
- if (!("version" in snapshot)) {
277
- return graphWorkflowSnapshotOf(model ??
278
- snapshot.definition ??
279
- {}, snapshot);
280
- }
281
- const fullSnapshot = snapshot;
282
- const definition = model
283
- ? graphWorkflowSnapshotDefinitionOf(model)
284
- : fullSnapshot.definition;
285
- return graphWorkflowSnapshotOf(definition, {
286
- inputs: fullSnapshot.state.inputs,
287
- outputs: fullSnapshot.state.outputs,
288
- nodes: fullSnapshot.state.nodes,
289
- edges: fullSnapshot.state.edges,
290
- ui: fullSnapshot.state.ui,
291
- metadata: fullSnapshot.state.metadata,
292
- });
293
- }
294
- function graphWorkflowSnapshotToJSON(snapshot, space) {
295
- return JSON.stringify(snapshot, undefined, space);
296
- }
297
- function graphWorkflowSnapshotFromJSON(input, model) {
298
- const snapshot = typeof input === "string" ? JSON.parse(input) : input;
299
- return graphWorkflowSnapshotRestore(snapshot, model);
300
- }
301
- function graphWorkflowSnapshotInputValuesOf(snapshot) {
302
- return Object.fromEntries(snapshot.state.inputs.map((entry) => [entry.path, cloneValue(entry.value)]));
303
- }
304
- function graphWorkflowSnapshotOutputValuesOf(snapshot) {
305
- return Object.fromEntries(snapshot.state.outputs.map((entry) => [entry.path, cloneValue(entry.value)]));
306
- }
307
- function dropUnsafeEntries(source) {
308
- const result = {};
309
- for (const [key, value] of Object.entries(source)) {
310
- if (GRAPH_CONSTRUCTOR_DATA_KEYS.includes(key))
311
- continue;
312
- const sanitized = sanitizeToGraphJsonValue(value);
313
- if (sanitized !== undefined)
314
- result[key] = sanitized;
315
- }
316
- return result;
317
- }
318
- /**
319
- * Sanitizes a legacy snapshot into a JSON-safe payload while preserving its
320
- * structural keys (`version`, `definition`, `state`). Constructor-key stripping
321
- * still applies to the payload contents inside, so the canonical→legacy
322
- * round trip stays lossless for persisted data.
323
- */
324
- function sanitizeLegacySnapshotPayload(snapshot) {
325
- return {
326
- version: snapshot.version,
327
- definition: dropUnsafeEntries((snapshot.definition ?? {})),
328
- state: dropUnsafeEntries((snapshot.state ?? {})),
329
- };
330
- }
331
- function sanitizeToGraphJsonValue(value) {
332
- if (value === null)
333
- return null;
334
- const type = typeof value;
335
- if (type === "string" || type === "boolean")
336
- return value;
337
- if (type === "number")
338
- return Number.isFinite(value) ? value : undefined;
339
- if (Array.isArray(value)) {
340
- const items = [];
341
- for (const item of value) {
342
- const sanitized = sanitizeToGraphJsonValue(item);
343
- if (sanitized !== undefined)
344
- items.push(sanitized);
345
- }
346
- return items;
347
- }
348
- if (type === "object") {
349
- return dropUnsafeEntries(value);
350
- }
351
- return undefined;
352
- }
353
- function boundaryAliasesFor(definition) {
354
- const aliases = new Set(GRAPH_LEGACY_BOUNDARY_ALIASES);
355
- if (definition.tag)
356
- aliases.add(definition.tag);
357
- if (definition.name)
358
- aliases.add(definition.name);
359
- return aliases;
360
- }
361
- function legacyEndpoint(refId, port, aliases, boundaryPortIds) {
362
- const resolvedPort = port ?? "";
363
- if (!refId || aliases.has(refId)) {
364
- return { scope: "workflow", port: resolvedPort };
365
- }
366
- // The legacy decorated-root canvas rendered workflow input ports as draggable
367
- // boundary badges (`input-{port}`, port handle `value`). Those bindings stay
368
- // lossless only when the badge id folds back onto the workflow port it was
369
- // drawn for (DECAF-50 §4.11); otherwise a workflow port would collapse into
370
- // one shared boundary endpoint and drop real edges (§4.4.6 canonical form).
371
- if (refId.startsWith("input-")) {
372
- const workflowPortId = boundaryPortIds?.get(refId.slice("input-".length) ?? "");
373
- if (workflowPortId) {
374
- return {
375
- scope: "workflow",
376
- port: workflowPortId,
377
- };
378
- }
379
- }
380
- return { scope: "node", nodeId: refId, port: resolvedPort };
381
- }
382
- /**
383
- * Maps workflow input-property names to their legacy boundary-badge ids
384
- * (`input-{property}`), so badges drawn on the canvas resolve back to the
385
- * workflow port they represent (§4.11).
386
- */
387
- function boundaryPortIdsFor(snapshot) {
388
- const map = new Map();
389
- for (const port of snapshot.definition.inputs) {
390
- map.set(`input-${port.property}`, port.property);
391
- }
392
- return map;
393
- }
394
- /**
395
- * Resolves the decorated definition's own edge labels by canonical endpoint
396
- * pair, so converted legacy edges that never carried a label on the edge row
397
- * (canvas-drawn clones merged over the relation rows) still restore the
398
- * document-carried {@link GraphEdgeInstance.label} (§4.4.7) instead of losing
399
- * the display affordance on save/reload.
400
- */
401
- function legacyRelationLabelByEndpoint(snapshot, aliases, boundaryPortIds) {
402
- const map = new Map();
403
- for (const relation of snapshot.definition.relations) {
404
- const label = typeof relation.label === "string" ? relation.label : undefined;
405
- if (!label)
406
- continue;
407
- const sourceRef = typeof relation.source === "string" ? relation.source : undefined;
408
- const targetRef = typeof relation.target === "string" ? relation.target : undefined;
409
- map.set(edgePairKeyOf({
410
- source: legacyEndpoint(sourceRef, relation.sourcePort, aliases, boundaryPortIds),
411
- target: legacyEndpoint(targetRef, relation.targetPort, aliases, boundaryPortIds),
412
- }), label);
413
- }
414
- return map;
415
- }
416
- function endpointToLegacyRef(endpoint) {
417
- if (endpoint.scope === "workflow") {
418
- return { refId: "$workflow", port: endpoint.port };
419
- }
420
- return { refId: endpoint.nodeId, port: endpoint.port };
421
- }
422
- function portInstanceFromDefinition(port, value) {
423
- const instance = {
424
- id: port.property,
425
- label: port.label,
426
- };
427
- instance.schema = (0, GraphValueSchemaDerivation_js_1.graphValueSchemaFromValidation)(port.validation, port.type, port.model);
428
- if (port.required)
429
- instance.required = true;
430
- if (value !== undefined)
431
- instance.defaultValue = value;
432
- const metadata = sanitizeToGraphJsonValue(port.graph ?? {});
433
- if (metadata && Object.keys(metadata).length)
434
- instance.metadata = metadata;
435
- return instance;
436
- }
437
- function inputBindingsFromPorts(ports) {
438
- if (!ports)
439
- return undefined;
440
- const bindings = {};
441
- for (const [property, port] of Object.entries(ports)) {
442
- if (port?.mode === "port") {
443
- bindings[property] = { mode: "edge" };
444
- }
445
- else if ("value" in (port ?? {})) {
446
- const value = sanitizeToGraphJsonValue(port.value);
447
- bindings[property] = { mode: "literal", value: value ?? null };
448
- }
449
- }
450
- return Object.keys(bindings).length ? bindings : undefined;
451
- }
452
- function nodeInstanceFromLegacy(node) {
453
- const instance = {
454
- id: node.id,
455
- kind: node.kind ?? node.ref?.kind ?? node.id,
456
- parameters: dropUnsafeEntries(node.data ?? {}),
457
- };
458
- if (node.label)
459
- instance.label = node.label;
460
- const bindings = inputBindingsFromPorts(node.ports);
461
- if (bindings)
462
- instance.inputBindings = bindings;
463
- const metadata = sanitizeToGraphJsonValue(node.metadata ?? {});
464
- if (metadata && Object.keys(metadata).length)
465
- instance.metadata = metadata;
466
- if (node.position || node.size || node.expanded !== undefined) {
467
- const ui = {
468
- position: node.position ? { x: node.position.x, y: node.position.y } : { x: 0, y: 0 },
469
- };
470
- if (node.size)
471
- ui.size = { width: node.size.width, height: node.size.height };
472
- if (node.expanded !== undefined)
473
- ui.expanded = node.expanded;
474
- instance.ui = ui;
475
- }
476
- return instance;
477
- }
478
- function edgeInstanceFromLegacy(edge, aliases, boundaryPortIds, relationLabelByPair) {
479
- const source = legacyEndpoint(edge.sourceRef ?? edge.source, edge.sourcePort, aliases, boundaryPortIds);
480
- const target = legacyEndpoint(edge.targetRef ?? edge.target, edge.targetPort, aliases, boundaryPortIds);
481
- const instance = {
482
- id: edge.id,
483
- type: "data",
484
- source,
485
- target,
486
- };
487
- const label = edge.label ?? relationLabelByPair?.get(edgePairKeyOf({ source, target }));
488
- if (label)
489
- instance.label = label;
490
- const metadata = sanitizeToGraphJsonValue(edge.metadata ?? {});
491
- if (metadata && Object.keys(metadata).length)
492
- instance.metadata = metadata;
493
- return instance;
494
- }
495
- /** Endpoint-pair key for edge identity (canonical `GraphEndpoint` shape). */
496
- function edgePairKeyOf(edge) {
497
- const keyOf = (endpoint) => endpoint.scope === "node"
498
- ? `node:${endpoint.nodeId}:${endpoint.port}`
499
- : `workflow:${endpoint.port}`;
500
- return `${keyOf(edge.source)}->${keyOf(edge.target)}`;
501
- }
502
- /**
503
- * Maps a legacy (pre-P7) canvas snapshot to the canonical
504
- * {@link GraphWorkflowDocument} (DECAF-50 §4.4.6): legacy `node.data` becomes
505
- * instance `parameters`, legacy `node.metadata` becomes instance `metadata`,
506
- * workflow boundary badges (`input-{port}`) fold back onto their workflow
507
- * ports, and edge labels missing from cloned edge rows are restored from the
508
- * decorated definition's relation labels (§4.4.7).
509
- */
510
- function graphWorkflowDocumentFromLegacySnapshot(snapshot) {
511
- const aliases = boundaryAliasesFor(snapshot.definition);
512
- const boundaryPortIds = boundaryPortIdsFor(snapshot);
513
- const relationLabelByPair = legacyRelationLabelByEndpoint(snapshot, aliases, boundaryPortIds);
514
- const inputs = Object.fromEntries(snapshot.state.inputs.map((entry) => [entry.path, sanitizeToGraphJsonValue(entry.value)]));
515
- const outputs = Object.fromEntries(snapshot.state.outputs.map((entry) => [entry.path, sanitizeToGraphJsonValue(entry.value)]));
516
- const document = {
517
- id: snapshot.definition.tag || snapshot.definition.name,
518
- name: snapshot.definition.name,
519
- inputs: snapshot.definition.inputs.map((port) => portInstanceFromDefinition(port, inputs[port.property])),
520
- outputs: snapshot.definition.outputs.map((port) => portInstanceFromDefinition(port, outputs[port.property])),
521
- nodes: snapshot.state.nodes.map(nodeInstanceFromLegacy),
522
- edges: snapshot.state.edges.map((edge) => edgeInstanceFromLegacy(edge, aliases, boundaryPortIds, relationLabelByPair)),
523
- };
524
- if (snapshot.definition.metadata) {
525
- const metadata = sanitizeToGraphJsonValue(snapshot.definition.metadata);
526
- if (metadata && Object.keys(metadata).length)
527
- document.metadata = metadata;
528
- }
529
- const ui = {};
530
- const viewport = snapshot.state.ui?.["diagramMetadata"];
531
- const parsedViewport = viewport?.["viewport"];
532
- if (parsedViewport && typeof parsedViewport === "object") {
533
- const v = parsedViewport;
534
- const x = typeof v["x"] === "number" ? v["x"] : Number(v["x"]) || 0;
535
- const y = typeof v["y"] === "number" ? v["y"] : Number(v["y"]) || 0;
536
- const zoom = typeof v["scale"] === "number" ? v["scale"] : Number(v["scale"]) || 1;
537
- ui.viewport = { x, y, zoom };
538
- }
539
- if (ui.viewport)
540
- document.ui = ui;
541
- return document;
542
- }
543
- /**
544
- * Converts a legacy persisted snapshot into the canonical wrapper. The canonical
545
- * `document` carries executable semantics; `editor.legacy` keeps the sanitized
546
- * (constructor-free) legacy payload so a canonical→legacy round trip is lossless
547
- * for persisted data.
548
- */
549
- function graphWorkflowSnapshotFromLegacy(snapshot) {
550
- const document = graphWorkflowDocumentFromLegacySnapshot(snapshot);
551
- const editor = {};
552
- const sanitizedLegacy = sanitizeLegacySnapshotPayload(snapshot);
553
- if (sanitizedLegacy && (0, GraphJsonValue_js_1.isGraphJsonSafeValue)(sanitizedLegacy))
554
- editor.legacy = sanitizedLegacy;
555
- const ui = snapshot.state.ui;
556
- if (ui) {
557
- const duplicateCounts = ui["duplicateCounts"];
558
- if (duplicateCounts && typeof duplicateCounts === "object") {
559
- editor.duplicateCounts = duplicateCounts;
560
- }
561
- const diagramMetadata = ui["diagramMetadata"];
562
- if (diagramMetadata && typeof diagramMetadata === "object") {
563
- editor.diagramMetadata = sanitizeToGraphJsonValue(diagramMetadata);
564
- }
565
- const nodeConfigs = ui["nodeConfigs"];
566
- if (nodeConfigs && typeof nodeConfigs === "object") {
567
- editor.nodeConfigs = sanitizeToGraphJsonValue(nodeConfigs);
568
- }
569
- }
570
- editor.nodePorts = {};
571
- for (const node of snapshot.state.nodes) {
572
- if (node.ports) {
573
- editor.nodePorts[node.id] = sanitizeToGraphJsonValue(node.ports);
574
- }
575
- }
576
- if (!Object.keys(editor.nodePorts).length)
577
- delete editor.nodePorts;
578
- const definitionDisplay = dropUnsafeEntries(snapshot.definition);
579
- delete definitionDisplay["inputs"];
580
- delete definitionDisplay["outputs"];
581
- delete definitionDisplay["nodes"];
582
- delete definitionDisplay["relations"];
583
- editor.definitionDisplay = definitionDisplay;
584
- const metadata = sanitizeToGraphJsonValue(snapshot.state.metadata ?? {});
585
- return { document, editor, metadata: Object.keys(metadata).length ? metadata : undefined };
586
- }
587
- /**
588
- * Reconstructs a legacy snapshot from a canonical wrapper. Uses the
589
- * `editor.legacy` payload when present for exact round trips; otherwise it
590
- * rebuilds a best-effort legacy snapshot from the document + editor state
591
- * (constructors are never restored).
592
- */
593
- function graphWorkflowSnapshotToLegacy(snapshot) {
594
- if (snapshot.editor?.legacy && (0, GraphJsonValue_js_1.isGraphJsonSafeValue)(snapshot.editor.legacy)) {
595
- return cloneValue(snapshot.editor.legacy);
596
- }
597
- const { document, editor } = snapshot;
598
- const aliases = new Set(GRAPH_LEGACY_BOUNDARY_ALIASES);
599
- if (document.id)
600
- aliases.add(document.id);
601
- if (document.name)
602
- aliases.add(document.name);
603
- const display = (editor?.definitionDisplay ?? {});
604
- const definition = {
605
- ...cloneValue(display),
606
- name: document.name,
607
- tag: document.id || display["tag"] || document.name,
608
- inputs: document.inputs.map((port) => portToLegacyDefinition(port)),
609
- outputs: document.outputs.map((port) => portToLegacyDefinition(port)),
610
- nodes: document.nodes.map((node) => ({ id: node.id, kind: node.kind })),
611
- relations: document.edges.map((edge) => ({
612
- id: edge.id,
613
- source: endpointToLegacyRef(edge.source).refId,
614
- sourcePort: edge.source.port,
615
- target: endpointToLegacyRef(edge.target).refId,
616
- targetPort: edge.target.port,
617
- label: edge.label,
618
- })),
619
- };
620
- const state = {
621
- inputs: document.inputs.map((port) => ({
622
- path: port.id,
623
- value: cloneValue(port.defaultValue),
624
- label: port.label,
625
- required: port.required,
626
- })),
627
- outputs: document.outputs.map((port) => ({
628
- path: port.id,
629
- value: cloneValue(port.defaultValue),
630
- label: port.label,
631
- required: port.required,
632
- })),
633
- nodes: document.nodes.map((node) => ({
634
- id: node.id,
635
- ref: { id: node.id, kind: node.kind },
636
- label: node.label,
637
- kind: node.kind,
638
- position: node.ui?.position ? { x: node.ui.position.x, y: node.ui.position.y } : undefined,
639
- size: node.ui?.size ? { width: node.ui.size.width, height: node.ui.size.height } : undefined,
640
- expanded: node.ui?.expanded,
641
- ports: editor?.nodePorts?.[node.id] ?? undefined,
642
- data: cloneValue(node.parameters ?? {}),
643
- metadata: cloneValue(node.metadata ?? {}),
644
- })),
645
- edges: document.edges.map((edge) => {
646
- const source = endpointToLegacyRef(edge.source);
647
- const target = endpointToLegacyRef(edge.target);
648
- const isBoundary = source.refId === "$workflow" || target.refId === "$workflow";
649
- const isConnection = edge.type === "connection";
650
- return {
651
- id: edge.id,
652
- source: source.refId,
653
- sourceRef: source.refId,
654
- sourcePort: source.port,
655
- target: target.refId,
656
- targetRef: target.refId,
657
- targetPort: target.port,
658
- label: edge.label,
659
- type: isConnection ? "connection" : isBoundary ? "output" : "data",
660
- metadata: cloneValue(edge.metadata ?? {}),
661
- };
662
- }),
663
- ui: cloneValue({
664
- ...(editor?.duplicateCounts ? { duplicateCounts: editor.duplicateCounts } : {}),
665
- ...(editor?.diagramMetadata ? { diagramMetadata: editor.diagramMetadata } : {}),
666
- ...(editor?.nodeConfigs ? { nodeConfigs: editor.nodeConfigs } : {}),
667
- }),
668
- metadata: cloneValue(snapshot.metadata ?? {}),
669
- };
670
- return {
671
- version: exports.GRAPH_WORKFLOW_SNAPSHOT_VERSION,
672
- definition,
673
- state,
674
- };
675
- }
676
- function portToLegacyDefinition(port) {
677
- return {
678
- property: port.id,
679
- label: port.label,
680
- required: port.required,
681
- metadata: cloneValue(port.metadata ?? {}),
682
- };
683
- }
684
- /** Normalizes any accepted snapshot/document form to a canonical wrapper. */
685
- function graphWorkflowSnapshotLikeToCanonical(value) {
686
- if ("document" in value) {
687
- return value;
688
- }
689
- if ("state" in value || "definition" in value) {
690
- return graphWorkflowSnapshotFromLegacy(value);
691
- }
692
- return { document: value };
693
- }
694
3
  //# sourceMappingURL=snapshot.js.map
695
4
  //# sourceMappingURL=snapshot.cjs.map