@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.
@@ -2037,6 +2037,19 @@ async function decryptVaultMemoryFields(memory, address, signMessage, embeddedWa
2037
2037
  }
2038
2038
 
2039
2039
  // src/lib/db/memoryVault/operations.ts
2040
+ function visibilityOrPrivate(value) {
2041
+ return value === "public" ? value : "private";
2042
+ }
2043
+ var NON_PRIVATE_VISIBILITIES = ["public"];
2044
+ function visibilityConditions(requested) {
2045
+ if (!requested?.length) return [];
2046
+ if (!requested.includes("private")) {
2047
+ return [Q3.where("visibility", Q3.oneOf([...requested]))];
2048
+ }
2049
+ const excluded = NON_PRIVATE_VISIBILITIES.filter((v) => !requested.includes(v));
2050
+ if (excluded.length === 0) return [];
2051
+ return [Q3.or(Q3.where("visibility", null), Q3.where("visibility", Q3.notIn(excluded)))];
2052
+ }
2040
2053
  function isOwnedByCtxUser(ctx, record) {
2041
2054
  return ctx.userId === void 0 || record.userId === ctx.userId;
2042
2055
  }
@@ -2098,6 +2111,10 @@ function vaultMemoryToStoredRaw(memory) {
2098
2111
  factType: memory.factType ?? null,
2099
2112
  archivedAt: memory.archivedAt ?? null,
2100
2113
  trustTier: memory.trustTier ?? null,
2114
+ visibility: visibilityOrPrivate(memory.visibility),
2115
+ twinOptIn: memory.twinOptIn ?? false,
2116
+ publishedAt: memory.publishedAt ?? null,
2117
+ geohash: memory.geohash ?? null,
2101
2118
  createdAt: memory.createdAt,
2102
2119
  updatedAt: memory.updatedAt,
2103
2120
  isDeleted: memory.isDeleted
@@ -2145,6 +2162,14 @@ async function createVaultMemoryOp(ctx, opts) {
2145
2162
  if (opts.trustTier !== void 0) {
2146
2163
  record._setRaw("trust_tier", normalizeTrustTier(opts.trustTier));
2147
2164
  }
2165
+ record._setRaw("visibility", opts.visibility ?? "private");
2166
+ record._setRaw(
2167
+ "published_at",
2168
+ opts.visibility && opts.visibility !== "private" ? opts.publishedAt ?? Date.now() : null
2169
+ );
2170
+ if (opts.geohash !== void 0) {
2171
+ record._setRaw("geohash", opts.geohash);
2172
+ }
2148
2173
  });
2149
2174
  });
2150
2175
  return vaultMemoryToStored(created, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner);
@@ -2291,6 +2316,14 @@ async function createVaultMemoriesBatchOp(ctx, optionsArray) {
2291
2316
  if (opts.trustTier !== void 0) {
2292
2317
  record._setRaw("trust_tier", normalizeTrustTier(opts.trustTier));
2293
2318
  }
2319
+ record._setRaw("visibility", opts.visibility ?? "private");
2320
+ record._setRaw(
2321
+ "published_at",
2322
+ opts.visibility && opts.visibility !== "private" ? opts.publishedAt ?? Date.now() : null
2323
+ );
2324
+ if (opts.geohash !== void 0) {
2325
+ record._setRaw("geohash", opts.geohash);
2326
+ }
2294
2327
  })
2295
2328
  );
2296
2329
  await ctx.database.batch(...prepared);
@@ -2354,6 +2387,10 @@ function vaultMemoryRawToStoredRaw(raw) {
2354
2387
  factType: raw.fact_type ?? null,
2355
2388
  archivedAt: raw.archived_at ?? null,
2356
2389
  trustTier: raw.trust_tier ?? null,
2390
+ visibility: visibilityOrPrivate(raw.visibility),
2391
+ twinOptIn: raw.twin_opt_in === true || raw.twin_opt_in === 1,
2392
+ publishedAt: raw.published_at ?? null,
2393
+ geohash: raw.geohash ?? null,
2357
2394
  createdAt: new Date(raw.created_at),
2358
2395
  updatedAt: new Date(raw.updated_at),
2359
2396
  isDeleted: raw.is_deleted === true || raw.is_deleted === 1
@@ -2370,6 +2407,7 @@ async function getAllVaultMemoriesOp(ctx, options) {
2370
2407
  const conditions = [
2371
2408
  ...baseVaultConditions(ctx, options),
2372
2409
  ...options?.scopes?.length ? [Q3.where("scope", Q3.oneOf(options.scopes))] : [],
2410
+ ...visibilityConditions(options?.visibility),
2373
2411
  ...options?.folderId !== void 0 ? [Q3.where("folder_id", options.folderId)] : [],
2374
2412
  ...options?.factTypes?.length ? [Q3.where("fact_type", Q3.oneOf(options.factTypes))] : [],
2375
2413
  Q3.sortBy(options?.since ? "updated_at" : "created_at", Q3.desc),
@@ -2583,6 +2621,38 @@ async function updateVaultMemoryOp(ctx, id, opts) {
2583
2621
  return null;
2584
2622
  }
2585
2623
  }
2624
+ async function setMemoryVisibilityOp(ctx, id, opts) {
2625
+ let record;
2626
+ try {
2627
+ record = await ctx.vaultMemoryCollection.find(id);
2628
+ } catch {
2629
+ return null;
2630
+ }
2631
+ if (record.isDeleted || !isOwnedByCtxUser(ctx, record)) return null;
2632
+ let stale = false;
2633
+ await ctx.database.write(async () => {
2634
+ if (record.isDeleted || !isOwnedByCtxUser(ctx, record)) {
2635
+ stale = true;
2636
+ return;
2637
+ }
2638
+ const currentUpdatedAt = record.updatedAt.getTime();
2639
+ const currentPublishedAt = record.publishedAt ?? null;
2640
+ await record.update((r) => {
2641
+ r._setRaw("visibility", opts.visibility);
2642
+ if (opts.visibility === "private") {
2643
+ r._setRaw("published_at", null);
2644
+ } else if (currentPublishedAt === null) {
2645
+ r._setRaw("published_at", Date.now());
2646
+ }
2647
+ if (opts.twinOptIn !== void 0) {
2648
+ r._setRaw("twin_opt_in", opts.twinOptIn);
2649
+ }
2650
+ r._setRaw("updated_at", currentUpdatedAt);
2651
+ });
2652
+ });
2653
+ if (stale) return null;
2654
+ return vaultMemoryToStored(record, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner);
2655
+ }
2586
2656
  async function deleteVaultMemoryOp(ctx, id) {
2587
2657
  try {
2588
2658
  const record = await ctx.vaultMemoryCollection.find(id);
@@ -4485,24 +4555,25 @@ function tokenize(text) {
4485
4555
  if (!m) return [];
4486
4556
  return m.filter((t) => !STOPWORDS.has(t));
4487
4557
  }
4488
- function scoreBM25(query, items) {
4489
- const queryTerms = tokenize(query);
4490
- if (queryTerms.length === 0 || items.length === 0) return /* @__PURE__ */ new Map();
4558
+ function prepareBM25Corpus(items) {
4559
+ const ids = items.map((i) => i.id);
4491
4560
  const docTokens = items.map((i) => tokenize(i.content));
4492
4561
  const docLens = docTokens.map((t) => t.length);
4493
- const avgdl = docLens.reduce((a, b) => a + b, 0) / docLens.length;
4494
- const queryTermSet = new Set(queryTerms);
4562
+ const avgdl = docLens.length ? docLens.reduce((a, b) => a + b, 0) / docLens.length : 0;
4495
4563
  const df = /* @__PURE__ */ new Map();
4496
4564
  for (const tokens of docTokens) {
4497
- const seen = /* @__PURE__ */ new Set();
4498
- for (const t of tokens) {
4499
- if (queryTermSet.has(t)) seen.add(t);
4500
- }
4565
+ const seen = new Set(tokens);
4501
4566
  for (const t of seen) df.set(t, (df.get(t) ?? 0) + 1);
4502
4567
  }
4503
- const N = items.length;
4568
+ return { ids, docTokens, docLens, avgdl, df, n: items.length };
4569
+ }
4570
+ function scoreBM25Prepared(query, corpus) {
4571
+ const queryTerms = tokenize(query);
4504
4572
  const scores = /* @__PURE__ */ new Map();
4505
- for (let i = 0; i < items.length; i++) {
4573
+ if (queryTerms.length === 0 || corpus.n === 0) return scores;
4574
+ const queryTermSet = new Set(queryTerms);
4575
+ const { ids, docTokens, docLens, avgdl, df, n: N } = corpus;
4576
+ for (let i = 0; i < N; i++) {
4506
4577
  const tokens = docTokens[i];
4507
4578
  const dl = docLens[i];
4508
4579
  if (dl === 0) continue;
@@ -4518,10 +4589,15 @@ function scoreBM25(query, items) {
4518
4589
  const tfNorm = f * (K1 + 1) / (f + K1 * (1 - B + B * dl / avgdl));
4519
4590
  score += idf * tfNorm;
4520
4591
  }
4521
- scores.set(items[i].id, score);
4592
+ scores.set(ids[i], score);
4522
4593
  }
4523
4594
  return scores;
4524
4595
  }
4596
+ function scoreBM25(query, items) {
4597
+ if (items.length === 0) return /* @__PURE__ */ new Map();
4598
+ if (tokenize(query).length === 0) return /* @__PURE__ */ new Map();
4599
+ return scoreBM25Prepared(query, prepareBM25Corpus(items));
4600
+ }
4525
4601
 
4526
4602
  // src/lib/memoryVault/decomposeQuery.ts
4527
4603
  var DEFAULT_MODEL = "inclusionai/ling-2.6-flash";
@@ -4776,7 +4852,7 @@ function rankFusedVaultMemories(query, queryEmbedding, items, options) {
4776
4852
  }
4777
4853
  });
4778
4854
  const baseIds = new Set(baseRanked.map((r) => r.uniqueId));
4779
- const bm25Scores = scoreBM25(
4855
+ const bm25Scores = options?.preparedBM25Corpus ? scoreBM25Prepared(query, options.preparedBM25Corpus) : scoreBM25(
4780
4856
  query,
4781
4857
  items.map((i) => ({ id: i.id, content: i.content }))
4782
4858
  );
@@ -4973,7 +5049,11 @@ async function rankComposite(originalQuery, originalQueryEmbedding, subQueries,
4973
5049
  const limit = options?.limit ?? 5;
4974
5050
  const perFacetTopN = options?.perFacetTopN ?? 10;
4975
5051
  if (items.length === 0 || subQueries.length === 0) return [];
5052
+ const preparedBM25Corpus = prepareBM25Corpus(
5053
+ items.map((i) => ({ id: i.id, content: i.content }))
5054
+ );
4976
5055
  const facetTuning = {
5056
+ preparedBM25Corpus,
4977
5057
  ...options?.recencyAlpha !== void 0 && { recencyAlpha: options.recencyAlpha },
4978
5058
  ...options?.recency && { recency: options.recency },
4979
5059
  ...options?.supersessionBoost !== void 0 && {
@@ -5648,7 +5728,7 @@ function createMemoryVaultSearchTool(vaultCtx, embeddingOptions, cache, searchOp
5648
5728
  legacy.map((r) => ({ id: r.uniqueId, content: r.content, score: r.similarity }))
5649
5729
  );
5650
5730
  }
5651
- const { recall: recall2 } = await import("./recall-I5AZFOUM.mjs");
5731
+ const { recall: recall2 } = await import("./recall-34WI57Z7.mjs");
5652
5732
  const result = await recall2(
5653
5733
  query,
5654
5734
  { vaultCtx, embeddingOptions, vaultCache: cache },
@@ -6630,6 +6710,7 @@ export {
6630
6710
  getAllVaultMemoriesOp,
6631
6711
  getAllVaultMemoryContentsOp,
6632
6712
  updateVaultMemoryOp,
6713
+ setMemoryVisibilityOp,
6633
6714
  deleteVaultMemoryOp,
6634
6715
  supersedeVaultMemoryOp,
6635
6716
  getUnfiledVaultMemoriesOp,
@@ -8,7 +8,7 @@ import {
8
8
  import "./chunk-GYKJOWEO.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
  };
@@ -4279,6 +4279,18 @@ var init_encryption2 = __esm({
4279
4279
  });
4280
4280
 
4281
4281
  // src/lib/db/memoryVault/operations.ts
4282
+ function visibilityOrPrivate(value) {
4283
+ return value === "public" ? value : "private";
4284
+ }
4285
+ function visibilityConditions(requested) {
4286
+ if (!requested?.length) return [];
4287
+ if (!requested.includes("private")) {
4288
+ return [import_watermelondb9.Q.where("visibility", import_watermelondb9.Q.oneOf([...requested]))];
4289
+ }
4290
+ const excluded = NON_PRIVATE_VISIBILITIES.filter((v) => !requested.includes(v));
4291
+ if (excluded.length === 0) return [];
4292
+ return [import_watermelondb9.Q.or(import_watermelondb9.Q.where("visibility", null), import_watermelondb9.Q.where("visibility", import_watermelondb9.Q.notIn(excluded)))];
4293
+ }
4282
4294
  function isOwnedByCtxUser(ctx, record) {
4283
4295
  return ctx.userId === void 0 || record.userId === ctx.userId;
4284
4296
  }
@@ -4339,6 +4351,10 @@ function vaultMemoryToStoredRaw(memory) {
4339
4351
  factType: memory.factType ?? null,
4340
4352
  archivedAt: memory.archivedAt ?? null,
4341
4353
  trustTier: memory.trustTier ?? null,
4354
+ visibility: visibilityOrPrivate(memory.visibility),
4355
+ twinOptIn: memory.twinOptIn ?? false,
4356
+ publishedAt: memory.publishedAt ?? null,
4357
+ geohash: memory.geohash ?? null,
4342
4358
  createdAt: memory.createdAt,
4343
4359
  updatedAt: memory.updatedAt,
4344
4360
  isDeleted: memory.isDeleted
@@ -4386,6 +4402,14 @@ async function createVaultMemoryOp(ctx, opts) {
4386
4402
  if (opts.trustTier !== void 0) {
4387
4403
  record._setRaw("trust_tier", normalizeTrustTier(opts.trustTier));
4388
4404
  }
4405
+ record._setRaw("visibility", opts.visibility ?? "private");
4406
+ record._setRaw(
4407
+ "published_at",
4408
+ opts.visibility && opts.visibility !== "private" ? opts.publishedAt ?? Date.now() : null
4409
+ );
4410
+ if (opts.geohash !== void 0) {
4411
+ record._setRaw("geohash", opts.geohash);
4412
+ }
4389
4413
  });
4390
4414
  });
4391
4415
  return vaultMemoryToStored(created, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner);
@@ -4532,6 +4556,14 @@ async function createVaultMemoriesBatchOp(ctx, optionsArray) {
4532
4556
  if (opts.trustTier !== void 0) {
4533
4557
  record._setRaw("trust_tier", normalizeTrustTier(opts.trustTier));
4534
4558
  }
4559
+ record._setRaw("visibility", opts.visibility ?? "private");
4560
+ record._setRaw(
4561
+ "published_at",
4562
+ opts.visibility && opts.visibility !== "private" ? opts.publishedAt ?? Date.now() : null
4563
+ );
4564
+ if (opts.geohash !== void 0) {
4565
+ record._setRaw("geohash", opts.geohash);
4566
+ }
4535
4567
  })
4536
4568
  );
4537
4569
  await ctx.database.batch(...prepared);
@@ -4595,6 +4627,10 @@ function vaultMemoryRawToStoredRaw(raw) {
4595
4627
  factType: raw.fact_type ?? null,
4596
4628
  archivedAt: raw.archived_at ?? null,
4597
4629
  trustTier: raw.trust_tier ?? null,
4630
+ visibility: visibilityOrPrivate(raw.visibility),
4631
+ twinOptIn: raw.twin_opt_in === true || raw.twin_opt_in === 1,
4632
+ publishedAt: raw.published_at ?? null,
4633
+ geohash: raw.geohash ?? null,
4598
4634
  createdAt: new Date(raw.created_at),
4599
4635
  updatedAt: new Date(raw.updated_at),
4600
4636
  isDeleted: raw.is_deleted === true || raw.is_deleted === 1
@@ -4611,6 +4647,7 @@ async function getAllVaultMemoriesOp(ctx, options) {
4611
4647
  const conditions = [
4612
4648
  ...baseVaultConditions(ctx, options),
4613
4649
  ...options?.scopes?.length ? [import_watermelondb9.Q.where("scope", import_watermelondb9.Q.oneOf(options.scopes))] : [],
4650
+ ...visibilityConditions(options?.visibility),
4614
4651
  ...options?.folderId !== void 0 ? [import_watermelondb9.Q.where("folder_id", options.folderId)] : [],
4615
4652
  ...options?.factTypes?.length ? [import_watermelondb9.Q.where("fact_type", import_watermelondb9.Q.oneOf(options.factTypes))] : [],
4616
4653
  import_watermelondb9.Q.sortBy(options?.since ? "updated_at" : "created_at", import_watermelondb9.Q.desc),
@@ -4824,6 +4861,38 @@ async function updateVaultMemoryOp(ctx, id, opts) {
4824
4861
  return null;
4825
4862
  }
4826
4863
  }
4864
+ async function setMemoryVisibilityOp(ctx, id, opts) {
4865
+ let record;
4866
+ try {
4867
+ record = await ctx.vaultMemoryCollection.find(id);
4868
+ } catch {
4869
+ return null;
4870
+ }
4871
+ if (record.isDeleted || !isOwnedByCtxUser(ctx, record)) return null;
4872
+ let stale = false;
4873
+ await ctx.database.write(async () => {
4874
+ if (record.isDeleted || !isOwnedByCtxUser(ctx, record)) {
4875
+ stale = true;
4876
+ return;
4877
+ }
4878
+ const currentUpdatedAt = record.updatedAt.getTime();
4879
+ const currentPublishedAt = record.publishedAt ?? null;
4880
+ await record.update((r) => {
4881
+ r._setRaw("visibility", opts.visibility);
4882
+ if (opts.visibility === "private") {
4883
+ r._setRaw("published_at", null);
4884
+ } else if (currentPublishedAt === null) {
4885
+ r._setRaw("published_at", Date.now());
4886
+ }
4887
+ if (opts.twinOptIn !== void 0) {
4888
+ r._setRaw("twin_opt_in", opts.twinOptIn);
4889
+ }
4890
+ r._setRaw("updated_at", currentUpdatedAt);
4891
+ });
4892
+ });
4893
+ if (stale) return null;
4894
+ return vaultMemoryToStored(record, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner);
4895
+ }
4827
4896
  async function deleteVaultMemoryOp(ctx, id) {
4828
4897
  try {
4829
4898
  const record = await ctx.vaultMemoryCollection.find(id);
@@ -5113,7 +5182,7 @@ async function updateVaultMemoryEmbeddingOp(ctx, id, embedding, embeddingModel)
5113
5182
  return false;
5114
5183
  }
5115
5184
  }
5116
- var import_watermelondb9, KNOWN_TRUST_TIERS, TOPICS_EXTRACTION_VERSION;
5185
+ var import_watermelondb9, NON_PRIVATE_VISIBILITIES, KNOWN_TRUST_TIERS, TOPICS_EXTRACTION_VERSION;
5117
5186
  var init_operations3 = __esm({
5118
5187
  "src/lib/db/memoryVault/operations.ts"() {
5119
5188
  "use strict";
@@ -5121,6 +5190,7 @@ var init_operations3 = __esm({
5121
5190
  init_logger();
5122
5191
  init_operations2();
5123
5192
  init_encryption2();
5193
+ NON_PRIVATE_VISIBILITIES = ["public"];
5124
5194
  KNOWN_TRUST_TIERS = /* @__PURE__ */ new Set(["quarantined", "trusted"]);
5125
5195
  TOPICS_EXTRACTION_VERSION = 3;
5126
5196
  }
@@ -5568,24 +5638,25 @@ function tokenize(text12) {
5568
5638
  if (!m) return [];
5569
5639
  return m.filter((t) => !STOPWORDS.has(t));
5570
5640
  }
5571
- function scoreBM25(query, items) {
5572
- const queryTerms = tokenize(query);
5573
- if (queryTerms.length === 0 || items.length === 0) return /* @__PURE__ */ new Map();
5641
+ function prepareBM25Corpus(items) {
5642
+ const ids = items.map((i) => i.id);
5574
5643
  const docTokens = items.map((i) => tokenize(i.content));
5575
5644
  const docLens = docTokens.map((t) => t.length);
5576
- const avgdl = docLens.reduce((a, b) => a + b, 0) / docLens.length;
5577
- const queryTermSet = new Set(queryTerms);
5645
+ const avgdl = docLens.length ? docLens.reduce((a, b) => a + b, 0) / docLens.length : 0;
5578
5646
  const df = /* @__PURE__ */ new Map();
5579
5647
  for (const tokens of docTokens) {
5580
- const seen = /* @__PURE__ */ new Set();
5581
- for (const t of tokens) {
5582
- if (queryTermSet.has(t)) seen.add(t);
5583
- }
5648
+ const seen = new Set(tokens);
5584
5649
  for (const t of seen) df.set(t, (df.get(t) ?? 0) + 1);
5585
5650
  }
5586
- const N = items.length;
5651
+ return { ids, docTokens, docLens, avgdl, df, n: items.length };
5652
+ }
5653
+ function scoreBM25Prepared(query, corpus) {
5654
+ const queryTerms = tokenize(query);
5587
5655
  const scores = /* @__PURE__ */ new Map();
5588
- for (let i = 0; i < items.length; i++) {
5656
+ if (queryTerms.length === 0 || corpus.n === 0) return scores;
5657
+ const queryTermSet = new Set(queryTerms);
5658
+ const { ids, docTokens, docLens, avgdl, df, n: N } = corpus;
5659
+ for (let i = 0; i < N; i++) {
5589
5660
  const tokens = docTokens[i];
5590
5661
  const dl = docLens[i];
5591
5662
  if (dl === 0) continue;
@@ -5601,10 +5672,15 @@ function scoreBM25(query, items) {
5601
5672
  const tfNorm = f * (K1 + 1) / (f + K1 * (1 - B + B * dl / avgdl));
5602
5673
  score += idf * tfNorm;
5603
5674
  }
5604
- scores.set(items[i].id, score);
5675
+ scores.set(ids[i], score);
5605
5676
  }
5606
5677
  return scores;
5607
5678
  }
5679
+ function scoreBM25(query, items) {
5680
+ if (items.length === 0) return /* @__PURE__ */ new Map();
5681
+ if (tokenize(query).length === 0) return /* @__PURE__ */ new Map();
5682
+ return scoreBM25Prepared(query, prepareBM25Corpus(items));
5683
+ }
5608
5684
  var K1, B, TOKEN_RE, STOPWORDS;
5609
5685
  var init_bm25 = __esm({
5610
5686
  "src/lib/memoryVault/bm25.ts"() {
@@ -6925,7 +7001,7 @@ function rankFusedVaultMemories(query, queryEmbedding, items, options) {
6925
7001
  }
6926
7002
  });
6927
7003
  const baseIds = new Set(baseRanked.map((r) => r.uniqueId));
6928
- const bm25Scores = scoreBM25(
7004
+ const bm25Scores = options?.preparedBM25Corpus ? scoreBM25Prepared(query, options.preparedBM25Corpus) : scoreBM25(
6929
7005
  query,
6930
7006
  items.map((i) => ({ id: i.id, content: i.content }))
6931
7007
  );
@@ -7122,7 +7198,11 @@ async function rankComposite(originalQuery, originalQueryEmbedding, subQueries,
7122
7198
  const limit = options?.limit ?? 5;
7123
7199
  const perFacetTopN = options?.perFacetTopN ?? 10;
7124
7200
  if (items.length === 0 || subQueries.length === 0) return [];
7201
+ const preparedBM25Corpus = prepareBM25Corpus(
7202
+ items.map((i) => ({ id: i.id, content: i.content }))
7203
+ );
7125
7204
  const facetTuning = {
7205
+ preparedBM25Corpus,
7126
7206
  ...options?.recencyAlpha !== void 0 && { recencyAlpha: options.recencyAlpha },
7127
7207
  ...options?.recency && { recency: options.recency },
7128
7208
  ...options?.supersessionBoost !== void 0 && {
@@ -7868,6 +7948,7 @@ var init_searchTool = __esm({
7868
7948
  // src/lib/memory/consolidate.ts
7869
7949
  var consolidate_exports = {};
7870
7950
  __export(consolidate_exports, {
7951
+ DEFAULT_CONSOLIDATION_MODEL: () => DEFAULT_CONSOLIDATION_MODEL,
7871
7952
  consolidateMemory: () => consolidateMemory
7872
7953
  });
7873
7954
  async function consolidateMemory(newContent, candidates, options) {
@@ -7896,7 +7977,7 @@ ${candidateText}`;
7896
7977
  ...options.apiKey !== void 0 && { apiKey: options.apiKey },
7897
7978
  ...options.getToken !== void 0 && { getToken: options.getToken },
7898
7979
  ...options.baseUrl !== void 0 && { baseUrl: options.baseUrl },
7899
- model: options.model ?? DEFAULT_MODEL3,
7980
+ model: options.model ?? DEFAULT_CONSOLIDATION_MODEL,
7900
7981
  systemPrompt: SYSTEM_PROMPT3,
7901
7982
  userMessage,
7902
7983
  tag: "memory/consolidate",
@@ -7972,14 +8053,14 @@ function validate2(parsed, newContent, validIds) {
7972
8053
  if (!targetId || !validIds.has(targetId)) return null;
7973
8054
  return { action: "update", targetId, content: c };
7974
8055
  }
7975
- var DEFAULT_MODEL3, DEFAULT_CONSOLIDATE_ATTEMPTS, DEFAULT_CONSOLIDATE_TOTAL_TIMEOUT_MS, SYSTEM_PROMPT3;
8056
+ var DEFAULT_CONSOLIDATION_MODEL, DEFAULT_CONSOLIDATE_ATTEMPTS, DEFAULT_CONSOLIDATE_TOTAL_TIMEOUT_MS, SYSTEM_PROMPT3;
7976
8057
  var init_consolidate = __esm({
7977
8058
  "src/lib/memory/consolidate.ts"() {
7978
8059
  "use strict";
7979
8060
  init_logger();
7980
8061
  init_redactor();
7981
8062
  init_portalLlm();
7982
- DEFAULT_MODEL3 = "inclusionai/ling-2.6-flash";
8063
+ DEFAULT_CONSOLIDATION_MODEL = "inclusionai/ling-2.6-flash";
7983
8064
  DEFAULT_CONSOLIDATE_ATTEMPTS = 3;
7984
8065
  DEFAULT_CONSOLIDATE_TOTAL_TIMEOUT_MS = 2e4;
7985
8066
  SYSTEM_PROMPT3 = `You consolidate a new memory against existing memories from the same user.
@@ -8177,6 +8258,7 @@ __export(index_exports, {
8177
8258
  sdkSchema: () => sdkSchema,
8178
8259
  searchVaultMemories: () => searchVaultMemories,
8179
8260
  setLogger: () => setLogger,
8261
+ setMemoryVisibilityOp: () => setMemoryVisibilityOp,
8180
8262
  shouldChunkMessage: () => shouldChunkMessage,
8181
8263
  stampTopicsExtractedAtOp: () => stampTopicsExtractedAtOp,
8182
8264
  streamCancelPath: () => streamCancelPath,
@@ -13697,6 +13779,18 @@ __decorateClass([
13697
13779
  __decorateClass([
13698
13780
  (0, import_decorators3.field)("trust_tier")
13699
13781
  ], VaultMemory.prototype, "trustTier", 2);
13782
+ __decorateClass([
13783
+ (0, import_decorators3.field)("visibility")
13784
+ ], VaultMemory.prototype, "visibility", 2);
13785
+ __decorateClass([
13786
+ (0, import_decorators3.field)("twin_opt_in")
13787
+ ], VaultMemory.prototype, "twinOptIn", 2);
13788
+ __decorateClass([
13789
+ (0, import_decorators3.field)("published_at")
13790
+ ], VaultMemory.prototype, "publishedAt", 2);
13791
+ __decorateClass([
13792
+ (0, import_decorators3.field)("geohash")
13793
+ ], VaultMemory.prototype, "geohash", 2);
13700
13794
  __decorateClass([
13701
13795
  import_decorators3.readonly,
13702
13796
  (0, import_decorators3.date)("created_at")
@@ -15313,18 +15407,16 @@ function createAutoExtractor(options) {
15313
15407
  } catch {
15314
15408
  }
15315
15409
  };
15316
- const consolidateBaseUrl = options.consolidate?.baseUrl ?? options.extract.baseUrl;
15317
- const consolidateOptions = options.consolidate ? {
15318
- ...options.extract.apiKey !== void 0 && { apiKey: options.extract.apiKey },
15319
- ...options.extract.getToken !== void 0 && { getToken: options.extract.getToken },
15320
- ...consolidateBaseUrl !== void 0 && { baseUrl: consolidateBaseUrl },
15321
- ...options.consolidate.model !== void 0 && { model: options.consolidate.model },
15322
- ...options.consolidate.onFallback !== void 0 && {
15323
- onFallback: options.consolidate.onFallback
15324
- }
15325
- // PII redaction is inherited from `extract.piiRedaction` inside
15326
- // extractAndRetain (so direct callers are covered too), not copied here.
15327
- } : void 0;
15410
+ const subPassAuth = (baseUrlOverride) => {
15411
+ const baseUrl = baseUrlOverride ?? options.extract.baseUrl;
15412
+ return {
15413
+ ...options.extract.apiKey !== void 0 && { apiKey: options.extract.apiKey },
15414
+ ...options.extract.getToken !== void 0 && { getToken: options.extract.getToken },
15415
+ ...baseUrl !== void 0 && { baseUrl }
15416
+ };
15417
+ };
15418
+ const consolidateOptions = options.consolidate ? { ...options.consolidate, ...subPassAuth(options.consolidate.baseUrl) } : void 0;
15419
+ const injectionClassifierOptions = options.injectionClassifier ? { ...options.injectionClassifier, ...subPassAuth(options.injectionClassifier.baseUrl) } : void 0;
15328
15420
  if (options.retainCtx.vaultCtx.entityCtx && !options.entityCtx) {
15329
15421
  getLogger().warn(
15330
15422
  "[memory/extract] retainCtx.vaultCtx.entityCtx is set but extractor was created without `entityCtx` \u2014 W5 graph lane will receive no writes"
@@ -15378,6 +15470,9 @@ function createAutoExtractor(options) {
15378
15470
  ...options.scope !== void 0 && { scope: options.scope },
15379
15471
  ...options.folderId !== void 0 && { folderId: options.folderId },
15380
15472
  ...consolidateOptions !== void 0 && { consolidateOptions },
15473
+ ...injectionClassifierOptions !== void 0 && {
15474
+ injectionClassifier: injectionClassifierOptions
15475
+ },
15381
15476
  ...options.onCandidateFailed && {
15382
15477
  onCandidateFailed: (candidate, error) => options.onCandidateFailed?.({ candidate, error, conversationId })
15383
15478
  },
@@ -15513,7 +15608,7 @@ function classifyDecay(m, now, policy) {
15513
15608
  init_logger();
15514
15609
  init_redactor();
15515
15610
  init_portalLlm();
15516
- var DEFAULT_MODEL4 = "inclusionai/ling-2.6-flash";
15611
+ var DEFAULT_MODEL3 = "inclusionai/ling-2.6-flash";
15517
15612
  var DEFAULT_ATTEMPTS2 = 2;
15518
15613
  var DEFAULT_TOTAL_TIMEOUT_MS2 = 12e3;
15519
15614
  var MAX_CONTENT_CHARS = 400;
@@ -15552,7 +15647,7 @@ function createLlmDecayClassifier(options) {
15552
15647
  ...options.apiKey !== void 0 && { apiKey: options.apiKey },
15553
15648
  ...options.getToken !== void 0 && { getToken: options.getToken },
15554
15649
  ...options.baseUrl !== void 0 && { baseUrl: options.baseUrl },
15555
- model: options.model ?? DEFAULT_MODEL4,
15650
+ model: options.model ?? DEFAULT_MODEL3,
15556
15651
  systemPrompt: SYSTEM_PROMPT5,
15557
15652
  userMessage: `Memory content:
15558
15653
  ${safe}
@@ -15985,7 +16080,7 @@ init_logger();
15985
16080
  init_portalLlm();
15986
16081
  init_recall();
15987
16082
  var DEFAULT_BASE_URL2 = BASE_URL;
15988
- var DEFAULT_MODEL5 = "anthropic/claude-sonnet-4-6";
16083
+ var DEFAULT_MODEL4 = "anthropic/claude-sonnet-4-6";
15989
16084
  var DEFAULT_MAX_TOKENS = 4096;
15990
16085
  var REQUEST_TIMEOUT_MS = 6e4;
15991
16086
  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.
@@ -16017,7 +16112,7 @@ async function reflect(query, ctx, options) {
16017
16112
  const evidence = recalledMemories.map((m, i) => `[${i + 1}] (id: ${m.id}, kind: ${m.kind})
16018
16113
  ${m.content}`).join("\n\n");
16019
16114
  const baseUrl = options.baseUrl ?? DEFAULT_BASE_URL2;
16020
- const model = options.llmModel ?? DEFAULT_MODEL5;
16115
+ const model = options.llmModel ?? DEFAULT_MODEL4;
16021
16116
  const wantsStructured = !!options.responseSchema;
16022
16117
  const sendResponseFormat = wantsStructured && supportsResponseFormat(model, "json_schema");
16023
16118
  const basePrompt = options.systemPrompt ?? DEFAULT_SYSTEM_PROMPT;
@@ -19883,7 +19978,7 @@ __decorateClass([
19883
19978
  ], VaultFolder.prototype, "context", 2);
19884
19979
 
19885
19980
  // src/lib/db/schema.ts
19886
- var SDK_SCHEMA_VERSION = 40;
19981
+ var SDK_SCHEMA_VERSION = 41;
19887
19982
  var sdkSchema = (0, import_watermelondb19.appSchema)({
19888
19983
  version: SDK_SCHEMA_VERSION,
19889
19984
  tables: [
@@ -20042,7 +20137,26 @@ var sdkSchema = (0, import_watermelondb19.appSchema)({
20042
20137
  // Tier-0 security (PR3) — "quarantined" when the write-time injection
20043
20138
  // screen flagged this fact, else null/"trusted". Indexed so the recall
20044
20139
  // choke point can default-exclude quarantined rows.
20045
- { name: "trust_tier", type: "string", isOptional: true, isIndexed: true }
20140
+ { name: "trust_tier", type: "string", isOptional: true, isIndexed: true },
20141
+ // People Nearby cross-user visibility axis — ORTHOGONAL to `scope`
20142
+ // (which partitions by MODEL access: private vs shared providers).
20143
+ // TWO tiers: 'private' (or null, or any unrecognised value —
20144
+ // grandfathered / fail-safe) = local-only; 'public' = embedding +
20145
+ // plaintext may be published (matching/profile/discovery/twin).
20146
+ // The server index is the authority for what IS published; this
20147
+ // column records the user's intent.
20148
+ { name: "visibility", type: "string", isOptional: true, isIndexed: true },
20149
+ // When true, the owner opted this memory into their own digital twin
20150
+ // even if it is otherwise private (twin-scoped upload only — never
20151
+ // indexed for matching, never displayed). Null/false = follows visibility.
20152
+ { name: "twin_opt_in", type: "boolean", isOptional: true },
20153
+ // Unix ms when visibility last became non-private. Null when private
20154
+ // (cleared on revoke) — the publish reconciler uses it to diff local
20155
+ // intent against the server index.
20156
+ { name: "published_at", type: "number", isOptional: true },
20157
+ // Reserved geo slot (coarse geohash) for landmark/Trail memories.
20158
+ // Unused at launch; populated by location-tagged memory sources.
20159
+ { name: "geohash", type: "string", isOptional: true }
20046
20160
  ]
20047
20161
  }),
20048
20162
  // Entity table — canonical names extracted from auto-extraction (W5).
@@ -20717,6 +20831,24 @@ var sdkMigrations = (0, import_migrations2.schemaMigrations)({
20717
20831
  ]
20718
20832
  })
20719
20833
  ]
20834
+ },
20835
+ // v40 -> v41: People Nearby visibility axis on memory_vault. Existing rows
20836
+ // keep visibility NULL — read as 'private' (nothing pre-existing is ever
20837
+ // published without an explicit user action; the consent posture requires
20838
+ // opt-in, never a retroactive default).
20839
+ {
20840
+ toVersion: 41,
20841
+ steps: [
20842
+ (0, import_migrations2.addColumns)({
20843
+ table: "memory_vault",
20844
+ columns: [
20845
+ { name: "visibility", type: "string", isOptional: true, isIndexed: true },
20846
+ { name: "twin_opt_in", type: "boolean", isOptional: true },
20847
+ { name: "published_at", type: "number", isOptional: true },
20848
+ { name: "geohash", type: "string", isOptional: true }
20849
+ ]
20850
+ })
20851
+ ]
20720
20852
  }
20721
20853
  ]
20722
20854
  });
@@ -22211,6 +22343,7 @@ function createNotionTools(getAccessToken, requestNotionAccess) {
22211
22343
  sdkSchema,
22212
22344
  searchVaultMemories,
22213
22345
  setLogger,
22346
+ setMemoryVisibilityOp,
22214
22347
  shouldChunkMessage,
22215
22348
  stampTopicsExtractedAtOp,
22216
22349
  streamCancelPath,