@andespindola/brainlink 0.1.0-beta.155 → 0.1.0-beta.156
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,5 +1,5 @@
|
|
|
1
1
|
export const createClientJs = () => `const canvas = document.getElementById('graph')
|
|
2
|
-
|
|
2
|
+
let ctx2dFallback = null
|
|
3
3
|
const byId = (id) => document.getElementById(id)
|
|
4
4
|
const elements = {
|
|
5
5
|
search: byId('search'),
|
|
@@ -476,7 +476,11 @@ const setFocusedNodeIds = (ids) => {
|
|
|
476
476
|
}
|
|
477
477
|
|
|
478
478
|
const drawFallback = () => {
|
|
479
|
-
if (state.rendererMode !== 'fallback'
|
|
479
|
+
if (state.rendererMode !== 'fallback') {
|
|
480
|
+
return
|
|
481
|
+
}
|
|
482
|
+
ctx2dFallback = ctx2dFallback ?? canvas.getContext('2d')
|
|
483
|
+
if (!ctx2dFallback) {
|
|
480
484
|
return
|
|
481
485
|
}
|
|
482
486
|
const width = state.viewport.width
|
|
@@ -1,19 +1,33 @@
|
|
|
1
1
|
import { getGraphLayout } from './get-graph-layout.js';
|
|
2
2
|
export const getGraphContexts = async (vaultPath, agentId) => {
|
|
3
3
|
const { layout } = await getGraphLayout(vaultPath, { agentId });
|
|
4
|
-
const nodeIdsByContext =
|
|
4
|
+
const nodeIdsByContext = new Map();
|
|
5
|
+
const contextByNodeId = new Map();
|
|
6
|
+
layout.nodes.forEach((node) => {
|
|
5
7
|
const title = node.segment || node.group || 'root';
|
|
6
|
-
const nodeIds =
|
|
8
|
+
const nodeIds = nodeIdsByContext.get(title) ?? new Set();
|
|
7
9
|
nodeIds.add(node.id);
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
10
|
+
nodeIdsByContext.set(title, nodeIds);
|
|
11
|
+
contextByNodeId.set(node.id, title);
|
|
12
|
+
});
|
|
13
|
+
const edgeCountByContext = new Map();
|
|
14
|
+
layout.edges.forEach((edge) => {
|
|
15
|
+
if (!edge.target) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const sourceContext = contextByNodeId.get(edge.source);
|
|
19
|
+
const targetContext = contextByNodeId.get(edge.target);
|
|
20
|
+
if (!sourceContext || sourceContext !== targetContext) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
edgeCountByContext.set(sourceContext, (edgeCountByContext.get(sourceContext) ?? 0) + 1);
|
|
24
|
+
});
|
|
11
25
|
return Array.from(nodeIdsByContext.entries())
|
|
12
26
|
.map(([title, nodeIds]) => ({
|
|
13
27
|
id: title,
|
|
14
28
|
title,
|
|
15
29
|
nodeCount: nodeIds.size,
|
|
16
|
-
edgeCount:
|
|
30
|
+
edgeCount: edgeCountByContext.get(title) ?? 0
|
|
17
31
|
}))
|
|
18
32
|
.sort((left, right) => right.nodeCount - left.nodeCount || left.title.localeCompare(right.title));
|
|
19
33
|
};
|
package/package.json
CHANGED