risicare 0.9.1 → 0.9.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.
Files changed (90) hide show
  1. package/CHANGELOG.md +1236 -0
  2. package/dist/frameworks/instructor.cjs +20 -5
  3. package/dist/frameworks/instructor.cjs.map +1 -1
  4. package/dist/frameworks/instructor.js +20 -5
  5. package/dist/frameworks/instructor.js.map +1 -1
  6. package/dist/frameworks/langchain.cjs +20 -5
  7. package/dist/frameworks/langchain.cjs.map +1 -1
  8. package/dist/frameworks/langchain.js +20 -5
  9. package/dist/frameworks/langchain.js.map +1 -1
  10. package/dist/frameworks/langgraph.cjs +20 -5
  11. package/dist/frameworks/langgraph.cjs.map +1 -1
  12. package/dist/frameworks/langgraph.js +20 -5
  13. package/dist/frameworks/langgraph.js.map +1 -1
  14. package/dist/frameworks/llamaindex.cjs +20 -5
  15. package/dist/frameworks/llamaindex.cjs.map +1 -1
  16. package/dist/frameworks/llamaindex.js +20 -5
  17. package/dist/frameworks/llamaindex.js.map +1 -1
  18. package/dist/index.cjs +77 -13
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.js +77 -13
  21. package/dist/index.js.map +1 -1
  22. package/dist/providers/anthropic/index.cjs +25 -6
  23. package/dist/providers/anthropic/index.cjs.map +1 -1
  24. package/dist/providers/anthropic/index.d.cts +3 -0
  25. package/dist/providers/anthropic/index.d.ts +3 -0
  26. package/dist/providers/anthropic/index.js +25 -6
  27. package/dist/providers/anthropic/index.js.map +1 -1
  28. package/dist/providers/bedrock/index.cjs +25 -6
  29. package/dist/providers/bedrock/index.cjs.map +1 -1
  30. package/dist/providers/bedrock/index.d.cts +3 -0
  31. package/dist/providers/bedrock/index.d.ts +3 -0
  32. package/dist/providers/bedrock/index.js +25 -6
  33. package/dist/providers/bedrock/index.js.map +1 -1
  34. package/dist/providers/cerebras/index.cjs +25 -6
  35. package/dist/providers/cerebras/index.cjs.map +1 -1
  36. package/dist/providers/cerebras/index.d.cts +3 -0
  37. package/dist/providers/cerebras/index.d.ts +3 -0
  38. package/dist/providers/cerebras/index.js +25 -6
  39. package/dist/providers/cerebras/index.js.map +1 -1
  40. package/dist/providers/cohere/index.cjs +25 -6
  41. package/dist/providers/cohere/index.cjs.map +1 -1
  42. package/dist/providers/cohere/index.d.cts +3 -0
  43. package/dist/providers/cohere/index.d.ts +3 -0
  44. package/dist/providers/cohere/index.js +25 -6
  45. package/dist/providers/cohere/index.js.map +1 -1
  46. package/dist/providers/google/index.cjs +25 -6
  47. package/dist/providers/google/index.cjs.map +1 -1
  48. package/dist/providers/google/index.d.cts +3 -0
  49. package/dist/providers/google/index.d.ts +3 -0
  50. package/dist/providers/google/index.js +25 -6
  51. package/dist/providers/google/index.js.map +1 -1
  52. package/dist/providers/groq/index.cjs +25 -6
  53. package/dist/providers/groq/index.cjs.map +1 -1
  54. package/dist/providers/groq/index.d.cts +3 -0
  55. package/dist/providers/groq/index.d.ts +3 -0
  56. package/dist/providers/groq/index.js +25 -6
  57. package/dist/providers/groq/index.js.map +1 -1
  58. package/dist/providers/huggingface/index.cjs +23 -5
  59. package/dist/providers/huggingface/index.cjs.map +1 -1
  60. package/dist/providers/huggingface/index.js +23 -5
  61. package/dist/providers/huggingface/index.js.map +1 -1
  62. package/dist/providers/mistral/index.cjs +25 -6
  63. package/dist/providers/mistral/index.cjs.map +1 -1
  64. package/dist/providers/mistral/index.d.cts +3 -0
  65. package/dist/providers/mistral/index.d.ts +3 -0
  66. package/dist/providers/mistral/index.js +25 -6
  67. package/dist/providers/mistral/index.js.map +1 -1
  68. package/dist/providers/ollama/index.cjs +25 -6
  69. package/dist/providers/ollama/index.cjs.map +1 -1
  70. package/dist/providers/ollama/index.d.cts +3 -0
  71. package/dist/providers/ollama/index.d.ts +3 -0
  72. package/dist/providers/ollama/index.js +25 -6
  73. package/dist/providers/ollama/index.js.map +1 -1
  74. package/dist/providers/openai/index.cjs +25 -6
  75. package/dist/providers/openai/index.cjs.map +1 -1
  76. package/dist/providers/openai/index.d.cts +3 -0
  77. package/dist/providers/openai/index.d.ts +3 -0
  78. package/dist/providers/openai/index.js +25 -6
  79. package/dist/providers/openai/index.js.map +1 -1
  80. package/dist/providers/together/index.cjs +25 -6
  81. package/dist/providers/together/index.cjs.map +1 -1
  82. package/dist/providers/together/index.d.cts +3 -0
  83. package/dist/providers/together/index.d.ts +3 -0
  84. package/dist/providers/together/index.js +25 -6
  85. package/dist/providers/together/index.js.map +1 -1
  86. package/dist/providers/vercel-ai/index.cjs +20 -5
  87. package/dist/providers/vercel-ai/index.cjs.map +1 -1
  88. package/dist/providers/vercel-ai/index.js +20 -5
  89. package/dist/providers/vercel-ai/index.js.map +1 -1
  90. package/package.json +3 -2
package/dist/index.cjs CHANGED
@@ -646,6 +646,12 @@ var BatchSpanProcessor = class _BatchSpanProcessor {
646
646
  _beforeExitHandler = null;
647
647
  // Retry tracking for failed batches (Audit #5)
648
648
  _retryCounts = /* @__PURE__ */ new Map();
649
+ /**
650
+ * The HTTP requests that the failed rounds of each re-queued span sent, by span id (issue
651
+ * #57). It has the same life as `_retryCounts`: `_forgetRetry` ends both. NaN = a round for
652
+ * which the exporter did not say. Empty for an exporter that does not state it.
653
+ */
654
+ _retryRequests = /* @__PURE__ */ new Map();
649
655
  static MAX_RETRIES = 3;
650
656
  _lastRefusalWarnAt = Number.NEGATIVE_INFINITY;
651
657
  _lastUnackWarnAt = Number.NEGATIVE_INFINITY;
@@ -860,6 +866,7 @@ var BatchSpanProcessor = class _BatchSpanProcessor {
860
866
  await shutdownExporter(exporter, Math.max(0, shutdownDeadline - Date.now()));
861
867
  }
862
868
  this._retryCounts.clear();
869
+ this._retryRequests.clear();
863
870
  debug(
864
871
  `BatchSpanProcessor shutdown. Exported: ${this.exportedSpans}, Dropped: ${this.droppedSpans}, Failed: ${this.failedExports}`
865
872
  );
@@ -876,7 +883,7 @@ var BatchSpanProcessor = class _BatchSpanProcessor {
876
883
  if (this._queue.length >= this._maxQueueSize) {
877
884
  if (this._quotaPaused()) {
878
885
  const oldest = this._queue.shift();
879
- if (oldest !== void 0) this._retryCounts.delete(oldest.spanId);
886
+ if (oldest !== void 0) this._forgetRetry(oldest.spanId);
880
887
  this._recordDropped("quota_exceeded");
881
888
  for (const exporter of this._exporters) {
882
889
  try {
@@ -1071,13 +1078,37 @@ var BatchSpanProcessor = class _BatchSpanProcessor {
1071
1078
  }
1072
1079
  }
1073
1080
  }
1074
- /** The requests in one export round, when every exporter that delivers states it. */
1075
- _requestsPerRound() {
1081
+ /** The one exporter that delivers, when there is exactly one. */
1082
+ _soleDeliverer() {
1076
1083
  const delivering = this._exporters.filter((e) => e.countsAsDelivery !== false);
1077
- if (delivering.length !== 1) return void 0;
1078
- const n = delivering[0].attemptsPerExport;
1084
+ return delivering.length === 1 ? delivering[0] : void 0;
1085
+ }
1086
+ /** The most requests in one export round, when every exporter that delivers states it. */
1087
+ _requestsPerRound() {
1088
+ const n = this._soleDeliverer()?.attemptsPerExport;
1079
1089
  return typeof n === "number" && Number.isFinite(n) && n > 0 ? n : void 0;
1080
1090
  }
1091
+ /**
1092
+ * The HTTP requests that the failed round for `batch` really sent (issue #57). `undefined`
1093
+ * when the exporter that delivers does not state it, so that the WARNING keeps its "up to"
1094
+ * text. NaN when the exporter has no record of the round.
1095
+ */
1096
+ _requestsSent(batch) {
1097
+ const exporter = this._soleDeliverer();
1098
+ if (exporter === void 0 || typeof exporter.takeAttempts !== "function") return void 0;
1099
+ try {
1100
+ const n = exporter.takeAttempts(batch);
1101
+ return typeof n === "number" && Number.isFinite(n) && n >= 0 ? n : Number.NaN;
1102
+ } catch (e) {
1103
+ debug(`takeAttempts of ${exporter.name} failed: ${describeThrown(e)}`);
1104
+ return Number.NaN;
1105
+ }
1106
+ }
1107
+ /** End the retry tracking of one span (retry-map drain sites 1 and 2 of 3, and the queue drop). */
1108
+ _forgetRetry(spanId) {
1109
+ this._retryCounts.delete(spanId);
1110
+ this._retryRequests.delete(spanId);
1111
+ }
1081
1112
  /**
1082
1113
  * One export round.
1083
1114
  *
@@ -1140,7 +1171,7 @@ var BatchSpanProcessor = class _BatchSpanProcessor {
1140
1171
  this._countDelivered(batch.length - unserializable.size, ack);
1141
1172
  batchExported = true;
1142
1173
  for (const span of batch) {
1143
- this._retryCounts.delete(span.spanId);
1174
+ this._forgetRetry(span.spanId);
1144
1175
  }
1145
1176
  }
1146
1177
  } else {
@@ -1156,16 +1187,21 @@ var BatchSpanProcessor = class _BatchSpanProcessor {
1156
1187
  if (unserializable.size > 0) this._recordDropped("unacknowledged", unserializable.size);
1157
1188
  if (!batchExported) {
1158
1189
  let dropped = 0;
1190
+ const sent = this._requestsSent(batch);
1191
+ const droppedRequests = [];
1159
1192
  const retryable = batch.filter((span) => {
1160
1193
  if (unserializable.has(span)) return false;
1161
1194
  const count = (this._retryCounts.get(span.spanId) ?? 0) + 1;
1195
+ const requests = sent === void 0 ? void 0 : (this._retryRequests.get(span.spanId) ?? 0) + sent;
1162
1196
  if (count > _BatchSpanProcessor.MAX_RETRIES) {
1163
- this._retryCounts.delete(span.spanId);
1197
+ this._forgetRetry(span.spanId);
1198
+ if (requests !== void 0) droppedRequests.push(requests);
1164
1199
  this._recordDropped("transport_refused");
1165
1200
  dropped++;
1166
1201
  return false;
1167
1202
  }
1168
1203
  this._retryCounts.set(span.spanId, count);
1204
+ if (requests !== void 0) this._retryRequests.set(span.spanId, requests);
1169
1205
  return true;
1170
1206
  });
1171
1207
  if (retryable.length > 0) {
@@ -1178,8 +1214,21 @@ var BatchSpanProcessor = class _BatchSpanProcessor {
1178
1214
  this._lastRefusalWarnAt = now;
1179
1215
  const rounds = _BatchSpanProcessor.MAX_RETRIES + 1;
1180
1216
  const perRound = this._requestsPerRound();
1217
+ const stated = droppedRequests.length > 0 && droppedRequests.every((n) => Number.isFinite(n));
1218
+ let requestsText = "";
1219
+ if (stated) {
1220
+ let lo = droppedRequests[0];
1221
+ let hi = lo;
1222
+ for (const n of droppedRequests) {
1223
+ if (n < lo) lo = n;
1224
+ if (n > hi) hi = n;
1225
+ }
1226
+ requestsText = lo === hi ? ` (${hi} HTTP ${hi === 1 ? "request" : "requests"} sent)` : ` (${lo} to ${hi} HTTP requests sent)`;
1227
+ } else if (perRound !== void 0) {
1228
+ requestsText = ` (up to ${rounds * perRound} HTTP requests: ${perRound} in each round)`;
1229
+ }
1181
1230
  warn(
1182
- `${dropped} span(s) DISCARDED (reason=transport_refused) after ${rounds} failed export rounds each` + (perRound !== void 0 ? ` (up to ${rounds * perRound} HTTP requests: ${perRound} in each round)` : "") + ` \u2014 the endpoint is not accepting spans and the retry budget is spent. ${this.droppedSpansByReason.transport_refused} span(s) discarded this way so far in this process. This data is gone; check the apiKey and the endpoint.`
1231
+ `${dropped} span(s) DISCARDED (reason=transport_refused) after ${rounds} failed export rounds each` + requestsText + ` \u2014 the endpoint is not accepting spans and the retry budget is spent. ${this.droppedSpansByReason.transport_refused} span(s) discarded this way so far in this process. This data is gone; check the apiKey and the endpoint.`
1183
1232
  );
1184
1233
  }
1185
1234
  }
@@ -2442,7 +2491,7 @@ function markCancel(span, error) {
2442
2491
  }
2443
2492
 
2444
2493
  // src/version.ts
2445
- var SDK_VERSION = "0.9.1";
2494
+ var SDK_VERSION = "0.9.2";
2446
2495
 
2447
2496
  // src/exporters/quota.ts
2448
2497
  var QUOTA_REASON = "monthly_quota_exceeded";
@@ -2587,6 +2636,8 @@ var HttpExporter = class {
2587
2636
  _calls = /* @__PURE__ */ new Map();
2588
2637
  /** The ack of each finished call, by its batch. Read once by `takeAck(spans)`. */
2589
2638
  _acks = /* @__PURE__ */ new WeakMap();
2639
+ /** The requests that each finished call sent, by its batch. Read once by `takeAttempts(spans)`. */
2640
+ _requests = /* @__PURE__ */ new WeakMap();
2590
2641
  /** The batch processor dropped span(s) from a full queue in the quota pause (S-1). */
2591
2642
  noteQuotaDrop(count = 1) {
2592
2643
  this._quota.addDrops(count);
@@ -2638,6 +2689,18 @@ var HttpExporter = class {
2638
2689
  get attemptsPerExport() {
2639
2690
  return this._maxRetries;
2640
2691
  }
2692
+ /**
2693
+ * Returns the number of HTTP requests that the `export()` call for `spans` sent, and clears
2694
+ * it. This is the number that was sent, not the most that the call may send
2695
+ * (`attemptsPerExport`): a 401 or 403 stops the loop after one request, and an open circuit
2696
+ * breaker sends none. Returns `null` when no call is on record for `spans`. The answer is
2697
+ * kept per batch, as `takeAck` keeps the ack.
2698
+ */
2699
+ takeAttempts(spans) {
2700
+ const n = this._requests.get(spans) ?? null;
2701
+ this._requests.delete(spans);
2702
+ return n;
2703
+ }
2641
2704
  /**
2642
2705
  * Returns the counts of the ack that the `export()` call for `spans` received, and clears
2643
2706
  * them. The answer is kept per batch, not on the instance: two processors that share this
@@ -2682,13 +2745,15 @@ var HttpExporter = class {
2682
2745
  misroute: null,
2683
2746
  noRetry: false,
2684
2747
  status: null,
2685
- error: null
2748
+ error: null,
2749
+ attempts: 0
2686
2750
  };
2687
2751
  this._calls.set(spans, call);
2688
2752
  try {
2689
2753
  return await this._export(spans, call);
2690
2754
  } finally {
2691
2755
  this._calls.delete(spans);
2756
+ this._requests.set(spans, this._endpointHasCredentials ? 0 : call.attempts);
2692
2757
  }
2693
2758
  }
2694
2759
  async _export(spans, call) {
@@ -2728,14 +2793,13 @@ var HttpExporter = class {
2728
2793
  isHalfOpen = true;
2729
2794
  }
2730
2795
  const maxAttempts = isHalfOpen ? 1 : this._maxRetries;
2731
- let attempts = 0;
2732
2796
  for (let attempt = 0; attempt < maxAttempts; attempt++) {
2733
2797
  call.refusalAfterMs = null;
2734
2798
  call.misroute = null;
2735
2799
  call.noRetry = false;
2736
2800
  call.status = null;
2737
2801
  call.error = null;
2738
- attempts++;
2802
+ call.attempts++;
2739
2803
  const result = await this._sendRequest(payload, parts.length, call, spans);
2740
2804
  if (cancelled.aborted) {
2741
2805
  this._acks.delete(spans);
@@ -2757,7 +2821,7 @@ var HttpExporter = class {
2757
2821
  }
2758
2822
  if (call.refusalAfterMs !== null) {
2759
2823
  warn(
2760
- `Risicare: the ingest endpoint refused this batch for capacity (HTTP 429/503) after ${attempts} attempt(s). This is a healthy server shedding load, not an outage. This export of the batch failed; the circuit breaker does not count it. Reduce batch size or export rate if it persists.`
2824
+ `Risicare: the ingest endpoint refused this batch for capacity (HTTP 429/503) after ${call.attempts} attempt(s). This is a healthy server shedding load, not an outage. This export of the batch failed; the circuit breaker does not count it. Reduce batch size or export rate if it persists.`
2761
2825
  );
2762
2826
  return "failure" /* FAILURE */;
2763
2827
  }