@anuma/sdk 1.1.3 → 1.1.5

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.
@@ -18224,6 +18224,13 @@ async function withEmbeddingRetry(call) {
18224
18224
  if (threw) throw lastThrown;
18225
18225
  return last;
18226
18226
  }
18227
+ function isFatalEmbeddingError(err) {
18228
+ return err instanceof EmbeddingHttpError && (err.status === 401 || err.status === 402 || err.status === 403);
18229
+ }
18230
+ function embeddingErrorFrom(response) {
18231
+ const message = typeof response.error === "object" && response.error && "error" in response.error ? response.error.error : "API embedding failed";
18232
+ return new EmbeddingHttpError(message, response.response?.status);
18233
+ }
18227
18234
  async function generateEmbedding(text11, options) {
18228
18235
  const { baseUrl = BASE_URL, getToken, apiKey, model, cache } = options;
18229
18236
  if (cache) {
@@ -18255,9 +18262,7 @@ async function generateEmbedding(text11, options) {
18255
18262
  })
18256
18263
  );
18257
18264
  if (response.error) {
18258
- throw new Error(
18259
- typeof response.error === "object" && response.error && "error" in response.error ? response.error.error : "API embedding failed"
18260
- );
18265
+ throw embeddingErrorFrom(response);
18261
18266
  }
18262
18267
  if (!response.data?.data?.[0]?.embedding) {
18263
18268
  throw new Error("No embedding returned from API");
@@ -18284,9 +18289,7 @@ async function generateEmbeddingsBatch(texts, headers, baseUrl, model, onUsage,
18284
18289
  })
18285
18290
  );
18286
18291
  if (response.error) {
18287
- throw new Error(
18288
- typeof response.error === "object" && response.error && "error" in response.error ? response.error.error : "API embedding failed"
18289
- );
18292
+ throw embeddingErrorFrom(response);
18290
18293
  }
18291
18294
  if (!response.data?.data) {
18292
18295
  throw new Error("No embeddings returned from API");
@@ -18422,6 +18425,7 @@ async function embedAllMessages(ctx, options, filter) {
18422
18425
  await updateMessageEmbeddingOp(ctx, message.uniqueId, embedding, embeddingModel);
18423
18426
  embeddedCount++;
18424
18427
  } catch (error) {
18428
+ if (isFatalEmbeddingError(error)) throw error;
18425
18429
  getLogger().error(`Failed to embed message ${message.uniqueId}:`, error);
18426
18430
  }
18427
18431
  }
@@ -18509,6 +18513,7 @@ async function chunkAndEmbedAllMessages(ctx, options, filter) {
18509
18513
  }
18510
18514
  }
18511
18515
  } catch (error) {
18516
+ if (isFatalEmbeddingError(error)) throw error;
18512
18517
  getLogger().error("Failed to batch-embed short messages:", error);
18513
18518
  }
18514
18519
  }
@@ -18525,12 +18530,13 @@ async function chunkAndEmbedAllMessages(ctx, options, filter) {
18525
18530
  await updateMessageChunksOp(ctx, msg.uniqueId, messageChunks, embeddingModel);
18526
18531
  embeddedCount++;
18527
18532
  } catch (error) {
18533
+ if (isFatalEmbeddingError(error)) throw error;
18528
18534
  getLogger().error(`Failed to embed message ${msg.uniqueId}:`, error);
18529
18535
  }
18530
18536
  }
18531
18537
  return embeddedCount;
18532
18538
  }
18533
- var DEFAULT_MIN_CONTENT_LENGTH, EMBED_MAX_ATTEMPTS, DEFAULT_EMBEDDING_BATCH_SIZE, DEFAULT_EMBEDDING_BATCH_CONCURRENCY;
18539
+ var DEFAULT_MIN_CONTENT_LENGTH, EMBED_MAX_ATTEMPTS, EmbeddingHttpError, DEFAULT_EMBEDDING_BATCH_SIZE, DEFAULT_EMBEDDING_BATCH_CONCURRENCY;
18534
18540
  var init_embeddings = __esm({
18535
18541
  "src/lib/memoryEngine/embeddings.ts"() {
18536
18542
  "use strict";
@@ -18542,6 +18548,13 @@ var init_embeddings = __esm({
18542
18548
  init_constants();
18543
18549
  DEFAULT_MIN_CONTENT_LENGTH = 10;
18544
18550
  EMBED_MAX_ATTEMPTS = 4;
18551
+ EmbeddingHttpError = class extends Error {
18552
+ constructor(message, status) {
18553
+ super(message);
18554
+ this.name = "EmbeddingHttpError";
18555
+ this.status = status;
18556
+ }
18557
+ };
18545
18558
  DEFAULT_EMBEDDING_BATCH_SIZE = 100;
18546
18559
  DEFAULT_EMBEDDING_BATCH_CONCURRENCY = 3;
18547
18560
  }
@@ -19682,7 +19695,31 @@ async function recall(query, ctx, options = {}) {
19682
19695
  m.scoreBreakdown.fused = r.similarity;
19683
19696
  byId.set(key, m);
19684
19697
  }
19685
- const memories = [...byId.values()].sort((a, b) => b.score - a.score).slice(0, limit);
19698
+ const ordered = [...byId.values()].sort((a, b) => b.score - a.score);
19699
+ const selectWith = (suppressed2) => {
19700
+ const out = [];
19701
+ for (const m of ordered) {
19702
+ if (out.length >= limit) break;
19703
+ if (m.kind === "chunk" && m.messageId && suppressed2.has(m.messageId)) continue;
19704
+ out.push(m);
19705
+ }
19706
+ return out;
19707
+ };
19708
+ const provenanceOf = (selected) => {
19709
+ const s = /* @__PURE__ */ new Set();
19710
+ for (const m of selected) {
19711
+ if (m.kind === "fact" && m.sourceChunkIds) for (const id of m.sourceChunkIds) s.add(id);
19712
+ }
19713
+ return s;
19714
+ };
19715
+ let suppressed = /* @__PURE__ */ new Set();
19716
+ let memories = selectWith(suppressed);
19717
+ for (let i = 0; i < ordered.length; i++) {
19718
+ const next = provenanceOf(memories);
19719
+ if (next.size === suppressed.size && [...next].every((id) => suppressed.has(id))) break;
19720
+ suppressed = next;
19721
+ memories = selectWith(suppressed);
19722
+ }
19686
19723
  return {
19687
19724
  memories,
19688
19725
  usedBudget,
@@ -19703,6 +19740,7 @@ function toFactMemory(r) {
19703
19740
  ...r.eventTimeStart !== void 0 && { eventTimeStart: r.eventTimeStart },
19704
19741
  ...r.eventTimeEnd !== void 0 && { eventTimeEnd: r.eventTimeEnd },
19705
19742
  ...r.eventTimeKind !== void 0 && { eventTimeKind: r.eventTimeKind },
19743
+ ...r.sourceChunkIds !== void 0 && r.sourceChunkIds !== null && { sourceChunkIds: r.sourceChunkIds },
19706
19744
  // r.similarity from searchVaultMemoriesWithSize is the fused score
19707
19745
  // (cosine + BM25 + RRF + recency + proof) when useFusion=true (the
19708
19746
  // default) and pure cosine when useFusion=false. The breakdown
@@ -19817,6 +19855,7 @@ function rankVaultMemories(_query, queryEmbedding, items, options) {
19817
19855
  updatedAt: item.updatedAt,
19818
19856
  createdAt: item.createdAt,
19819
19857
  eventTimeStart: item.eventTimeStart,
19858
+ sourceChunkIds: item.sourceChunkIds,
19820
19859
  eventTimeEnd: item.eventTimeEnd,
19821
19860
  eventTimeKind: item.eventTimeKind,
19822
19861
  similarity: cosineSimilarity(queryEmbedding, item.embedding)
@@ -19858,7 +19897,8 @@ function rankVaultMemories(_query, queryEmbedding, items, options) {
19858
19897
  content: r.content,
19859
19898
  similarity: r.similarity,
19860
19899
  createdAt: item?.createdAt ?? item?.updatedAt,
19861
- updatedAt: item?.updatedAt
19900
+ updatedAt: item?.updatedAt,
19901
+ sourceChunkIds: item?.sourceChunkIds
19862
19902
  };
19863
19903
  });
19864
19904
  }
@@ -19897,6 +19937,7 @@ function rankFusedVaultMemories(query, queryEmbedding, items, options) {
19897
19937
  createdAt: item.createdAt ?? item.updatedAt,
19898
19938
  updatedAt: item.updatedAt,
19899
19939
  eventTimeStart: item.eventTimeStart,
19940
+ sourceChunkIds: item.sourceChunkIds,
19900
19941
  eventTimeEnd: item.eventTimeEnd,
19901
19942
  eventTimeKind: item.eventTimeKind
19902
19943
  });
@@ -19939,7 +19980,8 @@ function rankFusedVaultMemories(query, queryEmbedding, items, options) {
19939
19980
  content: it.content,
19940
19981
  similarity: (fused.get(id) ?? 0) * boostFor(id),
19941
19982
  createdAt: it.createdAt ?? it.updatedAt,
19942
- updatedAt: it.updatedAt
19983
+ updatedAt: it.updatedAt,
19984
+ sourceChunkIds: it.sourceChunkIds
19943
19985
  });
19944
19986
  seen.add(id);
19945
19987
  }
@@ -19977,13 +20019,7 @@ async function rankFusedVaultMemoriesAsync(query, queryEmbedding, items, options
19977
20019
  combined = headSlice.map((r) => {
19978
20020
  const v2 = v2ScoreById.get(r.uniqueId) ?? 0;
19979
20021
  const ce = ceScoreById.get(r.uniqueId) ?? 0;
19980
- return {
19981
- uniqueId: r.uniqueId,
19982
- content: r.content,
19983
- similarity: v2 * (1 + ceWeight * ce),
19984
- createdAt: r.createdAt,
19985
- updatedAt: r.updatedAt
19986
- };
20022
+ return { ...r, similarity: v2 * (1 + ceWeight * ce) };
19987
20023
  });
19988
20024
  combined.sort((a, b) => b.similarity - a.similarity);
19989
20025
  } catch (err) {
@@ -20016,7 +20052,8 @@ async function rankFusedVaultMemoriesAsync(query, queryEmbedding, items, options
20016
20052
  content: it.content,
20017
20053
  similarity: fused.get(id) ?? 0,
20018
20054
  createdAt: it.createdAt ?? it.updatedAt,
20019
- updatedAt: it.updatedAt
20055
+ updatedAt: it.updatedAt,
20056
+ sourceChunkIds: it.sourceChunkIds
20020
20057
  });
20021
20058
  seen.add(id);
20022
20059
  }
@@ -20046,6 +20083,7 @@ async function rankFusedVaultMemoriesAsync(query, queryEmbedding, items, options
20046
20083
  createdAt: orig?.createdAt,
20047
20084
  updatedAt: orig?.updatedAt,
20048
20085
  eventTimeStart: orig?.eventTimeStart,
20086
+ sourceChunkIds: orig?.sourceChunkIds,
20049
20087
  eventTimeEnd: orig?.eventTimeEnd,
20050
20088
  eventTimeKind: orig?.eventTimeKind
20051
20089
  };
@@ -20109,6 +20147,7 @@ async function rankComposite(originalQuery, originalQueryEmbedding, subQueries,
20109
20147
  createdAt: item.createdAt ?? item.updatedAt,
20110
20148
  updatedAt: item.updatedAt,
20111
20149
  eventTimeStart: item.eventTimeStart,
20150
+ sourceChunkIds: item.sourceChunkIds,
20112
20151
  eventTimeEnd: item.eventTimeEnd,
20113
20152
  eventTimeKind: item.eventTimeKind
20114
20153
  };
@@ -20129,6 +20168,7 @@ async function rankComposite(originalQuery, originalQueryEmbedding, subQueries,
20129
20168
  createdAt: item.createdAt ?? item.updatedAt,
20130
20169
  updatedAt: item.updatedAt,
20131
20170
  eventTimeStart: item.eventTimeStart,
20171
+ sourceChunkIds: item.sourceChunkIds,
20132
20172
  eventTimeEnd: item.eventTimeEnd,
20133
20173
  eventTimeKind: item.eventTimeKind
20134
20174
  });
@@ -20180,6 +20220,7 @@ async function rankComposite(originalQuery, originalQueryEmbedding, subQueries,
20180
20220
  createdAt: orig?.createdAt,
20181
20221
  updatedAt: orig?.updatedAt,
20182
20222
  eventTimeStart: orig?.eventTimeStart,
20223
+ sourceChunkIds: orig?.sourceChunkIds,
20183
20224
  eventTimeEnd: orig?.eventTimeEnd,
20184
20225
  eventTimeKind: orig?.eventTimeKind
20185
20226
  };
@@ -20321,6 +20362,7 @@ async function searchVaultMemoriesWithSize(query, vaultCtx, embeddingOptions, ca
20321
20362
  updatedAt: m.updatedAt,
20322
20363
  proofCount: m.proofCount,
20323
20364
  eventTimeStart: m.eventTimeStart,
20365
+ sourceChunkIds: m.sourceChunkIds,
20324
20366
  eventTimeEnd: m.eventTimeEnd,
20325
20367
  eventTimeKind: normalizeEventTimeKind(m.eventTimeKind)
20326
20368
  }));
@@ -5419,6 +5419,9 @@ interface VaultSearchResult {
5419
5419
  eventTimeStart?: number | null;
5420
5420
  eventTimeEnd?: number | null;
5421
5421
  eventTimeKind?: "point" | "range" | "ongoing" | null;
5422
+ /** Message ids this fact was extracted from (provenance). recall() uses
5423
+ * these to suppress the originating chunk in the chunk lane. */
5424
+ sourceChunkIds?: string[] | null;
5422
5425
  }
5423
5426
  /**
5424
5427
  * Search vault memories by semantic similarity. Returns structured results
@@ -5419,6 +5419,9 @@ interface VaultSearchResult {
5419
5419
  eventTimeStart?: number | null;
5420
5420
  eventTimeEnd?: number | null;
5421
5421
  eventTimeKind?: "point" | "range" | "ongoing" | null;
5422
+ /** Message ids this fact was extracted from (provenance). recall() uses
5423
+ * these to suppress the originating chunk in the chunk lane. */
5424
+ sourceChunkIds?: string[] | null;
5422
5425
  }
5423
5426
  /**
5424
5427
  * Search vault memories by semantic similarity. Returns structured results
@@ -95,7 +95,7 @@ import {
95
95
  updateVaultMemoryEmbeddingOp,
96
96
  updateVaultMemoryOp,
97
97
  upsertMessageOp
98
- } from "./chunk-G3DC7QBH.mjs";
98
+ } from "./chunk-KLJBJWWI.mjs";
99
99
  import {
100
100
  createStreamingDeAnonymizer,
101
101
  resolvePiiRedactor
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  recall
3
- } from "./chunk-G3DC7QBH.mjs";
3
+ } from "./chunk-KLJBJWWI.mjs";
4
4
  import "./chunk-RCCKRTBI.mjs";
5
5
  import "./chunk-FMGZTVXQ.mjs";
6
6
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anuma/sdk",
3
- "version": "1.1.3",
3
+ "version": "1.1.5",
4
4
  "description": "",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",