@anuma/sdk 3.9.2 → 3.9.3

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.
@@ -2381,10 +2381,12 @@ async function getAllVaultMemoriesOp(ctx, options) {
2381
2381
  (raw) => vaultMemoryRawToStored(raw, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner)
2382
2382
  );
2383
2383
  }
2384
- function baseVaultSql(ctx) {
2384
+ function baseVaultSql(ctx, options) {
2385
2385
  const clauses = [
2386
2386
  '"is_deleted" = 0',
2387
- '"archived_at" is null',
2387
+ // Mirrors `baseVaultConditions`' `includeArchived` branch. Defaults to
2388
+ // excluding archived rows, so every existing caller is unchanged.
2389
+ ...options?.includeArchived ? [] : ['"archived_at" is null'],
2388
2390
  `"trust_tier" is not 'quarantined'`,
2389
2391
  '"superseded_by" is null'
2390
2392
  ];
@@ -2404,7 +2406,9 @@ async function getVaultCandidateKeysOp(ctx, options) {
2404
2406
  updatedAt: new Date(raw.updated_at)
2405
2407
  });
2406
2408
  try {
2407
- const base = baseVaultSql(ctx);
2409
+ const base = baseVaultSql(ctx, {
2410
+ ...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
2411
+ });
2408
2412
  const clauses = [base.sql];
2409
2413
  const args = [...base.args];
2410
2414
  if (options?.scopes?.length) {
@@ -2415,6 +2419,10 @@ async function getVaultCandidateKeysOp(ctx, options) {
2415
2419
  clauses.push(options.folderId === null ? '"folder_id" is null' : '"folder_id" = ?');
2416
2420
  if (options.folderId !== null) args.push(options.folderId);
2417
2421
  }
2422
+ if (options?.factTypes?.length) {
2423
+ clauses.push(`"fact_type" in (${options.factTypes.map(() => "?").join(",")})`);
2424
+ args.push(...options.factTypes);
2425
+ }
2418
2426
  const sql = `select "id", "scope", "folder_id", "embedding_model", "updated_at" from "memory_vault" where ${clauses.join(" and ")}`;
2419
2427
  const rows = await ctx.vaultMemoryCollection.query(Q3.unsafeSqlQuery(sql, args)).unsafeFetchRaw();
2420
2428
  return rows.map(mapRaw);
@@ -2423,15 +2431,18 @@ async function getVaultCandidateKeysOp(ctx, options) {
2423
2431
  "memoryVault: getVaultCandidateKeysOp projected SQL unavailable, using full-load fallback: " + (err instanceof Error ? err.message : String(err))
2424
2432
  );
2425
2433
  const conditions = [
2426
- ...baseVaultConditions(ctx),
2434
+ ...baseVaultConditions(ctx, {
2435
+ ...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
2436
+ }),
2427
2437
  ...options?.scopes?.length ? [Q3.where("scope", Q3.oneOf(options.scopes))] : [],
2428
- ...options?.folderId !== void 0 ? [Q3.where("folder_id", options.folderId)] : []
2438
+ ...options?.folderId !== void 0 ? [Q3.where("folder_id", options.folderId)] : [],
2439
+ ...options?.factTypes?.length ? [Q3.where("fact_type", Q3.oneOf(options.factTypes))] : []
2429
2440
  ];
2430
2441
  const rows = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
2431
2442
  return rows.map(mapRaw);
2432
2443
  }
2433
2444
  }
2434
- async function getVaultEmbeddingsByIdsOp(ctx, ids) {
2445
+ async function getVaultEmbeddingsByIdsOp(ctx, ids, options) {
2435
2446
  if (ids.length === 0) return [];
2436
2447
  const mapRaw = (raw) => ({
2437
2448
  uniqueId: raw.id,
@@ -2439,7 +2450,9 @@ async function getVaultEmbeddingsByIdsOp(ctx, ids) {
2439
2450
  embeddingModel: raw.embedding_model ?? null
2440
2451
  });
2441
2452
  try {
2442
- const base = baseVaultSql(ctx);
2453
+ const base = baseVaultSql(ctx, {
2454
+ ...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
2455
+ });
2443
2456
  const sql = `select "id", "embedding", "embedding_model" from "memory_vault" where ${base.sql} and "id" in (${ids.map(() => "?").join(",")})`;
2444
2457
  const rows = await ctx.vaultMemoryCollection.query(Q3.unsafeSqlQuery(sql, [...base.args, ...ids])).unsafeFetchRaw();
2445
2458
  return rows.map(mapRaw);
@@ -2447,13 +2460,25 @@ async function getVaultEmbeddingsByIdsOp(ctx, ids) {
2447
2460
  getLogger().debug(
2448
2461
  "memoryVault: getVaultEmbeddingsByIdsOp projected SQL unavailable, using full-load fallback: " + (err instanceof Error ? err.message : String(err))
2449
2462
  );
2450
- const rows = await ctx.vaultMemoryCollection.query(...baseVaultConditions(ctx), Q3.where("id", Q3.oneOf(ids))).unsafeFetchRaw();
2463
+ const rows = await ctx.vaultMemoryCollection.query(
2464
+ ...baseVaultConditions(ctx, {
2465
+ ...options?.includeArchived !== void 0 && {
2466
+ includeArchived: options.includeArchived
2467
+ }
2468
+ }),
2469
+ Q3.where("id", Q3.oneOf(ids))
2470
+ ).unsafeFetchRaw();
2451
2471
  return rows.map(mapRaw);
2452
2472
  }
2453
2473
  }
2454
- async function getVaultMemoriesByIdsOp(ctx, ids) {
2474
+ async function getVaultMemoriesByIdsOp(ctx, ids, options) {
2455
2475
  if (ids.length === 0) return [];
2456
- const conditions = [...baseVaultConditions(ctx), Q3.where("id", Q3.oneOf(ids))];
2476
+ const conditions = [
2477
+ ...baseVaultConditions(ctx, {
2478
+ ...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
2479
+ }),
2480
+ Q3.where("id", Q3.oneOf(ids))
2481
+ ];
2457
2482
  const results = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
2458
2483
  return mapInBatches(
2459
2484
  results,
@@ -5158,6 +5183,7 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
5158
5183
  vaultCtx,
5159
5184
  Object.keys(queryOpts).length > 0 ? queryOpts : void 0
5160
5185
  );
5186
+ const hydrateOpts = queryOpts.includeArchived ? { includeArchived: true } : void 0;
5161
5187
  const vaultSize = keys.length;
5162
5188
  if (keys.length === 0) {
5163
5189
  return { memories: [], embeddedItems: [], queryEmbedding: [], vaultSize: 0 };
@@ -5179,7 +5205,7 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
5179
5205
  else noVectorIds.push(k2.uniqueId);
5180
5206
  }
5181
5207
  if (missIds.length > 0) {
5182
- const rows = await getVaultEmbeddingsByIdsOp(vaultCtx, missIds);
5208
+ const rows = await getVaultEmbeddingsByIdsOp(vaultCtx, missIds, hydrateOpts);
5183
5209
  const gotVector = /* @__PURE__ */ new Set();
5184
5210
  for (const r of rows) {
5185
5211
  if (!r.embedding) continue;
@@ -5204,7 +5230,7 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
5204
5230
  `memoryVault: projected search un-embedded lane capped at ${laneIds.length}/${noVectorIds.length}`
5205
5231
  );
5206
5232
  }
5207
- const laneRows = (await getVaultMemoriesByIdsOp(vaultCtx, laneIds)).filter(
5233
+ const laneRows = (await getVaultMemoriesByIdsOp(vaultCtx, laneIds, hydrateOpts)).filter(
5208
5234
  (m) => !isEncrypted(m.content)
5209
5235
  );
5210
5236
  if (laneRows.length > 0) {
@@ -5234,7 +5260,7 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
5234
5260
  if (keyById.has(id)) admissionSet.add(id);
5235
5261
  }
5236
5262
  }
5237
- const admittedRows = await getVaultMemoriesByIdsOp(vaultCtx, [...admissionSet]);
5263
+ const admittedRows = await getVaultMemoriesByIdsOp(vaultCtx, [...admissionSet], hydrateOpts);
5238
5264
  const memories = admittedRows.filter((m) => !isEncrypted(m.content));
5239
5265
  if (memories.length < admittedRows.length) {
5240
5266
  getLogger().warn(
@@ -5598,7 +5624,7 @@ function createMemoryVaultSearchTool(vaultCtx, embeddingOptions, cache, searchOp
5598
5624
  legacy.map((r) => ({ id: r.uniqueId, content: r.content, score: r.similarity }))
5599
5625
  );
5600
5626
  }
5601
- const { recall: recall2 } = await import("./recall-KWTVD4IR.mjs");
5627
+ const { recall: recall2 } = await import("./recall-RSLYPJ5L.mjs");
5602
5628
  const result = await recall2(
5603
5629
  query,
5604
5630
  { vaultCtx, embeddingOptions, vaultCache: cache },
@@ -4622,10 +4622,12 @@ async function getAllVaultMemoriesOp(ctx, options) {
4622
4622
  (raw) => vaultMemoryRawToStored(raw, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner)
4623
4623
  );
4624
4624
  }
4625
- function baseVaultSql(ctx) {
4625
+ function baseVaultSql(ctx, options) {
4626
4626
  const clauses = [
4627
4627
  '"is_deleted" = 0',
4628
- '"archived_at" is null',
4628
+ // Mirrors `baseVaultConditions`' `includeArchived` branch. Defaults to
4629
+ // excluding archived rows, so every existing caller is unchanged.
4630
+ ...options?.includeArchived ? [] : ['"archived_at" is null'],
4629
4631
  `"trust_tier" is not 'quarantined'`,
4630
4632
  '"superseded_by" is null'
4631
4633
  ];
@@ -4645,7 +4647,9 @@ async function getVaultCandidateKeysOp(ctx, options) {
4645
4647
  updatedAt: new Date(raw.updated_at)
4646
4648
  });
4647
4649
  try {
4648
- const base = baseVaultSql(ctx);
4650
+ const base = baseVaultSql(ctx, {
4651
+ ...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
4652
+ });
4649
4653
  const clauses = [base.sql];
4650
4654
  const args = [...base.args];
4651
4655
  if (options?.scopes?.length) {
@@ -4656,6 +4660,10 @@ async function getVaultCandidateKeysOp(ctx, options) {
4656
4660
  clauses.push(options.folderId === null ? '"folder_id" is null' : '"folder_id" = ?');
4657
4661
  if (options.folderId !== null) args.push(options.folderId);
4658
4662
  }
4663
+ if (options?.factTypes?.length) {
4664
+ clauses.push(`"fact_type" in (${options.factTypes.map(() => "?").join(",")})`);
4665
+ args.push(...options.factTypes);
4666
+ }
4659
4667
  const sql = `select "id", "scope", "folder_id", "embedding_model", "updated_at" from "memory_vault" where ${clauses.join(" and ")}`;
4660
4668
  const rows = await ctx.vaultMemoryCollection.query(import_watermelondb9.Q.unsafeSqlQuery(sql, args)).unsafeFetchRaw();
4661
4669
  return rows.map(mapRaw);
@@ -4664,15 +4672,18 @@ async function getVaultCandidateKeysOp(ctx, options) {
4664
4672
  "memoryVault: getVaultCandidateKeysOp projected SQL unavailable, using full-load fallback: " + (err instanceof Error ? err.message : String(err))
4665
4673
  );
4666
4674
  const conditions = [
4667
- ...baseVaultConditions(ctx),
4675
+ ...baseVaultConditions(ctx, {
4676
+ ...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
4677
+ }),
4668
4678
  ...options?.scopes?.length ? [import_watermelondb9.Q.where("scope", import_watermelondb9.Q.oneOf(options.scopes))] : [],
4669
- ...options?.folderId !== void 0 ? [import_watermelondb9.Q.where("folder_id", options.folderId)] : []
4679
+ ...options?.folderId !== void 0 ? [import_watermelondb9.Q.where("folder_id", options.folderId)] : [],
4680
+ ...options?.factTypes?.length ? [import_watermelondb9.Q.where("fact_type", import_watermelondb9.Q.oneOf(options.factTypes))] : []
4670
4681
  ];
4671
4682
  const rows = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
4672
4683
  return rows.map(mapRaw);
4673
4684
  }
4674
4685
  }
4675
- async function getVaultEmbeddingsByIdsOp(ctx, ids) {
4686
+ async function getVaultEmbeddingsByIdsOp(ctx, ids, options) {
4676
4687
  if (ids.length === 0) return [];
4677
4688
  const mapRaw = (raw) => ({
4678
4689
  uniqueId: raw.id,
@@ -4680,7 +4691,9 @@ async function getVaultEmbeddingsByIdsOp(ctx, ids) {
4680
4691
  embeddingModel: raw.embedding_model ?? null
4681
4692
  });
4682
4693
  try {
4683
- const base = baseVaultSql(ctx);
4694
+ const base = baseVaultSql(ctx, {
4695
+ ...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
4696
+ });
4684
4697
  const sql = `select "id", "embedding", "embedding_model" from "memory_vault" where ${base.sql} and "id" in (${ids.map(() => "?").join(",")})`;
4685
4698
  const rows = await ctx.vaultMemoryCollection.query(import_watermelondb9.Q.unsafeSqlQuery(sql, [...base.args, ...ids])).unsafeFetchRaw();
4686
4699
  return rows.map(mapRaw);
@@ -4688,13 +4701,25 @@ async function getVaultEmbeddingsByIdsOp(ctx, ids) {
4688
4701
  getLogger().debug(
4689
4702
  "memoryVault: getVaultEmbeddingsByIdsOp projected SQL unavailable, using full-load fallback: " + (err instanceof Error ? err.message : String(err))
4690
4703
  );
4691
- const rows = await ctx.vaultMemoryCollection.query(...baseVaultConditions(ctx), import_watermelondb9.Q.where("id", import_watermelondb9.Q.oneOf(ids))).unsafeFetchRaw();
4704
+ const rows = await ctx.vaultMemoryCollection.query(
4705
+ ...baseVaultConditions(ctx, {
4706
+ ...options?.includeArchived !== void 0 && {
4707
+ includeArchived: options.includeArchived
4708
+ }
4709
+ }),
4710
+ import_watermelondb9.Q.where("id", import_watermelondb9.Q.oneOf(ids))
4711
+ ).unsafeFetchRaw();
4692
4712
  return rows.map(mapRaw);
4693
4713
  }
4694
4714
  }
4695
- async function getVaultMemoriesByIdsOp(ctx, ids) {
4715
+ async function getVaultMemoriesByIdsOp(ctx, ids, options) {
4696
4716
  if (ids.length === 0) return [];
4697
- const conditions = [...baseVaultConditions(ctx), import_watermelondb9.Q.where("id", import_watermelondb9.Q.oneOf(ids))];
4717
+ const conditions = [
4718
+ ...baseVaultConditions(ctx, {
4719
+ ...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
4720
+ }),
4721
+ import_watermelondb9.Q.where("id", import_watermelondb9.Q.oneOf(ids))
4722
+ ];
4698
4723
  const results = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
4699
4724
  return mapInBatches(
4700
4725
  results,
@@ -7277,6 +7302,7 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
7277
7302
  vaultCtx,
7278
7303
  Object.keys(queryOpts).length > 0 ? queryOpts : void 0
7279
7304
  );
7305
+ const hydrateOpts = queryOpts.includeArchived ? { includeArchived: true } : void 0;
7280
7306
  const vaultSize = keys.length;
7281
7307
  if (keys.length === 0) {
7282
7308
  return { memories: [], embeddedItems: [], queryEmbedding: [], vaultSize: 0 };
@@ -7298,7 +7324,7 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
7298
7324
  else noVectorIds.push(k2.uniqueId);
7299
7325
  }
7300
7326
  if (missIds.length > 0) {
7301
- const rows = await getVaultEmbeddingsByIdsOp(vaultCtx, missIds);
7327
+ const rows = await getVaultEmbeddingsByIdsOp(vaultCtx, missIds, hydrateOpts);
7302
7328
  const gotVector = /* @__PURE__ */ new Set();
7303
7329
  for (const r of rows) {
7304
7330
  if (!r.embedding) continue;
@@ -7323,7 +7349,7 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
7323
7349
  `memoryVault: projected search un-embedded lane capped at ${laneIds.length}/${noVectorIds.length}`
7324
7350
  );
7325
7351
  }
7326
- const laneRows = (await getVaultMemoriesByIdsOp(vaultCtx, laneIds)).filter(
7352
+ const laneRows = (await getVaultMemoriesByIdsOp(vaultCtx, laneIds, hydrateOpts)).filter(
7327
7353
  (m) => !isEncrypted(m.content)
7328
7354
  );
7329
7355
  if (laneRows.length > 0) {
@@ -7353,7 +7379,7 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
7353
7379
  if (keyById.has(id)) admissionSet.add(id);
7354
7380
  }
7355
7381
  }
7356
- const admittedRows = await getVaultMemoriesByIdsOp(vaultCtx, [...admissionSet]);
7382
+ const admittedRows = await getVaultMemoriesByIdsOp(vaultCtx, [...admissionSet], hydrateOpts);
7357
7383
  const memories = admittedRows.filter((m) => !isEncrypted(m.content));
7358
7384
  if (memories.length < admittedRows.length) {
7359
7385
  getLogger().warn(
@@ -108,7 +108,7 @@ import {
108
108
  upsertMessageOp,
109
109
  useEncryption,
110
110
  vaultMemoryToStored
111
- } from "./chunk-YFJAHJMB.mjs";
111
+ } from "./chunk-UQQCL7KP.mjs";
112
112
  import {
113
113
  PII_PATTERNS,
114
114
  PiiRedactor,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  recall
3
- } from "./chunk-YFJAHJMB.mjs";
3
+ } from "./chunk-UQQCL7KP.mjs";
4
4
  import "./chunk-BOY27A2C.mjs";
5
5
  import "./chunk-GYKJOWEO.mjs";
6
6
  export {
@@ -2554,10 +2554,12 @@ async function getVaultRankingProjectionsOp(ctx, options) {
2554
2554
  const results = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
2555
2555
  return results.map(vaultMemoryRawToRankable);
2556
2556
  }
2557
- function baseVaultSql(ctx) {
2557
+ function baseVaultSql(ctx, options) {
2558
2558
  const clauses = [
2559
2559
  '"is_deleted" = 0',
2560
- '"archived_at" is null',
2560
+ // Mirrors `baseVaultConditions`' `includeArchived` branch. Defaults to
2561
+ // excluding archived rows, so every existing caller is unchanged.
2562
+ ...options?.includeArchived ? [] : ['"archived_at" is null'],
2561
2563
  `"trust_tier" is not 'quarantined'`,
2562
2564
  '"superseded_by" is null'
2563
2565
  ];
@@ -2577,7 +2579,9 @@ async function getVaultCandidateKeysOp(ctx, options) {
2577
2579
  updatedAt: new Date(raw.updated_at)
2578
2580
  });
2579
2581
  try {
2580
- const base = baseVaultSql(ctx);
2582
+ const base = baseVaultSql(ctx, {
2583
+ ...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
2584
+ });
2581
2585
  const clauses = [base.sql];
2582
2586
  const args = [...base.args];
2583
2587
  if (options?.scopes?.length) {
@@ -2588,6 +2592,10 @@ async function getVaultCandidateKeysOp(ctx, options) {
2588
2592
  clauses.push(options.folderId === null ? '"folder_id" is null' : '"folder_id" = ?');
2589
2593
  if (options.folderId !== null) args.push(options.folderId);
2590
2594
  }
2595
+ if (options?.factTypes?.length) {
2596
+ clauses.push(`"fact_type" in (${options.factTypes.map(() => "?").join(",")})`);
2597
+ args.push(...options.factTypes);
2598
+ }
2591
2599
  const sql = `select "id", "scope", "folder_id", "embedding_model", "updated_at" from "memory_vault" where ${clauses.join(" and ")}`;
2592
2600
  const rows = await ctx.vaultMemoryCollection.query(Q3.unsafeSqlQuery(sql, args)).unsafeFetchRaw();
2593
2601
  return rows.map(mapRaw);
@@ -2596,15 +2604,18 @@ async function getVaultCandidateKeysOp(ctx, options) {
2596
2604
  "memoryVault: getVaultCandidateKeysOp projected SQL unavailable, using full-load fallback: " + (err instanceof Error ? err.message : String(err))
2597
2605
  );
2598
2606
  const conditions = [
2599
- ...baseVaultConditions(ctx),
2607
+ ...baseVaultConditions(ctx, {
2608
+ ...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
2609
+ }),
2600
2610
  ...options?.scopes?.length ? [Q3.where("scope", Q3.oneOf(options.scopes))] : [],
2601
- ...options?.folderId !== void 0 ? [Q3.where("folder_id", options.folderId)] : []
2611
+ ...options?.folderId !== void 0 ? [Q3.where("folder_id", options.folderId)] : [],
2612
+ ...options?.factTypes?.length ? [Q3.where("fact_type", Q3.oneOf(options.factTypes))] : []
2602
2613
  ];
2603
2614
  const rows = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
2604
2615
  return rows.map(mapRaw);
2605
2616
  }
2606
2617
  }
2607
- async function getVaultEmbeddingsByIdsOp(ctx, ids) {
2618
+ async function getVaultEmbeddingsByIdsOp(ctx, ids, options) {
2608
2619
  if (ids.length === 0) return [];
2609
2620
  const mapRaw = (raw) => ({
2610
2621
  uniqueId: raw.id,
@@ -2612,7 +2623,9 @@ async function getVaultEmbeddingsByIdsOp(ctx, ids) {
2612
2623
  embeddingModel: raw.embedding_model ?? null
2613
2624
  });
2614
2625
  try {
2615
- const base = baseVaultSql(ctx);
2626
+ const base = baseVaultSql(ctx, {
2627
+ ...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
2628
+ });
2616
2629
  const sql = `select "id", "embedding", "embedding_model" from "memory_vault" where ${base.sql} and "id" in (${ids.map(() => "?").join(",")})`;
2617
2630
  const rows = await ctx.vaultMemoryCollection.query(Q3.unsafeSqlQuery(sql, [...base.args, ...ids])).unsafeFetchRaw();
2618
2631
  return rows.map(mapRaw);
@@ -2620,13 +2633,25 @@ async function getVaultEmbeddingsByIdsOp(ctx, ids) {
2620
2633
  getLogger().debug(
2621
2634
  "memoryVault: getVaultEmbeddingsByIdsOp projected SQL unavailable, using full-load fallback: " + (err instanceof Error ? err.message : String(err))
2622
2635
  );
2623
- const rows = await ctx.vaultMemoryCollection.query(...baseVaultConditions(ctx), Q3.where("id", Q3.oneOf(ids))).unsafeFetchRaw();
2636
+ const rows = await ctx.vaultMemoryCollection.query(
2637
+ ...baseVaultConditions(ctx, {
2638
+ ...options?.includeArchived !== void 0 && {
2639
+ includeArchived: options.includeArchived
2640
+ }
2641
+ }),
2642
+ Q3.where("id", Q3.oneOf(ids))
2643
+ ).unsafeFetchRaw();
2624
2644
  return rows.map(mapRaw);
2625
2645
  }
2626
2646
  }
2627
- async function getVaultMemoriesByIdsOp(ctx, ids) {
2647
+ async function getVaultMemoriesByIdsOp(ctx, ids, options) {
2628
2648
  if (ids.length === 0) return [];
2629
- const conditions = [...baseVaultConditions(ctx), Q3.where("id", Q3.oneOf(ids))];
2649
+ const conditions = [
2650
+ ...baseVaultConditions(ctx, {
2651
+ ...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
2652
+ }),
2653
+ Q3.where("id", Q3.oneOf(ids))
2654
+ ];
2630
2655
  const results = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
2631
2656
  return mapInBatches(
2632
2657
  results,
@@ -5459,6 +5484,7 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
5459
5484
  vaultCtx,
5460
5485
  Object.keys(queryOpts).length > 0 ? queryOpts : void 0
5461
5486
  );
5487
+ const hydrateOpts = queryOpts.includeArchived ? { includeArchived: true } : void 0;
5462
5488
  const vaultSize = keys.length;
5463
5489
  if (keys.length === 0) {
5464
5490
  return { memories: [], embeddedItems: [], queryEmbedding: [], vaultSize: 0 };
@@ -5480,7 +5506,7 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
5480
5506
  else noVectorIds.push(k2.uniqueId);
5481
5507
  }
5482
5508
  if (missIds.length > 0) {
5483
- const rows = await getVaultEmbeddingsByIdsOp(vaultCtx, missIds);
5509
+ const rows = await getVaultEmbeddingsByIdsOp(vaultCtx, missIds, hydrateOpts);
5484
5510
  const gotVector = /* @__PURE__ */ new Set();
5485
5511
  for (const r of rows) {
5486
5512
  if (!r.embedding) continue;
@@ -5505,7 +5531,7 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
5505
5531
  `memoryVault: projected search un-embedded lane capped at ${laneIds.length}/${noVectorIds.length}`
5506
5532
  );
5507
5533
  }
5508
- const laneRows = (await getVaultMemoriesByIdsOp(vaultCtx, laneIds)).filter(
5534
+ const laneRows = (await getVaultMemoriesByIdsOp(vaultCtx, laneIds, hydrateOpts)).filter(
5509
5535
  (m) => !isEncrypted(m.content)
5510
5536
  );
5511
5537
  if (laneRows.length > 0) {
@@ -5535,7 +5561,7 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
5535
5561
  if (keyById.has(id)) admissionSet.add(id);
5536
5562
  }
5537
5563
  }
5538
- const admittedRows = await getVaultMemoriesByIdsOp(vaultCtx, [...admissionSet]);
5564
+ const admittedRows = await getVaultMemoriesByIdsOp(vaultCtx, [...admissionSet], hydrateOpts);
5539
5565
  const memories = admittedRows.filter((m) => !isEncrypted(m.content));
5540
5566
  if (memories.length < admittedRows.length) {
5541
5567
  getLogger().warn(
@@ -5899,7 +5925,7 @@ function createMemoryVaultSearchTool(vaultCtx, embeddingOptions, cache, searchOp
5899
5925
  legacy.map((r) => ({ id: r.uniqueId, content: r.content, score: r.similarity }))
5900
5926
  );
5901
5927
  }
5902
- const { recall: recall2 } = await import("./recall-SBQ4LNRJ.mjs");
5928
+ const { recall: recall2 } = await import("./recall-UCCIEG37.mjs");
5903
5929
  const result = await recall2(
5904
5930
  query,
5905
5931
  { vaultCtx, embeddingOptions, vaultCache: cache },
@@ -4866,10 +4866,12 @@ async function getVaultRankingProjectionsOp(ctx, options) {
4866
4866
  const results = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
4867
4867
  return results.map(vaultMemoryRawToRankable);
4868
4868
  }
4869
- function baseVaultSql(ctx) {
4869
+ function baseVaultSql(ctx, options) {
4870
4870
  const clauses = [
4871
4871
  '"is_deleted" = 0',
4872
- '"archived_at" is null',
4872
+ // Mirrors `baseVaultConditions`' `includeArchived` branch. Defaults to
4873
+ // excluding archived rows, so every existing caller is unchanged.
4874
+ ...options?.includeArchived ? [] : ['"archived_at" is null'],
4873
4875
  `"trust_tier" is not 'quarantined'`,
4874
4876
  '"superseded_by" is null'
4875
4877
  ];
@@ -4889,7 +4891,9 @@ async function getVaultCandidateKeysOp(ctx, options) {
4889
4891
  updatedAt: new Date(raw.updated_at)
4890
4892
  });
4891
4893
  try {
4892
- const base = baseVaultSql(ctx);
4894
+ const base = baseVaultSql(ctx, {
4895
+ ...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
4896
+ });
4893
4897
  const clauses = [base.sql];
4894
4898
  const args = [...base.args];
4895
4899
  if (options?.scopes?.length) {
@@ -4900,6 +4904,10 @@ async function getVaultCandidateKeysOp(ctx, options) {
4900
4904
  clauses.push(options.folderId === null ? '"folder_id" is null' : '"folder_id" = ?');
4901
4905
  if (options.folderId !== null) args.push(options.folderId);
4902
4906
  }
4907
+ if (options?.factTypes?.length) {
4908
+ clauses.push(`"fact_type" in (${options.factTypes.map(() => "?").join(",")})`);
4909
+ args.push(...options.factTypes);
4910
+ }
4903
4911
  const sql = `select "id", "scope", "folder_id", "embedding_model", "updated_at" from "memory_vault" where ${clauses.join(" and ")}`;
4904
4912
  const rows = await ctx.vaultMemoryCollection.query(import_watermelondb10.Q.unsafeSqlQuery(sql, args)).unsafeFetchRaw();
4905
4913
  return rows.map(mapRaw);
@@ -4908,15 +4916,18 @@ async function getVaultCandidateKeysOp(ctx, options) {
4908
4916
  "memoryVault: getVaultCandidateKeysOp projected SQL unavailable, using full-load fallback: " + (err instanceof Error ? err.message : String(err))
4909
4917
  );
4910
4918
  const conditions = [
4911
- ...baseVaultConditions(ctx),
4919
+ ...baseVaultConditions(ctx, {
4920
+ ...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
4921
+ }),
4912
4922
  ...options?.scopes?.length ? [import_watermelondb10.Q.where("scope", import_watermelondb10.Q.oneOf(options.scopes))] : [],
4913
- ...options?.folderId !== void 0 ? [import_watermelondb10.Q.where("folder_id", options.folderId)] : []
4923
+ ...options?.folderId !== void 0 ? [import_watermelondb10.Q.where("folder_id", options.folderId)] : [],
4924
+ ...options?.factTypes?.length ? [import_watermelondb10.Q.where("fact_type", import_watermelondb10.Q.oneOf(options.factTypes))] : []
4914
4925
  ];
4915
4926
  const rows = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
4916
4927
  return rows.map(mapRaw);
4917
4928
  }
4918
4929
  }
4919
- async function getVaultEmbeddingsByIdsOp(ctx, ids) {
4930
+ async function getVaultEmbeddingsByIdsOp(ctx, ids, options) {
4920
4931
  if (ids.length === 0) return [];
4921
4932
  const mapRaw = (raw) => ({
4922
4933
  uniqueId: raw.id,
@@ -4924,7 +4935,9 @@ async function getVaultEmbeddingsByIdsOp(ctx, ids) {
4924
4935
  embeddingModel: raw.embedding_model ?? null
4925
4936
  });
4926
4937
  try {
4927
- const base = baseVaultSql(ctx);
4938
+ const base = baseVaultSql(ctx, {
4939
+ ...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
4940
+ });
4928
4941
  const sql = `select "id", "embedding", "embedding_model" from "memory_vault" where ${base.sql} and "id" in (${ids.map(() => "?").join(",")})`;
4929
4942
  const rows = await ctx.vaultMemoryCollection.query(import_watermelondb10.Q.unsafeSqlQuery(sql, [...base.args, ...ids])).unsafeFetchRaw();
4930
4943
  return rows.map(mapRaw);
@@ -4932,13 +4945,25 @@ async function getVaultEmbeddingsByIdsOp(ctx, ids) {
4932
4945
  getLogger().debug(
4933
4946
  "memoryVault: getVaultEmbeddingsByIdsOp projected SQL unavailable, using full-load fallback: " + (err instanceof Error ? err.message : String(err))
4934
4947
  );
4935
- const rows = await ctx.vaultMemoryCollection.query(...baseVaultConditions(ctx), import_watermelondb10.Q.where("id", import_watermelondb10.Q.oneOf(ids))).unsafeFetchRaw();
4948
+ const rows = await ctx.vaultMemoryCollection.query(
4949
+ ...baseVaultConditions(ctx, {
4950
+ ...options?.includeArchived !== void 0 && {
4951
+ includeArchived: options.includeArchived
4952
+ }
4953
+ }),
4954
+ import_watermelondb10.Q.where("id", import_watermelondb10.Q.oneOf(ids))
4955
+ ).unsafeFetchRaw();
4936
4956
  return rows.map(mapRaw);
4937
4957
  }
4938
4958
  }
4939
- async function getVaultMemoriesByIdsOp(ctx, ids) {
4959
+ async function getVaultMemoriesByIdsOp(ctx, ids, options) {
4940
4960
  if (ids.length === 0) return [];
4941
- const conditions = [...baseVaultConditions(ctx), import_watermelondb10.Q.where("id", import_watermelondb10.Q.oneOf(ids))];
4961
+ const conditions = [
4962
+ ...baseVaultConditions(ctx, {
4963
+ ...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
4964
+ }),
4965
+ import_watermelondb10.Q.where("id", import_watermelondb10.Q.oneOf(ids))
4966
+ ];
4942
4967
  const results = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
4943
4968
  return mapInBatches(
4944
4969
  results,
@@ -7578,6 +7603,7 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
7578
7603
  vaultCtx,
7579
7604
  Object.keys(queryOpts).length > 0 ? queryOpts : void 0
7580
7605
  );
7606
+ const hydrateOpts = queryOpts.includeArchived ? { includeArchived: true } : void 0;
7581
7607
  const vaultSize = keys.length;
7582
7608
  if (keys.length === 0) {
7583
7609
  return { memories: [], embeddedItems: [], queryEmbedding: [], vaultSize: 0 };
@@ -7599,7 +7625,7 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
7599
7625
  else noVectorIds.push(k2.uniqueId);
7600
7626
  }
7601
7627
  if (missIds.length > 0) {
7602
- const rows = await getVaultEmbeddingsByIdsOp(vaultCtx, missIds);
7628
+ const rows = await getVaultEmbeddingsByIdsOp(vaultCtx, missIds, hydrateOpts);
7603
7629
  const gotVector = /* @__PURE__ */ new Set();
7604
7630
  for (const r of rows) {
7605
7631
  if (!r.embedding) continue;
@@ -7624,7 +7650,7 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
7624
7650
  `memoryVault: projected search un-embedded lane capped at ${laneIds.length}/${noVectorIds.length}`
7625
7651
  );
7626
7652
  }
7627
- const laneRows = (await getVaultMemoriesByIdsOp(vaultCtx, laneIds)).filter(
7653
+ const laneRows = (await getVaultMemoriesByIdsOp(vaultCtx, laneIds, hydrateOpts)).filter(
7628
7654
  (m) => !isEncrypted(m.content)
7629
7655
  );
7630
7656
  if (laneRows.length > 0) {
@@ -7654,7 +7680,7 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
7654
7680
  if (keyById.has(id)) admissionSet.add(id);
7655
7681
  }
7656
7682
  }
7657
- const admittedRows = await getVaultMemoriesByIdsOp(vaultCtx, [...admissionSet]);
7683
+ const admittedRows = await getVaultMemoriesByIdsOp(vaultCtx, [...admissionSet], hydrateOpts);
7658
7684
  const memories = admittedRows.filter((m) => !isEncrypted(m.content));
7659
7685
  if (memories.length < admittedRows.length) {
7660
7686
  getLogger().warn(
@@ -7243,6 +7243,16 @@ interface VaultCandidateKey {
7243
7243
  declare function getVaultCandidateKeysOp(ctx: VaultMemoryOperationsContext, options?: {
7244
7244
  scopes?: string[];
7245
7245
  folderId?: string | null;
7246
+ /**
7247
+ * Typed memory (PR1) — restrict to these fact types. Omit for no filter.
7248
+ * MUST stay in step with `getAllVaultMemoriesOp`: this op backs the
7249
+ * decrypt-last search path, and the two paths are meant to return the same
7250
+ * candidate set for the same query. Dropping it here made typed recall
7251
+ * silently path-dependent (#779).
7252
+ */
7253
+ factTypes?: string[];
7254
+ /** Include archived (decayed) memories. Default `false`, as elsewhere. */
7255
+ includeArchived?: boolean;
7246
7256
  }): Promise<VaultCandidateKey[]>;
7247
7257
  /**
7248
7258
  * Column-projected embedding lookup for a KNOWN set of ids — id + embedding +
@@ -7252,7 +7262,16 @@ declare function getVaultCandidateKeysOp(ctx: VaultMemoryOperationsContext, opti
7252
7262
  * OPFS-SQLite, falling back to the standard Q query + unsafeFetchRaw on
7253
7263
  * LokiJS (Q.unsafeSqlQuery throws there).
7254
7264
  */
7255
- declare function getVaultEmbeddingsByIdsOp(ctx: VaultMemoryOperationsContext, ids: string[]): Promise<Array<{
7265
+ declare function getVaultEmbeddingsByIdsOp(ctx: VaultMemoryOperationsContext, ids: string[],
7266
+ /**
7267
+ * Must match whatever admitted these ids. The caller has already filtered the
7268
+ * candidate set; re-applying a DEFAULT-ON exclusion here silently deletes rows
7269
+ * it deliberately admitted — which is how archived rows passed the key scan
7270
+ * and then vanished at hydration (#779).
7271
+ */
7272
+ options?: {
7273
+ includeArchived?: boolean;
7274
+ }): Promise<Array<{
7256
7275
  uniqueId: string;
7257
7276
  embedding: string | null;
7258
7277
  embeddingModel: string | null;
@@ -7270,7 +7289,11 @@ declare function getVaultEmbeddingsByIdsOp(ctx: VaultMemoryOperationsContext, id
7270
7289
  * excluded exactly as they are from recall — a caller can pass any id list and
7271
7290
  * only its own live rows come back.
7272
7291
  */
7273
- declare function getVaultMemoriesByIdsOp(ctx: VaultMemoryOperationsContext, ids: string[]): Promise<StoredVaultMemory[]>;
7292
+ declare function getVaultMemoriesByIdsOp(ctx: VaultMemoryOperationsContext, ids: string[],
7293
+ /** See {@link getVaultEmbeddingsByIdsOp} — must match what admitted these ids. */
7294
+ options?: {
7295
+ includeArchived?: boolean;
7296
+ }): Promise<StoredVaultMemory[]>;
7274
7297
  declare function getAllVaultMemoryContentsOp(ctx: VaultMemoryOperationsContext, options?: {
7275
7298
  since?: Date;
7276
7299
  }): Promise<string[]>;
@@ -7243,6 +7243,16 @@ interface VaultCandidateKey {
7243
7243
  declare function getVaultCandidateKeysOp(ctx: VaultMemoryOperationsContext, options?: {
7244
7244
  scopes?: string[];
7245
7245
  folderId?: string | null;
7246
+ /**
7247
+ * Typed memory (PR1) — restrict to these fact types. Omit for no filter.
7248
+ * MUST stay in step with `getAllVaultMemoriesOp`: this op backs the
7249
+ * decrypt-last search path, and the two paths are meant to return the same
7250
+ * candidate set for the same query. Dropping it here made typed recall
7251
+ * silently path-dependent (#779).
7252
+ */
7253
+ factTypes?: string[];
7254
+ /** Include archived (decayed) memories. Default `false`, as elsewhere. */
7255
+ includeArchived?: boolean;
7246
7256
  }): Promise<VaultCandidateKey[]>;
7247
7257
  /**
7248
7258
  * Column-projected embedding lookup for a KNOWN set of ids — id + embedding +
@@ -7252,7 +7262,16 @@ declare function getVaultCandidateKeysOp(ctx: VaultMemoryOperationsContext, opti
7252
7262
  * OPFS-SQLite, falling back to the standard Q query + unsafeFetchRaw on
7253
7263
  * LokiJS (Q.unsafeSqlQuery throws there).
7254
7264
  */
7255
- declare function getVaultEmbeddingsByIdsOp(ctx: VaultMemoryOperationsContext, ids: string[]): Promise<Array<{
7265
+ declare function getVaultEmbeddingsByIdsOp(ctx: VaultMemoryOperationsContext, ids: string[],
7266
+ /**
7267
+ * Must match whatever admitted these ids. The caller has already filtered the
7268
+ * candidate set; re-applying a DEFAULT-ON exclusion here silently deletes rows
7269
+ * it deliberately admitted — which is how archived rows passed the key scan
7270
+ * and then vanished at hydration (#779).
7271
+ */
7272
+ options?: {
7273
+ includeArchived?: boolean;
7274
+ }): Promise<Array<{
7256
7275
  uniqueId: string;
7257
7276
  embedding: string | null;
7258
7277
  embeddingModel: string | null;
@@ -7270,7 +7289,11 @@ declare function getVaultEmbeddingsByIdsOp(ctx: VaultMemoryOperationsContext, id
7270
7289
  * excluded exactly as they are from recall — a caller can pass any id list and
7271
7290
  * only its own live rows come back.
7272
7291
  */
7273
- declare function getVaultMemoriesByIdsOp(ctx: VaultMemoryOperationsContext, ids: string[]): Promise<StoredVaultMemory[]>;
7292
+ declare function getVaultMemoriesByIdsOp(ctx: VaultMemoryOperationsContext, ids: string[],
7293
+ /** See {@link getVaultEmbeddingsByIdsOp} — must match what admitted these ids. */
7294
+ options?: {
7295
+ includeArchived?: boolean;
7296
+ }): Promise<StoredVaultMemory[]>;
7274
7297
  declare function getAllVaultMemoryContentsOp(ctx: VaultMemoryOperationsContext, options?: {
7275
7298
  since?: Date;
7276
7299
  }): Promise<string[]>;
@@ -153,7 +153,7 @@ import {
153
153
  updateVaultMemoryOp,
154
154
  useEncryption,
155
155
  vaultMemoryToStored
156
- } from "./chunk-GDS7GHBF.mjs";
156
+ } from "./chunk-HLBQICNL.mjs";
157
157
  import {
158
158
  PiiRedactor,
159
159
  createStreamingDeAnonymizer,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  recall
3
- } from "./chunk-GDS7GHBF.mjs";
3
+ } from "./chunk-HLBQICNL.mjs";
4
4
  import "./chunk-BOY27A2C.mjs";
5
5
  import "./chunk-GYKJOWEO.mjs";
6
6
  export {
@@ -16583,10 +16583,12 @@ async function getAllVaultMemoriesOp(ctx, options) {
16583
16583
  (raw) => vaultMemoryRawToStored(raw, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner)
16584
16584
  );
16585
16585
  }
16586
- function baseVaultSql(ctx) {
16586
+ function baseVaultSql(ctx, options) {
16587
16587
  const clauses = [
16588
16588
  '"is_deleted" = 0',
16589
- '"archived_at" is null',
16589
+ // Mirrors `baseVaultConditions`' `includeArchived` branch. Defaults to
16590
+ // excluding archived rows, so every existing caller is unchanged.
16591
+ ...options?.includeArchived ? [] : ['"archived_at" is null'],
16590
16592
  `"trust_tier" is not 'quarantined'`,
16591
16593
  '"superseded_by" is null'
16592
16594
  ];
@@ -16606,7 +16608,9 @@ async function getVaultCandidateKeysOp(ctx, options) {
16606
16608
  updatedAt: new Date(raw.updated_at)
16607
16609
  });
16608
16610
  try {
16609
- const base = baseVaultSql(ctx);
16611
+ const base = baseVaultSql(ctx, {
16612
+ ...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
16613
+ });
16610
16614
  const clauses = [base.sql];
16611
16615
  const args = [...base.args];
16612
16616
  if (options?.scopes?.length) {
@@ -16617,6 +16621,10 @@ async function getVaultCandidateKeysOp(ctx, options) {
16617
16621
  clauses.push(options.folderId === null ? '"folder_id" is null' : '"folder_id" = ?');
16618
16622
  if (options.folderId !== null) args.push(options.folderId);
16619
16623
  }
16624
+ if (options?.factTypes?.length) {
16625
+ clauses.push(`"fact_type" in (${options.factTypes.map(() => "?").join(",")})`);
16626
+ args.push(...options.factTypes);
16627
+ }
16620
16628
  const sql = `select "id", "scope", "folder_id", "embedding_model", "updated_at" from "memory_vault" where ${clauses.join(" and ")}`;
16621
16629
  const rows = await ctx.vaultMemoryCollection.query(import_watermelondb3.Q.unsafeSqlQuery(sql, args)).unsafeFetchRaw();
16622
16630
  return rows.map(mapRaw);
@@ -16625,15 +16633,18 @@ async function getVaultCandidateKeysOp(ctx, options) {
16625
16633
  "memoryVault: getVaultCandidateKeysOp projected SQL unavailable, using full-load fallback: " + (err instanceof Error ? err.message : String(err))
16626
16634
  );
16627
16635
  const conditions = [
16628
- ...baseVaultConditions(ctx),
16636
+ ...baseVaultConditions(ctx, {
16637
+ ...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
16638
+ }),
16629
16639
  ...options?.scopes?.length ? [import_watermelondb3.Q.where("scope", import_watermelondb3.Q.oneOf(options.scopes))] : [],
16630
- ...options?.folderId !== void 0 ? [import_watermelondb3.Q.where("folder_id", options.folderId)] : []
16640
+ ...options?.folderId !== void 0 ? [import_watermelondb3.Q.where("folder_id", options.folderId)] : [],
16641
+ ...options?.factTypes?.length ? [import_watermelondb3.Q.where("fact_type", import_watermelondb3.Q.oneOf(options.factTypes))] : []
16631
16642
  ];
16632
16643
  const rows = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
16633
16644
  return rows.map(mapRaw);
16634
16645
  }
16635
16646
  }
16636
- async function getVaultEmbeddingsByIdsOp(ctx, ids) {
16647
+ async function getVaultEmbeddingsByIdsOp(ctx, ids, options) {
16637
16648
  if (ids.length === 0) return [];
16638
16649
  const mapRaw = (raw) => ({
16639
16650
  uniqueId: raw.id,
@@ -16641,7 +16652,9 @@ async function getVaultEmbeddingsByIdsOp(ctx, ids) {
16641
16652
  embeddingModel: raw.embedding_model ?? null
16642
16653
  });
16643
16654
  try {
16644
- const base = baseVaultSql(ctx);
16655
+ const base = baseVaultSql(ctx, {
16656
+ ...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
16657
+ });
16645
16658
  const sql = `select "id", "embedding", "embedding_model" from "memory_vault" where ${base.sql} and "id" in (${ids.map(() => "?").join(",")})`;
16646
16659
  const rows = await ctx.vaultMemoryCollection.query(import_watermelondb3.Q.unsafeSqlQuery(sql, [...base.args, ...ids])).unsafeFetchRaw();
16647
16660
  return rows.map(mapRaw);
@@ -16649,13 +16662,25 @@ async function getVaultEmbeddingsByIdsOp(ctx, ids) {
16649
16662
  getLogger().debug(
16650
16663
  "memoryVault: getVaultEmbeddingsByIdsOp projected SQL unavailable, using full-load fallback: " + (err instanceof Error ? err.message : String(err))
16651
16664
  );
16652
- const rows = await ctx.vaultMemoryCollection.query(...baseVaultConditions(ctx), import_watermelondb3.Q.where("id", import_watermelondb3.Q.oneOf(ids))).unsafeFetchRaw();
16665
+ const rows = await ctx.vaultMemoryCollection.query(
16666
+ ...baseVaultConditions(ctx, {
16667
+ ...options?.includeArchived !== void 0 && {
16668
+ includeArchived: options.includeArchived
16669
+ }
16670
+ }),
16671
+ import_watermelondb3.Q.where("id", import_watermelondb3.Q.oneOf(ids))
16672
+ ).unsafeFetchRaw();
16653
16673
  return rows.map(mapRaw);
16654
16674
  }
16655
16675
  }
16656
- async function getVaultMemoriesByIdsOp(ctx, ids) {
16676
+ async function getVaultMemoriesByIdsOp(ctx, ids, options) {
16657
16677
  if (ids.length === 0) return [];
16658
- const conditions = [...baseVaultConditions(ctx), import_watermelondb3.Q.where("id", import_watermelondb3.Q.oneOf(ids))];
16678
+ const conditions = [
16679
+ ...baseVaultConditions(ctx, {
16680
+ ...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
16681
+ }),
16682
+ import_watermelondb3.Q.where("id", import_watermelondb3.Q.oneOf(ids))
16683
+ ];
16659
16684
  const results = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
16660
16685
  return mapInBatches(
16661
16686
  results,
@@ -19349,6 +19374,7 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
19349
19374
  vaultCtx,
19350
19375
  Object.keys(queryOpts).length > 0 ? queryOpts : void 0
19351
19376
  );
19377
+ const hydrateOpts = queryOpts.includeArchived ? { includeArchived: true } : void 0;
19352
19378
  const vaultSize = keys.length;
19353
19379
  if (keys.length === 0) {
19354
19380
  return { memories: [], embeddedItems: [], queryEmbedding: [], vaultSize: 0 };
@@ -19370,7 +19396,7 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
19370
19396
  else noVectorIds.push(k2.uniqueId);
19371
19397
  }
19372
19398
  if (missIds.length > 0) {
19373
- const rows = await getVaultEmbeddingsByIdsOp(vaultCtx, missIds);
19399
+ const rows = await getVaultEmbeddingsByIdsOp(vaultCtx, missIds, hydrateOpts);
19374
19400
  const gotVector = /* @__PURE__ */ new Set();
19375
19401
  for (const r of rows) {
19376
19402
  if (!r.embedding) continue;
@@ -19395,7 +19421,7 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
19395
19421
  `memoryVault: projected search un-embedded lane capped at ${laneIds.length}/${noVectorIds.length}`
19396
19422
  );
19397
19423
  }
19398
- const laneRows = (await getVaultMemoriesByIdsOp(vaultCtx, laneIds)).filter(
19424
+ const laneRows = (await getVaultMemoriesByIdsOp(vaultCtx, laneIds, hydrateOpts)).filter(
19399
19425
  (m) => !isEncrypted(m.content)
19400
19426
  );
19401
19427
  if (laneRows.length > 0) {
@@ -19425,7 +19451,7 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
19425
19451
  if (keyById.has(id)) admissionSet.add(id);
19426
19452
  }
19427
19453
  }
19428
- const admittedRows = await getVaultMemoriesByIdsOp(vaultCtx, [...admissionSet]);
19454
+ const admittedRows = await getVaultMemoriesByIdsOp(vaultCtx, [...admissionSet], hydrateOpts);
19429
19455
  const memories = admittedRows.filter((m) => !isEncrypted(m.content));
19430
19456
  if (memories.length < admittedRows.length) {
19431
19457
  getLogger().warn(
@@ -19789,7 +19815,7 @@ function createMemoryVaultSearchTool(vaultCtx, embeddingOptions, cache, searchOp
19789
19815
  legacy.map((r) => ({ id: r.uniqueId, content: r.content, score: r.similarity }))
19790
19816
  );
19791
19817
  }
19792
- const { recall: recall2 } = await import("./recall-NLJNELJY.mjs");
19818
+ const { recall: recall2 } = await import("./recall-5OW4RJVC.mjs");
19793
19819
  const result = await recall2(
19794
19820
  query,
19795
19821
  { vaultCtx, embeddingOptions, vaultCache: cache },
@@ -17389,10 +17389,12 @@ async function getAllVaultMemoriesOp(ctx, options) {
17389
17389
  (raw) => vaultMemoryRawToStored(raw, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner)
17390
17390
  );
17391
17391
  }
17392
- function baseVaultSql(ctx) {
17392
+ function baseVaultSql(ctx, options) {
17393
17393
  const clauses = [
17394
17394
  '"is_deleted" = 0',
17395
- '"archived_at" is null',
17395
+ // Mirrors `baseVaultConditions`' `includeArchived` branch. Defaults to
17396
+ // excluding archived rows, so every existing caller is unchanged.
17397
+ ...options?.includeArchived ? [] : ['"archived_at" is null'],
17396
17398
  `"trust_tier" is not 'quarantined'`,
17397
17399
  '"superseded_by" is null'
17398
17400
  ];
@@ -17412,7 +17414,9 @@ async function getVaultCandidateKeysOp(ctx, options) {
17412
17414
  updatedAt: new Date(raw.updated_at)
17413
17415
  });
17414
17416
  try {
17415
- const base = baseVaultSql(ctx);
17417
+ const base = baseVaultSql(ctx, {
17418
+ ...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
17419
+ });
17416
17420
  const clauses = [base.sql];
17417
17421
  const args = [...base.args];
17418
17422
  if (options?.scopes?.length) {
@@ -17423,6 +17427,10 @@ async function getVaultCandidateKeysOp(ctx, options) {
17423
17427
  clauses.push(options.folderId === null ? '"folder_id" is null' : '"folder_id" = ?');
17424
17428
  if (options.folderId !== null) args.push(options.folderId);
17425
17429
  }
17430
+ if (options?.factTypes?.length) {
17431
+ clauses.push(`"fact_type" in (${options.factTypes.map(() => "?").join(",")})`);
17432
+ args.push(...options.factTypes);
17433
+ }
17426
17434
  const sql = `select "id", "scope", "folder_id", "embedding_model", "updated_at" from "memory_vault" where ${clauses.join(" and ")}`;
17427
17435
  const rows = await ctx.vaultMemoryCollection.query(import_watermelondb17.Q.unsafeSqlQuery(sql, args)).unsafeFetchRaw();
17428
17436
  return rows.map(mapRaw);
@@ -17431,15 +17439,18 @@ async function getVaultCandidateKeysOp(ctx, options) {
17431
17439
  "memoryVault: getVaultCandidateKeysOp projected SQL unavailable, using full-load fallback: " + (err instanceof Error ? err.message : String(err))
17432
17440
  );
17433
17441
  const conditions = [
17434
- ...baseVaultConditions(ctx),
17442
+ ...baseVaultConditions(ctx, {
17443
+ ...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
17444
+ }),
17435
17445
  ...options?.scopes?.length ? [import_watermelondb17.Q.where("scope", import_watermelondb17.Q.oneOf(options.scopes))] : [],
17436
- ...options?.folderId !== void 0 ? [import_watermelondb17.Q.where("folder_id", options.folderId)] : []
17446
+ ...options?.folderId !== void 0 ? [import_watermelondb17.Q.where("folder_id", options.folderId)] : [],
17447
+ ...options?.factTypes?.length ? [import_watermelondb17.Q.where("fact_type", import_watermelondb17.Q.oneOf(options.factTypes))] : []
17437
17448
  ];
17438
17449
  const rows = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
17439
17450
  return rows.map(mapRaw);
17440
17451
  }
17441
17452
  }
17442
- async function getVaultEmbeddingsByIdsOp(ctx, ids) {
17453
+ async function getVaultEmbeddingsByIdsOp(ctx, ids, options) {
17443
17454
  if (ids.length === 0) return [];
17444
17455
  const mapRaw = (raw) => ({
17445
17456
  uniqueId: raw.id,
@@ -17447,7 +17458,9 @@ async function getVaultEmbeddingsByIdsOp(ctx, ids) {
17447
17458
  embeddingModel: raw.embedding_model ?? null
17448
17459
  });
17449
17460
  try {
17450
- const base = baseVaultSql(ctx);
17461
+ const base = baseVaultSql(ctx, {
17462
+ ...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
17463
+ });
17451
17464
  const sql = `select "id", "embedding", "embedding_model" from "memory_vault" where ${base.sql} and "id" in (${ids.map(() => "?").join(",")})`;
17452
17465
  const rows = await ctx.vaultMemoryCollection.query(import_watermelondb17.Q.unsafeSqlQuery(sql, [...base.args, ...ids])).unsafeFetchRaw();
17453
17466
  return rows.map(mapRaw);
@@ -17455,13 +17468,25 @@ async function getVaultEmbeddingsByIdsOp(ctx, ids) {
17455
17468
  getLogger().debug(
17456
17469
  "memoryVault: getVaultEmbeddingsByIdsOp projected SQL unavailable, using full-load fallback: " + (err instanceof Error ? err.message : String(err))
17457
17470
  );
17458
- const rows = await ctx.vaultMemoryCollection.query(...baseVaultConditions(ctx), import_watermelondb17.Q.where("id", import_watermelondb17.Q.oneOf(ids))).unsafeFetchRaw();
17471
+ const rows = await ctx.vaultMemoryCollection.query(
17472
+ ...baseVaultConditions(ctx, {
17473
+ ...options?.includeArchived !== void 0 && {
17474
+ includeArchived: options.includeArchived
17475
+ }
17476
+ }),
17477
+ import_watermelondb17.Q.where("id", import_watermelondb17.Q.oneOf(ids))
17478
+ ).unsafeFetchRaw();
17459
17479
  return rows.map(mapRaw);
17460
17480
  }
17461
17481
  }
17462
- async function getVaultMemoriesByIdsOp(ctx, ids) {
17482
+ async function getVaultMemoriesByIdsOp(ctx, ids, options) {
17463
17483
  if (ids.length === 0) return [];
17464
- const conditions = [...baseVaultConditions(ctx), import_watermelondb17.Q.where("id", import_watermelondb17.Q.oneOf(ids))];
17484
+ const conditions = [
17485
+ ...baseVaultConditions(ctx, {
17486
+ ...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
17487
+ }),
17488
+ import_watermelondb17.Q.where("id", import_watermelondb17.Q.oneOf(ids))
17489
+ ];
17465
17490
  const results = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
17466
17491
  return mapInBatches(
17467
17492
  results,
@@ -21450,6 +21475,7 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
21450
21475
  vaultCtx,
21451
21476
  Object.keys(queryOpts).length > 0 ? queryOpts : void 0
21452
21477
  );
21478
+ const hydrateOpts = queryOpts.includeArchived ? { includeArchived: true } : void 0;
21453
21479
  const vaultSize = keys.length;
21454
21480
  if (keys.length === 0) {
21455
21481
  return { memories: [], embeddedItems: [], queryEmbedding: [], vaultSize: 0 };
@@ -21471,7 +21497,7 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
21471
21497
  else noVectorIds.push(k2.uniqueId);
21472
21498
  }
21473
21499
  if (missIds.length > 0) {
21474
- const rows = await getVaultEmbeddingsByIdsOp(vaultCtx, missIds);
21500
+ const rows = await getVaultEmbeddingsByIdsOp(vaultCtx, missIds, hydrateOpts);
21475
21501
  const gotVector = /* @__PURE__ */ new Set();
21476
21502
  for (const r of rows) {
21477
21503
  if (!r.embedding) continue;
@@ -21496,7 +21522,7 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
21496
21522
  `memoryVault: projected search un-embedded lane capped at ${laneIds.length}/${noVectorIds.length}`
21497
21523
  );
21498
21524
  }
21499
- const laneRows = (await getVaultMemoriesByIdsOp(vaultCtx, laneIds)).filter(
21525
+ const laneRows = (await getVaultMemoriesByIdsOp(vaultCtx, laneIds, hydrateOpts)).filter(
21500
21526
  (m) => !isEncrypted(m.content)
21501
21527
  );
21502
21528
  if (laneRows.length > 0) {
@@ -21526,7 +21552,7 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
21526
21552
  if (keyById.has(id)) admissionSet.add(id);
21527
21553
  }
21528
21554
  }
21529
- const admittedRows = await getVaultMemoriesByIdsOp(vaultCtx, [...admissionSet]);
21555
+ const admittedRows = await getVaultMemoriesByIdsOp(vaultCtx, [...admissionSet], hydrateOpts);
21530
21556
  const memories = admittedRows.filter((m) => !isEncrypted(m.content));
21531
21557
  if (memories.length < admittedRows.length) {
21532
21558
  getLogger().warn(
@@ -125,7 +125,7 @@ import {
125
125
  updateVaultMemoryOp,
126
126
  upsertMessageOp,
127
127
  vaultMemoryToStored
128
- } from "./chunk-QC4WHNIJ.mjs";
128
+ } from "./chunk-ICGTS7X6.mjs";
129
129
  import {
130
130
  createStreamingDeAnonymizer,
131
131
  resolvePiiRedactor
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  recall
3
- } from "./chunk-QC4WHNIJ.mjs";
3
+ } from "./chunk-ICGTS7X6.mjs";
4
4
  import "./chunk-MIXEASUP.mjs";
5
5
  import "./chunk-3RPGXXPZ.mjs";
6
6
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anuma/sdk",
3
- "version": "3.9.2",
3
+ "version": "3.9.3",
4
4
  "description": "",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",