risicare 0.9.2 → 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 +183 -0
- package/README.md +37 -19
- package/dist/frameworks/instructor.cjs +46 -1
- package/dist/frameworks/instructor.cjs.map +1 -1
- package/dist/frameworks/instructor.js +46 -1
- package/dist/frameworks/instructor.js.map +1 -1
- package/dist/frameworks/langchain.cjs +46 -1
- package/dist/frameworks/langchain.cjs.map +1 -1
- package/dist/frameworks/langchain.js +46 -1
- package/dist/frameworks/langchain.js.map +1 -1
- package/dist/frameworks/langgraph.cjs +46 -1
- package/dist/frameworks/langgraph.cjs.map +1 -1
- package/dist/frameworks/langgraph.js +46 -1
- package/dist/frameworks/langgraph.js.map +1 -1
- package/dist/frameworks/llamaindex.cjs +46 -1
- package/dist/frameworks/llamaindex.cjs.map +1 -1
- package/dist/frameworks/llamaindex.js +46 -1
- package/dist/frameworks/llamaindex.js.map +1 -1
- package/dist/index.cjs +329 -15
- 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 +329 -15
- package/dist/index.js.map +1 -1
- package/dist/providers/anthropic/index.cjs +117 -8
- package/dist/providers/anthropic/index.cjs.map +1 -1
- package/dist/providers/anthropic/index.js +117 -8
- package/dist/providers/anthropic/index.js.map +1 -1
- package/dist/providers/bedrock/index.cjs +64 -4
- package/dist/providers/bedrock/index.cjs.map +1 -1
- package/dist/providers/bedrock/index.js +64 -4
- package/dist/providers/bedrock/index.js.map +1 -1
- package/dist/providers/cerebras/index.cjs +64 -4
- package/dist/providers/cerebras/index.cjs.map +1 -1
- package/dist/providers/cerebras/index.js +64 -4
- package/dist/providers/cerebras/index.js.map +1 -1
- package/dist/providers/cohere/index.cjs +64 -4
- package/dist/providers/cohere/index.cjs.map +1 -1
- package/dist/providers/cohere/index.js +64 -4
- package/dist/providers/cohere/index.js.map +1 -1
- package/dist/providers/google/index.cjs +64 -4
- package/dist/providers/google/index.cjs.map +1 -1
- package/dist/providers/google/index.js +64 -4
- package/dist/providers/google/index.js.map +1 -1
- package/dist/providers/groq/index.cjs +64 -4
- package/dist/providers/groq/index.cjs.map +1 -1
- package/dist/providers/groq/index.js +64 -4
- package/dist/providers/groq/index.js.map +1 -1
- package/dist/providers/huggingface/index.cjs +64 -4
- package/dist/providers/huggingface/index.cjs.map +1 -1
- package/dist/providers/huggingface/index.js +64 -4
- package/dist/providers/huggingface/index.js.map +1 -1
- package/dist/providers/mistral/index.cjs +64 -4
- package/dist/providers/mistral/index.cjs.map +1 -1
- package/dist/providers/mistral/index.js +64 -4
- package/dist/providers/mistral/index.js.map +1 -1
- package/dist/providers/ollama/index.cjs +64 -4
- package/dist/providers/ollama/index.cjs.map +1 -1
- package/dist/providers/ollama/index.js +64 -4
- package/dist/providers/ollama/index.js.map +1 -1
- package/dist/providers/openai/index.cjs +102 -6
- package/dist/providers/openai/index.cjs.map +1 -1
- package/dist/providers/openai/index.js +102 -6
- package/dist/providers/openai/index.js.map +1 -1
- package/dist/providers/together/index.cjs +64 -4
- package/dist/providers/together/index.cjs.map +1 -1
- package/dist/providers/together/index.js +64 -4
- package/dist/providers/together/index.js.map +1 -1
- package/dist/providers/vercel-ai/index.cjs +48 -3
- package/dist/providers/vercel-ai/index.cjs.map +1 -1
- package/dist/providers/vercel-ai/index.js +48 -3
- package/dist/providers/vercel-ai/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -160,6 +160,51 @@ function hasCredentials(url) {
|
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
+
// src/masking.ts
|
|
164
|
+
var CONTENT_IN_JSON_OBJECT = /* @__PURE__ */ new Map([
|
|
165
|
+
[
|
|
166
|
+
"llm.invocation_parameters",
|
|
167
|
+
/* @__PURE__ */ new Set([
|
|
168
|
+
"additionalinstructions",
|
|
169
|
+
// OpenAI assistants run
|
|
170
|
+
"chathistory",
|
|
171
|
+
// Cohere
|
|
172
|
+
"contents",
|
|
173
|
+
// Gemini
|
|
174
|
+
"documents",
|
|
175
|
+
// Cohere RAG
|
|
176
|
+
"functions",
|
|
177
|
+
"input",
|
|
178
|
+
"inputtext",
|
|
179
|
+
// Bedrock Titan
|
|
180
|
+
"instructions",
|
|
181
|
+
"message",
|
|
182
|
+
// Cohere
|
|
183
|
+
"messages",
|
|
184
|
+
"preamble",
|
|
185
|
+
// Cohere
|
|
186
|
+
"prediction",
|
|
187
|
+
// OpenAI predicted output
|
|
188
|
+
"prompt",
|
|
189
|
+
"system",
|
|
190
|
+
// Anthropic
|
|
191
|
+
"systeminstruction",
|
|
192
|
+
// Gemini
|
|
193
|
+
"texts",
|
|
194
|
+
// Cohere embed
|
|
195
|
+
"toolconfig",
|
|
196
|
+
// Gemini
|
|
197
|
+
"tools"
|
|
198
|
+
])
|
|
199
|
+
]
|
|
200
|
+
]);
|
|
201
|
+
var VALUE_RULE_PREFIXES = new Set(
|
|
202
|
+
[...CONTENT_IN_JSON_OBJECT.keys()].flatMap((key) => {
|
|
203
|
+
const segments = key.split(".");
|
|
204
|
+
return segments.slice(1).map((_, i) => segments.slice(0, i + 1).join("."));
|
|
205
|
+
})
|
|
206
|
+
);
|
|
207
|
+
|
|
163
208
|
// src/exporters/batch.ts
|
|
164
209
|
var MAX_TIMEOUT_MS = 2 ** 31 - 1;
|
|
165
210
|
var MAX_BATCH_BYTES = 8 * 1024 * 1024;
|
|
@@ -496,7 +541,7 @@ function attachErrorCode(span, error) {
|
|
|
496
541
|
}
|
|
497
542
|
|
|
498
543
|
// src/version.ts
|
|
499
|
-
var SDK_VERSION = "0.
|
|
544
|
+
var SDK_VERSION = "0.10.0";
|
|
500
545
|
|
|
501
546
|
// src/exporters/quota.ts
|
|
502
547
|
var QUOTA_REASON = "monthly_quota_exceeded";
|
|
@@ -1097,7 +1142,7 @@ function className(error) {
|
|
|
1097
1142
|
}
|
|
1098
1143
|
return typeof error;
|
|
1099
1144
|
}
|
|
1100
|
-
function responseReadFailed(provider, site, error, span) {
|
|
1145
|
+
function responseReadFailed(provider, site, error, span, part = "response") {
|
|
1101
1146
|
try {
|
|
1102
1147
|
const cls = className(error);
|
|
1103
1148
|
span?.setAttribute("risicare.observer_error", cls);
|
|
@@ -1105,7 +1150,7 @@ function responseReadFailed(provider, site, error, span) {
|
|
|
1105
1150
|
const key = `${provider}\0${site}\0${cls}`;
|
|
1106
1151
|
if (logged.has(key) || logged.size >= LOGGED_MAX) return;
|
|
1107
1152
|
logged.add(key);
|
|
1108
|
-
debug(`could not read the ${provider}
|
|
1153
|
+
debug(`could not read the ${provider} ${part} in ${site} (${cls}); the span keeps fewer facts`);
|
|
1109
1154
|
} catch {
|
|
1110
1155
|
}
|
|
1111
1156
|
}
|
|
@@ -1116,6 +1161,13 @@ function readResponseSafely(provider, site, span, read) {
|
|
|
1116
1161
|
responseReadFailed(provider, site, error, span);
|
|
1117
1162
|
}
|
|
1118
1163
|
}
|
|
1164
|
+
function readRequestSafely(provider, site, span, read) {
|
|
1165
|
+
try {
|
|
1166
|
+
read();
|
|
1167
|
+
} catch (error) {
|
|
1168
|
+
responseReadFailed(provider, site, error, span, "request");
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1119
1171
|
|
|
1120
1172
|
// src/utils/stream-proxy.ts
|
|
1121
1173
|
var HANDOFF = /* @__PURE__ */ new Set(["tee", "toReadableStream", "getReader", "pipeTo", "pipeThrough"]);
|
|
@@ -1860,7 +1912,39 @@ function calculateCost(model, promptTokens, completionTokens) {
|
|
|
1860
1912
|
function tokenCount(value) {
|
|
1861
1913
|
return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : void 0;
|
|
1862
1914
|
}
|
|
1863
|
-
|
|
1915
|
+
var CACHE_READ_TOKENS_KEY = "gen_ai.usage.cache_read.input_tokens";
|
|
1916
|
+
var CACHE_WRITE_TOKENS_KEY = "gen_ai.usage.cache_write.input_tokens";
|
|
1917
|
+
var REASONING_TOKENS_KEY = "gen_ai.usage.reasoning.output_tokens";
|
|
1918
|
+
function providerInteger(value) {
|
|
1919
|
+
return typeof value === "number" && Number.isInteger(value) && value >= 0 ? value : void 0;
|
|
1920
|
+
}
|
|
1921
|
+
function nested(obj, outer, inner) {
|
|
1922
|
+
if (!obj || typeof obj !== "object") return void 0;
|
|
1923
|
+
const details = obj[outer];
|
|
1924
|
+
if (!details || typeof details !== "object") return void 0;
|
|
1925
|
+
return details[inner];
|
|
1926
|
+
}
|
|
1927
|
+
function anthropicUsageDetails(usage) {
|
|
1928
|
+
try {
|
|
1929
|
+
const u = usage && typeof usage === "object" ? usage : {};
|
|
1930
|
+
return {
|
|
1931
|
+
cacheRead: u.cache_read_input_tokens,
|
|
1932
|
+
cacheWrite: u.cache_creation_input_tokens,
|
|
1933
|
+
reasoning: nested(usage, "output_tokens_details", "thinking_tokens")
|
|
1934
|
+
};
|
|
1935
|
+
} catch {
|
|
1936
|
+
return {};
|
|
1937
|
+
}
|
|
1938
|
+
}
|
|
1939
|
+
function recordUsageDetails(span, details) {
|
|
1940
|
+
const cacheRead = providerInteger(details.cacheRead);
|
|
1941
|
+
const cacheWrite = providerInteger(details.cacheWrite);
|
|
1942
|
+
const reasoning = providerInteger(details.reasoning);
|
|
1943
|
+
if (cacheRead !== void 0) span.setAttribute(CACHE_READ_TOKENS_KEY, cacheRead);
|
|
1944
|
+
if (cacheWrite !== void 0) span.setAttribute(CACHE_WRITE_TOKENS_KEY, cacheWrite);
|
|
1945
|
+
if (reasoning !== void 0) span.setAttribute(REASONING_TOKENS_KEY, reasoning);
|
|
1946
|
+
}
|
|
1947
|
+
function recordTokenUsage(span, counts, model, details) {
|
|
1864
1948
|
const promptTokens = tokenCount(counts.prompt);
|
|
1865
1949
|
const completionTokens = tokenCount(counts.completion);
|
|
1866
1950
|
const bothKnown = promptTokens !== void 0 && completionTokens !== void 0;
|
|
@@ -1871,6 +1955,7 @@ function recordTokenUsage(span, counts, model) {
|
|
|
1871
1955
|
if (completionTokens !== void 0) span.setAttribute("gen_ai.usage.completion_tokens", completionTokens);
|
|
1872
1956
|
if (totalTokens !== void 0) span.setAttribute("gen_ai.usage.total_tokens", totalTokens);
|
|
1873
1957
|
if (costUsd !== void 0) span.setAttribute("llm.cost.total_usd", costUsd);
|
|
1958
|
+
if (details) recordUsageDetails(span, details);
|
|
1874
1959
|
}
|
|
1875
1960
|
|
|
1876
1961
|
// src/utils/assert-client.ts
|
|
@@ -1957,7 +2042,7 @@ function enrichSpanFromResponse(span, response) {
|
|
|
1957
2042
|
span.setAttribute("gen_ai.response.finish_reasons", [stopReason]);
|
|
1958
2043
|
}
|
|
1959
2044
|
if (usage) {
|
|
1960
|
-
recordTokenUsage(span, { prompt: usage.input_tokens, completion: usage.output_tokens }, model);
|
|
2045
|
+
recordTokenUsage(span, { prompt: usage.input_tokens, completion: usage.output_tokens }, model, anthropicUsageDetails(usage));
|
|
1961
2046
|
}
|
|
1962
2047
|
}
|
|
1963
2048
|
function createMessagesProxy(originalCreate) {
|
|
@@ -1985,9 +2070,23 @@ function createMessagesProxy(originalCreate) {
|
|
|
1985
2070
|
const traceContent = tracer.traceContent;
|
|
1986
2071
|
if (traceContent) {
|
|
1987
2072
|
captureSystemPrompt(span, params.system);
|
|
1988
|
-
|
|
2073
|
+
readRequestSafely(
|
|
2074
|
+
"anthropic",
|
|
2075
|
+
"capturePromptMessages",
|
|
2076
|
+
span,
|
|
2077
|
+
() => capturePromptMessages(span, params.messages, true)
|
|
2078
|
+
);
|
|
1989
2079
|
}
|
|
1990
2080
|
const streamed = {};
|
|
2081
|
+
const noteDetails = (u) => {
|
|
2082
|
+
const d = anthropicUsageDetails(u);
|
|
2083
|
+
const cacheRead = providerInteger(d.cacheRead);
|
|
2084
|
+
const cacheWrite = providerInteger(d.cacheWrite);
|
|
2085
|
+
const reasoning = providerInteger(d.reasoning);
|
|
2086
|
+
if (cacheRead !== void 0) streamed.cacheRead = cacheRead;
|
|
2087
|
+
if (cacheWrite !== void 0) streamed.cacheWrite = cacheWrite;
|
|
2088
|
+
if (reasoning !== void 0) streamed.reasoning = reasoning;
|
|
2089
|
+
};
|
|
1991
2090
|
return observeProviderCall(
|
|
1992
2091
|
span,
|
|
1993
2092
|
{
|
|
@@ -2008,19 +2107,29 @@ function createMessagesProxy(originalCreate) {
|
|
|
2008
2107
|
streamed.id = e.message.id;
|
|
2009
2108
|
const u = e.message.usage;
|
|
2010
2109
|
if (typeof u?.input_tokens === "number") streamed.input = u.input_tokens;
|
|
2110
|
+
noteDetails(u);
|
|
2011
2111
|
} else if (e?.type === "message_delta") {
|
|
2012
2112
|
if (e.delta?.stop_reason) streamed.stop_reason = e.delta.stop_reason;
|
|
2013
2113
|
if (typeof e.usage?.output_tokens === "number") streamed.output = e.usage.output_tokens;
|
|
2114
|
+
noteDetails(e.usage);
|
|
2014
2115
|
}
|
|
2015
2116
|
},
|
|
2016
2117
|
beforeEnd: () => {
|
|
2017
|
-
if (streamed.model === void 0 && streamed.input === void 0 && streamed.output === void 0)
|
|
2118
|
+
if (streamed.model === void 0 && streamed.input === void 0 && streamed.output === void 0 && streamed.cacheRead === void 0 && streamed.cacheWrite === void 0 && streamed.reasoning === void 0) {
|
|
2119
|
+
return;
|
|
2120
|
+
}
|
|
2018
2121
|
enrichSpanFromResponse(span, {
|
|
2019
2122
|
model: streamed.model,
|
|
2020
2123
|
id: streamed.id,
|
|
2021
2124
|
stop_reason: streamed.stop_reason,
|
|
2022
2125
|
// A count the stream did not give stays unknown (token-usage.ts).
|
|
2023
|
-
usage: {
|
|
2126
|
+
usage: {
|
|
2127
|
+
input_tokens: streamed.input,
|
|
2128
|
+
output_tokens: streamed.output,
|
|
2129
|
+
cache_read_input_tokens: streamed.cacheRead,
|
|
2130
|
+
cache_creation_input_tokens: streamed.cacheWrite,
|
|
2131
|
+
output_tokens_details: streamed.reasoning === void 0 ? void 0 : { thinking_tokens: streamed.reasoning }
|
|
2132
|
+
}
|
|
2024
2133
|
});
|
|
2025
2134
|
}
|
|
2026
2135
|
},
|