risicare 0.9.1 → 0.10.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.
Files changed (93) hide show
  1. package/CHANGELOG.md +1419 -0
  2. package/README.md +37 -19
  3. package/dist/frameworks/instructor.cjs +65 -5
  4. package/dist/frameworks/instructor.cjs.map +1 -1
  5. package/dist/frameworks/instructor.js +65 -5
  6. package/dist/frameworks/instructor.js.map +1 -1
  7. package/dist/frameworks/langchain.cjs +65 -5
  8. package/dist/frameworks/langchain.cjs.map +1 -1
  9. package/dist/frameworks/langchain.js +65 -5
  10. package/dist/frameworks/langchain.js.map +1 -1
  11. package/dist/frameworks/langgraph.cjs +65 -5
  12. package/dist/frameworks/langgraph.cjs.map +1 -1
  13. package/dist/frameworks/langgraph.js +65 -5
  14. package/dist/frameworks/langgraph.js.map +1 -1
  15. package/dist/frameworks/llamaindex.cjs +65 -5
  16. package/dist/frameworks/llamaindex.cjs.map +1 -1
  17. package/dist/frameworks/llamaindex.js +65 -5
  18. package/dist/frameworks/llamaindex.js.map +1 -1
  19. package/dist/index.cjs +405 -27
  20. package/dist/index.cjs.map +1 -1
  21. package/dist/index.d.cts +14 -5
  22. package/dist/index.d.ts +14 -5
  23. package/dist/index.js +405 -27
  24. package/dist/index.js.map +1 -1
  25. package/dist/providers/anthropic/index.cjs +141 -13
  26. package/dist/providers/anthropic/index.cjs.map +1 -1
  27. package/dist/providers/anthropic/index.d.cts +3 -0
  28. package/dist/providers/anthropic/index.d.ts +3 -0
  29. package/dist/providers/anthropic/index.js +141 -13
  30. package/dist/providers/anthropic/index.js.map +1 -1
  31. package/dist/providers/bedrock/index.cjs +88 -9
  32. package/dist/providers/bedrock/index.cjs.map +1 -1
  33. package/dist/providers/bedrock/index.d.cts +3 -0
  34. package/dist/providers/bedrock/index.d.ts +3 -0
  35. package/dist/providers/bedrock/index.js +88 -9
  36. package/dist/providers/bedrock/index.js.map +1 -1
  37. package/dist/providers/cerebras/index.cjs +88 -9
  38. package/dist/providers/cerebras/index.cjs.map +1 -1
  39. package/dist/providers/cerebras/index.d.cts +3 -0
  40. package/dist/providers/cerebras/index.d.ts +3 -0
  41. package/dist/providers/cerebras/index.js +88 -9
  42. package/dist/providers/cerebras/index.js.map +1 -1
  43. package/dist/providers/cohere/index.cjs +88 -9
  44. package/dist/providers/cohere/index.cjs.map +1 -1
  45. package/dist/providers/cohere/index.d.cts +3 -0
  46. package/dist/providers/cohere/index.d.ts +3 -0
  47. package/dist/providers/cohere/index.js +88 -9
  48. package/dist/providers/cohere/index.js.map +1 -1
  49. package/dist/providers/google/index.cjs +88 -9
  50. package/dist/providers/google/index.cjs.map +1 -1
  51. package/dist/providers/google/index.d.cts +3 -0
  52. package/dist/providers/google/index.d.ts +3 -0
  53. package/dist/providers/google/index.js +88 -9
  54. package/dist/providers/google/index.js.map +1 -1
  55. package/dist/providers/groq/index.cjs +88 -9
  56. package/dist/providers/groq/index.cjs.map +1 -1
  57. package/dist/providers/groq/index.d.cts +3 -0
  58. package/dist/providers/groq/index.d.ts +3 -0
  59. package/dist/providers/groq/index.js +88 -9
  60. package/dist/providers/groq/index.js.map +1 -1
  61. package/dist/providers/huggingface/index.cjs +86 -8
  62. package/dist/providers/huggingface/index.cjs.map +1 -1
  63. package/dist/providers/huggingface/index.js +86 -8
  64. package/dist/providers/huggingface/index.js.map +1 -1
  65. package/dist/providers/mistral/index.cjs +88 -9
  66. package/dist/providers/mistral/index.cjs.map +1 -1
  67. package/dist/providers/mistral/index.d.cts +3 -0
  68. package/dist/providers/mistral/index.d.ts +3 -0
  69. package/dist/providers/mistral/index.js +88 -9
  70. package/dist/providers/mistral/index.js.map +1 -1
  71. package/dist/providers/ollama/index.cjs +88 -9
  72. package/dist/providers/ollama/index.cjs.map +1 -1
  73. package/dist/providers/ollama/index.d.cts +3 -0
  74. package/dist/providers/ollama/index.d.ts +3 -0
  75. package/dist/providers/ollama/index.js +88 -9
  76. package/dist/providers/ollama/index.js.map +1 -1
  77. package/dist/providers/openai/index.cjs +126 -11
  78. package/dist/providers/openai/index.cjs.map +1 -1
  79. package/dist/providers/openai/index.d.cts +3 -0
  80. package/dist/providers/openai/index.d.ts +3 -0
  81. package/dist/providers/openai/index.js +126 -11
  82. package/dist/providers/openai/index.js.map +1 -1
  83. package/dist/providers/together/index.cjs +88 -9
  84. package/dist/providers/together/index.cjs.map +1 -1
  85. package/dist/providers/together/index.d.cts +3 -0
  86. package/dist/providers/together/index.d.ts +3 -0
  87. package/dist/providers/together/index.js +88 -9
  88. package/dist/providers/together/index.js.map +1 -1
  89. package/dist/providers/vercel-ai/index.cjs +67 -7
  90. package/dist/providers/vercel-ai/index.cjs.map +1 -1
  91. package/dist/providers/vercel-ai/index.js +67 -7
  92. package/dist/providers/vercel-ai/index.js.map +1 -1
  93. package/package.json +3 -2
@@ -137,6 +137,51 @@ function hasCredentials(url) {
137
137
  }
138
138
  }
139
139
 
140
+ // src/masking.ts
141
+ var CONTENT_IN_JSON_OBJECT = /* @__PURE__ */ new Map([
142
+ [
143
+ "llm.invocation_parameters",
144
+ /* @__PURE__ */ new Set([
145
+ "additionalinstructions",
146
+ // OpenAI assistants run
147
+ "chathistory",
148
+ // Cohere
149
+ "contents",
150
+ // Gemini
151
+ "documents",
152
+ // Cohere RAG
153
+ "functions",
154
+ "input",
155
+ "inputtext",
156
+ // Bedrock Titan
157
+ "instructions",
158
+ "message",
159
+ // Cohere
160
+ "messages",
161
+ "preamble",
162
+ // Cohere
163
+ "prediction",
164
+ // OpenAI predicted output
165
+ "prompt",
166
+ "system",
167
+ // Anthropic
168
+ "systeminstruction",
169
+ // Gemini
170
+ "texts",
171
+ // Cohere embed
172
+ "toolconfig",
173
+ // Gemini
174
+ "tools"
175
+ ])
176
+ ]
177
+ ]);
178
+ var VALUE_RULE_PREFIXES = new Set(
179
+ [...CONTENT_IN_JSON_OBJECT.keys()].flatMap((key) => {
180
+ const segments = key.split(".");
181
+ return segments.slice(1).map((_, i) => segments.slice(0, i + 1).join("."));
182
+ })
183
+ );
184
+
140
185
  // src/exporters/batch.ts
141
186
  var MAX_TIMEOUT_MS = 2 ** 31 - 1;
142
187
  var MAX_BATCH_BYTES = 8 * 1024 * 1024;
@@ -286,7 +331,7 @@ function runWithContext(overrides, fn) {
286
331
  }
287
332
 
288
333
  // src/version.ts
289
- var SDK_VERSION = "0.9.1";
334
+ var SDK_VERSION = "0.10.0";
290
335
 
291
336
  // src/exporters/quota.ts
292
337
  var QUOTA_REASON = "monthly_quota_exceeded";
@@ -431,6 +476,8 @@ var HttpExporter = class {
431
476
  _calls = /* @__PURE__ */ new Map();
432
477
  /** The ack of each finished call, by its batch. Read once by `takeAck(spans)`. */
433
478
  _acks = /* @__PURE__ */ new WeakMap();
479
+ /** The requests that each finished call sent, by its batch. Read once by `takeAttempts(spans)`. */
480
+ _requests = /* @__PURE__ */ new WeakMap();
434
481
  /** The batch processor dropped span(s) from a full queue in the quota pause (S-1). */
435
482
  noteQuotaDrop(count = 1) {
436
483
  this._quota.addDrops(count);
@@ -482,6 +529,18 @@ var HttpExporter = class {
482
529
  get attemptsPerExport() {
483
530
  return this._maxRetries;
484
531
  }
532
+ /**
533
+ * Returns the number of HTTP requests that the `export()` call for `spans` sent, and clears
534
+ * it. This is the number that was sent, not the most that the call may send
535
+ * (`attemptsPerExport`): a 401 or 403 stops the loop after one request, and an open circuit
536
+ * breaker sends none. Returns `null` when no call is on record for `spans`. The answer is
537
+ * kept per batch, as `takeAck` keeps the ack.
538
+ */
539
+ takeAttempts(spans) {
540
+ const n = this._requests.get(spans) ?? null;
541
+ this._requests.delete(spans);
542
+ return n;
543
+ }
485
544
  /**
486
545
  * Returns the counts of the ack that the `export()` call for `spans` received, and clears
487
546
  * them. The answer is kept per batch, not on the instance: two processors that share this
@@ -526,13 +585,15 @@ var HttpExporter = class {
526
585
  misroute: null,
527
586
  noRetry: false,
528
587
  status: null,
529
- error: null
588
+ error: null,
589
+ attempts: 0
530
590
  };
531
591
  this._calls.set(spans, call);
532
592
  try {
533
593
  return await this._export(spans, call);
534
594
  } finally {
535
595
  this._calls.delete(spans);
596
+ this._requests.set(spans, this._endpointHasCredentials ? 0 : call.attempts);
536
597
  }
537
598
  }
538
599
  async _export(spans, call) {
@@ -572,14 +633,13 @@ var HttpExporter = class {
572
633
  isHalfOpen = true;
573
634
  }
574
635
  const maxAttempts = isHalfOpen ? 1 : this._maxRetries;
575
- let attempts = 0;
576
636
  for (let attempt = 0; attempt < maxAttempts; attempt++) {
577
637
  call.refusalAfterMs = null;
578
638
  call.misroute = null;
579
639
  call.noRetry = false;
580
640
  call.status = null;
581
641
  call.error = null;
582
- attempts++;
642
+ call.attempts++;
583
643
  const result = await this._sendRequest(payload, parts.length, call, spans);
584
644
  if (cancelled.aborted) {
585
645
  this._acks.delete(spans);
@@ -601,7 +661,7 @@ var HttpExporter = class {
601
661
  }
602
662
  if (call.refusalAfterMs !== null) {
603
663
  warn(
604
- `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.`
664
+ `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.`
605
665
  );
606
666
  return "failure" /* FAILURE */;
607
667
  }