@anuma/sdk 10.5.0 → 10.5.2

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.
@@ -19287,6 +19287,7 @@ init_logger();
19287
19287
  init_redactor();
19288
19288
 
19289
19289
  // src/lib/memory/entitySalience.ts
19290
+ init_patterns();
19290
19291
  var GENERIC_ENTITY_NAMES = /* @__PURE__ */ new Set([
19291
19292
  "today",
19292
19293
  "tomorrow",
@@ -19432,6 +19433,125 @@ var WEAK_MODIFIERS = /* @__PURE__ */ new Set([
19432
19433
  "and",
19433
19434
  "or"
19434
19435
  ]);
19436
+ var MAX_ENTITY_NAME_LENGTH = 120;
19437
+ var MAX_ENTITY_NAME_TOKENS = 11;
19438
+ var PREFIXED_HEX = /^0x[0-9a-f]{16,}$/i;
19439
+ var BARE_HEX = /^[0-9a-f]{32,}$/i;
19440
+ var BASE58_STRING = /^[1-9A-HJ-NP-Za-km-z]{32,88}$/;
19441
+ var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
19442
+ var TRUNCATED_ID = /^[0-9a-z]{3,}(?:…|\.{2,3})[0-9a-z]{3,}$/i;
19443
+ var KEY_SEGMENT_MIN_LENGTH = 16;
19444
+ var LONG_DIGIT_RUN = /^\d{6,}$/;
19445
+ var CURRENCY_MARKED = /[$€£¥₹₿]\d|\d[$€£¥₹₿]/;
19446
+ var NUMERIC_TOKEN = /^[~≈+\-−]?(?:us\$|[$€£¥₹₿])?\d(?:[\d,.]*\d)?(?:k|mm|m|bn|b|t|x|%|[$€£¥₹₿])?$/i;
19447
+ var PLAIN_YEAR = /^(?:1\d{3}|20\d{2})$/;
19448
+ var SUFFIXED_NAME = /^\d*[1-9][kmb]$/i;
19449
+ var BARE_INTEGER = /^\d+$/;
19450
+ var TICKER = /^\$?[A-Z]{2,6}$/;
19451
+ var DETACHED_CURRENCY_SYMBOL = /(^|\s)([$€£¥₹₿])\s+(?=\d)|(\d)\s+([$€£¥₹₿])(?=\s|$)/gu;
19452
+ var LEADING_PUNCTUATION = /^[^\p{L}\p{N}$€£¥₹₿~≈+\-−]+/u;
19453
+ var TRAILING_KEPT_CHARACTER = /[\p{L}\p{N}$€£¥₹₿%]/u;
19454
+ var LEADING_CURRENCY_CODES = /* @__PURE__ */ new Set(["usd", "eur", "gbp", "jpy", "cad", "aud", "chf", "cny"]);
19455
+ var QUANTITY_UNIT_WORDS = /* @__PURE__ */ new Set([
19456
+ "usd",
19457
+ "usdc",
19458
+ "usdt",
19459
+ "eur",
19460
+ "gbp",
19461
+ "sol",
19462
+ "eth",
19463
+ "btc",
19464
+ "dollar",
19465
+ "dollars",
19466
+ "euro",
19467
+ "euros",
19468
+ "buck",
19469
+ "bucks",
19470
+ "k",
19471
+ "thousand",
19472
+ "million",
19473
+ "billion",
19474
+ "trillion",
19475
+ "share",
19476
+ "shares",
19477
+ "token",
19478
+ "tokens",
19479
+ "coin",
19480
+ "coins",
19481
+ "unit",
19482
+ "units",
19483
+ "position",
19484
+ "balance",
19485
+ "stake",
19486
+ "holdings"
19487
+ ]);
19488
+ var AMOUNT_WORDS = /* @__PURE__ */ new Set([...QUANTITY_UNIT_WORDS, "percent", "of"]);
19489
+ var NAME_PII_CATEGORIES = /* @__PURE__ */ new Set(["EMAIL", "PHONE", "SSN", "CREDIT_CARD"]);
19490
+ var NAME_PII_PATTERNS = PII_PATTERNS.filter(
19491
+ (pattern) => NAME_PII_CATEGORIES.has(pattern.category) && pattern.context === void 0
19492
+ );
19493
+ var KEPT_PLACEHOLDER_CATEGORIES = /* @__PURE__ */ new Set(["PERSON", "LOCATION", "ORG"]);
19494
+ var PLACEHOLDER_TOKEN = /\b([A-Za-z]+(?:_[A-Za-z]+)*)_\d+\b/g;
19495
+ function trimPunctuation(token) {
19496
+ const chars = Array.from(token.replace(LEADING_PUNCTUATION, ""));
19497
+ let end = chars.length;
19498
+ while (end > 0 && !TRAILING_KEPT_CHARACTER.test(chars[end - 1])) end--;
19499
+ return chars.slice(0, end).join("");
19500
+ }
19501
+ function hasLetterAndDigit(text16) {
19502
+ return /\p{L}/u.test(text16) && /\p{N}/u.test(text16);
19503
+ }
19504
+ function isIdentifierToken(token) {
19505
+ if (PREFIXED_HEX.test(token) || BARE_HEX.test(token) || BASE58_STRING.test(token)) return true;
19506
+ if (UUID.test(token) || LONG_DIGIT_RUN.test(token)) return true;
19507
+ if (TRUNCATED_ID.test(token) && hasLetterAndDigit(token)) return true;
19508
+ return token.split(/[-_.]/).some((segment) => segment.length >= KEY_SEGMENT_MIN_LENGTH && hasLetterAndDigit(segment));
19509
+ }
19510
+ function containsStructuredPii(name) {
19511
+ return NAME_PII_PATTERNS.some(
19512
+ (pattern) => (name.match(pattern.regex) ?? []).some((match) => pattern.validate?.(match) ?? true)
19513
+ );
19514
+ }
19515
+ function isAmountUnitToken(token) {
19516
+ return NUMERIC_TOKEN.test(token) || TICKER.test(token) || AMOUNT_WORDS.has(token.toLowerCase());
19517
+ }
19518
+ function isAmountWordOrNumber(token) {
19519
+ return NUMERIC_TOKEN.test(token) || AMOUNT_WORDS.has(token.toLowerCase());
19520
+ }
19521
+ function isAmount(tokens) {
19522
+ const start = LEADING_CURRENCY_CODES.has(tokens[0]?.toLowerCase() ?? "") ? 1 : 0;
19523
+ const first = tokens[start];
19524
+ if (first === void 0 || !NUMERIC_TOKEN.test(first)) return false;
19525
+ const units = tokens.slice(start + 1);
19526
+ if (start === 0 && units.length === 0)
19527
+ return !PLAIN_YEAR.test(first) && !SUFFIXED_NAME.test(first);
19528
+ if (!units.every(isAmountUnitToken)) return false;
19529
+ return start === 1 || !BARE_INTEGER.test(first) || units.some(isAmountWordOrNumber);
19530
+ }
19531
+ function hasQuantityPhrase(tokens) {
19532
+ return tokens.some(
19533
+ (token, i) => NUMERIC_TOKEN.test(token) && QUANTITY_UNIT_WORDS.has(tokens[i + 1]?.toLowerCase() ?? "")
19534
+ );
19535
+ }
19536
+ function isIdentifierOrAmountEntityName(name) {
19537
+ const trimmed = name.trim();
19538
+ if (trimmed.length > MAX_ENTITY_NAME_LENGTH) return true;
19539
+ if (containsStructuredPii(trimmed)) return true;
19540
+ const tokens = trimmed.replace(DETACHED_CURRENCY_SYMBOL, "$1$2$3$4").split(/\s+/).map(trimPunctuation).filter((token) => token.length > 0);
19541
+ if (tokens.length === 0) return false;
19542
+ if (tokens.length > MAX_ENTITY_NAME_TOKENS) return true;
19543
+ if (tokens.some(isIdentifierToken)) return true;
19544
+ if (tokens.some((token) => CURRENCY_MARKED.test(token))) return true;
19545
+ return isAmount(tokens) || hasQuantityPhrase(tokens);
19546
+ }
19547
+ function restoreEntityName(name, redactor) {
19548
+ for (const [token, category] of name.matchAll(PLACEHOLDER_TOKEN)) {
19549
+ if (KEPT_PLACEHOLDER_CATEGORIES.has(category.toUpperCase())) continue;
19550
+ if (redactor.restoreForStorage(token).text !== token) return null;
19551
+ }
19552
+ const restored = redactor.restoreForStorage(name);
19553
+ return restored.unresolved || isIdentifierOrAmountEntityName(restored.text) ? null : restored.text;
19554
+ }
19435
19555
 
19436
19556
  // src/lib/memory/injectionClassifier.ts
19437
19557
  init_logger();
@@ -21285,12 +21405,16 @@ async function prepareVaultCandidates(query, vaultCtx, embeddingOptions, cache,
21285
21405
  const currentModel = embeddingOptions.model ?? DEFAULT_API_EMBEDDING_MODEL;
21286
21406
  const uncachedTexts = [];
21287
21407
  const uncachedIndices = [];
21408
+ const resolvedVectors = /* @__PURE__ */ new Map();
21288
21409
  let staleReembedCount = 0;
21289
21410
  for (let i = 0; queryEmbedding.length > 0 && i < memories.length; i++) {
21290
21411
  const content = memories[i].content;
21291
21412
  const memoryId = memories[i].uniqueId;
21292
21413
  const cached = cachedRowVector(cache, memoryId, memories[i].updatedAt, content);
21293
- if (cached && cached.length === queryEmbedding.length) continue;
21414
+ if (cached && cached.length === queryEmbedding.length) {
21415
+ resolvedVectors.set(memoryId, cached);
21416
+ continue;
21417
+ }
21294
21418
  if (cached) cache.delete(memoryId);
21295
21419
  const storedModel = memories[i].embeddingModel;
21296
21420
  const modelCompatible = (storedModel ?? currentModel) === currentModel;
@@ -21298,13 +21422,9 @@ async function prepareVaultCandidates(query, vaultCtx, embeddingOptions, cache,
21298
21422
  try {
21299
21423
  const parsed = JSON.parse(memories[i].embedding);
21300
21424
  if (Array.isArray(parsed) && parsed.length === queryEmbedding.length) {
21301
- cacheRowVector(
21302
- cache,
21303
- memoryId,
21304
- Float32Array.from(parsed),
21305
- memories[i].updatedAt,
21306
- content
21307
- );
21425
+ const vector2 = Float32Array.from(parsed);
21426
+ resolvedVectors.set(memoryId, vector2);
21427
+ cacheRowVector(cache, memoryId, vector2, memories[i].updatedAt, content);
21308
21428
  continue;
21309
21429
  }
21310
21430
  } catch {
@@ -21337,20 +21457,17 @@ async function prepareVaultCandidates(query, vaultCtx, embeddingOptions, cache,
21337
21457
  }
21338
21458
  if (newEmbeddings) {
21339
21459
  for (let j = 0; j < uncachedTexts.length; j++) {
21340
- cacheRowVector(
21341
- cache,
21342
- memories[uncachedIndices[j]].uniqueId,
21343
- Float32Array.from(newEmbeddings[j]),
21344
- memories[uncachedIndices[j]].updatedAt,
21345
- memories[uncachedIndices[j]].content
21346
- );
21460
+ const memory = memories[uncachedIndices[j]];
21461
+ const vector2 = Float32Array.from(newEmbeddings[j]);
21462
+ resolvedVectors.set(memory.uniqueId, vector2);
21463
+ cacheRowVector(cache, memory.uniqueId, vector2, memory.updatedAt, memory.content);
21347
21464
  }
21348
21465
  }
21349
21466
  }
21350
21467
  embeddedItems = memories.map((m) => ({
21351
21468
  id: m.uniqueId,
21352
21469
  content: m.content,
21353
- embedding: cache.get(m.uniqueId) ?? [],
21470
+ embedding: resolvedVectors.get(m.uniqueId) ?? [],
21354
21471
  createdAt: m.createdAt,
21355
21472
  updatedAt: m.updatedAt,
21356
21473
  proofCount: m.proofCount,
@@ -22244,8 +22361,8 @@ function restoreCandidates(candidates, redactor, ownNames) {
22244
22361
  ...c,
22245
22362
  content: content.text,
22246
22363
  entities: c.entities.flatMap((e) => {
22247
- const restored = redactor.restoreForStorage(e.name);
22248
- return restored.unresolved ? [] : [{ ...e, name: restored.text }];
22364
+ const name = restoreEntityName(e.name, redactor);
22365
+ return name === null ? [] : [{ ...e, name }];
22249
22366
  })
22250
22367
  },
22251
22368
  unresolved: content.unresolved
@@ -22513,18 +22630,21 @@ function validateCandidates(parsed, validIds, userIds, fallbackSourceId, ownName
22513
22630
  }
22514
22631
  return out;
22515
22632
  }
22633
+ function isAcceptedEntityName(name) {
22634
+ return name.length > 0 && !isGenericEntityName(name) && !isIdentifierOrAmountEntityName(name);
22635
+ }
22516
22636
  function parseEntities(raw) {
22517
22637
  const out = [];
22518
22638
  for (const e of raw) {
22519
22639
  if (typeof e === "string") {
22520
22640
  const name2 = e.trim();
22521
- if (name2.length > 0 && !isGenericEntityName(name2)) out.push({ name: name2 });
22641
+ if (isAcceptedEntityName(name2)) out.push({ name: name2 });
22522
22642
  continue;
22523
22643
  }
22524
22644
  if (typeof e !== "object" || e === null) continue;
22525
22645
  const obj = e;
22526
22646
  const name = typeof obj.name === "string" ? obj.name.trim() : "";
22527
- if (name.length === 0 || isGenericEntityName(name)) continue;
22647
+ if (!isAcceptedEntityName(name)) continue;
22528
22648
  const kind = typeof obj.kind === "string" && ENTITY_KINDS.includes(obj.kind) ? obj.kind : void 0;
22529
22649
  const weight = typeof obj.salience === "string" && Object.keys(TOPIC_SALIENCE_WEIGHTS).includes(obj.salience) ? TOPIC_SALIENCE_WEIGHTS[obj.salience] : void 0;
22530
22650
  out.push({
@@ -24688,6 +24808,7 @@ Each memory is a short statement about the user. For each memory, list the NAMED
24688
24808
  Include only NAMED entities, skip generic/common nouns. A topic must identify a specific thing the user could recognize by name; if it would be equally true of thousands of unrelated memories, leave it out:
24689
24809
  - SKIP bare generic nouns even when the memory capitalizes them or a calendar entry is titled that way \u2014 "Home", "Work", "Meeting", "Lunch", "Birthday", "Appointment", "Trip", "Today", "Friday", "March" are NOT topics.
24690
24810
  - KEEP the specific thing instead, when the memory names one: "Blue Bottle on Valencia" over "cafe", "Chicago Marathon" over "event", "Hollowpoint Labs" over "work".
24811
+ - SKIP identifiers and numbers \u2014 addresses, hashes, keys, account or order numbers, balances, prices, amounts and position sizes are NOT topics. Use the general subject instead: "Solana" or "trading" rather than "3.5 SOL" or an address.
24691
24812
  - Prefer 0 entities over a weak one. A memory whose only candidate is a generic noun has NO entities.
24692
24813
  ${ENTITY_KIND_GUIDELINES}
24693
24814
 
@@ -24793,8 +24914,8 @@ List each memory's named entities.`,
24793
24914
  }
24794
24915
  function restoreEntities(entities, redactor) {
24795
24916
  return entities.flatMap((e) => {
24796
- const restored = redactor.restoreForStorage(e.name);
24797
- return restored.unresolved ? [] : [{ ...e, name: restored.text }];
24917
+ const name = restoreEntityName(e.name, redactor);
24918
+ return name === null ? [] : [{ ...e, name }];
24798
24919
  });
24799
24920
  }
24800
24921
  function parseTopicResponse(parsed, validIds) {
@@ -17756,6 +17756,125 @@ var WEAK_MODIFIERS = /* @__PURE__ */ new Set([
17756
17756
  "and",
17757
17757
  "or"
17758
17758
  ]);
17759
+ var MAX_ENTITY_NAME_LENGTH = 120;
17760
+ var MAX_ENTITY_NAME_TOKENS = 11;
17761
+ var PREFIXED_HEX = /^0x[0-9a-f]{16,}$/i;
17762
+ var BARE_HEX = /^[0-9a-f]{32,}$/i;
17763
+ var BASE58_STRING = /^[1-9A-HJ-NP-Za-km-z]{32,88}$/;
17764
+ var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
17765
+ var TRUNCATED_ID = /^[0-9a-z]{3,}(?:…|\.{2,3})[0-9a-z]{3,}$/i;
17766
+ var KEY_SEGMENT_MIN_LENGTH = 16;
17767
+ var LONG_DIGIT_RUN = /^\d{6,}$/;
17768
+ var CURRENCY_MARKED = /[$€£¥₹₿]\d|\d[$€£¥₹₿]/;
17769
+ var NUMERIC_TOKEN = /^[~≈+\-−]?(?:us\$|[$€£¥₹₿])?\d(?:[\d,.]*\d)?(?:k|mm|m|bn|b|t|x|%|[$€£¥₹₿])?$/i;
17770
+ var PLAIN_YEAR = /^(?:1\d{3}|20\d{2})$/;
17771
+ var SUFFIXED_NAME = /^\d*[1-9][kmb]$/i;
17772
+ var BARE_INTEGER = /^\d+$/;
17773
+ var TICKER = /^\$?[A-Z]{2,6}$/;
17774
+ var DETACHED_CURRENCY_SYMBOL = /(^|\s)([$€£¥₹₿])\s+(?=\d)|(\d)\s+([$€£¥₹₿])(?=\s|$)/gu;
17775
+ var LEADING_PUNCTUATION = /^[^\p{L}\p{N}$€£¥₹₿~≈+\-−]+/u;
17776
+ var TRAILING_KEPT_CHARACTER = /[\p{L}\p{N}$€£¥₹₿%]/u;
17777
+ var LEADING_CURRENCY_CODES = /* @__PURE__ */ new Set(["usd", "eur", "gbp", "jpy", "cad", "aud", "chf", "cny"]);
17778
+ var QUANTITY_UNIT_WORDS = /* @__PURE__ */ new Set([
17779
+ "usd",
17780
+ "usdc",
17781
+ "usdt",
17782
+ "eur",
17783
+ "gbp",
17784
+ "sol",
17785
+ "eth",
17786
+ "btc",
17787
+ "dollar",
17788
+ "dollars",
17789
+ "euro",
17790
+ "euros",
17791
+ "buck",
17792
+ "bucks",
17793
+ "k",
17794
+ "thousand",
17795
+ "million",
17796
+ "billion",
17797
+ "trillion",
17798
+ "share",
17799
+ "shares",
17800
+ "token",
17801
+ "tokens",
17802
+ "coin",
17803
+ "coins",
17804
+ "unit",
17805
+ "units",
17806
+ "position",
17807
+ "balance",
17808
+ "stake",
17809
+ "holdings"
17810
+ ]);
17811
+ var AMOUNT_WORDS = /* @__PURE__ */ new Set([...QUANTITY_UNIT_WORDS, "percent", "of"]);
17812
+ var NAME_PII_CATEGORIES = /* @__PURE__ */ new Set(["EMAIL", "PHONE", "SSN", "CREDIT_CARD"]);
17813
+ var NAME_PII_PATTERNS = PII_PATTERNS.filter(
17814
+ (pattern) => NAME_PII_CATEGORIES.has(pattern.category) && pattern.context === void 0
17815
+ );
17816
+ var KEPT_PLACEHOLDER_CATEGORIES = /* @__PURE__ */ new Set(["PERSON", "LOCATION", "ORG"]);
17817
+ var PLACEHOLDER_TOKEN = /\b([A-Za-z]+(?:_[A-Za-z]+)*)_\d+\b/g;
17818
+ function trimPunctuation(token) {
17819
+ const chars = Array.from(token.replace(LEADING_PUNCTUATION, ""));
17820
+ let end = chars.length;
17821
+ while (end > 0 && !TRAILING_KEPT_CHARACTER.test(chars[end - 1])) end--;
17822
+ return chars.slice(0, end).join("");
17823
+ }
17824
+ function hasLetterAndDigit(text16) {
17825
+ return /\p{L}/u.test(text16) && /\p{N}/u.test(text16);
17826
+ }
17827
+ function isIdentifierToken(token) {
17828
+ if (PREFIXED_HEX.test(token) || BARE_HEX.test(token) || BASE58_STRING.test(token)) return true;
17829
+ if (UUID.test(token) || LONG_DIGIT_RUN.test(token)) return true;
17830
+ if (TRUNCATED_ID.test(token) && hasLetterAndDigit(token)) return true;
17831
+ return token.split(/[-_.]/).some((segment) => segment.length >= KEY_SEGMENT_MIN_LENGTH && hasLetterAndDigit(segment));
17832
+ }
17833
+ function containsStructuredPii(name) {
17834
+ return NAME_PII_PATTERNS.some(
17835
+ (pattern) => (name.match(pattern.regex) ?? []).some((match) => pattern.validate?.(match) ?? true)
17836
+ );
17837
+ }
17838
+ function isAmountUnitToken(token) {
17839
+ return NUMERIC_TOKEN.test(token) || TICKER.test(token) || AMOUNT_WORDS.has(token.toLowerCase());
17840
+ }
17841
+ function isAmountWordOrNumber(token) {
17842
+ return NUMERIC_TOKEN.test(token) || AMOUNT_WORDS.has(token.toLowerCase());
17843
+ }
17844
+ function isAmount(tokens) {
17845
+ const start = LEADING_CURRENCY_CODES.has(tokens[0]?.toLowerCase() ?? "") ? 1 : 0;
17846
+ const first = tokens[start];
17847
+ if (first === void 0 || !NUMERIC_TOKEN.test(first)) return false;
17848
+ const units = tokens.slice(start + 1);
17849
+ if (start === 0 && units.length === 0)
17850
+ return !PLAIN_YEAR.test(first) && !SUFFIXED_NAME.test(first);
17851
+ if (!units.every(isAmountUnitToken)) return false;
17852
+ return start === 1 || !BARE_INTEGER.test(first) || units.some(isAmountWordOrNumber);
17853
+ }
17854
+ function hasQuantityPhrase(tokens) {
17855
+ return tokens.some(
17856
+ (token, i) => NUMERIC_TOKEN.test(token) && QUANTITY_UNIT_WORDS.has(tokens[i + 1]?.toLowerCase() ?? "")
17857
+ );
17858
+ }
17859
+ function isIdentifierOrAmountEntityName(name) {
17860
+ const trimmed = name.trim();
17861
+ if (trimmed.length > MAX_ENTITY_NAME_LENGTH) return true;
17862
+ if (containsStructuredPii(trimmed)) return true;
17863
+ const tokens = trimmed.replace(DETACHED_CURRENCY_SYMBOL, "$1$2$3$4").split(/\s+/).map(trimPunctuation).filter((token) => token.length > 0);
17864
+ if (tokens.length === 0) return false;
17865
+ if (tokens.length > MAX_ENTITY_NAME_TOKENS) return true;
17866
+ if (tokens.some(isIdentifierToken)) return true;
17867
+ if (tokens.some((token) => CURRENCY_MARKED.test(token))) return true;
17868
+ return isAmount(tokens) || hasQuantityPhrase(tokens);
17869
+ }
17870
+ function restoreEntityName(name, redactor) {
17871
+ for (const [token, category] of name.matchAll(PLACEHOLDER_TOKEN)) {
17872
+ if (KEPT_PLACEHOLDER_CATEGORIES.has(category.toUpperCase())) continue;
17873
+ if (redactor.restoreForStorage(token).text !== token) return null;
17874
+ }
17875
+ const restored = redactor.restoreForStorage(name);
17876
+ return restored.unresolved || isIdentifierOrAmountEntityName(restored.text) ? null : restored.text;
17877
+ }
17759
17878
 
17760
17879
  // src/lib/memory/injectionClassifier.ts
17761
17880
  var DEFAULT_MODEL = "inclusionai/ling-2.6-flash";
@@ -19593,12 +19712,16 @@ async function prepareVaultCandidates(query, vaultCtx, embeddingOptions, cache,
19593
19712
  const currentModel = embeddingOptions.model ?? DEFAULT_API_EMBEDDING_MODEL;
19594
19713
  const uncachedTexts = [];
19595
19714
  const uncachedIndices = [];
19715
+ const resolvedVectors = /* @__PURE__ */ new Map();
19596
19716
  let staleReembedCount = 0;
19597
19717
  for (let i = 0; queryEmbedding.length > 0 && i < memories.length; i++) {
19598
19718
  const content = memories[i].content;
19599
19719
  const memoryId = memories[i].uniqueId;
19600
19720
  const cached = cachedRowVector(cache, memoryId, memories[i].updatedAt, content);
19601
- if (cached && cached.length === queryEmbedding.length) continue;
19721
+ if (cached && cached.length === queryEmbedding.length) {
19722
+ resolvedVectors.set(memoryId, cached);
19723
+ continue;
19724
+ }
19602
19725
  if (cached) cache.delete(memoryId);
19603
19726
  const storedModel = memories[i].embeddingModel;
19604
19727
  const modelCompatible = (storedModel ?? currentModel) === currentModel;
@@ -19606,13 +19729,9 @@ async function prepareVaultCandidates(query, vaultCtx, embeddingOptions, cache,
19606
19729
  try {
19607
19730
  const parsed = JSON.parse(memories[i].embedding);
19608
19731
  if (Array.isArray(parsed) && parsed.length === queryEmbedding.length) {
19609
- cacheRowVector(
19610
- cache,
19611
- memoryId,
19612
- Float32Array.from(parsed),
19613
- memories[i].updatedAt,
19614
- content
19615
- );
19732
+ const vector2 = Float32Array.from(parsed);
19733
+ resolvedVectors.set(memoryId, vector2);
19734
+ cacheRowVector(cache, memoryId, vector2, memories[i].updatedAt, content);
19616
19735
  continue;
19617
19736
  }
19618
19737
  } catch {
@@ -19645,20 +19764,17 @@ async function prepareVaultCandidates(query, vaultCtx, embeddingOptions, cache,
19645
19764
  }
19646
19765
  if (newEmbeddings) {
19647
19766
  for (let j = 0; j < uncachedTexts.length; j++) {
19648
- cacheRowVector(
19649
- cache,
19650
- memories[uncachedIndices[j]].uniqueId,
19651
- Float32Array.from(newEmbeddings[j]),
19652
- memories[uncachedIndices[j]].updatedAt,
19653
- memories[uncachedIndices[j]].content
19654
- );
19767
+ const memory = memories[uncachedIndices[j]];
19768
+ const vector2 = Float32Array.from(newEmbeddings[j]);
19769
+ resolvedVectors.set(memory.uniqueId, vector2);
19770
+ cacheRowVector(cache, memory.uniqueId, vector2, memory.updatedAt, memory.content);
19655
19771
  }
19656
19772
  }
19657
19773
  }
19658
19774
  embeddedItems = memories.map((m) => ({
19659
19775
  id: m.uniqueId,
19660
19776
  content: m.content,
19661
- embedding: cache.get(m.uniqueId) ?? [],
19777
+ embedding: resolvedVectors.get(m.uniqueId) ?? [],
19662
19778
  createdAt: m.createdAt,
19663
19779
  updatedAt: m.updatedAt,
19664
19780
  proofCount: m.proofCount,
@@ -20551,8 +20667,8 @@ function restoreCandidates(candidates, redactor, ownNames) {
20551
20667
  ...c,
20552
20668
  content: content.text,
20553
20669
  entities: c.entities.flatMap((e) => {
20554
- const restored = redactor.restoreForStorage(e.name);
20555
- return restored.unresolved ? [] : [{ ...e, name: restored.text }];
20670
+ const name = restoreEntityName(e.name, redactor);
20671
+ return name === null ? [] : [{ ...e, name }];
20556
20672
  })
20557
20673
  },
20558
20674
  unresolved: content.unresolved
@@ -20820,18 +20936,21 @@ function validateCandidates(parsed, validIds, userIds, fallbackSourceId, ownName
20820
20936
  }
20821
20937
  return out;
20822
20938
  }
20939
+ function isAcceptedEntityName(name) {
20940
+ return name.length > 0 && !isGenericEntityName(name) && !isIdentifierOrAmountEntityName(name);
20941
+ }
20823
20942
  function parseEntities(raw) {
20824
20943
  const out = [];
20825
20944
  for (const e of raw) {
20826
20945
  if (typeof e === "string") {
20827
20946
  const name2 = e.trim();
20828
- if (name2.length > 0 && !isGenericEntityName(name2)) out.push({ name: name2 });
20947
+ if (isAcceptedEntityName(name2)) out.push({ name: name2 });
20829
20948
  continue;
20830
20949
  }
20831
20950
  if (typeof e !== "object" || e === null) continue;
20832
20951
  const obj = e;
20833
20952
  const name = typeof obj.name === "string" ? obj.name.trim() : "";
20834
- if (name.length === 0 || isGenericEntityName(name)) continue;
20953
+ if (!isAcceptedEntityName(name)) continue;
20835
20954
  const kind = typeof obj.kind === "string" && ENTITY_KINDS.includes(obj.kind) ? obj.kind : void 0;
20836
20955
  const weight = typeof obj.salience === "string" && Object.keys(TOPIC_SALIENCE_WEIGHTS).includes(obj.salience) ? TOPIC_SALIENCE_WEIGHTS[obj.salience] : void 0;
20837
20956
  out.push({
@@ -22974,6 +23093,7 @@ Each memory is a short statement about the user. For each memory, list the NAMED
22974
23093
  Include only NAMED entities, skip generic/common nouns. A topic must identify a specific thing the user could recognize by name; if it would be equally true of thousands of unrelated memories, leave it out:
22975
23094
  - SKIP bare generic nouns even when the memory capitalizes them or a calendar entry is titled that way \u2014 "Home", "Work", "Meeting", "Lunch", "Birthday", "Appointment", "Trip", "Today", "Friday", "March" are NOT topics.
22976
23095
  - KEEP the specific thing instead, when the memory names one: "Blue Bottle on Valencia" over "cafe", "Chicago Marathon" over "event", "Hollowpoint Labs" over "work".
23096
+ - SKIP identifiers and numbers \u2014 addresses, hashes, keys, account or order numbers, balances, prices, amounts and position sizes are NOT topics. Use the general subject instead: "Solana" or "trading" rather than "3.5 SOL" or an address.
22977
23097
  - Prefer 0 entities over a weak one. A memory whose only candidate is a generic noun has NO entities.
22978
23098
  ${ENTITY_KIND_GUIDELINES}
22979
23099
 
@@ -23079,8 +23199,8 @@ List each memory's named entities.`,
23079
23199
  }
23080
23200
  function restoreEntities(entities, redactor) {
23081
23201
  return entities.flatMap((e) => {
23082
- const restored = redactor.restoreForStorage(e.name);
23083
- return restored.unresolved ? [] : [{ ...e, name: restored.text }];
23202
+ const name = restoreEntityName(e.name, redactor);
23203
+ return name === null ? [] : [{ ...e, name }];
23084
23204
  });
23085
23205
  }
23086
23206
  function parseTopicResponse(parsed, validIds) {
@@ -1100,6 +1100,7 @@ export {
1100
1100
  setLogger,
1101
1101
  getLogger,
1102
1102
  taskTypeHeader,
1103
+ PII_PATTERNS,
1103
1104
  PiiRedactor,
1104
1105
  isPiiRedactor,
1105
1106
  resolvePiiRedactor,
@@ -4,7 +4,7 @@ import {
4
4
  notifyConsolidationFallback,
5
5
  requiresResponsesTransport,
6
6
  resolvePiiRedactor
7
- } from "./chunk-6ANL34M3.mjs";
7
+ } from "./chunk-6QCUNXU6.mjs";
8
8
  import "./chunk-GYKJOWEO.mjs";
9
9
 
10
10
  // src/lib/memory/consolidate.ts