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.js CHANGED
@@ -560,6 +560,12 @@ var BatchSpanProcessor = class _BatchSpanProcessor {
560
560
  _beforeExitHandler = null;
561
561
  // Retry tracking for failed batches (Audit #5)
562
562
  _retryCounts = /* @__PURE__ */ new Map();
563
+ /**
564
+ * The HTTP requests that the failed rounds of each re-queued span sent, by span id (issue
565
+ * #57). It has the same life as `_retryCounts`: `_forgetRetry` ends both. NaN = a round for
566
+ * which the exporter did not say. Empty for an exporter that does not state it.
567
+ */
568
+ _retryRequests = /* @__PURE__ */ new Map();
563
569
  static MAX_RETRIES = 3;
564
570
  _lastRefusalWarnAt = Number.NEGATIVE_INFINITY;
565
571
  _lastUnackWarnAt = Number.NEGATIVE_INFINITY;
@@ -774,6 +780,7 @@ var BatchSpanProcessor = class _BatchSpanProcessor {
774
780
  await shutdownExporter(exporter, Math.max(0, shutdownDeadline - Date.now()));
775
781
  }
776
782
  this._retryCounts.clear();
783
+ this._retryRequests.clear();
777
784
  debug(
778
785
  `BatchSpanProcessor shutdown. Exported: ${this.exportedSpans}, Dropped: ${this.droppedSpans}, Failed: ${this.failedExports}`
779
786
  );
@@ -790,7 +797,7 @@ var BatchSpanProcessor = class _BatchSpanProcessor {
790
797
  if (this._queue.length >= this._maxQueueSize) {
791
798
  if (this._quotaPaused()) {
792
799
  const oldest = this._queue.shift();
793
- if (oldest !== void 0) this._retryCounts.delete(oldest.spanId);
800
+ if (oldest !== void 0) this._forgetRetry(oldest.spanId);
794
801
  this._recordDropped("quota_exceeded");
795
802
  for (const exporter of this._exporters) {
796
803
  try {
@@ -985,13 +992,37 @@ var BatchSpanProcessor = class _BatchSpanProcessor {
985
992
  }
986
993
  }
987
994
  }
988
- /** The requests in one export round, when every exporter that delivers states it. */
989
- _requestsPerRound() {
995
+ /** The one exporter that delivers, when there is exactly one. */
996
+ _soleDeliverer() {
990
997
  const delivering = this._exporters.filter((e) => e.countsAsDelivery !== false);
991
- if (delivering.length !== 1) return void 0;
992
- const n = delivering[0].attemptsPerExport;
998
+ return delivering.length === 1 ? delivering[0] : void 0;
999
+ }
1000
+ /** The most requests in one export round, when every exporter that delivers states it. */
1001
+ _requestsPerRound() {
1002
+ const n = this._soleDeliverer()?.attemptsPerExport;
993
1003
  return typeof n === "number" && Number.isFinite(n) && n > 0 ? n : void 0;
994
1004
  }
1005
+ /**
1006
+ * The HTTP requests that the failed round for `batch` really sent (issue #57). `undefined`
1007
+ * when the exporter that delivers does not state it, so that the WARNING keeps its "up to"
1008
+ * text. NaN when the exporter has no record of the round.
1009
+ */
1010
+ _requestsSent(batch) {
1011
+ const exporter = this._soleDeliverer();
1012
+ if (exporter === void 0 || typeof exporter.takeAttempts !== "function") return void 0;
1013
+ try {
1014
+ const n = exporter.takeAttempts(batch);
1015
+ return typeof n === "number" && Number.isFinite(n) && n >= 0 ? n : Number.NaN;
1016
+ } catch (e) {
1017
+ debug(`takeAttempts of ${exporter.name} failed: ${describeThrown(e)}`);
1018
+ return Number.NaN;
1019
+ }
1020
+ }
1021
+ /** End the retry tracking of one span (retry-map drain sites 1 and 2 of 3, and the queue drop). */
1022
+ _forgetRetry(spanId) {
1023
+ this._retryCounts.delete(spanId);
1024
+ this._retryRequests.delete(spanId);
1025
+ }
995
1026
  /**
996
1027
  * One export round.
997
1028
  *
@@ -1054,7 +1085,7 @@ var BatchSpanProcessor = class _BatchSpanProcessor {
1054
1085
  this._countDelivered(batch.length - unserializable.size, ack);
1055
1086
  batchExported = true;
1056
1087
  for (const span of batch) {
1057
- this._retryCounts.delete(span.spanId);
1088
+ this._forgetRetry(span.spanId);
1058
1089
  }
1059
1090
  }
1060
1091
  } else {
@@ -1070,16 +1101,21 @@ var BatchSpanProcessor = class _BatchSpanProcessor {
1070
1101
  if (unserializable.size > 0) this._recordDropped("unacknowledged", unserializable.size);
1071
1102
  if (!batchExported) {
1072
1103
  let dropped = 0;
1104
+ const sent = this._requestsSent(batch);
1105
+ const droppedRequests = [];
1073
1106
  const retryable = batch.filter((span) => {
1074
1107
  if (unserializable.has(span)) return false;
1075
1108
  const count = (this._retryCounts.get(span.spanId) ?? 0) + 1;
1109
+ const requests = sent === void 0 ? void 0 : (this._retryRequests.get(span.spanId) ?? 0) + sent;
1076
1110
  if (count > _BatchSpanProcessor.MAX_RETRIES) {
1077
- this._retryCounts.delete(span.spanId);
1111
+ this._forgetRetry(span.spanId);
1112
+ if (requests !== void 0) droppedRequests.push(requests);
1078
1113
  this._recordDropped("transport_refused");
1079
1114
  dropped++;
1080
1115
  return false;
1081
1116
  }
1082
1117
  this._retryCounts.set(span.spanId, count);
1118
+ if (requests !== void 0) this._retryRequests.set(span.spanId, requests);
1083
1119
  return true;
1084
1120
  });
1085
1121
  if (retryable.length > 0) {
@@ -1092,8 +1128,21 @@ var BatchSpanProcessor = class _BatchSpanProcessor {
1092
1128
  this._lastRefusalWarnAt = now;
1093
1129
  const rounds = _BatchSpanProcessor.MAX_RETRIES + 1;
1094
1130
  const perRound = this._requestsPerRound();
1131
+ const stated = droppedRequests.length > 0 && droppedRequests.every((n) => Number.isFinite(n));
1132
+ let requestsText = "";
1133
+ if (stated) {
1134
+ let lo = droppedRequests[0];
1135
+ let hi = lo;
1136
+ for (const n of droppedRequests) {
1137
+ if (n < lo) lo = n;
1138
+ if (n > hi) hi = n;
1139
+ }
1140
+ requestsText = lo === hi ? ` (${hi} HTTP ${hi === 1 ? "request" : "requests"} sent)` : ` (${lo} to ${hi} HTTP requests sent)`;
1141
+ } else if (perRound !== void 0) {
1142
+ requestsText = ` (up to ${rounds * perRound} HTTP requests: ${perRound} in each round)`;
1143
+ }
1095
1144
  warn(
1096
- `${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.`
1145
+ `${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.`
1097
1146
  );
1098
1147
  }
1099
1148
  }
@@ -2356,7 +2405,7 @@ function markCancel(span, error) {
2356
2405
  }
2357
2406
 
2358
2407
  // src/version.ts
2359
- var SDK_VERSION = "0.9.1";
2408
+ var SDK_VERSION = "0.9.2";
2360
2409
 
2361
2410
  // src/exporters/quota.ts
2362
2411
  var QUOTA_REASON = "monthly_quota_exceeded";
@@ -2501,6 +2550,8 @@ var HttpExporter = class {
2501
2550
  _calls = /* @__PURE__ */ new Map();
2502
2551
  /** The ack of each finished call, by its batch. Read once by `takeAck(spans)`. */
2503
2552
  _acks = /* @__PURE__ */ new WeakMap();
2553
+ /** The requests that each finished call sent, by its batch. Read once by `takeAttempts(spans)`. */
2554
+ _requests = /* @__PURE__ */ new WeakMap();
2504
2555
  /** The batch processor dropped span(s) from a full queue in the quota pause (S-1). */
2505
2556
  noteQuotaDrop(count = 1) {
2506
2557
  this._quota.addDrops(count);
@@ -2552,6 +2603,18 @@ var HttpExporter = class {
2552
2603
  get attemptsPerExport() {
2553
2604
  return this._maxRetries;
2554
2605
  }
2606
+ /**
2607
+ * Returns the number of HTTP requests that the `export()` call for `spans` sent, and clears
2608
+ * it. This is the number that was sent, not the most that the call may send
2609
+ * (`attemptsPerExport`): a 401 or 403 stops the loop after one request, and an open circuit
2610
+ * breaker sends none. Returns `null` when no call is on record for `spans`. The answer is
2611
+ * kept per batch, as `takeAck` keeps the ack.
2612
+ */
2613
+ takeAttempts(spans) {
2614
+ const n = this._requests.get(spans) ?? null;
2615
+ this._requests.delete(spans);
2616
+ return n;
2617
+ }
2555
2618
  /**
2556
2619
  * Returns the counts of the ack that the `export()` call for `spans` received, and clears
2557
2620
  * them. The answer is kept per batch, not on the instance: two processors that share this
@@ -2596,13 +2659,15 @@ var HttpExporter = class {
2596
2659
  misroute: null,
2597
2660
  noRetry: false,
2598
2661
  status: null,
2599
- error: null
2662
+ error: null,
2663
+ attempts: 0
2600
2664
  };
2601
2665
  this._calls.set(spans, call);
2602
2666
  try {
2603
2667
  return await this._export(spans, call);
2604
2668
  } finally {
2605
2669
  this._calls.delete(spans);
2670
+ this._requests.set(spans, this._endpointHasCredentials ? 0 : call.attempts);
2606
2671
  }
2607
2672
  }
2608
2673
  async _export(spans, call) {
@@ -2642,14 +2707,13 @@ var HttpExporter = class {
2642
2707
  isHalfOpen = true;
2643
2708
  }
2644
2709
  const maxAttempts = isHalfOpen ? 1 : this._maxRetries;
2645
- let attempts = 0;
2646
2710
  for (let attempt = 0; attempt < maxAttempts; attempt++) {
2647
2711
  call.refusalAfterMs = null;
2648
2712
  call.misroute = null;
2649
2713
  call.noRetry = false;
2650
2714
  call.status = null;
2651
2715
  call.error = null;
2652
- attempts++;
2716
+ call.attempts++;
2653
2717
  const result = await this._sendRequest(payload, parts.length, call, spans);
2654
2718
  if (cancelled.aborted) {
2655
2719
  this._acks.delete(spans);
@@ -2671,7 +2735,7 @@ var HttpExporter = class {
2671
2735
  }
2672
2736
  if (call.refusalAfterMs !== null) {
2673
2737
  warn(
2674
- `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.`
2738
+ `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.`
2675
2739
  );
2676
2740
  return "failure" /* FAILURE */;
2677
2741
  }