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.
- package/CHANGELOG.md +1419 -0
- package/README.md +37 -19
- package/dist/frameworks/instructor.cjs +65 -5
- package/dist/frameworks/instructor.cjs.map +1 -1
- package/dist/frameworks/instructor.js +65 -5
- package/dist/frameworks/instructor.js.map +1 -1
- package/dist/frameworks/langchain.cjs +65 -5
- package/dist/frameworks/langchain.cjs.map +1 -1
- package/dist/frameworks/langchain.js +65 -5
- package/dist/frameworks/langchain.js.map +1 -1
- package/dist/frameworks/langgraph.cjs +65 -5
- package/dist/frameworks/langgraph.cjs.map +1 -1
- package/dist/frameworks/langgraph.js +65 -5
- package/dist/frameworks/langgraph.js.map +1 -1
- package/dist/frameworks/llamaindex.cjs +65 -5
- package/dist/frameworks/llamaindex.cjs.map +1 -1
- package/dist/frameworks/llamaindex.js +65 -5
- package/dist/frameworks/llamaindex.js.map +1 -1
- package/dist/index.cjs +405 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -5
- package/dist/index.d.ts +14 -5
- package/dist/index.js +405 -27
- package/dist/index.js.map +1 -1
- package/dist/providers/anthropic/index.cjs +141 -13
- package/dist/providers/anthropic/index.cjs.map +1 -1
- package/dist/providers/anthropic/index.d.cts +3 -0
- package/dist/providers/anthropic/index.d.ts +3 -0
- package/dist/providers/anthropic/index.js +141 -13
- package/dist/providers/anthropic/index.js.map +1 -1
- package/dist/providers/bedrock/index.cjs +88 -9
- package/dist/providers/bedrock/index.cjs.map +1 -1
- package/dist/providers/bedrock/index.d.cts +3 -0
- package/dist/providers/bedrock/index.d.ts +3 -0
- package/dist/providers/bedrock/index.js +88 -9
- package/dist/providers/bedrock/index.js.map +1 -1
- package/dist/providers/cerebras/index.cjs +88 -9
- package/dist/providers/cerebras/index.cjs.map +1 -1
- package/dist/providers/cerebras/index.d.cts +3 -0
- package/dist/providers/cerebras/index.d.ts +3 -0
- package/dist/providers/cerebras/index.js +88 -9
- package/dist/providers/cerebras/index.js.map +1 -1
- package/dist/providers/cohere/index.cjs +88 -9
- package/dist/providers/cohere/index.cjs.map +1 -1
- package/dist/providers/cohere/index.d.cts +3 -0
- package/dist/providers/cohere/index.d.ts +3 -0
- package/dist/providers/cohere/index.js +88 -9
- package/dist/providers/cohere/index.js.map +1 -1
- package/dist/providers/google/index.cjs +88 -9
- package/dist/providers/google/index.cjs.map +1 -1
- package/dist/providers/google/index.d.cts +3 -0
- package/dist/providers/google/index.d.ts +3 -0
- package/dist/providers/google/index.js +88 -9
- package/dist/providers/google/index.js.map +1 -1
- package/dist/providers/groq/index.cjs +88 -9
- package/dist/providers/groq/index.cjs.map +1 -1
- package/dist/providers/groq/index.d.cts +3 -0
- package/dist/providers/groq/index.d.ts +3 -0
- package/dist/providers/groq/index.js +88 -9
- package/dist/providers/groq/index.js.map +1 -1
- package/dist/providers/huggingface/index.cjs +86 -8
- package/dist/providers/huggingface/index.cjs.map +1 -1
- package/dist/providers/huggingface/index.js +86 -8
- package/dist/providers/huggingface/index.js.map +1 -1
- package/dist/providers/mistral/index.cjs +88 -9
- package/dist/providers/mistral/index.cjs.map +1 -1
- package/dist/providers/mistral/index.d.cts +3 -0
- package/dist/providers/mistral/index.d.ts +3 -0
- package/dist/providers/mistral/index.js +88 -9
- package/dist/providers/mistral/index.js.map +1 -1
- package/dist/providers/ollama/index.cjs +88 -9
- package/dist/providers/ollama/index.cjs.map +1 -1
- package/dist/providers/ollama/index.d.cts +3 -0
- package/dist/providers/ollama/index.d.ts +3 -0
- package/dist/providers/ollama/index.js +88 -9
- package/dist/providers/ollama/index.js.map +1 -1
- package/dist/providers/openai/index.cjs +126 -11
- package/dist/providers/openai/index.cjs.map +1 -1
- package/dist/providers/openai/index.d.cts +3 -0
- package/dist/providers/openai/index.d.ts +3 -0
- package/dist/providers/openai/index.js +126 -11
- package/dist/providers/openai/index.js.map +1 -1
- package/dist/providers/together/index.cjs +88 -9
- package/dist/providers/together/index.cjs.map +1 -1
- package/dist/providers/together/index.d.cts +3 -0
- package/dist/providers/together/index.d.ts +3 -0
- package/dist/providers/together/index.js +88 -9
- package/dist/providers/together/index.js.map +1 -1
- package/dist/providers/vercel-ai/index.cjs +67 -7
- package/dist/providers/vercel-ai/index.cjs.map +1 -1
- package/dist/providers/vercel-ai/index.js +67 -7
- package/dist/providers/vercel-ai/index.js.map +1 -1
- package/package.json +3 -2
|
@@ -138,6 +138,51 @@ function hasCredentials(url) {
|
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
+
// src/masking.ts
|
|
142
|
+
var CONTENT_IN_JSON_OBJECT = /* @__PURE__ */ new Map([
|
|
143
|
+
[
|
|
144
|
+
"llm.invocation_parameters",
|
|
145
|
+
/* @__PURE__ */ new Set([
|
|
146
|
+
"additionalinstructions",
|
|
147
|
+
// OpenAI assistants run
|
|
148
|
+
"chathistory",
|
|
149
|
+
// Cohere
|
|
150
|
+
"contents",
|
|
151
|
+
// Gemini
|
|
152
|
+
"documents",
|
|
153
|
+
// Cohere RAG
|
|
154
|
+
"functions",
|
|
155
|
+
"input",
|
|
156
|
+
"inputtext",
|
|
157
|
+
// Bedrock Titan
|
|
158
|
+
"instructions",
|
|
159
|
+
"message",
|
|
160
|
+
// Cohere
|
|
161
|
+
"messages",
|
|
162
|
+
"preamble",
|
|
163
|
+
// Cohere
|
|
164
|
+
"prediction",
|
|
165
|
+
// OpenAI predicted output
|
|
166
|
+
"prompt",
|
|
167
|
+
"system",
|
|
168
|
+
// Anthropic
|
|
169
|
+
"systeminstruction",
|
|
170
|
+
// Gemini
|
|
171
|
+
"texts",
|
|
172
|
+
// Cohere embed
|
|
173
|
+
"toolconfig",
|
|
174
|
+
// Gemini
|
|
175
|
+
"tools"
|
|
176
|
+
])
|
|
177
|
+
]
|
|
178
|
+
]);
|
|
179
|
+
var VALUE_RULE_PREFIXES = new Set(
|
|
180
|
+
[...CONTENT_IN_JSON_OBJECT.keys()].flatMap((key) => {
|
|
181
|
+
const segments = key.split(".");
|
|
182
|
+
return segments.slice(1).map((_, i) => segments.slice(0, i + 1).join("."));
|
|
183
|
+
})
|
|
184
|
+
);
|
|
185
|
+
|
|
141
186
|
// src/exporters/batch.ts
|
|
142
187
|
var MAX_TIMEOUT_MS = 2 ** 31 - 1;
|
|
143
188
|
var MAX_BATCH_BYTES = 8 * 1024 * 1024;
|
|
@@ -282,7 +327,7 @@ function getContext() {
|
|
|
282
327
|
}
|
|
283
328
|
|
|
284
329
|
// src/version.ts
|
|
285
|
-
var SDK_VERSION = "0.
|
|
330
|
+
var SDK_VERSION = "0.10.0";
|
|
286
331
|
|
|
287
332
|
// src/exporters/quota.ts
|
|
288
333
|
var QUOTA_REASON = "monthly_quota_exceeded";
|
|
@@ -427,6 +472,8 @@ var HttpExporter = class {
|
|
|
427
472
|
_calls = /* @__PURE__ */ new Map();
|
|
428
473
|
/** The ack of each finished call, by its batch. Read once by `takeAck(spans)`. */
|
|
429
474
|
_acks = /* @__PURE__ */ new WeakMap();
|
|
475
|
+
/** The requests that each finished call sent, by its batch. Read once by `takeAttempts(spans)`. */
|
|
476
|
+
_requests = /* @__PURE__ */ new WeakMap();
|
|
430
477
|
/** The batch processor dropped span(s) from a full queue in the quota pause (S-1). */
|
|
431
478
|
noteQuotaDrop(count = 1) {
|
|
432
479
|
this._quota.addDrops(count);
|
|
@@ -478,6 +525,18 @@ var HttpExporter = class {
|
|
|
478
525
|
get attemptsPerExport() {
|
|
479
526
|
return this._maxRetries;
|
|
480
527
|
}
|
|
528
|
+
/**
|
|
529
|
+
* Returns the number of HTTP requests that the `export()` call for `spans` sent, and clears
|
|
530
|
+
* it. This is the number that was sent, not the most that the call may send
|
|
531
|
+
* (`attemptsPerExport`): a 401 or 403 stops the loop after one request, and an open circuit
|
|
532
|
+
* breaker sends none. Returns `null` when no call is on record for `spans`. The answer is
|
|
533
|
+
* kept per batch, as `takeAck` keeps the ack.
|
|
534
|
+
*/
|
|
535
|
+
takeAttempts(spans) {
|
|
536
|
+
const n = this._requests.get(spans) ?? null;
|
|
537
|
+
this._requests.delete(spans);
|
|
538
|
+
return n;
|
|
539
|
+
}
|
|
481
540
|
/**
|
|
482
541
|
* Returns the counts of the ack that the `export()` call for `spans` received, and clears
|
|
483
542
|
* them. The answer is kept per batch, not on the instance: two processors that share this
|
|
@@ -522,13 +581,15 @@ var HttpExporter = class {
|
|
|
522
581
|
misroute: null,
|
|
523
582
|
noRetry: false,
|
|
524
583
|
status: null,
|
|
525
|
-
error: null
|
|
584
|
+
error: null,
|
|
585
|
+
attempts: 0
|
|
526
586
|
};
|
|
527
587
|
this._calls.set(spans, call);
|
|
528
588
|
try {
|
|
529
589
|
return await this._export(spans, call);
|
|
530
590
|
} finally {
|
|
531
591
|
this._calls.delete(spans);
|
|
592
|
+
this._requests.set(spans, this._endpointHasCredentials ? 0 : call.attempts);
|
|
532
593
|
}
|
|
533
594
|
}
|
|
534
595
|
async _export(spans, call) {
|
|
@@ -568,14 +629,13 @@ var HttpExporter = class {
|
|
|
568
629
|
isHalfOpen = true;
|
|
569
630
|
}
|
|
570
631
|
const maxAttempts = isHalfOpen ? 1 : this._maxRetries;
|
|
571
|
-
let attempts = 0;
|
|
572
632
|
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
573
633
|
call.refusalAfterMs = null;
|
|
574
634
|
call.misroute = null;
|
|
575
635
|
call.noRetry = false;
|
|
576
636
|
call.status = null;
|
|
577
637
|
call.error = null;
|
|
578
|
-
attempts++;
|
|
638
|
+
call.attempts++;
|
|
579
639
|
const result = await this._sendRequest(payload, parts.length, call, spans);
|
|
580
640
|
if (cancelled.aborted) {
|
|
581
641
|
this._acks.delete(spans);
|
|
@@ -597,7 +657,7 @@ var HttpExporter = class {
|
|
|
597
657
|
}
|
|
598
658
|
if (call.refusalAfterMs !== null) {
|
|
599
659
|
warn(
|
|
600
|
-
`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.`
|
|
660
|
+
`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.`
|
|
601
661
|
);
|
|
602
662
|
return "failure" /* FAILURE */;
|
|
603
663
|
}
|
|
@@ -868,7 +928,7 @@ function className(error) {
|
|
|
868
928
|
}
|
|
869
929
|
return typeof error;
|
|
870
930
|
}
|
|
871
|
-
function responseReadFailed(provider, site, error, span) {
|
|
931
|
+
function responseReadFailed(provider, site, error, span, part = "response") {
|
|
872
932
|
try {
|
|
873
933
|
const cls = className(error);
|
|
874
934
|
span?.setAttribute("risicare.observer_error", cls);
|
|
@@ -876,7 +936,7 @@ function responseReadFailed(provider, site, error, span) {
|
|
|
876
936
|
const key = `${provider}\0${site}\0${cls}`;
|
|
877
937
|
if (logged.has(key) || logged.size >= LOGGED_MAX) return;
|
|
878
938
|
logged.add(key);
|
|
879
|
-
debug(`could not read the ${provider}
|
|
939
|
+
debug(`could not read the ${provider} ${part} in ${site} (${cls}); the span keeps fewer facts`);
|
|
880
940
|
} catch {
|
|
881
941
|
}
|
|
882
942
|
}
|
|
@@ -1169,7 +1229,21 @@ function calculateCost(model, promptTokens, completionTokens) {
|
|
|
1169
1229
|
function tokenCount(value) {
|
|
1170
1230
|
return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : void 0;
|
|
1171
1231
|
}
|
|
1172
|
-
|
|
1232
|
+
var CACHE_READ_TOKENS_KEY = "gen_ai.usage.cache_read.input_tokens";
|
|
1233
|
+
var CACHE_WRITE_TOKENS_KEY = "gen_ai.usage.cache_write.input_tokens";
|
|
1234
|
+
var REASONING_TOKENS_KEY = "gen_ai.usage.reasoning.output_tokens";
|
|
1235
|
+
function providerInteger(value) {
|
|
1236
|
+
return typeof value === "number" && Number.isInteger(value) && value >= 0 ? value : void 0;
|
|
1237
|
+
}
|
|
1238
|
+
function recordUsageDetails(span, details) {
|
|
1239
|
+
const cacheRead = providerInteger(details.cacheRead);
|
|
1240
|
+
const cacheWrite = providerInteger(details.cacheWrite);
|
|
1241
|
+
const reasoning = providerInteger(details.reasoning);
|
|
1242
|
+
if (cacheRead !== void 0) span.setAttribute(CACHE_READ_TOKENS_KEY, cacheRead);
|
|
1243
|
+
if (cacheWrite !== void 0) span.setAttribute(CACHE_WRITE_TOKENS_KEY, cacheWrite);
|
|
1244
|
+
if (reasoning !== void 0) span.setAttribute(REASONING_TOKENS_KEY, reasoning);
|
|
1245
|
+
}
|
|
1246
|
+
function recordTokenUsage(span, counts, model, details) {
|
|
1173
1247
|
const promptTokens = tokenCount(counts.prompt);
|
|
1174
1248
|
const completionTokens = tokenCount(counts.completion);
|
|
1175
1249
|
const bothKnown = promptTokens !== void 0 && completionTokens !== void 0;
|
|
@@ -1180,6 +1254,7 @@ function recordTokenUsage(span, counts, model) {
|
|
|
1180
1254
|
if (completionTokens !== void 0) span.setAttribute("gen_ai.usage.completion_tokens", completionTokens);
|
|
1181
1255
|
if (totalTokens !== void 0) span.setAttribute("gen_ai.usage.total_tokens", totalTokens);
|
|
1182
1256
|
if (costUsd !== void 0) span.setAttribute("llm.cost.total_usd", costUsd);
|
|
1257
|
+
if (details) recordUsageDetails(span, details);
|
|
1183
1258
|
}
|
|
1184
1259
|
|
|
1185
1260
|
// src/utils/assert-client.ts
|
|
@@ -1352,9 +1427,11 @@ function createSendProxy(originalSend) {
|
|
|
1352
1427
|
);
|
|
1353
1428
|
};
|
|
1354
1429
|
}
|
|
1430
|
+
var PATCHED = /* @__PURE__ */ new WeakSet();
|
|
1355
1431
|
function patchBedrock(client) {
|
|
1356
1432
|
assertClient("patchBedrock", client);
|
|
1357
|
-
|
|
1433
|
+
if (PATCHED.has(client)) return client;
|
|
1434
|
+
const proxy = new Proxy(client, {
|
|
1358
1435
|
get(target, prop, receiver) {
|
|
1359
1436
|
const value = Reflect.get(target, prop, receiver);
|
|
1360
1437
|
if (prop === "send" && typeof value === "function") {
|
|
@@ -1363,6 +1440,8 @@ function patchBedrock(client) {
|
|
|
1363
1440
|
return value;
|
|
1364
1441
|
}
|
|
1365
1442
|
});
|
|
1443
|
+
PATCHED.add(proxy);
|
|
1444
|
+
return proxy;
|
|
1366
1445
|
}
|
|
1367
1446
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1368
1447
|
0 && (module.exports = {
|