@anuma/sdk 3.3.0 → 3.4.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.
@@ -3119,6 +3119,9 @@ async function withEmbeddingRetry(call) {
3119
3119
  }
3120
3120
  }
3121
3121
  if (threw) throw lastThrown;
3122
+ if (last?.error instanceof Error && last.response?.status === void 0) {
3123
+ throw last.error;
3124
+ }
3122
3125
  return last;
3123
3126
  }
3124
3127
  var EmbeddingHttpError = class extends Error {
@@ -4498,6 +4501,7 @@ async function searchVaultMemoriesWithSize(query, vaultCtx, embeddingOptions, ca
4498
4501
  createdAt: m.createdAt,
4499
4502
  updatedAt: m.updatedAt,
4500
4503
  proofCount: m.proofCount,
4504
+ lastObservedAt: m.lastObservedAt,
4501
4505
  eventTimeStart: m.eventTimeStart,
4502
4506
  sourceChunkIds: m.sourceChunkIds,
4503
4507
  eventTimeEnd: m.eventTimeEnd,
@@ -4514,13 +4518,27 @@ async function searchVaultMemoriesWithSize(query, vaultCtx, embeddingOptions, ca
4514
4518
  );
4515
4519
  }
4516
4520
  }
4517
- const timestampById = new Map(
4518
- memories.map((m) => [m.uniqueId, { createdAt: m.createdAt, updatedAt: m.updatedAt }])
4521
+ const metaById = new Map(
4522
+ memories.map((m) => [
4523
+ m.uniqueId,
4524
+ {
4525
+ createdAt: m.createdAt,
4526
+ updatedAt: m.updatedAt,
4527
+ proofCount: m.proofCount,
4528
+ lastObservedAt: m.lastObservedAt
4529
+ }
4530
+ ])
4519
4531
  );
4520
4532
  const stampTimestamps = (out) => {
4521
4533
  const results2 = out.results.map((r) => {
4522
- const ts = timestampById.get(r.uniqueId);
4523
- return ts ? { ...r, createdAt: ts.createdAt, updatedAt: ts.updatedAt } : r;
4534
+ const meta = metaById.get(r.uniqueId);
4535
+ return meta ? {
4536
+ ...r,
4537
+ createdAt: meta.createdAt,
4538
+ updatedAt: meta.updatedAt,
4539
+ proofCount: meta.proofCount,
4540
+ lastObservedAt: meta.lastObservedAt
4541
+ } : r;
4524
4542
  });
4525
4543
  return {
4526
4544
  results: results2,
@@ -4714,7 +4732,7 @@ function createMemoryVaultSearchTool(vaultCtx, embeddingOptions, cache, searchOp
4714
4732
  legacy.map((r) => ({ id: r.uniqueId, content: r.content, score: r.similarity }))
4715
4733
  );
4716
4734
  }
4717
- const { recall: recall2 } = await import("./recall-YZGWZC5W.mjs");
4735
+ const { recall: recall2 } = await import("./recall-OTUNGQHQ.mjs");
4718
4736
  const result = await recall2(
4719
4737
  query,
4720
4738
  { vaultCtx, embeddingOptions, vaultCache: cache },
@@ -4978,6 +4996,42 @@ Which should be expanded?`,
4978
4996
  };
4979
4997
  }
4980
4998
 
4999
+ // src/lib/memory/observationTrend.ts
5000
+ var DAY_MS2 = 1e3 * 60 * 60 * 24;
5001
+ var TREND_RECENT_WINDOW_DAYS = 30;
5002
+ var TREND_STALE_WINDOW_DAYS = 90;
5003
+ function toMs(value) {
5004
+ return value instanceof Date ? value.getTime() : value;
5005
+ }
5006
+ function classifyObservationTrend(input, now = Date.now()) {
5007
+ const createdMs = toMs(input.createdAt);
5008
+ if (!Number.isFinite(createdMs) || !Number.isFinite(now)) return "stable";
5009
+ const lastMsRaw = input.lastObservedAt;
5010
+ const lastMs = lastMsRaw !== null && lastMsRaw !== void 0 && Number.isFinite(lastMsRaw) ? Math.max(createdMs, lastMsRaw) : createdMs;
5011
+ const proofs = Math.max(1, input.proofCount ?? 1);
5012
+ const ageDays = Math.max(0, (now - createdMs) / DAY_MS2);
5013
+ const daysSinceLast = Math.max(0, (now - lastMs) / DAY_MS2);
5014
+ if (daysSinceLast >= TREND_STALE_WINDOW_DAYS) return "stale";
5015
+ if (daysSinceLast >= TREND_RECENT_WINDOW_DAYS) return "weakening";
5016
+ if (ageDays <= TREND_RECENT_WINDOW_DAYS && proofs <= 2) return "new";
5017
+ if (proofs >= 3) return "strengthening";
5018
+ if (proofs >= 2 && ageDays > TREND_RECENT_WINDOW_DAYS) return "strengthening";
5019
+ return "stable";
5020
+ }
5021
+ function summarizeObservationTrends(inputs, now = Date.now()) {
5022
+ const counts = {
5023
+ new: 0,
5024
+ strengthening: 0,
5025
+ stable: 0,
5026
+ weakening: 0,
5027
+ stale: 0
5028
+ };
5029
+ for (const input of inputs) {
5030
+ counts[classifyObservationTrend(input, now)]++;
5031
+ }
5032
+ return counts;
5033
+ }
5034
+
4981
5035
  // src/lib/memory/queryTemporal.ts
4982
5036
  var RELATIVE_DAY_ENTRIES = [
4983
5037
  [/\btoday\b/, "today", 0],
@@ -5372,7 +5426,7 @@ async function recall(query, ctx, options = {}) {
5372
5426
  const fuseStart = nowMs();
5373
5427
  if (types.length === 1 || factResults.length === 0 || chunkResults.length === 0) {
5374
5428
  const memories2 = [
5375
- ...factResults.map(toFactMemory),
5429
+ ...factResults.map((r) => toFactMemory(r, options.now)),
5376
5430
  ...chunkResults.map(toChunkMemory)
5377
5431
  ];
5378
5432
  memories2.sort((a, b) => b.score - a.score);
@@ -5393,7 +5447,7 @@ async function recall(query, ctx, options = {}) {
5393
5447
  const fused = rrfFuse([factRanking, chunkRanking], options.rrfK);
5394
5448
  const byId = /* @__PURE__ */ new Map();
5395
5449
  for (const r of factResults) {
5396
- const m = toFactMemory(r);
5450
+ const m = toFactMemory(r, options.now);
5397
5451
  m.score = fused.get(`fact:${r.uniqueId}`) ?? 0;
5398
5452
  if (!m.scoreBreakdown) m.scoreBreakdown = {};
5399
5453
  m.scoreBreakdown.fused = r.similarity;
@@ -5442,7 +5496,10 @@ async function recall(query, ctx, options = {}) {
5442
5496
  ...vaultSize !== void 0 && { vaultSize }
5443
5497
  };
5444
5498
  }
5445
- function toFactMemory(r) {
5499
+ function toFactMemory(r, now) {
5500
+ const createdAt = r.createdAt ?? /* @__PURE__ */ new Date(0);
5501
+ const proofCount = r.proofCount ?? void 0;
5502
+ const lastObservedAt = r.lastObservedAt ?? null;
5446
5503
  return {
5447
5504
  id: r.uniqueId,
5448
5505
  kind: "fact",
@@ -5458,6 +5515,18 @@ function toFactMemory(r) {
5458
5515
  // (and UI reading them) carry the fact's type. Undefined when untyped.
5459
5516
  ...r.factType !== void 0 && { factType: r.factType },
5460
5517
  ...r.sourceChunkIds !== void 0 && r.sourceChunkIds !== null && { sourceChunkIds: r.sourceChunkIds },
5518
+ ...proofCount !== void 0 && proofCount !== null && { proofCount },
5519
+ ...lastObservedAt !== null && { lastObservedAt },
5520
+ // C2 — algorithmic trend from evidence timestamps (no LLM). Honor
5521
+ // RecallOptions.now so back-dated eval harnesses get consistent labels.
5522
+ observationTrend: classifyObservationTrend(
5523
+ {
5524
+ createdAt,
5525
+ lastObservedAt,
5526
+ proofCount
5527
+ },
5528
+ now ?? Date.now()
5529
+ ),
5461
5530
  // r.similarity from searchVaultMemoriesWithSize is the fused score
5462
5531
  // (cosine + BM25 + RRF + recency + proof) when useFusion=true (the
5463
5532
  // default) and pure cosine when useFusion=false. The breakdown
@@ -5466,7 +5535,7 @@ function toFactMemory(r) {
5466
5535
  content: r.content,
5467
5536
  score: r.similarity,
5468
5537
  scoreBreakdown: { fused: r.similarity },
5469
- createdAt: r.createdAt ?? /* @__PURE__ */ new Date(0),
5538
+ createdAt,
5470
5539
  updatedAt: r.updatedAt ?? /* @__PURE__ */ new Date(0)
5471
5540
  };
5472
5541
  }
@@ -5660,6 +5729,10 @@ export {
5660
5729
  capHopsForDensity,
5661
5730
  traverseGraphLane,
5662
5731
  createLlmNeighborRefiner,
5732
+ TREND_RECENT_WINDOW_DAYS,
5733
+ TREND_STALE_WINDOW_DAYS,
5734
+ classifyObservationTrend,
5735
+ summarizeObservationTrends,
5663
5736
  recall,
5664
5737
  preEmbedVaultMemories,
5665
5738
  eagerEmbedContent,