@botbotgo/agent-harness 0.0.246 → 0.0.248
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.
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const PRODUCT_VIEW_KINDS = new Set(["agent", "llm", "tool", "skill"]);
|
|
2
|
+
const STRUCTURAL_EDGE_KINDS = new Set(["sequence", "contains"]);
|
|
2
3
|
function sanitizeMermaidId(value) {
|
|
3
4
|
return value.replace(/[^A-Za-z0-9_]/g, "_");
|
|
4
5
|
}
|
|
@@ -31,6 +32,68 @@ function renderEdge(edge, fromId, toId) {
|
|
|
31
32
|
? ` ${fromId} ${connector}|"${escapeMermaidLabel(label)}"| ${toId}`
|
|
32
33
|
: ` ${fromId} ${connector} ${toId}`;
|
|
33
34
|
}
|
|
35
|
+
function edgeKey(edge) {
|
|
36
|
+
return `${edge.from}::${edge.to}::${edge.kind}::${edge.label ?? ""}::${edge.condition ?? ""}`;
|
|
37
|
+
}
|
|
38
|
+
function collapseEdgePath(source, target, path) {
|
|
39
|
+
const representative = [...path].reverse().find((edge) => !STRUCTURAL_EDGE_KINDS.has(edge.kind) || edge.label || edge.condition);
|
|
40
|
+
const sourceEventIds = [...new Set(path.flatMap((edge) => edge.sourceEventIds))];
|
|
41
|
+
return {
|
|
42
|
+
id: `collapsed:${source}:${target}:${sourceEventIds.join(",")}`,
|
|
43
|
+
from: source,
|
|
44
|
+
to: target,
|
|
45
|
+
kind: representative?.kind ?? "sequence",
|
|
46
|
+
label: representative?.label,
|
|
47
|
+
condition: representative?.condition,
|
|
48
|
+
sourceEventIds,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function collectVisibleEdges(graph, visibleNodes, includedEdgeKinds) {
|
|
52
|
+
const visibleNodeIds = new Set(visibleNodes.map((node) => node.id));
|
|
53
|
+
const candidateEdges = graph.edges.filter((edge) => includedEdgeKinds ? includedEdgeKinds.has(edge.kind) : true);
|
|
54
|
+
const outgoingByNodeId = new Map();
|
|
55
|
+
for (const edge of candidateEdges) {
|
|
56
|
+
const outgoing = outgoingByNodeId.get(edge.from);
|
|
57
|
+
if (outgoing) {
|
|
58
|
+
outgoing.push(edge);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
outgoingByNodeId.set(edge.from, [edge]);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const visibleEdges = candidateEdges.filter((edge) => visibleNodeIds.has(edge.from) && visibleNodeIds.has(edge.to));
|
|
65
|
+
const seenEdgeKeys = new Set(visibleEdges.map((edge) => edgeKey(edge)));
|
|
66
|
+
for (const node of visibleNodes) {
|
|
67
|
+
const queue = (outgoingByNodeId.get(node.id) ?? [])
|
|
68
|
+
.filter((edge) => !visibleNodeIds.has(edge.to))
|
|
69
|
+
.map((edge) => ({ nodeId: edge.to, path: [edge] }));
|
|
70
|
+
const visitedHiddenNodes = new Set();
|
|
71
|
+
while (queue.length > 0) {
|
|
72
|
+
const current = queue.shift();
|
|
73
|
+
if (visitedHiddenNodes.has(current.nodeId)) {
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
visitedHiddenNodes.add(current.nodeId);
|
|
77
|
+
for (const edge of outgoingByNodeId.get(current.nodeId) ?? []) {
|
|
78
|
+
const nextPath = [...current.path, edge];
|
|
79
|
+
if (visibleNodeIds.has(edge.to)) {
|
|
80
|
+
if (edge.to === node.id) {
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
const collapsed = collapseEdgePath(node.id, edge.to, nextPath);
|
|
84
|
+
const key = edgeKey(collapsed);
|
|
85
|
+
if (!seenEdgeKeys.has(key)) {
|
|
86
|
+
seenEdgeKeys.add(key);
|
|
87
|
+
visibleEdges.push(collapsed);
|
|
88
|
+
}
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
queue.push({ nodeId: edge.to, path: nextPath });
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return visibleEdges;
|
|
96
|
+
}
|
|
34
97
|
export function exportFlowGraphToMermaid(graph, options = {}) {
|
|
35
98
|
const direction = options.direction ?? "TD";
|
|
36
99
|
const view = options.view ?? "product";
|
|
@@ -49,12 +112,7 @@ export function exportFlowGraphToMermaid(graph, options = {}) {
|
|
|
49
112
|
return includedKinds ? includedKinds.has(node.kind) : true;
|
|
50
113
|
});
|
|
51
114
|
const nodeIdSet = new Set(nodes.map((node) => node.id));
|
|
52
|
-
const edges = graph
|
|
53
|
-
if (!nodeIdSet.has(edge.from) || !nodeIdSet.has(edge.to)) {
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
return includedEdgeKinds ? includedEdgeKinds.has(edge.kind) : true;
|
|
57
|
-
});
|
|
115
|
+
const edges = collectVisibleEdges(graph, nodes, includedEdgeKinds);
|
|
58
116
|
const lines = [`flowchart ${direction}`];
|
|
59
117
|
const mermaidIdByNodeId = new Map();
|
|
60
118
|
for (const node of nodes) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const AGENT_HARNESS_VERSION = "0.0.
|
|
1
|
+
export declare const AGENT_HARNESS_VERSION = "0.0.247";
|
package/dist/package-version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const AGENT_HARNESS_VERSION = "0.0.
|
|
1
|
+
export const AGENT_HARNESS_VERSION = "0.0.247";
|