@aeriondyseti/vector-memory-mcp 0.2.0 → 0.2.2
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/README.md +4 -4
- package/dist/config/index.d.ts +8 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +14 -0
- package/dist/config/index.js.map +1 -0
- package/dist/db/connection.d.ts +3 -0
- package/dist/db/connection.d.ts.map +1 -0
- package/dist/db/connection.js +10 -0
- package/dist/db/connection.js.map +1 -0
- package/dist/db/memory.repository.d.ts +12 -0
- package/dist/db/memory.repository.d.ts.map +1 -0
- package/dist/db/memory.repository.js +79 -0
- package/dist/db/memory.repository.js.map +1 -0
- package/dist/db/schema.d.ts +4 -0
- package/dist/db/schema.d.ts.map +1 -0
- package/dist/db/schema.js +12 -0
- package/dist/db/schema.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/handlers.d.ts +8 -0
- package/dist/mcp/handlers.d.ts.map +1 -0
- package/dist/mcp/handlers.js +81 -0
- package/dist/mcp/handlers.js.map +1 -0
- package/dist/mcp/server.d.ts +5 -0
- package/dist/mcp/server.d.ts.map +1 -0
- package/dist/mcp/server.js +22 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/mcp/tools.d.ts +7 -0
- package/dist/mcp/tools.d.ts.map +1 -0
- package/dist/mcp/tools.js +73 -0
- package/dist/mcp/tools.js.map +1 -0
- package/dist/services/embeddings.service.d.ts +12 -0
- package/dist/services/embeddings.service.d.ts.map +1 -0
- package/dist/services/embeddings.service.js +55 -0
- package/dist/services/embeddings.service.js.map +1 -0
- package/dist/services/memory.service.d.ts +14 -0
- package/dist/services/memory.service.d.ts.map +1 -0
- package/dist/services/memory.service.js +80 -0
- package/dist/services/memory.service.js.map +1 -0
- package/dist/types/memory.d.ts +18 -0
- package/dist/types/memory.d.ts.map +1 -0
- package/dist/types/memory.js +18 -0
- package/dist/types/memory.js.map +1 -0
- package/package.json +9 -6
- package/src/config/index.ts +0 -29
- package/src/db/connection.ts +0 -11
- package/src/db/memory.repository.ts +0 -94
- package/src/db/schema.ts +0 -33
- package/src/index.ts +0 -23
- package/src/mcp/handlers.ts +0 -111
- package/src/mcp/server.ts +0 -34
- package/src/mcp/tools.ts +0 -80
- package/src/services/embeddings.service.ts +0 -46
- package/src/services/memory.service.ts +0 -102
- package/src/types/memory.ts +0 -35
package/README.md
CHANGED
|
@@ -179,7 +179,7 @@ vector-memory-mcp/
|
|
|
179
179
|
|
|
180
180
|
- **MCP Framework**: @modelcontextprotocol/sdk (official SDK)
|
|
181
181
|
- **Vector Database**: LanceDB (fast, local, vector search)
|
|
182
|
-
- **Embeddings**: @
|
|
182
|
+
- **Embeddings**: [@huggingface/transformers](https://huggingface.co/docs/transformers.js) (Xenova/all-MiniLM-L6-v2, 384 dimensions)
|
|
183
183
|
- **Language**: TypeScript 5.0+
|
|
184
184
|
- **Runtime**: Bun 1.0+
|
|
185
185
|
- **Testing**: Bun test
|
|
@@ -193,7 +193,7 @@ vector-memory-mcp/
|
|
|
193
193
|
```
|
|
194
194
|
Claude Code calls store_memory tool
|
|
195
195
|
↓
|
|
196
|
-
Content → @
|
|
196
|
+
Content → @huggingface/transformers → 384d vector
|
|
197
197
|
↓
|
|
198
198
|
Store in LanceDB with metadata
|
|
199
199
|
↓
|
|
@@ -205,7 +205,7 @@ Store in LanceDB with metadata
|
|
|
205
205
|
```
|
|
206
206
|
Claude Code calls search_memories
|
|
207
207
|
↓
|
|
208
|
-
Query → @
|
|
208
|
+
Query → @huggingface/transformers → 384d vector
|
|
209
209
|
↓
|
|
210
210
|
Vector search in LanceDB
|
|
211
211
|
↓
|
|
@@ -346,7 +346,7 @@ MIT License - see [LICENSE](LICENSE) for details.
|
|
|
346
346
|
|
|
347
347
|
- Built with [@modelcontextprotocol/sdk](https://github.com/modelcontextprotocol/typescript-sdk) - Official MCP TypeScript SDK
|
|
348
348
|
- Uses [LanceDB](https://lancedb.com/) for fast, local vector search
|
|
349
|
-
- Powered by [@
|
|
349
|
+
- Powered by [@huggingface/transformers](https://huggingface.co/docs/transformers.js) for local embeddings
|
|
350
350
|
- Database layer via [Drizzle ORM](https://orm.drizzle.team/)
|
|
351
351
|
- Inspired by [doobidoo's mcp-memory-service](https://github.com/doobidoo/mcp-memory-service)
|
|
352
352
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,MAAM;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,MAAM,CAAC;IACvB,kBAAkB,EAAE,MAAM,CAAC;CAC5B;AAaD,wBAAgB,UAAU,IAAI,MAAM,CAMnC;AAED,eAAO,MAAM,MAAM,QAAe,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { join } from "path";
|
|
2
|
+
import { homedir } from "os";
|
|
3
|
+
const DEFAULT_DB_PATH = join(homedir(), ".local", "share", "vector-memory-mcp", "memories.db");
|
|
4
|
+
const DEFAULT_EMBEDDING_MODEL = "Xenova/all-MiniLM-L6-v2";
|
|
5
|
+
const DEFAULT_EMBEDDING_DIMENSION = 384;
|
|
6
|
+
export function loadConfig() {
|
|
7
|
+
return {
|
|
8
|
+
dbPath: process.env.VECTOR_MEMORY_DB_PATH ?? DEFAULT_DB_PATH,
|
|
9
|
+
embeddingModel: process.env.VECTOR_MEMORY_MODEL ?? DEFAULT_EMBEDDING_MODEL,
|
|
10
|
+
embeddingDimension: DEFAULT_EMBEDDING_DIMENSION,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export const config = loadConfig();
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAQ7B,MAAM,eAAe,GAAG,IAAI,CAC1B,OAAO,EAAE,EACT,QAAQ,EACR,OAAO,EACP,mBAAmB,EACnB,aAAa,CACd,CAAC;AAEF,MAAM,uBAAuB,GAAG,yBAAyB,CAAC;AAC1D,MAAM,2BAA2B,GAAG,GAAG,CAAC;AAExC,MAAM,UAAU,UAAU;IACxB,OAAO;QACL,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,qBAAqB,IAAI,eAAe;QAC5D,cAAc,EAAE,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,uBAAuB;QAC1E,kBAAkB,EAAE,2BAA2B;KAChD,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,MAAM,GAAG,UAAU,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../src/db/connection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,kBAAkB,CAAC;AAI5C,wBAAsB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,CAMnF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as lancedb from "@lancedb/lancedb";
|
|
2
|
+
import { mkdirSync } from "fs";
|
|
3
|
+
import { dirname } from "path";
|
|
4
|
+
export async function connectToDatabase(dbPath) {
|
|
5
|
+
// Ensure directory exists
|
|
6
|
+
mkdirSync(dirname(dbPath), { recursive: true });
|
|
7
|
+
const db = await lancedb.connect(dbPath);
|
|
8
|
+
return db;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=connection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/db/connection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAC/B,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAE/B,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,MAAc;IACpD,0BAA0B;IAC1B,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAEhD,MAAM,EAAE,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACzC,OAAO,EAAE,CAAC;AACZ,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as lancedb from "@lancedb/lancedb";
|
|
2
|
+
import { type Memory, type VectorRow } from "../types/memory.js";
|
|
3
|
+
export declare class MemoryRepository {
|
|
4
|
+
private db;
|
|
5
|
+
constructor(db: lancedb.Connection);
|
|
6
|
+
private getTable;
|
|
7
|
+
insert(memory: Memory): Promise<void>;
|
|
8
|
+
findById(id: string): Promise<Memory | null>;
|
|
9
|
+
markDeleted(id: string): Promise<boolean>;
|
|
10
|
+
findSimilar(embedding: number[], limit: number): Promise<VectorRow[]>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=memory.repository.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.repository.d.ts","sourceRoot":"","sources":["../../src/db/memory.repository.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,kBAAkB,CAAC;AAE5C,OAAO,EACL,KAAK,MAAM,EACX,KAAK,SAAS,EAEf,MAAM,oBAAoB,CAAC;AAE5B,qBAAa,gBAAgB;IACf,OAAO,CAAC,EAAE;gBAAF,EAAE,EAAE,OAAO,CAAC,UAAU;YAE5B,QAAQ;IAShB,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAerC,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IA4B5C,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAqBzC,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;CAS5E"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { TABLE_NAME, memorySchema } from "./schema.js";
|
|
2
|
+
import { DELETED_TOMBSTONE, } from "../types/memory.js";
|
|
3
|
+
export class MemoryRepository {
|
|
4
|
+
db;
|
|
5
|
+
constructor(db) {
|
|
6
|
+
this.db = db;
|
|
7
|
+
}
|
|
8
|
+
async getTable() {
|
|
9
|
+
const names = await this.db.tableNames();
|
|
10
|
+
if (names.includes(TABLE_NAME)) {
|
|
11
|
+
return await this.db.openTable(TABLE_NAME);
|
|
12
|
+
}
|
|
13
|
+
// Create with empty data to initialize schema
|
|
14
|
+
return await this.db.createTable(TABLE_NAME, [], { schema: memorySchema });
|
|
15
|
+
}
|
|
16
|
+
async insert(memory) {
|
|
17
|
+
const table = await this.getTable();
|
|
18
|
+
await table.add([
|
|
19
|
+
{
|
|
20
|
+
id: memory.id,
|
|
21
|
+
vector: memory.embedding,
|
|
22
|
+
content: memory.content,
|
|
23
|
+
metadata: JSON.stringify(memory.metadata),
|
|
24
|
+
created_at: memory.createdAt.getTime(),
|
|
25
|
+
updated_at: memory.updatedAt.getTime(),
|
|
26
|
+
superseded_by: memory.supersededBy,
|
|
27
|
+
},
|
|
28
|
+
]);
|
|
29
|
+
}
|
|
30
|
+
async findById(id) {
|
|
31
|
+
const table = await this.getTable();
|
|
32
|
+
const results = await table.query().where(`id = '${id}'`).limit(1).toArray();
|
|
33
|
+
if (results.length === 0) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
const row = results[0];
|
|
37
|
+
// Handle Arrow Vector type conversion
|
|
38
|
+
// LanceDB returns an Arrow Vector object which is iterable but not an array
|
|
39
|
+
const vectorData = row.vector;
|
|
40
|
+
const embedding = Array.isArray(vectorData)
|
|
41
|
+
? vectorData
|
|
42
|
+
: Array.from(vectorData);
|
|
43
|
+
return {
|
|
44
|
+
id: row.id,
|
|
45
|
+
content: row.content,
|
|
46
|
+
embedding,
|
|
47
|
+
metadata: JSON.parse(row.metadata),
|
|
48
|
+
createdAt: new Date(row.created_at),
|
|
49
|
+
updatedAt: new Date(row.updated_at),
|
|
50
|
+
supersededBy: row.superseded_by,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
async markDeleted(id) {
|
|
54
|
+
const table = await this.getTable();
|
|
55
|
+
// Verify existence first to match previous behavior (return false if not found)
|
|
56
|
+
const existing = await table.query().where(`id = '${id}'`).limit(1).toArray();
|
|
57
|
+
if (existing.length === 0) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
const now = Date.now();
|
|
61
|
+
await table.update({
|
|
62
|
+
where: `id = '${id}'`,
|
|
63
|
+
values: {
|
|
64
|
+
superseded_by: DELETED_TOMBSTONE,
|
|
65
|
+
updated_at: now,
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
async findSimilar(embedding, limit) {
|
|
71
|
+
const table = await this.getTable();
|
|
72
|
+
const results = await table.vectorSearch(embedding).limit(limit).toArray();
|
|
73
|
+
return results.map((r) => ({
|
|
74
|
+
id: r.id,
|
|
75
|
+
distance: r._distance,
|
|
76
|
+
}));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=memory.repository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.repository.js","sourceRoot":"","sources":["../../src/db/memory.repository.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAGL,iBAAiB,GAClB,MAAM,oBAAoB,CAAC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N,aAAa,EAAE,iBAAiB;gBAChC,UAAU,EAAE,GAAG;aAChB;SACF,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,SAAmB,EAAE,KAAa;QAClD,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;QACpC,MAAM,OAAO,GAAG,MAAM,KAAK,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC;QAE3E,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YACzB,EAAE,EAAE,CAAC,CAAC,EAAY;YAClB,QAAQ,EAAE,CAAC,CAAC,SAAmB;SAChC,CAAC,CAAC,CAAC;IACN,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/db/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EAOP,MAAM,cAAc,CAAC;AAEtB,eAAO,MAAM,UAAU,aAAa,CAAC;AAErC,eAAO,MAAM,YAAY,aAoBvB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Schema, Field, FixedSizeList, Float32, Utf8, Timestamp, TimeUnit, } from "apache-arrow";
|
|
2
|
+
export const TABLE_NAME = "memories";
|
|
3
|
+
export const memorySchema = new Schema([
|
|
4
|
+
new Field("id", new Utf8(), false),
|
|
5
|
+
new Field("vector", new FixedSizeList(384, new Field("item", new Float32())), false),
|
|
6
|
+
new Field("content", new Utf8(), false),
|
|
7
|
+
new Field("metadata", new Utf8(), false), // JSON string
|
|
8
|
+
new Field("created_at", new Timestamp(TimeUnit.MILLISECOND), false),
|
|
9
|
+
new Field("updated_at", new Timestamp(TimeUnit.MILLISECOND), false),
|
|
10
|
+
new Field("superseded_by", new Utf8(), true), // Nullable
|
|
11
|
+
]);
|
|
12
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/db/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,KAAK,EACL,aAAa,EACb,OAAO,EACP,IAAI,EACJ,SAAS,EACT,QAAQ,GACT,MAAM,cAAc,CAAC;AAEtB,MAAM,CAAC,MAAM,UAAU,GAAG,UAAU,CAAC;AAErC,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,MAAM,CAAC;IACrC,IAAI,KAAK,CAAC,IAAI,EAAE,IAAI,IAAI,EAAE,EAAE,KAAK,CAAC;IAClC,IAAI,KAAK,CACP,QAAQ,EACR,IAAI,aAAa,CAAC,GAAG,EAAE,IAAI,KAAK,CAAC,MAAM,EAAE,IAAI,OAAO,EAAE,CAAC,CAAC,EACxD,KAAK,CACN;IACD,IAAI,KAAK,CAAC,SAAS,EAAE,IAAI,IAAI,EAAE,EAAE,KAAK,CAAC;IACvC,IAAI,KAAK,CAAC,UAAU,EAAE,IAAI,IAAI,EAAE,EAAE,KAAK,CAAC,EAAE,cAAc;IACxD,IAAI,KAAK,CACP,YAAY,EACZ,IAAI,SAAS,CAAC,QAAQ,CAAC,WAAW,CAAC,EACnC,KAAK,CACN;IACD,IAAI,KAAK,CACP,YAAY,EACZ,IAAI,SAAS,CAAC,QAAQ,CAAC,WAAW,CAAC,EACnC,KAAK,CACN;IACD,IAAI,KAAK,CAAC,eAAe,EAAE,IAAI,IAAI,EAAE,EAAE,IAAI,CAAC,EAAE,WAAW;CAC1D,CAAC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { config } from "./config/index.js";
|
|
3
|
+
import { connectToDatabase } from "./db/connection.js";
|
|
4
|
+
import { MemoryRepository } from "./db/memory.repository.js";
|
|
5
|
+
import { EmbeddingsService } from "./services/embeddings.service.js";
|
|
6
|
+
import { MemoryService } from "./services/memory.service.js";
|
|
7
|
+
import { startServer } from "./mcp/server.js";
|
|
8
|
+
async function main() {
|
|
9
|
+
// Initialize database
|
|
10
|
+
const db = await connectToDatabase(config.dbPath);
|
|
11
|
+
// Initialize layers
|
|
12
|
+
const repository = new MemoryRepository(db);
|
|
13
|
+
const embeddings = new EmbeddingsService(config.embeddingModel, config.embeddingDimension);
|
|
14
|
+
const memoryService = new MemoryService(repository, embeddings);
|
|
15
|
+
// Start MCP server
|
|
16
|
+
await startServer(memoryService);
|
|
17
|
+
}
|
|
18
|
+
main().catch(console.error);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C,KAAK,UAAU,IAAI;IACjB,sBAAsB;IACtB,MAAM,EAAE,GAAG,MAAM,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAElD,oBAAoB;IACpB,MAAM,UAAU,GAAG,IAAI,gBAAgB,CAAC,EAAE,CAAC,CAAC;IAC5C,MAAM,UAAU,GAAG,IAAI,iBAAiB,CAAC,MAAM,CAAC,cAAc,EAAE,MAAM,CAAC,kBAAkB,CAAC,CAAC;IAC3F,MAAM,aAAa,GAAG,IAAI,aAAa,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IAEhE,mBAAmB;IACnB,MAAM,WAAW,CAAC,aAAa,CAAC,CAAC;AACnC,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
|
2
|
+
import type { MemoryService } from "../services/memory.service.js";
|
|
3
|
+
export declare function handleStoreMemory(args: Record<string, unknown> | undefined, service: MemoryService): Promise<CallToolResult>;
|
|
4
|
+
export declare function handleDeleteMemory(args: Record<string, unknown> | undefined, service: MemoryService): Promise<CallToolResult>;
|
|
5
|
+
export declare function handleSearchMemories(args: Record<string, unknown> | undefined, service: MemoryService): Promise<CallToolResult>;
|
|
6
|
+
export declare function handleGetMemory(args: Record<string, unknown> | undefined, service: MemoryService): Promise<CallToolResult>;
|
|
7
|
+
export declare function handleToolCall(name: string, args: Record<string, unknown> | undefined, service: MemoryService): Promise<CallToolResult>;
|
|
8
|
+
//# sourceMappingURL=handlers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handlers.d.ts","sourceRoot":"","sources":["../../src/mcp/handlers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAEnE,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,EACzC,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,cAAc,CAAC,CAQzB;AAED,wBAAsB,kBAAkB,CACtC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,EACzC,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,cAAc,CAAC,CAczB;AAED,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,EACzC,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,cAAc,CAAC,CAsBzB;AAED,wBAAsB,eAAe,CACnC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,EACzC,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,cAAc,CAAC,CAuBzB;AAED,wBAAsB,cAAc,CAClC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,EACzC,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,cAAc,CAAC,CAgBzB"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
export async function handleStoreMemory(args, service) {
|
|
2
|
+
const content = args?.content;
|
|
3
|
+
const metadata = args?.metadata ?? {};
|
|
4
|
+
const memory = await service.store(content, metadata);
|
|
5
|
+
return {
|
|
6
|
+
content: [{ type: "text", text: `Memory stored with ID: ${memory.id}` }],
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export async function handleDeleteMemory(args, service) {
|
|
10
|
+
const id = args?.id;
|
|
11
|
+
const success = await service.delete(id);
|
|
12
|
+
return {
|
|
13
|
+
content: [
|
|
14
|
+
{
|
|
15
|
+
type: "text",
|
|
16
|
+
text: success
|
|
17
|
+
? `Memory ${id} deleted successfully`
|
|
18
|
+
: `Memory ${id} not found`,
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export async function handleSearchMemories(args, service) {
|
|
24
|
+
const query = args?.query;
|
|
25
|
+
const limit = args?.limit ?? 10;
|
|
26
|
+
const memories = await service.search(query, limit);
|
|
27
|
+
if (memories.length === 0) {
|
|
28
|
+
return {
|
|
29
|
+
content: [{ type: "text", text: "No memories found matching your query." }],
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
const results = memories.map((mem) => {
|
|
33
|
+
let result = `ID: ${mem.id}\nContent: ${mem.content}`;
|
|
34
|
+
if (Object.keys(mem.metadata).length > 0) {
|
|
35
|
+
result += `\nMetadata: ${JSON.stringify(mem.metadata)}`;
|
|
36
|
+
}
|
|
37
|
+
return result;
|
|
38
|
+
});
|
|
39
|
+
return {
|
|
40
|
+
content: [{ type: "text", text: results.join("\n\n---\n\n") }],
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export async function handleGetMemory(args, service) {
|
|
44
|
+
const id = args?.id;
|
|
45
|
+
const memory = await service.get(id);
|
|
46
|
+
if (!memory) {
|
|
47
|
+
return {
|
|
48
|
+
content: [{ type: "text", text: `Memory ${id} not found` }],
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
let result = `ID: ${memory.id}\nContent: ${memory.content}`;
|
|
52
|
+
if (Object.keys(memory.metadata).length > 0) {
|
|
53
|
+
result += `\nMetadata: ${JSON.stringify(memory.metadata)}`;
|
|
54
|
+
}
|
|
55
|
+
result += `\nCreated: ${memory.createdAt.toISOString()}`;
|
|
56
|
+
result += `\nUpdated: ${memory.updatedAt.toISOString()}`;
|
|
57
|
+
if (memory.supersededBy) {
|
|
58
|
+
result += `\nSuperseded by: ${memory.supersededBy}`;
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
content: [{ type: "text", text: result }],
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
export async function handleToolCall(name, args, service) {
|
|
65
|
+
switch (name) {
|
|
66
|
+
case "store_memory":
|
|
67
|
+
return handleStoreMemory(args, service);
|
|
68
|
+
case "delete_memory":
|
|
69
|
+
return handleDeleteMemory(args, service);
|
|
70
|
+
case "search_memories":
|
|
71
|
+
return handleSearchMemories(args, service);
|
|
72
|
+
case "get_memory":
|
|
73
|
+
return handleGetMemory(args, service);
|
|
74
|
+
default:
|
|
75
|
+
return {
|
|
76
|
+
content: [{ type: "text", text: `Unknown tool: ${name}` }],
|
|
77
|
+
isError: true,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=handlers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handlers.js","sourceRoot":"","sources":["../../src/mcp/handlers.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,IAAyC,EACzC,OAAsB;IAEtB,MAAM,OAAO,GAAG,IAAI,EAAE,OAAiB,CAAC;IACxC,MAAM,QAAQ,GAAI,IAAI,EAAE,QAAoC,IAAI,EAAE,CAAC;IACnE,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAEtD,OAAO;QACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,0BAA0B,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC;KACzE,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,IAAyC,EACzC,OAAsB;IAEtB,MAAM,EAAE,GAAG,IAAI,EAAE,EAAY,CAAC;IAC9B,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAEzC,OAAO;QACL,OAAO,EAAE;YACP;gBACE,IAAI,EAAE,MAAM;gBACZ,IAAI,EAAE,OAAO;oBACX,CAAC,CAAC,UAAU,EAAE,uBAAuB;oBACrC,CAAC,CAAC,UAAU,EAAE,YAAY;aAC7B;SACF;KACF,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,IAAyC,EACzC,OAAsB;IAEtB,MAAM,KAAK,GAAG,IAAI,EAAE,KAAe,CAAC;IACpC,MAAM,KAAK,GAAI,IAAI,EAAE,KAAgB,IAAI,EAAE,CAAC;IAC5C,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,MAAM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.js";
|
|
3
|
+
export declare function createServer(memoryService: MemoryService): Server;
|
|
4
|
+
export declare function startServer(memoryService: MemoryService): Promise<void>;
|
|
5
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/mcp/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AASnE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAEnE,wBAAgB,YAAY,CAAC,aAAa,EAAE,aAAa,GAAG,MAAM,CAgBjE;AAED,wBAAsB,WAAW,CAAC,aAAa,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAI7E"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
2
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
3
|
+
import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
4
|
+
import { tools } from "./tools.js";
|
|
5
|
+
import { handleToolCall } from "./handlers.js";
|
|
6
|
+
export function createServer(memoryService) {
|
|
7
|
+
const server = new Server({ name: "vector-memory-mcp", version: "0.2.0" }, { capabilities: { tools: {} } });
|
|
8
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
9
|
+
return { tools };
|
|
10
|
+
});
|
|
11
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
12
|
+
const { name, arguments: args } = request.params;
|
|
13
|
+
return handleToolCall(name, args, memoryService);
|
|
14
|
+
});
|
|
15
|
+
return server;
|
|
16
|
+
}
|
|
17
|
+
export async function startServer(memoryService) {
|
|
18
|
+
const server = createServer(memoryService);
|
|
19
|
+
const transport = new StdioServerTransport();
|
|
20
|
+
await server.connect(transport);
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=server.js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 +1,7 @@
|
|
|
1
|
+
import type { Tool } from "@modelcontextprotocol/sdk/types.js";
|
|
2
|
+
export declare const storeMemoryTool: Tool;
|
|
3
|
+
export declare const deleteMemoryTool: Tool;
|
|
4
|
+
export declare const searchMemoriesTool: Tool;
|
|
5
|
+
export declare const getMemoryTool: Tool;
|
|
6
|
+
export declare const tools: Tool[];
|
|
7
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../src/mcp/tools.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oCAAoC,CAAC;AAE/D,eAAO,MAAM,eAAe,EAAE,IAkB7B,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,IAc9B,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,IAmBhC,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,IAa3B,CAAC;AAEF,eAAO,MAAM,KAAK,EAAE,IAAI,EAKvB,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export const storeMemoryTool = {
|
|
2
|
+
name: "store_memory",
|
|
3
|
+
description: "Store a new memory. Use this to save information for later recall.",
|
|
4
|
+
inputSchema: {
|
|
5
|
+
type: "object",
|
|
6
|
+
properties: {
|
|
7
|
+
content: {
|
|
8
|
+
type: "string",
|
|
9
|
+
description: "The text content to store as a memory",
|
|
10
|
+
},
|
|
11
|
+
metadata: {
|
|
12
|
+
type: "object",
|
|
13
|
+
description: "Optional key-value metadata to attach to the memory",
|
|
14
|
+
additionalProperties: true,
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
required: ["content"],
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
export const deleteMemoryTool = {
|
|
21
|
+
name: "delete_memory",
|
|
22
|
+
description: "Delete a memory by its ID. The memory will be soft-deleted and won't appear in search results.",
|
|
23
|
+
inputSchema: {
|
|
24
|
+
type: "object",
|
|
25
|
+
properties: {
|
|
26
|
+
id: {
|
|
27
|
+
type: "string",
|
|
28
|
+
description: "The ID of the memory to delete",
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
required: ["id"],
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
export const searchMemoriesTool = {
|
|
35
|
+
name: "search_memories",
|
|
36
|
+
description: "Search for memories using semantic similarity. Returns the most relevant memories for the given query.",
|
|
37
|
+
inputSchema: {
|
|
38
|
+
type: "object",
|
|
39
|
+
properties: {
|
|
40
|
+
query: {
|
|
41
|
+
type: "string",
|
|
42
|
+
description: "The search query to find relevant memories",
|
|
43
|
+
},
|
|
44
|
+
limit: {
|
|
45
|
+
type: "integer",
|
|
46
|
+
description: "Maximum number of results to return (default: 10)",
|
|
47
|
+
default: 10,
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
required: ["query"],
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
export const getMemoryTool = {
|
|
54
|
+
name: "get_memory",
|
|
55
|
+
description: "Retrieve a specific memory by its ID.",
|
|
56
|
+
inputSchema: {
|
|
57
|
+
type: "object",
|
|
58
|
+
properties: {
|
|
59
|
+
id: {
|
|
60
|
+
type: "string",
|
|
61
|
+
description: "The ID of the memory to retrieve",
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
required: ["id"],
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
export const tools = [
|
|
68
|
+
storeMemoryTool,
|
|
69
|
+
deleteMemoryTool,
|
|
70
|
+
searchMemoriesTool,
|
|
71
|
+
getMemoryTool,
|
|
72
|
+
];
|
|
73
|
+
//# sourceMappingURL=tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../../src/mcp/tools.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,eAAe,GAAS;IACnC,IAAI,EAAE,cAAc;IACpB,WAAW,EAAE,oEAAoE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CAAC;AAEF,MAAM,CAAC,MAAM,KAAK,GAAW;IAC3B,eAAe;IACf,gBAAgB;IAChB,kBAAkB;IAClB,aAAa;CACd,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare class EmbeddingsService {
|
|
2
|
+
private modelName;
|
|
3
|
+
private extractor;
|
|
4
|
+
private initPromise;
|
|
5
|
+
private _dimension;
|
|
6
|
+
constructor(modelName: string, dimension: number);
|
|
7
|
+
get dimension(): number;
|
|
8
|
+
private init;
|
|
9
|
+
embed(text: string): Promise<number[]>;
|
|
10
|
+
embedBatch(texts: string[]): Promise<number[][]>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=embeddings.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embeddings.service.d.ts","sourceRoot":"","sources":["../../src/services/embeddings.service.ts"],"names":[],"mappings":"AAEA,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,SAAS,CAA0C;IAC3D,OAAO,CAAC,WAAW,CAA8B;IACjD,OAAO,CAAC,UAAU,CAAS;gBAEf,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;IAKhD,IAAI,SAAS,IAAI,MAAM,CAEtB;YAEa,IAAI;IAeZ,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAgBtC,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;CAiBvD"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { pipeline } from "@huggingface/transformers";
|
|
2
|
+
export class EmbeddingsService {
|
|
3
|
+
modelName;
|
|
4
|
+
extractor = null;
|
|
5
|
+
initPromise = null;
|
|
6
|
+
_dimension;
|
|
7
|
+
constructor(modelName, dimension) {
|
|
8
|
+
this.modelName = modelName;
|
|
9
|
+
this._dimension = dimension;
|
|
10
|
+
}
|
|
11
|
+
get dimension() {
|
|
12
|
+
return this._dimension;
|
|
13
|
+
}
|
|
14
|
+
async init() {
|
|
15
|
+
if (this.extractor) {
|
|
16
|
+
return; // Already initialized
|
|
17
|
+
}
|
|
18
|
+
if (!this.initPromise) {
|
|
19
|
+
this.initPromise = (async () => {
|
|
20
|
+
this.extractor = await pipeline("feature-extraction", this.modelName, {
|
|
21
|
+
dtype: "fp32",
|
|
22
|
+
});
|
|
23
|
+
})();
|
|
24
|
+
}
|
|
25
|
+
await this.initPromise;
|
|
26
|
+
}
|
|
27
|
+
async embed(text) {
|
|
28
|
+
await this.init();
|
|
29
|
+
if (!this.extractor) {
|
|
30
|
+
throw new Error("Extractor not initialized.");
|
|
31
|
+
}
|
|
32
|
+
const output = await this.extractor(text, {
|
|
33
|
+
pooling: "mean",
|
|
34
|
+
normalize: true,
|
|
35
|
+
});
|
|
36
|
+
// output.tolist() returns number[][] for single input, we want the first element
|
|
37
|
+
const embeddings = output.tolist();
|
|
38
|
+
return embeddings[0];
|
|
39
|
+
}
|
|
40
|
+
async embedBatch(texts) {
|
|
41
|
+
await this.init();
|
|
42
|
+
if (!this.extractor) {
|
|
43
|
+
throw new Error("Extractor not initialized.");
|
|
44
|
+
}
|
|
45
|
+
if (texts.length === 0) {
|
|
46
|
+
return [];
|
|
47
|
+
}
|
|
48
|
+
const output = await this.extractor(texts, {
|
|
49
|
+
pooling: "mean",
|
|
50
|
+
normalize: true,
|
|
51
|
+
});
|
|
52
|
+
return output.tolist();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=embeddings.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embeddings.service.js","sourceRoot":"","sources":["../../src/services/embeddings.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAkC,MAAM,2BAA2B,CAAC;AAErF,MAAM,OAAO,iBAAiB;IACpB,SAAS,CAAS;IAClB,SAAS,GAAqC,IAA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AAS,EAAE,CAAC;YACpB,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;QAChD,CAAC;QAED,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACvB,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE;YACzC,OAAO,EAAE,MAAM;YACf,SAAS,EAAE,IAAI;SAChB,CAAC,CAAC;QAEH,OAAO,MAAM,CAAC,MAAM,EAAgB,CAAC;IACvC,CAAC;CACF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Memory } from "../types/memory.js";
|
|
2
|
+
import type { MemoryRepository } from "../db/memory.repository.js";
|
|
3
|
+
import type { EmbeddingsService } from "./embeddings.service.js";
|
|
4
|
+
export declare class MemoryService {
|
|
5
|
+
private repository;
|
|
6
|
+
private embeddings;
|
|
7
|
+
constructor(repository: MemoryRepository, embeddings: EmbeddingsService);
|
|
8
|
+
store(content: string, metadata?: Record<string, unknown>): Promise<Memory>;
|
|
9
|
+
get(id: string): Promise<Memory | null>;
|
|
10
|
+
delete(id: string): Promise<boolean>;
|
|
11
|
+
search(query: string, limit?: number): Promise<Memory[]>;
|
|
12
|
+
private followSupersessionChain;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=memory.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.service.d.ts","sourceRoot":"","sources":["../../src/services/memory.service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAEjD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAEjE,qBAAa,aAAa;IAEtB,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,UAAU;gBADV,UAAU,EAAE,gBAAgB,EAC5B,UAAU,EAAE,iBAAiB;IAGjC,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAmB/E,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAIvC,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAIpC,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,GAAE,MAAW,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;YAqCpD,uBAAuB;CAyBtC"}
|