agentflow-core 0.3.3 → 0.4.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.
@@ -0,0 +1,56 @@
1
+ // src/loader.ts
2
+ function toNodesMap(raw) {
3
+ if (raw instanceof Map) return raw;
4
+ if (Array.isArray(raw)) {
5
+ return new Map(raw);
6
+ }
7
+ if (raw !== null && typeof raw === "object") {
8
+ return new Map(Object.entries(raw));
9
+ }
10
+ return /* @__PURE__ */ new Map();
11
+ }
12
+ function loadGraph(input) {
13
+ const raw = typeof input === "string" ? JSON.parse(input) : input;
14
+ const nodes = toNodesMap(raw.nodes);
15
+ return {
16
+ id: raw.id ?? "",
17
+ rootNodeId: raw.rootNodeId ?? raw.rootId ?? "",
18
+ nodes,
19
+ edges: raw.edges ?? [],
20
+ startTime: raw.startTime ?? 0,
21
+ endTime: raw.endTime ?? null,
22
+ status: raw.status ?? "completed",
23
+ trigger: raw.trigger ?? "unknown",
24
+ agentId: raw.agentId ?? "unknown",
25
+ events: raw.events ?? [],
26
+ traceId: raw.traceId,
27
+ spanId: raw.spanId,
28
+ parentSpanId: raw.parentSpanId
29
+ };
30
+ }
31
+ function graphToJson(graph) {
32
+ const nodesObj = {};
33
+ for (const [id, node] of graph.nodes) {
34
+ nodesObj[id] = node;
35
+ }
36
+ return {
37
+ id: graph.id,
38
+ rootNodeId: graph.rootNodeId,
39
+ nodes: nodesObj,
40
+ edges: graph.edges,
41
+ startTime: graph.startTime,
42
+ endTime: graph.endTime,
43
+ status: graph.status,
44
+ trigger: graph.trigger,
45
+ agentId: graph.agentId,
46
+ events: graph.events,
47
+ traceId: graph.traceId,
48
+ spanId: graph.spanId,
49
+ parentSpanId: graph.parentSpanId
50
+ };
51
+ }
52
+
53
+ export {
54
+ loadGraph,
55
+ graphToJson
56
+ };