@anuma/sdk 3.11.1 → 3.11.3

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.
@@ -5232,7 +5232,20 @@ type RecallDegradation =
5232
5232
  "rerank-unavailable"
5233
5233
  /** `budget: 'high'` requested but no `decomposeOptions`, so query
5234
5234
  * decomposition was skipped and the budget downgraded to mid. */
5235
- | "decompose-unavailable";
5235
+ | "decompose-unavailable"
5236
+ /** There was no usable cosine lane, so results were ranked on BM25 (lexical)
5237
+ * alone: either the query embedding failed (or came back empty), or no
5238
+ * candidate had a vector to score against it because the row (re)embed failed.
5239
+ * Also set when the chunk lane — cosine-only, with no lexical equivalent — was
5240
+ * skipped for the same reason. The embeddings provider is a single upstream
5241
+ * with no fallback, so this is a whole-provider outage rather than a per-item
5242
+ * miss — expect a quality drop, not a total loss.
5243
+ *
5244
+ * NOT set for a partial failure that leaves cosine running (a sub-query embed
5245
+ * failing back to the single-query path, or a row batch failing while other
5246
+ * rows keep usable vectors) — those are logged, not reported, so this stays a
5247
+ * reliable outage signal rather than a general embedding-error counter. */
5248
+ | "embeddings-unavailable";
5236
5249
  /**
5237
5250
  * Per-call recall observability payload (see {@link RecallOptions.onDiagnostics}).
5238
5251
  * All timings are wall-clock milliseconds. Lane counts are post-dedupe,
@@ -5232,7 +5232,20 @@ type RecallDegradation =
5232
5232
  "rerank-unavailable"
5233
5233
  /** `budget: 'high'` requested but no `decomposeOptions`, so query
5234
5234
  * decomposition was skipped and the budget downgraded to mid. */
5235
- | "decompose-unavailable";
5235
+ | "decompose-unavailable"
5236
+ /** There was no usable cosine lane, so results were ranked on BM25 (lexical)
5237
+ * alone: either the query embedding failed (or came back empty), or no
5238
+ * candidate had a vector to score against it because the row (re)embed failed.
5239
+ * Also set when the chunk lane — cosine-only, with no lexical equivalent — was
5240
+ * skipped for the same reason. The embeddings provider is a single upstream
5241
+ * with no fallback, so this is a whole-provider outage rather than a per-item
5242
+ * miss — expect a quality drop, not a total loss.
5243
+ *
5244
+ * NOT set for a partial failure that leaves cosine running (a sub-query embed
5245
+ * failing back to the single-query path, or a row batch failing while other
5246
+ * rows keep usable vectors) — those are logged, not reported, so this stays a
5247
+ * reliable outage signal rather than a general embedding-error counter. */
5248
+ | "embeddings-unavailable";
5236
5249
  /**
5237
5250
  * Per-call recall observability payload (see {@link RecallOptions.onDiagnostics}).
5238
5251
  * All timings are wall-clock milliseconds. Lane counts are post-dedupe,
@@ -5,11 +5,14 @@ import {
5
5
  DEFAULT_MIN_CHUNK_SIZE,
6
6
  DEFAULT_MIN_CONTENT_LENGTH,
7
7
  DEFAULT_VAULT_CACHE_SIZE,
8
+ EMBEDDINGS_DEGRADED_EMPTY,
8
9
  ENTITY_FANOUT,
9
10
  ENTITY_KINDS,
10
11
  LRUCache,
11
12
  MAX_HOPS,
12
13
  NODE_BUDGET,
14
+ RECALL_MAX_LIMIT,
15
+ RECALL_TOOL_NAME,
13
16
  RerankerUnavailableError,
14
17
  TOPICS_EXTRACTION_VERSION,
15
18
  TREND_RECENT_WINDOW_DAYS,
@@ -111,7 +114,7 @@ import {
111
114
  upsertMessageOp,
112
115
  useEncryption,
113
116
  vaultMemoryToStored
114
- } from "./chunk-7CTI3XR6.mjs";
117
+ } from "./chunk-7AW2VD5W.mjs";
115
118
  import {
116
119
  PII_PATTERNS,
117
120
  PiiRedactor,
@@ -1069,6 +1072,9 @@ var CompletionsStrategy = class {
1069
1072
  }
1070
1073
  }
1071
1074
  }
1075
+ if (choice.finish_reason) {
1076
+ accumulator.finishReason = choice.finish_reason;
1077
+ }
1072
1078
  if (choice.finish_reason === "tool_calls" || choice.finish_reason === "stop") {
1073
1079
  if (accumulator.toolCalls.size > 0) {
1074
1080
  accumulator.content = mergeXaiInlineParameterTags(
@@ -1151,7 +1157,9 @@ var CompletionsStrategy = class {
1151
1157
  content: finalContent,
1152
1158
  ...toolCalls && { tool_calls: toolCalls }
1153
1159
  },
1154
- finish_reason: toolCalls ? "tool_calls" : "stop"
1160
+ // Prefer what the provider actually said; fall back to the derived
1161
+ // value only when the stream carried no finish_reason at all.
1162
+ finish_reason: accumulator.finishReason ?? (toolCalls ? "tool_calls" : "stop")
1155
1163
  }
1156
1164
  ],
1157
1165
  ...usage && { usage },
@@ -1822,7 +1830,7 @@ var ResponsesStrategy = class {
1822
1830
  }
1823
1831
  return result;
1824
1832
  }
1825
- if (typedChunk.type === "response.completed") {
1833
+ if (typedChunk.type === "response.completed" || typedChunk.type === "response.incomplete") {
1826
1834
  if (typedChunk.response?.usage) {
1827
1835
  const u = typedChunk.response.usage;
1828
1836
  const promptTokens = u.input_tokens ?? u.prompt_tokens ?? 0;
@@ -1838,6 +1846,11 @@ var ResponsesStrategy = class {
1838
1846
  ...creditsExhausted !== void 0 && { credits_exhausted: creditsExhausted }
1839
1847
  };
1840
1848
  }
1849
+ const resp = typedChunk.response;
1850
+ const looksIncomplete = typedChunk.type === "response.incomplete" || resp?.status === "incomplete";
1851
+ if (looksIncomplete && resp?.incomplete_details?.reason === "max_output_tokens") {
1852
+ accumulator.finishReason = "length";
1853
+ }
1841
1854
  if (typedChunk.response?.tools_checksum && !accumulator.toolsChecksum) {
1842
1855
  accumulator.toolsChecksum = typedChunk.response.tools_checksum;
1843
1856
  }
@@ -3374,7 +3387,17 @@ Executing tool: ${toolInfo}
3374
3387
  flushDeAnon();
3375
3388
  currentAccumulator.content += tip;
3376
3389
  }
3390
+ const truncatedToNothing = (acc) => acc.finishReason === "length" && acc.toolCalls.size === 0 && acc.content.trim() === "";
3391
+ const TRUNCATION_ERROR = "Model response was truncated at the output-token limit before it produced any usable content or tool call. Retry with a higher `maxOutputTokens`, or prompt for fewer/smaller tool calls per turn.";
3377
3392
  if (toolIteration > 0) {
3393
+ if (truncatedToNothing(currentAccumulator)) {
3394
+ await fireRunError({ error: TRUNCATION_ERROR, stage: "model" });
3395
+ return {
3396
+ data: buildResponseFinal(currentAccumulator),
3397
+ error: TRUNCATION_ERROR,
3398
+ toolsChecksum: currentAccumulator.toolsChecksum
3399
+ };
3400
+ }
3378
3401
  const finalResponse = buildResponseFinal(currentAccumulator);
3379
3402
  if (onFinish) onFinish(finalResponse);
3380
3403
  await fireRunEnd({
@@ -3388,6 +3411,14 @@ Executing tool: ${toolInfo}
3388
3411
  autoExecutedToolResults: accumulatedToolResults
3389
3412
  };
3390
3413
  }
3414
+ if (truncatedToNothing(accumulator)) {
3415
+ await fireRunError({ error: TRUNCATION_ERROR, stage: "model" });
3416
+ return {
3417
+ data: response,
3418
+ error: TRUNCATION_ERROR,
3419
+ toolsChecksum: accumulator.toolsChecksum
3420
+ };
3421
+ }
3391
3422
  if (onFinish) onFinish(response);
3392
3423
  await fireRunEnd({
3393
3424
  finalContent: finalContentText(accumulator),
@@ -6396,6 +6427,11 @@ async function retain(content, ctx, options = {}) {
6396
6427
  ...options.folderId !== void 0 && { folderId: options.folderId }
6397
6428
  }
6398
6429
  );
6430
+ if (prepared.embeddingFailure || prepared.embeddingsUnavailable) {
6431
+ throw new Error(
6432
+ "retain: embeddings unavailable \u2014 refusing to auto-merge against an inert cosine lane, which would create a duplicate instead of merging into the existing memory. Retry when embeddings recover, or pass enableAutoMerge: false to force a create."
6433
+ );
6434
+ }
6399
6435
  if (options.consolidateOptions) {
6400
6436
  const outcome = await tryConsolidate(trimmed, ctx, options, prepared);
6401
6437
  if (outcome) {
@@ -7628,10 +7664,6 @@ function rankProfileCandidates(inputs, now = Date.now(), options = {}) {
7628
7664
  return ranked;
7629
7665
  }
7630
7666
 
7631
- // src/lib/memory/recallConstants.ts
7632
- var RECALL_TOOL_NAME = "recall_memory";
7633
- var RECALL_MAX_LIMIT = 50;
7634
-
7635
7667
  // src/lib/memory/recallTool.ts
7636
7668
  var DEFAULT_LIMIT = 8;
7637
7669
  var DEFAULT_BUDGET = "low";
@@ -7782,7 +7814,11 @@ function createRecallTool(ctx, toolOptions, callbacks) {
7782
7814
  conversationMemories += effectiveLimit;
7783
7815
  let surfaced = 0;
7784
7816
  try {
7817
+ let recallDegraded = [];
7785
7818
  const recallOpts = {
7819
+ onDiagnostics: (d) => {
7820
+ recallDegraded = d.degraded;
7821
+ },
7786
7822
  types: defaultTypes,
7787
7823
  limit: effectiveLimit,
7788
7824
  budget: defaultBudget,
@@ -7814,6 +7850,9 @@ function createRecallTool(ctx, toolOptions, callbacks) {
7814
7850
  }
7815
7851
  }
7816
7852
  surfaced = result.memories.length;
7853
+ if (result.memories.length === 0 && recallDegraded.includes("embeddings-unavailable")) {
7854
+ return EMBEDDINGS_DEGRADED_EMPTY;
7855
+ }
7817
7856
  const formatted = formatRecallResult(result.memories);
7818
7857
  return truncatedByBudget && surfaced > 0 ? `${formatted}
7819
7858
 
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  recall
3
- } from "./chunk-7CTI3XR6.mjs";
3
+ } from "./chunk-7AW2VD5W.mjs";
4
4
  import "./chunk-ILAWDQDE.mjs";
5
5
  import "./chunk-GYKJOWEO.mjs";
6
6
  export {