@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.
@@ -30938,6 +30938,7 @@ init_logger();
30938
30938
  init_redactor();
30939
30939
 
30940
30940
  // src/lib/memory/entitySalience.ts
30941
+ init_patterns();
30941
30942
  var GENERIC_ENTITY_NAMES = /* @__PURE__ */ new Set([
30942
30943
  "today",
30943
30944
  "tomorrow",
@@ -31083,6 +31084,125 @@ var WEAK_MODIFIERS = /* @__PURE__ */ new Set([
31083
31084
  "and",
31084
31085
  "or"
31085
31086
  ]);
31087
+ var MAX_ENTITY_NAME_LENGTH = 120;
31088
+ var MAX_ENTITY_NAME_TOKENS = 11;
31089
+ var PREFIXED_HEX = /^0x[0-9a-f]{16,}$/i;
31090
+ var BARE_HEX = /^[0-9a-f]{32,}$/i;
31091
+ var BASE58_STRING = /^[1-9A-HJ-NP-Za-km-z]{32,88}$/;
31092
+ var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
31093
+ var TRUNCATED_ID = /^[0-9a-z]{3,}(?:…|\.{2,3})[0-9a-z]{3,}$/i;
31094
+ var KEY_SEGMENT_MIN_LENGTH = 16;
31095
+ var LONG_DIGIT_RUN = /^\d{6,}$/;
31096
+ var CURRENCY_MARKED = /[$€£¥₹₿]\d|\d[$€£¥₹₿]/;
31097
+ var NUMERIC_TOKEN = /^[~≈+\-−]?(?:us\$|[$€£¥₹₿])?\d(?:[\d,.]*\d)?(?:k|mm|m|bn|b|t|x|%|[$€£¥₹₿])?$/i;
31098
+ var PLAIN_YEAR = /^(?:1\d{3}|20\d{2})$/;
31099
+ var SUFFIXED_NAME = /^\d*[1-9][kmb]$/i;
31100
+ var BARE_INTEGER = /^\d+$/;
31101
+ var TICKER = /^\$?[A-Z]{2,6}$/;
31102
+ var DETACHED_CURRENCY_SYMBOL = /(^|\s)([$€£¥₹₿])\s+(?=\d)|(\d)\s+([$€£¥₹₿])(?=\s|$)/gu;
31103
+ var LEADING_PUNCTUATION = /^[^\p{L}\p{N}$€£¥₹₿~≈+\-−]+/u;
31104
+ var TRAILING_KEPT_CHARACTER = /[\p{L}\p{N}$€£¥₹₿%]/u;
31105
+ var LEADING_CURRENCY_CODES = /* @__PURE__ */ new Set(["usd", "eur", "gbp", "jpy", "cad", "aud", "chf", "cny"]);
31106
+ var QUANTITY_UNIT_WORDS = /* @__PURE__ */ new Set([
31107
+ "usd",
31108
+ "usdc",
31109
+ "usdt",
31110
+ "eur",
31111
+ "gbp",
31112
+ "sol",
31113
+ "eth",
31114
+ "btc",
31115
+ "dollar",
31116
+ "dollars",
31117
+ "euro",
31118
+ "euros",
31119
+ "buck",
31120
+ "bucks",
31121
+ "k",
31122
+ "thousand",
31123
+ "million",
31124
+ "billion",
31125
+ "trillion",
31126
+ "share",
31127
+ "shares",
31128
+ "token",
31129
+ "tokens",
31130
+ "coin",
31131
+ "coins",
31132
+ "unit",
31133
+ "units",
31134
+ "position",
31135
+ "balance",
31136
+ "stake",
31137
+ "holdings"
31138
+ ]);
31139
+ var AMOUNT_WORDS = /* @__PURE__ */ new Set([...QUANTITY_UNIT_WORDS, "percent", "of"]);
31140
+ var NAME_PII_CATEGORIES = /* @__PURE__ */ new Set(["EMAIL", "PHONE", "SSN", "CREDIT_CARD"]);
31141
+ var NAME_PII_PATTERNS = PII_PATTERNS.filter(
31142
+ (pattern) => NAME_PII_CATEGORIES.has(pattern.category) && pattern.context === void 0
31143
+ );
31144
+ var KEPT_PLACEHOLDER_CATEGORIES = /* @__PURE__ */ new Set(["PERSON", "LOCATION", "ORG"]);
31145
+ var PLACEHOLDER_TOKEN = /\b([A-Za-z]+(?:_[A-Za-z]+)*)_\d+\b/g;
31146
+ function trimPunctuation(token) {
31147
+ const chars = Array.from(token.replace(LEADING_PUNCTUATION, ""));
31148
+ let end = chars.length;
31149
+ while (end > 0 && !TRAILING_KEPT_CHARACTER.test(chars[end - 1])) end--;
31150
+ return chars.slice(0, end).join("");
31151
+ }
31152
+ function hasLetterAndDigit(text12) {
31153
+ return /\p{L}/u.test(text12) && /\p{N}/u.test(text12);
31154
+ }
31155
+ function isIdentifierToken(token) {
31156
+ if (PREFIXED_HEX.test(token) || BARE_HEX.test(token) || BASE58_STRING.test(token)) return true;
31157
+ if (UUID.test(token) || LONG_DIGIT_RUN.test(token)) return true;
31158
+ if (TRUNCATED_ID.test(token) && hasLetterAndDigit(token)) return true;
31159
+ return token.split(/[-_.]/).some((segment) => segment.length >= KEY_SEGMENT_MIN_LENGTH && hasLetterAndDigit(segment));
31160
+ }
31161
+ function containsStructuredPii(name) {
31162
+ return NAME_PII_PATTERNS.some(
31163
+ (pattern) => (name.match(pattern.regex) ?? []).some((match) => pattern.validate?.(match) ?? true)
31164
+ );
31165
+ }
31166
+ function isAmountUnitToken(token) {
31167
+ return NUMERIC_TOKEN.test(token) || TICKER.test(token) || AMOUNT_WORDS.has(token.toLowerCase());
31168
+ }
31169
+ function isAmountWordOrNumber(token) {
31170
+ return NUMERIC_TOKEN.test(token) || AMOUNT_WORDS.has(token.toLowerCase());
31171
+ }
31172
+ function isAmount(tokens) {
31173
+ const start = LEADING_CURRENCY_CODES.has(tokens[0]?.toLowerCase() ?? "") ? 1 : 0;
31174
+ const first = tokens[start];
31175
+ if (first === void 0 || !NUMERIC_TOKEN.test(first)) return false;
31176
+ const units = tokens.slice(start + 1);
31177
+ if (start === 0 && units.length === 0)
31178
+ return !PLAIN_YEAR.test(first) && !SUFFIXED_NAME.test(first);
31179
+ if (!units.every(isAmountUnitToken)) return false;
31180
+ return start === 1 || !BARE_INTEGER.test(first) || units.some(isAmountWordOrNumber);
31181
+ }
31182
+ function hasQuantityPhrase(tokens) {
31183
+ return tokens.some(
31184
+ (token, i) => NUMERIC_TOKEN.test(token) && QUANTITY_UNIT_WORDS.has(tokens[i + 1]?.toLowerCase() ?? "")
31185
+ );
31186
+ }
31187
+ function isIdentifierOrAmountEntityName(name) {
31188
+ const trimmed = name.trim();
31189
+ if (trimmed.length > MAX_ENTITY_NAME_LENGTH) return true;
31190
+ if (containsStructuredPii(trimmed)) return true;
31191
+ const tokens = trimmed.replace(DETACHED_CURRENCY_SYMBOL, "$1$2$3$4").split(/\s+/).map(trimPunctuation).filter((token) => token.length > 0);
31192
+ if (tokens.length === 0) return false;
31193
+ if (tokens.length > MAX_ENTITY_NAME_TOKENS) return true;
31194
+ if (tokens.some(isIdentifierToken)) return true;
31195
+ if (tokens.some((token) => CURRENCY_MARKED.test(token))) return true;
31196
+ return isAmount(tokens) || hasQuantityPhrase(tokens);
31197
+ }
31198
+ function restoreEntityName(name, redactor) {
31199
+ for (const [token, category] of name.matchAll(PLACEHOLDER_TOKEN)) {
31200
+ if (KEPT_PLACEHOLDER_CATEGORIES.has(category.toUpperCase())) continue;
31201
+ if (redactor.restoreForStorage(token).text !== token) return null;
31202
+ }
31203
+ const restored = redactor.restoreForStorage(name);
31204
+ return restored.unresolved || isIdentifierOrAmountEntityName(restored.text) ? null : restored.text;
31205
+ }
31086
31206
 
31087
31207
  // src/lib/memory/injectionClassifier.ts
31088
31208
  init_logger();
@@ -32936,12 +33056,16 @@ async function prepareVaultCandidates(query, vaultCtx, embeddingOptions, cache,
32936
33056
  const currentModel = embeddingOptions.model ?? DEFAULT_API_EMBEDDING_MODEL;
32937
33057
  const uncachedTexts = [];
32938
33058
  const uncachedIndices = [];
33059
+ const resolvedVectors = /* @__PURE__ */ new Map();
32939
33060
  let staleReembedCount = 0;
32940
33061
  for (let i = 0; queryEmbedding.length > 0 && i < memories.length; i++) {
32941
33062
  const content = memories[i].content;
32942
33063
  const memoryId = memories[i].uniqueId;
32943
33064
  const cached = cachedRowVector(cache, memoryId, memories[i].updatedAt, content);
32944
- if (cached && cached.length === queryEmbedding.length) continue;
33065
+ if (cached && cached.length === queryEmbedding.length) {
33066
+ resolvedVectors.set(memoryId, cached);
33067
+ continue;
33068
+ }
32945
33069
  if (cached) cache.delete(memoryId);
32946
33070
  const storedModel = memories[i].embeddingModel;
32947
33071
  const modelCompatible = (storedModel ?? currentModel) === currentModel;
@@ -32949,13 +33073,9 @@ async function prepareVaultCandidates(query, vaultCtx, embeddingOptions, cache,
32949
33073
  try {
32950
33074
  const parsed = JSON.parse(memories[i].embedding);
32951
33075
  if (Array.isArray(parsed) && parsed.length === queryEmbedding.length) {
32952
- cacheRowVector(
32953
- cache,
32954
- memoryId,
32955
- Float32Array.from(parsed),
32956
- memories[i].updatedAt,
32957
- content
32958
- );
33076
+ const vector = Float32Array.from(parsed);
33077
+ resolvedVectors.set(memoryId, vector);
33078
+ cacheRowVector(cache, memoryId, vector, memories[i].updatedAt, content);
32959
33079
  continue;
32960
33080
  }
32961
33081
  } catch {
@@ -32988,20 +33108,17 @@ async function prepareVaultCandidates(query, vaultCtx, embeddingOptions, cache,
32988
33108
  }
32989
33109
  if (newEmbeddings) {
32990
33110
  for (let j = 0; j < uncachedTexts.length; j++) {
32991
- cacheRowVector(
32992
- cache,
32993
- memories[uncachedIndices[j]].uniqueId,
32994
- Float32Array.from(newEmbeddings[j]),
32995
- memories[uncachedIndices[j]].updatedAt,
32996
- memories[uncachedIndices[j]].content
32997
- );
33111
+ const memory = memories[uncachedIndices[j]];
33112
+ const vector = Float32Array.from(newEmbeddings[j]);
33113
+ resolvedVectors.set(memory.uniqueId, vector);
33114
+ cacheRowVector(cache, memory.uniqueId, vector, memory.updatedAt, memory.content);
32998
33115
  }
32999
33116
  }
33000
33117
  }
33001
33118
  embeddedItems = memories.map((m) => ({
33002
33119
  id: m.uniqueId,
33003
33120
  content: m.content,
33004
- embedding: cache.get(m.uniqueId) ?? [],
33121
+ embedding: resolvedVectors.get(m.uniqueId) ?? [],
33005
33122
  createdAt: m.createdAt,
33006
33123
  updatedAt: m.updatedAt,
33007
33124
  proofCount: m.proofCount,
@@ -33895,8 +34012,8 @@ function restoreCandidates(candidates, redactor, ownNames) {
33895
34012
  ...c,
33896
34013
  content: content.text,
33897
34014
  entities: c.entities.flatMap((e) => {
33898
- const restored = redactor.restoreForStorage(e.name);
33899
- return restored.unresolved ? [] : [{ ...e, name: restored.text }];
34015
+ const name = restoreEntityName(e.name, redactor);
34016
+ return name === null ? [] : [{ ...e, name }];
33900
34017
  })
33901
34018
  },
33902
34019
  unresolved: content.unresolved
@@ -34164,18 +34281,21 @@ function validateCandidates(parsed, validIds, userIds, fallbackSourceId, ownName
34164
34281
  }
34165
34282
  return out;
34166
34283
  }
34284
+ function isAcceptedEntityName(name) {
34285
+ return name.length > 0 && !isGenericEntityName(name) && !isIdentifierOrAmountEntityName(name);
34286
+ }
34167
34287
  function parseEntities(raw) {
34168
34288
  const out = [];
34169
34289
  for (const e of raw) {
34170
34290
  if (typeof e === "string") {
34171
34291
  const name2 = e.trim();
34172
- if (name2.length > 0 && !isGenericEntityName(name2)) out.push({ name: name2 });
34292
+ if (isAcceptedEntityName(name2)) out.push({ name: name2 });
34173
34293
  continue;
34174
34294
  }
34175
34295
  if (typeof e !== "object" || e === null) continue;
34176
34296
  const obj = e;
34177
34297
  const name = typeof obj.name === "string" ? obj.name.trim() : "";
34178
- if (name.length === 0 || isGenericEntityName(name)) continue;
34298
+ if (!isAcceptedEntityName(name)) continue;
34179
34299
  const kind = typeof obj.kind === "string" && ENTITY_KINDS.includes(obj.kind) ? obj.kind : void 0;
34180
34300
  const weight = typeof obj.salience === "string" && Object.keys(TOPIC_SALIENCE_WEIGHTS).includes(obj.salience) ? TOPIC_SALIENCE_WEIGHTS[obj.salience] : void 0;
34181
34301
  out.push({
@@ -36365,6 +36485,7 @@ Each memory is a short statement about the user. For each memory, list the NAMED
36365
36485
  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:
36366
36486
  - 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.
36367
36487
  - KEEP the specific thing instead, when the memory names one: "Blue Bottle on Valencia" over "cafe", "Chicago Marathon" over "event", "Hollowpoint Labs" over "work".
36488
+ - 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.
36368
36489
  - Prefer 0 entities over a weak one. A memory whose only candidate is a generic noun has NO entities.
36369
36490
  ${ENTITY_KIND_GUIDELINES}
36370
36491
 
@@ -36470,8 +36591,8 @@ List each memory's named entities.`,
36470
36591
  }
36471
36592
  function restoreEntities(entities, redactor) {
36472
36593
  return entities.flatMap((e) => {
36473
- const restored = redactor.restoreForStorage(e.name);
36474
- return restored.unresolved ? [] : [{ ...e, name: restored.text }];
36594
+ const name = restoreEntityName(e.name, redactor);
36595
+ return name === null ? [] : [{ ...e, name }];
36475
36596
  });
36476
36597
  }
36477
36598
  function parseTopicResponse(parsed, validIds) {
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  INTERNAL_FLOW_MARKER,
3
+ PII_PATTERNS,
3
4
  callPortalJsonCompletion,
4
5
  createStreamingDeAnonymizer,
5
6
  extractCompletionContent,
@@ -13,7 +14,7 @@ import {
13
14
  taskTypeHeader,
14
15
  validateEndpointOverride,
15
16
  withInternalFlowMarker
16
- } from "./chunk-BIMEZT3O.mjs";
17
+ } from "./chunk-JEY3L7WD.mjs";
17
18
  import {
18
19
  BASE_URL,
19
20
  __commonJS,
@@ -29337,6 +29338,125 @@ var WEAK_MODIFIERS = /* @__PURE__ */ new Set([
29337
29338
  "and",
29338
29339
  "or"
29339
29340
  ]);
29341
+ var MAX_ENTITY_NAME_LENGTH = 120;
29342
+ var MAX_ENTITY_NAME_TOKENS = 11;
29343
+ var PREFIXED_HEX = /^0x[0-9a-f]{16,}$/i;
29344
+ var BARE_HEX = /^[0-9a-f]{32,}$/i;
29345
+ var BASE58_STRING = /^[1-9A-HJ-NP-Za-km-z]{32,88}$/;
29346
+ var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
29347
+ var TRUNCATED_ID = /^[0-9a-z]{3,}(?:…|\.{2,3})[0-9a-z]{3,}$/i;
29348
+ var KEY_SEGMENT_MIN_LENGTH = 16;
29349
+ var LONG_DIGIT_RUN = /^\d{6,}$/;
29350
+ var CURRENCY_MARKED = /[$€£¥₹₿]\d|\d[$€£¥₹₿]/;
29351
+ var NUMERIC_TOKEN = /^[~≈+\-−]?(?:us\$|[$€£¥₹₿])?\d(?:[\d,.]*\d)?(?:k|mm|m|bn|b|t|x|%|[$€£¥₹₿])?$/i;
29352
+ var PLAIN_YEAR = /^(?:1\d{3}|20\d{2})$/;
29353
+ var SUFFIXED_NAME = /^\d*[1-9][kmb]$/i;
29354
+ var BARE_INTEGER = /^\d+$/;
29355
+ var TICKER = /^\$?[A-Z]{2,6}$/;
29356
+ var DETACHED_CURRENCY_SYMBOL = /(^|\s)([$€£¥₹₿])\s+(?=\d)|(\d)\s+([$€£¥₹₿])(?=\s|$)/gu;
29357
+ var LEADING_PUNCTUATION = /^[^\p{L}\p{N}$€£¥₹₿~≈+\-−]+/u;
29358
+ var TRAILING_KEPT_CHARACTER = /[\p{L}\p{N}$€£¥₹₿%]/u;
29359
+ var LEADING_CURRENCY_CODES = /* @__PURE__ */ new Set(["usd", "eur", "gbp", "jpy", "cad", "aud", "chf", "cny"]);
29360
+ var QUANTITY_UNIT_WORDS = /* @__PURE__ */ new Set([
29361
+ "usd",
29362
+ "usdc",
29363
+ "usdt",
29364
+ "eur",
29365
+ "gbp",
29366
+ "sol",
29367
+ "eth",
29368
+ "btc",
29369
+ "dollar",
29370
+ "dollars",
29371
+ "euro",
29372
+ "euros",
29373
+ "buck",
29374
+ "bucks",
29375
+ "k",
29376
+ "thousand",
29377
+ "million",
29378
+ "billion",
29379
+ "trillion",
29380
+ "share",
29381
+ "shares",
29382
+ "token",
29383
+ "tokens",
29384
+ "coin",
29385
+ "coins",
29386
+ "unit",
29387
+ "units",
29388
+ "position",
29389
+ "balance",
29390
+ "stake",
29391
+ "holdings"
29392
+ ]);
29393
+ var AMOUNT_WORDS = /* @__PURE__ */ new Set([...QUANTITY_UNIT_WORDS, "percent", "of"]);
29394
+ var NAME_PII_CATEGORIES = /* @__PURE__ */ new Set(["EMAIL", "PHONE", "SSN", "CREDIT_CARD"]);
29395
+ var NAME_PII_PATTERNS = PII_PATTERNS.filter(
29396
+ (pattern) => NAME_PII_CATEGORIES.has(pattern.category) && pattern.context === void 0
29397
+ );
29398
+ var KEPT_PLACEHOLDER_CATEGORIES = /* @__PURE__ */ new Set(["PERSON", "LOCATION", "ORG"]);
29399
+ var PLACEHOLDER_TOKEN = /\b([A-Za-z]+(?:_[A-Za-z]+)*)_\d+\b/g;
29400
+ function trimPunctuation(token) {
29401
+ const chars = Array.from(token.replace(LEADING_PUNCTUATION, ""));
29402
+ let end = chars.length;
29403
+ while (end > 0 && !TRAILING_KEPT_CHARACTER.test(chars[end - 1])) end--;
29404
+ return chars.slice(0, end).join("");
29405
+ }
29406
+ function hasLetterAndDigit(text12) {
29407
+ return /\p{L}/u.test(text12) && /\p{N}/u.test(text12);
29408
+ }
29409
+ function isIdentifierToken(token) {
29410
+ if (PREFIXED_HEX.test(token) || BARE_HEX.test(token) || BASE58_STRING.test(token)) return true;
29411
+ if (UUID.test(token) || LONG_DIGIT_RUN.test(token)) return true;
29412
+ if (TRUNCATED_ID.test(token) && hasLetterAndDigit(token)) return true;
29413
+ return token.split(/[-_.]/).some((segment) => segment.length >= KEY_SEGMENT_MIN_LENGTH && hasLetterAndDigit(segment));
29414
+ }
29415
+ function containsStructuredPii(name) {
29416
+ return NAME_PII_PATTERNS.some(
29417
+ (pattern) => (name.match(pattern.regex) ?? []).some((match) => pattern.validate?.(match) ?? true)
29418
+ );
29419
+ }
29420
+ function isAmountUnitToken(token) {
29421
+ return NUMERIC_TOKEN.test(token) || TICKER.test(token) || AMOUNT_WORDS.has(token.toLowerCase());
29422
+ }
29423
+ function isAmountWordOrNumber(token) {
29424
+ return NUMERIC_TOKEN.test(token) || AMOUNT_WORDS.has(token.toLowerCase());
29425
+ }
29426
+ function isAmount(tokens) {
29427
+ const start = LEADING_CURRENCY_CODES.has(tokens[0]?.toLowerCase() ?? "") ? 1 : 0;
29428
+ const first = tokens[start];
29429
+ if (first === void 0 || !NUMERIC_TOKEN.test(first)) return false;
29430
+ const units = tokens.slice(start + 1);
29431
+ if (start === 0 && units.length === 0)
29432
+ return !PLAIN_YEAR.test(first) && !SUFFIXED_NAME.test(first);
29433
+ if (!units.every(isAmountUnitToken)) return false;
29434
+ return start === 1 || !BARE_INTEGER.test(first) || units.some(isAmountWordOrNumber);
29435
+ }
29436
+ function hasQuantityPhrase(tokens) {
29437
+ return tokens.some(
29438
+ (token, i) => NUMERIC_TOKEN.test(token) && QUANTITY_UNIT_WORDS.has(tokens[i + 1]?.toLowerCase() ?? "")
29439
+ );
29440
+ }
29441
+ function isIdentifierOrAmountEntityName(name) {
29442
+ const trimmed = name.trim();
29443
+ if (trimmed.length > MAX_ENTITY_NAME_LENGTH) return true;
29444
+ if (containsStructuredPii(trimmed)) return true;
29445
+ const tokens = trimmed.replace(DETACHED_CURRENCY_SYMBOL, "$1$2$3$4").split(/\s+/).map(trimPunctuation).filter((token) => token.length > 0);
29446
+ if (tokens.length === 0) return false;
29447
+ if (tokens.length > MAX_ENTITY_NAME_TOKENS) return true;
29448
+ if (tokens.some(isIdentifierToken)) return true;
29449
+ if (tokens.some((token) => CURRENCY_MARKED.test(token))) return true;
29450
+ return isAmount(tokens) || hasQuantityPhrase(tokens);
29451
+ }
29452
+ function restoreEntityName(name, redactor) {
29453
+ for (const [token, category] of name.matchAll(PLACEHOLDER_TOKEN)) {
29454
+ if (KEPT_PLACEHOLDER_CATEGORIES.has(category.toUpperCase())) continue;
29455
+ if (redactor.restoreForStorage(token).text !== token) return null;
29456
+ }
29457
+ const restored = redactor.restoreForStorage(name);
29458
+ return restored.unresolved || isIdentifierOrAmountEntityName(restored.text) ? null : restored.text;
29459
+ }
29340
29460
 
29341
29461
  // src/lib/memory/injectionClassifier.ts
29342
29462
  var DEFAULT_MODEL = "inclusionai/ling-2.6-flash";
@@ -31174,12 +31294,16 @@ async function prepareVaultCandidates(query, vaultCtx, embeddingOptions, cache,
31174
31294
  const currentModel = embeddingOptions.model ?? DEFAULT_API_EMBEDDING_MODEL;
31175
31295
  const uncachedTexts = [];
31176
31296
  const uncachedIndices = [];
31297
+ const resolvedVectors = /* @__PURE__ */ new Map();
31177
31298
  let staleReembedCount = 0;
31178
31299
  for (let i = 0; queryEmbedding.length > 0 && i < memories.length; i++) {
31179
31300
  const content = memories[i].content;
31180
31301
  const memoryId = memories[i].uniqueId;
31181
31302
  const cached = cachedRowVector(cache, memoryId, memories[i].updatedAt, content);
31182
- if (cached && cached.length === queryEmbedding.length) continue;
31303
+ if (cached && cached.length === queryEmbedding.length) {
31304
+ resolvedVectors.set(memoryId, cached);
31305
+ continue;
31306
+ }
31183
31307
  if (cached) cache.delete(memoryId);
31184
31308
  const storedModel = memories[i].embeddingModel;
31185
31309
  const modelCompatible = (storedModel ?? currentModel) === currentModel;
@@ -31187,13 +31311,9 @@ async function prepareVaultCandidates(query, vaultCtx, embeddingOptions, cache,
31187
31311
  try {
31188
31312
  const parsed = JSON.parse(memories[i].embedding);
31189
31313
  if (Array.isArray(parsed) && parsed.length === queryEmbedding.length) {
31190
- cacheRowVector(
31191
- cache,
31192
- memoryId,
31193
- Float32Array.from(parsed),
31194
- memories[i].updatedAt,
31195
- content
31196
- );
31314
+ const vector = Float32Array.from(parsed);
31315
+ resolvedVectors.set(memoryId, vector);
31316
+ cacheRowVector(cache, memoryId, vector, memories[i].updatedAt, content);
31197
31317
  continue;
31198
31318
  }
31199
31319
  } catch {
@@ -31226,20 +31346,17 @@ async function prepareVaultCandidates(query, vaultCtx, embeddingOptions, cache,
31226
31346
  }
31227
31347
  if (newEmbeddings) {
31228
31348
  for (let j = 0; j < uncachedTexts.length; j++) {
31229
- cacheRowVector(
31230
- cache,
31231
- memories[uncachedIndices[j]].uniqueId,
31232
- Float32Array.from(newEmbeddings[j]),
31233
- memories[uncachedIndices[j]].updatedAt,
31234
- memories[uncachedIndices[j]].content
31235
- );
31349
+ const memory = memories[uncachedIndices[j]];
31350
+ const vector = Float32Array.from(newEmbeddings[j]);
31351
+ resolvedVectors.set(memory.uniqueId, vector);
31352
+ cacheRowVector(cache, memory.uniqueId, vector, memory.updatedAt, memory.content);
31236
31353
  }
31237
31354
  }
31238
31355
  }
31239
31356
  embeddedItems = memories.map((m) => ({
31240
31357
  id: m.uniqueId,
31241
31358
  content: m.content,
31242
- embedding: cache.get(m.uniqueId) ?? [],
31359
+ embedding: resolvedVectors.get(m.uniqueId) ?? [],
31243
31360
  createdAt: m.createdAt,
31244
31361
  updatedAt: m.updatedAt,
31245
31362
  proofCount: m.proofCount,
@@ -31839,7 +31956,7 @@ async function tryConsolidate(trimmed, ctx, options, prepared) {
31839
31956
  content: m.content,
31840
31957
  similarity: m.similarity
31841
31958
  }));
31842
- const { consolidateMemory: doConsolidate } = await import("./consolidate-JZJYY3SZ.mjs");
31959
+ const { consolidateMemory: doConsolidate } = await import("./consolidate-5DFDLGSS.mjs");
31843
31960
  const decision = await doConsolidate(trimmed, candidates, consolidateOptions);
31844
31961
  if (decision.action === "create") return decision.fallbackReason ? null : { create: true };
31845
31962
  if (decision.action === "supersede" && decision.content) {
@@ -32132,8 +32249,8 @@ function restoreCandidates(candidates, redactor, ownNames) {
32132
32249
  ...c,
32133
32250
  content: content.text,
32134
32251
  entities: c.entities.flatMap((e) => {
32135
- const restored = redactor.restoreForStorage(e.name);
32136
- return restored.unresolved ? [] : [{ ...e, name: restored.text }];
32252
+ const name = restoreEntityName(e.name, redactor);
32253
+ return name === null ? [] : [{ ...e, name }];
32137
32254
  })
32138
32255
  },
32139
32256
  unresolved: content.unresolved
@@ -32401,18 +32518,21 @@ function validateCandidates(parsed, validIds, userIds, fallbackSourceId, ownName
32401
32518
  }
32402
32519
  return out;
32403
32520
  }
32521
+ function isAcceptedEntityName(name) {
32522
+ return name.length > 0 && !isGenericEntityName(name) && !isIdentifierOrAmountEntityName(name);
32523
+ }
32404
32524
  function parseEntities(raw) {
32405
32525
  const out = [];
32406
32526
  for (const e of raw) {
32407
32527
  if (typeof e === "string") {
32408
32528
  const name2 = e.trim();
32409
- if (name2.length > 0 && !isGenericEntityName(name2)) out.push({ name: name2 });
32529
+ if (isAcceptedEntityName(name2)) out.push({ name: name2 });
32410
32530
  continue;
32411
32531
  }
32412
32532
  if (typeof e !== "object" || e === null) continue;
32413
32533
  const obj = e;
32414
32534
  const name = typeof obj.name === "string" ? obj.name.trim() : "";
32415
- if (name.length === 0 || isGenericEntityName(name)) continue;
32535
+ if (!isAcceptedEntityName(name)) continue;
32416
32536
  const kind = typeof obj.kind === "string" && ENTITY_KINDS.includes(obj.kind) ? obj.kind : void 0;
32417
32537
  const weight = typeof obj.salience === "string" && Object.keys(TOPIC_SALIENCE_WEIGHTS).includes(obj.salience) ? TOPIC_SALIENCE_WEIGHTS[obj.salience] : void 0;
32418
32538
  out.push({
@@ -34581,6 +34701,7 @@ Each memory is a short statement about the user. For each memory, list the NAMED
34581
34701
  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:
34582
34702
  - 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.
34583
34703
  - KEEP the specific thing instead, when the memory names one: "Blue Bottle on Valencia" over "cafe", "Chicago Marathon" over "event", "Hollowpoint Labs" over "work".
34704
+ - 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.
34584
34705
  - Prefer 0 entities over a weak one. A memory whose only candidate is a generic noun has NO entities.
34585
34706
  ${ENTITY_KIND_GUIDELINES}
34586
34707
 
@@ -34686,8 +34807,8 @@ List each memory's named entities.`,
34686
34807
  }
34687
34808
  function restoreEntities(entities, redactor) {
34688
34809
  return entities.flatMap((e) => {
34689
- const restored = redactor.restoreForStorage(e.name);
34690
- return restored.unresolved ? [] : [{ ...e, name: restored.text }];
34810
+ const name = restoreEntityName(e.name, redactor);
34811
+ return name === null ? [] : [{ ...e, name }];
34691
34812
  });
34692
34813
  }
34693
34814
  function parseTopicResponse(parsed, validIds) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anuma/sdk",
3
- "version": "10.5.0",
3
+ "version": "10.5.2",
4
4
  "description": "",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",