@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.
@@ -2912,6 +2912,9 @@ async function withEmbeddingRetry(call) {
2912
2912
  }
2913
2913
  }
2914
2914
  if (threw) throw lastThrown;
2915
+ if (last?.error instanceof Error && last.response?.status === void 0) {
2916
+ throw last.error;
2917
+ }
2915
2918
  return last;
2916
2919
  }
2917
2920
  var EmbeddingHttpError = class extends Error {
@@ -4291,6 +4294,7 @@ async function searchVaultMemoriesWithSize(query, vaultCtx, embeddingOptions, ca
4291
4294
  createdAt: m.createdAt,
4292
4295
  updatedAt: m.updatedAt,
4293
4296
  proofCount: m.proofCount,
4297
+ lastObservedAt: m.lastObservedAt,
4294
4298
  eventTimeStart: m.eventTimeStart,
4295
4299
  sourceChunkIds: m.sourceChunkIds,
4296
4300
  eventTimeEnd: m.eventTimeEnd,
@@ -4307,13 +4311,27 @@ async function searchVaultMemoriesWithSize(query, vaultCtx, embeddingOptions, ca
4307
4311
  );
4308
4312
  }
4309
4313
  }
4310
- const timestampById = new Map(
4311
- memories.map((m) => [m.uniqueId, { createdAt: m.createdAt, updatedAt: m.updatedAt }])
4314
+ const metaById = new Map(
4315
+ memories.map((m) => [
4316
+ m.uniqueId,
4317
+ {
4318
+ createdAt: m.createdAt,
4319
+ updatedAt: m.updatedAt,
4320
+ proofCount: m.proofCount,
4321
+ lastObservedAt: m.lastObservedAt
4322
+ }
4323
+ ])
4312
4324
  );
4313
4325
  const stampTimestamps = (out) => {
4314
4326
  const results2 = out.results.map((r) => {
4315
- const ts = timestampById.get(r.uniqueId);
4316
- return ts ? { ...r, createdAt: ts.createdAt, updatedAt: ts.updatedAt } : r;
4327
+ const meta = metaById.get(r.uniqueId);
4328
+ return meta ? {
4329
+ ...r,
4330
+ createdAt: meta.createdAt,
4331
+ updatedAt: meta.updatedAt,
4332
+ proofCount: meta.proofCount,
4333
+ lastObservedAt: meta.lastObservedAt
4334
+ } : r;
4317
4335
  });
4318
4336
  return {
4319
4337
  results: results2,
@@ -4507,7 +4525,7 @@ function createMemoryVaultSearchTool(vaultCtx, embeddingOptions, cache, searchOp
4507
4525
  legacy.map((r) => ({ id: r.uniqueId, content: r.content, score: r.similarity }))
4508
4526
  );
4509
4527
  }
4510
- const { recall: recall2 } = await import("./recall-7FUJRHOI.mjs");
4528
+ const { recall: recall2 } = await import("./recall-7ZX6T2VD.mjs");
4511
4529
  const result = await recall2(
4512
4530
  query,
4513
4531
  { vaultCtx, embeddingOptions, vaultCache: cache },
@@ -4771,6 +4789,42 @@ Which should be expanded?`,
4771
4789
  };
4772
4790
  }
4773
4791
 
4792
+ // src/lib/memory/observationTrend.ts
4793
+ var DAY_MS2 = 1e3 * 60 * 60 * 24;
4794
+ var TREND_RECENT_WINDOW_DAYS = 30;
4795
+ var TREND_STALE_WINDOW_DAYS = 90;
4796
+ function toMs(value) {
4797
+ return value instanceof Date ? value.getTime() : value;
4798
+ }
4799
+ function classifyObservationTrend(input, now = Date.now()) {
4800
+ const createdMs = toMs(input.createdAt);
4801
+ if (!Number.isFinite(createdMs) || !Number.isFinite(now)) return "stable";
4802
+ const lastMsRaw = input.lastObservedAt;
4803
+ const lastMs = lastMsRaw !== null && lastMsRaw !== void 0 && Number.isFinite(lastMsRaw) ? Math.max(createdMs, lastMsRaw) : createdMs;
4804
+ const proofs = Math.max(1, input.proofCount ?? 1);
4805
+ const ageDays = Math.max(0, (now - createdMs) / DAY_MS2);
4806
+ const daysSinceLast = Math.max(0, (now - lastMs) / DAY_MS2);
4807
+ if (daysSinceLast >= TREND_STALE_WINDOW_DAYS) return "stale";
4808
+ if (daysSinceLast >= TREND_RECENT_WINDOW_DAYS) return "weakening";
4809
+ if (ageDays <= TREND_RECENT_WINDOW_DAYS && proofs <= 2) return "new";
4810
+ if (proofs >= 3) return "strengthening";
4811
+ if (proofs >= 2 && ageDays > TREND_RECENT_WINDOW_DAYS) return "strengthening";
4812
+ return "stable";
4813
+ }
4814
+ function summarizeObservationTrends(inputs, now = Date.now()) {
4815
+ const counts = {
4816
+ new: 0,
4817
+ strengthening: 0,
4818
+ stable: 0,
4819
+ weakening: 0,
4820
+ stale: 0
4821
+ };
4822
+ for (const input of inputs) {
4823
+ counts[classifyObservationTrend(input, now)]++;
4824
+ }
4825
+ return counts;
4826
+ }
4827
+
4774
4828
  // src/lib/memory/queryTemporal.ts
4775
4829
  var RELATIVE_DAY_ENTRIES = [
4776
4830
  [/\btoday\b/, "today", 0],
@@ -5165,7 +5219,7 @@ async function recall(query, ctx, options = {}) {
5165
5219
  const fuseStart = nowMs();
5166
5220
  if (types.length === 1 || factResults.length === 0 || chunkResults.length === 0) {
5167
5221
  const memories2 = [
5168
- ...factResults.map(toFactMemory),
5222
+ ...factResults.map((r) => toFactMemory(r, options.now)),
5169
5223
  ...chunkResults.map(toChunkMemory)
5170
5224
  ];
5171
5225
  memories2.sort((a, b) => b.score - a.score);
@@ -5186,7 +5240,7 @@ async function recall(query, ctx, options = {}) {
5186
5240
  const fused = rrfFuse([factRanking, chunkRanking], options.rrfK);
5187
5241
  const byId = /* @__PURE__ */ new Map();
5188
5242
  for (const r of factResults) {
5189
- const m = toFactMemory(r);
5243
+ const m = toFactMemory(r, options.now);
5190
5244
  m.score = fused.get(`fact:${r.uniqueId}`) ?? 0;
5191
5245
  if (!m.scoreBreakdown) m.scoreBreakdown = {};
5192
5246
  m.scoreBreakdown.fused = r.similarity;
@@ -5235,7 +5289,10 @@ async function recall(query, ctx, options = {}) {
5235
5289
  ...vaultSize !== void 0 && { vaultSize }
5236
5290
  };
5237
5291
  }
5238
- function toFactMemory(r) {
5292
+ function toFactMemory(r, now) {
5293
+ const createdAt = r.createdAt ?? /* @__PURE__ */ new Date(0);
5294
+ const proofCount = r.proofCount ?? void 0;
5295
+ const lastObservedAt = r.lastObservedAt ?? null;
5239
5296
  return {
5240
5297
  id: r.uniqueId,
5241
5298
  kind: "fact",
@@ -5251,6 +5308,18 @@ function toFactMemory(r) {
5251
5308
  // (and UI reading them) carry the fact's type. Undefined when untyped.
5252
5309
  ...r.factType !== void 0 && { factType: r.factType },
5253
5310
  ...r.sourceChunkIds !== void 0 && r.sourceChunkIds !== null && { sourceChunkIds: r.sourceChunkIds },
5311
+ ...proofCount !== void 0 && proofCount !== null && { proofCount },
5312
+ ...lastObservedAt !== null && { lastObservedAt },
5313
+ // C2 — algorithmic trend from evidence timestamps (no LLM). Honor
5314
+ // RecallOptions.now so back-dated eval harnesses get consistent labels.
5315
+ observationTrend: classifyObservationTrend(
5316
+ {
5317
+ createdAt,
5318
+ lastObservedAt,
5319
+ proofCount
5320
+ },
5321
+ now ?? Date.now()
5322
+ ),
5254
5323
  // r.similarity from searchVaultMemoriesWithSize is the fused score
5255
5324
  // (cosine + BM25 + RRF + recency + proof) when useFusion=true (the
5256
5325
  // default) and pure cosine when useFusion=false. The breakdown
@@ -5259,7 +5328,7 @@ function toFactMemory(r) {
5259
5328
  content: r.content,
5260
5329
  score: r.similarity,
5261
5330
  scoreBreakdown: { fused: r.similarity },
5262
- createdAt: r.createdAt ?? /* @__PURE__ */ new Date(0),
5331
+ createdAt,
5263
5332
  updatedAt: r.updatedAt ?? /* @__PURE__ */ new Date(0)
5264
5333
  };
5265
5334
  }
@@ -5427,6 +5496,10 @@ export {
5427
5496
  capHopsForDensity,
5428
5497
  traverseGraphLane,
5429
5498
  createLlmNeighborRefiner,
5499
+ TREND_RECENT_WINDOW_DAYS,
5500
+ TREND_STALE_WINDOW_DAYS,
5501
+ classifyObservationTrend,
5502
+ summarizeObservationTrends,
5430
5503
  recall,
5431
5504
  preEmbedVaultMemories,
5432
5505
  eagerEmbedContent,