@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.cjs
CHANGED
|
@@ -12292,11 +12292,6 @@ function parseTopics(value) {
|
|
|
12292
12292
|
}
|
|
12293
12293
|
|
|
12294
12294
|
// src/lib/db/entities/operations.ts
|
|
12295
|
-
async function assertCanWrite(ctx) {
|
|
12296
|
-
if (ctx.canWrite && !await ctx.canWrite()) {
|
|
12297
|
-
throw new Error("Memory source is no longer eligible");
|
|
12298
|
-
}
|
|
12299
|
-
}
|
|
12300
12295
|
function entityToStored(e) {
|
|
12301
12296
|
return {
|
|
12302
12297
|
uniqueId: e.id,
|
|
@@ -12437,7 +12432,6 @@ async function linkMemoryEntitiesOp(ctx, memoryId, entityInputs, options) {
|
|
|
12437
12432
|
let skipped = false;
|
|
12438
12433
|
let entities = [];
|
|
12439
12434
|
await ctx.database.write(async () => {
|
|
12440
|
-
await assertCanWrite(ctx);
|
|
12441
12435
|
const {
|
|
12442
12436
|
entities: byName,
|
|
12443
12437
|
operations: entityOps,
|
|
@@ -12513,7 +12507,6 @@ async function replaceMemoryEntities(ctx, memoryId, entityInputs, options) {
|
|
|
12513
12507
|
let skipped = false;
|
|
12514
12508
|
let entities = [];
|
|
12515
12509
|
await ctx.database.write(async () => {
|
|
12516
|
-
await assertCanWrite(ctx);
|
|
12517
12510
|
const vaultRow = await findVaultRowInWrite(ctx, memoryId);
|
|
12518
12511
|
if (options.guarded && autoLinkBlocked(vaultRow)) {
|
|
12519
12512
|
skipped = true;
|
|
@@ -12574,7 +12567,6 @@ async function unlinkMemoryEntitiesOp(ctx, memoryIds) {
|
|
|
12574
12567
|
const links = await ctx.memoryEntityCollection.query(import_watermelondb11.Q.where("memory_id", import_watermelondb11.Q.oneOf(Array.from(memoryIds)))).fetch();
|
|
12575
12568
|
if (links.length === 0) return;
|
|
12576
12569
|
await ctx.database.write(async () => {
|
|
12577
|
-
await assertCanWrite(ctx);
|
|
12578
12570
|
await ctx.database.batch(...links.map((l) => l.prepareDestroyPermanently()));
|
|
12579
12571
|
});
|
|
12580
12572
|
}
|
|
@@ -12583,7 +12575,6 @@ async function unlinkAllMemoryEntitiesForUserOp(ctx, userId) {
|
|
|
12583
12575
|
const links = await ctx.memoryEntityCollection.query(import_watermelondb11.Q.where("user_id", userId)).fetch();
|
|
12584
12576
|
if (links.length === 0) return;
|
|
12585
12577
|
await ctx.database.write(async () => {
|
|
12586
|
-
await assertCanWrite(ctx);
|
|
12587
12578
|
await ctx.database.batch(...links.map((l) => l.prepareDestroyPermanently()));
|
|
12588
12579
|
});
|
|
12589
12580
|
}
|
|
@@ -12603,7 +12594,6 @@ async function backfillMemoryEntityUserIdsOp(ctx, vaultMemoryCollection) {
|
|
|
12603
12594
|
}
|
|
12604
12595
|
if (toUpdate.length === 0) return 0;
|
|
12605
12596
|
await ctx.database.write(async () => {
|
|
12606
|
-
await assertCanWrite(ctx);
|
|
12607
12597
|
await ctx.database.batch(
|
|
12608
12598
|
...toUpdate.map(({ link, userId }) => link.prepareUpdate((r) => r._setRaw("user_id", userId)))
|
|
12609
12599
|
);
|
|
@@ -14997,11 +14987,6 @@ function visibilityConditions(requested) {
|
|
|
14997
14987
|
function isKinded(record2) {
|
|
14998
14988
|
return record2.kind !== null && record2.kind !== void 0;
|
|
14999
14989
|
}
|
|
15000
|
-
async function assertCanWrite2(ctx) {
|
|
15001
|
-
if (ctx.canWrite && !await ctx.canWrite()) {
|
|
15002
|
-
throw new Error("Memory source is no longer eligible");
|
|
15003
|
-
}
|
|
15004
|
-
}
|
|
15005
14990
|
function assertValidKindLevel(kind, level) {
|
|
15006
14991
|
const hasKind = kind !== null && kind !== void 0;
|
|
15007
14992
|
if (hasKind && !MEMORY_KINDS.includes(kind)) {
|
|
@@ -15182,7 +15167,8 @@ async function createVaultMemoryOp(ctx, opts) {
|
|
|
15182
15167
|
ctx.embeddedWalletSigner
|
|
15183
15168
|
) : opts.content;
|
|
15184
15169
|
const created = await ctx.database.write(async () => {
|
|
15185
|
-
await
|
|
15170
|
+
if (ctx.canWrite && !await ctx.canWrite())
|
|
15171
|
+
throw new Error("Memory source is no longer eligible");
|
|
15186
15172
|
return ctx.vaultMemoryCollection.create(
|
|
15187
15173
|
(record2) => populateNewVaultMemory(record2, ctx, opts, encryptedContent, encryptedKindValue)
|
|
15188
15174
|
);
|
|
@@ -15201,7 +15187,8 @@ async function createSupersedingMemoryOp(ctx, opts, targetId) {
|
|
|
15201
15187
|
) : opts.content;
|
|
15202
15188
|
let createdRecord = null;
|
|
15203
15189
|
await ctx.database.write(async () => {
|
|
15204
|
-
await
|
|
15190
|
+
if (ctx.canWrite && !await ctx.canWrite())
|
|
15191
|
+
throw new Error("Memory source is no longer eligible");
|
|
15205
15192
|
let target;
|
|
15206
15193
|
try {
|
|
15207
15194
|
target = await ctx.vaultMemoryCollection.find(targetId);
|
|
@@ -15293,7 +15280,8 @@ async function createVaultMemoriesBatchOp(ctx, optionsArray) {
|
|
|
15293
15280
|
})
|
|
15294
15281
|
);
|
|
15295
15282
|
const created = await ctx.database.write(async () => {
|
|
15296
|
-
await
|
|
15283
|
+
if (ctx.canWrite && !await ctx.canWrite())
|
|
15284
|
+
throw new Error("Memory source is no longer eligible");
|
|
15297
15285
|
const prepared = optionsArray.map(
|
|
15298
15286
|
(opts, i) => ctx.vaultMemoryCollection.prepareCreate(
|
|
15299
15287
|
(record2) => populateNewVaultMemory(record2, ctx, opts, encryptedContents[i], encryptedKindValues[i])
|
|
@@ -15598,7 +15586,8 @@ async function updateVaultMemoryOp(ctx, id, opts) {
|
|
|
15598
15586
|
const record2 = probe;
|
|
15599
15587
|
const originalUpdatedAt = record2.updatedAt.getTime();
|
|
15600
15588
|
await ctx.database.write(async () => {
|
|
15601
|
-
await
|
|
15589
|
+
if (ctx.canWrite && !await ctx.canWrite())
|
|
15590
|
+
throw new Error("Memory source is no longer eligible");
|
|
15602
15591
|
if (record2.isDeleted || record2.supersededBy || !isOwnedByCtxUser(ctx, record2) || opts.freeFormOnly && isKinded(record2)) {
|
|
15603
15592
|
stale = true;
|
|
15604
15593
|
return;
|
|
@@ -15709,7 +15698,6 @@ async function setMemoryEntitiesOp(ctx, memoryId, entities) {
|
|
|
15709
15698
|
let stale = false;
|
|
15710
15699
|
const originalUpdatedAt = record2.updatedAt.getTime();
|
|
15711
15700
|
await ctx.database.write(async (writer) => {
|
|
15712
|
-
await assertCanWrite2(ctx);
|
|
15713
15701
|
if (record2.isDeleted || !isOwnedByCtxUser(ctx, record2)) {
|
|
15714
15702
|
stale = true;
|
|
15715
15703
|
return;
|
|
@@ -15751,7 +15739,6 @@ async function clearMemoryTopicsOverrideOp(ctx, memoryId, options) {
|
|
|
15751
15739
|
const originalUpdatedAt = record2.updatedAt.getTime();
|
|
15752
15740
|
let cleared = false;
|
|
15753
15741
|
await ctx.database.write(async () => {
|
|
15754
|
-
await assertCanWrite2(ctx);
|
|
15755
15742
|
if (options?.unlessTopicsRecorded && parseTopics(record2.topics) !== null) return;
|
|
15756
15743
|
cleared = true;
|
|
15757
15744
|
await record2.update((r) => {
|
|
@@ -15775,7 +15762,6 @@ async function setMemoryVisibilityOp(ctx, id, opts) {
|
|
|
15775
15762
|
if (record2.isDeleted || !isOwnedByCtxUser(ctx, record2)) return null;
|
|
15776
15763
|
let stale = false;
|
|
15777
15764
|
await ctx.database.write(async () => {
|
|
15778
|
-
await assertCanWrite2(ctx);
|
|
15779
15765
|
if (record2.isDeleted || !isOwnedByCtxUser(ctx, record2)) {
|
|
15780
15766
|
stale = true;
|
|
15781
15767
|
return;
|
|
@@ -15804,7 +15790,6 @@ async function deleteVaultMemoryOp(ctx, id) {
|
|
|
15804
15790
|
if (record2.isDeleted || !isOwnedByCtxUser(ctx, record2)) return false;
|
|
15805
15791
|
let stale = false;
|
|
15806
15792
|
await ctx.database.write(async () => {
|
|
15807
|
-
await assertCanWrite2(ctx);
|
|
15808
15793
|
if (record2.isDeleted || !isOwnedByCtxUser(ctx, record2)) {
|
|
15809
15794
|
stale = true;
|
|
15810
15795
|
return;
|
|
@@ -15842,7 +15827,8 @@ async function supersedeVaultMemoryOp(ctx, id, supersededById) {
|
|
|
15842
15827
|
}
|
|
15843
15828
|
let stale = false;
|
|
15844
15829
|
await ctx.database.write(async () => {
|
|
15845
|
-
await
|
|
15830
|
+
if (ctx.canWrite && !await ctx.canWrite())
|
|
15831
|
+
throw new Error("Memory source is no longer eligible");
|
|
15846
15832
|
if (record2.isDeleted || record2.supersededBy || !isOwnedByCtxUser(ctx, record2)) {
|
|
15847
15833
|
stale = true;
|
|
15848
15834
|
return;
|
|
@@ -16004,7 +15990,6 @@ async function stampTopicsExtractedAtOp(ctx, memoryIds, extractedAt, version = T
|
|
|
16004
15990
|
for (let i = 0; i < uniqueIds.length; i += CHUNK) {
|
|
16005
15991
|
const chunkIds = uniqueIds.slice(i, i + CHUNK);
|
|
16006
15992
|
await ctx.database.write(async () => {
|
|
16007
|
-
await assertCanWrite2(ctx);
|
|
16008
15993
|
const records = [];
|
|
16009
15994
|
for (const id of chunkIds) {
|
|
16010
15995
|
try {
|
|
@@ -16038,7 +16023,6 @@ async function relinkMemoryTopicsOp(ctx, memoryIds) {
|
|
|
16038
16023
|
for (const id of Array.from(new Set(memoryIds))) {
|
|
16039
16024
|
try {
|
|
16040
16025
|
await ctx.database.write(async (writer) => {
|
|
16041
|
-
await assertCanWrite2(ctx);
|
|
16042
16026
|
let record2;
|
|
16043
16027
|
try {
|
|
16044
16028
|
record2 = await ctx.vaultMemoryCollection.find(id);
|
|
@@ -16069,7 +16053,6 @@ async function backfillMemoryTopicsOp(ctx, memoryIds) {
|
|
|
16069
16053
|
for (let i = 0; i < uniqueIds.length; i += CHUNK) {
|
|
16070
16054
|
const chunkIds = uniqueIds.slice(i, i + CHUNK);
|
|
16071
16055
|
await ctx.database.write(async () => {
|
|
16072
|
-
await assertCanWrite2(ctx);
|
|
16073
16056
|
const writes = [];
|
|
16074
16057
|
for (const id of chunkIds) {
|
|
16075
16058
|
let record2;
|
|
@@ -16102,7 +16085,6 @@ async function deleteAllVaultMemoriesForUserOp(ctx, userId) {
|
|
|
16102
16085
|
const records = await ctx.vaultMemoryCollection.query(import_watermelondb23.Q.where("user_id", userId), import_watermelondb23.Q.where("is_deleted", false)).fetch();
|
|
16103
16086
|
if (records.length === 0) return 0;
|
|
16104
16087
|
await ctx.database.write(async () => {
|
|
16105
|
-
await assertCanWrite2(ctx);
|
|
16106
16088
|
const prepared = records.map(
|
|
16107
16089
|
(record2) => record2.prepareUpdate((r) => {
|
|
16108
16090
|
r._setRaw("is_deleted", true);
|
|
@@ -16157,7 +16139,6 @@ async function archiveVaultMemoryOp(ctx, id, opts) {
|
|
|
16157
16139
|
let stale = false;
|
|
16158
16140
|
const archivedAtValue = opts?.now ?? Date.now();
|
|
16159
16141
|
await ctx.database.write(async () => {
|
|
16160
|
-
await assertCanWrite2(ctx);
|
|
16161
16142
|
if (record2.isDeleted || !isOwnedByCtxUser(ctx, record2) || record2.archivedAt !== null) {
|
|
16162
16143
|
stale = true;
|
|
16163
16144
|
return;
|
|
@@ -16181,7 +16162,6 @@ async function restoreVaultMemoryOp(ctx, id) {
|
|
|
16181
16162
|
if (record2.isDeleted || !isOwnedByCtxUser(ctx, record2)) return false;
|
|
16182
16163
|
let stale = false;
|
|
16183
16164
|
await ctx.database.write(async () => {
|
|
16184
|
-
await assertCanWrite2(ctx);
|
|
16185
16165
|
if (record2.isDeleted || !isOwnedByCtxUser(ctx, record2)) {
|
|
16186
16166
|
stale = true;
|
|
16187
16167
|
return;
|
|
@@ -16202,7 +16182,6 @@ async function hardDeleteDecayedOp(ctx, id, opts) {
|
|
|
16202
16182
|
const now = opts.now ?? Date.now();
|
|
16203
16183
|
let stale = false;
|
|
16204
16184
|
await ctx.database.write(async () => {
|
|
16205
|
-
await assertCanWrite2(ctx);
|
|
16206
16185
|
const archivedAt = record2.archivedAt;
|
|
16207
16186
|
if (record2.isDeleted || !isOwnedByCtxUser(ctx, record2) || archivedAt === null || now - archivedAt <= opts.hardDeleteWindowMs) {
|
|
16208
16187
|
stale = true;
|
|
@@ -16242,7 +16221,6 @@ async function updateVaultMemoryEmbeddingOp(ctx, id, embedding2, embeddingModel,
|
|
|
16242
16221
|
}
|
|
16243
16222
|
let written = false;
|
|
16244
16223
|
await ctx.database.write(async () => {
|
|
16245
|
-
await assertCanWrite2(ctx);
|
|
16246
16224
|
if (record2.isDeleted || !isOwnedByCtxUser(ctx, record2)) return;
|
|
16247
16225
|
const originalUpdatedAt = record2.updatedAt.getTime();
|
|
16248
16226
|
if (originalUpdatedAt !== readUpdatedAt || record2._getRaw("content") !== readStoredContent)
|
|
@@ -20239,13 +20217,6 @@ function restoreCandidates(candidates, redactor, ownNames) {
|
|
|
20239
20217
|
).map((c) => c.candidate);
|
|
20240
20218
|
}
|
|
20241
20219
|
async function extractAndRetain(messages, retainCtx, options) {
|
|
20242
|
-
const { memoryStore, signal } = options;
|
|
20243
|
-
if (memoryStore === null) throw new Error("Memory store is not ready");
|
|
20244
|
-
if (memoryStore && options.folderId !== void 0 && options.folderId !== null)
|
|
20245
|
-
throw new Error("Remote memory extraction does not support folders");
|
|
20246
|
-
if (memoryStore && options.extract.piiRedaction && !memoryStore.masksEmbeddingInput)
|
|
20247
|
-
throw new Error("PII-redacted extraction requires a memory store that masks embedding inputs");
|
|
20248
|
-
signal?.throwIfAborted();
|
|
20249
20220
|
const minConfidence = options.minConfidence ?? DEFAULT_MIN_CONFIDENCE;
|
|
20250
20221
|
const resolvedConsolidatePii = options.consolidateOptions?.piiRedaction ?? options.extract.piiRedaction;
|
|
20251
20222
|
const consolidateOptions = options.consolidateOptions !== void 0 ? {
|
|
@@ -20279,7 +20250,6 @@ async function extractAndRetain(messages, retainCtx, options) {
|
|
|
20279
20250
|
}
|
|
20280
20251
|
});
|
|
20281
20252
|
const extractMs = Date.now() - tExtract;
|
|
20282
|
-
signal?.throwIfAborted();
|
|
20283
20253
|
const filtered = candidates.filter((c) => c.confidence >= minConfidence);
|
|
20284
20254
|
const log = getLogger();
|
|
20285
20255
|
const screened = screenCandidatesForInjection(filtered);
|
|
@@ -20327,33 +20297,16 @@ async function extractAndRetain(messages, retainCtx, options) {
|
|
|
20327
20297
|
const results = [];
|
|
20328
20298
|
const quarantinedInfo = [];
|
|
20329
20299
|
let failedWrites = 0;
|
|
20330
|
-
let auditRows;
|
|
20331
20300
|
const tRetain = Date.now();
|
|
20332
20301
|
for (const { candidate, isQuarantined, reason, signature } of toRetain) {
|
|
20333
20302
|
try {
|
|
20334
|
-
signal?.throwIfAborted();
|
|
20335
20303
|
if (isQuarantined) {
|
|
20336
|
-
|
|
20337
|
-
|
|
20338
|
-
|
|
20339
|
-
|
|
20340
|
-
|
|
20341
|
-
|
|
20342
|
-
includeSuperseded: true
|
|
20343
|
-
}));
|
|
20344
|
-
const sourceKey = [...new Set(candidate.sourceMessageIds)].sort().join("\0");
|
|
20345
|
-
const normalize = (value) => value.normalize("NFKC").trim().replace(/\s+/g, " ").toLowerCase();
|
|
20346
|
-
existingId = (await auditRows).find(
|
|
20347
|
-
(row) => row.trustTier === "quarantined" && row.scope === (options.scope ?? "private") && [...new Set(row.sourceChunkIds ?? [])].sort().join("\0") === sourceKey && normalize(row.content) === normalize(candidate.content)
|
|
20348
|
-
)?.uniqueId ?? null;
|
|
20349
|
-
} else {
|
|
20350
|
-
existingId = await findQuarantinedDuplicateOp(
|
|
20351
|
-
retainCtx.vaultCtx,
|
|
20352
|
-
candidate.content,
|
|
20353
|
-
candidate.sourceMessageIds,
|
|
20354
|
-
{ scope: options.scope ?? "private", folderId: options.folderId ?? null }
|
|
20355
|
-
).catch(() => null);
|
|
20356
|
-
}
|
|
20304
|
+
const existingId = await findQuarantinedDuplicateOp(
|
|
20305
|
+
retainCtx.vaultCtx,
|
|
20306
|
+
candidate.content,
|
|
20307
|
+
candidate.sourceMessageIds,
|
|
20308
|
+
{ scope: options.scope ?? "private", folderId: options.folderId ?? null }
|
|
20309
|
+
).catch(() => null);
|
|
20357
20310
|
if (existingId) {
|
|
20358
20311
|
quarantinedInfo.push({
|
|
20359
20312
|
candidate,
|
|
@@ -20364,26 +20317,18 @@ async function extractAndRetain(messages, retainCtx, options) {
|
|
|
20364
20317
|
continue;
|
|
20365
20318
|
}
|
|
20366
20319
|
}
|
|
20367
|
-
const
|
|
20320
|
+
const result = await retain(candidate.content, retainCtx, {
|
|
20368
20321
|
source: "auto-extracted",
|
|
20369
20322
|
sourceChunkIds: candidate.sourceMessageIds,
|
|
20370
20323
|
respectTombstones: true,
|
|
20371
20324
|
...options.scope !== void 0 && { scope: options.scope },
|
|
20325
|
+
...options.folderId !== void 0 && { folderId: options.folderId },
|
|
20372
20326
|
...consolidateOptions !== void 0 && { consolidateOptions },
|
|
20373
20327
|
...candidate.eventTime !== null && { eventTime: candidate.eventTime },
|
|
20374
20328
|
factType: candidate.type,
|
|
20375
20329
|
...isQuarantined && { trustTier: "quarantined", enableAutoMerge: false }
|
|
20376
|
-
};
|
|
20377
|
-
const result = memoryStore ? await memoryStore.retain(candidate.content, {
|
|
20378
|
-
...retainOptions,
|
|
20379
|
-
canWrite: retainCtx.vaultCtx.canWrite,
|
|
20380
|
-
signal
|
|
20381
|
-
}) : await retain(candidate.content, retainCtx, {
|
|
20382
|
-
...retainOptions,
|
|
20383
|
-
...options.folderId !== void 0 && { folderId: options.folderId }
|
|
20384
20330
|
});
|
|
20385
20331
|
if (isQuarantined) {
|
|
20386
|
-
auditRows = void 0;
|
|
20387
20332
|
const info = {
|
|
20388
20333
|
candidate,
|
|
20389
20334
|
memoryId: result.memoryId,
|
|
@@ -20402,16 +20347,9 @@ async function extractAndRetain(messages, retainCtx, options) {
|
|
|
20402
20347
|
}
|
|
20403
20348
|
succeededCandidates.push(candidate);
|
|
20404
20349
|
results.push(result);
|
|
20405
|
-
if (result.action !== "suppressed" && candidate.entities.length > 0) {
|
|
20350
|
+
if (result.action !== "suppressed" && options.entityCtx && candidate.entities.length > 0) {
|
|
20406
20351
|
try {
|
|
20407
|
-
|
|
20408
|
-
if (memoryStore) {
|
|
20409
|
-
await memoryStore.addTopics(result.memoryId, candidate.entities, {
|
|
20410
|
-
unlessUserManaged: true,
|
|
20411
|
-
canWrite: retainCtx.vaultCtx.canWrite,
|
|
20412
|
-
signal
|
|
20413
|
-
});
|
|
20414
|
-
} else if (options.entityCtx && !await isMemoryTopicsUserManaged(options.entityCtx, result.memoryId)) {
|
|
20352
|
+
if (!await isMemoryTopicsUserManaged(options.entityCtx, result.memoryId)) {
|
|
20415
20353
|
await linkMemoryEntitiesOp(options.entityCtx, result.memoryId, candidate.entities, {
|
|
20416
20354
|
unlessTopicsUserManaged: true
|
|
20417
20355
|
});
|
|
@@ -20661,7 +20599,7 @@ function createAutoExtractor(options) {
|
|
|
20661
20599
|
};
|
|
20662
20600
|
const consolidateOptions = options.consolidate ? { ...options.consolidate, ...subPassAuth(options.consolidate.baseUrl) } : void 0;
|
|
20663
20601
|
const injectionClassifierOptions = options.injectionClassifier ? { ...options.injectionClassifier, ...subPassAuth(options.injectionClassifier.baseUrl) } : void 0;
|
|
20664
|
-
if (
|
|
20602
|
+
if (options.retainCtx.vaultCtx.entityCtx && !options.entityCtx) {
|
|
20665
20603
|
getLogger().warn(
|
|
20666
20604
|
"[memory/extract] retainCtx.vaultCtx.entityCtx is set but extractor was created without `entityCtx` \u2014 W5 graph lane will receive no writes"
|
|
20667
20605
|
);
|
|
@@ -20706,8 +20644,6 @@ function createAutoExtractor(options) {
|
|
|
20706
20644
|
try {
|
|
20707
20645
|
const { candidates, results, failedCount, outcome: outcome2, failure, funnel, timings, model } = await extractAndRetain(window2, retainCtx, {
|
|
20708
20646
|
extract,
|
|
20709
|
-
memoryStore: options.memoryStore,
|
|
20710
|
-
signal: options.signal,
|
|
20711
20647
|
...options.minConfidence !== void 0 && { minConfidence: options.minConfidence },
|
|
20712
20648
|
...options.entityCtx !== void 0 && { entityCtx: options.entityCtx },
|
|
20713
20649
|
...options.scope !== void 0 && { scope: options.scope },
|
|
@@ -22839,7 +22775,6 @@ function createLocalMemoryStore(options) {
|
|
|
22839
22775
|
database,
|
|
22840
22776
|
entityCollection: database.get("entity"),
|
|
22841
22777
|
memoryEntityCollection: database.get("memory_entity"),
|
|
22842
|
-
canWrite: options.canWrite,
|
|
22843
22778
|
...userId !== void 0 && { userId },
|
|
22844
22779
|
...options.allowUnscopedRows !== void 0 && {
|
|
22845
22780
|
allowUnscopedRows: options.allowUnscopedRows
|
|
@@ -22851,21 +22786,10 @@ function createLocalMemoryStore(options) {
|
|
|
22851
22786
|
walletAddress: options.walletAddress,
|
|
22852
22787
|
signMessage: options.signMessage,
|
|
22853
22788
|
embeddedWalletSigner: options.embeddedWalletSigner,
|
|
22854
|
-
canWrite: options.canWrite,
|
|
22855
22789
|
...userId !== void 0 && { userId },
|
|
22856
22790
|
...options.singleTenant !== void 0 && { singleTenant: options.singleTenant },
|
|
22857
22791
|
entityCtx
|
|
22858
22792
|
};
|
|
22859
|
-
const assertWrite = async (writeOptions) => {
|
|
22860
|
-
writeOptions?.signal?.throwIfAborted();
|
|
22861
|
-
if (writeOptions?.canWrite && !await writeOptions.canWrite()) {
|
|
22862
|
-
throw new Error("Memory source is no longer eligible");
|
|
22863
|
-
}
|
|
22864
|
-
if (options.canWrite && !await options.canWrite()) {
|
|
22865
|
-
throw new Error("Memory source is no longer eligible");
|
|
22866
|
-
}
|
|
22867
|
-
writeOptions?.signal?.throwIfAborted();
|
|
22868
|
-
};
|
|
22869
22793
|
const vaultCache = options.vaultCache ?? createVaultEmbeddingCache();
|
|
22870
22794
|
const ownedBy = userId !== void 0 ? [import_watermelondb32.Q.where("user_id", userId)] : [];
|
|
22871
22795
|
const linksOwnedBy = userId === void 0 ? [] : options.allowUnscopedRows ? [import_watermelondb32.Q.or(import_watermelondb32.Q.where("user_id", userId), import_watermelondb32.Q.where("user_id", null))] : [import_watermelondb32.Q.where("user_id", userId)];
|
|
@@ -22977,25 +22901,9 @@ function createLocalMemoryStore(options) {
|
|
|
22977
22901
|
archive: (id) => archiveVaultMemoryOp(vaultCtx, id),
|
|
22978
22902
|
restore: (id) => restoreVaultMemoryOp(vaultCtx, id),
|
|
22979
22903
|
setTopics: (memoryId, topics) => setMemoryEntitiesOp(vaultCtx, memoryId, topics),
|
|
22980
|
-
addTopics: (memoryId, topics
|
|
22981
|
-
await assertWrite(writeOptions);
|
|
22904
|
+
addTopics: (memoryId, topics) => database.write(async (writer) => {
|
|
22982
22905
|
const owned = await vaultCtx.vaultMemoryCollection.query(import_watermelondb32.Q.where("id", memoryId), import_watermelondb32.Q.where("is_deleted", false), ...ownedBy).fetchCount();
|
|
22983
|
-
return owned > 0 ? writer.callWriter(
|
|
22984
|
-
() => linkMemoryEntitiesOp(
|
|
22985
|
-
{
|
|
22986
|
-
...entityCtx,
|
|
22987
|
-
canWrite: async () => {
|
|
22988
|
-
await assertWrite(writeOptions);
|
|
22989
|
-
return true;
|
|
22990
|
-
}
|
|
22991
|
-
},
|
|
22992
|
-
memoryId,
|
|
22993
|
-
topics,
|
|
22994
|
-
{
|
|
22995
|
-
unlessTopicsUserManaged: writeOptions?.unlessUserManaged
|
|
22996
|
-
}
|
|
22997
|
-
)
|
|
22998
|
-
) : [];
|
|
22906
|
+
return owned > 0 ? writer.callWriter(() => linkMemoryEntitiesOp(entityCtx, memoryId, topics)) : [];
|
|
22999
22907
|
}),
|
|
23000
22908
|
setVisibility: (id, visibility, visibilityOptions) => setMemoryVisibilityOp(vaultCtx, id, { visibility, ...visibilityOptions }),
|
|
23001
22909
|
recall: (query, recallOptions) => recall(
|
|
@@ -23005,17 +22913,7 @@ function createLocalMemoryStore(options) {
|
|
|
23005
22913
|
),
|
|
23006
22914
|
retain: (content, retainOptions) => retain(
|
|
23007
22915
|
content,
|
|
23008
|
-
{
|
|
23009
|
-
vaultCtx: {
|
|
23010
|
-
...vaultCtx,
|
|
23011
|
-
canWrite: async () => {
|
|
23012
|
-
await assertWrite(retainOptions);
|
|
23013
|
-
return true;
|
|
23014
|
-
}
|
|
23015
|
-
},
|
|
23016
|
-
embeddingOptions: options.embeddingOptions,
|
|
23017
|
-
vaultCache
|
|
23018
|
-
},
|
|
22916
|
+
{ vaultCtx, embeddingOptions: options.embeddingOptions, vaultCache },
|
|
23019
22917
|
retainOptions
|
|
23020
22918
|
),
|
|
23021
22919
|
factSource: {
|
|
@@ -23663,14 +23561,7 @@ function stored(row) {
|
|
|
23663
23561
|
function createRemoteMemoryPipeline(options) {
|
|
23664
23562
|
const { persistence, embeddingOptions } = options;
|
|
23665
23563
|
const model = embeddingOptions.model ?? DEFAULT_API_EMBEDDING_MODEL;
|
|
23666
|
-
const operation = (mode, queryOptions = embeddingOptions
|
|
23667
|
-
const signal = writeOptions?.signal;
|
|
23668
|
-
const assertWrite = async () => {
|
|
23669
|
-
signal?.throwIfAborted();
|
|
23670
|
-
if (writeOptions?.canWrite && !await writeOptions.canWrite())
|
|
23671
|
-
throw new Error("Memory source is no longer eligible");
|
|
23672
|
-
signal?.throwIfAborted();
|
|
23673
|
-
};
|
|
23564
|
+
const operation = (mode, queryOptions = embeddingOptions) => {
|
|
23674
23565
|
const rejectUndecryptable = (failed) => {
|
|
23675
23566
|
if (!failed.length) return;
|
|
23676
23567
|
if (mode === "retain")
|
|
@@ -23688,7 +23579,7 @@ function createRemoteMemoryPipeline(options) {
|
|
|
23688
23579
|
return items.map((item) => stored(item.memory));
|
|
23689
23580
|
};
|
|
23690
23581
|
const get = async (id) => {
|
|
23691
|
-
const snapshot = snapshots.get(id) ?? await
|
|
23582
|
+
const snapshot = snapshots.get(id) ?? await persistence.get(id);
|
|
23692
23583
|
if (!snapshot || snapshot.memory.is_deleted || snapshot.memory.superseded_by) return null;
|
|
23693
23584
|
snapshots.set(id, snapshot);
|
|
23694
23585
|
return stored(snapshot.memory);
|
|
@@ -23738,7 +23629,7 @@ function createRemoteMemoryPipeline(options) {
|
|
|
23738
23629
|
if (forced.size < 100 && temporal[i] !== void 0) forced.add(temporal[i]);
|
|
23739
23630
|
}
|
|
23740
23631
|
const forceIds = [...forced];
|
|
23741
|
-
const windowOptions = (i,
|
|
23632
|
+
const windowOptions = (i, signal) => ({
|
|
23742
23633
|
limit: Math.min(100, Math.max((search.limit ?? 8) * 3, 30)),
|
|
23743
23634
|
force_ids: i === 0 ? forceIds : [],
|
|
23744
23635
|
...search.scopes && { scopes: search.scopes },
|
|
@@ -23746,15 +23637,13 @@ function createRemoteMemoryPipeline(options) {
|
|
|
23746
23637
|
...search.memoryIds !== void 0 && { memory_ids: search.memoryIds },
|
|
23747
23638
|
include_archived: search.includeArchived,
|
|
23748
23639
|
embedding_model: model,
|
|
23749
|
-
...
|
|
23640
|
+
...signal && { signal }
|
|
23750
23641
|
});
|
|
23751
23642
|
const vectors = [queryEmbedding, ...facetEmbeddings];
|
|
23752
23643
|
let windows;
|
|
23753
23644
|
if (mode === "retain") {
|
|
23754
23645
|
windows = await Promise.all(
|
|
23755
|
-
vectors.map(
|
|
23756
|
-
(embedding2, i) => persistence.candidateSet(embedding2, windowOptions(i, signal))
|
|
23757
|
-
)
|
|
23646
|
+
vectors.map((embedding2, i) => persistence.candidateSet(embedding2, windowOptions(i)))
|
|
23758
23647
|
);
|
|
23759
23648
|
} else {
|
|
23760
23649
|
const deadline = new AbortController();
|
|
@@ -23842,15 +23731,12 @@ function createRemoteMemoryPipeline(options) {
|
|
|
23842
23731
|
twin_opt_in: false
|
|
23843
23732
|
};
|
|
23844
23733
|
};
|
|
23845
|
-
const write = async (memory, snapshot) =>
|
|
23846
|
-
await assertWrite();
|
|
23847
|
-
return remember([await persistence.put(memory, snapshot, signal)])[0];
|
|
23848
|
-
};
|
|
23734
|
+
const write = async (memory, snapshot) => remember([await persistence.put(memory, snapshot)])[0];
|
|
23849
23735
|
const port = {
|
|
23850
23736
|
prepare,
|
|
23851
23737
|
get,
|
|
23852
23738
|
getFresh: async (id) => {
|
|
23853
|
-
const current = await
|
|
23739
|
+
const current = await persistence.get(id);
|
|
23854
23740
|
return current && !current.memory.is_deleted && !current.memory.superseded_by ? stored(current.memory) : null;
|
|
23855
23741
|
},
|
|
23856
23742
|
tombstones: async (embedding2, embeddingModel, scope, folderId) => {
|
|
@@ -23861,8 +23747,7 @@ function createRemoteMemoryPipeline(options) {
|
|
|
23861
23747
|
embedding_model: embeddingModel,
|
|
23862
23748
|
strict_model: true,
|
|
23863
23749
|
include_deleted: true,
|
|
23864
|
-
deleted_only: true
|
|
23865
|
-
signal
|
|
23750
|
+
deleted_only: true
|
|
23866
23751
|
});
|
|
23867
23752
|
rejectUndecryptable(window2.failed);
|
|
23868
23753
|
return remember(window2.items);
|
|
@@ -23918,18 +23803,14 @@ function createRemoteMemoryPipeline(options) {
|
|
|
23918
23803
|
if (!target || !newer || id === successor) return false;
|
|
23919
23804
|
const old = snapshots.get(id);
|
|
23920
23805
|
const next = snapshots.get(successor);
|
|
23921
|
-
await assertWrite();
|
|
23922
23806
|
remember(
|
|
23923
|
-
await persistence.putMany(
|
|
23924
|
-
|
|
23925
|
-
{
|
|
23926
|
-
|
|
23927
|
-
|
|
23928
|
-
|
|
23929
|
-
|
|
23930
|
-
],
|
|
23931
|
-
signal
|
|
23932
|
-
)
|
|
23807
|
+
await persistence.putMany([
|
|
23808
|
+
{
|
|
23809
|
+
memory: { ...old.memory, superseded_by: successor, superseded_at: Date.now() },
|
|
23810
|
+
expectedVersion: old
|
|
23811
|
+
},
|
|
23812
|
+
{ memory: next.memory, expectedVersion: next }
|
|
23813
|
+
])
|
|
23933
23814
|
);
|
|
23934
23815
|
return true;
|
|
23935
23816
|
},
|
|
@@ -23938,22 +23819,18 @@ function createRemoteMemoryPipeline(options) {
|
|
|
23938
23819
|
if (!target) return { created: null, retired: false };
|
|
23939
23820
|
const snapshot = snapshots.get(targetId);
|
|
23940
23821
|
const successor = createRow(input);
|
|
23941
|
-
await assertWrite();
|
|
23942
23822
|
const rows = remember(
|
|
23943
|
-
await persistence.putMany(
|
|
23944
|
-
|
|
23945
|
-
|
|
23946
|
-
{
|
|
23947
|
-
memory
|
|
23948
|
-
|
|
23949
|
-
|
|
23950
|
-
|
|
23951
|
-
|
|
23952
|
-
|
|
23953
|
-
|
|
23954
|
-
],
|
|
23955
|
-
signal
|
|
23956
|
-
)
|
|
23823
|
+
await persistence.putMany([
|
|
23824
|
+
{ memory: successor, expectedVersion: 0 },
|
|
23825
|
+
{
|
|
23826
|
+
memory: {
|
|
23827
|
+
...snapshot.memory,
|
|
23828
|
+
superseded_by: successor.memory_id,
|
|
23829
|
+
superseded_at: Date.now()
|
|
23830
|
+
},
|
|
23831
|
+
expectedVersion: snapshot
|
|
23832
|
+
}
|
|
23833
|
+
])
|
|
23957
23834
|
);
|
|
23958
23835
|
return { created: rows[0], retired: true };
|
|
23959
23836
|
}
|
|
@@ -23988,7 +23865,7 @@ function createRemoteMemoryPipeline(options) {
|
|
|
23988
23865
|
factSource,
|
|
23989
23866
|
recall: async (query, recallOptions = {}) => recall(query, { embeddingOptions, factSource }, { ...recallOptions, types: ["fact"] }),
|
|
23990
23867
|
retain: async (content, retainOptions) => {
|
|
23991
|
-
const { port } = operation("retain"
|
|
23868
|
+
const { port } = operation("retain");
|
|
23992
23869
|
return retainWithPersistence(
|
|
23993
23870
|
content,
|
|
23994
23871
|
{
|
|
@@ -24571,21 +24448,16 @@ function createRemoteMemoryStore(options) {
|
|
|
24571
24448
|
const record2 = await persistence.get(id);
|
|
24572
24449
|
return record2 && !record2.memory.is_deleted ? record2 : null;
|
|
24573
24450
|
};
|
|
24574
|
-
const mutateLocked = async (id, change, edit
|
|
24575
|
-
|
|
24576
|
-
const record2 = writeOptions?.signal ? await persistence.get(id, writeOptions.signal) : await live(id);
|
|
24451
|
+
const mutateLocked = async (id, change, edit) => {
|
|
24452
|
+
const record2 = await live(id);
|
|
24577
24453
|
if (!record2) return null;
|
|
24578
|
-
if (record2.memory.is_deleted) return null;
|
|
24579
|
-
if (writeOptions?.canWrite && !await writeOptions.canWrite())
|
|
24580
|
-
throw new Error("Memory source is no longer eligible");
|
|
24581
|
-
writeOptions?.signal?.throwIfAborted();
|
|
24582
24454
|
const next = edit(structuredClone(record2.memory));
|
|
24583
24455
|
if (!next) return null;
|
|
24584
|
-
const saved =
|
|
24456
|
+
const saved = await persistence.put(next, record2);
|
|
24585
24457
|
notify(typeof change === "function" ? change(record2.memory) : change, [saved]);
|
|
24586
24458
|
return saved;
|
|
24587
24459
|
};
|
|
24588
|
-
const mutate = (id, change, edit
|
|
24460
|
+
const mutate = (id, change, edit) => serialized(id, () => mutateLocked(id, change, edit));
|
|
24589
24461
|
const serializedAll = (ids, task) => [...new Set(ids)].sort().reduceRight((inner, id) => () => serialized(id, inner), task)();
|
|
24590
24462
|
const mutateMany = async (ids, change, edit) => {
|
|
24591
24463
|
const saved = /* @__PURE__ */ new Map();
|
|
@@ -25098,21 +24970,13 @@ function createRemoteMemoryStore(options) {
|
|
|
25098
24970
|
}))
|
|
25099
24971
|
);
|
|
25100
24972
|
},
|
|
25101
|
-
addTopics: async (memoryId, topics
|
|
24973
|
+
addTopics: async (memoryId, topics) => {
|
|
25102
24974
|
const added = await withKnownKinds(topicInputs(topics, "auto"));
|
|
25103
|
-
const saved = await mutate(
|
|
25104
|
-
|
|
25105
|
-
|
|
25106
|
-
(
|
|
25107
|
-
|
|
25108
|
-
return {
|
|
25109
|
-
...memory,
|
|
25110
|
-
topics: serializeTopics(mergeTopics(parseTopics(memory.topics) ?? [], added)),
|
|
25111
|
-
topics_updated_at: Date.now()
|
|
25112
|
-
};
|
|
25113
|
-
},
|
|
25114
|
-
writeOptions
|
|
25115
|
-
);
|
|
24975
|
+
const saved = await mutate(memoryId, "edit", (memory) => ({
|
|
24976
|
+
...memory,
|
|
24977
|
+
topics: serializeTopics(mergeTopics(parseTopics(memory.topics) ?? [], added)),
|
|
24978
|
+
topics_updated_at: Date.now()
|
|
24979
|
+
}));
|
|
25116
24980
|
if (!saved) return [];
|
|
25117
24981
|
const now = /* @__PURE__ */ new Date();
|
|
25118
24982
|
return mergeTopics([], added).map(
|
|
@@ -25965,7 +25829,6 @@ function createDurableAutoExtractor(options) {
|
|
|
25965
25829
|
};
|
|
25966
25830
|
const folderId = options.folderId ?? null;
|
|
25967
25831
|
let disposed = false;
|
|
25968
|
-
let activeBatch = null;
|
|
25969
25832
|
let running = false;
|
|
25970
25833
|
let wakeRequested = false;
|
|
25971
25834
|
let timer;
|
|
@@ -26002,18 +25865,14 @@ function createDurableAutoExtractor(options) {
|
|
|
26002
25865
|
}, delay);
|
|
26003
25866
|
}
|
|
26004
25867
|
async function extractBatch(messages, conversationId, ids, jobScope, jobFolderId) {
|
|
26005
|
-
if (disposed) throw new Error("Extraction session was disposed");
|
|
26006
25868
|
let watchdog;
|
|
26007
25869
|
let cancelled = false;
|
|
26008
|
-
const controller = new AbortController();
|
|
26009
|
-
activeBatch = controller;
|
|
26010
25870
|
const model = options.modelForScope?.(jobScope) ?? options.extract.model;
|
|
26011
25871
|
try {
|
|
26012
25872
|
return await Promise.race([
|
|
26013
25873
|
new Promise((resolve, reject) => {
|
|
26014
25874
|
const worker = createAutoExtractor({
|
|
26015
25875
|
...options,
|
|
26016
|
-
signal: controller.signal,
|
|
26017
25876
|
retainCtx: {
|
|
26018
25877
|
...options.retainCtx,
|
|
26019
25878
|
vaultCtx: {
|
|
@@ -26042,8 +25901,6 @@ function createDurableAutoExtractor(options) {
|
|
|
26042
25901
|
]);
|
|
26043
25902
|
} finally {
|
|
26044
25903
|
cancelled = true;
|
|
26045
|
-
controller.abort();
|
|
26046
|
-
if (activeBatch === controller) activeBatch = null;
|
|
26047
25904
|
if (watchdog !== void 0) clearTimeout(watchdog);
|
|
26048
25905
|
}
|
|
26049
25906
|
}
|
|
@@ -26055,7 +25912,6 @@ function createDurableAutoExtractor(options) {
|
|
|
26055
25912
|
for (const message of loaded)
|
|
26056
25913
|
if (message && message.messageId > 0) sequences.set(message.uniqueId, message.messageId);
|
|
26057
25914
|
await database.write(async () => {
|
|
26058
|
-
if (disposed) return;
|
|
26059
25915
|
const current = idsOf(job);
|
|
26060
25916
|
const acknowledged = ids.filter((id) => current.includes(id));
|
|
26061
25917
|
if (!acknowledged.length) return;
|
|
@@ -26228,7 +26084,6 @@ function createDurableAutoExtractor(options) {
|
|
|
26228
26084
|
jobScope,
|
|
26229
26085
|
jobFolderId
|
|
26230
26086
|
);
|
|
26231
|
-
if (disposed) throw new Error("Extraction session was disposed");
|
|
26232
26087
|
options.onTurnComplete?.(result);
|
|
26233
26088
|
return result;
|
|
26234
26089
|
};
|
|
@@ -26265,7 +26120,6 @@ function createDurableAutoExtractor(options) {
|
|
|
26265
26120
|
);
|
|
26266
26121
|
scheduleAfterSuccess = true;
|
|
26267
26122
|
} catch (error) {
|
|
26268
|
-
if (disposed) break;
|
|
26269
26123
|
attempts.set(job.id, attempted + 1);
|
|
26270
26124
|
retry = true;
|
|
26271
26125
|
reportError(error, conversationId);
|
|
@@ -26288,14 +26142,6 @@ function createDurableAutoExtractor(options) {
|
|
|
26288
26142
|
schedule(retry ? options.retryDelayMs ?? 3e4 : 0);
|
|
26289
26143
|
}
|
|
26290
26144
|
}
|
|
26291
|
-
function dispose() {
|
|
26292
|
-
disposed = true;
|
|
26293
|
-
activeBatch?.abort(options.signal?.reason);
|
|
26294
|
-
if (timer !== void 0) clearTimeout(timer);
|
|
26295
|
-
options.signal?.removeEventListener("abort", dispose);
|
|
26296
|
-
}
|
|
26297
|
-
if (options.signal?.aborted) dispose();
|
|
26298
|
-
else options.signal?.addEventListener("abort", dispose, { once: true });
|
|
26299
26145
|
schedule(0);
|
|
26300
26146
|
return {
|
|
26301
26147
|
processTurn(messages, conversationId) {
|
|
@@ -26375,7 +26221,10 @@ function createDurableAutoExtractor(options) {
|
|
|
26375
26221
|
return true;
|
|
26376
26222
|
},
|
|
26377
26223
|
isProcessing: () => running,
|
|
26378
|
-
dispose
|
|
26224
|
+
dispose() {
|
|
26225
|
+
disposed = true;
|
|
26226
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
26227
|
+
}
|
|
26379
26228
|
};
|
|
26380
26229
|
}
|
|
26381
26230
|
|
|
@@ -32645,7 +32494,6 @@ var CONVERSATION_REDACTOR_LIMIT = 50;
|
|
|
32645
32494
|
var NO_CONVERSATION_KEY = "__no_conversation__";
|
|
32646
32495
|
var NO_STORE_FOLDERS = "Folders are not supported with a memoryStore";
|
|
32647
32496
|
var NO_STORE_MASK = "piiRedaction needs a memoryStore built with embeddingOptions.maskInput";
|
|
32648
|
-
var MEMORY_STORE_NOT_READY = "Memory store is not ready";
|
|
32649
32497
|
var conversationRedactors = /* @__PURE__ */ new Map();
|
|
32650
32498
|
function getConversationRedactor(conversationId, nerDetector) {
|
|
32651
32499
|
const key = conversationId ?? NO_CONVERSATION_KEY;
|
|
@@ -32736,7 +32584,7 @@ function useChatStorage(options) {
|
|
|
32736
32584
|
() => ({ getToken, baseUrl, model: embeddingModel, maskInput: maskEmbeddingInput }),
|
|
32737
32585
|
[getToken, baseUrl, embeddingModel, maskEmbeddingInput]
|
|
32738
32586
|
);
|
|
32739
|
-
const storeMaskMissing = memoryStore !== void 0 &&
|
|
32587
|
+
const storeMaskMissing = memoryStore !== void 0 && maskEmbeddingInput !== void 0 && !memoryStore.masksEmbeddingInput;
|
|
32740
32588
|
const blobManagerRef = (0, import_react6.useRef)(new BlobUrlManager());
|
|
32741
32589
|
(0, import_react6.useEffect)(() => {
|
|
32742
32590
|
const manager = blobManagerRef.current;
|
|
@@ -33013,7 +32861,6 @@ function useChatStorage(options) {
|
|
|
33013
32861
|
);
|
|
33014
32862
|
const retainVaultMemory = (0, import_react6.useCallback)(
|
|
33015
32863
|
async (input) => {
|
|
33016
|
-
if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
|
|
33017
32864
|
if (memoryStore) {
|
|
33018
32865
|
if (storeMaskMissing) throw new Error(NO_STORE_MASK);
|
|
33019
32866
|
if (input.folderId !== void 0) throw new Error(NO_STORE_FOLDERS);
|
|
@@ -33045,7 +32892,6 @@ function useChatStorage(options) {
|
|
|
33045
32892
|
);
|
|
33046
32893
|
const createMemoryVaultTool2 = (0, import_react6.useCallback)(
|
|
33047
32894
|
(options2) => {
|
|
33048
|
-
if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
|
|
33049
32895
|
if (storeMaskMissing) throw new Error(NO_STORE_MASK);
|
|
33050
32896
|
const embOpts = getToken ? vaultEmbeddingOptions : void 0;
|
|
33051
32897
|
return createMemoryVaultTool(
|
|
@@ -33067,7 +32913,6 @@ function useChatStorage(options) {
|
|
|
33067
32913
|
);
|
|
33068
32914
|
const getVaultMemories = (0, import_react6.useCallback)(
|
|
33069
32915
|
(options2) => {
|
|
33070
|
-
if (memoryStore === null) return Promise.resolve([]);
|
|
33071
32916
|
if (!memoryStore) return getAllVaultMemoriesOp(vaultCtx, options2);
|
|
33072
32917
|
const { folderId, levels, kinds, ...listOptions } = options2 ?? {};
|
|
33073
32918
|
if (folderId !== void 0) throw new Error(NO_STORE_FOLDERS);
|
|
@@ -33079,7 +32924,6 @@ function useChatStorage(options) {
|
|
|
33079
32924
|
);
|
|
33080
32925
|
const createVaultMemory = (0, import_react6.useCallback)(
|
|
33081
32926
|
async (content, scope) => {
|
|
33082
|
-
if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
|
|
33083
32927
|
if (storeMaskMissing) throw new Error(NO_STORE_MASK);
|
|
33084
32928
|
if (memoryStore) return memoryStore.create({ content, scope });
|
|
33085
32929
|
const result = await createVaultMemoryOp(vaultCtx, { content, scope });
|
|
@@ -33101,7 +32945,6 @@ function useChatStorage(options) {
|
|
|
33101
32945
|
);
|
|
33102
32946
|
const updateVaultMemory = (0, import_react6.useCallback)(
|
|
33103
32947
|
async (id, content, scope) => {
|
|
33104
|
-
if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
|
|
33105
32948
|
if (storeMaskMissing) throw new Error(NO_STORE_MASK);
|
|
33106
32949
|
if (memoryStore) return memoryStore.update(id, { content, scope });
|
|
33107
32950
|
const existing = await getVaultMemoryOp(vaultCtx, id);
|
|
@@ -33127,7 +32970,6 @@ function useChatStorage(options) {
|
|
|
33127
32970
|
);
|
|
33128
32971
|
const deleteVaultMemory = (0, import_react6.useCallback)(
|
|
33129
32972
|
async (id) => {
|
|
33130
|
-
if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
|
|
33131
32973
|
if (memoryStore) return memoryStore.delete(id);
|
|
33132
32974
|
const existing = await getVaultMemoryOp(vaultCtx, id);
|
|
33133
32975
|
const result = await deleteVaultMemoryOp(vaultCtx, id);
|
|
@@ -33141,7 +32983,7 @@ function useChatStorage(options) {
|
|
|
33141
32983
|
const chunkVectorCacheRef = (0, import_react6.useRef)(createChunkVectorCache());
|
|
33142
32984
|
const clientToolEmbeddingsCacheRef = (0, import_react6.useRef)(/* @__PURE__ */ new Map());
|
|
33143
32985
|
(0, import_react6.useEffect)(() => {
|
|
33144
|
-
if (!getToken || memoryStore
|
|
32986
|
+
if (!getToken || memoryStore) return;
|
|
33145
32987
|
void (async () => {
|
|
33146
32988
|
try {
|
|
33147
32989
|
await preEmbedVaultMemories(vaultCtx, vaultEmbeddingOptions, vaultEmbeddingCache);
|
|
@@ -33157,7 +32999,6 @@ function useChatStorage(options) {
|
|
|
33157
32999
|
}, [vaultEmbeddingCache]);
|
|
33158
33000
|
const createMemoryVaultSearchTool2 = (0, import_react6.useCallback)(
|
|
33159
33001
|
(searchOptions) => {
|
|
33160
|
-
if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
|
|
33161
33002
|
if (!getToken && !memoryStore) {
|
|
33162
33003
|
throw new Error("getToken is required for memory vault search tool");
|
|
33163
33004
|
}
|
|
@@ -33173,7 +33014,6 @@ function useChatStorage(options) {
|
|
|
33173
33014
|
);
|
|
33174
33015
|
const createRecallTool2 = (0, import_react6.useCallback)(
|
|
33175
33016
|
(toolOptions, callbacks) => {
|
|
33176
|
-
if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
|
|
33177
33017
|
if (!getToken && !memoryStore) {
|
|
33178
33018
|
throw new Error("getToken is required for recall tool");
|
|
33179
33019
|
}
|
|
@@ -33213,7 +33053,6 @@ function useChatStorage(options) {
|
|
|
33213
33053
|
);
|
|
33214
33054
|
const searchVaultMemoriesFn = (0, import_react6.useCallback)(
|
|
33215
33055
|
async (query, searchOptions) => {
|
|
33216
|
-
if (memoryStore === null) return [];
|
|
33217
33056
|
if (storeMaskMissing) throw new Error(NO_STORE_MASK);
|
|
33218
33057
|
if (memoryStore) return (await memoryStore.factSource.search(query, searchOptions)).results;
|
|
33219
33058
|
if (!getToken) return [];
|
|
@@ -33229,7 +33068,7 @@ function useChatStorage(options) {
|
|
|
33229
33068
|
);
|
|
33230
33069
|
const recallFn = (0, import_react6.useCallback)(
|
|
33231
33070
|
async (query, options2) => {
|
|
33232
|
-
if (
|
|
33071
|
+
if (!getToken && !memoryStore) {
|
|
33233
33072
|
return {
|
|
33234
33073
|
memories: [],
|
|
33235
33074
|
usedBudget: options2?.budget ?? "low",
|