@openweave/weave-graph 0.2.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.
- package/LICENSE +21 -0
- package/README.md +290 -0
- package/dist/compression.d.ts +94 -0
- package/dist/compression.d.ts.map +1 -0
- package/dist/compression.js +210 -0
- package/dist/compression.js.map +1 -0
- package/dist/edge.d.ts +43 -0
- package/dist/edge.d.ts.map +1 -0
- package/dist/edge.js +79 -0
- package/dist/edge.js.map +1 -0
- package/dist/index.d.ts +159 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +339 -0
- package/dist/index.js.map +1 -0
- package/dist/node.d.ts +43 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +79 -0
- package/dist/node.js.map +1 -0
- package/dist/persistence.d.ts +58 -0
- package/dist/persistence.d.ts.map +1 -0
- package/dist/persistence.js +188 -0
- package/dist/persistence.js.map +1 -0
- package/dist/types.d.ts +74 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +27 -0
- package/dist/types.js.map +1 -0
- package/package.json +42 -0
package/dist/edge.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { EdgeType } from "./types";
|
|
2
|
+
import { randomUUID } from "crypto";
|
|
3
|
+
/**
|
|
4
|
+
* EdgeBuilder utility for creating and managing graph edges
|
|
5
|
+
*/
|
|
6
|
+
export class EdgeBuilder {
|
|
7
|
+
/**
|
|
8
|
+
* Create a new edge between two nodes
|
|
9
|
+
*/
|
|
10
|
+
static create(sourceId, targetId, type, weight, metadata) {
|
|
11
|
+
return {
|
|
12
|
+
id: randomUUID(),
|
|
13
|
+
sourceId,
|
|
14
|
+
targetId,
|
|
15
|
+
type,
|
|
16
|
+
weight: weight ?? 1.0,
|
|
17
|
+
metadata: metadata ?? {},
|
|
18
|
+
createdAt: new Date(),
|
|
19
|
+
updatedAt: new Date(),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Create a RELATES edge
|
|
24
|
+
*/
|
|
25
|
+
static relates(sourceId, targetId, weight) {
|
|
26
|
+
return this.create(sourceId, targetId, EdgeType.RELATES, weight);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Create a CAUSES edge
|
|
30
|
+
*/
|
|
31
|
+
static causes(sourceId, targetId, weight) {
|
|
32
|
+
return this.create(sourceId, targetId, EdgeType.CAUSES, weight);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Create a CORRECTS edge (links CORRECTION to ERROR)
|
|
36
|
+
*/
|
|
37
|
+
static corrects(correctionId, errorId, weight) {
|
|
38
|
+
return this.create(correctionId, errorId, EdgeType.CORRECTS, weight);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Create an IMPLEMENTS edge (code → decision)
|
|
42
|
+
*/
|
|
43
|
+
static implements(codeEntityId, decisionId, weight) {
|
|
44
|
+
return this.create(codeEntityId, decisionId, EdgeType.IMPLEMENTS, weight);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Create a DEPENDS_ON edge
|
|
48
|
+
*/
|
|
49
|
+
static dependsOn(sourceId, targetId, weight) {
|
|
50
|
+
return this.create(sourceId, targetId, EdgeType.DEPENDS_ON, weight);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Create a BLOCKS edge
|
|
54
|
+
*/
|
|
55
|
+
static blocks(blockerId, blockedId, weight) {
|
|
56
|
+
return this.create(blockerId, blockedId, EdgeType.BLOCKS, weight);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Clone an edge with updated values
|
|
60
|
+
*/
|
|
61
|
+
static clone(edge, updates) {
|
|
62
|
+
return {
|
|
63
|
+
...edge,
|
|
64
|
+
updatedAt: new Date(),
|
|
65
|
+
...updates,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Increase the weight (confidence) of an edge
|
|
70
|
+
*/
|
|
71
|
+
static reinforceWeight(edge, factor = 1.1) {
|
|
72
|
+
return {
|
|
73
|
+
...edge,
|
|
74
|
+
weight: (edge.weight ?? 1.0) * factor,
|
|
75
|
+
updatedAt: new Date(),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=edge.js.map
|
package/dist/edge.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"edge.js","sourceRoot":"","sources":["../src/edge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,QAAQ,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEpC;;GAEG;AACH,MAAM,OAAO,WAAW;IACtB;;OAEG;IACH,MAAM,CAAC,MAAM,CACX,QAAgB,EAChB,QAAgB,EAChB,IAAc,EACd,MAAe,EACf,QAAkC;QAElC,OAAO;YACL,EAAE,EAAE,UAAU,EAAE;YAChB,QAAQ;YACR,QAAQ;YACR,IAAI;YACJ,MAAM,EAAE,MAAM,IAAI,GAAG;YACrB,QAAQ,EAAE,QAAQ,IAAI,EAAE;YACxB,SAAS,EAAE,IAAI,IAAI,EAAE;YACrB,SAAS,EAAE,IAAI,IAAI,EAAE;SACtB,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,OAAO,CACZ,QAAgB,EAChB,QAAgB,EAChB,MAAe;QAEf,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IACnE,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,MAAM,CACX,QAAgB,EAChB,QAAgB,EAChB,MAAe;QAEf,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClE,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,QAAQ,CACb,YAAoB,EACpB,OAAe,EACf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
4
|
+
* Main interface for managing the WeaveGraph
|
|
5
|
+
* Handles node/edge operations, queries, and persistence metadata
|
|
6
|
+
*/
|
|
7
|
+
export declare class ContextGraphManager {
|
|
8
|
+
private nodes;
|
|
9
|
+
private edges;
|
|
10
|
+
private edgesBySource;
|
|
11
|
+
private edgesByTarget;
|
|
12
|
+
private nodesByLabel;
|
|
13
|
+
private chatId;
|
|
14
|
+
private compressionThreshold;
|
|
15
|
+
private version;
|
|
16
|
+
private createdAt;
|
|
17
|
+
private updatedAt;
|
|
18
|
+
constructor(chatId: string, compressionThreshold?: number);
|
|
19
|
+
/**
|
|
20
|
+
* Add a node to the graph
|
|
21
|
+
*/
|
|
22
|
+
addNode(node: Node): Node;
|
|
23
|
+
/**
|
|
24
|
+
* Get a node by ID
|
|
25
|
+
*/
|
|
26
|
+
getNode(nodeId: string): Node | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Update an existing node
|
|
29
|
+
*/
|
|
30
|
+
updateNode(nodeId: string, updates: Partial<Node>): Node | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Delete a node (and all related edges)
|
|
33
|
+
*/
|
|
34
|
+
deleteNode(nodeId: string): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Add an edge to the graph
|
|
37
|
+
*/
|
|
38
|
+
addEdge(edge: Edge): Edge;
|
|
39
|
+
/**
|
|
40
|
+
* Get an edge by ID
|
|
41
|
+
*/
|
|
42
|
+
getEdge(edgeId: string): Edge | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Update an existing edge
|
|
45
|
+
*/
|
|
46
|
+
updateEdge(edgeId: string, updates: Partial<Edge>): Edge | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Delete an edge
|
|
49
|
+
*/
|
|
50
|
+
deleteEdge(edgeId: string): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Get all edges from a source node
|
|
53
|
+
*/
|
|
54
|
+
getEdgesFromNode(nodeId: string): Edge[];
|
|
55
|
+
/**
|
|
56
|
+
* Get all edges to a target node
|
|
57
|
+
*/
|
|
58
|
+
getEdgesToNode(nodeId: string): Edge[];
|
|
59
|
+
/**
|
|
60
|
+
* Query nodes by label (keyword search)
|
|
61
|
+
* Returns nodes where the label contains the query string
|
|
62
|
+
*/
|
|
63
|
+
queryNodesByLabel(query: string): Node[];
|
|
64
|
+
/**
|
|
65
|
+
* Query nodes by type
|
|
66
|
+
*/
|
|
67
|
+
queryNodesByType(type: NodeType): Node[];
|
|
68
|
+
/**
|
|
69
|
+
* Query edges by type
|
|
70
|
+
*/
|
|
71
|
+
queryEdgesByType(type: EdgeType): Edge[];
|
|
72
|
+
/**
|
|
73
|
+
* Get graph statistics
|
|
74
|
+
*/
|
|
75
|
+
getStats(): {
|
|
76
|
+
totalNodes: number;
|
|
77
|
+
totalEdges: number;
|
|
78
|
+
nodesByType: {
|
|
79
|
+
[k: string]: number;
|
|
80
|
+
};
|
|
81
|
+
edgesByType: {
|
|
82
|
+
[k: string]: number;
|
|
83
|
+
};
|
|
84
|
+
chatId: string;
|
|
85
|
+
createdAt: Date;
|
|
86
|
+
updatedAt: Date;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Snapshot the graph for serialization
|
|
90
|
+
*/
|
|
91
|
+
snapshot(): GraphSnapshot;
|
|
92
|
+
/**
|
|
93
|
+
* Restore graph from snapshot
|
|
94
|
+
*/
|
|
95
|
+
static fromSnapshot(snapshot: GraphSnapshot): ContextGraphManager;
|
|
96
|
+
/**
|
|
97
|
+
* Get the current window size percentage
|
|
98
|
+
* Calculates actual context window usage based on node and edge sizes
|
|
99
|
+
*/
|
|
100
|
+
getContextWindowUsage(): number;
|
|
101
|
+
/**
|
|
102
|
+
* Get estimated context size in bytes
|
|
103
|
+
*/
|
|
104
|
+
getContextSize(): number;
|
|
105
|
+
/**
|
|
106
|
+
* Check if compression threshold has been reached
|
|
107
|
+
*/
|
|
108
|
+
shouldCompress(): boolean;
|
|
109
|
+
/**
|
|
110
|
+
* Compress the graph by archiving low-frequency nodes
|
|
111
|
+
* Returns compression statistics
|
|
112
|
+
*/
|
|
113
|
+
compress(targetReductionPercentage?: number): {
|
|
114
|
+
archivedNodeCount: number;
|
|
115
|
+
archiveStats: {
|
|
116
|
+
archivedNodeCount: number;
|
|
117
|
+
archivedEdgeCount: number;
|
|
118
|
+
};
|
|
119
|
+
newContextSize: number;
|
|
120
|
+
contextUsagePercentage: number;
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* Suppress an error node and create a correction
|
|
124
|
+
*/
|
|
125
|
+
suppressError(errorNodeId: string, correctionLabel: string, correctionDescription?: string): {
|
|
126
|
+
correctionNode: Node;
|
|
127
|
+
correctionEdge: Edge;
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* Get all error nodes that have been corrected
|
|
131
|
+
*/
|
|
132
|
+
getCorrectedErrors(): Map<string, {
|
|
133
|
+
error: Node;
|
|
134
|
+
corrections: Node[];
|
|
135
|
+
}>;
|
|
136
|
+
/**
|
|
137
|
+
* Get all error nodes that haven't been corrected yet
|
|
138
|
+
*/
|
|
139
|
+
getUncorrectedErrors(): Node[];
|
|
140
|
+
/**
|
|
141
|
+
* Get all nodes
|
|
142
|
+
*/
|
|
143
|
+
getAllNodes(): Node[];
|
|
144
|
+
/**
|
|
145
|
+
* Get all edges
|
|
146
|
+
*/
|
|
147
|
+
getAllEdges(): Edge[];
|
|
148
|
+
/**
|
|
149
|
+
* Clear the entire graph
|
|
150
|
+
*/
|
|
151
|
+
clear(): void;
|
|
152
|
+
}
|
|
153
|
+
export type { Node, Edge, NodeType, EdgeType, GraphSnapshot, QueryResult } from "./types";
|
|
154
|
+
export { PersistenceManager } from "./persistence";
|
|
155
|
+
export { NodeBuilder } from "./node";
|
|
156
|
+
export { EdgeBuilder } from "./edge";
|
|
157
|
+
export { CompressionManager, ErrorSuppression } from "./compression";
|
|
158
|
+
export type { CompressionStats } from "./compression";
|
|
159
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,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E,MAAM,QAAQ,CAAC;AACrC,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACrE,YAAY,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
import { NodeType } from "./types";
|
|
2
|
+
import { NodeBuilder } from "./node";
|
|
3
|
+
import { EdgeBuilder } from "./edge";
|
|
4
|
+
import { CompressionManager, ErrorSuppression } from "./compression";
|
|
5
|
+
/**
|
|
6
|
+
* ContextGraphManager
|
|
7
|
+
* Main interface for managing the WeaveGraph
|
|
8
|
+
* Handles node/edge operations, queries, and persistence metadata
|
|
9
|
+
*/
|
|
10
|
+
export class ContextGraphManager {
|
|
11
|
+
nodes;
|
|
12
|
+
edges;
|
|
13
|
+
edgesBySource; // sourceId -> Set<edgeId>
|
|
14
|
+
edgesByTarget; // targetId -> Set<edgeId>
|
|
15
|
+
nodesByLabel; // label (lowercased) -> Set<nodeId>
|
|
16
|
+
chatId;
|
|
17
|
+
compressionThreshold = 0.75;
|
|
18
|
+
version = "0.1.0";
|
|
19
|
+
createdAt;
|
|
20
|
+
updatedAt;
|
|
21
|
+
constructor(chatId, compressionThreshold) {
|
|
22
|
+
this.chatId = chatId;
|
|
23
|
+
this.nodes = new Map();
|
|
24
|
+
this.edges = new Map();
|
|
25
|
+
this.edgesBySource = new Map();
|
|
26
|
+
this.edgesByTarget = new Map();
|
|
27
|
+
this.nodesByLabel = new Map();
|
|
28
|
+
this.createdAt = new Date();
|
|
29
|
+
this.updatedAt = new Date();
|
|
30
|
+
if (compressionThreshold !== undefined) {
|
|
31
|
+
this.compressionThreshold = compressionThreshold;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Add a node to the graph
|
|
36
|
+
*/
|
|
37
|
+
addNode(node) {
|
|
38
|
+
this.nodes.set(node.id, node);
|
|
39
|
+
// Index by label for keyword search
|
|
40
|
+
const labelKey = node.label.toLowerCase();
|
|
41
|
+
if (!this.nodesByLabel.has(labelKey)) {
|
|
42
|
+
this.nodesByLabel.set(labelKey, new Set());
|
|
43
|
+
}
|
|
44
|
+
this.nodesByLabel.get(labelKey).add(node.id);
|
|
45
|
+
this.updatedAt = new Date();
|
|
46
|
+
return node;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Get a node by ID
|
|
50
|
+
*/
|
|
51
|
+
getNode(nodeId) {
|
|
52
|
+
return this.nodes.get(nodeId);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Update an existing node
|
|
56
|
+
*/
|
|
57
|
+
updateNode(nodeId, updates) {
|
|
58
|
+
const node = this.nodes.get(nodeId);
|
|
59
|
+
if (!node)
|
|
60
|
+
return undefined;
|
|
61
|
+
const updated = NodeBuilder.clone(node, updates);
|
|
62
|
+
this.nodes.set(nodeId, updated);
|
|
63
|
+
this.updatedAt = new Date();
|
|
64
|
+
return updated;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Delete a node (and all related edges)
|
|
68
|
+
*/
|
|
69
|
+
deleteNode(nodeId) {
|
|
70
|
+
const node = this.nodes.get(nodeId);
|
|
71
|
+
if (!node)
|
|
72
|
+
return false;
|
|
73
|
+
// Remove label index
|
|
74
|
+
const labelKey = node.label.toLowerCase();
|
|
75
|
+
const labelSet = this.nodesByLabel.get(labelKey);
|
|
76
|
+
if (labelSet) {
|
|
77
|
+
labelSet.delete(nodeId);
|
|
78
|
+
if (labelSet.size === 0) {
|
|
79
|
+
this.nodesByLabel.delete(labelKey);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// Remove all connected edges
|
|
83
|
+
const sourceEdges = this.edgesBySource.get(nodeId) || new Set();
|
|
84
|
+
const targetEdges = this.edgesByTarget.get(nodeId) || new Set();
|
|
85
|
+
[...sourceEdges, ...targetEdges].forEach((edgeId) => {
|
|
86
|
+
this.edges.delete(edgeId);
|
|
87
|
+
});
|
|
88
|
+
this.edgesBySource.delete(nodeId);
|
|
89
|
+
this.edgesByTarget.delete(nodeId);
|
|
90
|
+
this.nodes.delete(nodeId);
|
|
91
|
+
this.updatedAt = new Date();
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Add an edge to the graph
|
|
96
|
+
*/
|
|
97
|
+
addEdge(edge) {
|
|
98
|
+
this.edges.set(edge.id, edge);
|
|
99
|
+
// Index by source and target
|
|
100
|
+
if (!this.edgesBySource.has(edge.sourceId)) {
|
|
101
|
+
this.edgesBySource.set(edge.sourceId, new Set());
|
|
102
|
+
}
|
|
103
|
+
this.edgesBySource.get(edge.sourceId).add(edge.id);
|
|
104
|
+
if (!this.edgesByTarget.has(edge.targetId)) {
|
|
105
|
+
this.edgesByTarget.set(edge.targetId, new Set());
|
|
106
|
+
}
|
|
107
|
+
this.edgesByTarget.get(edge.targetId).add(edge.id);
|
|
108
|
+
this.updatedAt = new Date();
|
|
109
|
+
return edge;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Get an edge by ID
|
|
113
|
+
*/
|
|
114
|
+
getEdge(edgeId) {
|
|
115
|
+
return this.edges.get(edgeId);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Update an existing edge
|
|
119
|
+
*/
|
|
120
|
+
updateEdge(edgeId, updates) {
|
|
121
|
+
const edge = this.edges.get(edgeId);
|
|
122
|
+
if (!edge)
|
|
123
|
+
return undefined;
|
|
124
|
+
const updated = EdgeBuilder.clone(edge, updates);
|
|
125
|
+
this.edges.set(edgeId, updated);
|
|
126
|
+
this.updatedAt = new Date();
|
|
127
|
+
return updated;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Delete an edge
|
|
131
|
+
*/
|
|
132
|
+
deleteEdge(edgeId) {
|
|
133
|
+
const edge = this.edges.get(edgeId);
|
|
134
|
+
if (!edge)
|
|
135
|
+
return false;
|
|
136
|
+
this.edgesBySource.get(edge.sourceId)?.delete(edgeId);
|
|
137
|
+
this.edgesByTarget.get(edge.targetId)?.delete(edgeId);
|
|
138
|
+
this.edges.delete(edgeId);
|
|
139
|
+
this.updatedAt = new Date();
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Get all edges from a source node
|
|
144
|
+
*/
|
|
145
|
+
getEdgesFromNode(nodeId) {
|
|
146
|
+
const edgeIds = this.edgesBySource.get(nodeId) || new Set();
|
|
147
|
+
return Array.from(edgeIds)
|
|
148
|
+
.map((id) => this.edges.get(id))
|
|
149
|
+
.filter((edge) => edge !== undefined);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Get all edges to a target node
|
|
153
|
+
*/
|
|
154
|
+
getEdgesToNode(nodeId) {
|
|
155
|
+
const edgeIds = this.edgesByTarget.get(nodeId) || new Set();
|
|
156
|
+
return Array.from(edgeIds)
|
|
157
|
+
.map((id) => this.edges.get(id))
|
|
158
|
+
.filter((edge) => edge !== undefined);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Query nodes by label (keyword search)
|
|
162
|
+
* Returns nodes where the label contains the query string
|
|
163
|
+
*/
|
|
164
|
+
queryNodesByLabel(query) {
|
|
165
|
+
const lowerQuery = query.toLowerCase();
|
|
166
|
+
const results = [];
|
|
167
|
+
for (const [label, nodeIds] of this.nodesByLabel.entries()) {
|
|
168
|
+
if (label.includes(lowerQuery)) {
|
|
169
|
+
nodeIds.forEach((nodeId) => {
|
|
170
|
+
const node = this.nodes.get(nodeId);
|
|
171
|
+
if (node)
|
|
172
|
+
results.push(node);
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return results.sort((a, b) => (b.frequency ?? 0) - (a.frequency ?? 0));
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Query nodes by type
|
|
180
|
+
*/
|
|
181
|
+
queryNodesByType(type) {
|
|
182
|
+
return Array.from(this.nodes.values()).filter((node) => node.type === type);
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Query edges by type
|
|
186
|
+
*/
|
|
187
|
+
queryEdgesByType(type) {
|
|
188
|
+
return Array.from(this.edges.values()).filter((edge) => edge.type === type);
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Get graph statistics
|
|
192
|
+
*/
|
|
193
|
+
getStats() {
|
|
194
|
+
const nodesByType = new Map();
|
|
195
|
+
const edgesByType = new Map();
|
|
196
|
+
for (const node of this.nodes.values()) {
|
|
197
|
+
nodesByType.set(node.type, (nodesByType.get(node.type) ?? 0) + 1);
|
|
198
|
+
}
|
|
199
|
+
for (const edge of this.edges.values()) {
|
|
200
|
+
edgesByType.set(edge.type, (edgesByType.get(edge.type) ?? 0) + 1);
|
|
201
|
+
}
|
|
202
|
+
return {
|
|
203
|
+
totalNodes: this.nodes.size,
|
|
204
|
+
totalEdges: this.edges.size,
|
|
205
|
+
nodesByType: Object.fromEntries(nodesByType),
|
|
206
|
+
edgesByType: Object.fromEntries(edgesByType),
|
|
207
|
+
chatId: this.chatId,
|
|
208
|
+
createdAt: this.createdAt,
|
|
209
|
+
updatedAt: this.updatedAt,
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Snapshot the graph for serialization
|
|
214
|
+
*/
|
|
215
|
+
snapshot() {
|
|
216
|
+
return {
|
|
217
|
+
nodes: Object.fromEntries(this.nodes),
|
|
218
|
+
edges: Object.fromEntries(this.edges),
|
|
219
|
+
metadata: {
|
|
220
|
+
chatId: this.chatId,
|
|
221
|
+
version: this.version,
|
|
222
|
+
createdAt: this.createdAt,
|
|
223
|
+
updatedAt: this.updatedAt,
|
|
224
|
+
compressionThreshold: this.compressionThreshold,
|
|
225
|
+
},
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Restore graph from snapshot
|
|
230
|
+
*/
|
|
231
|
+
static fromSnapshot(snapshot) {
|
|
232
|
+
const manager = new ContextGraphManager(snapshot.metadata.chatId, snapshot.metadata.compressionThreshold);
|
|
233
|
+
Object.values(snapshot.nodes).forEach((node) => {
|
|
234
|
+
manager.addNode(node);
|
|
235
|
+
});
|
|
236
|
+
Object.values(snapshot.edges).forEach((edge) => {
|
|
237
|
+
manager.addEdge(edge);
|
|
238
|
+
});
|
|
239
|
+
manager.createdAt = snapshot.metadata.createdAt;
|
|
240
|
+
manager.updatedAt = snapshot.metadata.updatedAt;
|
|
241
|
+
return manager;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Get the current window size percentage
|
|
245
|
+
* Calculates actual context window usage based on node and edge sizes
|
|
246
|
+
*/
|
|
247
|
+
getContextWindowUsage() {
|
|
248
|
+
const contextSize = CompressionManager.calculateContextSize(this.getAllNodes(), this.getAllEdges());
|
|
249
|
+
return CompressionManager.calculateContextUsagePercentage(contextSize);
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Get estimated context size in bytes
|
|
253
|
+
*/
|
|
254
|
+
getContextSize() {
|
|
255
|
+
return CompressionManager.calculateContextSize(this.getAllNodes(), this.getAllEdges());
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Check if compression threshold has been reached
|
|
259
|
+
*/
|
|
260
|
+
shouldCompress() {
|
|
261
|
+
return this.getContextWindowUsage() >= this.compressionThreshold;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Compress the graph by archiving low-frequency nodes
|
|
265
|
+
* Returns compression statistics
|
|
266
|
+
*/
|
|
267
|
+
compress(targetReductionPercentage = 0.3) {
|
|
268
|
+
const archiveCandidates = CompressionManager.identifyArchiveCandidates(this.getAllNodes(), this.getAllEdges(), targetReductionPercentage);
|
|
269
|
+
const compressionMgr = new CompressionManager();
|
|
270
|
+
compressionMgr.archiveNodes(archiveCandidates, this.nodes, this.edges);
|
|
271
|
+
// Remove archived nodes from active graph
|
|
272
|
+
for (const nodeId of archiveCandidates) {
|
|
273
|
+
this.deleteNode(nodeId);
|
|
274
|
+
}
|
|
275
|
+
return {
|
|
276
|
+
archivedNodeCount: archiveCandidates.length,
|
|
277
|
+
archiveStats: compressionMgr.getArchiveStats(),
|
|
278
|
+
newContextSize: this.getContextSize(),
|
|
279
|
+
contextUsagePercentage: this.getContextWindowUsage(),
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Suppress an error node and create a correction
|
|
284
|
+
*/
|
|
285
|
+
suppressError(errorNodeId, correctionLabel, correctionDescription) {
|
|
286
|
+
const errorNode = this.getNode(errorNodeId);
|
|
287
|
+
if (!errorNode || errorNode.type !== NodeType.ERROR) {
|
|
288
|
+
throw new Error("Node must be an ERROR type to suppress it");
|
|
289
|
+
}
|
|
290
|
+
// Mark error as suppressed
|
|
291
|
+
const suppressedError = ErrorSuppression.suppressNode(errorNode);
|
|
292
|
+
this.updateNode(errorNodeId, suppressedError);
|
|
293
|
+
// Create correction node and link it
|
|
294
|
+
const { correctionNode, correctionEdge } = ErrorSuppression.createCorrection(errorNodeId, correctionLabel, correctionDescription);
|
|
295
|
+
this.addNode(correctionNode);
|
|
296
|
+
this.addEdge(correctionEdge);
|
|
297
|
+
return { correctionNode, correctionEdge };
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Get all error nodes that have been corrected
|
|
301
|
+
*/
|
|
302
|
+
getCorrectedErrors() {
|
|
303
|
+
return ErrorSuppression.findCorrectedErrors(this.nodes, this.edges);
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Get all error nodes that haven't been corrected yet
|
|
307
|
+
*/
|
|
308
|
+
getUncorrectedErrors() {
|
|
309
|
+
return ErrorSuppression.findUncorrectedErrors(this.nodes, this.edges);
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Get all nodes
|
|
313
|
+
*/
|
|
314
|
+
getAllNodes() {
|
|
315
|
+
return Array.from(this.nodes.values());
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Get all edges
|
|
319
|
+
*/
|
|
320
|
+
getAllEdges() {
|
|
321
|
+
return Array.from(this.edges.values());
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Clear the entire graph
|
|
325
|
+
*/
|
|
326
|
+
clear() {
|
|
327
|
+
this.nodes.clear();
|
|
328
|
+
this.edges.clear();
|
|
329
|
+
this.edgesBySource.clear();
|
|
330
|
+
this.edgesByTarget.clear();
|
|
331
|
+
this.nodesByLabel.clear();
|
|
332
|
+
this.updatedAt = new Date();
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
export { PersistenceManager } from "./persistence";
|
|
336
|
+
export { NodeBuilder } from "./node";
|
|
337
|
+
export { EdgeBuilder } from "./edge";
|
|
338
|
+
export { CompressionManager, ErrorSuppression } from "./compression";
|
|
339
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,QAAQ,EAA2B,MAAM,SAAS,CAAC;AACxE,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAErE;;;;GAIG;AACH,MAAM,OAAO,mBAAmB;IACtB,KAAK,CAAoB;IACzB,KAAK,CAAoB;IACzB,aAAa,CAA2B,CAAC,0BAA0B;IACnE,aAAa,CAA2B,CAAC,0BAA0B;IACnE,YAAY,CAA2B,CAAC,oCAAoC;IAC5E,MAAM,CAAS;IACf,oBAAoB,GAAW,IAAI,CAAC;IACpC,OAAO,GAAW,OAAO,CAAC;IAC1B,SAAS,CAAO;IAChB,SAAS,CAAO;IAExB,YAAY,MAAc,EAAE,oBAA6B;QACvD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,IAAI,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C,KAAK,CAAC,KAAK,EAAE,CAAC;QACnB,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QACrB,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;QAC3B,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;QAC3B,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,CAAC;QAC1B,IAAI,CAAC,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC;IAC9B,CAAC;CACF;AAID,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/node.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Node, NodeType } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* NodeBuilder utility for creating and managing graph nodes
|
|
4
|
+
*/
|
|
5
|
+
export declare class NodeBuilder {
|
|
6
|
+
/**
|
|
7
|
+
* Create a new node with the given type and label
|
|
8
|
+
*/
|
|
9
|
+
static create(type: NodeType, label: string, description?: string, metadata?: Record<string, unknown>): Node;
|
|
10
|
+
/**
|
|
11
|
+
* Create a CONCEPT node
|
|
12
|
+
*/
|
|
13
|
+
static concept(label: string, description?: string): Node;
|
|
14
|
+
/**
|
|
15
|
+
* Create a DECISION node
|
|
16
|
+
*/
|
|
17
|
+
static decision(label: string, description?: string): Node;
|
|
18
|
+
/**
|
|
19
|
+
* Create a MILESTONE node
|
|
20
|
+
*/
|
|
21
|
+
static milestone(label: string, description?: string): Node;
|
|
22
|
+
/**
|
|
23
|
+
* Create an ERROR node
|
|
24
|
+
*/
|
|
25
|
+
static error(label: string, description?: string): Node;
|
|
26
|
+
/**
|
|
27
|
+
* Create a CORRECTION node
|
|
28
|
+
*/
|
|
29
|
+
static correction(label: string, description?: string): Node;
|
|
30
|
+
/**
|
|
31
|
+
* Create a CODE_ENTITY node
|
|
32
|
+
*/
|
|
33
|
+
static codeEntity(label: string, description?: string): Node;
|
|
34
|
+
/**
|
|
35
|
+
* Clone a node with updated values
|
|
36
|
+
*/
|
|
37
|
+
static clone(node: Node, updates?: Partial<Node>): Node;
|
|
38
|
+
/**
|
|
39
|
+
* Increment frequency counter for a node
|
|
40
|
+
*/
|
|
41
|
+
static incrementFrequency(node: Node): Node;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=node.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAGzC;;GAEG;AACH,qBAAa,WAAW;IACtB;;OAEG;IACH,MAAM,CAAC,MAAM,CACX,IAAI,EAAE,QAAQ,EACd,KAAK,EAAE,MAAM,EACb,WAAW,CAAC,EAAE,MAAM,EACpB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACjC,IAAI;IAaP;;OAEG;IACH,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI;IAIzD;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI;IAI1D;;OAEG;IACH,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI;IAI3D;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI;IAIvD;;OAEG;IACH,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,CAAC,E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