@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.
@@ -21591,6 +21591,7 @@ init_logger();
21591
21591
  init_redactor();
21592
21592
 
21593
21593
  // src/lib/memory/entitySalience.ts
21594
+ init_patterns();
21594
21595
  var GENERIC_ENTITY_NAMES = /* @__PURE__ */ new Set([
21595
21596
  "today",
21596
21597
  "tomorrow",
@@ -21736,6 +21737,125 @@ var WEAK_MODIFIERS = /* @__PURE__ */ new Set([
21736
21737
  "and",
21737
21738
  "or"
21738
21739
  ]);
21740
+ var MAX_ENTITY_NAME_LENGTH = 120;
21741
+ var MAX_ENTITY_NAME_TOKENS = 11;
21742
+ var PREFIXED_HEX = /^0x[0-9a-f]{16,}$/i;
21743
+ var BARE_HEX = /^[0-9a-f]{32,}$/i;
21744
+ var BASE58_STRING = /^[1-9A-HJ-NP-Za-km-z]{32,88}$/;
21745
+ var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
21746
+ var TRUNCATED_ID = /^[0-9a-z]{3,}(?:…|\.{2,3})[0-9a-z]{3,}$/i;
21747
+ var KEY_SEGMENT_MIN_LENGTH = 16;
21748
+ var LONG_DIGIT_RUN = /^\d{6,}$/;
21749
+ var CURRENCY_MARKED = /[$€£¥₹₿]\d|\d[$€£¥₹₿]/;
21750
+ var NUMERIC_TOKEN = /^[~≈+\-−]?(?:us\$|[$€£¥₹₿])?\d(?:[\d,.]*\d)?(?:k|mm|m|bn|b|t|x|%|[$€£¥₹₿])?$/i;
21751
+ var PLAIN_YEAR = /^(?:1\d{3}|20\d{2})$/;
21752
+ var SUFFIXED_NAME = /^\d*[1-9][kmb]$/i;
21753
+ var BARE_INTEGER = /^\d+$/;
21754
+ var TICKER = /^\$?[A-Z]{2,6}$/;
21755
+ var DETACHED_CURRENCY_SYMBOL = /(^|\s)([$€£¥₹₿])\s+(?=\d)|(\d)\s+([$€£¥₹₿])(?=\s|$)/gu;
21756
+ var LEADING_PUNCTUATION = /^[^\p{L}\p{N}$€£¥₹₿~≈+\-−]+/u;
21757
+ var TRAILING_KEPT_CHARACTER = /[\p{L}\p{N}$€£¥₹₿%]/u;
21758
+ var LEADING_CURRENCY_CODES = /* @__PURE__ */ new Set(["usd", "eur", "gbp", "jpy", "cad", "aud", "chf", "cny"]);
21759
+ var QUANTITY_UNIT_WORDS = /* @__PURE__ */ new Set([
21760
+ "usd",
21761
+ "usdc",
21762
+ "usdt",
21763
+ "eur",
21764
+ "gbp",
21765
+ "sol",
21766
+ "eth",
21767
+ "btc",
21768
+ "dollar",
21769
+ "dollars",
21770
+ "euro",
21771
+ "euros",
21772
+ "buck",
21773
+ "bucks",
21774
+ "k",
21775
+ "thousand",
21776
+ "million",
21777
+ "billion",
21778
+ "trillion",
21779
+ "share",
21780
+ "shares",
21781
+ "token",
21782
+ "tokens",
21783
+ "coin",
21784
+ "coins",
21785
+ "unit",
21786
+ "units",
21787
+ "position",
21788
+ "balance",
21789
+ "stake",
21790
+ "holdings"
21791
+ ]);
21792
+ var AMOUNT_WORDS = /* @__PURE__ */ new Set([...QUANTITY_UNIT_WORDS, "percent", "of"]);
21793
+ var NAME_PII_CATEGORIES = /* @__PURE__ */ new Set(["EMAIL", "PHONE", "SSN", "CREDIT_CARD"]);
21794
+ var NAME_PII_PATTERNS = PII_PATTERNS.filter(
21795
+ (pattern) => NAME_PII_CATEGORIES.has(pattern.category) && pattern.context === void 0
21796
+ );
21797
+ var KEPT_PLACEHOLDER_CATEGORIES = /* @__PURE__ */ new Set(["PERSON", "LOCATION", "ORG"]);
21798
+ var PLACEHOLDER_TOKEN = /\b([A-Za-z]+(?:_[A-Za-z]+)*)_\d+\b/g;
21799
+ function trimPunctuation(token) {
21800
+ const chars = Array.from(token.replace(LEADING_PUNCTUATION, ""));
21801
+ let end = chars.length;
21802
+ while (end > 0 && !TRAILING_KEPT_CHARACTER.test(chars[end - 1])) end--;
21803
+ return chars.slice(0, end).join("");
21804
+ }
21805
+ function hasLetterAndDigit(text16) {
21806
+ return /\p{L}/u.test(text16) && /\p{N}/u.test(text16);
21807
+ }
21808
+ function isIdentifierToken(token) {
21809
+ if (PREFIXED_HEX.test(token) || BARE_HEX.test(token) || BASE58_STRING.test(token)) return true;
21810
+ if (UUID.test(token) || LONG_DIGIT_RUN.test(token)) return true;
21811
+ if (TRUNCATED_ID.test(token) && hasLetterAndDigit(token)) return true;
21812
+ return token.split(/[-_.]/).some((segment) => segment.length >= KEY_SEGMENT_MIN_LENGTH && hasLetterAndDigit(segment));
21813
+ }
21814
+ function containsStructuredPii(name) {
21815
+ return NAME_PII_PATTERNS.some(
21816
+ (pattern) => (name.match(pattern.regex) ?? []).some((match) => pattern.validate?.(match) ?? true)
21817
+ );
21818
+ }
21819
+ function isAmountUnitToken(token) {
21820
+ return NUMERIC_TOKEN.test(token) || TICKER.test(token) || AMOUNT_WORDS.has(token.toLowerCase());
21821
+ }
21822
+ function isAmountWordOrNumber(token) {
21823
+ return NUMERIC_TOKEN.test(token) || AMOUNT_WORDS.has(token.toLowerCase());
21824
+ }
21825
+ function isAmount(tokens) {
21826
+ const start = LEADING_CURRENCY_CODES.has(tokens[0]?.toLowerCase() ?? "") ? 1 : 0;
21827
+ const first = tokens[start];
21828
+ if (first === void 0 || !NUMERIC_TOKEN.test(first)) return false;
21829
+ const units = tokens.slice(start + 1);
21830
+ if (start === 0 && units.length === 0)
21831
+ return !PLAIN_YEAR.test(first) && !SUFFIXED_NAME.test(first);
21832
+ if (!units.every(isAmountUnitToken)) return false;
21833
+ return start === 1 || !BARE_INTEGER.test(first) || units.some(isAmountWordOrNumber);
21834
+ }
21835
+ function hasQuantityPhrase(tokens) {
21836
+ return tokens.some(
21837
+ (token, i) => NUMERIC_TOKEN.test(token) && QUANTITY_UNIT_WORDS.has(tokens[i + 1]?.toLowerCase() ?? "")
21838
+ );
21839
+ }
21840
+ function isIdentifierOrAmountEntityName(name) {
21841
+ const trimmed = name.trim();
21842
+ if (trimmed.length > MAX_ENTITY_NAME_LENGTH) return true;
21843
+ if (containsStructuredPii(trimmed)) return true;
21844
+ const tokens = trimmed.replace(DETACHED_CURRENCY_SYMBOL, "$1$2$3$4").split(/\s+/).map(trimPunctuation).filter((token) => token.length > 0);
21845
+ if (tokens.length === 0) return false;
21846
+ if (tokens.length > MAX_ENTITY_NAME_TOKENS) return true;
21847
+ if (tokens.some(isIdentifierToken)) return true;
21848
+ if (tokens.some((token) => CURRENCY_MARKED.test(token))) return true;
21849
+ return isAmount(tokens) || hasQuantityPhrase(tokens);
21850
+ }
21851
+ function restoreEntityName(name, redactor) {
21852
+ for (const [token, category] of name.matchAll(PLACEHOLDER_TOKEN)) {
21853
+ if (KEPT_PLACEHOLDER_CATEGORIES.has(category.toUpperCase())) continue;
21854
+ if (redactor.restoreForStorage(token).text !== token) return null;
21855
+ }
21856
+ const restored = redactor.restoreForStorage(name);
21857
+ return restored.unresolved || isIdentifierOrAmountEntityName(restored.text) ? null : restored.text;
21858
+ }
21739
21859
 
21740
21860
  // src/lib/memory/injectionClassifier.ts
21741
21861
  init_logger();
@@ -23589,12 +23709,16 @@ async function prepareVaultCandidates(query, vaultCtx, embeddingOptions, cache,
23589
23709
  const currentModel = embeddingOptions.model ?? DEFAULT_API_EMBEDDING_MODEL;
23590
23710
  const uncachedTexts = [];
23591
23711
  const uncachedIndices = [];
23712
+ const resolvedVectors = /* @__PURE__ */ new Map();
23592
23713
  let staleReembedCount = 0;
23593
23714
  for (let i = 0; queryEmbedding.length > 0 && i < memories.length; i++) {
23594
23715
  const content = memories[i].content;
23595
23716
  const memoryId = memories[i].uniqueId;
23596
23717
  const cached = cachedRowVector(cache, memoryId, memories[i].updatedAt, content);
23597
- if (cached && cached.length === queryEmbedding.length) continue;
23718
+ if (cached && cached.length === queryEmbedding.length) {
23719
+ resolvedVectors.set(memoryId, cached);
23720
+ continue;
23721
+ }
23598
23722
  if (cached) cache.delete(memoryId);
23599
23723
  const storedModel = memories[i].embeddingModel;
23600
23724
  const modelCompatible = (storedModel ?? currentModel) === currentModel;
@@ -23602,13 +23726,9 @@ async function prepareVaultCandidates(query, vaultCtx, embeddingOptions, cache,
23602
23726
  try {
23603
23727
  const parsed = JSON.parse(memories[i].embedding);
23604
23728
  if (Array.isArray(parsed) && parsed.length === queryEmbedding.length) {
23605
- cacheRowVector(
23606
- cache,
23607
- memoryId,
23608
- Float32Array.from(parsed),
23609
- memories[i].updatedAt,
23610
- content
23611
- );
23729
+ const vector2 = Float32Array.from(parsed);
23730
+ resolvedVectors.set(memoryId, vector2);
23731
+ cacheRowVector(cache, memoryId, vector2, memories[i].updatedAt, content);
23612
23732
  continue;
23613
23733
  }
23614
23734
  } catch {
@@ -23641,20 +23761,17 @@ async function prepareVaultCandidates(query, vaultCtx, embeddingOptions, cache,
23641
23761
  }
23642
23762
  if (newEmbeddings) {
23643
23763
  for (let j = 0; j < uncachedTexts.length; j++) {
23644
- cacheRowVector(
23645
- cache,
23646
- memories[uncachedIndices[j]].uniqueId,
23647
- Float32Array.from(newEmbeddings[j]),
23648
- memories[uncachedIndices[j]].updatedAt,
23649
- memories[uncachedIndices[j]].content
23650
- );
23764
+ const memory = memories[uncachedIndices[j]];
23765
+ const vector2 = Float32Array.from(newEmbeddings[j]);
23766
+ resolvedVectors.set(memory.uniqueId, vector2);
23767
+ cacheRowVector(cache, memory.uniqueId, vector2, memory.updatedAt, memory.content);
23651
23768
  }
23652
23769
  }
23653
23770
  }
23654
23771
  embeddedItems = memories.map((m) => ({
23655
23772
  id: m.uniqueId,
23656
23773
  content: m.content,
23657
- embedding: cache.get(m.uniqueId) ?? [],
23774
+ embedding: resolvedVectors.get(m.uniqueId) ?? [],
23658
23775
  createdAt: m.createdAt,
23659
23776
  updatedAt: m.updatedAt,
23660
23777
  proofCount: m.proofCount,
@@ -24548,8 +24665,8 @@ function restoreCandidates(candidates, redactor, ownNames) {
24548
24665
  ...c,
24549
24666
  content: content.text,
24550
24667
  entities: c.entities.flatMap((e) => {
24551
- const restored = redactor.restoreForStorage(e.name);
24552
- return restored.unresolved ? [] : [{ ...e, name: restored.text }];
24668
+ const name = restoreEntityName(e.name, redactor);
24669
+ return name === null ? [] : [{ ...e, name }];
24553
24670
  })
24554
24671
  },
24555
24672
  unresolved: content.unresolved
@@ -24817,18 +24934,21 @@ function validateCandidates(parsed, validIds, userIds, fallbackSourceId, ownName
24817
24934
  }
24818
24935
  return out;
24819
24936
  }
24937
+ function isAcceptedEntityName(name) {
24938
+ return name.length > 0 && !isGenericEntityName(name) && !isIdentifierOrAmountEntityName(name);
24939
+ }
24820
24940
  function parseEntities(raw) {
24821
24941
  const out = [];
24822
24942
  for (const e of raw) {
24823
24943
  if (typeof e === "string") {
24824
24944
  const name2 = e.trim();
24825
- if (name2.length > 0 && !isGenericEntityName(name2)) out.push({ name: name2 });
24945
+ if (isAcceptedEntityName(name2)) out.push({ name: name2 });
24826
24946
  continue;
24827
24947
  }
24828
24948
  if (typeof e !== "object" || e === null) continue;
24829
24949
  const obj = e;
24830
24950
  const name = typeof obj.name === "string" ? obj.name.trim() : "";
24831
- if (name.length === 0 || isGenericEntityName(name)) continue;
24951
+ if (!isAcceptedEntityName(name)) continue;
24832
24952
  const kind = typeof obj.kind === "string" && ENTITY_KINDS.includes(obj.kind) ? obj.kind : void 0;
24833
24953
  const weight = typeof obj.salience === "string" && Object.keys(TOPIC_SALIENCE_WEIGHTS).includes(obj.salience) ? TOPIC_SALIENCE_WEIGHTS[obj.salience] : void 0;
24834
24954
  out.push({
@@ -27018,6 +27138,7 @@ Each memory is a short statement about the user. For each memory, list the NAMED
27018
27138
  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:
27019
27139
  - 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.
27020
27140
  - KEEP the specific thing instead, when the memory names one: "Blue Bottle on Valencia" over "cafe", "Chicago Marathon" over "event", "Hollowpoint Labs" over "work".
27141
+ - 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.
27021
27142
  - Prefer 0 entities over a weak one. A memory whose only candidate is a generic noun has NO entities.
27022
27143
  ${ENTITY_KIND_GUIDELINES}
27023
27144
 
@@ -27123,8 +27244,8 @@ List each memory's named entities.`,
27123
27244
  }
27124
27245
  function restoreEntities(entities, redactor) {
27125
27246
  return entities.flatMap((e) => {
27126
- const restored = redactor.restoreForStorage(e.name);
27127
- return restored.unresolved ? [] : [{ ...e, name: restored.text }];
27247
+ const name = restoreEntityName(e.name, redactor);
27248
+ return name === null ? [] : [{ ...e, name }];
27128
27249
  });
27129
27250
  }
27130
27251
  function parseTopicResponse(parsed, validIds) {
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  INTERNAL_FLOW_MARKER,
3
+ PII_PATTERNS,
3
4
  PiiRedactor,
4
5
  callPortalJsonCompletion,
5
6
  consoleLogger,
@@ -19,7 +20,7 @@ import {
19
20
  taskTypeHeader,
20
21
  validateEndpointOverride,
21
22
  withInternalFlowMarker
22
- } from "./chunk-6ANL34M3.mjs";
23
+ } from "./chunk-6QCUNXU6.mjs";
23
24
  import {
24
25
  BASE_URL,
25
26
  MCP_R2_DOMAIN,
@@ -19852,6 +19853,125 @@ var WEAK_MODIFIERS = /* @__PURE__ */ new Set([
19852
19853
  "and",
19853
19854
  "or"
19854
19855
  ]);
19856
+ var MAX_ENTITY_NAME_LENGTH = 120;
19857
+ var MAX_ENTITY_NAME_TOKENS = 11;
19858
+ var PREFIXED_HEX = /^0x[0-9a-f]{16,}$/i;
19859
+ var BARE_HEX = /^[0-9a-f]{32,}$/i;
19860
+ var BASE58_STRING = /^[1-9A-HJ-NP-Za-km-z]{32,88}$/;
19861
+ var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
19862
+ var TRUNCATED_ID = /^[0-9a-z]{3,}(?:…|\.{2,3})[0-9a-z]{3,}$/i;
19863
+ var KEY_SEGMENT_MIN_LENGTH = 16;
19864
+ var LONG_DIGIT_RUN = /^\d{6,}$/;
19865
+ var CURRENCY_MARKED = /[$€£¥₹₿]\d|\d[$€£¥₹₿]/;
19866
+ var NUMERIC_TOKEN = /^[~≈+\-−]?(?:us\$|[$€£¥₹₿])?\d(?:[\d,.]*\d)?(?:k|mm|m|bn|b|t|x|%|[$€£¥₹₿])?$/i;
19867
+ var PLAIN_YEAR = /^(?:1\d{3}|20\d{2})$/;
19868
+ var SUFFIXED_NAME = /^\d*[1-9][kmb]$/i;
19869
+ var BARE_INTEGER = /^\d+$/;
19870
+ var TICKER = /^\$?[A-Z]{2,6}$/;
19871
+ var DETACHED_CURRENCY_SYMBOL = /(^|\s)([$€£¥₹₿])\s+(?=\d)|(\d)\s+([$€£¥₹₿])(?=\s|$)/gu;
19872
+ var LEADING_PUNCTUATION = /^[^\p{L}\p{N}$€£¥₹₿~≈+\-−]+/u;
19873
+ var TRAILING_KEPT_CHARACTER = /[\p{L}\p{N}$€£¥₹₿%]/u;
19874
+ var LEADING_CURRENCY_CODES = /* @__PURE__ */ new Set(["usd", "eur", "gbp", "jpy", "cad", "aud", "chf", "cny"]);
19875
+ var QUANTITY_UNIT_WORDS = /* @__PURE__ */ new Set([
19876
+ "usd",
19877
+ "usdc",
19878
+ "usdt",
19879
+ "eur",
19880
+ "gbp",
19881
+ "sol",
19882
+ "eth",
19883
+ "btc",
19884
+ "dollar",
19885
+ "dollars",
19886
+ "euro",
19887
+ "euros",
19888
+ "buck",
19889
+ "bucks",
19890
+ "k",
19891
+ "thousand",
19892
+ "million",
19893
+ "billion",
19894
+ "trillion",
19895
+ "share",
19896
+ "shares",
19897
+ "token",
19898
+ "tokens",
19899
+ "coin",
19900
+ "coins",
19901
+ "unit",
19902
+ "units",
19903
+ "position",
19904
+ "balance",
19905
+ "stake",
19906
+ "holdings"
19907
+ ]);
19908
+ var AMOUNT_WORDS = /* @__PURE__ */ new Set([...QUANTITY_UNIT_WORDS, "percent", "of"]);
19909
+ var NAME_PII_CATEGORIES = /* @__PURE__ */ new Set(["EMAIL", "PHONE", "SSN", "CREDIT_CARD"]);
19910
+ var NAME_PII_PATTERNS = PII_PATTERNS.filter(
19911
+ (pattern) => NAME_PII_CATEGORIES.has(pattern.category) && pattern.context === void 0
19912
+ );
19913
+ var KEPT_PLACEHOLDER_CATEGORIES = /* @__PURE__ */ new Set(["PERSON", "LOCATION", "ORG"]);
19914
+ var PLACEHOLDER_TOKEN = /\b([A-Za-z]+(?:_[A-Za-z]+)*)_\d+\b/g;
19915
+ function trimPunctuation(token) {
19916
+ const chars = Array.from(token.replace(LEADING_PUNCTUATION, ""));
19917
+ let end = chars.length;
19918
+ while (end > 0 && !TRAILING_KEPT_CHARACTER.test(chars[end - 1])) end--;
19919
+ return chars.slice(0, end).join("");
19920
+ }
19921
+ function hasLetterAndDigit(text16) {
19922
+ return /\p{L}/u.test(text16) && /\p{N}/u.test(text16);
19923
+ }
19924
+ function isIdentifierToken(token) {
19925
+ if (PREFIXED_HEX.test(token) || BARE_HEX.test(token) || BASE58_STRING.test(token)) return true;
19926
+ if (UUID.test(token) || LONG_DIGIT_RUN.test(token)) return true;
19927
+ if (TRUNCATED_ID.test(token) && hasLetterAndDigit(token)) return true;
19928
+ return token.split(/[-_.]/).some((segment) => segment.length >= KEY_SEGMENT_MIN_LENGTH && hasLetterAndDigit(segment));
19929
+ }
19930
+ function containsStructuredPii(name) {
19931
+ return NAME_PII_PATTERNS.some(
19932
+ (pattern) => (name.match(pattern.regex) ?? []).some((match) => pattern.validate?.(match) ?? true)
19933
+ );
19934
+ }
19935
+ function isAmountUnitToken(token) {
19936
+ return NUMERIC_TOKEN.test(token) || TICKER.test(token) || AMOUNT_WORDS.has(token.toLowerCase());
19937
+ }
19938
+ function isAmountWordOrNumber(token) {
19939
+ return NUMERIC_TOKEN.test(token) || AMOUNT_WORDS.has(token.toLowerCase());
19940
+ }
19941
+ function isAmount(tokens) {
19942
+ const start = LEADING_CURRENCY_CODES.has(tokens[0]?.toLowerCase() ?? "") ? 1 : 0;
19943
+ const first = tokens[start];
19944
+ if (first === void 0 || !NUMERIC_TOKEN.test(first)) return false;
19945
+ const units = tokens.slice(start + 1);
19946
+ if (start === 0 && units.length === 0)
19947
+ return !PLAIN_YEAR.test(first) && !SUFFIXED_NAME.test(first);
19948
+ if (!units.every(isAmountUnitToken)) return false;
19949
+ return start === 1 || !BARE_INTEGER.test(first) || units.some(isAmountWordOrNumber);
19950
+ }
19951
+ function hasQuantityPhrase(tokens) {
19952
+ return tokens.some(
19953
+ (token, i) => NUMERIC_TOKEN.test(token) && QUANTITY_UNIT_WORDS.has(tokens[i + 1]?.toLowerCase() ?? "")
19954
+ );
19955
+ }
19956
+ function isIdentifierOrAmountEntityName(name) {
19957
+ const trimmed = name.trim();
19958
+ if (trimmed.length > MAX_ENTITY_NAME_LENGTH) return true;
19959
+ if (containsStructuredPii(trimmed)) return true;
19960
+ const tokens = trimmed.replace(DETACHED_CURRENCY_SYMBOL, "$1$2$3$4").split(/\s+/).map(trimPunctuation).filter((token) => token.length > 0);
19961
+ if (tokens.length === 0) return false;
19962
+ if (tokens.length > MAX_ENTITY_NAME_TOKENS) return true;
19963
+ if (tokens.some(isIdentifierToken)) return true;
19964
+ if (tokens.some((token) => CURRENCY_MARKED.test(token))) return true;
19965
+ return isAmount(tokens) || hasQuantityPhrase(tokens);
19966
+ }
19967
+ function restoreEntityName(name, redactor) {
19968
+ for (const [token, category] of name.matchAll(PLACEHOLDER_TOKEN)) {
19969
+ if (KEPT_PLACEHOLDER_CATEGORIES.has(category.toUpperCase())) continue;
19970
+ if (redactor.restoreForStorage(token).text !== token) return null;
19971
+ }
19972
+ const restored = redactor.restoreForStorage(name);
19973
+ return restored.unresolved || isIdentifierOrAmountEntityName(restored.text) ? null : restored.text;
19974
+ }
19855
19975
 
19856
19976
  // src/lib/memory/injectionClassifier.ts
19857
19977
  var DEFAULT_MODEL = "inclusionai/ling-2.6-flash";
@@ -21689,12 +21809,16 @@ async function prepareVaultCandidates(query, vaultCtx, embeddingOptions, cache,
21689
21809
  const currentModel = embeddingOptions.model ?? DEFAULT_API_EMBEDDING_MODEL;
21690
21810
  const uncachedTexts = [];
21691
21811
  const uncachedIndices = [];
21812
+ const resolvedVectors = /* @__PURE__ */ new Map();
21692
21813
  let staleReembedCount = 0;
21693
21814
  for (let i = 0; queryEmbedding.length > 0 && i < memories.length; i++) {
21694
21815
  const content = memories[i].content;
21695
21816
  const memoryId = memories[i].uniqueId;
21696
21817
  const cached = cachedRowVector(cache, memoryId, memories[i].updatedAt, content);
21697
- if (cached && cached.length === queryEmbedding.length) continue;
21818
+ if (cached && cached.length === queryEmbedding.length) {
21819
+ resolvedVectors.set(memoryId, cached);
21820
+ continue;
21821
+ }
21698
21822
  if (cached) cache.delete(memoryId);
21699
21823
  const storedModel = memories[i].embeddingModel;
21700
21824
  const modelCompatible = (storedModel ?? currentModel) === currentModel;
@@ -21702,13 +21826,9 @@ async function prepareVaultCandidates(query, vaultCtx, embeddingOptions, cache,
21702
21826
  try {
21703
21827
  const parsed = JSON.parse(memories[i].embedding);
21704
21828
  if (Array.isArray(parsed) && parsed.length === queryEmbedding.length) {
21705
- cacheRowVector(
21706
- cache,
21707
- memoryId,
21708
- Float32Array.from(parsed),
21709
- memories[i].updatedAt,
21710
- content
21711
- );
21829
+ const vector2 = Float32Array.from(parsed);
21830
+ resolvedVectors.set(memoryId, vector2);
21831
+ cacheRowVector(cache, memoryId, vector2, memories[i].updatedAt, content);
21712
21832
  continue;
21713
21833
  }
21714
21834
  } catch {
@@ -21741,20 +21861,17 @@ async function prepareVaultCandidates(query, vaultCtx, embeddingOptions, cache,
21741
21861
  }
21742
21862
  if (newEmbeddings) {
21743
21863
  for (let j = 0; j < uncachedTexts.length; j++) {
21744
- cacheRowVector(
21745
- cache,
21746
- memories[uncachedIndices[j]].uniqueId,
21747
- Float32Array.from(newEmbeddings[j]),
21748
- memories[uncachedIndices[j]].updatedAt,
21749
- memories[uncachedIndices[j]].content
21750
- );
21864
+ const memory = memories[uncachedIndices[j]];
21865
+ const vector2 = Float32Array.from(newEmbeddings[j]);
21866
+ resolvedVectors.set(memory.uniqueId, vector2);
21867
+ cacheRowVector(cache, memory.uniqueId, vector2, memory.updatedAt, memory.content);
21751
21868
  }
21752
21869
  }
21753
21870
  }
21754
21871
  embeddedItems = memories.map((m) => ({
21755
21872
  id: m.uniqueId,
21756
21873
  content: m.content,
21757
- embedding: cache.get(m.uniqueId) ?? [],
21874
+ embedding: resolvedVectors.get(m.uniqueId) ?? [],
21758
21875
  createdAt: m.createdAt,
21759
21876
  updatedAt: m.updatedAt,
21760
21877
  proofCount: m.proofCount,
@@ -22354,7 +22471,7 @@ async function tryConsolidate(trimmed, ctx, options, prepared) {
22354
22471
  content: m.content,
22355
22472
  similarity: m.similarity
22356
22473
  }));
22357
- const { consolidateMemory: doConsolidate } = await import("./consolidate-JL4P6FXW.mjs");
22474
+ const { consolidateMemory: doConsolidate } = await import("./consolidate-RASCVKD2.mjs");
22358
22475
  const decision = await doConsolidate(trimmed, candidates, consolidateOptions);
22359
22476
  if (decision.action === "create") return decision.fallbackReason ? null : { create: true };
22360
22477
  if (decision.action === "supersede" && decision.content) {
@@ -22647,8 +22764,8 @@ function restoreCandidates(candidates, redactor, ownNames) {
22647
22764
  ...c,
22648
22765
  content: content.text,
22649
22766
  entities: c.entities.flatMap((e) => {
22650
- const restored = redactor.restoreForStorage(e.name);
22651
- return restored.unresolved ? [] : [{ ...e, name: restored.text }];
22767
+ const name = restoreEntityName(e.name, redactor);
22768
+ return name === null ? [] : [{ ...e, name }];
22652
22769
  })
22653
22770
  },
22654
22771
  unresolved: content.unresolved
@@ -22916,18 +23033,21 @@ function validateCandidates(parsed, validIds, userIds, fallbackSourceId, ownName
22916
23033
  }
22917
23034
  return out;
22918
23035
  }
23036
+ function isAcceptedEntityName(name) {
23037
+ return name.length > 0 && !isGenericEntityName(name) && !isIdentifierOrAmountEntityName(name);
23038
+ }
22919
23039
  function parseEntities(raw) {
22920
23040
  const out = [];
22921
23041
  for (const e of raw) {
22922
23042
  if (typeof e === "string") {
22923
23043
  const name2 = e.trim();
22924
- if (name2.length > 0 && !isGenericEntityName(name2)) out.push({ name: name2 });
23044
+ if (isAcceptedEntityName(name2)) out.push({ name: name2 });
22925
23045
  continue;
22926
23046
  }
22927
23047
  if (typeof e !== "object" || e === null) continue;
22928
23048
  const obj = e;
22929
23049
  const name = typeof obj.name === "string" ? obj.name.trim() : "";
22930
- if (name.length === 0 || isGenericEntityName(name)) continue;
23050
+ if (!isAcceptedEntityName(name)) continue;
22931
23051
  const kind = typeof obj.kind === "string" && ENTITY_KINDS.includes(obj.kind) ? obj.kind : void 0;
22932
23052
  const weight = typeof obj.salience === "string" && Object.keys(TOPIC_SALIENCE_WEIGHTS).includes(obj.salience) ? TOPIC_SALIENCE_WEIGHTS[obj.salience] : void 0;
22933
23053
  out.push({
@@ -25096,6 +25216,7 @@ Each memory is a short statement about the user. For each memory, list the NAMED
25096
25216
  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:
25097
25217
  - 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.
25098
25218
  - KEEP the specific thing instead, when the memory names one: "Blue Bottle on Valencia" over "cafe", "Chicago Marathon" over "event", "Hollowpoint Labs" over "work".
25219
+ - 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.
25099
25220
  - Prefer 0 entities over a weak one. A memory whose only candidate is a generic noun has NO entities.
25100
25221
  ${ENTITY_KIND_GUIDELINES}
25101
25222
 
@@ -25201,8 +25322,8 @@ List each memory's named entities.`,
25201
25322
  }
25202
25323
  function restoreEntities(entities, redactor) {
25203
25324
  return entities.flatMap((e) => {
25204
- const restored = redactor.restoreForStorage(e.name);
25205
- return restored.unresolved ? [] : [{ ...e, name: restored.text }];
25325
+ const name = restoreEntityName(e.name, redactor);
25326
+ return name === null ? [] : [{ ...e, name }];
25206
25327
  });
25207
25328
  }
25208
25329
  function parseTopicResponse(parsed, validIds) {
@@ -1084,6 +1084,7 @@ function notifyConsolidationFallback(reason, onFallback, detail) {
1084
1084
  export {
1085
1085
  getLogger,
1086
1086
  taskTypeHeader,
1087
+ PII_PATTERNS,
1087
1088
  resolvePiiRedactor,
1088
1089
  createStreamingDeAnonymizer,
1089
1090
  validateEndpointOverride,
@@ -4,7 +4,7 @@ import {
4
4
  notifyConsolidationFallback,
5
5
  requiresResponsesTransport,
6
6
  resolvePiiRedactor
7
- } from "./chunk-BIMEZT3O.mjs";
7
+ } from "./chunk-JEY3L7WD.mjs";
8
8
  import "./chunk-3RPGXXPZ.mjs";
9
9
 
10
10
  // src/lib/memory/consolidate.ts