@anuma/sdk 3.13.1 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16938,7 +16938,8 @@ function configMatches(a, b) {
16938
16938
  return a.redacted === b.redacted && a.facetsSignature === b.facetsSignature && (a.reviewedMemoryIdsSignature ?? "") === b.reviewedMemoryIdsSignature && a.scopes.length === b.scopes.length && a.scopes.every((s, i) => s === b.scopes[i]);
16939
16939
  }
16940
16940
  function reviewedMemoryIdsSignature(ids) {
16941
- if (ids === void 0 || ids.length === 0) return "";
16941
+ if (ids === void 0) return "";
16942
+ if (ids.length === 0) return "\0gated-empty";
16942
16943
  return [...new Set(ids)].sort().join("\n");
16943
16944
  }
16944
16945
  function facetsSignature(facets) {
@@ -17048,7 +17049,16 @@ async function synthesizeFacet(facet, ctx, options, prior) {
17048
17049
  const factTypeWeights = { ...DEFAULT_PROFILE_FACT_TYPE_WEIGHTS, ...options.factTypeWeights };
17049
17050
  const proofCountAlpha = options.proofCountAlpha ?? DEFAULT_PROFILE_PROOF_ALPHA;
17050
17051
  const reviewed = options.reviewedMemoryIds;
17051
- const hasReviewGate = reviewed !== void 0 && reviewed.length > 0;
17052
+ const hasReviewGate = reviewed !== void 0;
17053
+ if (hasReviewGate && reviewed.length === 0) {
17054
+ return {
17055
+ key: facet.key,
17056
+ label: facet.label,
17057
+ text: "",
17058
+ sourceMemoryIds: [],
17059
+ generatedAt: Date.now()
17060
+ };
17061
+ }
17052
17062
  const recalled = await recall(facet.query, ctx, {
17053
17063
  scopes,
17054
17064
  limit: hasReviewGate ? RECALL_MAX_LIMIT : limit,
@@ -17563,6 +17573,31 @@ function createMemoryEngineTool(storageCtx, embeddingOptions, searchOptions, cal
17563
17573
  // src/expo/useChatStorage.ts
17564
17574
  init_constants();
17565
17575
 
17576
+ // src/lib/memoryVault/embeddingCacheRegistry.ts
17577
+ init_useEncryption();
17578
+ init_lruCache();
17579
+ var registry = /* @__PURE__ */ new WeakMap();
17580
+ function buildKey(walletAddress, model) {
17581
+ return JSON.stringify([walletAddress ?? null, model]);
17582
+ }
17583
+ function getVaultEmbeddingCache(database, walletAddress, model) {
17584
+ let perDb = registry.get(database);
17585
+ if (!perDb) {
17586
+ perDb = /* @__PURE__ */ new Map();
17587
+ registry.set(database, perDb);
17588
+ }
17589
+ const key = buildKey(walletAddress, model);
17590
+ let cache = perDb.get(key);
17591
+ if (!cache) {
17592
+ cache = createVaultEmbeddingCache();
17593
+ perDb.set(key, cache);
17594
+ }
17595
+ return cache;
17596
+ }
17597
+ onClearAllEncryptionState(() => {
17598
+ registry = /* @__PURE__ */ new WeakMap();
17599
+ });
17600
+
17566
17601
  // src/lib/memoryVault/index.ts
17567
17602
  init_searchTool();
17568
17603
 
@@ -19024,14 +19059,17 @@ function useChatStorage(options) {
19024
19059
  },
19025
19060
  [vaultCtx]
19026
19061
  );
19027
- const vaultEmbeddingCacheRef = (0, import_react4.useRef)(createVaultEmbeddingCache());
19062
+ const vaultEmbeddingCache = (0, import_react4.useMemo)(
19063
+ () => getVaultEmbeddingCache(database, walletAddress, embeddingModel),
19064
+ [database, walletAddress, embeddingModel]
19065
+ );
19028
19066
  const chunkVectorCacheRef = (0, import_react4.useRef)(createChunkVectorCache());
19029
19067
  (0, import_react4.useEffect)(() => {
19030
19068
  return onClearAllEncryptionState(() => {
19031
- vaultEmbeddingCacheRef.current.clear();
19069
+ vaultEmbeddingCache.clear();
19032
19070
  chunkVectorCacheRef.current.clear();
19033
19071
  });
19034
- }, []);
19072
+ }, [vaultEmbeddingCache]);
19035
19073
  const createRecallTool2 = (0, import_react4.useCallback)(
19036
19074
  (toolOptions, callbacks) => {
19037
19075
  if (!getToken) {
@@ -19048,7 +19086,7 @@ function useChatStorage(options) {
19048
19086
  model: embeddingModel,
19049
19087
  maskInput: maskEmbeddingInput
19050
19088
  },
19051
- vaultCache: vaultEmbeddingCacheRef.current,
19089
+ vaultCache: vaultEmbeddingCache,
19052
19090
  chunkCache: chunkVectorCacheRef.current
19053
19091
  // entityCtx is intentionally omitted on Expo for now — the
19054
19092
  // W5 graph lane is a no-op without it (recall falls through
@@ -19066,7 +19104,8 @@ function useChatStorage(options) {
19066
19104
  baseUrl,
19067
19105
  embeddingModel,
19068
19106
  currentConversationId,
19069
- maskEmbeddingInput
19107
+ maskEmbeddingInput,
19108
+ vaultEmbeddingCache
19070
19109
  ]
19071
19110
  );
19072
19111
  const recallFn = (0, import_react4.useCallback)(
@@ -19091,7 +19130,7 @@ function useChatStorage(options) {
19091
19130
  model: embeddingModel,
19092
19131
  maskInput: maskEmbeddingInput
19093
19132
  },
19094
- vaultCache: vaultEmbeddingCacheRef.current,
19133
+ vaultCache: vaultEmbeddingCache,
19095
19134
  chunkCache: chunkVectorCacheRef.current
19096
19135
  },
19097
19136
  resolvedOptions
@@ -19104,7 +19143,8 @@ function useChatStorage(options) {
19104
19143
  baseUrl,
19105
19144
  embeddingModel,
19106
19145
  currentConversationId,
19107
- maskEmbeddingInput
19146
+ maskEmbeddingInput,
19147
+ vaultEmbeddingCache
19108
19148
  ]
19109
19149
  );
19110
19150
  const getVaultMemories = (0, import_react4.useCallback)(
@@ -7710,10 +7710,20 @@ interface SynthesizeProfileOptions extends PortalLlmAuth {
7710
7710
  */
7711
7711
  proofCountAlpha?: number;
7712
7712
  /**
7713
- * When non-empty, intersect each facet's recalled evidence with this id set
7714
- * before the LLM runs (publish-review gate). Empty intersection → empty
7715
- * section (legitimate no-evidence), not a stale fallback. Omit / empty →
7716
- * no gate.
7713
+ * Publish-review gate: when SUPPLIED, each facet's recalled evidence is
7714
+ * intersected with this id set before the LLM runs, so synthesis can only draw
7715
+ * on memories the user approved for publication. Empty intersection → empty
7716
+ * section (legitimate no-evidence), not a stale fallback.
7717
+ *
7718
+ * Pass the user's published set (e.g. `getAllVaultMemoriesOp(ctx, { visibility:
7719
+ * ["public"] })`) to keep a published profile derivable only from published
7720
+ * memories — People Nearby's two-tier model treats `private` memories as never
7721
+ * leaving the device, and a summary derived from them is a derivative that does.
7722
+ *
7723
+ * `[]` means "nothing approved" and gates everything OUT (no recall, no LLM
7724
+ * call, empty sections). **Omitting the field is the only way to run ungated**
7725
+ * — that asymmetry is deliberate, so a caller computing a published set can
7726
+ * never accidentally disable the gate by finding it empty.
7717
7727
  */
7718
7728
  reviewedMemoryIds?: readonly string[];
7719
7729
  }
@@ -7710,10 +7710,20 @@ interface SynthesizeProfileOptions extends PortalLlmAuth {
7710
7710
  */
7711
7711
  proofCountAlpha?: number;
7712
7712
  /**
7713
- * When non-empty, intersect each facet's recalled evidence with this id set
7714
- * before the LLM runs (publish-review gate). Empty intersection → empty
7715
- * section (legitimate no-evidence), not a stale fallback. Omit / empty →
7716
- * no gate.
7713
+ * Publish-review gate: when SUPPLIED, each facet's recalled evidence is
7714
+ * intersected with this id set before the LLM runs, so synthesis can only draw
7715
+ * on memories the user approved for publication. Empty intersection → empty
7716
+ * section (legitimate no-evidence), not a stale fallback.
7717
+ *
7718
+ * Pass the user's published set (e.g. `getAllVaultMemoriesOp(ctx, { visibility:
7719
+ * ["public"] })`) to keep a published profile derivable only from published
7720
+ * memories — People Nearby's two-tier model treats `private` memories as never
7721
+ * leaving the device, and a summary derived from them is a derivative that does.
7722
+ *
7723
+ * `[]` means "nothing approved" and gates everything OUT (no recall, no LLM
7724
+ * call, empty sections). **Omitting the field is the only way to run ungated**
7725
+ * — that asymmetry is deliberate, so a caller computing a published set can
7726
+ * never accidentally disable the gate by finding it empty.
7717
7727
  */
7718
7728
  reviewedMemoryIds?: readonly string[];
7719
7729
  }
@@ -8219,7 +8219,8 @@ function configMatches(a, b) {
8219
8219
  return a.redacted === b.redacted && a.facetsSignature === b.facetsSignature && (a.reviewedMemoryIdsSignature ?? "") === b.reviewedMemoryIdsSignature && a.scopes.length === b.scopes.length && a.scopes.every((s, i) => s === b.scopes[i]);
8220
8220
  }
8221
8221
  function reviewedMemoryIdsSignature(ids) {
8222
- if (ids === void 0 || ids.length === 0) return "";
8222
+ if (ids === void 0) return "";
8223
+ if (ids.length === 0) return "\0gated-empty";
8223
8224
  return [...new Set(ids)].sort().join("\n");
8224
8225
  }
8225
8226
  function facetsSignature(facets) {
@@ -8329,7 +8330,16 @@ async function synthesizeFacet(facet, ctx, options, prior) {
8329
8330
  const factTypeWeights = { ...DEFAULT_PROFILE_FACT_TYPE_WEIGHTS, ...options.factTypeWeights };
8330
8331
  const proofCountAlpha = options.proofCountAlpha ?? DEFAULT_PROFILE_PROOF_ALPHA;
8331
8332
  const reviewed = options.reviewedMemoryIds;
8332
- const hasReviewGate = reviewed !== void 0 && reviewed.length > 0;
8333
+ const hasReviewGate = reviewed !== void 0;
8334
+ if (hasReviewGate && reviewed.length === 0) {
8335
+ return {
8336
+ key: facet.key,
8337
+ label: facet.label,
8338
+ text: "",
8339
+ sourceMemoryIds: [],
8340
+ generatedAt: Date.now()
8341
+ };
8342
+ }
8333
8343
  const recalled = await recall(facet.query, ctx, {
8334
8344
  scopes,
8335
8345
  limit: hasReviewGate ? RECALL_MAX_LIMIT : limit,
@@ -8829,6 +8839,29 @@ function createMemoryEngineTool(storageCtx, embeddingOptions, searchOptions, cal
8829
8839
  };
8830
8840
  }
8831
8841
 
8842
+ // src/lib/memoryVault/embeddingCacheRegistry.ts
8843
+ var registry = /* @__PURE__ */ new WeakMap();
8844
+ function buildKey(walletAddress, model) {
8845
+ return JSON.stringify([walletAddress ?? null, model]);
8846
+ }
8847
+ function getVaultEmbeddingCache(database, walletAddress, model) {
8848
+ let perDb = registry.get(database);
8849
+ if (!perDb) {
8850
+ perDb = /* @__PURE__ */ new Map();
8851
+ registry.set(database, perDb);
8852
+ }
8853
+ const key = buildKey(walletAddress, model);
8854
+ let cache = perDb.get(key);
8855
+ if (!cache) {
8856
+ cache = createVaultEmbeddingCache();
8857
+ perDb.set(key, cache);
8858
+ }
8859
+ return cache;
8860
+ }
8861
+ onClearAllEncryptionState(() => {
8862
+ registry = /* @__PURE__ */ new WeakMap();
8863
+ });
8864
+
8832
8865
  // src/lib/memoryVault/tool.ts
8833
8866
  var MANUAL_FACT_TYPES = [
8834
8867
  "identity",
@@ -10275,14 +10308,17 @@ function useChatStorage(options) {
10275
10308
  },
10276
10309
  [vaultCtx]
10277
10310
  );
10278
- const vaultEmbeddingCacheRef = useRef4(createVaultEmbeddingCache());
10311
+ const vaultEmbeddingCache = useMemo(
10312
+ () => getVaultEmbeddingCache(database, walletAddress, embeddingModel),
10313
+ [database, walletAddress, embeddingModel]
10314
+ );
10279
10315
  const chunkVectorCacheRef = useRef4(createChunkVectorCache());
10280
10316
  useEffect4(() => {
10281
10317
  return onClearAllEncryptionState(() => {
10282
- vaultEmbeddingCacheRef.current.clear();
10318
+ vaultEmbeddingCache.clear();
10283
10319
  chunkVectorCacheRef.current.clear();
10284
10320
  });
10285
- }, []);
10321
+ }, [vaultEmbeddingCache]);
10286
10322
  const createRecallTool2 = useCallback4(
10287
10323
  (toolOptions, callbacks) => {
10288
10324
  if (!getToken) {
@@ -10299,7 +10335,7 @@ function useChatStorage(options) {
10299
10335
  model: embeddingModel,
10300
10336
  maskInput: maskEmbeddingInput
10301
10337
  },
10302
- vaultCache: vaultEmbeddingCacheRef.current,
10338
+ vaultCache: vaultEmbeddingCache,
10303
10339
  chunkCache: chunkVectorCacheRef.current
10304
10340
  // entityCtx is intentionally omitted on Expo for now — the
10305
10341
  // W5 graph lane is a no-op without it (recall falls through
@@ -10317,7 +10353,8 @@ function useChatStorage(options) {
10317
10353
  baseUrl,
10318
10354
  embeddingModel,
10319
10355
  currentConversationId,
10320
- maskEmbeddingInput
10356
+ maskEmbeddingInput,
10357
+ vaultEmbeddingCache
10321
10358
  ]
10322
10359
  );
10323
10360
  const recallFn = useCallback4(
@@ -10342,7 +10379,7 @@ function useChatStorage(options) {
10342
10379
  model: embeddingModel,
10343
10380
  maskInput: maskEmbeddingInput
10344
10381
  },
10345
- vaultCache: vaultEmbeddingCacheRef.current,
10382
+ vaultCache: vaultEmbeddingCache,
10346
10383
  chunkCache: chunkVectorCacheRef.current
10347
10384
  },
10348
10385
  resolvedOptions
@@ -10355,7 +10392,8 @@ function useChatStorage(options) {
10355
10392
  baseUrl,
10356
10393
  embeddingModel,
10357
10394
  currentConversationId,
10358
- maskEmbeddingInput
10395
+ maskEmbeddingInput,
10396
+ vaultEmbeddingCache
10359
10397
  ]
10360
10398
  );
10361
10399
  const getVaultMemories = useCallback4(
@@ -18265,7 +18265,8 @@ function configMatches(a, b) {
18265
18265
  return a.redacted === b.redacted && a.facetsSignature === b.facetsSignature && (a.reviewedMemoryIdsSignature ?? "") === b.reviewedMemoryIdsSignature && a.scopes.length === b.scopes.length && a.scopes.every((s, i) => s === b.scopes[i]);
18266
18266
  }
18267
18267
  function reviewedMemoryIdsSignature(ids) {
18268
- if (ids === void 0 || ids.length === 0) return "";
18268
+ if (ids === void 0) return "";
18269
+ if (ids.length === 0) return "\0gated-empty";
18269
18270
  return [...new Set(ids)].sort().join("\n");
18270
18271
  }
18271
18272
  function facetsSignature(facets) {
@@ -18375,7 +18376,16 @@ async function synthesizeFacet(facet, ctx, options, prior) {
18375
18376
  const factTypeWeights = { ...DEFAULT_PROFILE_FACT_TYPE_WEIGHTS, ...options.factTypeWeights };
18376
18377
  const proofCountAlpha = options.proofCountAlpha ?? DEFAULT_PROFILE_PROOF_ALPHA;
18377
18378
  const reviewed = options.reviewedMemoryIds;
18378
- const hasReviewGate = reviewed !== void 0 && reviewed.length > 0;
18379
+ const hasReviewGate = reviewed !== void 0;
18380
+ if (hasReviewGate && reviewed.length === 0) {
18381
+ return {
18382
+ key: facet.key,
18383
+ label: facet.label,
18384
+ text: "",
18385
+ sourceMemoryIds: [],
18386
+ generatedAt: Date.now()
18387
+ };
18388
+ }
18379
18389
  const recalled = await recall(facet.query, ctx, {
18380
18390
  scopes,
18381
18391
  limit: hasReviewGate ? RECALL_MAX_LIMIT : limit,
@@ -18890,6 +18900,31 @@ function createMemoryEngineTool(storageCtx, embeddingOptions, searchOptions, cal
18890
18900
  // src/react/useChatStorage.ts
18891
18901
  init_constants();
18892
18902
 
18903
+ // src/lib/memoryVault/embeddingCacheRegistry.ts
18904
+ init_useEncryption();
18905
+ init_lruCache();
18906
+ var registry = /* @__PURE__ */ new WeakMap();
18907
+ function buildKey(walletAddress, model) {
18908
+ return JSON.stringify([walletAddress ?? null, model]);
18909
+ }
18910
+ function getVaultEmbeddingCache(database, walletAddress, model) {
18911
+ let perDb = registry.get(database);
18912
+ if (!perDb) {
18913
+ perDb = /* @__PURE__ */ new Map();
18914
+ registry.set(database, perDb);
18915
+ }
18916
+ const key = buildKey(walletAddress, model);
18917
+ let cache = perDb.get(key);
18918
+ if (!cache) {
18919
+ cache = createVaultEmbeddingCache();
18920
+ perDb.set(key, cache);
18921
+ }
18922
+ return cache;
18923
+ }
18924
+ onClearAllEncryptionState(() => {
18925
+ registry = /* @__PURE__ */ new WeakMap();
18926
+ });
18927
+
18893
18928
  // src/lib/memoryVault/index.ts
18894
18929
  init_searchTool();
18895
18930
 
@@ -19411,8 +19446,8 @@ var ZipProcessor = class {
19411
19446
  * Set the processor registry for handling nested files
19412
19447
  * This must be called before processing if you want nested file support
19413
19448
  */
19414
- setRegistry(registry) {
19415
- this.registry = registry;
19449
+ setRegistry(registry2) {
19450
+ this.registry = registry2;
19416
19451
  }
19417
19452
  async process(file) {
19418
19453
  try {
@@ -19651,15 +19686,15 @@ var ProcessorRegistry = class {
19651
19686
  init_logger();
19652
19687
  var MAX_TOTAL_IMAGES = 20;
19653
19688
  function createDefaultRegistry() {
19654
- const registry = new ProcessorRegistry();
19655
- registry.register(new PdfProcessor());
19656
- registry.register(new ExcelProcessor());
19657
- registry.register(new WordProcessor());
19658
- registry.register(new TextProcessor());
19689
+ const registry2 = new ProcessorRegistry();
19690
+ registry2.register(new PdfProcessor());
19691
+ registry2.register(new ExcelProcessor());
19692
+ registry2.register(new WordProcessor());
19693
+ registry2.register(new TextProcessor());
19659
19694
  const zipProcessor = new ZipProcessor();
19660
- zipProcessor.setRegistry(registry);
19661
- registry.register(zipProcessor);
19662
- return registry;
19695
+ zipProcessor.setRegistry(registry2);
19696
+ registry2.register(zipProcessor);
19697
+ return registry2;
19663
19698
  }
19664
19699
  var cachedDefaultRegistry = null;
19665
19700
  function getDefaultRegistry() {
@@ -19672,10 +19707,10 @@ function isSupportedFile(file) {
19672
19707
  return getDefaultRegistry().isSupported(file);
19673
19708
  }
19674
19709
  function getSupportedFileTypes() {
19675
- const registry = getDefaultRegistry();
19710
+ const registry2 = getDefaultRegistry();
19676
19711
  return {
19677
- mimeTypes: registry.getSupportedMimeTypes(),
19678
- extensions: registry.getSupportedExtensions()
19712
+ mimeTypes: registry2.getSupportedMimeTypes(),
19713
+ extensions: registry2.getSupportedExtensions()
19679
19714
  };
19680
19715
  }
19681
19716
  function formatExtractedContent(fileName, content, format) {
@@ -19731,16 +19766,16 @@ async function preprocessFiles(files, options = {}) {
19731
19766
  metadata: { processedCount: 0, skippedCount: 0, errorCount: 0 }
19732
19767
  };
19733
19768
  }
19734
- let registry;
19769
+ let registry2;
19735
19770
  if (processors === void 0) {
19736
- registry = getDefaultRegistry();
19771
+ registry2 = getDefaultRegistry();
19737
19772
  } else {
19738
- registry = new ProcessorRegistry();
19773
+ registry2 = new ProcessorRegistry();
19739
19774
  processors.forEach((p) => {
19740
19775
  if (p instanceof ZipProcessor) {
19741
- p.setRegistry(registry);
19776
+ p.setRegistry(registry2);
19742
19777
  }
19743
- registry.register(p);
19778
+ registry2.register(p);
19744
19779
  });
19745
19780
  }
19746
19781
  const extractedTexts = [];
@@ -19759,7 +19794,7 @@ async function preprocessFiles(files, options = {}) {
19759
19794
  skippedCount++;
19760
19795
  continue;
19761
19796
  }
19762
- const processor = registry.findProcessor(file);
19797
+ const processor = registry2.findProcessor(file);
19763
19798
  if (!processor) {
19764
19799
  skippedCount++;
19765
19800
  continue;
@@ -21412,6 +21447,10 @@ function useChatStorage(options) {
21412
21447
  }),
21413
21448
  [database, vaultMemoryCollection, walletAddress, signMessage, embeddedWalletSigner]
21414
21449
  );
21450
+ const vaultEmbeddingCache = (0, import_react5.useMemo)(
21451
+ () => getVaultEmbeddingCache(database, walletAddress, embeddingModel),
21452
+ [database, walletAddress, embeddingModel]
21453
+ );
21415
21454
  const entityCollection = (0, import_react5.useMemo)(() => database.get("entity"), [database]);
21416
21455
  const memoryEntityCollection = (0, import_react5.useMemo)(
21417
21456
  () => database.get("memory_entity"),
@@ -21637,10 +21676,10 @@ function useChatStorage(options) {
21637
21676
  vaultCtx,
21638
21677
  options2,
21639
21678
  embOpts,
21640
- embOpts ? vaultEmbeddingCacheRef.current : void 0
21679
+ embOpts ? vaultEmbeddingCache : void 0
21641
21680
  );
21642
21681
  },
21643
- [vaultCtx, getToken, vaultEmbeddingOptions]
21682
+ [vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache]
21644
21683
  );
21645
21684
  const getVaultMemories = (0, import_react5.useCallback)(
21646
21685
  (options2) => {
@@ -21655,7 +21694,7 @@ function useChatStorage(options) {
21655
21694
  eagerEmbedContent(
21656
21695
  content,
21657
21696
  vaultEmbeddingOptions,
21658
- vaultEmbeddingCacheRef.current,
21697
+ vaultEmbeddingCache,
21659
21698
  vaultCtx,
21660
21699
  result.uniqueId
21661
21700
  ).catch((err) => {
@@ -21664,7 +21703,7 @@ function useChatStorage(options) {
21664
21703
  }
21665
21704
  return result;
21666
21705
  },
21667
- [vaultCtx, getToken, vaultEmbeddingOptions]
21706
+ [vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache]
21668
21707
  );
21669
21708
  const updateVaultMemory = (0, import_react5.useCallback)(
21670
21709
  async (id, content, scope) => {
@@ -21672,55 +21711,46 @@ function useChatStorage(options) {
21672
21711
  const result = await updateVaultMemoryOp(vaultCtx, id, { content, scope, embedding: null });
21673
21712
  if (result && getToken) {
21674
21713
  if (existing) {
21675
- vaultEmbeddingCacheRef.current.delete(id);
21714
+ vaultEmbeddingCache.delete(id);
21676
21715
  }
21677
- eagerEmbedContent(
21678
- content,
21679
- vaultEmbeddingOptions,
21680
- vaultEmbeddingCacheRef.current,
21681
- vaultCtx,
21682
- id
21683
- ).catch((err) => {
21684
- getLogger().warn("[useChatStorage] Failed to eagerly embed updated vault memory:", err);
21685
- });
21716
+ eagerEmbedContent(content, vaultEmbeddingOptions, vaultEmbeddingCache, vaultCtx, id).catch(
21717
+ (err) => {
21718
+ getLogger().warn("[useChatStorage] Failed to eagerly embed updated vault memory:", err);
21719
+ }
21720
+ );
21686
21721
  }
21687
21722
  return result;
21688
21723
  },
21689
- [vaultCtx, getToken, vaultEmbeddingOptions]
21724
+ [vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache]
21690
21725
  );
21691
21726
  const deleteVaultMemory = (0, import_react5.useCallback)(
21692
21727
  async (id) => {
21693
21728
  const existing = await getVaultMemoryOp(vaultCtx, id);
21694
21729
  const result = await deleteVaultMemoryOp(vaultCtx, id);
21695
21730
  if (result && existing) {
21696
- vaultEmbeddingCacheRef.current.delete(id);
21731
+ vaultEmbeddingCache.delete(id);
21697
21732
  }
21698
21733
  return result;
21699
21734
  },
21700
- [vaultCtx]
21735
+ [vaultCtx, vaultEmbeddingCache]
21701
21736
  );
21702
- const vaultEmbeddingCacheRef = (0, import_react5.useRef)(createVaultEmbeddingCache());
21703
21737
  const chunkVectorCacheRef = (0, import_react5.useRef)(createChunkVectorCache());
21704
21738
  const clientToolEmbeddingsCacheRef = (0, import_react5.useRef)(/* @__PURE__ */ new Map());
21705
21739
  (0, import_react5.useEffect)(() => {
21706
21740
  if (!getToken) return;
21707
21741
  void (async () => {
21708
21742
  try {
21709
- await preEmbedVaultMemories(
21710
- vaultCtx,
21711
- vaultEmbeddingOptions,
21712
- vaultEmbeddingCacheRef.current
21713
- );
21743
+ await preEmbedVaultMemories(vaultCtx, vaultEmbeddingOptions, vaultEmbeddingCache);
21714
21744
  } catch {
21715
21745
  }
21716
21746
  })();
21717
- }, [vaultCtx, getToken, vaultEmbeddingOptions]);
21747
+ }, [vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache]);
21718
21748
  (0, import_react5.useEffect)(() => {
21719
21749
  return onClearAllEncryptionState(() => {
21720
- vaultEmbeddingCacheRef.current.clear();
21750
+ vaultEmbeddingCache.clear();
21721
21751
  chunkVectorCacheRef.current.clear();
21722
21752
  });
21723
- }, []);
21753
+ }, [vaultEmbeddingCache]);
21724
21754
  const createMemoryVaultSearchTool2 = (0, import_react5.useCallback)(
21725
21755
  (searchOptions) => {
21726
21756
  if (!getToken) {
@@ -21729,11 +21759,11 @@ function useChatStorage(options) {
21729
21759
  return createMemoryVaultSearchTool(
21730
21760
  vaultCtx,
21731
21761
  vaultEmbeddingOptions,
21732
- vaultEmbeddingCacheRef.current,
21762
+ vaultEmbeddingCache,
21733
21763
  searchOptions
21734
21764
  );
21735
21765
  },
21736
- [vaultCtx, getToken, vaultEmbeddingOptions]
21766
+ [vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache]
21737
21767
  );
21738
21768
  const createRecallTool2 = (0, import_react5.useCallback)(
21739
21769
  (toolOptions, callbacks) => {
@@ -21746,7 +21776,7 @@ function useChatStorage(options) {
21746
21776
  vaultCtx,
21747
21777
  storageCtx,
21748
21778
  embeddingOptions: vaultEmbeddingOptions,
21749
- vaultCache: vaultEmbeddingCacheRef.current,
21779
+ vaultCache: vaultEmbeddingCache,
21750
21780
  chunkCache: chunkVectorCacheRef.current,
21751
21781
  // Graph lane fires when entityCtx is present and the query
21752
21782
  // contains extractable entities. Empty memory_entity (e.g.
@@ -21758,7 +21788,15 @@ function useChatStorage(options) {
21758
21788
  callbacks
21759
21789
  );
21760
21790
  },
21761
- [vaultCtx, storageCtx, entityCtx, getToken, vaultEmbeddingOptions, currentConversationId]
21791
+ [
21792
+ vaultCtx,
21793
+ storageCtx,
21794
+ entityCtx,
21795
+ getToken,
21796
+ vaultEmbeddingOptions,
21797
+ vaultEmbeddingCache,
21798
+ currentConversationId
21799
+ ]
21762
21800
  );
21763
21801
  const searchVaultMemoriesFn = (0, import_react5.useCallback)(
21764
21802
  async (query, searchOptions) => {
@@ -21767,11 +21805,11 @@ function useChatStorage(options) {
21767
21805
  query,
21768
21806
  vaultCtx,
21769
21807
  vaultEmbeddingOptions,
21770
- vaultEmbeddingCacheRef.current,
21808
+ vaultEmbeddingCache,
21771
21809
  searchOptions
21772
21810
  );
21773
21811
  },
21774
- [vaultCtx, getToken, vaultEmbeddingOptions]
21812
+ [vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache]
21775
21813
  );
21776
21814
  const recallFn = (0, import_react5.useCallback)(
21777
21815
  async (query, options2) => {
@@ -21794,7 +21832,7 @@ function useChatStorage(options) {
21794
21832
  // createRecallTool / searchVaultMemoriesFn. Without this, recall()
21795
21833
  // would embed the raw query (often containing the user's PII).
21796
21834
  embeddingOptions: vaultEmbeddingOptions,
21797
- vaultCache: vaultEmbeddingCacheRef.current,
21835
+ vaultCache: vaultEmbeddingCache,
21798
21836
  chunkCache: chunkVectorCacheRef.current,
21799
21837
  // Graph lane fires only when entityCtx is present and the query
21800
21838
  // has extractable entities; empty memory_entity is a graceful
@@ -21804,7 +21842,15 @@ function useChatStorage(options) {
21804
21842
  resolvedOptions
21805
21843
  );
21806
21844
  },
21807
- [vaultCtx, storageCtx, entityCtx, getToken, currentConversationId, vaultEmbeddingOptions]
21845
+ [
21846
+ vaultCtx,
21847
+ storageCtx,
21848
+ entityCtx,
21849
+ getToken,
21850
+ currentConversationId,
21851
+ vaultEmbeddingOptions,
21852
+ vaultEmbeddingCache
21853
+ ]
21808
21854
  );
21809
21855
  const {
21810
21856
  isLoading,
@@ -22914,7 +22960,7 @@ Based on these results, continue with the task.`;
22914
22960
  createRecallTool: createRecallTool2,
22915
22961
  recall: recallFn,
22916
22962
  searchVaultMemories: searchVaultMemoriesFn,
22917
- vaultEmbeddingCache: vaultEmbeddingCacheRef.current,
22963
+ vaultEmbeddingCache,
22918
22964
  getVaultMemories,
22919
22965
  createVaultMemory,
22920
22966
  updateVaultMemory,
@@ -8949,10 +8949,20 @@ interface SynthesizeProfileOptions extends PortalLlmAuth {
8949
8949
  */
8950
8950
  proofCountAlpha?: number;
8951
8951
  /**
8952
- * When non-empty, intersect each facet's recalled evidence with this id set
8953
- * before the LLM runs (publish-review gate). Empty intersection → empty
8954
- * section (legitimate no-evidence), not a stale fallback. Omit / empty →
8955
- * no gate.
8952
+ * Publish-review gate: when SUPPLIED, each facet's recalled evidence is
8953
+ * intersected with this id set before the LLM runs, so synthesis can only draw
8954
+ * on memories the user approved for publication. Empty intersection → empty
8955
+ * section (legitimate no-evidence), not a stale fallback.
8956
+ *
8957
+ * Pass the user's published set (e.g. `getAllVaultMemoriesOp(ctx, { visibility:
8958
+ * ["public"] })`) to keep a published profile derivable only from published
8959
+ * memories — People Nearby's two-tier model treats `private` memories as never
8960
+ * leaving the device, and a summary derived from them is a derivative that does.
8961
+ *
8962
+ * `[]` means "nothing approved" and gates everything OUT (no recall, no LLM
8963
+ * call, empty sections). **Omitting the field is the only way to run ungated**
8964
+ * — that asymmetry is deliberate, so a caller computing a published set can
8965
+ * never accidentally disable the gate by finding it empty.
8956
8966
  */
8957
8967
  reviewedMemoryIds?: readonly string[];
8958
8968
  }
@@ -9752,6 +9762,13 @@ interface UseChatStorageResult extends BaseUseChatStorageResult {
9752
9762
  /**
9753
9763
  * The shared vault embedding cache. Use this to eagerly embed content
9754
9764
  * when saving vault memories (via eagerEmbedContent).
9765
+ *
9766
+ * Shared per `(database, walletAddress, embeddingModel)` rather than owned by
9767
+ * this hook instance: every `useChatStorage` on the same three gets this exact
9768
+ * object, and it outlives their unmounts. Writes and evictions are therefore
9769
+ * visible to all of them — which is the point (a memory deleted through one
9770
+ * hook stops being served by the others) but does mean `clear()` clears for
9771
+ * everyone.
9755
9772
  */
9756
9773
  vaultEmbeddingCache: VaultEmbeddingCache;
9757
9774
  /**
@@ -8949,10 +8949,20 @@ interface SynthesizeProfileOptions extends PortalLlmAuth {
8949
8949
  */
8950
8950
  proofCountAlpha?: number;
8951
8951
  /**
8952
- * When non-empty, intersect each facet's recalled evidence with this id set
8953
- * before the LLM runs (publish-review gate). Empty intersection → empty
8954
- * section (legitimate no-evidence), not a stale fallback. Omit / empty →
8955
- * no gate.
8952
+ * Publish-review gate: when SUPPLIED, each facet's recalled evidence is
8953
+ * intersected with this id set before the LLM runs, so synthesis can only draw
8954
+ * on memories the user approved for publication. Empty intersection → empty
8955
+ * section (legitimate no-evidence), not a stale fallback.
8956
+ *
8957
+ * Pass the user's published set (e.g. `getAllVaultMemoriesOp(ctx, { visibility:
8958
+ * ["public"] })`) to keep a published profile derivable only from published
8959
+ * memories — People Nearby's two-tier model treats `private` memories as never
8960
+ * leaving the device, and a summary derived from them is a derivative that does.
8961
+ *
8962
+ * `[]` means "nothing approved" and gates everything OUT (no recall, no LLM
8963
+ * call, empty sections). **Omitting the field is the only way to run ungated**
8964
+ * — that asymmetry is deliberate, so a caller computing a published set can
8965
+ * never accidentally disable the gate by finding it empty.
8956
8966
  */
8957
8967
  reviewedMemoryIds?: readonly string[];
8958
8968
  }
@@ -9752,6 +9762,13 @@ interface UseChatStorageResult extends BaseUseChatStorageResult {
9752
9762
  /**
9753
9763
  * The shared vault embedding cache. Use this to eagerly embed content
9754
9764
  * when saving vault memories (via eagerEmbedContent).
9765
+ *
9766
+ * Shared per `(database, walletAddress, embeddingModel)` rather than owned by
9767
+ * this hook instance: every `useChatStorage` on the same three gets this exact
9768
+ * object, and it outlives their unmounts. Writes and evictions are therefore
9769
+ * visible to all of them — which is the point (a memory deleted through one
9770
+ * hook stops being served by the others) but does mean `clear()` clears for
9771
+ * everyone.
9755
9772
  */
9756
9773
  vaultEmbeddingCache: VaultEmbeddingCache;
9757
9774
  /**
@@ -9036,7 +9036,8 @@ function configMatches(a, b) {
9036
9036
  return a.redacted === b.redacted && a.facetsSignature === b.facetsSignature && (a.reviewedMemoryIdsSignature ?? "") === b.reviewedMemoryIdsSignature && a.scopes.length === b.scopes.length && a.scopes.every((s, i) => s === b.scopes[i]);
9037
9037
  }
9038
9038
  function reviewedMemoryIdsSignature(ids) {
9039
- if (ids === void 0 || ids.length === 0) return "";
9039
+ if (ids === void 0) return "";
9040
+ if (ids.length === 0) return "\0gated-empty";
9040
9041
  return [...new Set(ids)].sort().join("\n");
9041
9042
  }
9042
9043
  function facetsSignature(facets) {
@@ -9146,7 +9147,16 @@ async function synthesizeFacet(facet, ctx, options, prior) {
9146
9147
  const factTypeWeights = { ...DEFAULT_PROFILE_FACT_TYPE_WEIGHTS, ...options.factTypeWeights };
9147
9148
  const proofCountAlpha = options.proofCountAlpha ?? DEFAULT_PROFILE_PROOF_ALPHA;
9148
9149
  const reviewed = options.reviewedMemoryIds;
9149
- const hasReviewGate = reviewed !== void 0 && reviewed.length > 0;
9150
+ const hasReviewGate = reviewed !== void 0;
9151
+ if (hasReviewGate && reviewed.length === 0) {
9152
+ return {
9153
+ key: facet.key,
9154
+ label: facet.label,
9155
+ text: "",
9156
+ sourceMemoryIds: [],
9157
+ generatedAt: Date.now()
9158
+ };
9159
+ }
9150
9160
  const recalled = await recall(facet.query, ctx, {
9151
9161
  scopes,
9152
9162
  limit: hasReviewGate ? RECALL_MAX_LIMIT : limit,
@@ -9646,6 +9656,29 @@ function createMemoryEngineTool(storageCtx, embeddingOptions, searchOptions, cal
9646
9656
  };
9647
9657
  }
9648
9658
 
9659
+ // src/lib/memoryVault/embeddingCacheRegistry.ts
9660
+ var registry = /* @__PURE__ */ new WeakMap();
9661
+ function buildKey(walletAddress, model) {
9662
+ return JSON.stringify([walletAddress ?? null, model]);
9663
+ }
9664
+ function getVaultEmbeddingCache(database, walletAddress, model) {
9665
+ let perDb = registry.get(database);
9666
+ if (!perDb) {
9667
+ perDb = /* @__PURE__ */ new Map();
9668
+ registry.set(database, perDb);
9669
+ }
9670
+ const key = buildKey(walletAddress, model);
9671
+ let cache = perDb.get(key);
9672
+ if (!cache) {
9673
+ cache = createVaultEmbeddingCache();
9674
+ perDb.set(key, cache);
9675
+ }
9676
+ return cache;
9677
+ }
9678
+ onClearAllEncryptionState(() => {
9679
+ registry = /* @__PURE__ */ new WeakMap();
9680
+ });
9681
+
9649
9682
  // src/lib/memoryVault/tool.ts
9650
9683
  var MANUAL_FACT_TYPES = [
9651
9684
  "identity",
@@ -10150,8 +10183,8 @@ var ZipProcessor = class {
10150
10183
  * Set the processor registry for handling nested files
10151
10184
  * This must be called before processing if you want nested file support
10152
10185
  */
10153
- setRegistry(registry) {
10154
- this.registry = registry;
10186
+ setRegistry(registry2) {
10187
+ this.registry = registry2;
10155
10188
  }
10156
10189
  async process(file) {
10157
10190
  try {
@@ -10389,15 +10422,15 @@ var ProcessorRegistry = class {
10389
10422
  // src/lib/processors/preprocessor.ts
10390
10423
  var MAX_TOTAL_IMAGES = 20;
10391
10424
  function createDefaultRegistry() {
10392
- const registry = new ProcessorRegistry();
10393
- registry.register(new PdfProcessor());
10394
- registry.register(new ExcelProcessor());
10395
- registry.register(new WordProcessor());
10396
- registry.register(new TextProcessor());
10425
+ const registry2 = new ProcessorRegistry();
10426
+ registry2.register(new PdfProcessor());
10427
+ registry2.register(new ExcelProcessor());
10428
+ registry2.register(new WordProcessor());
10429
+ registry2.register(new TextProcessor());
10397
10430
  const zipProcessor = new ZipProcessor();
10398
- zipProcessor.setRegistry(registry);
10399
- registry.register(zipProcessor);
10400
- return registry;
10431
+ zipProcessor.setRegistry(registry2);
10432
+ registry2.register(zipProcessor);
10433
+ return registry2;
10401
10434
  }
10402
10435
  var cachedDefaultRegistry = null;
10403
10436
  function getDefaultRegistry() {
@@ -10410,10 +10443,10 @@ function isSupportedFile(file) {
10410
10443
  return getDefaultRegistry().isSupported(file);
10411
10444
  }
10412
10445
  function getSupportedFileTypes() {
10413
- const registry = getDefaultRegistry();
10446
+ const registry2 = getDefaultRegistry();
10414
10447
  return {
10415
- mimeTypes: registry.getSupportedMimeTypes(),
10416
- extensions: registry.getSupportedExtensions()
10448
+ mimeTypes: registry2.getSupportedMimeTypes(),
10449
+ extensions: registry2.getSupportedExtensions()
10417
10450
  };
10418
10451
  }
10419
10452
  function formatExtractedContent(fileName, content, format) {
@@ -10469,16 +10502,16 @@ async function preprocessFiles(files, options = {}) {
10469
10502
  metadata: { processedCount: 0, skippedCount: 0, errorCount: 0 }
10470
10503
  };
10471
10504
  }
10472
- let registry;
10505
+ let registry2;
10473
10506
  if (processors === void 0) {
10474
- registry = getDefaultRegistry();
10507
+ registry2 = getDefaultRegistry();
10475
10508
  } else {
10476
- registry = new ProcessorRegistry();
10509
+ registry2 = new ProcessorRegistry();
10477
10510
  processors.forEach((p) => {
10478
10511
  if (p instanceof ZipProcessor) {
10479
- p.setRegistry(registry);
10512
+ p.setRegistry(registry2);
10480
10513
  }
10481
- registry.register(p);
10514
+ registry2.register(p);
10482
10515
  });
10483
10516
  }
10484
10517
  const extractedTexts = [];
@@ -10497,7 +10530,7 @@ async function preprocessFiles(files, options = {}) {
10497
10530
  skippedCount++;
10498
10531
  continue;
10499
10532
  }
10500
- const processor = registry.findProcessor(file);
10533
+ const processor = registry2.findProcessor(file);
10501
10534
  if (!processor) {
10502
10535
  skippedCount++;
10503
10536
  continue;
@@ -12139,6 +12172,10 @@ function useChatStorage(options) {
12139
12172
  }),
12140
12173
  [database, vaultMemoryCollection, walletAddress, signMessage, embeddedWalletSigner]
12141
12174
  );
12175
+ const vaultEmbeddingCache = useMemo3(
12176
+ () => getVaultEmbeddingCache(database, walletAddress, embeddingModel),
12177
+ [database, walletAddress, embeddingModel]
12178
+ );
12142
12179
  const entityCollection = useMemo3(() => database.get("entity"), [database]);
12143
12180
  const memoryEntityCollection = useMemo3(
12144
12181
  () => database.get("memory_entity"),
@@ -12364,10 +12401,10 @@ function useChatStorage(options) {
12364
12401
  vaultCtx,
12365
12402
  options2,
12366
12403
  embOpts,
12367
- embOpts ? vaultEmbeddingCacheRef.current : void 0
12404
+ embOpts ? vaultEmbeddingCache : void 0
12368
12405
  );
12369
12406
  },
12370
- [vaultCtx, getToken, vaultEmbeddingOptions]
12407
+ [vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache]
12371
12408
  );
12372
12409
  const getVaultMemories = useCallback4(
12373
12410
  (options2) => {
@@ -12382,7 +12419,7 @@ function useChatStorage(options) {
12382
12419
  eagerEmbedContent(
12383
12420
  content,
12384
12421
  vaultEmbeddingOptions,
12385
- vaultEmbeddingCacheRef.current,
12422
+ vaultEmbeddingCache,
12386
12423
  vaultCtx,
12387
12424
  result.uniqueId
12388
12425
  ).catch((err) => {
@@ -12391,7 +12428,7 @@ function useChatStorage(options) {
12391
12428
  }
12392
12429
  return result;
12393
12430
  },
12394
- [vaultCtx, getToken, vaultEmbeddingOptions]
12431
+ [vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache]
12395
12432
  );
12396
12433
  const updateVaultMemory = useCallback4(
12397
12434
  async (id, content, scope) => {
@@ -12399,55 +12436,46 @@ function useChatStorage(options) {
12399
12436
  const result = await updateVaultMemoryOp(vaultCtx, id, { content, scope, embedding: null });
12400
12437
  if (result && getToken) {
12401
12438
  if (existing) {
12402
- vaultEmbeddingCacheRef.current.delete(id);
12439
+ vaultEmbeddingCache.delete(id);
12403
12440
  }
12404
- eagerEmbedContent(
12405
- content,
12406
- vaultEmbeddingOptions,
12407
- vaultEmbeddingCacheRef.current,
12408
- vaultCtx,
12409
- id
12410
- ).catch((err) => {
12411
- getLogger().warn("[useChatStorage] Failed to eagerly embed updated vault memory:", err);
12412
- });
12441
+ eagerEmbedContent(content, vaultEmbeddingOptions, vaultEmbeddingCache, vaultCtx, id).catch(
12442
+ (err) => {
12443
+ getLogger().warn("[useChatStorage] Failed to eagerly embed updated vault memory:", err);
12444
+ }
12445
+ );
12413
12446
  }
12414
12447
  return result;
12415
12448
  },
12416
- [vaultCtx, getToken, vaultEmbeddingOptions]
12449
+ [vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache]
12417
12450
  );
12418
12451
  const deleteVaultMemory = useCallback4(
12419
12452
  async (id) => {
12420
12453
  const existing = await getVaultMemoryOp(vaultCtx, id);
12421
12454
  const result = await deleteVaultMemoryOp(vaultCtx, id);
12422
12455
  if (result && existing) {
12423
- vaultEmbeddingCacheRef.current.delete(id);
12456
+ vaultEmbeddingCache.delete(id);
12424
12457
  }
12425
12458
  return result;
12426
12459
  },
12427
- [vaultCtx]
12460
+ [vaultCtx, vaultEmbeddingCache]
12428
12461
  );
12429
- const vaultEmbeddingCacheRef = useRef4(createVaultEmbeddingCache());
12430
12462
  const chunkVectorCacheRef = useRef4(createChunkVectorCache());
12431
12463
  const clientToolEmbeddingsCacheRef = useRef4(/* @__PURE__ */ new Map());
12432
12464
  useEffect3(() => {
12433
12465
  if (!getToken) return;
12434
12466
  void (async () => {
12435
12467
  try {
12436
- await preEmbedVaultMemories(
12437
- vaultCtx,
12438
- vaultEmbeddingOptions,
12439
- vaultEmbeddingCacheRef.current
12440
- );
12468
+ await preEmbedVaultMemories(vaultCtx, vaultEmbeddingOptions, vaultEmbeddingCache);
12441
12469
  } catch {
12442
12470
  }
12443
12471
  })();
12444
- }, [vaultCtx, getToken, vaultEmbeddingOptions]);
12472
+ }, [vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache]);
12445
12473
  useEffect3(() => {
12446
12474
  return onClearAllEncryptionState(() => {
12447
- vaultEmbeddingCacheRef.current.clear();
12475
+ vaultEmbeddingCache.clear();
12448
12476
  chunkVectorCacheRef.current.clear();
12449
12477
  });
12450
- }, []);
12478
+ }, [vaultEmbeddingCache]);
12451
12479
  const createMemoryVaultSearchTool2 = useCallback4(
12452
12480
  (searchOptions) => {
12453
12481
  if (!getToken) {
@@ -12456,11 +12484,11 @@ function useChatStorage(options) {
12456
12484
  return createMemoryVaultSearchTool(
12457
12485
  vaultCtx,
12458
12486
  vaultEmbeddingOptions,
12459
- vaultEmbeddingCacheRef.current,
12487
+ vaultEmbeddingCache,
12460
12488
  searchOptions
12461
12489
  );
12462
12490
  },
12463
- [vaultCtx, getToken, vaultEmbeddingOptions]
12491
+ [vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache]
12464
12492
  );
12465
12493
  const createRecallTool2 = useCallback4(
12466
12494
  (toolOptions, callbacks) => {
@@ -12473,7 +12501,7 @@ function useChatStorage(options) {
12473
12501
  vaultCtx,
12474
12502
  storageCtx,
12475
12503
  embeddingOptions: vaultEmbeddingOptions,
12476
- vaultCache: vaultEmbeddingCacheRef.current,
12504
+ vaultCache: vaultEmbeddingCache,
12477
12505
  chunkCache: chunkVectorCacheRef.current,
12478
12506
  // Graph lane fires when entityCtx is present and the query
12479
12507
  // contains extractable entities. Empty memory_entity (e.g.
@@ -12485,7 +12513,15 @@ function useChatStorage(options) {
12485
12513
  callbacks
12486
12514
  );
12487
12515
  },
12488
- [vaultCtx, storageCtx, entityCtx, getToken, vaultEmbeddingOptions, currentConversationId]
12516
+ [
12517
+ vaultCtx,
12518
+ storageCtx,
12519
+ entityCtx,
12520
+ getToken,
12521
+ vaultEmbeddingOptions,
12522
+ vaultEmbeddingCache,
12523
+ currentConversationId
12524
+ ]
12489
12525
  );
12490
12526
  const searchVaultMemoriesFn = useCallback4(
12491
12527
  async (query, searchOptions) => {
@@ -12494,11 +12530,11 @@ function useChatStorage(options) {
12494
12530
  query,
12495
12531
  vaultCtx,
12496
12532
  vaultEmbeddingOptions,
12497
- vaultEmbeddingCacheRef.current,
12533
+ vaultEmbeddingCache,
12498
12534
  searchOptions
12499
12535
  );
12500
12536
  },
12501
- [vaultCtx, getToken, vaultEmbeddingOptions]
12537
+ [vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache]
12502
12538
  );
12503
12539
  const recallFn = useCallback4(
12504
12540
  async (query, options2) => {
@@ -12521,7 +12557,7 @@ function useChatStorage(options) {
12521
12557
  // createRecallTool / searchVaultMemoriesFn. Without this, recall()
12522
12558
  // would embed the raw query (often containing the user's PII).
12523
12559
  embeddingOptions: vaultEmbeddingOptions,
12524
- vaultCache: vaultEmbeddingCacheRef.current,
12560
+ vaultCache: vaultEmbeddingCache,
12525
12561
  chunkCache: chunkVectorCacheRef.current,
12526
12562
  // Graph lane fires only when entityCtx is present and the query
12527
12563
  // has extractable entities; empty memory_entity is a graceful
@@ -12531,7 +12567,15 @@ function useChatStorage(options) {
12531
12567
  resolvedOptions
12532
12568
  );
12533
12569
  },
12534
- [vaultCtx, storageCtx, entityCtx, getToken, currentConversationId, vaultEmbeddingOptions]
12570
+ [
12571
+ vaultCtx,
12572
+ storageCtx,
12573
+ entityCtx,
12574
+ getToken,
12575
+ currentConversationId,
12576
+ vaultEmbeddingOptions,
12577
+ vaultEmbeddingCache
12578
+ ]
12535
12579
  );
12536
12580
  const {
12537
12581
  isLoading,
@@ -13641,7 +13685,7 @@ Based on these results, continue with the task.`;
13641
13685
  createRecallTool: createRecallTool2,
13642
13686
  recall: recallFn,
13643
13687
  searchVaultMemories: searchVaultMemoriesFn,
13644
- vaultEmbeddingCache: vaultEmbeddingCacheRef.current,
13688
+ vaultEmbeddingCache,
13645
13689
  getVaultMemories,
13646
13690
  createVaultMemory,
13647
13691
  updateVaultMemory,
@@ -20310,7 +20310,7 @@ function createMemoryVaultSearchTool(vaultCtx, embeddingOptions, cache, searchOp
20310
20310
  legacy.map((r) => ({ id: r.uniqueId, content: r.content, score: r.similarity }))
20311
20311
  );
20312
20312
  }
20313
- const { recall: recall2 } = await import("./recall-RMCSM6L6.mjs");
20313
+ const { recall: recall2 } = await import("./recall-YZWIV6IH.mjs");
20314
20314
  let recallDegraded = [];
20315
20315
  const result = await recall2(
20316
20316
  query,
@@ -21357,14 +21357,14 @@ export {
21357
21357
  embedAllMessages,
21358
21358
  chunkAndEmbedMessage,
21359
21359
  chunkAndEmbedAllMessages,
21360
+ DEFAULT_VAULT_CACHE_SIZE,
21361
+ LRUCache,
21362
+ createVaultEmbeddingCache,
21360
21363
  RECALL_TOOL_NAME,
21361
21364
  RECALL_MAX_LIMIT,
21362
21365
  EMBEDDINGS_DEGRADED_EMPTY,
21363
21366
  RerankerUnavailableError,
21364
21367
  isRerankerAvailable,
21365
- DEFAULT_VAULT_CACHE_SIZE,
21366
- LRUCache,
21367
- createVaultEmbeddingCache,
21368
21368
  MAX_HOPS,
21369
21369
  ENTITY_FANOUT,
21370
21370
  NODE_BUDGET,
@@ -19576,6 +19576,44 @@ var init_embeddings = __esm({
19576
19576
  }
19577
19577
  });
19578
19578
 
19579
+ // src/lib/memoryVault/lruCache.ts
19580
+ function createVaultEmbeddingCache(maxSize = DEFAULT_VAULT_CACHE_SIZE) {
19581
+ return new LRUCache(maxSize);
19582
+ }
19583
+ var DEFAULT_VAULT_CACHE_SIZE, LRUCache;
19584
+ var init_lruCache = __esm({
19585
+ "src/lib/memoryVault/lruCache.ts"() {
19586
+ "use strict";
19587
+ DEFAULT_VAULT_CACHE_SIZE = 5e3;
19588
+ LRUCache = class extends Map {
19589
+ constructor(maxSize) {
19590
+ super();
19591
+ this.maxSize = maxSize;
19592
+ }
19593
+ get(key) {
19594
+ if (!super.has(key)) return void 0;
19595
+ const value = super.get(key);
19596
+ super.delete(key);
19597
+ super.set(key, value);
19598
+ return value;
19599
+ }
19600
+ set(key, value) {
19601
+ if (super.has(key)) {
19602
+ super.delete(key);
19603
+ }
19604
+ super.set(key, value);
19605
+ if (this.size > this.maxSize) {
19606
+ const oldest = this.keys().next().value;
19607
+ if (oldest !== void 0) {
19608
+ super.delete(oldest);
19609
+ }
19610
+ }
19611
+ return this;
19612
+ }
19613
+ };
19614
+ }
19615
+ });
19616
+
19579
19617
  // src/lib/memory/mmr.ts
19580
19618
  function applyMMR(candidates, k, lambda = 0.5) {
19581
19619
  if (candidates.length === 0 || k <= 0) return [];
@@ -20355,44 +20393,6 @@ Output strict JSON. No prose.`;
20355
20393
  }
20356
20394
  });
20357
20395
 
20358
- // src/lib/memoryVault/lruCache.ts
20359
- function createVaultEmbeddingCache(maxSize = DEFAULT_VAULT_CACHE_SIZE) {
20360
- return new LRUCache(maxSize);
20361
- }
20362
- var DEFAULT_VAULT_CACHE_SIZE, LRUCache;
20363
- var init_lruCache = __esm({
20364
- "src/lib/memoryVault/lruCache.ts"() {
20365
- "use strict";
20366
- DEFAULT_VAULT_CACHE_SIZE = 5e3;
20367
- LRUCache = class extends Map {
20368
- constructor(maxSize) {
20369
- super();
20370
- this.maxSize = maxSize;
20371
- }
20372
- get(key) {
20373
- if (!super.has(key)) return void 0;
20374
- const value = super.get(key);
20375
- super.delete(key);
20376
- super.set(key, value);
20377
- return value;
20378
- }
20379
- set(key, value) {
20380
- if (super.has(key)) {
20381
- super.delete(key);
20382
- }
20383
- super.set(key, value);
20384
- if (this.size > this.maxSize) {
20385
- const oldest = this.keys().next().value;
20386
- if (oldest !== void 0) {
20387
- super.delete(oldest);
20388
- }
20389
- }
20390
- return this;
20391
- }
20392
- };
20393
- }
20394
- });
20395
-
20396
20396
  // src/lib/memory/queryEntities.ts
20397
20397
  function hasMeaningfulCandidate(candidates) {
20398
20398
  for (const candidate of candidates) {
@@ -29956,7 +29956,8 @@ function configMatches(a, b) {
29956
29956
  return a.redacted === b.redacted && a.facetsSignature === b.facetsSignature && (a.reviewedMemoryIdsSignature ?? "") === b.reviewedMemoryIdsSignature && a.scopes.length === b.scopes.length && a.scopes.every((s, i) => s === b.scopes[i]);
29957
29957
  }
29958
29958
  function reviewedMemoryIdsSignature(ids) {
29959
- if (ids === void 0 || ids.length === 0) return "";
29959
+ if (ids === void 0) return "";
29960
+ if (ids.length === 0) return "\0gated-empty";
29960
29961
  return [...new Set(ids)].sort().join("\n");
29961
29962
  }
29962
29963
  function facetsSignature(facets) {
@@ -30066,7 +30067,16 @@ async function synthesizeFacet(facet, ctx, options, prior) {
30066
30067
  const factTypeWeights = { ...DEFAULT_PROFILE_FACT_TYPE_WEIGHTS, ...options.factTypeWeights };
30067
30068
  const proofCountAlpha = options.proofCountAlpha ?? DEFAULT_PROFILE_PROOF_ALPHA;
30068
30069
  const reviewed = options.reviewedMemoryIds;
30069
- const hasReviewGate = reviewed !== void 0 && reviewed.length > 0;
30070
+ const hasReviewGate = reviewed !== void 0;
30071
+ if (hasReviewGate && reviewed.length === 0) {
30072
+ return {
30073
+ key: facet.key,
30074
+ label: facet.label,
30075
+ text: "",
30076
+ sourceMemoryIds: [],
30077
+ generatedAt: Date.now()
30078
+ };
30079
+ }
30070
30080
  const recalled = await recall(facet.query, ctx, {
30071
30081
  scopes,
30072
30082
  limit: hasReviewGate ? RECALL_MAX_LIMIT : limit,
@@ -8356,10 +8356,20 @@ interface SynthesizeProfileOptions extends PortalLlmAuth {
8356
8356
  */
8357
8357
  proofCountAlpha?: number;
8358
8358
  /**
8359
- * When non-empty, intersect each facet's recalled evidence with this id set
8360
- * before the LLM runs (publish-review gate). Empty intersection → empty
8361
- * section (legitimate no-evidence), not a stale fallback. Omit / empty →
8362
- * no gate.
8359
+ * Publish-review gate: when SUPPLIED, each facet's recalled evidence is
8360
+ * intersected with this id set before the LLM runs, so synthesis can only draw
8361
+ * on memories the user approved for publication. Empty intersection → empty
8362
+ * section (legitimate no-evidence), not a stale fallback.
8363
+ *
8364
+ * Pass the user's published set (e.g. `getAllVaultMemoriesOp(ctx, { visibility:
8365
+ * ["public"] })`) to keep a published profile derivable only from published
8366
+ * memories — People Nearby's two-tier model treats `private` memories as never
8367
+ * leaving the device, and a summary derived from them is a derivative that does.
8368
+ *
8369
+ * `[]` means "nothing approved" and gates everything OUT (no recall, no LLM
8370
+ * call, empty sections). **Omitting the field is the only way to run ungated**
8371
+ * — that asymmetry is deliberate, so a caller computing a published set can
8372
+ * never accidentally disable the gate by finding it empty.
8363
8373
  */
8364
8374
  reviewedMemoryIds?: readonly string[];
8365
8375
  }
@@ -8356,10 +8356,20 @@ interface SynthesizeProfileOptions extends PortalLlmAuth {
8356
8356
  */
8357
8357
  proofCountAlpha?: number;
8358
8358
  /**
8359
- * When non-empty, intersect each facet's recalled evidence with this id set
8360
- * before the LLM runs (publish-review gate). Empty intersection → empty
8361
- * section (legitimate no-evidence), not a stale fallback. Omit / empty →
8362
- * no gate.
8359
+ * Publish-review gate: when SUPPLIED, each facet's recalled evidence is
8360
+ * intersected with this id set before the LLM runs, so synthesis can only draw
8361
+ * on memories the user approved for publication. Empty intersection → empty
8362
+ * section (legitimate no-evidence), not a stale fallback.
8363
+ *
8364
+ * Pass the user's published set (e.g. `getAllVaultMemoriesOp(ctx, { visibility:
8365
+ * ["public"] })`) to keep a published profile derivable only from published
8366
+ * memories — People Nearby's two-tier model treats `private` memories as never
8367
+ * leaving the device, and a summary derived from them is a derivative that does.
8368
+ *
8369
+ * `[]` means "nothing approved" and gates everything OUT (no recall, no LLM
8370
+ * call, empty sections). **Omitting the field is the only way to run ungated**
8371
+ * — that asymmetry is deliberate, so a caller computing a published set can
8372
+ * never accidentally disable the gate by finding it empty.
8363
8373
  */
8364
8374
  reviewedMemoryIds?: readonly string[];
8365
8375
  }
@@ -133,7 +133,7 @@ import {
133
133
  updateVaultMemoryOp,
134
134
  upsertMessageOp,
135
135
  vaultMemoryToStored
136
- } from "./chunk-ME6ZQN52.mjs";
136
+ } from "./chunk-WZE6ZVKE.mjs";
137
137
  import {
138
138
  createStreamingDeAnonymizer,
139
139
  notifyConsolidationFallback,
@@ -6991,7 +6991,8 @@ function configMatches(a, b) {
6991
6991
  return a.redacted === b.redacted && a.facetsSignature === b.facetsSignature && (a.reviewedMemoryIdsSignature ?? "") === b.reviewedMemoryIdsSignature && a.scopes.length === b.scopes.length && a.scopes.every((s, i) => s === b.scopes[i]);
6992
6992
  }
6993
6993
  function reviewedMemoryIdsSignature(ids) {
6994
- if (ids === void 0 || ids.length === 0) return "";
6994
+ if (ids === void 0) return "";
6995
+ if (ids.length === 0) return "\0gated-empty";
6995
6996
  return [...new Set(ids)].sort().join("\n");
6996
6997
  }
6997
6998
  function facetsSignature(facets) {
@@ -7101,7 +7102,16 @@ async function synthesizeFacet(facet, ctx, options, prior) {
7101
7102
  const factTypeWeights = { ...DEFAULT_PROFILE_FACT_TYPE_WEIGHTS, ...options.factTypeWeights };
7102
7103
  const proofCountAlpha = options.proofCountAlpha ?? DEFAULT_PROFILE_PROOF_ALPHA;
7103
7104
  const reviewed = options.reviewedMemoryIds;
7104
- const hasReviewGate = reviewed !== void 0 && reviewed.length > 0;
7105
+ const hasReviewGate = reviewed !== void 0;
7106
+ if (hasReviewGate && reviewed.length === 0) {
7107
+ return {
7108
+ key: facet.key,
7109
+ label: facet.label,
7110
+ text: "",
7111
+ sourceMemoryIds: [],
7112
+ generatedAt: Date.now()
7113
+ };
7114
+ }
7105
7115
  const recalled = await recall(facet.query, ctx, {
7106
7116
  scopes,
7107
7117
  limit: hasReviewGate ? RECALL_MAX_LIMIT : limit,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  recall
3
- } from "./chunk-ME6ZQN52.mjs";
3
+ } from "./chunk-WZE6ZVKE.mjs";
4
4
  import "./chunk-OBDRKQQI.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.13.1",
3
+ "version": "4.0.0",
4
4
  "description": "",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",