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
|
@@ -41,6 +41,9 @@ declare function deriveModelFamily(modelId: string): string;
|
|
|
41
41
|
* Non-AI commands (ListFoundationModels, etc.) pass through unmodified.
|
|
42
42
|
* The original client is NOT modified.
|
|
43
43
|
*
|
|
44
|
+
* Patching a proxy that this function returned gives back the same proxy, so the
|
|
45
|
+
* second patch adds no second span.
|
|
46
|
+
*
|
|
44
47
|
* @param client - A BedrockRuntimeClient instance
|
|
45
48
|
* @returns A proxied client with automatic tracing
|
|
46
49
|
*/
|
|
@@ -41,6 +41,9 @@ declare function deriveModelFamily(modelId: string): string;
|
|
|
41
41
|
* Non-AI commands (ListFoundationModels, etc.) pass through unmodified.
|
|
42
42
|
* The original client is NOT modified.
|
|
43
43
|
*
|
|
44
|
+
* Patching a proxy that this function returned gives back the same proxy, so the
|
|
45
|
+
* second patch adds no second span.
|
|
46
|
+
*
|
|
44
47
|
* @param client - A BedrockRuntimeClient instance
|
|
45
48
|
* @returns A proxied client with automatic tracing
|
|
46
49
|
*/
|
|
@@ -101,6 +101,51 @@ function hasCredentials(url) {
|
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
+
// src/masking.ts
|
|
105
|
+
var CONTENT_IN_JSON_OBJECT = /* @__PURE__ */ new Map([
|
|
106
|
+
[
|
|
107
|
+
"llm.invocation_parameters",
|
|
108
|
+
/* @__PURE__ */ new Set([
|
|
109
|
+
"additionalinstructions",
|
|
110
|
+
// OpenAI assistants run
|
|
111
|
+
"chathistory",
|
|
112
|
+
// Cohere
|
|
113
|
+
"contents",
|
|
114
|
+
// Gemini
|
|
115
|
+
"documents",
|
|
116
|
+
// Cohere RAG
|
|
117
|
+
"functions",
|
|
118
|
+
"input",
|
|
119
|
+
"inputtext",
|
|
120
|
+
// Bedrock Titan
|
|
121
|
+
"instructions",
|
|
122
|
+
"message",
|
|
123
|
+
// Cohere
|
|
124
|
+
"messages",
|
|
125
|
+
"preamble",
|
|
126
|
+
// Cohere
|
|
127
|
+
"prediction",
|
|
128
|
+
// OpenAI predicted output
|
|
129
|
+
"prompt",
|
|
130
|
+
"system",
|
|
131
|
+
// Anthropic
|
|
132
|
+
"systeminstruction",
|
|
133
|
+
// Gemini
|
|
134
|
+
"texts",
|
|
135
|
+
// Cohere embed
|
|
136
|
+
"toolconfig",
|
|
137
|
+
// Gemini
|
|
138
|
+
"tools"
|
|
139
|
+
])
|
|
140
|
+
]
|
|
141
|
+
]);
|
|
142
|
+
var VALUE_RULE_PREFIXES = new Set(
|
|
143
|
+
[...CONTENT_IN_JSON_OBJECT.keys()].flatMap((key) => {
|
|
144
|
+
const segments = key.split(".");
|
|
145
|
+
return segments.slice(1).map((_, i) => segments.slice(0, i + 1).join("."));
|
|
146
|
+
})
|
|
147
|
+
);
|
|
148
|
+
|
|
104
149
|
// src/exporters/batch.ts
|
|
105
150
|
var MAX_TIMEOUT_MS = 2 ** 31 - 1;
|
|
106
151
|
var MAX_BATCH_BYTES = 8 * 1024 * 1024;
|
|
@@ -245,7 +290,7 @@ function getContext() {
|
|
|
245
290
|
}
|
|
246
291
|
|
|
247
292
|
// src/version.ts
|
|
248
|
-
var SDK_VERSION = "0.
|
|
293
|
+
var SDK_VERSION = "0.10.0";
|
|
249
294
|
|
|
250
295
|
// src/exporters/quota.ts
|
|
251
296
|
var QUOTA_REASON = "monthly_quota_exceeded";
|
|
@@ -390,6 +435,8 @@ var HttpExporter = class {
|
|
|
390
435
|
_calls = /* @__PURE__ */ new Map();
|
|
391
436
|
/** The ack of each finished call, by its batch. Read once by `takeAck(spans)`. */
|
|
392
437
|
_acks = /* @__PURE__ */ new WeakMap();
|
|
438
|
+
/** The requests that each finished call sent, by its batch. Read once by `takeAttempts(spans)`. */
|
|
439
|
+
_requests = /* @__PURE__ */ new WeakMap();
|
|
393
440
|
/** The batch processor dropped span(s) from a full queue in the quota pause (S-1). */
|
|
394
441
|
noteQuotaDrop(count = 1) {
|
|
395
442
|
this._quota.addDrops(count);
|
|
@@ -441,6 +488,18 @@ var HttpExporter = class {
|
|
|
441
488
|
get attemptsPerExport() {
|
|
442
489
|
return this._maxRetries;
|
|
443
490
|
}
|
|
491
|
+
/**
|
|
492
|
+
* Returns the number of HTTP requests that the `export()` call for `spans` sent, and clears
|
|
493
|
+
* it. This is the number that was sent, not the most that the call may send
|
|
494
|
+
* (`attemptsPerExport`): a 401 or 403 stops the loop after one request, and an open circuit
|
|
495
|
+
* breaker sends none. Returns `null` when no call is on record for `spans`. The answer is
|
|
496
|
+
* kept per batch, as `takeAck` keeps the ack.
|
|
497
|
+
*/
|
|
498
|
+
takeAttempts(spans) {
|
|
499
|
+
const n = this._requests.get(spans) ?? null;
|
|
500
|
+
this._requests.delete(spans);
|
|
501
|
+
return n;
|
|
502
|
+
}
|
|
444
503
|
/**
|
|
445
504
|
* Returns the counts of the ack that the `export()` call for `spans` received, and clears
|
|
446
505
|
* them. The answer is kept per batch, not on the instance: two processors that share this
|
|
@@ -485,13 +544,15 @@ var HttpExporter = class {
|
|
|
485
544
|
misroute: null,
|
|
486
545
|
noRetry: false,
|
|
487
546
|
status: null,
|
|
488
|
-
error: null
|
|
547
|
+
error: null,
|
|
548
|
+
attempts: 0
|
|
489
549
|
};
|
|
490
550
|
this._calls.set(spans, call);
|
|
491
551
|
try {
|
|
492
552
|
return await this._export(spans, call);
|
|
493
553
|
} finally {
|
|
494
554
|
this._calls.delete(spans);
|
|
555
|
+
this._requests.set(spans, this._endpointHasCredentials ? 0 : call.attempts);
|
|
495
556
|
}
|
|
496
557
|
}
|
|
497
558
|
async _export(spans, call) {
|
|
@@ -531,14 +592,13 @@ var HttpExporter = class {
|
|
|
531
592
|
isHalfOpen = true;
|
|
532
593
|
}
|
|
533
594
|
const maxAttempts = isHalfOpen ? 1 : this._maxRetries;
|
|
534
|
-
let attempts = 0;
|
|
535
595
|
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
536
596
|
call.refusalAfterMs = null;
|
|
537
597
|
call.misroute = null;
|
|
538
598
|
call.noRetry = false;
|
|
539
599
|
call.status = null;
|
|
540
600
|
call.error = null;
|
|
541
|
-
attempts++;
|
|
601
|
+
call.attempts++;
|
|
542
602
|
const result = await this._sendRequest(payload, parts.length, call, spans);
|
|
543
603
|
if (cancelled.aborted) {
|
|
544
604
|
this._acks.delete(spans);
|
|
@@ -560,7 +620,7 @@ var HttpExporter = class {
|
|
|
560
620
|
}
|
|
561
621
|
if (call.refusalAfterMs !== null) {
|
|
562
622
|
warn(
|
|
563
|
-
`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.`
|
|
623
|
+
`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.`
|
|
564
624
|
);
|
|
565
625
|
return "failure" /* FAILURE */;
|
|
566
626
|
}
|
|
@@ -831,7 +891,7 @@ function className(error) {
|
|
|
831
891
|
}
|
|
832
892
|
return typeof error;
|
|
833
893
|
}
|
|
834
|
-
function responseReadFailed(provider, site, error, span) {
|
|
894
|
+
function responseReadFailed(provider, site, error, span, part = "response") {
|
|
835
895
|
try {
|
|
836
896
|
const cls = className(error);
|
|
837
897
|
span?.setAttribute("risicare.observer_error", cls);
|
|
@@ -839,7 +899,7 @@ function responseReadFailed(provider, site, error, span) {
|
|
|
839
899
|
const key = `${provider}\0${site}\0${cls}`;
|
|
840
900
|
if (logged.has(key) || logged.size >= LOGGED_MAX) return;
|
|
841
901
|
logged.add(key);
|
|
842
|
-
debug(`could not read the ${provider}
|
|
902
|
+
debug(`could not read the ${provider} ${part} in ${site} (${cls}); the span keeps fewer facts`);
|
|
843
903
|
} catch {
|
|
844
904
|
}
|
|
845
905
|
}
|
|
@@ -1132,7 +1192,21 @@ function calculateCost(model, promptTokens, completionTokens) {
|
|
|
1132
1192
|
function tokenCount(value) {
|
|
1133
1193
|
return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : void 0;
|
|
1134
1194
|
}
|
|
1135
|
-
|
|
1195
|
+
var CACHE_READ_TOKENS_KEY = "gen_ai.usage.cache_read.input_tokens";
|
|
1196
|
+
var CACHE_WRITE_TOKENS_KEY = "gen_ai.usage.cache_write.input_tokens";
|
|
1197
|
+
var REASONING_TOKENS_KEY = "gen_ai.usage.reasoning.output_tokens";
|
|
1198
|
+
function providerInteger(value) {
|
|
1199
|
+
return typeof value === "number" && Number.isInteger(value) && value >= 0 ? value : void 0;
|
|
1200
|
+
}
|
|
1201
|
+
function recordUsageDetails(span, details) {
|
|
1202
|
+
const cacheRead = providerInteger(details.cacheRead);
|
|
1203
|
+
const cacheWrite = providerInteger(details.cacheWrite);
|
|
1204
|
+
const reasoning = providerInteger(details.reasoning);
|
|
1205
|
+
if (cacheRead !== void 0) span.setAttribute(CACHE_READ_TOKENS_KEY, cacheRead);
|
|
1206
|
+
if (cacheWrite !== void 0) span.setAttribute(CACHE_WRITE_TOKENS_KEY, cacheWrite);
|
|
1207
|
+
if (reasoning !== void 0) span.setAttribute(REASONING_TOKENS_KEY, reasoning);
|
|
1208
|
+
}
|
|
1209
|
+
function recordTokenUsage(span, counts, model, details) {
|
|
1136
1210
|
const promptTokens = tokenCount(counts.prompt);
|
|
1137
1211
|
const completionTokens = tokenCount(counts.completion);
|
|
1138
1212
|
const bothKnown = promptTokens !== void 0 && completionTokens !== void 0;
|
|
@@ -1143,6 +1217,7 @@ function recordTokenUsage(span, counts, model) {
|
|
|
1143
1217
|
if (completionTokens !== void 0) span.setAttribute("gen_ai.usage.completion_tokens", completionTokens);
|
|
1144
1218
|
if (totalTokens !== void 0) span.setAttribute("gen_ai.usage.total_tokens", totalTokens);
|
|
1145
1219
|
if (costUsd !== void 0) span.setAttribute("llm.cost.total_usd", costUsd);
|
|
1220
|
+
if (details) recordUsageDetails(span, details);
|
|
1146
1221
|
}
|
|
1147
1222
|
|
|
1148
1223
|
// src/utils/assert-client.ts
|
|
@@ -1315,9 +1390,11 @@ function createSendProxy(originalSend) {
|
|
|
1315
1390
|
);
|
|
1316
1391
|
};
|
|
1317
1392
|
}
|
|
1393
|
+
var PATCHED = /* @__PURE__ */ new WeakSet();
|
|
1318
1394
|
function patchBedrock(client) {
|
|
1319
1395
|
assertClient("patchBedrock", client);
|
|
1320
|
-
|
|
1396
|
+
if (PATCHED.has(client)) return client;
|
|
1397
|
+
const proxy = new Proxy(client, {
|
|
1321
1398
|
get(target, prop, receiver) {
|
|
1322
1399
|
const value = Reflect.get(target, prop, receiver);
|
|
1323
1400
|
if (prop === "send" && typeof value === "function") {
|
|
@@ -1326,6 +1403,8 @@ function patchBedrock(client) {
|
|
|
1326
1403
|
return value;
|
|
1327
1404
|
}
|
|
1328
1405
|
});
|
|
1406
|
+
PATCHED.add(proxy);
|
|
1407
|
+
return proxy;
|
|
1329
1408
|
}
|
|
1330
1409
|
export {
|
|
1331
1410
|
deriveModelFamily,
|