@agentskit/memory 0.9.0 → 0.10.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/dist/index.cjs +443 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +142 -1
- package/dist/index.d.ts +142 -1
- package/dist/index.js +430 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2,6 +2,8 @@ import { __require } from './chunk-G5S2A3MJ.js';
|
|
|
2
2
|
export { createInMemoryPersonalization, renderProfileContext } from './chunk-G5S2A3MJ.js';
|
|
3
3
|
import { serializeMessages, deserializeMessages, MemoryError, ErrorCodes, ConfigError } from '@agentskit/core';
|
|
4
4
|
import { tokenize, createPIIRedactor } from '@agentskit/core/security';
|
|
5
|
+
import { readFile, mkdir, writeFile } from 'fs/promises';
|
|
6
|
+
import { dirname } from 'path';
|
|
5
7
|
|
|
6
8
|
function fileChatMemory(path) {
|
|
7
9
|
return {
|
|
@@ -1323,6 +1325,433 @@ function wrapVectorMemoryWithRedaction(inner, options) {
|
|
|
1323
1325
|
};
|
|
1324
1326
|
}
|
|
1325
1327
|
|
|
1326
|
-
|
|
1328
|
+
// src/kv-store-types.ts
|
|
1329
|
+
var isExpired = (entry, ttlSeconds, now) => {
|
|
1330
|
+
if (ttlSeconds === void 0) return false;
|
|
1331
|
+
return now - entry.insertedAt > ttlSeconds * 1e3;
|
|
1332
|
+
};
|
|
1333
|
+
var enforceMaxMessages = (map, maxMessages) => {
|
|
1334
|
+
if (maxMessages === void 0) return;
|
|
1335
|
+
while (map.size > maxMessages) {
|
|
1336
|
+
const oldest = map.keys().next().value;
|
|
1337
|
+
if (oldest === void 0) break;
|
|
1338
|
+
map.delete(oldest);
|
|
1339
|
+
}
|
|
1340
|
+
};
|
|
1341
|
+
|
|
1342
|
+
// src/kv-store-basic.ts
|
|
1343
|
+
var createInMemoryStore = (config) => {
|
|
1344
|
+
const store = /* @__PURE__ */ new Map();
|
|
1345
|
+
const now = () => Date.now();
|
|
1346
|
+
return {
|
|
1347
|
+
id: "in-memory",
|
|
1348
|
+
async get(key) {
|
|
1349
|
+
const entry = store.get(key);
|
|
1350
|
+
if (!entry) return void 0;
|
|
1351
|
+
if (isExpired(entry, config.ttlSeconds, now())) {
|
|
1352
|
+
store.delete(key);
|
|
1353
|
+
return void 0;
|
|
1354
|
+
}
|
|
1355
|
+
return entry.value;
|
|
1356
|
+
},
|
|
1357
|
+
async set(key, value) {
|
|
1358
|
+
store.set(key, { value, insertedAt: now() });
|
|
1359
|
+
enforceMaxMessages(store, config.maxMessages);
|
|
1360
|
+
}
|
|
1361
|
+
};
|
|
1362
|
+
};
|
|
1363
|
+
var createFileStore = (config) => {
|
|
1364
|
+
const path = config.path;
|
|
1365
|
+
let cache;
|
|
1366
|
+
const load = async () => {
|
|
1367
|
+
if (cache) return cache;
|
|
1368
|
+
try {
|
|
1369
|
+
const parsed = JSON.parse(await readFile(path, "utf8"));
|
|
1370
|
+
cache = new Map(Object.entries(parsed));
|
|
1371
|
+
} catch (err) {
|
|
1372
|
+
if (err.code === "ENOENT") cache = /* @__PURE__ */ new Map();
|
|
1373
|
+
else throw err;
|
|
1374
|
+
}
|
|
1375
|
+
return cache;
|
|
1376
|
+
};
|
|
1377
|
+
const persist = async (map) => {
|
|
1378
|
+
await mkdir(dirname(path), { recursive: true });
|
|
1379
|
+
await writeFile(path, JSON.stringify(Object.fromEntries(map), null, 2), { encoding: "utf8", mode: 384 });
|
|
1380
|
+
};
|
|
1381
|
+
return {
|
|
1382
|
+
id: `file:${path}`,
|
|
1383
|
+
async get(key) {
|
|
1384
|
+
const map = await load();
|
|
1385
|
+
const entry = map.get(key);
|
|
1386
|
+
if (!entry) return void 0;
|
|
1387
|
+
if (isExpired(entry, config.ttlSeconds, Date.now())) {
|
|
1388
|
+
map.delete(key);
|
|
1389
|
+
await persist(map);
|
|
1390
|
+
return void 0;
|
|
1391
|
+
}
|
|
1392
|
+
return entry.value;
|
|
1393
|
+
},
|
|
1394
|
+
async set(key, value) {
|
|
1395
|
+
const map = await load();
|
|
1396
|
+
map.set(key, { value, insertedAt: Date.now() });
|
|
1397
|
+
enforceMaxMessages(map, config.maxMessages);
|
|
1398
|
+
await persist(map);
|
|
1399
|
+
}
|
|
1400
|
+
};
|
|
1401
|
+
};
|
|
1402
|
+
var resolveLocalStorage = () => {
|
|
1403
|
+
const maybe = globalThis.localStorage;
|
|
1404
|
+
return maybe && typeof maybe.getItem === "function" && typeof maybe.setItem === "function" ? maybe : void 0;
|
|
1405
|
+
};
|
|
1406
|
+
var defaultLocalStoragePath = () => `${process.cwd()}/.agentskit/memory-localstorage.json`;
|
|
1407
|
+
var createLocalStorageStore = ({
|
|
1408
|
+
config,
|
|
1409
|
+
storage = resolveLocalStorage(),
|
|
1410
|
+
filePath = defaultLocalStoragePath()
|
|
1411
|
+
}) => {
|
|
1412
|
+
const key = config.key;
|
|
1413
|
+
let cache;
|
|
1414
|
+
const mapFromJson = (raw) => raw ? new Map(Object.entries(JSON.parse(raw))) : /* @__PURE__ */ new Map();
|
|
1415
|
+
const loadFromFile = async () => {
|
|
1416
|
+
if (cache) return cache;
|
|
1417
|
+
try {
|
|
1418
|
+
cache = mapFromJson(await readFile(filePath, "utf8"));
|
|
1419
|
+
} catch (err) {
|
|
1420
|
+
if (err.code === "ENOENT") cache = /* @__PURE__ */ new Map();
|
|
1421
|
+
else throw err;
|
|
1422
|
+
}
|
|
1423
|
+
return cache;
|
|
1424
|
+
};
|
|
1425
|
+
const load = async () => storage ? mapFromJson(storage.getItem(key)) : loadFromFile();
|
|
1426
|
+
const persist = async (map) => {
|
|
1427
|
+
const raw = JSON.stringify(Object.fromEntries(map), null, 2);
|
|
1428
|
+
if (storage) {
|
|
1429
|
+
storage.setItem(key, raw);
|
|
1430
|
+
return;
|
|
1431
|
+
}
|
|
1432
|
+
await mkdir(dirname(filePath), { recursive: true });
|
|
1433
|
+
await writeFile(filePath, raw, { encoding: "utf8", mode: 384 });
|
|
1434
|
+
};
|
|
1435
|
+
return {
|
|
1436
|
+
id: storage ? `localstorage:${key}` : `localstorage-file:${filePath}:${key}`,
|
|
1437
|
+
async get(itemKey) {
|
|
1438
|
+
const map = await load();
|
|
1439
|
+
const entry = map.get(itemKey);
|
|
1440
|
+
if (!entry) return void 0;
|
|
1441
|
+
if (isExpired(entry, config.ttlSeconds, Date.now())) {
|
|
1442
|
+
map.delete(itemKey);
|
|
1443
|
+
await persist(map);
|
|
1444
|
+
return void 0;
|
|
1445
|
+
}
|
|
1446
|
+
return entry.value;
|
|
1447
|
+
},
|
|
1448
|
+
async set(itemKey, value) {
|
|
1449
|
+
const map = await load();
|
|
1450
|
+
map.set(itemKey, { value, insertedAt: Date.now() });
|
|
1451
|
+
enforceMaxMessages(map, config.maxMessages);
|
|
1452
|
+
await persist(map);
|
|
1453
|
+
}
|
|
1454
|
+
};
|
|
1455
|
+
};
|
|
1456
|
+
|
|
1457
|
+
// src/kv-store-sqlite.ts
|
|
1458
|
+
var createSqliteStore = ({ config, open }) => {
|
|
1459
|
+
const db = open(config.path);
|
|
1460
|
+
db.exec(
|
|
1461
|
+
`CREATE TABLE IF NOT EXISTS memory (
|
|
1462
|
+
key TEXT PRIMARY KEY,
|
|
1463
|
+
value TEXT NOT NULL,
|
|
1464
|
+
inserted_at INTEGER NOT NULL
|
|
1465
|
+
)`
|
|
1466
|
+
);
|
|
1467
|
+
const getStmt = db.prepare("SELECT value, inserted_at FROM memory WHERE key = ?");
|
|
1468
|
+
const setStmt = db.prepare(
|
|
1469
|
+
"INSERT INTO memory(key, value, inserted_at) VALUES(?, ?, ?) ON CONFLICT(key) DO UPDATE SET value=excluded.value, inserted_at=excluded.inserted_at"
|
|
1470
|
+
);
|
|
1471
|
+
const delStmt = db.prepare("DELETE FROM memory WHERE key = ?");
|
|
1472
|
+
const oldestStmt = db.prepare("SELECT key FROM memory ORDER BY inserted_at ASC LIMIT 1");
|
|
1473
|
+
const countStmt = db.prepare("SELECT COUNT(*) as n FROM memory");
|
|
1474
|
+
const enforce = () => {
|
|
1475
|
+
if (config.maxMessages === void 0) return;
|
|
1476
|
+
const countResult = countStmt.get();
|
|
1477
|
+
let count = countResult ? countResult.n : 0;
|
|
1478
|
+
while (count > config.maxMessages) {
|
|
1479
|
+
const oldest = oldestStmt.get();
|
|
1480
|
+
if (!oldest) break;
|
|
1481
|
+
delStmt.run(oldest.key);
|
|
1482
|
+
count -= 1;
|
|
1483
|
+
}
|
|
1484
|
+
};
|
|
1485
|
+
return {
|
|
1486
|
+
id: `sqlite:${config.path}`,
|
|
1487
|
+
async get(key) {
|
|
1488
|
+
const row = getStmt.get(key);
|
|
1489
|
+
if (!row) return void 0;
|
|
1490
|
+
if (isExpired({ insertedAt: row.inserted_at }, config.ttlSeconds, Date.now())) {
|
|
1491
|
+
delStmt.run(key);
|
|
1492
|
+
return void 0;
|
|
1493
|
+
}
|
|
1494
|
+
return JSON.parse(row.value);
|
|
1495
|
+
},
|
|
1496
|
+
async set(key, value) {
|
|
1497
|
+
setStmt.run(key, JSON.stringify(value), Date.now());
|
|
1498
|
+
enforce();
|
|
1499
|
+
}
|
|
1500
|
+
};
|
|
1501
|
+
};
|
|
1502
|
+
var tryDefaultSqliteOpener = async () => {
|
|
1503
|
+
try {
|
|
1504
|
+
const moduleId = "better-sqlite3";
|
|
1505
|
+
const mod = await import(
|
|
1506
|
+
/* @vite-ignore */
|
|
1507
|
+
moduleId
|
|
1508
|
+
);
|
|
1509
|
+
const Ctor = mod.default;
|
|
1510
|
+
if (typeof Ctor !== "function") return void 0;
|
|
1511
|
+
return (path) => new Ctor(path);
|
|
1512
|
+
} catch {
|
|
1513
|
+
return void 0;
|
|
1514
|
+
}
|
|
1515
|
+
};
|
|
1516
|
+
var createRedisStore = ({ config, client }) => {
|
|
1517
|
+
const prefix = config.prefix;
|
|
1518
|
+
const namespaced = (key) => `${prefix}${key}`;
|
|
1519
|
+
const wrap = async (op, fn) => {
|
|
1520
|
+
try {
|
|
1521
|
+
return await fn();
|
|
1522
|
+
} catch (cause) {
|
|
1523
|
+
throw new MemoryError({
|
|
1524
|
+
code: "AK_MEMORY_REDIS_CONNECTION_FAILED",
|
|
1525
|
+
message: `createRedisStore.${op}: redis command failed \u2014 ${cause instanceof Error ? cause.message : String(cause)}`,
|
|
1526
|
+
cause: cause instanceof Error ? cause : void 0
|
|
1527
|
+
});
|
|
1528
|
+
}
|
|
1529
|
+
};
|
|
1530
|
+
const enforce = async () => {
|
|
1531
|
+
if (config.maxMessages === void 0) return;
|
|
1532
|
+
const keys = await wrap("enforce", () => Promise.resolve(client.keys(`${prefix}*`)));
|
|
1533
|
+
if (keys.length <= config.maxMessages) return;
|
|
1534
|
+
const envelopes = [];
|
|
1535
|
+
for (const fullKey of keys) {
|
|
1536
|
+
const raw = await wrap("enforce", () => Promise.resolve(client.get(fullKey)));
|
|
1537
|
+
if (raw === null) continue;
|
|
1538
|
+
envelopes.push({ key: fullKey, insertedAt: JSON.parse(raw).insertedAt });
|
|
1539
|
+
}
|
|
1540
|
+
envelopes.sort((a, b) => a.insertedAt - b.insertedAt);
|
|
1541
|
+
let excess = envelopes.length - config.maxMessages;
|
|
1542
|
+
for (const entry of envelopes) {
|
|
1543
|
+
if (excess <= 0) break;
|
|
1544
|
+
await wrap("enforce", () => Promise.resolve(client.del(entry.key)));
|
|
1545
|
+
excess -= 1;
|
|
1546
|
+
}
|
|
1547
|
+
};
|
|
1548
|
+
return {
|
|
1549
|
+
id: `redis:${prefix}`,
|
|
1550
|
+
async get(key) {
|
|
1551
|
+
const raw = await wrap("get", () => Promise.resolve(client.get(namespaced(key))));
|
|
1552
|
+
if (raw === null) return void 0;
|
|
1553
|
+
const envelope = JSON.parse(raw);
|
|
1554
|
+
if (isExpired({ value: envelope.value, insertedAt: envelope.insertedAt }, config.ttlSeconds, Date.now())) {
|
|
1555
|
+
await wrap("get", () => Promise.resolve(client.del(namespaced(key))));
|
|
1556
|
+
return void 0;
|
|
1557
|
+
}
|
|
1558
|
+
return envelope.value;
|
|
1559
|
+
},
|
|
1560
|
+
async set(key, value) {
|
|
1561
|
+
const payload = JSON.stringify({ value, insertedAt: Date.now() });
|
|
1562
|
+
const options = config.ttlSeconds === void 0 ? void 0 : { EX: config.ttlSeconds };
|
|
1563
|
+
await wrap("set", () => Promise.resolve(client.set(namespaced(key), payload, options)));
|
|
1564
|
+
await enforce();
|
|
1565
|
+
}
|
|
1566
|
+
};
|
|
1567
|
+
};
|
|
1568
|
+
var adaptIoredis = (io) => ({
|
|
1569
|
+
get: (key) => io.get(key),
|
|
1570
|
+
set: (key, value, options) => options?.EX === void 0 ? io.set(key, value) : io.set(key, value, "EX", options.EX),
|
|
1571
|
+
del: (key) => io.del(key),
|
|
1572
|
+
keys: (pattern) => io.keys(pattern)
|
|
1573
|
+
});
|
|
1574
|
+
var tryDefaultRedisClient = async (url) => {
|
|
1575
|
+
try {
|
|
1576
|
+
const moduleId = "redis";
|
|
1577
|
+
const mod = await import(
|
|
1578
|
+
/* @vite-ignore */
|
|
1579
|
+
moduleId
|
|
1580
|
+
);
|
|
1581
|
+
const createClient = mod.createClient;
|
|
1582
|
+
if (typeof createClient !== "function") return void 0;
|
|
1583
|
+
const client = createClient({ url });
|
|
1584
|
+
try {
|
|
1585
|
+
await client.connect();
|
|
1586
|
+
} catch (cause) {
|
|
1587
|
+
throw new MemoryError({
|
|
1588
|
+
code: "AK_MEMORY_REDIS_CONNECTION_FAILED",
|
|
1589
|
+
message: `tryDefaultRedisClient: redis connect() failed \u2014 ${cause instanceof Error ? cause.message : String(cause)}`,
|
|
1590
|
+
cause: cause instanceof Error ? cause : void 0
|
|
1591
|
+
});
|
|
1592
|
+
}
|
|
1593
|
+
return client;
|
|
1594
|
+
} catch (err) {
|
|
1595
|
+
if (err instanceof MemoryError) throw err;
|
|
1596
|
+
return void 0;
|
|
1597
|
+
}
|
|
1598
|
+
};
|
|
1599
|
+
var createVectorStore = ({
|
|
1600
|
+
config,
|
|
1601
|
+
vectorStore,
|
|
1602
|
+
embedder
|
|
1603
|
+
}) => {
|
|
1604
|
+
const collection = config.collection;
|
|
1605
|
+
const embedOne = async (text) => {
|
|
1606
|
+
const [vec] = await embedder.embed([text]);
|
|
1607
|
+
if (vec === void 0) {
|
|
1608
|
+
throw new MemoryError({
|
|
1609
|
+
code: "AK_MEMORY_VECTOR_EMBEDDER_REQUIRED",
|
|
1610
|
+
message: "createVectorStore: embedder returned no vector for the input text."
|
|
1611
|
+
});
|
|
1612
|
+
}
|
|
1613
|
+
return vec;
|
|
1614
|
+
};
|
|
1615
|
+
return {
|
|
1616
|
+
id: `vector:${config.provider}:${collection}`,
|
|
1617
|
+
async get(key) {
|
|
1618
|
+
const vec = await embedOne(key);
|
|
1619
|
+
const hits = await vectorStore.query(vec, 1, { __collection: collection, __key: key });
|
|
1620
|
+
const hit = hits[0];
|
|
1621
|
+
if (hit === void 0) return void 0;
|
|
1622
|
+
if (hit.metadata["__key"] !== key) return void 0;
|
|
1623
|
+
const insertedAt = hit.metadata["__insertedAt"];
|
|
1624
|
+
if (typeof insertedAt === "number" && isExpired({ insertedAt }, config.ttlSeconds, Date.now())) {
|
|
1625
|
+
return void 0;
|
|
1626
|
+
}
|
|
1627
|
+
return hit.metadata["__value"];
|
|
1628
|
+
},
|
|
1629
|
+
async set(key, value) {
|
|
1630
|
+
const vec = await embedOne(key);
|
|
1631
|
+
await vectorStore.upsert([
|
|
1632
|
+
{
|
|
1633
|
+
chunkId: `${collection}:${key}`,
|
|
1634
|
+
vec,
|
|
1635
|
+
metadata: { __collection: collection, __key: key, __value: value, __insertedAt: Date.now() }
|
|
1636
|
+
}
|
|
1637
|
+
]);
|
|
1638
|
+
},
|
|
1639
|
+
async recall(query, k = 5) {
|
|
1640
|
+
const vec = await embedOne(query);
|
|
1641
|
+
const hits = await vectorStore.query(vec, k, { __collection: collection });
|
|
1642
|
+
const now = Date.now();
|
|
1643
|
+
const results = [];
|
|
1644
|
+
for (const hit of hits) {
|
|
1645
|
+
const insertedAt = hit.metadata["__insertedAt"];
|
|
1646
|
+
if (typeof insertedAt === "number" && isExpired({ insertedAt }, config.ttlSeconds, now)) {
|
|
1647
|
+
continue;
|
|
1648
|
+
}
|
|
1649
|
+
results.push(hit.metadata["__value"]);
|
|
1650
|
+
}
|
|
1651
|
+
return results;
|
|
1652
|
+
}
|
|
1653
|
+
};
|
|
1654
|
+
};
|
|
1655
|
+
var MemoryBackendNotImplementedError = class extends Error {
|
|
1656
|
+
constructor(backend) {
|
|
1657
|
+
super(
|
|
1658
|
+
`Memory backend "${backend}" is not implemented. Supported: "in-memory", "file", "sqlite", "localstorage", "redis", "vector".`
|
|
1659
|
+
);
|
|
1660
|
+
this.code = "MEMORY_BACKEND_NOT_IMPLEMENTED";
|
|
1661
|
+
this.backend = backend;
|
|
1662
|
+
}
|
|
1663
|
+
};
|
|
1664
|
+
var MEMORY_BACKEND_SUPPORT = {
|
|
1665
|
+
"in-memory": "supported",
|
|
1666
|
+
file: "supported",
|
|
1667
|
+
sqlite: "supported",
|
|
1668
|
+
redis: "supported",
|
|
1669
|
+
vector: "supported",
|
|
1670
|
+
localstorage: "supported"
|
|
1671
|
+
};
|
|
1672
|
+
var isMemoryBackendSupported = (backend) => MEMORY_BACKEND_SUPPORT[backend] === "supported";
|
|
1673
|
+
var createKvMemoryFromConfig = ({
|
|
1674
|
+
config,
|
|
1675
|
+
sqlite,
|
|
1676
|
+
localStorageFilePath,
|
|
1677
|
+
redis,
|
|
1678
|
+
vectorStore,
|
|
1679
|
+
embedder
|
|
1680
|
+
}) => {
|
|
1681
|
+
if (config.backend === "in-memory") return createInMemoryStore(config);
|
|
1682
|
+
if (config.backend === "file") return createFileStore(config);
|
|
1683
|
+
if (config.backend === "localstorage") {
|
|
1684
|
+
return createLocalStorageStore({
|
|
1685
|
+
config,
|
|
1686
|
+
...localStorageFilePath ? { filePath: localStorageFilePath } : {}
|
|
1687
|
+
});
|
|
1688
|
+
}
|
|
1689
|
+
if (config.backend === "sqlite") {
|
|
1690
|
+
if (!sqlite) {
|
|
1691
|
+
throw new MemoryError({
|
|
1692
|
+
code: "AK_MEMORY_SQLITE_OPENER_REQUIRED",
|
|
1693
|
+
message: "createKvMemoryFromConfig: sqlite backend requires an `open` function (better-sqlite3), or call createKvMemoryFromConfigAuto which lazy-imports it."
|
|
1694
|
+
});
|
|
1695
|
+
}
|
|
1696
|
+
return createSqliteStore({ config, open: sqlite });
|
|
1697
|
+
}
|
|
1698
|
+
if (config.backend === "redis") {
|
|
1699
|
+
if (!redis) {
|
|
1700
|
+
throw new MemoryError({
|
|
1701
|
+
code: "AK_MEMORY_REDIS_CLIENT_REQUIRED",
|
|
1702
|
+
message: "createKvMemoryFromConfig: redis backend requires a `redis` client, or call createKvMemoryFromConfigAuto which lazy-imports it."
|
|
1703
|
+
});
|
|
1704
|
+
}
|
|
1705
|
+
return createRedisStore({ config, client: redis });
|
|
1706
|
+
}
|
|
1707
|
+
if (config.backend === "vector") {
|
|
1708
|
+
if (!vectorStore) {
|
|
1709
|
+
throw new MemoryError({
|
|
1710
|
+
code: "AK_MEMORY_VECTOR_STORE_REQUIRED",
|
|
1711
|
+
message: "createKvMemoryFromConfig: vector backend requires a `vectorStore`."
|
|
1712
|
+
});
|
|
1713
|
+
}
|
|
1714
|
+
if (!embedder) {
|
|
1715
|
+
throw new MemoryError({
|
|
1716
|
+
code: "AK_MEMORY_VECTOR_EMBEDDER_REQUIRED",
|
|
1717
|
+
message: "createKvMemoryFromConfig: vector backend requires an `embedder`."
|
|
1718
|
+
});
|
|
1719
|
+
}
|
|
1720
|
+
return createVectorStore({ config, vectorStore, embedder });
|
|
1721
|
+
}
|
|
1722
|
+
const exhausted = config;
|
|
1723
|
+
throw new MemoryBackendNotImplementedError(exhausted.backend);
|
|
1724
|
+
};
|
|
1725
|
+
var createKvMemoryFromConfigAuto = async (config) => {
|
|
1726
|
+
if (config.backend === "sqlite") {
|
|
1727
|
+
const sqlite = await tryDefaultSqliteOpener();
|
|
1728
|
+
if (!sqlite) {
|
|
1729
|
+
throw new MemoryError({
|
|
1730
|
+
code: "AK_MEMORY_PEER_MISSING",
|
|
1731
|
+
message: "createKvMemoryFromConfigAuto: sqlite backend needs `better-sqlite3` (pnpm add better-sqlite3)."
|
|
1732
|
+
});
|
|
1733
|
+
}
|
|
1734
|
+
return createKvMemoryFromConfig({ config, sqlite });
|
|
1735
|
+
}
|
|
1736
|
+
if (config.backend === "redis") {
|
|
1737
|
+
const redis = await tryDefaultRedisClient(config.url);
|
|
1738
|
+
if (!redis) {
|
|
1739
|
+
throw new MemoryError({
|
|
1740
|
+
code: "AK_MEMORY_PEER_MISSING",
|
|
1741
|
+
message: "createKvMemoryFromConfigAuto: redis backend needs `redis` (pnpm add redis)."
|
|
1742
|
+
});
|
|
1743
|
+
}
|
|
1744
|
+
return createKvMemoryFromConfig({ config, redis });
|
|
1745
|
+
}
|
|
1746
|
+
if (config.backend === "vector") {
|
|
1747
|
+
throw new MemoryError({
|
|
1748
|
+
code: "AK_MEMORY_VECTOR_STORE_REQUIRED",
|
|
1749
|
+
message: "createKvMemoryFromConfigAuto: vector backend requires an injected vectorStore + embedder."
|
|
1750
|
+
});
|
|
1751
|
+
}
|
|
1752
|
+
return createKvMemoryFromConfig({ config });
|
|
1753
|
+
};
|
|
1754
|
+
|
|
1755
|
+
export { MEMORY_BACKEND_SUPPORT, MemoryBackendNotImplementedError, adaptIoredis, chroma, createEncryptedMemory, createFileStore, createHierarchicalMemory, createInMemoryGraph, createInMemoryStore, createKvMemoryFromConfig, createKvMemoryFromConfigAuto, createLocalStorageStore, createRedisStore, createSqliteStore, createVectorStore, fileChatMemory, fileVectorMemory, forgetSubject, isMemoryBackendSupported, makeForgettable, matchesFilter, milvusVectorStore, mongoAtlasVectorStore, pgvector, pinecone, qdrant, redisChatMemory, redisVectorMemory, sqliteChatMemory, supabaseVectorStore, tryDefaultRedisClient, tryDefaultSqliteOpener, tursoChatMemory, upstashVector, weaviateVectorStore, wrapChatMemoryWithRedaction, wrapVectorMemoryWithRedaction };
|
|
1327
1756
|
//# sourceMappingURL=index.js.map
|
|
1328
1757
|
//# sourceMappingURL=index.js.map
|