@aeriondyseti/vector-memory-mcp 0.2.3 → 0.3.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/README.md +2 -2
- package/package.json +9 -11
- package/src/mcp/handlers.ts +2 -1
- package/src/mcp/tools.ts +12 -1
- package/src/services/embeddings.service.ts +16 -36
- package/src/services/memory.service.ts +7 -2
- package/dist/config/index.d.ts +0 -8
- package/dist/config/index.d.ts.map +0 -1
- package/dist/config/index.js +0 -14
- package/dist/config/index.js.map +0 -1
- package/dist/db/connection.d.ts +0 -3
- package/dist/db/connection.d.ts.map +0 -1
- package/dist/db/connection.js +0 -10
- package/dist/db/connection.js.map +0 -1
- package/dist/db/memory.repository.d.ts +0 -12
- package/dist/db/memory.repository.d.ts.map +0 -1
- package/dist/db/memory.repository.js +0 -79
- package/dist/db/memory.repository.js.map +0 -1
- package/dist/db/schema.d.ts +0 -4
- package/dist/db/schema.d.ts.map +0 -1
- package/dist/db/schema.js +0 -12
- package/dist/db/schema.js.map +0 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -19
- package/dist/index.js.map +0 -1
- package/dist/mcp/handlers.d.ts +0 -8
- package/dist/mcp/handlers.d.ts.map +0 -1
- package/dist/mcp/handlers.js +0 -81
- package/dist/mcp/handlers.js.map +0 -1
- package/dist/mcp/server.d.ts +0 -5
- package/dist/mcp/server.d.ts.map +0 -1
- package/dist/mcp/server.js +0 -22
- package/dist/mcp/server.js.map +0 -1
- package/dist/mcp/tools.d.ts +0 -7
- package/dist/mcp/tools.d.ts.map +0 -1
- package/dist/mcp/tools.js +0 -73
- package/dist/mcp/tools.js.map +0 -1
- package/dist/services/embeddings.service.d.ts +0 -12
- package/dist/services/embeddings.service.d.ts.map +0 -1
- package/dist/services/embeddings.service.js +0 -55
- package/dist/services/embeddings.service.js.map +0 -1
- package/dist/services/memory.service.d.ts +0 -14
- package/dist/services/memory.service.d.ts.map +0 -1
- package/dist/services/memory.service.js +0 -80
- package/dist/services/memory.service.js.map +0 -1
- package/dist/types/memory.d.ts +0 -18
- package/dist/types/memory.d.ts.map +0 -1
- package/dist/types/memory.js +0 -18
- package/dist/types/memory.js.map +0 -1
package/README.md
CHANGED
|
@@ -161,7 +161,7 @@ vector-memory-mcp/
|
|
|
161
161
|
│ ├── config/ # Configuration management
|
|
162
162
|
│ ├── db/ # Database layer (LanceDB)
|
|
163
163
|
│ ├── services/
|
|
164
|
-
│ │ ├── embeddings.service.ts # Embeddings via @
|
|
164
|
+
│ │ ├── embeddings.service.ts # Embeddings via @huggingface/transformers
|
|
165
165
|
│ │ └── memory.service.ts # Core memory operations
|
|
166
166
|
│ └── mcp/
|
|
167
167
|
│ ├── server.ts # MCP server setup
|
|
@@ -285,7 +285,7 @@ bun run build
|
|
|
285
285
|
|
|
286
286
|
### ✅ Phase 1: Foundation (Current)
|
|
287
287
|
- ✅ Core database with LanceDB
|
|
288
|
-
- ✅ Embedding generation with @
|
|
288
|
+
- ✅ Embedding generation with @huggingface/transformers
|
|
289
289
|
- ✅ Basic MCP tools (store, search, get, delete)
|
|
290
290
|
- ✅ TypeScript implementation with Drizzle ORM
|
|
291
291
|
|
package/package.json
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeriondyseti/vector-memory-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "A zero-configuration RAG memory server for MCP clients",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "
|
|
7
|
-
"types": "dist/index.d.ts",
|
|
6
|
+
"main": "src/index.ts",
|
|
8
7
|
"bin": {
|
|
9
|
-
"vector-memory-mcp": "
|
|
8
|
+
"vector-memory-mcp": "src/index.ts"
|
|
10
9
|
},
|
|
11
10
|
"files": [
|
|
12
11
|
"src",
|
|
13
|
-
"dist",
|
|
14
12
|
"README.md",
|
|
15
13
|
"LICENSE"
|
|
16
14
|
],
|
|
@@ -26,13 +24,13 @@
|
|
|
26
24
|
"scripts": {
|
|
27
25
|
"start": "bun run src/index.ts",
|
|
28
26
|
"dev": "bun --watch run src/index.ts",
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"test": "bun test",
|
|
33
|
-
"test:
|
|
27
|
+
"typecheck": "bunx tsc --noEmit",
|
|
28
|
+
"test": "bun test --preload ./tests/preload.ts",
|
|
29
|
+
"test:quick": "bun test",
|
|
30
|
+
"test:coverage": "bun test --preload ./tests/preload.ts --coverage",
|
|
31
|
+
"test:preload": "bun run tests/preload.ts"
|
|
34
32
|
},
|
|
35
|
-
|
|
33
|
+
"keywords": ["mcp", "memory", "rag", "embeddings", "lancedb"],
|
|
36
34
|
"license": "MIT",
|
|
37
35
|
"dependencies": {
|
|
38
36
|
"@lancedb/lancedb": "^0.22.3",
|
package/src/mcp/handlers.ts
CHANGED
|
@@ -6,8 +6,9 @@ export async function handleStoreMemory(
|
|
|
6
6
|
service: MemoryService
|
|
7
7
|
): Promise<CallToolResult> {
|
|
8
8
|
const content = args?.content as string;
|
|
9
|
+
const embeddingText = args?.embedding_text as string | undefined;
|
|
9
10
|
const metadata = (args?.metadata as Record<string, unknown>) ?? {};
|
|
10
|
-
const memory = await service.store(content, metadata);
|
|
11
|
+
const memory = await service.store(content, metadata, embeddingText);
|
|
11
12
|
|
|
12
13
|
return {
|
|
13
14
|
content: [{ type: "text", text: `Memory stored with ID: ${memory.id}` }],
|
package/src/mcp/tools.ts
CHANGED
|
@@ -2,7 +2,11 @@ import type { Tool } from "@modelcontextprotocol/sdk/types.js";
|
|
|
2
2
|
|
|
3
3
|
export const storeMemoryTool: Tool = {
|
|
4
4
|
name: "store_memory",
|
|
5
|
-
description:
|
|
5
|
+
description:
|
|
6
|
+
"Store a new memory. Use this to save information for later recall. " +
|
|
7
|
+
"IMPORTANT: If the content exceeds 1000 characters, you MUST provide an embedding_text " +
|
|
8
|
+
"parameter with a concise summary (under 1000 characters) that captures the key semantic " +
|
|
9
|
+
"meaning for search purposes. The full content will still be stored and returned in search results.",
|
|
6
10
|
inputSchema: {
|
|
7
11
|
type: "object",
|
|
8
12
|
properties: {
|
|
@@ -10,6 +14,13 @@ export const storeMemoryTool: Tool = {
|
|
|
10
14
|
type: "string",
|
|
11
15
|
description: "The text content to store as a memory",
|
|
12
16
|
},
|
|
17
|
+
embedding_text: {
|
|
18
|
+
type: "string",
|
|
19
|
+
description:
|
|
20
|
+
"A concise summary (under 1000 characters) used for generating the search embedding. " +
|
|
21
|
+
"REQUIRED when content exceeds 1000 characters. If not provided, the full content is used for embedding, " +
|
|
22
|
+
"which may be truncated by the embedding model and result in poor search relevance.",
|
|
23
|
+
},
|
|
13
24
|
metadata: {
|
|
14
25
|
type: "object",
|
|
15
26
|
description: "Optional key-value metadata to attach to the memory",
|
|
@@ -3,7 +3,7 @@ import { pipeline, type FeatureExtractionPipeline } from "@huggingface/transform
|
|
|
3
3
|
export class EmbeddingsService {
|
|
4
4
|
private modelName: string;
|
|
5
5
|
private extractor: FeatureExtractionPipeline | null = null;
|
|
6
|
-
private initPromise: Promise<
|
|
6
|
+
private initPromise: Promise<FeatureExtractionPipeline> | null = null;
|
|
7
7
|
private _dimension: number;
|
|
8
8
|
|
|
9
9
|
constructor(modelName: string, dimension: number) {
|
|
@@ -15,52 +15,32 @@ export class EmbeddingsService {
|
|
|
15
15
|
return this._dimension;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
private async
|
|
18
|
+
private async getExtractor(): Promise<FeatureExtractionPipeline> {
|
|
19
19
|
if (this.extractor) {
|
|
20
|
-
return;
|
|
20
|
+
return this.extractor;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
if (!this.initPromise) {
|
|
24
|
-
this.initPromise = (
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
});
|
|
28
|
-
})();
|
|
24
|
+
this.initPromise = pipeline("feature-extraction", this.modelName, {
|
|
25
|
+
quantized: true,
|
|
26
|
+
}) as Promise<FeatureExtractionPipeline>;
|
|
29
27
|
}
|
|
30
|
-
|
|
28
|
+
|
|
29
|
+
this.extractor = await this.initPromise;
|
|
30
|
+
return this.extractor;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
async embed(text: string): Promise<number[]> {
|
|
34
|
-
await this.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const output = await this.extractor(text, {
|
|
40
|
-
pooling: "mean",
|
|
41
|
-
normalize: true,
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
// output.tolist() returns number[][] for single input, we want the first element
|
|
45
|
-
const embeddings = output.tolist() as number[][];
|
|
46
|
-
return embeddings[0];
|
|
34
|
+
const extractor = await this.getExtractor();
|
|
35
|
+
const output = await extractor(text, { pooling: "mean", normalize: true });
|
|
36
|
+
return Array.from(output.data as Float32Array);
|
|
47
37
|
}
|
|
48
38
|
|
|
49
39
|
async embedBatch(texts: string[]): Promise<number[][]> {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
40
|
+
const results: number[][] = [];
|
|
41
|
+
for (const text of texts) {
|
|
42
|
+
results.push(await this.embed(text));
|
|
53
43
|
}
|
|
54
|
-
|
|
55
|
-
if (texts.length === 0) {
|
|
56
|
-
return [];
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const output = await this.extractor(texts, {
|
|
60
|
-
pooling: "mean",
|
|
61
|
-
normalize: true,
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
return output.tolist() as number[][];
|
|
44
|
+
return results;
|
|
65
45
|
}
|
|
66
46
|
}
|
|
@@ -10,10 +10,15 @@ export class MemoryService {
|
|
|
10
10
|
private embeddings: EmbeddingsService
|
|
11
11
|
) {}
|
|
12
12
|
|
|
13
|
-
async store(
|
|
13
|
+
async store(
|
|
14
|
+
content: string,
|
|
15
|
+
metadata: Record<string, unknown> = {},
|
|
16
|
+
embeddingText?: string
|
|
17
|
+
): Promise<Memory> {
|
|
14
18
|
const id = randomUUID();
|
|
15
19
|
const now = new Date();
|
|
16
|
-
const
|
|
20
|
+
const textToEmbed = embeddingText ?? content;
|
|
21
|
+
const embedding = await this.embeddings.embed(textToEmbed);
|
|
17
22
|
|
|
18
23
|
const memory: Memory = {
|
|
19
24
|
id,
|
package/dist/config/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/dist/config/index.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
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
|
package/dist/config/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/dist/db/connection.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/dist/db/connection.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,12 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,79 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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,i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AAE,GAAG;YACrB,MAAM,EAAE;gBACN,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"}
|
package/dist/db/schema.d.ts
DELETED
package/dist/db/schema.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/dist/db/schema.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
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
|
package/dist/db/schema.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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
DELETED
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|
package/dist/index.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
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
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/dist/mcp/handlers.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/dist/mcp/handlers.js
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
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
|
package/dist/mcp/handlers.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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;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AC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,iBAAiB,IAAI,EAAE,EAAE,CAAC;gBAC1D,OAAO,EAAE,IAAI;aACd,CAAC;IACN,CAAC;AACH,CAAC"}
|
package/dist/mcp/server.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
2
|
-
import type { MemoryService } from "../services/memory.service.js";
|
|
3
|
-
export declare function createServer(memoryService: MemoryService): Server;
|
|
4
|
-
export declare function startServer(memoryService: MemoryService): Promise<void>;
|
|
5
|
-
//# sourceMappingURL=server.d.ts.map
|
package/dist/mcp/server.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/dist/mcp/server.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
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.map
|
package/dist/mcp/server.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/mcp/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EACL,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAG/C,MAAM,UAAU,YAAY,CAAC,aAA4B;IACvD,MAAM,MAAM,GAAG,IAAI,MAAM,CACvB,EAAE,IAAI,EAAE,mBAAmB,EAAE,OAAO,EAAE,OAAO,EAAE,EAC/C,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,CAChC,CAAC;IAEF,MAAM,CAAC,iBAAiB,CAAC,sBAAsB,EAAE,KAAK,IAAI,EAAE;QAC1D,OAAO,EAAE,KAAK,EAAE,CAAC;IACnB,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,iBAAiB,CAAC,qBAAqB,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;QAChE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC;QACjD,OAAO,cAAc,CAAC,IAAI,EAAE,IAAI,EAAE,aAAa,CAAC,CAAC;IACnD,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,aAA4B;IAC5D,MAAM,MAAM,GAAG,YAAY,CAAC,aAAa,CAAC,CAAC;IAC3C,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;AAClC,CAAC"}
|
package/dist/mcp/tools.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
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
|
package/dist/mcp/tools.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/dist/mcp/tools.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
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
|
package/dist/mcp/tools.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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;IACjF,WAAW,EAAE;QACX,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,OAAO,EAAE;gBACP,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,uCAAuC;aACrD;YACD,QAAQ,EAAE;gBACR,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,qDAAqD;gBAClE,oBAAoB,EAAE,IAAI;aAC3B;SACF;QACD,QAAQ,EAAE,CAAC,SAAS,CAAC;KACtB;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAS;IACpC,IAAI,EAAE,eAAe;IACrB,WAAW,EACT,gGAAgG;IAClG,WAAW,EAAE;QACX,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,EAAE,EAAE;gBACF,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,gCAAgC;aAC9C;SACF;QACD,QAAQ,EAAE,CAAC,IAAI,CAAC;KACjB;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAS;IACtC,IAAI,EAAE,iBAAiB;IACvB,WAAW,EACT,wGAAwG;IAC1G,WAAW,EAAE;QACX,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,KAAK,EAAE;gBACL,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,4CAA4C;aAC1D;YACD,KAAK,EAAE;gBACL,IAAI,EAAE,SAAS;gBACf,WAAW,EAAE,mDAAmD;gBAChE,OAAO,EAAE,EAAE;aACZ;SACF;QACD,QAAQ,EAAE,CAAC,OAAO,CAAC;KACpB;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAS;IACjC,IAAI,EAAE,YAAY;IAClB,WAAW,EAAE,uCAAuC;IACpD,WAAW,EAAE;QACX,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,EAAE,EAAE;gBACF,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,kCAAkC;aAChD;SACF;QACD,QAAQ,EAAE,CAAC,IAAI,CAAC;KACjB;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,KAAK,GAAW;IAC3B,eAAe;IACf,gBAAgB;IAChB,kBAAkB;IAClB,aAAa;CACd,CAAC"}
|
|
@@ -1,12 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,55 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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,IAAI,CAAC;IACnD,WAAW,GAAyB,IAAI,CAAC;IACzC,UAAU,CAAS;IAE3B,YAAY,SAAiB,EAAE,SAAiB;QAC9C,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;IAC9B,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAEO,KAAK,CAAC,IAAI;QAChB,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACnB,OAAO,CAAC,sBAAsB;QAChC,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;YACtB,IAAI,CAAC,WAAW,GAAG,CAAC,KAAK,IAAI,EAAE;gBAC7B,IAAI,CAAC,SAAS,GAAG,MAAM,QAAQ,CAAC,oBAAoB,EAAE,IAAI,CAAC,SAAS,EAAE;oBACpE,KAAK,EAAE,MAAM;iBACd,CAAC,CAAC;YACL,CAAC,CAAC,EAAE,CAAC;QACP,CAAC;QACD,MAAM,IAAI,CAAC,WAAW,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,IAAY;QACtB,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;QAClB,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YACpB,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;QAChD,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE;YACxC,OAAO,EAAE,MAAM;YACf,SAAS,EAAE,IAAI;SAChB,CAAC,CAAC;QAEH,iFAAiF;QACjF,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAgB,CAAC;QACjD,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC;IACvB,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,KAAe;QAC9B,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;QAClB,IAAI,CAAC,IAAI,CAAC,SAAS,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"}
|
|
@@ -1,14 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from "crypto";
|
|
2
|
-
import { DELETED_TOMBSTONE, isSuperseded } from "../types/memory.js";
|
|
3
|
-
export class MemoryService {
|
|
4
|
-
repository;
|
|
5
|
-
embeddings;
|
|
6
|
-
constructor(repository, embeddings) {
|
|
7
|
-
this.repository = repository;
|
|
8
|
-
this.embeddings = embeddings;
|
|
9
|
-
}
|
|
10
|
-
async store(content, metadata = {}) {
|
|
11
|
-
const id = randomUUID();
|
|
12
|
-
const now = new Date();
|
|
13
|
-
const embedding = await this.embeddings.embed(content);
|
|
14
|
-
const memory = {
|
|
15
|
-
id,
|
|
16
|
-
content,
|
|
17
|
-
embedding,
|
|
18
|
-
metadata,
|
|
19
|
-
createdAt: now,
|
|
20
|
-
updatedAt: now,
|
|
21
|
-
supersededBy: null,
|
|
22
|
-
};
|
|
23
|
-
await this.repository.insert(memory);
|
|
24
|
-
return memory;
|
|
25
|
-
}
|
|
26
|
-
async get(id) {
|
|
27
|
-
return await this.repository.findById(id);
|
|
28
|
-
}
|
|
29
|
-
async delete(id) {
|
|
30
|
-
return await this.repository.markDeleted(id);
|
|
31
|
-
}
|
|
32
|
-
async search(query, limit = 10) {
|
|
33
|
-
const queryEmbedding = await this.embeddings.embed(query);
|
|
34
|
-
const fetchLimit = limit * 3;
|
|
35
|
-
const rows = await this.repository.findSimilar(queryEmbedding, fetchLimit);
|
|
36
|
-
const results = [];
|
|
37
|
-
const seenIds = new Set();
|
|
38
|
-
for (const row of rows) {
|
|
39
|
-
let memory = await this.repository.findById(row.id);
|
|
40
|
-
if (!memory) {
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
if (isSuperseded(memory)) {
|
|
44
|
-
memory = await this.followSupersessionChain(row.id);
|
|
45
|
-
if (!memory) {
|
|
46
|
-
continue;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
if (seenIds.has(memory.id)) {
|
|
50
|
-
continue;
|
|
51
|
-
}
|
|
52
|
-
seenIds.add(memory.id);
|
|
53
|
-
results.push(memory);
|
|
54
|
-
if (results.length >= limit) {
|
|
55
|
-
break;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return results;
|
|
59
|
-
}
|
|
60
|
-
async followSupersessionChain(memoryId) {
|
|
61
|
-
const visited = new Set();
|
|
62
|
-
let currentId = memoryId;
|
|
63
|
-
while (currentId && !visited.has(currentId)) {
|
|
64
|
-
visited.add(currentId);
|
|
65
|
-
const memory = await this.repository.findById(currentId);
|
|
66
|
-
if (!memory) {
|
|
67
|
-
return null;
|
|
68
|
-
}
|
|
69
|
-
if (memory.supersededBy === null) {
|
|
70
|
-
return memory;
|
|
71
|
-
}
|
|
72
|
-
if (memory.supersededBy === DELETED_TOMBSTONE) {
|
|
73
|
-
return null;
|
|
74
|
-
}
|
|
75
|
-
currentId = memory.supersededBy;
|
|
76
|
-
}
|
|
77
|
-
return null;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
//# sourceMappingURL=memory.service.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"memory.service.js","sourceRoot":"","sources":["../../src/services/memory.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEpC,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAIrE,MAAM,OAAO,aAAa;IAEd;IACA;IAFV,YACU,UAA4B,EAC5B,UAA6B;QAD7B,eAAU,GAAV,UAAU,CAAkB;QAC5B,eAAU,GAAV,UAAU,CAAmB;IACpC,CAAC;IAEJ,KAAK,CAAC,KAAK,CAAC,OAAe,EAAE,WAAoC,EAAE;QACjE,MAAM,EAAE,GAAG,UAAU,EAAE,CAAC;QACxB,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAEvD,MAAM,MAAM,GAAW;YACrB,EAAE;YACF,OAAO;YACP,SAAS;YACT,QAAQ;YACR,SAAS,EAAE,GAAG;YACd,SAAS,EAAE,GAAG;YACd,YAAY,EAAE,IAAI;SACnB,CAAC;QAEF,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACrC,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,EAAU;QAClB,OAAO,MAAM,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC,C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CAAC;IACjB,CAAC;IAEO,KAAK,CAAC,uBAAuB,CAAC,QAAgB;QACpD,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;QAClC,IAAI,SAAS,GAAkB,QAAQ,CAAC;QAExC,OAAO,SAAS,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;YAC5C,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;YACvB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;YAEzD,IAAI,CAAC,MAAM,EAAE,CAAC;gBACZ,OAAO,IAAI,CAAC;YACd,CAAC;YAED,IAAI,MAAM,CAAC,YAAY,KAAK,IAAI,EAAE,CAAC;gBACjC,OAAO,MAAM,CAAC;YAChB,CAAC;YAED,IAAI,MAAM,CAAC,YAAY,KAAK,iBAAiB,EAAE,CAAC;gBAC9C,OAAO,IAAI,CAAC;YACd,CAAC;YAED,SAAS,GAAG,MAAM,CAAC,YAAY,CAAC;QAClC,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
|
package/dist/types/memory.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export declare const DELETED_TOMBSTONE = "DELETED";
|
|
2
|
-
export interface Memory {
|
|
3
|
-
id: string;
|
|
4
|
-
content: string;
|
|
5
|
-
embedding: number[];
|
|
6
|
-
metadata: Record<string, unknown>;
|
|
7
|
-
createdAt: Date;
|
|
8
|
-
updatedAt: Date;
|
|
9
|
-
supersededBy: string | null;
|
|
10
|
-
}
|
|
11
|
-
export interface VectorRow {
|
|
12
|
-
id: string;
|
|
13
|
-
distance: number;
|
|
14
|
-
}
|
|
15
|
-
export declare function isDeleted(memory: Memory): boolean;
|
|
16
|
-
export declare function isSuperseded(memory: Memory): boolean;
|
|
17
|
-
export declare function memoryToDict(memory: Memory): Record<string, unknown>;
|
|
18
|
-
//# sourceMappingURL=memory.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../src/types/memory.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,YAAY,CAAC;AAE3C,MAAM,WAAW,MAAM;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,SAAS,EAAE,IAAI,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;IAChB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAED,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAEjD;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAEpD;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CASpE"}
|
package/dist/types/memory.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export const DELETED_TOMBSTONE = "DELETED";
|
|
2
|
-
export function isDeleted(memory) {
|
|
3
|
-
return memory.supersededBy === DELETED_TOMBSTONE;
|
|
4
|
-
}
|
|
5
|
-
export function isSuperseded(memory) {
|
|
6
|
-
return memory.supersededBy !== null;
|
|
7
|
-
}
|
|
8
|
-
export function memoryToDict(memory) {
|
|
9
|
-
return {
|
|
10
|
-
id: memory.id,
|
|
11
|
-
content: memory.content,
|
|
12
|
-
metadata: memory.metadata,
|
|
13
|
-
createdAt: memory.createdAt.toISOString(),
|
|
14
|
-
updatedAt: memory.updatedAt.toISOString(),
|
|
15
|
-
supersededBy: memory.supersededBy,
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
//# sourceMappingURL=memory.js.map
|
package/dist/types/memory.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"memory.js","sourceRoot":"","sources":["../../src/types/memory.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,iBAAiB,GAAG,SAAS,CAAC;AAiB3C,MAAM,UAAU,SAAS,CAAC,MAAc;IACtC,OAAO,MAAM,CAAC,YAAY,KAAK,iBAAiB,CAAC;AACnD,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,MAAc;IACzC,OAAO,MAAM,CAAC,YAAY,KAAK,IAAI,CAAC;AACtC,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,MAAc;IACzC,OAAO;QACL,EAAE,EAAE,MAAM,CAAC,EAAE;QACb,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC,WAAW,EAAE;QACzC,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC,WAAW,EAAE;QACzC,YAAY,EAAE,MAAM,CAAC,YAAY;KAClC,CAAC;AACJ,CAAC"}
|