mem0ai 2.1.9 → 2.1.10
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/dist/oss/index.d.mts +43 -1
- package/dist/oss/index.d.ts +43 -1
- package/dist/oss/index.js +277 -62
- package/dist/oss/index.js.map +1 -1
- package/dist/oss/index.mjs +276 -62
- package/dist/oss/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/oss/index.d.mts
CHANGED
|
@@ -21,6 +21,15 @@ interface VectorStoreConfig {
|
|
|
21
21
|
dimension?: number;
|
|
22
22
|
[key: string]: any;
|
|
23
23
|
}
|
|
24
|
+
interface HistoryStoreConfig {
|
|
25
|
+
provider: string;
|
|
26
|
+
config: {
|
|
27
|
+
historyDbPath?: string;
|
|
28
|
+
supabaseUrl?: string;
|
|
29
|
+
supabaseKey?: string;
|
|
30
|
+
tableName?: string;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
24
33
|
interface LLMConfig {
|
|
25
34
|
provider?: string;
|
|
26
35
|
config?: Record<string, any>;
|
|
@@ -52,6 +61,8 @@ interface MemoryConfig {
|
|
|
52
61
|
provider: string;
|
|
53
62
|
config: LLMConfig;
|
|
54
63
|
};
|
|
64
|
+
historyStore?: HistoryStoreConfig;
|
|
65
|
+
disableHistory?: boolean;
|
|
55
66
|
historyDbPath?: string;
|
|
56
67
|
customPrompt?: string;
|
|
57
68
|
graphStore?: GraphStoreConfig;
|
|
@@ -216,6 +227,17 @@ declare const MemoryConfigSchema: z.ZodObject<{
|
|
|
216
227
|
} | undefined;
|
|
217
228
|
customPrompt?: string | undefined;
|
|
218
229
|
}>>;
|
|
230
|
+
historyStore: z.ZodOptional<z.ZodObject<{
|
|
231
|
+
provider: z.ZodString;
|
|
232
|
+
config: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
233
|
+
}, "strip", z.ZodTypeAny, {
|
|
234
|
+
provider: string;
|
|
235
|
+
config: Record<string, any>;
|
|
236
|
+
}, {
|
|
237
|
+
provider: string;
|
|
238
|
+
config: Record<string, any>;
|
|
239
|
+
}>>;
|
|
240
|
+
disableHistory: z.ZodOptional<z.ZodBoolean>;
|
|
219
241
|
}, "strip", z.ZodTypeAny, {
|
|
220
242
|
embedder: {
|
|
221
243
|
provider: string;
|
|
@@ -257,6 +279,11 @@ declare const MemoryConfigSchema: z.ZodObject<{
|
|
|
257
279
|
} | undefined;
|
|
258
280
|
customPrompt?: string | undefined;
|
|
259
281
|
} | undefined;
|
|
282
|
+
historyStore?: {
|
|
283
|
+
provider: string;
|
|
284
|
+
config: Record<string, any>;
|
|
285
|
+
} | undefined;
|
|
286
|
+
disableHistory?: boolean | undefined;
|
|
260
287
|
}, {
|
|
261
288
|
embedder: {
|
|
262
289
|
provider: string;
|
|
@@ -298,6 +325,11 @@ declare const MemoryConfigSchema: z.ZodObject<{
|
|
|
298
325
|
} | undefined;
|
|
299
326
|
customPrompt?: string | undefined;
|
|
300
327
|
} | undefined;
|
|
328
|
+
historyStore?: {
|
|
329
|
+
provider: string;
|
|
330
|
+
config: Record<string, any>;
|
|
331
|
+
} | undefined;
|
|
332
|
+
disableHistory?: boolean | undefined;
|
|
301
333
|
}>;
|
|
302
334
|
|
|
303
335
|
interface Entity {
|
|
@@ -528,6 +560,13 @@ declare class RedisDB implements VectorStore {
|
|
|
528
560
|
close(): Promise<void>;
|
|
529
561
|
}
|
|
530
562
|
|
|
563
|
+
interface HistoryManager {
|
|
564
|
+
addHistory(memoryId: string, previousValue: string | null, newValue: string | null, action: string, createdAt?: string, updatedAt?: string, isDeleted?: number): Promise<void>;
|
|
565
|
+
getHistory(memoryId: string): Promise<any[]>;
|
|
566
|
+
reset(): Promise<void>;
|
|
567
|
+
close(): void;
|
|
568
|
+
}
|
|
569
|
+
|
|
531
570
|
declare class EmbedderFactory {
|
|
532
571
|
static create(provider: string, config: EmbeddingConfig): Embedder;
|
|
533
572
|
}
|
|
@@ -537,5 +576,8 @@ declare class LLMFactory {
|
|
|
537
576
|
declare class VectorStoreFactory {
|
|
538
577
|
static create(provider: string, config: VectorStoreConfig): VectorStore;
|
|
539
578
|
}
|
|
579
|
+
declare class HistoryManagerFactory {
|
|
580
|
+
static create(provider: string, config: HistoryStoreConfig): HistoryManager;
|
|
581
|
+
}
|
|
540
582
|
|
|
541
|
-
export { type AddMemoryOptions, AnthropicLLM, type DeleteAllMemoryOptions, type Embedder, EmbedderFactory, type EmbeddingConfig, type Entity, type GetAllMemoryOptions, type GraphStoreConfig, GroqLLM, type LLM, type LLMConfig, LLMFactory, type LLMResponse, Memory, type MemoryConfig, MemoryConfigSchema, type MemoryItem, MemoryVectorStore, type Message, type MultiModalMessages, type Neo4jConfig, OllamaEmbedder, OllamaLLM, OpenAIEmbedder, OpenAILLM, OpenAIStructuredLLM, Qdrant, RedisDB, type SearchFilters, type SearchMemoryOptions, type SearchResult, type VectorStore, type VectorStoreConfig, VectorStoreFactory, type VectorStoreResult };
|
|
583
|
+
export { type AddMemoryOptions, AnthropicLLM, type DeleteAllMemoryOptions, type Embedder, EmbedderFactory, type EmbeddingConfig, type Entity, type GetAllMemoryOptions, type GraphStoreConfig, GroqLLM, HistoryManagerFactory, type HistoryStoreConfig, type LLM, type LLMConfig, LLMFactory, type LLMResponse, Memory, type MemoryConfig, MemoryConfigSchema, type MemoryItem, MemoryVectorStore, type Message, type MultiModalMessages, type Neo4jConfig, OllamaEmbedder, OllamaLLM, OpenAIEmbedder, OpenAILLM, OpenAIStructuredLLM, Qdrant, RedisDB, type SearchFilters, type SearchMemoryOptions, type SearchResult, type VectorStore, type VectorStoreConfig, VectorStoreFactory, type VectorStoreResult };
|
package/dist/oss/index.d.ts
CHANGED
|
@@ -21,6 +21,15 @@ interface VectorStoreConfig {
|
|
|
21
21
|
dimension?: number;
|
|
22
22
|
[key: string]: any;
|
|
23
23
|
}
|
|
24
|
+
interface HistoryStoreConfig {
|
|
25
|
+
provider: string;
|
|
26
|
+
config: {
|
|
27
|
+
historyDbPath?: string;
|
|
28
|
+
supabaseUrl?: string;
|
|
29
|
+
supabaseKey?: string;
|
|
30
|
+
tableName?: string;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
24
33
|
interface LLMConfig {
|
|
25
34
|
provider?: string;
|
|
26
35
|
config?: Record<string, any>;
|
|
@@ -52,6 +61,8 @@ interface MemoryConfig {
|
|
|
52
61
|
provider: string;
|
|
53
62
|
config: LLMConfig;
|
|
54
63
|
};
|
|
64
|
+
historyStore?: HistoryStoreConfig;
|
|
65
|
+
disableHistory?: boolean;
|
|
55
66
|
historyDbPath?: string;
|
|
56
67
|
customPrompt?: string;
|
|
57
68
|
graphStore?: GraphStoreConfig;
|
|
@@ -216,6 +227,17 @@ declare const MemoryConfigSchema: z.ZodObject<{
|
|
|
216
227
|
} | undefined;
|
|
217
228
|
customPrompt?: string | undefined;
|
|
218
229
|
}>>;
|
|
230
|
+
historyStore: z.ZodOptional<z.ZodObject<{
|
|
231
|
+
provider: z.ZodString;
|
|
232
|
+
config: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
233
|
+
}, "strip", z.ZodTypeAny, {
|
|
234
|
+
provider: string;
|
|
235
|
+
config: Record<string, any>;
|
|
236
|
+
}, {
|
|
237
|
+
provider: string;
|
|
238
|
+
config: Record<string, any>;
|
|
239
|
+
}>>;
|
|
240
|
+
disableHistory: z.ZodOptional<z.ZodBoolean>;
|
|
219
241
|
}, "strip", z.ZodTypeAny, {
|
|
220
242
|
embedder: {
|
|
221
243
|
provider: string;
|
|
@@ -257,6 +279,11 @@ declare const MemoryConfigSchema: z.ZodObject<{
|
|
|
257
279
|
} | undefined;
|
|
258
280
|
customPrompt?: string | undefined;
|
|
259
281
|
} | undefined;
|
|
282
|
+
historyStore?: {
|
|
283
|
+
provider: string;
|
|
284
|
+
config: Record<string, any>;
|
|
285
|
+
} | undefined;
|
|
286
|
+
disableHistory?: boolean | undefined;
|
|
260
287
|
}, {
|
|
261
288
|
embedder: {
|
|
262
289
|
provider: string;
|
|
@@ -298,6 +325,11 @@ declare const MemoryConfigSchema: z.ZodObject<{
|
|
|
298
325
|
} | undefined;
|
|
299
326
|
customPrompt?: string | undefined;
|
|
300
327
|
} | undefined;
|
|
328
|
+
historyStore?: {
|
|
329
|
+
provider: string;
|
|
330
|
+
config: Record<string, any>;
|
|
331
|
+
} | undefined;
|
|
332
|
+
disableHistory?: boolean | undefined;
|
|
301
333
|
}>;
|
|
302
334
|
|
|
303
335
|
interface Entity {
|
|
@@ -528,6 +560,13 @@ declare class RedisDB implements VectorStore {
|
|
|
528
560
|
close(): Promise<void>;
|
|
529
561
|
}
|
|
530
562
|
|
|
563
|
+
interface HistoryManager {
|
|
564
|
+
addHistory(memoryId: string, previousValue: string | null, newValue: string | null, action: string, createdAt?: string, updatedAt?: string, isDeleted?: number): Promise<void>;
|
|
565
|
+
getHistory(memoryId: string): Promise<any[]>;
|
|
566
|
+
reset(): Promise<void>;
|
|
567
|
+
close(): void;
|
|
568
|
+
}
|
|
569
|
+
|
|
531
570
|
declare class EmbedderFactory {
|
|
532
571
|
static create(provider: string, config: EmbeddingConfig): Embedder;
|
|
533
572
|
}
|
|
@@ -537,5 +576,8 @@ declare class LLMFactory {
|
|
|
537
576
|
declare class VectorStoreFactory {
|
|
538
577
|
static create(provider: string, config: VectorStoreConfig): VectorStore;
|
|
539
578
|
}
|
|
579
|
+
declare class HistoryManagerFactory {
|
|
580
|
+
static create(provider: string, config: HistoryStoreConfig): HistoryManager;
|
|
581
|
+
}
|
|
540
582
|
|
|
541
|
-
export { type AddMemoryOptions, AnthropicLLM, type DeleteAllMemoryOptions, type Embedder, EmbedderFactory, type EmbeddingConfig, type Entity, type GetAllMemoryOptions, type GraphStoreConfig, GroqLLM, type LLM, type LLMConfig, LLMFactory, type LLMResponse, Memory, type MemoryConfig, MemoryConfigSchema, type MemoryItem, MemoryVectorStore, type Message, type MultiModalMessages, type Neo4jConfig, OllamaEmbedder, OllamaLLM, OpenAIEmbedder, OpenAILLM, OpenAIStructuredLLM, Qdrant, RedisDB, type SearchFilters, type SearchMemoryOptions, type SearchResult, type VectorStore, type VectorStoreConfig, VectorStoreFactory, type VectorStoreResult };
|
|
583
|
+
export { type AddMemoryOptions, AnthropicLLM, type DeleteAllMemoryOptions, type Embedder, EmbedderFactory, type EmbeddingConfig, type Entity, type GetAllMemoryOptions, type GraphStoreConfig, GroqLLM, HistoryManagerFactory, type HistoryStoreConfig, type LLM, type LLMConfig, LLMFactory, type LLMResponse, Memory, type MemoryConfig, MemoryConfigSchema, type MemoryItem, MemoryVectorStore, type Message, type MultiModalMessages, type Neo4jConfig, OllamaEmbedder, OllamaLLM, OpenAIEmbedder, OpenAILLM, OpenAIStructuredLLM, Qdrant, RedisDB, type SearchFilters, type SearchMemoryOptions, type SearchResult, type VectorStore, type VectorStoreConfig, VectorStoreFactory, type VectorStoreResult };
|
package/dist/oss/index.js
CHANGED
|
@@ -33,6 +33,7 @@ __export(index_exports, {
|
|
|
33
33
|
AnthropicLLM: () => AnthropicLLM,
|
|
34
34
|
EmbedderFactory: () => EmbedderFactory,
|
|
35
35
|
GroqLLM: () => GroqLLM,
|
|
36
|
+
HistoryManagerFactory: () => HistoryManagerFactory,
|
|
36
37
|
LLMFactory: () => LLMFactory,
|
|
37
38
|
Memory: () => Memory,
|
|
38
39
|
MemoryConfigSchema: () => MemoryConfigSchema,
|
|
@@ -49,7 +50,7 @@ __export(index_exports, {
|
|
|
49
50
|
module.exports = __toCommonJS(index_exports);
|
|
50
51
|
|
|
51
52
|
// src/oss/src/memory/index.ts
|
|
52
|
-
var
|
|
53
|
+
var import_uuid3 = require("uuid");
|
|
53
54
|
var import_crypto = require("crypto");
|
|
54
55
|
|
|
55
56
|
// src/oss/src/types/index.ts
|
|
@@ -92,7 +93,12 @@ var MemoryConfigSchema = import_zod.z.object({
|
|
|
92
93
|
config: import_zod.z.record(import_zod.z.string(), import_zod.z.any())
|
|
93
94
|
}).optional(),
|
|
94
95
|
customPrompt: import_zod.z.string().optional()
|
|
95
|
-
}).optional()
|
|
96
|
+
}).optional(),
|
|
97
|
+
historyStore: import_zod.z.object({
|
|
98
|
+
provider: import_zod.z.string(),
|
|
99
|
+
config: import_zod.z.record(import_zod.z.string(), import_zod.z.any())
|
|
100
|
+
}).optional(),
|
|
101
|
+
disableHistory: import_zod.z.boolean().optional()
|
|
96
102
|
});
|
|
97
103
|
|
|
98
104
|
// src/oss/src/embeddings/openai.ts
|
|
@@ -1227,6 +1233,11 @@ var SupabaseDB = class {
|
|
|
1227
1233
|
async initialize() {
|
|
1228
1234
|
try {
|
|
1229
1235
|
const testVector = Array(1536).fill(0);
|
|
1236
|
+
try {
|
|
1237
|
+
await this.client.from(this.tableName).delete().eq("id", "test_vector");
|
|
1238
|
+
} catch (error) {
|
|
1239
|
+
console.warn("No test vector to delete, safe to ignore.");
|
|
1240
|
+
}
|
|
1230
1241
|
const { error: testError } = await this.client.from(this.tableName).insert({
|
|
1231
1242
|
id: "test_vector",
|
|
1232
1243
|
[this.embeddingColumnName]: testVector,
|
|
@@ -1239,6 +1250,50 @@ var SupabaseDB = class {
|
|
|
1239
1250
|
1. The vector extension is enabled
|
|
1240
1251
|
2. The table "${this.tableName}" exists with correct schema
|
|
1241
1252
|
3. The match_vectors function is created
|
|
1253
|
+
|
|
1254
|
+
RUN THE FOLLOWING SQL IN YOUR SUPABASE SQL EDITOR:
|
|
1255
|
+
|
|
1256
|
+
-- Enable the vector extension
|
|
1257
|
+
create extension if not exists vector;
|
|
1258
|
+
|
|
1259
|
+
-- Create the memories table
|
|
1260
|
+
create table if not exists memories (
|
|
1261
|
+
id text primary key,
|
|
1262
|
+
embedding vector(1536),
|
|
1263
|
+
metadata jsonb,
|
|
1264
|
+
created_at timestamp with time zone default timezone('utc', now()),
|
|
1265
|
+
updated_at timestamp with time zone default timezone('utc', now())
|
|
1266
|
+
);
|
|
1267
|
+
|
|
1268
|
+
-- Create the vector similarity search function
|
|
1269
|
+
create or replace function match_vectors(
|
|
1270
|
+
query_embedding vector(1536),
|
|
1271
|
+
match_count int,
|
|
1272
|
+
filter jsonb default '{}'::jsonb
|
|
1273
|
+
)
|
|
1274
|
+
returns table (
|
|
1275
|
+
id text,
|
|
1276
|
+
similarity float,
|
|
1277
|
+
metadata jsonb
|
|
1278
|
+
)
|
|
1279
|
+
language plpgsql
|
|
1280
|
+
as $$
|
|
1281
|
+
begin
|
|
1282
|
+
return query
|
|
1283
|
+
select
|
|
1284
|
+
id,
|
|
1285
|
+
similarity,
|
|
1286
|
+
metadata
|
|
1287
|
+
from memories
|
|
1288
|
+
where case
|
|
1289
|
+
when filter::text = '{}'::text then true
|
|
1290
|
+
else metadata @> filter
|
|
1291
|
+
end
|
|
1292
|
+
order by embedding <=> query_embedding
|
|
1293
|
+
limit match_count;
|
|
1294
|
+
end;
|
|
1295
|
+
$$;
|
|
1296
|
+
|
|
1242
1297
|
See the SQL migration instructions in the code comments.`
|
|
1243
1298
|
);
|
|
1244
1299
|
}
|
|
@@ -1358,6 +1413,173 @@ See the SQL migration instructions in the code comments.`
|
|
|
1358
1413
|
}
|
|
1359
1414
|
};
|
|
1360
1415
|
|
|
1416
|
+
// src/oss/src/storage/SQLiteManager.ts
|
|
1417
|
+
var import_sqlite32 = __toESM(require("sqlite3"));
|
|
1418
|
+
var SQLiteManager = class {
|
|
1419
|
+
constructor(dbPath) {
|
|
1420
|
+
this.db = new import_sqlite32.default.Database(dbPath);
|
|
1421
|
+
this.init().catch(console.error);
|
|
1422
|
+
}
|
|
1423
|
+
async init() {
|
|
1424
|
+
await this.run(`
|
|
1425
|
+
CREATE TABLE IF NOT EXISTS memory_history (
|
|
1426
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
1427
|
+
memory_id TEXT NOT NULL,
|
|
1428
|
+
previous_value TEXT,
|
|
1429
|
+
new_value TEXT,
|
|
1430
|
+
action TEXT NOT NULL,
|
|
1431
|
+
created_at TEXT,
|
|
1432
|
+
updated_at TEXT,
|
|
1433
|
+
is_deleted INTEGER DEFAULT 0
|
|
1434
|
+
)
|
|
1435
|
+
`);
|
|
1436
|
+
}
|
|
1437
|
+
async run(sql, params = []) {
|
|
1438
|
+
return new Promise((resolve, reject) => {
|
|
1439
|
+
this.db.run(sql, params, (err) => {
|
|
1440
|
+
if (err) reject(err);
|
|
1441
|
+
else resolve();
|
|
1442
|
+
});
|
|
1443
|
+
});
|
|
1444
|
+
}
|
|
1445
|
+
async all(sql, params = []) {
|
|
1446
|
+
return new Promise((resolve, reject) => {
|
|
1447
|
+
this.db.all(sql, params, (err, rows) => {
|
|
1448
|
+
if (err) reject(err);
|
|
1449
|
+
else resolve(rows);
|
|
1450
|
+
});
|
|
1451
|
+
});
|
|
1452
|
+
}
|
|
1453
|
+
async addHistory(memoryId, previousValue, newValue, action, createdAt, updatedAt, isDeleted = 0) {
|
|
1454
|
+
await this.run(
|
|
1455
|
+
`INSERT INTO memory_history
|
|
1456
|
+
(memory_id, previous_value, new_value, action, created_at, updated_at, is_deleted)
|
|
1457
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)`,
|
|
1458
|
+
[
|
|
1459
|
+
memoryId,
|
|
1460
|
+
previousValue,
|
|
1461
|
+
newValue,
|
|
1462
|
+
action,
|
|
1463
|
+
createdAt,
|
|
1464
|
+
updatedAt,
|
|
1465
|
+
isDeleted
|
|
1466
|
+
]
|
|
1467
|
+
);
|
|
1468
|
+
}
|
|
1469
|
+
async getHistory(memoryId) {
|
|
1470
|
+
return this.all(
|
|
1471
|
+
"SELECT * FROM memory_history WHERE memory_id = ? ORDER BY id DESC",
|
|
1472
|
+
[memoryId]
|
|
1473
|
+
);
|
|
1474
|
+
}
|
|
1475
|
+
async reset() {
|
|
1476
|
+
await this.run("DROP TABLE IF EXISTS memory_history");
|
|
1477
|
+
await this.init();
|
|
1478
|
+
}
|
|
1479
|
+
close() {
|
|
1480
|
+
this.db.close();
|
|
1481
|
+
}
|
|
1482
|
+
};
|
|
1483
|
+
|
|
1484
|
+
// src/oss/src/storage/MemoryHistoryManager.ts
|
|
1485
|
+
var import_uuid = require("uuid");
|
|
1486
|
+
var MemoryHistoryManager = class {
|
|
1487
|
+
constructor() {
|
|
1488
|
+
this.memoryStore = /* @__PURE__ */ new Map();
|
|
1489
|
+
}
|
|
1490
|
+
async addHistory(memoryId, previousValue, newValue, action, createdAt, updatedAt, isDeleted = 0) {
|
|
1491
|
+
const historyEntry = {
|
|
1492
|
+
id: (0, import_uuid.v4)(),
|
|
1493
|
+
memory_id: memoryId,
|
|
1494
|
+
previous_value: previousValue,
|
|
1495
|
+
new_value: newValue,
|
|
1496
|
+
action,
|
|
1497
|
+
created_at: createdAt || (/* @__PURE__ */ new Date()).toISOString(),
|
|
1498
|
+
updated_at: updatedAt || null,
|
|
1499
|
+
is_deleted: isDeleted
|
|
1500
|
+
};
|
|
1501
|
+
this.memoryStore.set(historyEntry.id, historyEntry);
|
|
1502
|
+
}
|
|
1503
|
+
async getHistory(memoryId) {
|
|
1504
|
+
return Array.from(this.memoryStore.values()).filter((entry) => entry.memory_id === memoryId).sort(
|
|
1505
|
+
(a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime()
|
|
1506
|
+
).slice(0, 100);
|
|
1507
|
+
}
|
|
1508
|
+
async reset() {
|
|
1509
|
+
this.memoryStore.clear();
|
|
1510
|
+
}
|
|
1511
|
+
close() {
|
|
1512
|
+
return;
|
|
1513
|
+
}
|
|
1514
|
+
};
|
|
1515
|
+
|
|
1516
|
+
// src/oss/src/storage/SupabaseHistoryManager.ts
|
|
1517
|
+
var import_supabase_js2 = require("@supabase/supabase-js");
|
|
1518
|
+
var import_uuid2 = require("uuid");
|
|
1519
|
+
var SupabaseHistoryManager = class {
|
|
1520
|
+
constructor(config) {
|
|
1521
|
+
this.tableName = config.tableName || "memory_history";
|
|
1522
|
+
this.supabase = (0, import_supabase_js2.createClient)(config.supabaseUrl, config.supabaseKey);
|
|
1523
|
+
this.initializeSupabase().catch(console.error);
|
|
1524
|
+
}
|
|
1525
|
+
async initializeSupabase() {
|
|
1526
|
+
const { error } = await this.supabase.from(this.tableName).select("id").limit(1);
|
|
1527
|
+
if (error) {
|
|
1528
|
+
console.error(
|
|
1529
|
+
"Error: Table does not exist. Please run this SQL in your Supabase SQL Editor:"
|
|
1530
|
+
);
|
|
1531
|
+
console.error(`
|
|
1532
|
+
create table ${this.tableName} (
|
|
1533
|
+
id text primary key,
|
|
1534
|
+
memory_id text not null,
|
|
1535
|
+
previous_value text,
|
|
1536
|
+
new_value text,
|
|
1537
|
+
action text not null,
|
|
1538
|
+
created_at timestamp with time zone default timezone('utc', now()),
|
|
1539
|
+
updated_at timestamp with time zone,
|
|
1540
|
+
is_deleted integer default 0
|
|
1541
|
+
);
|
|
1542
|
+
`);
|
|
1543
|
+
throw error;
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
async addHistory(memoryId, previousValue, newValue, action, createdAt, updatedAt, isDeleted = 0) {
|
|
1547
|
+
const historyEntry = {
|
|
1548
|
+
id: (0, import_uuid2.v4)(),
|
|
1549
|
+
memory_id: memoryId,
|
|
1550
|
+
previous_value: previousValue,
|
|
1551
|
+
new_value: newValue,
|
|
1552
|
+
action,
|
|
1553
|
+
created_at: createdAt || (/* @__PURE__ */ new Date()).toISOString(),
|
|
1554
|
+
updated_at: updatedAt || null,
|
|
1555
|
+
is_deleted: isDeleted
|
|
1556
|
+
};
|
|
1557
|
+
const { error } = await this.supabase.from(this.tableName).insert(historyEntry);
|
|
1558
|
+
if (error) {
|
|
1559
|
+
console.error("Error adding history to Supabase:", error);
|
|
1560
|
+
throw error;
|
|
1561
|
+
}
|
|
1562
|
+
}
|
|
1563
|
+
async getHistory(memoryId) {
|
|
1564
|
+
const { data, error } = await this.supabase.from(this.tableName).select("*").eq("memory_id", memoryId).order("created_at", { ascending: false }).limit(100);
|
|
1565
|
+
if (error) {
|
|
1566
|
+
console.error("Error getting history from Supabase:", error);
|
|
1567
|
+
throw error;
|
|
1568
|
+
}
|
|
1569
|
+
return data || [];
|
|
1570
|
+
}
|
|
1571
|
+
async reset() {
|
|
1572
|
+
const { error } = await this.supabase.from(this.tableName).delete().neq("id", "");
|
|
1573
|
+
if (error) {
|
|
1574
|
+
console.error("Error resetting Supabase history:", error);
|
|
1575
|
+
throw error;
|
|
1576
|
+
}
|
|
1577
|
+
}
|
|
1578
|
+
close() {
|
|
1579
|
+
return;
|
|
1580
|
+
}
|
|
1581
|
+
};
|
|
1582
|
+
|
|
1361
1583
|
// src/oss/src/utils/factory.ts
|
|
1362
1584
|
var EmbedderFactory = class {
|
|
1363
1585
|
static create(provider, config) {
|
|
@@ -1408,6 +1630,24 @@ var VectorStoreFactory = class {
|
|
|
1408
1630
|
}
|
|
1409
1631
|
}
|
|
1410
1632
|
};
|
|
1633
|
+
var HistoryManagerFactory = class {
|
|
1634
|
+
static create(provider, config) {
|
|
1635
|
+
switch (provider.toLowerCase()) {
|
|
1636
|
+
case "sqlite":
|
|
1637
|
+
return new SQLiteManager(config.config.historyDbPath || ":memory:");
|
|
1638
|
+
case "supabase":
|
|
1639
|
+
return new SupabaseHistoryManager({
|
|
1640
|
+
supabaseUrl: config.config.supabaseUrl || "",
|
|
1641
|
+
supabaseKey: config.config.supabaseKey || "",
|
|
1642
|
+
tableName: config.config.tableName || "memory_history"
|
|
1643
|
+
});
|
|
1644
|
+
case "memory":
|
|
1645
|
+
return new MemoryHistoryManager();
|
|
1646
|
+
default:
|
|
1647
|
+
throw new Error(`Unsupported history store provider: ${provider}`);
|
|
1648
|
+
}
|
|
1649
|
+
}
|
|
1650
|
+
};
|
|
1411
1651
|
|
|
1412
1652
|
// src/oss/src/prompts/index.ts
|
|
1413
1653
|
function getFactRetrievalMessages(parsedMessages) {
|
|
@@ -1640,76 +1880,27 @@ function removeCodeBlocks(text) {
|
|
|
1640
1880
|
return text.replace(/```[^`]*```/g, "");
|
|
1641
1881
|
}
|
|
1642
1882
|
|
|
1643
|
-
// src/oss/src/storage/
|
|
1644
|
-
var
|
|
1645
|
-
|
|
1646
|
-
constructor(dbPath) {
|
|
1647
|
-
this.db = new import_sqlite32.default.Database(dbPath);
|
|
1648
|
-
this.init().catch(console.error);
|
|
1649
|
-
}
|
|
1650
|
-
async init() {
|
|
1651
|
-
await this.run(`
|
|
1652
|
-
CREATE TABLE IF NOT EXISTS memory_history (
|
|
1653
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
1654
|
-
memory_id TEXT NOT NULL,
|
|
1655
|
-
previous_value TEXT,
|
|
1656
|
-
new_value TEXT,
|
|
1657
|
-
action TEXT NOT NULL,
|
|
1658
|
-
created_at TEXT,
|
|
1659
|
-
updated_at TEXT,
|
|
1660
|
-
is_deleted INTEGER DEFAULT 0
|
|
1661
|
-
)
|
|
1662
|
-
`);
|
|
1663
|
-
}
|
|
1664
|
-
async run(sql, params = []) {
|
|
1665
|
-
return new Promise((resolve, reject) => {
|
|
1666
|
-
this.db.run(sql, params, (err) => {
|
|
1667
|
-
if (err) reject(err);
|
|
1668
|
-
else resolve();
|
|
1669
|
-
});
|
|
1670
|
-
});
|
|
1671
|
-
}
|
|
1672
|
-
async all(sql, params = []) {
|
|
1673
|
-
return new Promise((resolve, reject) => {
|
|
1674
|
-
this.db.all(sql, params, (err, rows) => {
|
|
1675
|
-
if (err) reject(err);
|
|
1676
|
-
else resolve(rows);
|
|
1677
|
-
});
|
|
1678
|
-
});
|
|
1883
|
+
// src/oss/src/storage/DummyHistoryManager.ts
|
|
1884
|
+
var DummyHistoryManager = class {
|
|
1885
|
+
constructor() {
|
|
1679
1886
|
}
|
|
1680
1887
|
async addHistory(memoryId, previousValue, newValue, action, createdAt, updatedAt, isDeleted = 0) {
|
|
1681
|
-
|
|
1682
|
-
`INSERT INTO memory_history
|
|
1683
|
-
(memory_id, previous_value, new_value, action, created_at, updated_at, is_deleted)
|
|
1684
|
-
VALUES (?, ?, ?, ?, ?, ?, ?)`,
|
|
1685
|
-
[
|
|
1686
|
-
memoryId,
|
|
1687
|
-
previousValue,
|
|
1688
|
-
newValue,
|
|
1689
|
-
action,
|
|
1690
|
-
createdAt,
|
|
1691
|
-
updatedAt,
|
|
1692
|
-
isDeleted
|
|
1693
|
-
]
|
|
1694
|
-
);
|
|
1888
|
+
return;
|
|
1695
1889
|
}
|
|
1696
1890
|
async getHistory(memoryId) {
|
|
1697
|
-
return
|
|
1698
|
-
"SELECT * FROM memory_history WHERE memory_id = ? ORDER BY id DESC",
|
|
1699
|
-
[memoryId]
|
|
1700
|
-
);
|
|
1891
|
+
return [];
|
|
1701
1892
|
}
|
|
1702
1893
|
async reset() {
|
|
1703
|
-
|
|
1704
|
-
await this.init();
|
|
1894
|
+
return;
|
|
1705
1895
|
}
|
|
1706
1896
|
close() {
|
|
1707
|
-
|
|
1897
|
+
return;
|
|
1708
1898
|
}
|
|
1709
1899
|
};
|
|
1710
1900
|
|
|
1711
1901
|
// src/oss/src/config/defaults.ts
|
|
1712
1902
|
var DEFAULT_MEMORY_CONFIG = {
|
|
1903
|
+
disableHistory: false,
|
|
1713
1904
|
version: "v1.1",
|
|
1714
1905
|
embedder: {
|
|
1715
1906
|
provider: "openai",
|
|
@@ -1747,7 +1938,12 @@ var DEFAULT_MEMORY_CONFIG = {
|
|
|
1747
1938
|
}
|
|
1748
1939
|
}
|
|
1749
1940
|
},
|
|
1750
|
-
|
|
1941
|
+
historyStore: {
|
|
1942
|
+
provider: "sqlite",
|
|
1943
|
+
config: {
|
|
1944
|
+
historyDbPath: "memory.db"
|
|
1945
|
+
}
|
|
1946
|
+
}
|
|
1751
1947
|
};
|
|
1752
1948
|
|
|
1753
1949
|
// src/oss/src/config/manager.ts
|
|
@@ -1784,6 +1980,11 @@ var ConfigManager = class {
|
|
|
1784
1980
|
...DEFAULT_MEMORY_CONFIG.graphStore,
|
|
1785
1981
|
...userConfig.graphStore
|
|
1786
1982
|
},
|
|
1983
|
+
historyStore: {
|
|
1984
|
+
...DEFAULT_MEMORY_CONFIG.historyStore,
|
|
1985
|
+
...userConfig.historyStore
|
|
1986
|
+
},
|
|
1987
|
+
disableHistory: userConfig.disableHistory || DEFAULT_MEMORY_CONFIG.disableHistory,
|
|
1787
1988
|
enableGraph: userConfig.enableGraph || DEFAULT_MEMORY_CONFIG.enableGraph
|
|
1788
1989
|
};
|
|
1789
1990
|
return MemoryConfigSchema.parse(mergedConfig);
|
|
@@ -2562,7 +2763,20 @@ var Memory = class _Memory {
|
|
|
2562
2763
|
this.config.llm.provider,
|
|
2563
2764
|
this.config.llm.config
|
|
2564
2765
|
);
|
|
2565
|
-
|
|
2766
|
+
if (this.config.disableHistory) {
|
|
2767
|
+
this.db = new DummyHistoryManager();
|
|
2768
|
+
} else {
|
|
2769
|
+
const defaultConfig = {
|
|
2770
|
+
provider: "sqlite",
|
|
2771
|
+
config: {
|
|
2772
|
+
historyDbPath: this.config.historyDbPath || ":memory:"
|
|
2773
|
+
}
|
|
2774
|
+
};
|
|
2775
|
+
this.db = this.config.historyStore && !this.config.disableHistory ? HistoryManagerFactory.create(
|
|
2776
|
+
this.config.historyStore.provider,
|
|
2777
|
+
this.config.historyStore
|
|
2778
|
+
) : HistoryManagerFactory.create("sqlite", defaultConfig);
|
|
2779
|
+
}
|
|
2566
2780
|
this.collectionName = this.config.vectorStore.config.collectionName;
|
|
2567
2781
|
this.apiVersion = this.config.version || "v1.0";
|
|
2568
2782
|
this.enableGraph = this.config.enableGraph || false;
|
|
@@ -2865,7 +3079,7 @@ ${parsedMessages}`] : getFactRetrievalMessages(parsedMessages);
|
|
|
2865
3079
|
return { results };
|
|
2866
3080
|
}
|
|
2867
3081
|
async createMemory(data, existingEmbeddings, metadata) {
|
|
2868
|
-
const memoryId = (0,
|
|
3082
|
+
const memoryId = (0, import_uuid3.v4)();
|
|
2869
3083
|
const embedding = existingEmbeddings[data] || await this.embedder.embed(data);
|
|
2870
3084
|
const memoryMetadata = {
|
|
2871
3085
|
...metadata,
|
|
@@ -2941,6 +3155,7 @@ ${parsedMessages}`] : getFactRetrievalMessages(parsedMessages);
|
|
|
2941
3155
|
AnthropicLLM,
|
|
2942
3156
|
EmbedderFactory,
|
|
2943
3157
|
GroqLLM,
|
|
3158
|
+
HistoryManagerFactory,
|
|
2944
3159
|
LLMFactory,
|
|
2945
3160
|
Memory,
|
|
2946
3161
|
MemoryConfigSchema,
|