@anuma/sdk 7.0.4-next.20261015012621 → 7.0.5
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/expo/index.cjs +68 -224
- package/dist/expo/index.d.mts +4 -24
- package/dist/expo/index.d.ts +4 -24
- package/dist/expo/index.mjs +68 -224
- package/dist/memory/context.d.mts +0 -1
- package/dist/memory/context.d.ts +0 -1
- package/dist/react/index.cjs +68 -229
- package/dist/react/index.d.mts +4 -24
- package/dist/react/index.d.ts +4 -24
- package/dist/react/index.mjs +68 -229
- package/dist/server/index.cjs +28 -144
- package/dist/server/index.d.mts +2 -22
- package/dist/server/index.d.ts +2 -22
- package/dist/server/index.mjs +28 -144
- package/package.json +1 -1
package/dist/react/index.mjs
CHANGED
|
@@ -10495,11 +10495,6 @@ function parseTopics(value) {
|
|
|
10495
10495
|
}
|
|
10496
10496
|
|
|
10497
10497
|
// src/lib/db/entities/operations.ts
|
|
10498
|
-
async function assertCanWrite(ctx) {
|
|
10499
|
-
if (ctx.canWrite && !await ctx.canWrite()) {
|
|
10500
|
-
throw new Error("Memory source is no longer eligible");
|
|
10501
|
-
}
|
|
10502
|
-
}
|
|
10503
10498
|
function entityToStored(e) {
|
|
10504
10499
|
return {
|
|
10505
10500
|
uniqueId: e.id,
|
|
@@ -10640,7 +10635,6 @@ async function linkMemoryEntitiesOp(ctx, memoryId, entityInputs, options) {
|
|
|
10640
10635
|
let skipped = false;
|
|
10641
10636
|
let entities = [];
|
|
10642
10637
|
await ctx.database.write(async () => {
|
|
10643
|
-
await assertCanWrite(ctx);
|
|
10644
10638
|
const {
|
|
10645
10639
|
entities: byName,
|
|
10646
10640
|
operations: entityOps,
|
|
@@ -10716,7 +10710,6 @@ async function replaceMemoryEntities(ctx, memoryId, entityInputs, options) {
|
|
|
10716
10710
|
let skipped = false;
|
|
10717
10711
|
let entities = [];
|
|
10718
10712
|
await ctx.database.write(async () => {
|
|
10719
|
-
await assertCanWrite(ctx);
|
|
10720
10713
|
const vaultRow = await findVaultRowInWrite(ctx, memoryId);
|
|
10721
10714
|
if (options.guarded && autoLinkBlocked(vaultRow)) {
|
|
10722
10715
|
skipped = true;
|
|
@@ -10777,7 +10770,6 @@ async function unlinkMemoryEntitiesOp(ctx, memoryIds) {
|
|
|
10777
10770
|
const links = await ctx.memoryEntityCollection.query(Q5.where("memory_id", Q5.oneOf(Array.from(memoryIds)))).fetch();
|
|
10778
10771
|
if (links.length === 0) return;
|
|
10779
10772
|
await ctx.database.write(async () => {
|
|
10780
|
-
await assertCanWrite(ctx);
|
|
10781
10773
|
await ctx.database.batch(...links.map((l) => l.prepareDestroyPermanently()));
|
|
10782
10774
|
});
|
|
10783
10775
|
}
|
|
@@ -10786,7 +10778,6 @@ async function unlinkAllMemoryEntitiesForUserOp(ctx, userId) {
|
|
|
10786
10778
|
const links = await ctx.memoryEntityCollection.query(Q5.where("user_id", userId)).fetch();
|
|
10787
10779
|
if (links.length === 0) return;
|
|
10788
10780
|
await ctx.database.write(async () => {
|
|
10789
|
-
await assertCanWrite(ctx);
|
|
10790
10781
|
await ctx.database.batch(...links.map((l) => l.prepareDestroyPermanently()));
|
|
10791
10782
|
});
|
|
10792
10783
|
}
|
|
@@ -10806,7 +10797,6 @@ async function backfillMemoryEntityUserIdsOp(ctx, vaultMemoryCollection) {
|
|
|
10806
10797
|
}
|
|
10807
10798
|
if (toUpdate.length === 0) return 0;
|
|
10808
10799
|
await ctx.database.write(async () => {
|
|
10809
|
-
await assertCanWrite(ctx);
|
|
10810
10800
|
await ctx.database.batch(
|
|
10811
10801
|
...toUpdate.map(({ link, userId }) => link.prepareUpdate((r) => r._setRaw("user_id", userId)))
|
|
10812
10802
|
);
|
|
@@ -13200,11 +13190,6 @@ function visibilityConditions(requested) {
|
|
|
13200
13190
|
function isKinded(record2) {
|
|
13201
13191
|
return record2.kind !== null && record2.kind !== void 0;
|
|
13202
13192
|
}
|
|
13203
|
-
async function assertCanWrite2(ctx) {
|
|
13204
|
-
if (ctx.canWrite && !await ctx.canWrite()) {
|
|
13205
|
-
throw new Error("Memory source is no longer eligible");
|
|
13206
|
-
}
|
|
13207
|
-
}
|
|
13208
13193
|
function assertValidKindLevel(kind, level) {
|
|
13209
13194
|
const hasKind = kind !== null && kind !== void 0;
|
|
13210
13195
|
if (hasKind && !MEMORY_KINDS.includes(kind)) {
|
|
@@ -13385,7 +13370,8 @@ async function createVaultMemoryOp(ctx, opts) {
|
|
|
13385
13370
|
ctx.embeddedWalletSigner
|
|
13386
13371
|
) : opts.content;
|
|
13387
13372
|
const created = await ctx.database.write(async () => {
|
|
13388
|
-
await
|
|
13373
|
+
if (ctx.canWrite && !await ctx.canWrite())
|
|
13374
|
+
throw new Error("Memory source is no longer eligible");
|
|
13389
13375
|
return ctx.vaultMemoryCollection.create(
|
|
13390
13376
|
(record2) => populateNewVaultMemory(record2, ctx, opts, encryptedContent, encryptedKindValue)
|
|
13391
13377
|
);
|
|
@@ -13404,7 +13390,8 @@ async function createSupersedingMemoryOp(ctx, opts, targetId) {
|
|
|
13404
13390
|
) : opts.content;
|
|
13405
13391
|
let createdRecord = null;
|
|
13406
13392
|
await ctx.database.write(async () => {
|
|
13407
|
-
await
|
|
13393
|
+
if (ctx.canWrite && !await ctx.canWrite())
|
|
13394
|
+
throw new Error("Memory source is no longer eligible");
|
|
13408
13395
|
let target;
|
|
13409
13396
|
try {
|
|
13410
13397
|
target = await ctx.vaultMemoryCollection.find(targetId);
|
|
@@ -13496,7 +13483,8 @@ async function createVaultMemoriesBatchOp(ctx, optionsArray) {
|
|
|
13496
13483
|
})
|
|
13497
13484
|
);
|
|
13498
13485
|
const created = await ctx.database.write(async () => {
|
|
13499
|
-
await
|
|
13486
|
+
if (ctx.canWrite && !await ctx.canWrite())
|
|
13487
|
+
throw new Error("Memory source is no longer eligible");
|
|
13500
13488
|
const prepared = optionsArray.map(
|
|
13501
13489
|
(opts, i) => ctx.vaultMemoryCollection.prepareCreate(
|
|
13502
13490
|
(record2) => populateNewVaultMemory(record2, ctx, opts, encryptedContents[i], encryptedKindValues[i])
|
|
@@ -13801,7 +13789,8 @@ async function updateVaultMemoryOp(ctx, id, opts) {
|
|
|
13801
13789
|
const record2 = probe;
|
|
13802
13790
|
const originalUpdatedAt = record2.updatedAt.getTime();
|
|
13803
13791
|
await ctx.database.write(async () => {
|
|
13804
|
-
await
|
|
13792
|
+
if (ctx.canWrite && !await ctx.canWrite())
|
|
13793
|
+
throw new Error("Memory source is no longer eligible");
|
|
13805
13794
|
if (record2.isDeleted || record2.supersededBy || !isOwnedByCtxUser(ctx, record2) || opts.freeFormOnly && isKinded(record2)) {
|
|
13806
13795
|
stale = true;
|
|
13807
13796
|
return;
|
|
@@ -13912,7 +13901,6 @@ async function setMemoryEntitiesOp(ctx, memoryId, entities) {
|
|
|
13912
13901
|
let stale = false;
|
|
13913
13902
|
const originalUpdatedAt = record2.updatedAt.getTime();
|
|
13914
13903
|
await ctx.database.write(async (writer) => {
|
|
13915
|
-
await assertCanWrite2(ctx);
|
|
13916
13904
|
if (record2.isDeleted || !isOwnedByCtxUser(ctx, record2)) {
|
|
13917
13905
|
stale = true;
|
|
13918
13906
|
return;
|
|
@@ -13954,7 +13942,6 @@ async function clearMemoryTopicsOverrideOp(ctx, memoryId, options) {
|
|
|
13954
13942
|
const originalUpdatedAt = record2.updatedAt.getTime();
|
|
13955
13943
|
let cleared = false;
|
|
13956
13944
|
await ctx.database.write(async () => {
|
|
13957
|
-
await assertCanWrite2(ctx);
|
|
13958
13945
|
if (options?.unlessTopicsRecorded && parseTopics(record2.topics) !== null) return;
|
|
13959
13946
|
cleared = true;
|
|
13960
13947
|
await record2.update((r) => {
|
|
@@ -13978,7 +13965,6 @@ async function setMemoryVisibilityOp(ctx, id, opts) {
|
|
|
13978
13965
|
if (record2.isDeleted || !isOwnedByCtxUser(ctx, record2)) return null;
|
|
13979
13966
|
let stale = false;
|
|
13980
13967
|
await ctx.database.write(async () => {
|
|
13981
|
-
await assertCanWrite2(ctx);
|
|
13982
13968
|
if (record2.isDeleted || !isOwnedByCtxUser(ctx, record2)) {
|
|
13983
13969
|
stale = true;
|
|
13984
13970
|
return;
|
|
@@ -14007,7 +13993,6 @@ async function deleteVaultMemoryOp(ctx, id) {
|
|
|
14007
13993
|
if (record2.isDeleted || !isOwnedByCtxUser(ctx, record2)) return false;
|
|
14008
13994
|
let stale = false;
|
|
14009
13995
|
await ctx.database.write(async () => {
|
|
14010
|
-
await assertCanWrite2(ctx);
|
|
14011
13996
|
if (record2.isDeleted || !isOwnedByCtxUser(ctx, record2)) {
|
|
14012
13997
|
stale = true;
|
|
14013
13998
|
return;
|
|
@@ -14045,7 +14030,8 @@ async function supersedeVaultMemoryOp(ctx, id, supersededById) {
|
|
|
14045
14030
|
}
|
|
14046
14031
|
let stale = false;
|
|
14047
14032
|
await ctx.database.write(async () => {
|
|
14048
|
-
await
|
|
14033
|
+
if (ctx.canWrite && !await ctx.canWrite())
|
|
14034
|
+
throw new Error("Memory source is no longer eligible");
|
|
14049
14035
|
if (record2.isDeleted || record2.supersededBy || !isOwnedByCtxUser(ctx, record2)) {
|
|
14050
14036
|
stale = true;
|
|
14051
14037
|
return;
|
|
@@ -14207,7 +14193,6 @@ async function stampTopicsExtractedAtOp(ctx, memoryIds, extractedAt, version = T
|
|
|
14207
14193
|
for (let i = 0; i < uniqueIds.length; i += CHUNK) {
|
|
14208
14194
|
const chunkIds = uniqueIds.slice(i, i + CHUNK);
|
|
14209
14195
|
await ctx.database.write(async () => {
|
|
14210
|
-
await assertCanWrite2(ctx);
|
|
14211
14196
|
const records = [];
|
|
14212
14197
|
for (const id of chunkIds) {
|
|
14213
14198
|
try {
|
|
@@ -14241,7 +14226,6 @@ async function relinkMemoryTopicsOp(ctx, memoryIds) {
|
|
|
14241
14226
|
for (const id of Array.from(new Set(memoryIds))) {
|
|
14242
14227
|
try {
|
|
14243
14228
|
await ctx.database.write(async (writer) => {
|
|
14244
|
-
await assertCanWrite2(ctx);
|
|
14245
14229
|
let record2;
|
|
14246
14230
|
try {
|
|
14247
14231
|
record2 = await ctx.vaultMemoryCollection.find(id);
|
|
@@ -14272,7 +14256,6 @@ async function backfillMemoryTopicsOp(ctx, memoryIds) {
|
|
|
14272
14256
|
for (let i = 0; i < uniqueIds.length; i += CHUNK) {
|
|
14273
14257
|
const chunkIds = uniqueIds.slice(i, i + CHUNK);
|
|
14274
14258
|
await ctx.database.write(async () => {
|
|
14275
|
-
await assertCanWrite2(ctx);
|
|
14276
14259
|
const writes = [];
|
|
14277
14260
|
for (const id of chunkIds) {
|
|
14278
14261
|
let record2;
|
|
@@ -14305,7 +14288,6 @@ async function deleteAllVaultMemoriesForUserOp(ctx, userId) {
|
|
|
14305
14288
|
const records = await ctx.vaultMemoryCollection.query(Q8.where("user_id", userId), Q8.where("is_deleted", false)).fetch();
|
|
14306
14289
|
if (records.length === 0) return 0;
|
|
14307
14290
|
await ctx.database.write(async () => {
|
|
14308
|
-
await assertCanWrite2(ctx);
|
|
14309
14291
|
const prepared = records.map(
|
|
14310
14292
|
(record2) => record2.prepareUpdate((r) => {
|
|
14311
14293
|
r._setRaw("is_deleted", true);
|
|
@@ -14360,7 +14342,6 @@ async function archiveVaultMemoryOp(ctx, id, opts) {
|
|
|
14360
14342
|
let stale = false;
|
|
14361
14343
|
const archivedAtValue = opts?.now ?? Date.now();
|
|
14362
14344
|
await ctx.database.write(async () => {
|
|
14363
|
-
await assertCanWrite2(ctx);
|
|
14364
14345
|
if (record2.isDeleted || !isOwnedByCtxUser(ctx, record2) || record2.archivedAt !== null) {
|
|
14365
14346
|
stale = true;
|
|
14366
14347
|
return;
|
|
@@ -14384,7 +14365,6 @@ async function restoreVaultMemoryOp(ctx, id) {
|
|
|
14384
14365
|
if (record2.isDeleted || !isOwnedByCtxUser(ctx, record2)) return false;
|
|
14385
14366
|
let stale = false;
|
|
14386
14367
|
await ctx.database.write(async () => {
|
|
14387
|
-
await assertCanWrite2(ctx);
|
|
14388
14368
|
if (record2.isDeleted || !isOwnedByCtxUser(ctx, record2)) {
|
|
14389
14369
|
stale = true;
|
|
14390
14370
|
return;
|
|
@@ -14405,7 +14385,6 @@ async function hardDeleteDecayedOp(ctx, id, opts) {
|
|
|
14405
14385
|
const now = opts.now ?? Date.now();
|
|
14406
14386
|
let stale = false;
|
|
14407
14387
|
await ctx.database.write(async () => {
|
|
14408
|
-
await assertCanWrite2(ctx);
|
|
14409
14388
|
const archivedAt = record2.archivedAt;
|
|
14410
14389
|
if (record2.isDeleted || !isOwnedByCtxUser(ctx, record2) || archivedAt === null || now - archivedAt <= opts.hardDeleteWindowMs) {
|
|
14411
14390
|
stale = true;
|
|
@@ -14445,7 +14424,6 @@ async function updateVaultMemoryEmbeddingOp(ctx, id, embedding2, embeddingModel,
|
|
|
14445
14424
|
}
|
|
14446
14425
|
let written = false;
|
|
14447
14426
|
await ctx.database.write(async () => {
|
|
14448
|
-
await assertCanWrite2(ctx);
|
|
14449
14427
|
if (record2.isDeleted || !isOwnedByCtxUser(ctx, record2)) return;
|
|
14450
14428
|
const originalUpdatedAt = record2.updatedAt.getTime();
|
|
14451
14429
|
if (originalUpdatedAt !== readUpdatedAt || record2._getRaw("content") !== readStoredContent)
|
|
@@ -18415,13 +18393,6 @@ function restoreCandidates(candidates, redactor, ownNames) {
|
|
|
18415
18393
|
).map((c) => c.candidate);
|
|
18416
18394
|
}
|
|
18417
18395
|
async function extractAndRetain(messages, retainCtx, options) {
|
|
18418
|
-
const { memoryStore, signal } = options;
|
|
18419
|
-
if (memoryStore === null) throw new Error("Memory store is not ready");
|
|
18420
|
-
if (memoryStore && options.folderId !== void 0 && options.folderId !== null)
|
|
18421
|
-
throw new Error("Remote memory extraction does not support folders");
|
|
18422
|
-
if (memoryStore && options.extract.piiRedaction && !memoryStore.masksEmbeddingInput)
|
|
18423
|
-
throw new Error("PII-redacted extraction requires a memory store that masks embedding inputs");
|
|
18424
|
-
signal?.throwIfAborted();
|
|
18425
18396
|
const minConfidence = options.minConfidence ?? DEFAULT_MIN_CONFIDENCE;
|
|
18426
18397
|
const resolvedConsolidatePii = options.consolidateOptions?.piiRedaction ?? options.extract.piiRedaction;
|
|
18427
18398
|
const consolidateOptions = options.consolidateOptions !== void 0 ? {
|
|
@@ -18455,7 +18426,6 @@ async function extractAndRetain(messages, retainCtx, options) {
|
|
|
18455
18426
|
}
|
|
18456
18427
|
});
|
|
18457
18428
|
const extractMs = Date.now() - tExtract;
|
|
18458
|
-
signal?.throwIfAborted();
|
|
18459
18429
|
const filtered = candidates.filter((c) => c.confidence >= minConfidence);
|
|
18460
18430
|
const log = getLogger();
|
|
18461
18431
|
const screened = screenCandidatesForInjection(filtered);
|
|
@@ -18503,33 +18473,16 @@ async function extractAndRetain(messages, retainCtx, options) {
|
|
|
18503
18473
|
const results = [];
|
|
18504
18474
|
const quarantinedInfo = [];
|
|
18505
18475
|
let failedWrites = 0;
|
|
18506
|
-
let auditRows;
|
|
18507
18476
|
const tRetain = Date.now();
|
|
18508
18477
|
for (const { candidate, isQuarantined, reason, signature } of toRetain) {
|
|
18509
18478
|
try {
|
|
18510
|
-
signal?.throwIfAborted();
|
|
18511
18479
|
if (isQuarantined) {
|
|
18512
|
-
|
|
18513
|
-
|
|
18514
|
-
|
|
18515
|
-
|
|
18516
|
-
|
|
18517
|
-
|
|
18518
|
-
includeSuperseded: true
|
|
18519
|
-
}));
|
|
18520
|
-
const sourceKey = [...new Set(candidate.sourceMessageIds)].sort().join("\0");
|
|
18521
|
-
const normalize = (value) => value.normalize("NFKC").trim().replace(/\s+/g, " ").toLowerCase();
|
|
18522
|
-
existingId = (await auditRows).find(
|
|
18523
|
-
(row) => row.trustTier === "quarantined" && row.scope === (options.scope ?? "private") && [...new Set(row.sourceChunkIds ?? [])].sort().join("\0") === sourceKey && normalize(row.content) === normalize(candidate.content)
|
|
18524
|
-
)?.uniqueId ?? null;
|
|
18525
|
-
} else {
|
|
18526
|
-
existingId = await findQuarantinedDuplicateOp(
|
|
18527
|
-
retainCtx.vaultCtx,
|
|
18528
|
-
candidate.content,
|
|
18529
|
-
candidate.sourceMessageIds,
|
|
18530
|
-
{ scope: options.scope ?? "private", folderId: options.folderId ?? null }
|
|
18531
|
-
).catch(() => null);
|
|
18532
|
-
}
|
|
18480
|
+
const existingId = await findQuarantinedDuplicateOp(
|
|
18481
|
+
retainCtx.vaultCtx,
|
|
18482
|
+
candidate.content,
|
|
18483
|
+
candidate.sourceMessageIds,
|
|
18484
|
+
{ scope: options.scope ?? "private", folderId: options.folderId ?? null }
|
|
18485
|
+
).catch(() => null);
|
|
18533
18486
|
if (existingId) {
|
|
18534
18487
|
quarantinedInfo.push({
|
|
18535
18488
|
candidate,
|
|
@@ -18540,26 +18493,18 @@ async function extractAndRetain(messages, retainCtx, options) {
|
|
|
18540
18493
|
continue;
|
|
18541
18494
|
}
|
|
18542
18495
|
}
|
|
18543
|
-
const
|
|
18496
|
+
const result = await retain(candidate.content, retainCtx, {
|
|
18544
18497
|
source: "auto-extracted",
|
|
18545
18498
|
sourceChunkIds: candidate.sourceMessageIds,
|
|
18546
18499
|
respectTombstones: true,
|
|
18547
18500
|
...options.scope !== void 0 && { scope: options.scope },
|
|
18501
|
+
...options.folderId !== void 0 && { folderId: options.folderId },
|
|
18548
18502
|
...consolidateOptions !== void 0 && { consolidateOptions },
|
|
18549
18503
|
...candidate.eventTime !== null && { eventTime: candidate.eventTime },
|
|
18550
18504
|
factType: candidate.type,
|
|
18551
18505
|
...isQuarantined && { trustTier: "quarantined", enableAutoMerge: false }
|
|
18552
|
-
};
|
|
18553
|
-
const result = memoryStore ? await memoryStore.retain(candidate.content, {
|
|
18554
|
-
...retainOptions,
|
|
18555
|
-
canWrite: retainCtx.vaultCtx.canWrite,
|
|
18556
|
-
signal
|
|
18557
|
-
}) : await retain(candidate.content, retainCtx, {
|
|
18558
|
-
...retainOptions,
|
|
18559
|
-
...options.folderId !== void 0 && { folderId: options.folderId }
|
|
18560
18506
|
});
|
|
18561
18507
|
if (isQuarantined) {
|
|
18562
|
-
auditRows = void 0;
|
|
18563
18508
|
const info = {
|
|
18564
18509
|
candidate,
|
|
18565
18510
|
memoryId: result.memoryId,
|
|
@@ -18578,16 +18523,9 @@ async function extractAndRetain(messages, retainCtx, options) {
|
|
|
18578
18523
|
}
|
|
18579
18524
|
succeededCandidates.push(candidate);
|
|
18580
18525
|
results.push(result);
|
|
18581
|
-
if (result.action !== "suppressed" && candidate.entities.length > 0) {
|
|
18526
|
+
if (result.action !== "suppressed" && options.entityCtx && candidate.entities.length > 0) {
|
|
18582
18527
|
try {
|
|
18583
|
-
|
|
18584
|
-
if (memoryStore) {
|
|
18585
|
-
await memoryStore.addTopics(result.memoryId, candidate.entities, {
|
|
18586
|
-
unlessUserManaged: true,
|
|
18587
|
-
canWrite: retainCtx.vaultCtx.canWrite,
|
|
18588
|
-
signal
|
|
18589
|
-
});
|
|
18590
|
-
} else if (options.entityCtx && !await isMemoryTopicsUserManaged(options.entityCtx, result.memoryId)) {
|
|
18528
|
+
if (!await isMemoryTopicsUserManaged(options.entityCtx, result.memoryId)) {
|
|
18591
18529
|
await linkMemoryEntitiesOp(options.entityCtx, result.memoryId, candidate.entities, {
|
|
18592
18530
|
unlessTopicsUserManaged: true
|
|
18593
18531
|
});
|
|
@@ -18835,7 +18773,7 @@ function createAutoExtractor(options) {
|
|
|
18835
18773
|
};
|
|
18836
18774
|
const consolidateOptions = options.consolidate ? { ...options.consolidate, ...subPassAuth(options.consolidate.baseUrl) } : void 0;
|
|
18837
18775
|
const injectionClassifierOptions = options.injectionClassifier ? { ...options.injectionClassifier, ...subPassAuth(options.injectionClassifier.baseUrl) } : void 0;
|
|
18838
|
-
if (
|
|
18776
|
+
if (options.retainCtx.vaultCtx.entityCtx && !options.entityCtx) {
|
|
18839
18777
|
getLogger().warn(
|
|
18840
18778
|
"[memory/extract] retainCtx.vaultCtx.entityCtx is set but extractor was created without `entityCtx` \u2014 W5 graph lane will receive no writes"
|
|
18841
18779
|
);
|
|
@@ -18880,8 +18818,6 @@ function createAutoExtractor(options) {
|
|
|
18880
18818
|
try {
|
|
18881
18819
|
const { candidates, results, failedCount, outcome: outcome2, failure, funnel, timings, model } = await extractAndRetain(window2, retainCtx, {
|
|
18882
18820
|
extract,
|
|
18883
|
-
memoryStore: options.memoryStore,
|
|
18884
|
-
signal: options.signal,
|
|
18885
18821
|
...options.minConfidence !== void 0 && { minConfidence: options.minConfidence },
|
|
18886
18822
|
...options.entityCtx !== void 0 && { entityCtx: options.entityCtx },
|
|
18887
18823
|
...options.scope !== void 0 && { scope: options.scope },
|
|
@@ -20994,7 +20930,6 @@ function createLocalMemoryStore(options) {
|
|
|
20994
20930
|
database,
|
|
20995
20931
|
entityCollection: database.get("entity"),
|
|
20996
20932
|
memoryEntityCollection: database.get("memory_entity"),
|
|
20997
|
-
canWrite: options.canWrite,
|
|
20998
20933
|
...userId !== void 0 && { userId },
|
|
20999
20934
|
...options.allowUnscopedRows !== void 0 && {
|
|
21000
20935
|
allowUnscopedRows: options.allowUnscopedRows
|
|
@@ -21006,21 +20941,10 @@ function createLocalMemoryStore(options) {
|
|
|
21006
20941
|
walletAddress: options.walletAddress,
|
|
21007
20942
|
signMessage: options.signMessage,
|
|
21008
20943
|
embeddedWalletSigner: options.embeddedWalletSigner,
|
|
21009
|
-
canWrite: options.canWrite,
|
|
21010
20944
|
...userId !== void 0 && { userId },
|
|
21011
20945
|
...options.singleTenant !== void 0 && { singleTenant: options.singleTenant },
|
|
21012
20946
|
entityCtx
|
|
21013
20947
|
};
|
|
21014
|
-
const assertWrite = async (writeOptions) => {
|
|
21015
|
-
writeOptions?.signal?.throwIfAborted();
|
|
21016
|
-
if (writeOptions?.canWrite && !await writeOptions.canWrite()) {
|
|
21017
|
-
throw new Error("Memory source is no longer eligible");
|
|
21018
|
-
}
|
|
21019
|
-
if (options.canWrite && !await options.canWrite()) {
|
|
21020
|
-
throw new Error("Memory source is no longer eligible");
|
|
21021
|
-
}
|
|
21022
|
-
writeOptions?.signal?.throwIfAborted();
|
|
21023
|
-
};
|
|
21024
20948
|
const vaultCache = options.vaultCache ?? createVaultEmbeddingCache();
|
|
21025
20949
|
const ownedBy = userId !== void 0 ? [Q15.where("user_id", userId)] : [];
|
|
21026
20950
|
const linksOwnedBy = userId === void 0 ? [] : options.allowUnscopedRows ? [Q15.or(Q15.where("user_id", userId), Q15.where("user_id", null))] : [Q15.where("user_id", userId)];
|
|
@@ -21132,25 +21056,9 @@ function createLocalMemoryStore(options) {
|
|
|
21132
21056
|
archive: (id) => archiveVaultMemoryOp(vaultCtx, id),
|
|
21133
21057
|
restore: (id) => restoreVaultMemoryOp(vaultCtx, id),
|
|
21134
21058
|
setTopics: (memoryId, topics) => setMemoryEntitiesOp(vaultCtx, memoryId, topics),
|
|
21135
|
-
addTopics: (memoryId, topics
|
|
21136
|
-
await assertWrite(writeOptions);
|
|
21059
|
+
addTopics: (memoryId, topics) => database.write(async (writer) => {
|
|
21137
21060
|
const owned = await vaultCtx.vaultMemoryCollection.query(Q15.where("id", memoryId), Q15.where("is_deleted", false), ...ownedBy).fetchCount();
|
|
21138
|
-
return owned > 0 ? writer.callWriter(
|
|
21139
|
-
() => linkMemoryEntitiesOp(
|
|
21140
|
-
{
|
|
21141
|
-
...entityCtx,
|
|
21142
|
-
canWrite: async () => {
|
|
21143
|
-
await assertWrite(writeOptions);
|
|
21144
|
-
return true;
|
|
21145
|
-
}
|
|
21146
|
-
},
|
|
21147
|
-
memoryId,
|
|
21148
|
-
topics,
|
|
21149
|
-
{
|
|
21150
|
-
unlessTopicsUserManaged: writeOptions?.unlessUserManaged
|
|
21151
|
-
}
|
|
21152
|
-
)
|
|
21153
|
-
) : [];
|
|
21061
|
+
return owned > 0 ? writer.callWriter(() => linkMemoryEntitiesOp(entityCtx, memoryId, topics)) : [];
|
|
21154
21062
|
}),
|
|
21155
21063
|
setVisibility: (id, visibility, visibilityOptions) => setMemoryVisibilityOp(vaultCtx, id, { visibility, ...visibilityOptions }),
|
|
21156
21064
|
recall: (query, recallOptions) => recall(
|
|
@@ -21160,17 +21068,7 @@ function createLocalMemoryStore(options) {
|
|
|
21160
21068
|
),
|
|
21161
21069
|
retain: (content, retainOptions) => retain(
|
|
21162
21070
|
content,
|
|
21163
|
-
{
|
|
21164
|
-
vaultCtx: {
|
|
21165
|
-
...vaultCtx,
|
|
21166
|
-
canWrite: async () => {
|
|
21167
|
-
await assertWrite(retainOptions);
|
|
21168
|
-
return true;
|
|
21169
|
-
}
|
|
21170
|
-
},
|
|
21171
|
-
embeddingOptions: options.embeddingOptions,
|
|
21172
|
-
vaultCache
|
|
21173
|
-
},
|
|
21071
|
+
{ vaultCtx, embeddingOptions: options.embeddingOptions, vaultCache },
|
|
21174
21072
|
retainOptions
|
|
21175
21073
|
),
|
|
21176
21074
|
factSource: {
|
|
@@ -21816,14 +21714,7 @@ function stored(row) {
|
|
|
21816
21714
|
function createRemoteMemoryPipeline(options) {
|
|
21817
21715
|
const { persistence, embeddingOptions } = options;
|
|
21818
21716
|
const model = embeddingOptions.model ?? DEFAULT_API_EMBEDDING_MODEL;
|
|
21819
|
-
const operation = (mode, queryOptions = embeddingOptions
|
|
21820
|
-
const signal = writeOptions?.signal;
|
|
21821
|
-
const assertWrite = async () => {
|
|
21822
|
-
signal?.throwIfAborted();
|
|
21823
|
-
if (writeOptions?.canWrite && !await writeOptions.canWrite())
|
|
21824
|
-
throw new Error("Memory source is no longer eligible");
|
|
21825
|
-
signal?.throwIfAborted();
|
|
21826
|
-
};
|
|
21717
|
+
const operation = (mode, queryOptions = embeddingOptions) => {
|
|
21827
21718
|
const rejectUndecryptable = (failed) => {
|
|
21828
21719
|
if (!failed.length) return;
|
|
21829
21720
|
if (mode === "retain")
|
|
@@ -21841,7 +21732,7 @@ function createRemoteMemoryPipeline(options) {
|
|
|
21841
21732
|
return items.map((item) => stored(item.memory));
|
|
21842
21733
|
};
|
|
21843
21734
|
const get = async (id) => {
|
|
21844
|
-
const snapshot = snapshots.get(id) ?? await
|
|
21735
|
+
const snapshot = snapshots.get(id) ?? await persistence.get(id);
|
|
21845
21736
|
if (!snapshot || snapshot.memory.is_deleted || snapshot.memory.superseded_by) return null;
|
|
21846
21737
|
snapshots.set(id, snapshot);
|
|
21847
21738
|
return stored(snapshot.memory);
|
|
@@ -21891,7 +21782,7 @@ function createRemoteMemoryPipeline(options) {
|
|
|
21891
21782
|
if (forced.size < 100 && temporal[i] !== void 0) forced.add(temporal[i]);
|
|
21892
21783
|
}
|
|
21893
21784
|
const forceIds = [...forced];
|
|
21894
|
-
const windowOptions = (i,
|
|
21785
|
+
const windowOptions = (i, signal) => ({
|
|
21895
21786
|
limit: Math.min(100, Math.max((search.limit ?? 8) * 3, 30)),
|
|
21896
21787
|
force_ids: i === 0 ? forceIds : [],
|
|
21897
21788
|
...search.scopes && { scopes: search.scopes },
|
|
@@ -21899,15 +21790,13 @@ function createRemoteMemoryPipeline(options) {
|
|
|
21899
21790
|
...search.memoryIds !== void 0 && { memory_ids: search.memoryIds },
|
|
21900
21791
|
include_archived: search.includeArchived,
|
|
21901
21792
|
embedding_model: model,
|
|
21902
|
-
...
|
|
21793
|
+
...signal && { signal }
|
|
21903
21794
|
});
|
|
21904
21795
|
const vectors = [queryEmbedding, ...facetEmbeddings];
|
|
21905
21796
|
let windows;
|
|
21906
21797
|
if (mode === "retain") {
|
|
21907
21798
|
windows = await Promise.all(
|
|
21908
|
-
vectors.map(
|
|
21909
|
-
(embedding2, i) => persistence.candidateSet(embedding2, windowOptions(i, signal))
|
|
21910
|
-
)
|
|
21799
|
+
vectors.map((embedding2, i) => persistence.candidateSet(embedding2, windowOptions(i)))
|
|
21911
21800
|
);
|
|
21912
21801
|
} else {
|
|
21913
21802
|
const deadline = new AbortController();
|
|
@@ -21995,15 +21884,12 @@ function createRemoteMemoryPipeline(options) {
|
|
|
21995
21884
|
twin_opt_in: false
|
|
21996
21885
|
};
|
|
21997
21886
|
};
|
|
21998
|
-
const write = async (memory, snapshot) =>
|
|
21999
|
-
await assertWrite();
|
|
22000
|
-
return remember([await persistence.put(memory, snapshot, signal)])[0];
|
|
22001
|
-
};
|
|
21887
|
+
const write = async (memory, snapshot) => remember([await persistence.put(memory, snapshot)])[0];
|
|
22002
21888
|
const port = {
|
|
22003
21889
|
prepare,
|
|
22004
21890
|
get,
|
|
22005
21891
|
getFresh: async (id) => {
|
|
22006
|
-
const current = await
|
|
21892
|
+
const current = await persistence.get(id);
|
|
22007
21893
|
return current && !current.memory.is_deleted && !current.memory.superseded_by ? stored(current.memory) : null;
|
|
22008
21894
|
},
|
|
22009
21895
|
tombstones: async (embedding2, embeddingModel, scope, folderId) => {
|
|
@@ -22014,8 +21900,7 @@ function createRemoteMemoryPipeline(options) {
|
|
|
22014
21900
|
embedding_model: embeddingModel,
|
|
22015
21901
|
strict_model: true,
|
|
22016
21902
|
include_deleted: true,
|
|
22017
|
-
deleted_only: true
|
|
22018
|
-
signal
|
|
21903
|
+
deleted_only: true
|
|
22019
21904
|
});
|
|
22020
21905
|
rejectUndecryptable(window2.failed);
|
|
22021
21906
|
return remember(window2.items);
|
|
@@ -22071,18 +21956,14 @@ function createRemoteMemoryPipeline(options) {
|
|
|
22071
21956
|
if (!target || !newer || id === successor) return false;
|
|
22072
21957
|
const old = snapshots.get(id);
|
|
22073
21958
|
const next = snapshots.get(successor);
|
|
22074
|
-
await assertWrite();
|
|
22075
21959
|
remember(
|
|
22076
|
-
await persistence.putMany(
|
|
22077
|
-
|
|
22078
|
-
{
|
|
22079
|
-
|
|
22080
|
-
|
|
22081
|
-
|
|
22082
|
-
|
|
22083
|
-
],
|
|
22084
|
-
signal
|
|
22085
|
-
)
|
|
21960
|
+
await persistence.putMany([
|
|
21961
|
+
{
|
|
21962
|
+
memory: { ...old.memory, superseded_by: successor, superseded_at: Date.now() },
|
|
21963
|
+
expectedVersion: old
|
|
21964
|
+
},
|
|
21965
|
+
{ memory: next.memory, expectedVersion: next }
|
|
21966
|
+
])
|
|
22086
21967
|
);
|
|
22087
21968
|
return true;
|
|
22088
21969
|
},
|
|
@@ -22091,22 +21972,18 @@ function createRemoteMemoryPipeline(options) {
|
|
|
22091
21972
|
if (!target) return { created: null, retired: false };
|
|
22092
21973
|
const snapshot = snapshots.get(targetId);
|
|
22093
21974
|
const successor = createRow(input);
|
|
22094
|
-
await assertWrite();
|
|
22095
21975
|
const rows = remember(
|
|
22096
|
-
await persistence.putMany(
|
|
22097
|
-
|
|
22098
|
-
|
|
22099
|
-
{
|
|
22100
|
-
memory
|
|
22101
|
-
|
|
22102
|
-
|
|
22103
|
-
|
|
22104
|
-
|
|
22105
|
-
|
|
22106
|
-
|
|
22107
|
-
],
|
|
22108
|
-
signal
|
|
22109
|
-
)
|
|
21976
|
+
await persistence.putMany([
|
|
21977
|
+
{ memory: successor, expectedVersion: 0 },
|
|
21978
|
+
{
|
|
21979
|
+
memory: {
|
|
21980
|
+
...snapshot.memory,
|
|
21981
|
+
superseded_by: successor.memory_id,
|
|
21982
|
+
superseded_at: Date.now()
|
|
21983
|
+
},
|
|
21984
|
+
expectedVersion: snapshot
|
|
21985
|
+
}
|
|
21986
|
+
])
|
|
22110
21987
|
);
|
|
22111
21988
|
return { created: rows[0], retired: true };
|
|
22112
21989
|
}
|
|
@@ -22141,7 +22018,7 @@ function createRemoteMemoryPipeline(options) {
|
|
|
22141
22018
|
factSource,
|
|
22142
22019
|
recall: async (query, recallOptions = {}) => recall(query, { embeddingOptions, factSource }, { ...recallOptions, types: ["fact"] }),
|
|
22143
22020
|
retain: async (content, retainOptions) => {
|
|
22144
|
-
const { port } = operation("retain"
|
|
22021
|
+
const { port } = operation("retain");
|
|
22145
22022
|
return retainWithPersistence(
|
|
22146
22023
|
content,
|
|
22147
22024
|
{
|
|
@@ -22723,21 +22600,16 @@ function createRemoteMemoryStore(options) {
|
|
|
22723
22600
|
const record2 = await persistence.get(id);
|
|
22724
22601
|
return record2 && !record2.memory.is_deleted ? record2 : null;
|
|
22725
22602
|
};
|
|
22726
|
-
const mutateLocked = async (id, change, edit
|
|
22727
|
-
|
|
22728
|
-
const record2 = writeOptions?.signal ? await persistence.get(id, writeOptions.signal) : await live(id);
|
|
22603
|
+
const mutateLocked = async (id, change, edit) => {
|
|
22604
|
+
const record2 = await live(id);
|
|
22729
22605
|
if (!record2) return null;
|
|
22730
|
-
if (record2.memory.is_deleted) return null;
|
|
22731
|
-
if (writeOptions?.canWrite && !await writeOptions.canWrite())
|
|
22732
|
-
throw new Error("Memory source is no longer eligible");
|
|
22733
|
-
writeOptions?.signal?.throwIfAborted();
|
|
22734
22606
|
const next = edit(structuredClone(record2.memory));
|
|
22735
22607
|
if (!next) return null;
|
|
22736
|
-
const saved =
|
|
22608
|
+
const saved = await persistence.put(next, record2);
|
|
22737
22609
|
notify(typeof change === "function" ? change(record2.memory) : change, [saved]);
|
|
22738
22610
|
return saved;
|
|
22739
22611
|
};
|
|
22740
|
-
const mutate = (id, change, edit
|
|
22612
|
+
const mutate = (id, change, edit) => serialized(id, () => mutateLocked(id, change, edit));
|
|
22741
22613
|
const serializedAll = (ids, task) => [...new Set(ids)].sort().reduceRight((inner, id) => () => serialized(id, inner), task)();
|
|
22742
22614
|
const mutateMany = async (ids, change, edit) => {
|
|
22743
22615
|
const saved = /* @__PURE__ */ new Map();
|
|
@@ -23250,21 +23122,13 @@ function createRemoteMemoryStore(options) {
|
|
|
23250
23122
|
}))
|
|
23251
23123
|
);
|
|
23252
23124
|
},
|
|
23253
|
-
addTopics: async (memoryId, topics
|
|
23125
|
+
addTopics: async (memoryId, topics) => {
|
|
23254
23126
|
const added = await withKnownKinds(topicInputs(topics, "auto"));
|
|
23255
|
-
const saved = await mutate(
|
|
23256
|
-
|
|
23257
|
-
|
|
23258
|
-
(
|
|
23259
|
-
|
|
23260
|
-
return {
|
|
23261
|
-
...memory,
|
|
23262
|
-
topics: serializeTopics(mergeTopics(parseTopics(memory.topics) ?? [], added)),
|
|
23263
|
-
topics_updated_at: Date.now()
|
|
23264
|
-
};
|
|
23265
|
-
},
|
|
23266
|
-
writeOptions
|
|
23267
|
-
);
|
|
23127
|
+
const saved = await mutate(memoryId, "edit", (memory) => ({
|
|
23128
|
+
...memory,
|
|
23129
|
+
topics: serializeTopics(mergeTopics(parseTopics(memory.topics) ?? [], added)),
|
|
23130
|
+
topics_updated_at: Date.now()
|
|
23131
|
+
}));
|
|
23268
23132
|
if (!saved) return [];
|
|
23269
23133
|
const now = /* @__PURE__ */ new Date();
|
|
23270
23134
|
return mergeTopics([], added).map(
|
|
@@ -24115,7 +23979,6 @@ function createDurableAutoExtractor(options) {
|
|
|
24115
23979
|
};
|
|
24116
23980
|
const folderId = options.folderId ?? null;
|
|
24117
23981
|
let disposed = false;
|
|
24118
|
-
let activeBatch = null;
|
|
24119
23982
|
let running = false;
|
|
24120
23983
|
let wakeRequested = false;
|
|
24121
23984
|
let timer;
|
|
@@ -24152,18 +24015,14 @@ function createDurableAutoExtractor(options) {
|
|
|
24152
24015
|
}, delay);
|
|
24153
24016
|
}
|
|
24154
24017
|
async function extractBatch(messages, conversationId, ids, jobScope, jobFolderId) {
|
|
24155
|
-
if (disposed) throw new Error("Extraction session was disposed");
|
|
24156
24018
|
let watchdog;
|
|
24157
24019
|
let cancelled = false;
|
|
24158
|
-
const controller = new AbortController();
|
|
24159
|
-
activeBatch = controller;
|
|
24160
24020
|
const model = options.modelForScope?.(jobScope) ?? options.extract.model;
|
|
24161
24021
|
try {
|
|
24162
24022
|
return await Promise.race([
|
|
24163
24023
|
new Promise((resolve, reject) => {
|
|
24164
24024
|
const worker = createAutoExtractor({
|
|
24165
24025
|
...options,
|
|
24166
|
-
signal: controller.signal,
|
|
24167
24026
|
retainCtx: {
|
|
24168
24027
|
...options.retainCtx,
|
|
24169
24028
|
vaultCtx: {
|
|
@@ -24192,8 +24051,6 @@ function createDurableAutoExtractor(options) {
|
|
|
24192
24051
|
]);
|
|
24193
24052
|
} finally {
|
|
24194
24053
|
cancelled = true;
|
|
24195
|
-
controller.abort();
|
|
24196
|
-
if (activeBatch === controller) activeBatch = null;
|
|
24197
24054
|
if (watchdog !== void 0) clearTimeout(watchdog);
|
|
24198
24055
|
}
|
|
24199
24056
|
}
|
|
@@ -24205,7 +24062,6 @@ function createDurableAutoExtractor(options) {
|
|
|
24205
24062
|
for (const message of loaded)
|
|
24206
24063
|
if (message && message.messageId > 0) sequences.set(message.uniqueId, message.messageId);
|
|
24207
24064
|
await database.write(async () => {
|
|
24208
|
-
if (disposed) return;
|
|
24209
24065
|
const current = idsOf(job);
|
|
24210
24066
|
const acknowledged = ids.filter((id) => current.includes(id));
|
|
24211
24067
|
if (!acknowledged.length) return;
|
|
@@ -24378,7 +24234,6 @@ function createDurableAutoExtractor(options) {
|
|
|
24378
24234
|
jobScope,
|
|
24379
24235
|
jobFolderId
|
|
24380
24236
|
);
|
|
24381
|
-
if (disposed) throw new Error("Extraction session was disposed");
|
|
24382
24237
|
options.onTurnComplete?.(result);
|
|
24383
24238
|
return result;
|
|
24384
24239
|
};
|
|
@@ -24415,7 +24270,6 @@ function createDurableAutoExtractor(options) {
|
|
|
24415
24270
|
);
|
|
24416
24271
|
scheduleAfterSuccess = true;
|
|
24417
24272
|
} catch (error) {
|
|
24418
|
-
if (disposed) break;
|
|
24419
24273
|
attempts.set(job.id, attempted + 1);
|
|
24420
24274
|
retry = true;
|
|
24421
24275
|
reportError(error, conversationId);
|
|
@@ -24438,14 +24292,6 @@ function createDurableAutoExtractor(options) {
|
|
|
24438
24292
|
schedule(retry ? options.retryDelayMs ?? 3e4 : 0);
|
|
24439
24293
|
}
|
|
24440
24294
|
}
|
|
24441
|
-
function dispose() {
|
|
24442
|
-
disposed = true;
|
|
24443
|
-
activeBatch?.abort(options.signal?.reason);
|
|
24444
|
-
if (timer !== void 0) clearTimeout(timer);
|
|
24445
|
-
options.signal?.removeEventListener("abort", dispose);
|
|
24446
|
-
}
|
|
24447
|
-
if (options.signal?.aborted) dispose();
|
|
24448
|
-
else options.signal?.addEventListener("abort", dispose, { once: true });
|
|
24449
24295
|
schedule(0);
|
|
24450
24296
|
return {
|
|
24451
24297
|
processTurn(messages, conversationId) {
|
|
@@ -24525,7 +24371,10 @@ function createDurableAutoExtractor(options) {
|
|
|
24525
24371
|
return true;
|
|
24526
24372
|
},
|
|
24527
24373
|
isProcessing: () => running,
|
|
24528
|
-
dispose
|
|
24374
|
+
dispose() {
|
|
24375
|
+
disposed = true;
|
|
24376
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
24377
|
+
}
|
|
24529
24378
|
};
|
|
24530
24379
|
}
|
|
24531
24380
|
|
|
@@ -30786,7 +30635,6 @@ var CONVERSATION_REDACTOR_LIMIT = 50;
|
|
|
30786
30635
|
var NO_CONVERSATION_KEY = "__no_conversation__";
|
|
30787
30636
|
var NO_STORE_FOLDERS = "Folders are not supported with a memoryStore";
|
|
30788
30637
|
var NO_STORE_MASK = "piiRedaction needs a memoryStore built with embeddingOptions.maskInput";
|
|
30789
|
-
var MEMORY_STORE_NOT_READY = "Memory store is not ready";
|
|
30790
30638
|
var conversationRedactors = /* @__PURE__ */ new Map();
|
|
30791
30639
|
function getConversationRedactor(conversationId, nerDetector) {
|
|
30792
30640
|
const key = conversationId ?? NO_CONVERSATION_KEY;
|
|
@@ -30877,7 +30725,7 @@ function useChatStorage(options) {
|
|
|
30877
30725
|
() => ({ getToken, baseUrl, model: embeddingModel, maskInput: maskEmbeddingInput }),
|
|
30878
30726
|
[getToken, baseUrl, embeddingModel, maskEmbeddingInput]
|
|
30879
30727
|
);
|
|
30880
|
-
const storeMaskMissing = memoryStore !== void 0 &&
|
|
30728
|
+
const storeMaskMissing = memoryStore !== void 0 && maskEmbeddingInput !== void 0 && !memoryStore.masksEmbeddingInput;
|
|
30881
30729
|
const blobManagerRef = useRef4(new BlobUrlManager());
|
|
30882
30730
|
useEffect4(() => {
|
|
30883
30731
|
const manager = blobManagerRef.current;
|
|
@@ -31154,7 +31002,6 @@ function useChatStorage(options) {
|
|
|
31154
31002
|
);
|
|
31155
31003
|
const retainVaultMemory = useCallback5(
|
|
31156
31004
|
async (input) => {
|
|
31157
|
-
if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
|
|
31158
31005
|
if (memoryStore) {
|
|
31159
31006
|
if (storeMaskMissing) throw new Error(NO_STORE_MASK);
|
|
31160
31007
|
if (input.folderId !== void 0) throw new Error(NO_STORE_FOLDERS);
|
|
@@ -31186,7 +31033,6 @@ function useChatStorage(options) {
|
|
|
31186
31033
|
);
|
|
31187
31034
|
const createMemoryVaultTool2 = useCallback5(
|
|
31188
31035
|
(options2) => {
|
|
31189
|
-
if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
|
|
31190
31036
|
if (storeMaskMissing) throw new Error(NO_STORE_MASK);
|
|
31191
31037
|
const embOpts = getToken ? vaultEmbeddingOptions : void 0;
|
|
31192
31038
|
return createMemoryVaultTool(
|
|
@@ -31208,7 +31054,6 @@ function useChatStorage(options) {
|
|
|
31208
31054
|
);
|
|
31209
31055
|
const getVaultMemories = useCallback5(
|
|
31210
31056
|
(options2) => {
|
|
31211
|
-
if (memoryStore === null) return Promise.resolve([]);
|
|
31212
31057
|
if (!memoryStore) return getAllVaultMemoriesOp(vaultCtx, options2);
|
|
31213
31058
|
const { folderId, levels, kinds, ...listOptions } = options2 ?? {};
|
|
31214
31059
|
if (folderId !== void 0) throw new Error(NO_STORE_FOLDERS);
|
|
@@ -31220,7 +31065,6 @@ function useChatStorage(options) {
|
|
|
31220
31065
|
);
|
|
31221
31066
|
const createVaultMemory = useCallback5(
|
|
31222
31067
|
async (content, scope) => {
|
|
31223
|
-
if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
|
|
31224
31068
|
if (storeMaskMissing) throw new Error(NO_STORE_MASK);
|
|
31225
31069
|
if (memoryStore) return memoryStore.create({ content, scope });
|
|
31226
31070
|
const result = await createVaultMemoryOp(vaultCtx, { content, scope });
|
|
@@ -31242,7 +31086,6 @@ function useChatStorage(options) {
|
|
|
31242
31086
|
);
|
|
31243
31087
|
const updateVaultMemory = useCallback5(
|
|
31244
31088
|
async (id, content, scope) => {
|
|
31245
|
-
if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
|
|
31246
31089
|
if (storeMaskMissing) throw new Error(NO_STORE_MASK);
|
|
31247
31090
|
if (memoryStore) return memoryStore.update(id, { content, scope });
|
|
31248
31091
|
const existing = await getVaultMemoryOp(vaultCtx, id);
|
|
@@ -31268,7 +31111,6 @@ function useChatStorage(options) {
|
|
|
31268
31111
|
);
|
|
31269
31112
|
const deleteVaultMemory = useCallback5(
|
|
31270
31113
|
async (id) => {
|
|
31271
|
-
if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
|
|
31272
31114
|
if (memoryStore) return memoryStore.delete(id);
|
|
31273
31115
|
const existing = await getVaultMemoryOp(vaultCtx, id);
|
|
31274
31116
|
const result = await deleteVaultMemoryOp(vaultCtx, id);
|
|
@@ -31282,7 +31124,7 @@ function useChatStorage(options) {
|
|
|
31282
31124
|
const chunkVectorCacheRef = useRef4(createChunkVectorCache());
|
|
31283
31125
|
const clientToolEmbeddingsCacheRef = useRef4(/* @__PURE__ */ new Map());
|
|
31284
31126
|
useEffect4(() => {
|
|
31285
|
-
if (!getToken || memoryStore
|
|
31127
|
+
if (!getToken || memoryStore) return;
|
|
31286
31128
|
void (async () => {
|
|
31287
31129
|
try {
|
|
31288
31130
|
await preEmbedVaultMemories(vaultCtx, vaultEmbeddingOptions, vaultEmbeddingCache);
|
|
@@ -31298,7 +31140,6 @@ function useChatStorage(options) {
|
|
|
31298
31140
|
}, [vaultEmbeddingCache]);
|
|
31299
31141
|
const createMemoryVaultSearchTool2 = useCallback5(
|
|
31300
31142
|
(searchOptions) => {
|
|
31301
|
-
if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
|
|
31302
31143
|
if (!getToken && !memoryStore) {
|
|
31303
31144
|
throw new Error("getToken is required for memory vault search tool");
|
|
31304
31145
|
}
|
|
@@ -31314,7 +31155,6 @@ function useChatStorage(options) {
|
|
|
31314
31155
|
);
|
|
31315
31156
|
const createRecallTool2 = useCallback5(
|
|
31316
31157
|
(toolOptions, callbacks) => {
|
|
31317
|
-
if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
|
|
31318
31158
|
if (!getToken && !memoryStore) {
|
|
31319
31159
|
throw new Error("getToken is required for recall tool");
|
|
31320
31160
|
}
|
|
@@ -31354,7 +31194,6 @@ function useChatStorage(options) {
|
|
|
31354
31194
|
);
|
|
31355
31195
|
const searchVaultMemoriesFn = useCallback5(
|
|
31356
31196
|
async (query, searchOptions) => {
|
|
31357
|
-
if (memoryStore === null) return [];
|
|
31358
31197
|
if (storeMaskMissing) throw new Error(NO_STORE_MASK);
|
|
31359
31198
|
if (memoryStore) return (await memoryStore.factSource.search(query, searchOptions)).results;
|
|
31360
31199
|
if (!getToken) return [];
|
|
@@ -31370,7 +31209,7 @@ function useChatStorage(options) {
|
|
|
31370
31209
|
);
|
|
31371
31210
|
const recallFn = useCallback5(
|
|
31372
31211
|
async (query, options2) => {
|
|
31373
|
-
if (
|
|
31212
|
+
if (!getToken && !memoryStore) {
|
|
31374
31213
|
return {
|
|
31375
31214
|
memories: [],
|
|
31376
31215
|
usedBudget: options2?.budget ?? "low",
|