@mce-bt/microagents-memory 0.1.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,9 @@
1
+ export { ShortTermMemory, type STMConfig } from './stm.js';
2
+ export { MidTermMemory, type MTMConfig, type EpisodicMemory } from './mtm.js';
3
+ export { LongTermMemory, type LTMConfig, type KnowledgeFact } from './ltm.js';
4
+ export { MemoryManager, type MemoryManagerConfig, type ContextBlock } from './manager.js';
5
+ export { KnowledgeGraph, type KGConfig, type Entity, type Relation, type SearchEntitiesOptions, type GraphSnapshot, } from './knowledge-graph.js';
6
+ export { MemoryExtractor, createExtractionAdapter, type ExtractionLLMAdapter, type ExtractionResult, type ExtractionStats, type ExtractedEntity, type ExtractedRelation, } from './memory-extractor.js';
7
+ export { createMemoryTools } from './memory-tools.js';
8
+ export { SummarizationPipeline, type SummarizationPipelineConfig, type PipelineResult, } from './summarization-pipeline.js';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,KAAK,SAAS,EAAE,MAAM,UAAU,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,KAAK,SAAS,EAAE,KAAK,cAAc,EAAE,MAAM,UAAU,CAAC;AAC9E,OAAO,EAAE,cAAc,EAAE,KAAK,SAAS,EAAE,KAAK,aAAa,EAAE,MAAM,UAAU,CAAC;AAC9E,OAAO,EAAE,aAAa,EAAE,KAAK,mBAAmB,EAAE,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AAC1F,OAAO,EACL,cAAc,EACd,KAAK,QAAQ,EACb,KAAK,MAAM,EACX,KAAK,QAAQ,EACb,KAAK,qBAAqB,EAC1B,KAAK,aAAa,GACnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,eAAe,EACf,uBAAuB,EACvB,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,iBAAiB,GACvB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EACL,qBAAqB,EACrB,KAAK,2BAA2B,EAChC,KAAK,cAAc,GACpB,MAAM,6BAA6B,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ export { ShortTermMemory } from './stm.js';
2
+ export { MidTermMemory } from './mtm.js';
3
+ export { LongTermMemory } from './ltm.js';
4
+ export { MemoryManager } from './manager.js';
5
+ export { KnowledgeGraph, } from './knowledge-graph.js';
6
+ export { MemoryExtractor, createExtractionAdapter, } from './memory-extractor.js';
7
+ export { createMemoryTools } from './memory-tools.js';
8
+ export { SummarizationPipeline, } from './summarization-pipeline.js';
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAkB,MAAM,UAAU,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAuC,MAAM,UAAU,CAAC;AAC9E,OAAO,EAAE,cAAc,EAAsC,MAAM,UAAU,CAAC;AAC9E,OAAO,EAAE,aAAa,EAA+C,MAAM,cAAc,CAAC;AAC1F,OAAO,EACL,cAAc,GAMf,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,eAAe,EACf,uBAAuB,GAMxB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EACL,qBAAqB,GAGtB,MAAM,6BAA6B,CAAC"}
@@ -0,0 +1,179 @@
1
+ export interface KGConfig {
2
+ connectionString: string;
3
+ /** Embedding dimensions (default: 1536) */
4
+ embeddingDimensions?: number;
5
+ }
6
+ export interface Entity {
7
+ id: string;
8
+ agentId: string;
9
+ name: string;
10
+ entityType: string;
11
+ observations: string[];
12
+ embedding?: number[];
13
+ metadata: Record<string, unknown>;
14
+ createdAt: Date;
15
+ updatedAt: Date;
16
+ }
17
+ export interface Relation {
18
+ id: string;
19
+ agentId: string;
20
+ fromEntity: string;
21
+ toEntity: string;
22
+ relationType: string;
23
+ weight: number;
24
+ validFrom: Date;
25
+ validUntil: Date | null;
26
+ metadata: Record<string, unknown>;
27
+ createdAt: Date;
28
+ }
29
+ export interface SearchEntitiesOptions {
30
+ query?: string;
31
+ entityType?: string;
32
+ limit?: number;
33
+ embedding?: number[];
34
+ threshold?: number;
35
+ }
36
+ export interface GraphSnapshot {
37
+ entities: Entity[];
38
+ relations: Relation[];
39
+ }
40
+ /**
41
+ * Knowledge Graph — Postgres-backed entity-relation graph with temporal validity.
42
+ *
43
+ * Combines the MCP memory server's entity-relation-observation model with
44
+ * Graphiti's temporal validity windows, all implemented in PostgreSQL.
45
+ *
46
+ * Entities have names, types, observations (atomic facts), and optional embeddings
47
+ * for semantic search. Relations connect entities with typed, directed edges that
48
+ * carry validity windows (valid_from / valid_until) for temporal reasoning.
49
+ */
50
+ export declare class KnowledgeGraph {
51
+ private pool;
52
+ private config;
53
+ private agentId;
54
+ private embeddingDimensions;
55
+ constructor(config: KGConfig);
56
+ start(agentId: string): Promise<void>;
57
+ stop(): Promise<void>;
58
+ private ensureSchema;
59
+ /**
60
+ * Create or update an entity. If an entity with the same name already exists
61
+ * for this agent, merges new observations (deduplicates) and updates metadata.
62
+ */
63
+ upsertEntity(input: {
64
+ name: string;
65
+ entityType: string;
66
+ observations?: string[];
67
+ embedding?: number[];
68
+ metadata?: Record<string, unknown>;
69
+ }): Promise<Entity>;
70
+ /**
71
+ * Get an entity by name (scoped to this agent).
72
+ */
73
+ getEntityByName(name: string): Promise<Entity | null>;
74
+ /**
75
+ * Get an entity by ID.
76
+ */
77
+ getEntityById(id: string): Promise<Entity | null>;
78
+ /**
79
+ * Add observations to an existing entity. Deduplicates automatically.
80
+ */
81
+ addObservations(entityName: string, observations: string[]): Promise<string[]>;
82
+ /**
83
+ * Remove specific observations from an entity.
84
+ */
85
+ removeObservations(entityName: string, observations: string[]): Promise<void>;
86
+ /**
87
+ * Delete an entity and all its relations (cascading).
88
+ */
89
+ deleteEntity(name: string): Promise<void>;
90
+ /**
91
+ * Create a relation between two entities. Skips if an identical active relation exists.
92
+ * If a contradicting relation exists (same from/to/type but different validity),
93
+ * the old one is invalidated (valid_until set to now).
94
+ */
95
+ createRelation(input: {
96
+ from: string;
97
+ to: string;
98
+ relationType: string;
99
+ weight?: number;
100
+ metadata?: Record<string, unknown>;
101
+ validFrom?: Date;
102
+ }): Promise<Relation | null>;
103
+ /**
104
+ * Invalidate a relation by setting valid_until to now.
105
+ * Preserves history — the relation is never deleted.
106
+ */
107
+ invalidateRelation(id: string): Promise<void>;
108
+ /**
109
+ * Delete a relation permanently (use invalidate for temporal preservation).
110
+ */
111
+ deleteRelation(input: {
112
+ from: string;
113
+ to: string;
114
+ relationType: string;
115
+ }): Promise<void>;
116
+ /**
117
+ * Get all active relations for an entity (as source or target).
118
+ * Only returns relations where valid_until IS NULL (currently active).
119
+ */
120
+ getEntityRelations(entityName: string, options?: {
121
+ includeExpired?: boolean;
122
+ }): Promise<(Relation & {
123
+ fromName: string;
124
+ toName: string;
125
+ })[]>;
126
+ /**
127
+ * Search entities by text query (matches name, type, and observations).
128
+ */
129
+ searchEntities(options?: SearchEntitiesOptions): Promise<Entity[]>;
130
+ /**
131
+ * Semantic search entities by embedding similarity.
132
+ */
133
+ searchEntitiesByEmbedding(queryEmbedding: number[], options?: {
134
+ entityType?: string;
135
+ limit?: number;
136
+ threshold?: number;
137
+ }): Promise<(Entity & {
138
+ similarity: number;
139
+ })[]>;
140
+ /**
141
+ * Open specific entities by name and return them with their relations.
142
+ * Similar to MCP memory server's open_nodes.
143
+ */
144
+ openEntities(names: string[]): Promise<GraphSnapshot>;
145
+ /**
146
+ * Read the full graph for this agent (active relations only).
147
+ */
148
+ readGraph(options?: {
149
+ includeExpired?: boolean;
150
+ }): Promise<GraphSnapshot>;
151
+ /**
152
+ * Get the state of relations at a specific point in time.
153
+ */
154
+ getRelationsAt(date: Date, options?: {
155
+ entityName?: string;
156
+ }): Promise<Relation[]>;
157
+ /**
158
+ * Get the history of changes to a specific relation type between two entities.
159
+ */
160
+ getRelationHistory(from: string, to: string, relationType: string): Promise<Relation[]>;
161
+ /**
162
+ * Update a relation: invalidates the existing one and creates a new one.
163
+ * This preserves temporal history (Graphiti pattern).
164
+ */
165
+ supersedRelation(input: {
166
+ from: string;
167
+ to: string;
168
+ relationType: string;
169
+ weight?: number;
170
+ metadata?: Record<string, unknown>;
171
+ }): Promise<Relation | null>;
172
+ /**
173
+ * Get entity counts grouped by type.
174
+ */
175
+ getEntityTypeCounts(): Promise<Record<string, number>>;
176
+ private rowToEntity;
177
+ private rowToRelation;
178
+ }
179
+ //# sourceMappingURL=knowledge-graph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"knowledge-graph.d.ts","sourceRoot":"","sources":["../src/knowledge-graph.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,QAAQ;IACvB,gBAAgB,EAAE,MAAM,CAAC;IACzB,2CAA2C;IAC3C,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,MAAM,WAAW,MAAM;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,SAAS,EAAE,IAAI,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;CACjB;AAED,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,U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