@anuma/sdk 3.9.5 → 3.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16239,6 +16239,19 @@ async function decryptVaultMemoryFields(memory, address, signMessage, embeddedWa
16239
16239
  }
16240
16240
 
16241
16241
  // src/lib/db/memoryVault/operations.ts
16242
+ function visibilityOrPrivate(value) {
16243
+ return value === "public" ? value : "private";
16244
+ }
16245
+ var NON_PRIVATE_VISIBILITIES = ["public"];
16246
+ function visibilityConditions(requested) {
16247
+ if (!requested?.length) return [];
16248
+ if (!requested.includes("private")) {
16249
+ return [import_watermelondb3.Q.where("visibility", import_watermelondb3.Q.oneOf([...requested]))];
16250
+ }
16251
+ const excluded = NON_PRIVATE_VISIBILITIES.filter((v) => !requested.includes(v));
16252
+ if (excluded.length === 0) return [];
16253
+ return [import_watermelondb3.Q.or(import_watermelondb3.Q.where("visibility", null), import_watermelondb3.Q.where("visibility", import_watermelondb3.Q.notIn(excluded)))];
16254
+ }
16242
16255
  function isOwnedByCtxUser(ctx, record) {
16243
16256
  return ctx.userId === void 0 || record.userId === ctx.userId;
16244
16257
  }
@@ -16300,6 +16313,10 @@ function vaultMemoryToStoredRaw(memory) {
16300
16313
  factType: memory.factType ?? null,
16301
16314
  archivedAt: memory.archivedAt ?? null,
16302
16315
  trustTier: memory.trustTier ?? null,
16316
+ visibility: visibilityOrPrivate(memory.visibility),
16317
+ twinOptIn: memory.twinOptIn ?? false,
16318
+ publishedAt: memory.publishedAt ?? null,
16319
+ geohash: memory.geohash ?? null,
16303
16320
  createdAt: memory.createdAt,
16304
16321
  updatedAt: memory.updatedAt,
16305
16322
  isDeleted: memory.isDeleted
@@ -16347,6 +16364,14 @@ async function createVaultMemoryOp(ctx, opts) {
16347
16364
  if (opts.trustTier !== void 0) {
16348
16365
  record._setRaw("trust_tier", normalizeTrustTier(opts.trustTier));
16349
16366
  }
16367
+ record._setRaw("visibility", opts.visibility ?? "private");
16368
+ record._setRaw(
16369
+ "published_at",
16370
+ opts.visibility && opts.visibility !== "private" ? opts.publishedAt ?? Date.now() : null
16371
+ );
16372
+ if (opts.geohash !== void 0) {
16373
+ record._setRaw("geohash", opts.geohash);
16374
+ }
16350
16375
  });
16351
16376
  });
16352
16377
  return vaultMemoryToStored(created, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner);
@@ -16493,6 +16518,14 @@ async function createVaultMemoriesBatchOp(ctx, optionsArray) {
16493
16518
  if (opts.trustTier !== void 0) {
16494
16519
  record._setRaw("trust_tier", normalizeTrustTier(opts.trustTier));
16495
16520
  }
16521
+ record._setRaw("visibility", opts.visibility ?? "private");
16522
+ record._setRaw(
16523
+ "published_at",
16524
+ opts.visibility && opts.visibility !== "private" ? opts.publishedAt ?? Date.now() : null
16525
+ );
16526
+ if (opts.geohash !== void 0) {
16527
+ record._setRaw("geohash", opts.geohash);
16528
+ }
16496
16529
  })
16497
16530
  );
16498
16531
  await ctx.database.batch(...prepared);
@@ -16556,6 +16589,10 @@ function vaultMemoryRawToStoredRaw(raw) {
16556
16589
  factType: raw.fact_type ?? null,
16557
16590
  archivedAt: raw.archived_at ?? null,
16558
16591
  trustTier: raw.trust_tier ?? null,
16592
+ visibility: visibilityOrPrivate(raw.visibility),
16593
+ twinOptIn: raw.twin_opt_in === true || raw.twin_opt_in === 1,
16594
+ publishedAt: raw.published_at ?? null,
16595
+ geohash: raw.geohash ?? null,
16559
16596
  createdAt: new Date(raw.created_at),
16560
16597
  updatedAt: new Date(raw.updated_at),
16561
16598
  isDeleted: raw.is_deleted === true || raw.is_deleted === 1
@@ -16572,6 +16609,7 @@ async function getAllVaultMemoriesOp(ctx, options) {
16572
16609
  const conditions = [
16573
16610
  ...baseVaultConditions(ctx, options),
16574
16611
  ...options?.scopes?.length ? [import_watermelondb3.Q.where("scope", import_watermelondb3.Q.oneOf(options.scopes))] : [],
16612
+ ...visibilityConditions(options?.visibility),
16575
16613
  ...options?.folderId !== void 0 ? [import_watermelondb3.Q.where("folder_id", options.folderId)] : [],
16576
16614
  ...options?.factTypes?.length ? [import_watermelondb3.Q.where("fact_type", import_watermelondb3.Q.oneOf(options.factTypes))] : [],
16577
16615
  import_watermelondb3.Q.sortBy(options?.since ? "updated_at" : "created_at", import_watermelondb3.Q.desc),
@@ -16785,6 +16823,38 @@ async function updateVaultMemoryOp(ctx, id, opts) {
16785
16823
  return null;
16786
16824
  }
16787
16825
  }
16826
+ async function setMemoryVisibilityOp(ctx, id, opts) {
16827
+ let record;
16828
+ try {
16829
+ record = await ctx.vaultMemoryCollection.find(id);
16830
+ } catch {
16831
+ return null;
16832
+ }
16833
+ if (record.isDeleted || !isOwnedByCtxUser(ctx, record)) return null;
16834
+ let stale = false;
16835
+ await ctx.database.write(async () => {
16836
+ if (record.isDeleted || !isOwnedByCtxUser(ctx, record)) {
16837
+ stale = true;
16838
+ return;
16839
+ }
16840
+ const currentUpdatedAt = record.updatedAt.getTime();
16841
+ const currentPublishedAt = record.publishedAt ?? null;
16842
+ await record.update((r) => {
16843
+ r._setRaw("visibility", opts.visibility);
16844
+ if (opts.visibility === "private") {
16845
+ r._setRaw("published_at", null);
16846
+ } else if (currentPublishedAt === null) {
16847
+ r._setRaw("published_at", Date.now());
16848
+ }
16849
+ if (opts.twinOptIn !== void 0) {
16850
+ r._setRaw("twin_opt_in", opts.twinOptIn);
16851
+ }
16852
+ r._setRaw("updated_at", currentUpdatedAt);
16853
+ });
16854
+ });
16855
+ if (stale) return null;
16856
+ return vaultMemoryToStored(record, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner);
16857
+ }
16788
16858
  async function deleteVaultMemoryOp(ctx, id) {
16789
16859
  try {
16790
16860
  const record = await ctx.vaultMemoryCollection.find(id);
@@ -18676,24 +18746,25 @@ function tokenize(text) {
18676
18746
  if (!m) return [];
18677
18747
  return m.filter((t) => !STOPWORDS.has(t));
18678
18748
  }
18679
- function scoreBM25(query, items) {
18680
- const queryTerms = tokenize(query);
18681
- if (queryTerms.length === 0 || items.length === 0) return /* @__PURE__ */ new Map();
18749
+ function prepareBM25Corpus(items) {
18750
+ const ids = items.map((i) => i.id);
18682
18751
  const docTokens = items.map((i) => tokenize(i.content));
18683
18752
  const docLens = docTokens.map((t) => t.length);
18684
- const avgdl = docLens.reduce((a, b) => a + b, 0) / docLens.length;
18685
- const queryTermSet = new Set(queryTerms);
18753
+ const avgdl = docLens.length ? docLens.reduce((a, b) => a + b, 0) / docLens.length : 0;
18686
18754
  const df = /* @__PURE__ */ new Map();
18687
18755
  for (const tokens of docTokens) {
18688
- const seen = /* @__PURE__ */ new Set();
18689
- for (const t of tokens) {
18690
- if (queryTermSet.has(t)) seen.add(t);
18691
- }
18756
+ const seen = new Set(tokens);
18692
18757
  for (const t of seen) df.set(t, (df.get(t) ?? 0) + 1);
18693
18758
  }
18694
- const N = items.length;
18759
+ return { ids, docTokens, docLens, avgdl, df, n: items.length };
18760
+ }
18761
+ function scoreBM25Prepared(query, corpus) {
18762
+ const queryTerms = tokenize(query);
18695
18763
  const scores = /* @__PURE__ */ new Map();
18696
- for (let i = 0; i < items.length; i++) {
18764
+ if (queryTerms.length === 0 || corpus.n === 0) return scores;
18765
+ const queryTermSet = new Set(queryTerms);
18766
+ const { ids, docTokens, docLens, avgdl, df, n: N } = corpus;
18767
+ for (let i = 0; i < N; i++) {
18697
18768
  const tokens = docTokens[i];
18698
18769
  const dl = docLens[i];
18699
18770
  if (dl === 0) continue;
@@ -18709,10 +18780,15 @@ function scoreBM25(query, items) {
18709
18780
  const tfNorm = f * (K1 + 1) / (f + K1 * (1 - B + B * dl / avgdl));
18710
18781
  score += idf * tfNorm;
18711
18782
  }
18712
- scores.set(items[i].id, score);
18783
+ scores.set(ids[i], score);
18713
18784
  }
18714
18785
  return scores;
18715
18786
  }
18787
+ function scoreBM25(query, items) {
18788
+ if (items.length === 0) return /* @__PURE__ */ new Map();
18789
+ if (tokenize(query).length === 0) return /* @__PURE__ */ new Map();
18790
+ return scoreBM25Prepared(query, prepareBM25Corpus(items));
18791
+ }
18716
18792
 
18717
18793
  // src/lib/memoryVault/decomposeQuery.ts
18718
18794
  var DEFAULT_MODEL = "inclusionai/ling-2.6-flash";
@@ -18967,7 +19043,7 @@ function rankFusedVaultMemories(query, queryEmbedding, items, options) {
18967
19043
  }
18968
19044
  });
18969
19045
  const baseIds = new Set(baseRanked.map((r) => r.uniqueId));
18970
- const bm25Scores = scoreBM25(
19046
+ const bm25Scores = options?.preparedBM25Corpus ? scoreBM25Prepared(query, options.preparedBM25Corpus) : scoreBM25(
18971
19047
  query,
18972
19048
  items.map((i) => ({ id: i.id, content: i.content }))
18973
19049
  );
@@ -19164,7 +19240,11 @@ async function rankComposite(originalQuery, originalQueryEmbedding, subQueries,
19164
19240
  const limit = options?.limit ?? 5;
19165
19241
  const perFacetTopN = options?.perFacetTopN ?? 10;
19166
19242
  if (items.length === 0 || subQueries.length === 0) return [];
19243
+ const preparedBM25Corpus = prepareBM25Corpus(
19244
+ items.map((i) => ({ id: i.id, content: i.content }))
19245
+ );
19167
19246
  const facetTuning = {
19247
+ preparedBM25Corpus,
19168
19248
  ...options?.recencyAlpha !== void 0 && { recencyAlpha: options.recencyAlpha },
19169
19249
  ...options?.recency && { recency: options.recency },
19170
19250
  ...options?.supersessionBoost !== void 0 && {
@@ -19839,7 +19919,7 @@ function createMemoryVaultSearchTool(vaultCtx, embeddingOptions, cache, searchOp
19839
19919
  legacy.map((r) => ({ id: r.uniqueId, content: r.content, score: r.similarity }))
19840
19920
  );
19841
19921
  }
19842
- const { recall: recall2 } = await import("./recall-RVRZ4RQT.mjs");
19922
+ const { recall: recall2 } = await import("./recall-XO6QTDMG.mjs");
19843
19923
  const result = await recall2(
19844
19924
  query,
19845
19925
  { vaultCtx, embeddingOptions, vaultCache: cache },
@@ -20825,6 +20905,7 @@ export {
20825
20905
  getAllVaultMemoriesOp,
20826
20906
  getAllVaultMemoryContentsOp,
20827
20907
  updateVaultMemoryOp,
20908
+ setMemoryVisibilityOp,
20828
20909
  deleteVaultMemoryOp,
20829
20910
  supersedeVaultMemoryOp,
20830
20911
  getUnfiledVaultMemoriesOp,
@@ -8,7 +8,7 @@ import {
8
8
  import "./chunk-3RPGXXPZ.mjs";
9
9
 
10
10
  // src/lib/memory/consolidate.ts
11
- var DEFAULT_MODEL = "inclusionai/ling-2.6-flash";
11
+ var DEFAULT_CONSOLIDATION_MODEL = "inclusionai/ling-2.6-flash";
12
12
  var DEFAULT_CONSOLIDATE_ATTEMPTS = 3;
13
13
  var DEFAULT_CONSOLIDATE_TOTAL_TIMEOUT_MS = 2e4;
14
14
  var SYSTEM_PROMPT = `You consolidate a new memory against existing memories from the same user.
@@ -70,7 +70,7 @@ ${candidateText}`;
70
70
  ...options.apiKey !== void 0 && { apiKey: options.apiKey },
71
71
  ...options.getToken !== void 0 && { getToken: options.getToken },
72
72
  ...options.baseUrl !== void 0 && { baseUrl: options.baseUrl },
73
- model: options.model ?? DEFAULT_MODEL,
73
+ model: options.model ?? DEFAULT_CONSOLIDATION_MODEL,
74
74
  systemPrompt: SYSTEM_PROMPT,
75
75
  userMessage,
76
76
  tag: "memory/consolidate",
@@ -147,5 +147,6 @@ function validate(parsed, newContent, validIds) {
147
147
  return { action: "update", targetId, content: c };
148
148
  }
149
149
  export {
150
+ DEFAULT_CONSOLIDATION_MODEL,
150
151
  consolidateMemory
151
152
  };
@@ -17046,6 +17046,18 @@ var init_encryption2 = __esm({
17046
17046
  });
17047
17047
 
17048
17048
  // src/lib/db/memoryVault/operations.ts
17049
+ function visibilityOrPrivate(value) {
17050
+ return value === "public" ? value : "private";
17051
+ }
17052
+ function visibilityConditions(requested) {
17053
+ if (!requested?.length) return [];
17054
+ if (!requested.includes("private")) {
17055
+ return [import_watermelondb17.Q.where("visibility", import_watermelondb17.Q.oneOf([...requested]))];
17056
+ }
17057
+ const excluded = NON_PRIVATE_VISIBILITIES.filter((v) => !requested.includes(v));
17058
+ if (excluded.length === 0) return [];
17059
+ return [import_watermelondb17.Q.or(import_watermelondb17.Q.where("visibility", null), import_watermelondb17.Q.where("visibility", import_watermelondb17.Q.notIn(excluded)))];
17060
+ }
17049
17061
  function isOwnedByCtxUser(ctx, record) {
17050
17062
  return ctx.userId === void 0 || record.userId === ctx.userId;
17051
17063
  }
@@ -17106,6 +17118,10 @@ function vaultMemoryToStoredRaw(memory) {
17106
17118
  factType: memory.factType ?? null,
17107
17119
  archivedAt: memory.archivedAt ?? null,
17108
17120
  trustTier: memory.trustTier ?? null,
17121
+ visibility: visibilityOrPrivate(memory.visibility),
17122
+ twinOptIn: memory.twinOptIn ?? false,
17123
+ publishedAt: memory.publishedAt ?? null,
17124
+ geohash: memory.geohash ?? null,
17109
17125
  createdAt: memory.createdAt,
17110
17126
  updatedAt: memory.updatedAt,
17111
17127
  isDeleted: memory.isDeleted
@@ -17153,6 +17169,14 @@ async function createVaultMemoryOp(ctx, opts) {
17153
17169
  if (opts.trustTier !== void 0) {
17154
17170
  record._setRaw("trust_tier", normalizeTrustTier(opts.trustTier));
17155
17171
  }
17172
+ record._setRaw("visibility", opts.visibility ?? "private");
17173
+ record._setRaw(
17174
+ "published_at",
17175
+ opts.visibility && opts.visibility !== "private" ? opts.publishedAt ?? Date.now() : null
17176
+ );
17177
+ if (opts.geohash !== void 0) {
17178
+ record._setRaw("geohash", opts.geohash);
17179
+ }
17156
17180
  });
17157
17181
  });
17158
17182
  return vaultMemoryToStored(created, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner);
@@ -17299,6 +17323,14 @@ async function createVaultMemoriesBatchOp(ctx, optionsArray) {
17299
17323
  if (opts.trustTier !== void 0) {
17300
17324
  record._setRaw("trust_tier", normalizeTrustTier(opts.trustTier));
17301
17325
  }
17326
+ record._setRaw("visibility", opts.visibility ?? "private");
17327
+ record._setRaw(
17328
+ "published_at",
17329
+ opts.visibility && opts.visibility !== "private" ? opts.publishedAt ?? Date.now() : null
17330
+ );
17331
+ if (opts.geohash !== void 0) {
17332
+ record._setRaw("geohash", opts.geohash);
17333
+ }
17302
17334
  })
17303
17335
  );
17304
17336
  await ctx.database.batch(...prepared);
@@ -17362,6 +17394,10 @@ function vaultMemoryRawToStoredRaw(raw) {
17362
17394
  factType: raw.fact_type ?? null,
17363
17395
  archivedAt: raw.archived_at ?? null,
17364
17396
  trustTier: raw.trust_tier ?? null,
17397
+ visibility: visibilityOrPrivate(raw.visibility),
17398
+ twinOptIn: raw.twin_opt_in === true || raw.twin_opt_in === 1,
17399
+ publishedAt: raw.published_at ?? null,
17400
+ geohash: raw.geohash ?? null,
17365
17401
  createdAt: new Date(raw.created_at),
17366
17402
  updatedAt: new Date(raw.updated_at),
17367
17403
  isDeleted: raw.is_deleted === true || raw.is_deleted === 1
@@ -17378,6 +17414,7 @@ async function getAllVaultMemoriesOp(ctx, options) {
17378
17414
  const conditions = [
17379
17415
  ...baseVaultConditions(ctx, options),
17380
17416
  ...options?.scopes?.length ? [import_watermelondb17.Q.where("scope", import_watermelondb17.Q.oneOf(options.scopes))] : [],
17417
+ ...visibilityConditions(options?.visibility),
17381
17418
  ...options?.folderId !== void 0 ? [import_watermelondb17.Q.where("folder_id", options.folderId)] : [],
17382
17419
  ...options?.factTypes?.length ? [import_watermelondb17.Q.where("fact_type", import_watermelondb17.Q.oneOf(options.factTypes))] : [],
17383
17420
  import_watermelondb17.Q.sortBy(options?.since ? "updated_at" : "created_at", import_watermelondb17.Q.desc),
@@ -17591,6 +17628,38 @@ async function updateVaultMemoryOp(ctx, id, opts) {
17591
17628
  return null;
17592
17629
  }
17593
17630
  }
17631
+ async function setMemoryVisibilityOp(ctx, id, opts) {
17632
+ let record;
17633
+ try {
17634
+ record = await ctx.vaultMemoryCollection.find(id);
17635
+ } catch {
17636
+ return null;
17637
+ }
17638
+ if (record.isDeleted || !isOwnedByCtxUser(ctx, record)) return null;
17639
+ let stale = false;
17640
+ await ctx.database.write(async () => {
17641
+ if (record.isDeleted || !isOwnedByCtxUser(ctx, record)) {
17642
+ stale = true;
17643
+ return;
17644
+ }
17645
+ const currentUpdatedAt = record.updatedAt.getTime();
17646
+ const currentPublishedAt = record.publishedAt ?? null;
17647
+ await record.update((r) => {
17648
+ r._setRaw("visibility", opts.visibility);
17649
+ if (opts.visibility === "private") {
17650
+ r._setRaw("published_at", null);
17651
+ } else if (currentPublishedAt === null) {
17652
+ r._setRaw("published_at", Date.now());
17653
+ }
17654
+ if (opts.twinOptIn !== void 0) {
17655
+ r._setRaw("twin_opt_in", opts.twinOptIn);
17656
+ }
17657
+ r._setRaw("updated_at", currentUpdatedAt);
17658
+ });
17659
+ });
17660
+ if (stale) return null;
17661
+ return vaultMemoryToStored(record, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner);
17662
+ }
17594
17663
  async function deleteVaultMemoryOp(ctx, id) {
17595
17664
  try {
17596
17665
  const record = await ctx.vaultMemoryCollection.find(id);
@@ -17880,7 +17949,7 @@ async function updateVaultMemoryEmbeddingOp(ctx, id, embedding, embeddingModel)
17880
17949
  return false;
17881
17950
  }
17882
17951
  }
17883
- var import_watermelondb17, KNOWN_TRUST_TIERS, TOPICS_EXTRACTION_VERSION;
17952
+ var import_watermelondb17, NON_PRIVATE_VISIBILITIES, KNOWN_TRUST_TIERS, TOPICS_EXTRACTION_VERSION;
17884
17953
  var init_operations3 = __esm({
17885
17954
  "src/lib/db/memoryVault/operations.ts"() {
17886
17955
  "use strict";
@@ -17888,6 +17957,7 @@ var init_operations3 = __esm({
17888
17957
  init_logger();
17889
17958
  init_operations2();
17890
17959
  init_encryption2();
17960
+ NON_PRIVATE_VISIBILITIES = ["public"];
17891
17961
  KNOWN_TRUST_TIERS = /* @__PURE__ */ new Set(["quarantined", "trusted"]);
17892
17962
  TOPICS_EXTRACTION_VERSION = 3;
17893
17963
  }
@@ -19494,24 +19564,25 @@ function tokenize(text12) {
19494
19564
  if (!m) return [];
19495
19565
  return m.filter((t) => !STOPWORDS.has(t));
19496
19566
  }
19497
- function scoreBM25(query, items) {
19498
- const queryTerms = tokenize(query);
19499
- if (queryTerms.length === 0 || items.length === 0) return /* @__PURE__ */ new Map();
19567
+ function prepareBM25Corpus(items) {
19568
+ const ids = items.map((i) => i.id);
19500
19569
  const docTokens = items.map((i) => tokenize(i.content));
19501
19570
  const docLens = docTokens.map((t) => t.length);
19502
- const avgdl = docLens.reduce((a, b) => a + b, 0) / docLens.length;
19503
- const queryTermSet = new Set(queryTerms);
19571
+ const avgdl = docLens.length ? docLens.reduce((a, b) => a + b, 0) / docLens.length : 0;
19504
19572
  const df = /* @__PURE__ */ new Map();
19505
19573
  for (const tokens of docTokens) {
19506
- const seen = /* @__PURE__ */ new Set();
19507
- for (const t of tokens) {
19508
- if (queryTermSet.has(t)) seen.add(t);
19509
- }
19574
+ const seen = new Set(tokens);
19510
19575
  for (const t of seen) df.set(t, (df.get(t) ?? 0) + 1);
19511
19576
  }
19512
- const N = items.length;
19577
+ return { ids, docTokens, docLens, avgdl, df, n: items.length };
19578
+ }
19579
+ function scoreBM25Prepared(query, corpus) {
19580
+ const queryTerms = tokenize(query);
19513
19581
  const scores = /* @__PURE__ */ new Map();
19514
- for (let i = 0; i < items.length; i++) {
19582
+ if (queryTerms.length === 0 || corpus.n === 0) return scores;
19583
+ const queryTermSet = new Set(queryTerms);
19584
+ const { ids, docTokens, docLens, avgdl, df, n: N } = corpus;
19585
+ for (let i = 0; i < N; i++) {
19515
19586
  const tokens = docTokens[i];
19516
19587
  const dl = docLens[i];
19517
19588
  if (dl === 0) continue;
@@ -19527,10 +19598,15 @@ function scoreBM25(query, items) {
19527
19598
  const tfNorm = f * (K1 + 1) / (f + K1 * (1 - B + B * dl / avgdl));
19528
19599
  score += idf * tfNorm;
19529
19600
  }
19530
- scores.set(items[i].id, score);
19601
+ scores.set(ids[i], score);
19531
19602
  }
19532
19603
  return scores;
19533
19604
  }
19605
+ function scoreBM25(query, items) {
19606
+ if (items.length === 0) return /* @__PURE__ */ new Map();
19607
+ if (tokenize(query).length === 0) return /* @__PURE__ */ new Map();
19608
+ return scoreBM25Prepared(query, prepareBM25Corpus(items));
19609
+ }
19534
19610
  var K1, B, TOKEN_RE, STOPWORDS;
19535
19611
  var init_bm25 = __esm({
19536
19612
  "src/lib/memoryVault/bm25.ts"() {
@@ -21098,7 +21174,7 @@ function rankFusedVaultMemories(query, queryEmbedding, items, options) {
21098
21174
  }
21099
21175
  });
21100
21176
  const baseIds = new Set(baseRanked.map((r) => r.uniqueId));
21101
- const bm25Scores = scoreBM25(
21177
+ const bm25Scores = options?.preparedBM25Corpus ? scoreBM25Prepared(query, options.preparedBM25Corpus) : scoreBM25(
21102
21178
  query,
21103
21179
  items.map((i) => ({ id: i.id, content: i.content }))
21104
21180
  );
@@ -21295,7 +21371,11 @@ async function rankComposite(originalQuery, originalQueryEmbedding, subQueries,
21295
21371
  const limit = options?.limit ?? 5;
21296
21372
  const perFacetTopN = options?.perFacetTopN ?? 10;
21297
21373
  if (items.length === 0 || subQueries.length === 0) return [];
21374
+ const preparedBM25Corpus = prepareBM25Corpus(
21375
+ items.map((i) => ({ id: i.id, content: i.content }))
21376
+ );
21298
21377
  const facetTuning = {
21378
+ preparedBM25Corpus,
21299
21379
  ...options?.recencyAlpha !== void 0 && { recencyAlpha: options.recencyAlpha },
21300
21380
  ...options?.recency && { recency: options.recency },
21301
21381
  ...options?.supersessionBoost !== void 0 && {
@@ -22693,6 +22773,7 @@ var init_redactor = __esm({
22693
22773
  // src/lib/memory/consolidate.ts
22694
22774
  var consolidate_exports = {};
22695
22775
  __export(consolidate_exports, {
22776
+ DEFAULT_CONSOLIDATION_MODEL: () => DEFAULT_CONSOLIDATION_MODEL,
22696
22777
  consolidateMemory: () => consolidateMemory
22697
22778
  });
22698
22779
  async function consolidateMemory(newContent, candidates, options) {
@@ -22721,7 +22802,7 @@ ${candidateText}`;
22721
22802
  ...options.apiKey !== void 0 && { apiKey: options.apiKey },
22722
22803
  ...options.getToken !== void 0 && { getToken: options.getToken },
22723
22804
  ...options.baseUrl !== void 0 && { baseUrl: options.baseUrl },
22724
- model: options.model ?? DEFAULT_MODEL3,
22805
+ model: options.model ?? DEFAULT_CONSOLIDATION_MODEL,
22725
22806
  systemPrompt: SYSTEM_PROMPT3,
22726
22807
  userMessage,
22727
22808
  tag: "memory/consolidate",
@@ -22797,14 +22878,14 @@ function validate2(parsed, newContent, validIds) {
22797
22878
  if (!targetId || !validIds.has(targetId)) return null;
22798
22879
  return { action: "update", targetId, content: c };
22799
22880
  }
22800
- var DEFAULT_MODEL3, DEFAULT_CONSOLIDATE_ATTEMPTS, DEFAULT_CONSOLIDATE_TOTAL_TIMEOUT_MS, SYSTEM_PROMPT3;
22881
+ var DEFAULT_CONSOLIDATION_MODEL, DEFAULT_CONSOLIDATE_ATTEMPTS, DEFAULT_CONSOLIDATE_TOTAL_TIMEOUT_MS, SYSTEM_PROMPT3;
22801
22882
  var init_consolidate = __esm({
22802
22883
  "src/lib/memory/consolidate.ts"() {
22803
22884
  "use strict";
22804
22885
  init_logger();
22805
22886
  init_redactor();
22806
22887
  init_portalLlm();
22807
- DEFAULT_MODEL3 = "inclusionai/ling-2.6-flash";
22888
+ DEFAULT_CONSOLIDATION_MODEL = "inclusionai/ling-2.6-flash";
22808
22889
  DEFAULT_CONSOLIDATE_ATTEMPTS = 3;
22809
22890
  DEFAULT_CONSOLIDATE_TOTAL_TIMEOUT_MS = 2e4;
22810
22891
  SYSTEM_PROMPT3 = `You consolidate a new memory against existing memories from the same user.
@@ -23103,6 +23184,7 @@ __export(index_exports, {
23103
23184
  searchVaultMemories: () => searchVaultMemories,
23104
23185
  selectServerToolsForPrompt: () => selectServerToolsForPrompt,
23105
23186
  serverPlatformStorage: () => serverPlatformStorage,
23187
+ setMemoryVisibilityOp: () => setMemoryVisibilityOp,
23106
23188
  setModelPreferenceOp: () => setModelPreferenceOp,
23107
23189
  setUserPreferenceOp: () => setUserPreferenceOp,
23108
23190
  shouldAnalyzeStyle: () => shouldAnalyzeStyle,
@@ -23493,6 +23575,18 @@ __decorateClass([
23493
23575
  __decorateClass([
23494
23576
  (0, import_decorators6.field)("trust_tier")
23495
23577
  ], VaultMemory.prototype, "trustTier", 2);
23578
+ __decorateClass([
23579
+ (0, import_decorators6.field)("visibility")
23580
+ ], VaultMemory.prototype, "visibility", 2);
23581
+ __decorateClass([
23582
+ (0, import_decorators6.field)("twin_opt_in")
23583
+ ], VaultMemory.prototype, "twinOptIn", 2);
23584
+ __decorateClass([
23585
+ (0, import_decorators6.field)("published_at")
23586
+ ], VaultMemory.prototype, "publishedAt", 2);
23587
+ __decorateClass([
23588
+ (0, import_decorators6.field)("geohash")
23589
+ ], VaultMemory.prototype, "geohash", 2);
23496
23590
  __decorateClass([
23497
23591
  import_decorators6.readonly,
23498
23592
  (0, import_decorators6.date)("created_at")
@@ -23640,7 +23734,7 @@ __decorateClass([
23640
23734
  ], VaultFolder.prototype, "context", 2);
23641
23735
 
23642
23736
  // src/lib/db/schema.ts
23643
- var SDK_SCHEMA_VERSION = 40;
23737
+ var SDK_SCHEMA_VERSION = 41;
23644
23738
  var sdkSchema = (0, import_watermelondb12.appSchema)({
23645
23739
  version: SDK_SCHEMA_VERSION,
23646
23740
  tables: [
@@ -23799,7 +23893,26 @@ var sdkSchema = (0, import_watermelondb12.appSchema)({
23799
23893
  // Tier-0 security (PR3) — "quarantined" when the write-time injection
23800
23894
  // screen flagged this fact, else null/"trusted". Indexed so the recall
23801
23895
  // choke point can default-exclude quarantined rows.
23802
- { name: "trust_tier", type: "string", isOptional: true, isIndexed: true }
23896
+ { name: "trust_tier", type: "string", isOptional: true, isIndexed: true },
23897
+ // People Nearby cross-user visibility axis — ORTHOGONAL to `scope`
23898
+ // (which partitions by MODEL access: private vs shared providers).
23899
+ // TWO tiers: 'private' (or null, or any unrecognised value —
23900
+ // grandfathered / fail-safe) = local-only; 'public' = embedding +
23901
+ // plaintext may be published (matching/profile/discovery/twin).
23902
+ // The server index is the authority for what IS published; this
23903
+ // column records the user's intent.
23904
+ { name: "visibility", type: "string", isOptional: true, isIndexed: true },
23905
+ // When true, the owner opted this memory into their own digital twin
23906
+ // even if it is otherwise private (twin-scoped upload only — never
23907
+ // indexed for matching, never displayed). Null/false = follows visibility.
23908
+ { name: "twin_opt_in", type: "boolean", isOptional: true },
23909
+ // Unix ms when visibility last became non-private. Null when private
23910
+ // (cleared on revoke) — the publish reconciler uses it to diff local
23911
+ // intent against the server index.
23912
+ { name: "published_at", type: "number", isOptional: true },
23913
+ // Reserved geo slot (coarse geohash) for landmark/Trail memories.
23914
+ // Unused at launch; populated by location-tagged memory sources.
23915
+ { name: "geohash", type: "string", isOptional: true }
23803
23916
  ]
23804
23917
  }),
23805
23918
  // Entity table — canonical names extracted from auto-extraction (W5).
@@ -24474,6 +24587,24 @@ var sdkMigrations = (0, import_migrations.schemaMigrations)({
24474
24587
  ]
24475
24588
  })
24476
24589
  ]
24590
+ },
24591
+ // v40 -> v41: People Nearby visibility axis on memory_vault. Existing rows
24592
+ // keep visibility NULL — read as 'private' (nothing pre-existing is ever
24593
+ // published without an explicit user action; the consent posture requires
24594
+ // opt-in, never a retroactive default).
24595
+ {
24596
+ toVersion: 41,
24597
+ steps: [
24598
+ (0, import_migrations.addColumns)({
24599
+ table: "memory_vault",
24600
+ columns: [
24601
+ { name: "visibility", type: "string", isOptional: true, isIndexed: true },
24602
+ { name: "twin_opt_in", type: "boolean", isOptional: true },
24603
+ { name: "published_at", type: "number", isOptional: true },
24604
+ { name: "geohash", type: "string", isOptional: true }
24605
+ ]
24606
+ })
24607
+ ]
24477
24608
  }
24478
24609
  ]
24479
24610
  });
@@ -28469,18 +28600,16 @@ function createAutoExtractor(options) {
28469
28600
  } catch {
28470
28601
  }
28471
28602
  };
28472
- const consolidateBaseUrl = options.consolidate?.baseUrl ?? options.extract.baseUrl;
28473
- const consolidateOptions = options.consolidate ? {
28474
- ...options.extract.apiKey !== void 0 && { apiKey: options.extract.apiKey },
28475
- ...options.extract.getToken !== void 0 && { getToken: options.extract.getToken },
28476
- ...consolidateBaseUrl !== void 0 && { baseUrl: consolidateBaseUrl },
28477
- ...options.consolidate.model !== void 0 && { model: options.consolidate.model },
28478
- ...options.consolidate.onFallback !== void 0 && {
28479
- onFallback: options.consolidate.onFallback
28480
- }
28481
- // PII redaction is inherited from `extract.piiRedaction` inside
28482
- // extractAndRetain (so direct callers are covered too), not copied here.
28483
- } : void 0;
28603
+ const subPassAuth = (baseUrlOverride) => {
28604
+ const baseUrl = baseUrlOverride ?? options.extract.baseUrl;
28605
+ return {
28606
+ ...options.extract.apiKey !== void 0 && { apiKey: options.extract.apiKey },
28607
+ ...options.extract.getToken !== void 0 && { getToken: options.extract.getToken },
28608
+ ...baseUrl !== void 0 && { baseUrl }
28609
+ };
28610
+ };
28611
+ const consolidateOptions = options.consolidate ? { ...options.consolidate, ...subPassAuth(options.consolidate.baseUrl) } : void 0;
28612
+ const injectionClassifierOptions = options.injectionClassifier ? { ...options.injectionClassifier, ...subPassAuth(options.injectionClassifier.baseUrl) } : void 0;
28484
28613
  if (options.retainCtx.vaultCtx.entityCtx && !options.entityCtx) {
28485
28614
  getLogger().warn(
28486
28615
  "[memory/extract] retainCtx.vaultCtx.entityCtx is set but extractor was created without `entityCtx` \u2014 W5 graph lane will receive no writes"
@@ -28534,6 +28663,9 @@ function createAutoExtractor(options) {
28534
28663
  ...options.scope !== void 0 && { scope: options.scope },
28535
28664
  ...options.folderId !== void 0 && { folderId: options.folderId },
28536
28665
  ...consolidateOptions !== void 0 && { consolidateOptions },
28666
+ ...injectionClassifierOptions !== void 0 && {
28667
+ injectionClassifier: injectionClassifierOptions
28668
+ },
28537
28669
  ...options.onCandidateFailed && {
28538
28670
  onCandidateFailed: (candidate, error) => options.onCandidateFailed?.({ candidate, error, conversationId })
28539
28671
  },
@@ -28669,7 +28801,7 @@ function classifyDecay(m, now, policy) {
28669
28801
  init_logger();
28670
28802
  init_redactor();
28671
28803
  init_portalLlm();
28672
- var DEFAULT_MODEL4 = "inclusionai/ling-2.6-flash";
28804
+ var DEFAULT_MODEL3 = "inclusionai/ling-2.6-flash";
28673
28805
  var DEFAULT_ATTEMPTS2 = 2;
28674
28806
  var DEFAULT_TOTAL_TIMEOUT_MS2 = 12e3;
28675
28807
  var MAX_CONTENT_CHARS = 400;
@@ -28708,7 +28840,7 @@ function createLlmDecayClassifier(options) {
28708
28840
  ...options.apiKey !== void 0 && { apiKey: options.apiKey },
28709
28841
  ...options.getToken !== void 0 && { getToken: options.getToken },
28710
28842
  ...options.baseUrl !== void 0 && { baseUrl: options.baseUrl },
28711
- model: options.model ?? DEFAULT_MODEL4,
28843
+ model: options.model ?? DEFAULT_MODEL3,
28712
28844
  systemPrompt: SYSTEM_PROMPT5,
28713
28845
  userMessage: `Memory content:
28714
28846
  ${safe}
@@ -29141,7 +29273,7 @@ init_logger();
29141
29273
  init_portalLlm();
29142
29274
  init_recall();
29143
29275
  var DEFAULT_BASE_URL2 = BASE_URL;
29144
- var DEFAULT_MODEL5 = "anthropic/claude-sonnet-4-6";
29276
+ var DEFAULT_MODEL4 = "anthropic/claude-sonnet-4-6";
29145
29277
  var DEFAULT_MAX_TOKENS = 4096;
29146
29278
  var REQUEST_TIMEOUT_MS = 6e4;
29147
29279
  var DEFAULT_SYSTEM_PROMPT = `You are a personal assistant with access to the user's memory. Answer the user's question using the supplied memories as evidence.
@@ -29173,7 +29305,7 @@ async function reflect(query, ctx, options) {
29173
29305
  const evidence = recalledMemories.map((m, i) => `[${i + 1}] (id: ${m.id}, kind: ${m.kind})
29174
29306
  ${m.content}`).join("\n\n");
29175
29307
  const baseUrl = options.baseUrl ?? DEFAULT_BASE_URL2;
29176
- const model = options.llmModel ?? DEFAULT_MODEL5;
29308
+ const model = options.llmModel ?? DEFAULT_MODEL4;
29177
29309
  const wantsStructured = !!options.responseSchema;
29178
29310
  const sendResponseFormat = wantsStructured && supportsResponseFormat(model, "json_schema");
29179
29311
  const basePrompt = options.systemPrompt ?? DEFAULT_SYSTEM_PROMPT;
@@ -35669,6 +35801,7 @@ function buildSystemPrompt(ctx, options) {
35669
35801
  searchVaultMemories,
35670
35802
  selectServerToolsForPrompt,
35671
35803
  serverPlatformStorage,
35804
+ setMemoryVisibilityOp,
35672
35805
  setModelPreferenceOp,
35673
35806
  setUserPreferenceOp,
35674
35807
  shouldAnalyzeStyle,