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
|
@@ -124,6 +124,51 @@ function hasCredentials(url) {
|
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
+
// src/masking.ts
|
|
128
|
+
var CONTENT_IN_JSON_OBJECT = /* @__PURE__ */ new Map([
|
|
129
|
+
[
|
|
130
|
+
"llm.invocation_parameters",
|
|
131
|
+
/* @__PURE__ */ new Set([
|
|
132
|
+
"additionalinstructions",
|
|
133
|
+
// OpenAI assistants run
|
|
134
|
+
"chathistory",
|
|
135
|
+
// Cohere
|
|
136
|
+
"contents",
|
|
137
|
+
// Gemini
|
|
138
|
+
"documents",
|
|
139
|
+
// Cohere RAG
|
|
140
|
+
"functions",
|
|
141
|
+
"input",
|
|
142
|
+
"inputtext",
|
|
143
|
+
// Bedrock Titan
|
|
144
|
+
"instructions",
|
|
145
|
+
"message",
|
|
146
|
+
// Cohere
|
|
147
|
+
"messages",
|
|
148
|
+
"preamble",
|
|
149
|
+
// Cohere
|
|
150
|
+
"prediction",
|
|
151
|
+
// OpenAI predicted output
|
|
152
|
+
"prompt",
|
|
153
|
+
"system",
|
|
154
|
+
// Anthropic
|
|
155
|
+
"systeminstruction",
|
|
156
|
+
// Gemini
|
|
157
|
+
"texts",
|
|
158
|
+
// Cohere embed
|
|
159
|
+
"toolconfig",
|
|
160
|
+
// Gemini
|
|
161
|
+
"tools"
|
|
162
|
+
])
|
|
163
|
+
]
|
|
164
|
+
]);
|
|
165
|
+
var VALUE_RULE_PREFIXES = new Set(
|
|
166
|
+
[...CONTENT_IN_JSON_OBJECT.keys()].flatMap((key) => {
|
|
167
|
+
const segments = key.split(".");
|
|
168
|
+
return segments.slice(1).map((_, i) => segments.slice(0, i + 1).join("."));
|
|
169
|
+
})
|
|
170
|
+
);
|
|
171
|
+
|
|
127
172
|
// src/exporters/batch.ts
|
|
128
173
|
var MAX_TIMEOUT_MS = 2 ** 31 - 1;
|
|
129
174
|
var MAX_BATCH_BYTES = 8 * 1024 * 1024;
|
|
@@ -460,7 +505,7 @@ function attachErrorCode(span, error) {
|
|
|
460
505
|
}
|
|
461
506
|
|
|
462
507
|
// src/version.ts
|
|
463
|
-
var SDK_VERSION = "0.
|
|
508
|
+
var SDK_VERSION = "0.10.0";
|
|
464
509
|
|
|
465
510
|
// src/exporters/quota.ts
|
|
466
511
|
var QUOTA_REASON = "monthly_quota_exceeded";
|
|
@@ -1061,7 +1106,7 @@ function className(error) {
|
|
|
1061
1106
|
}
|
|
1062
1107
|
return typeof error;
|
|
1063
1108
|
}
|
|
1064
|
-
function responseReadFailed(provider, site, error, span) {
|
|
1109
|
+
function responseReadFailed(provider, site, error, span, part = "response") {
|
|
1065
1110
|
try {
|
|
1066
1111
|
const cls = className(error);
|
|
1067
1112
|
span?.setAttribute("risicare.observer_error", cls);
|
|
@@ -1069,7 +1114,7 @@ function responseReadFailed(provider, site, error, span) {
|
|
|
1069
1114
|
const key = `${provider}\0${site}\0${cls}`;
|
|
1070
1115
|
if (logged.has(key) || logged.size >= LOGGED_MAX) return;
|
|
1071
1116
|
logged.add(key);
|
|
1072
|
-
debug(`could not read the ${provider}
|
|
1117
|
+
debug(`could not read the ${provider} ${part} in ${site} (${cls}); the span keeps fewer facts`);
|
|
1073
1118
|
} catch {
|
|
1074
1119
|
}
|
|
1075
1120
|
}
|
|
@@ -1080,6 +1125,13 @@ function readResponseSafely(provider, site, span, read) {
|
|
|
1080
1125
|
responseReadFailed(provider, site, error, span);
|
|
1081
1126
|
}
|
|
1082
1127
|
}
|
|
1128
|
+
function readRequestSafely(provider, site, span, read) {
|
|
1129
|
+
try {
|
|
1130
|
+
read();
|
|
1131
|
+
} catch (error) {
|
|
1132
|
+
responseReadFailed(provider, site, error, span, "request");
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
1083
1135
|
|
|
1084
1136
|
// src/utils/stream-proxy.ts
|
|
1085
1137
|
var HANDOFF = /* @__PURE__ */ new Set(["tee", "toReadableStream", "getReader", "pipeTo", "pipeThrough"]);
|
|
@@ -1824,7 +1876,39 @@ function calculateCost(model, promptTokens, completionTokens) {
|
|
|
1824
1876
|
function tokenCount(value) {
|
|
1825
1877
|
return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : void 0;
|
|
1826
1878
|
}
|
|
1827
|
-
|
|
1879
|
+
var CACHE_READ_TOKENS_KEY = "gen_ai.usage.cache_read.input_tokens";
|
|
1880
|
+
var CACHE_WRITE_TOKENS_KEY = "gen_ai.usage.cache_write.input_tokens";
|
|
1881
|
+
var REASONING_TOKENS_KEY = "gen_ai.usage.reasoning.output_tokens";
|
|
1882
|
+
function providerInteger(value) {
|
|
1883
|
+
return typeof value === "number" && Number.isInteger(value) && value >= 0 ? value : void 0;
|
|
1884
|
+
}
|
|
1885
|
+
function nested(obj, outer, inner) {
|
|
1886
|
+
if (!obj || typeof obj !== "object") return void 0;
|
|
1887
|
+
const details = obj[outer];
|
|
1888
|
+
if (!details || typeof details !== "object") return void 0;
|
|
1889
|
+
return details[inner];
|
|
1890
|
+
}
|
|
1891
|
+
function anthropicUsageDetails(usage) {
|
|
1892
|
+
try {
|
|
1893
|
+
const u = usage && typeof usage === "object" ? usage : {};
|
|
1894
|
+
return {
|
|
1895
|
+
cacheRead: u.cache_read_input_tokens,
|
|
1896
|
+
cacheWrite: u.cache_creation_input_tokens,
|
|
1897
|
+
reasoning: nested(usage, "output_tokens_details", "thinking_tokens")
|
|
1898
|
+
};
|
|
1899
|
+
} catch {
|
|
1900
|
+
return {};
|
|
1901
|
+
}
|
|
1902
|
+
}
|
|
1903
|
+
function recordUsageDetails(span, details) {
|
|
1904
|
+
const cacheRead = providerInteger(details.cacheRead);
|
|
1905
|
+
const cacheWrite = providerInteger(details.cacheWrite);
|
|
1906
|
+
const reasoning = providerInteger(details.reasoning);
|
|
1907
|
+
if (cacheRead !== void 0) span.setAttribute(CACHE_READ_TOKENS_KEY, cacheRead);
|
|
1908
|
+
if (cacheWrite !== void 0) span.setAttribute(CACHE_WRITE_TOKENS_KEY, cacheWrite);
|
|
1909
|
+
if (reasoning !== void 0) span.setAttribute(REASONING_TOKENS_KEY, reasoning);
|
|
1910
|
+
}
|
|
1911
|
+
function recordTokenUsage(span, counts, model, details) {
|
|
1828
1912
|
const promptTokens = tokenCount(counts.prompt);
|
|
1829
1913
|
const completionTokens = tokenCount(counts.completion);
|
|
1830
1914
|
const bothKnown = promptTokens !== void 0 && completionTokens !== void 0;
|
|
@@ -1835,6 +1919,7 @@ function recordTokenUsage(span, counts, model) {
|
|
|
1835
1919
|
if (completionTokens !== void 0) span.setAttribute("gen_ai.usage.completion_tokens", completionTokens);
|
|
1836
1920
|
if (totalTokens !== void 0) span.setAttribute("gen_ai.usage.total_tokens", totalTokens);
|
|
1837
1921
|
if (costUsd !== void 0) span.setAttribute("llm.cost.total_usd", costUsd);
|
|
1922
|
+
if (details) recordUsageDetails(span, details);
|
|
1838
1923
|
}
|
|
1839
1924
|
|
|
1840
1925
|
// src/utils/assert-client.ts
|
|
@@ -1921,7 +2006,7 @@ function enrichSpanFromResponse(span, response) {
|
|
|
1921
2006
|
span.setAttribute("gen_ai.response.finish_reasons", [stopReason]);
|
|
1922
2007
|
}
|
|
1923
2008
|
if (usage) {
|
|
1924
|
-
recordTokenUsage(span, { prompt: usage.input_tokens, completion: usage.output_tokens }, model);
|
|
2009
|
+
recordTokenUsage(span, { prompt: usage.input_tokens, completion: usage.output_tokens }, model, anthropicUsageDetails(usage));
|
|
1925
2010
|
}
|
|
1926
2011
|
}
|
|
1927
2012
|
function createMessagesProxy(originalCreate) {
|
|
@@ -1949,9 +2034,23 @@ function createMessagesProxy(originalCreate) {
|
|
|
1949
2034
|
const traceContent = tracer.traceContent;
|
|
1950
2035
|
if (traceContent) {
|
|
1951
2036
|
captureSystemPrompt(span, params.system);
|
|
1952
|
-
|
|
2037
|
+
readRequestSafely(
|
|
2038
|
+
"anthropic",
|
|
2039
|
+
"capturePromptMessages",
|
|
2040
|
+
span,
|
|
2041
|
+
() => capturePromptMessages(span, params.messages, true)
|
|
2042
|
+
);
|
|
1953
2043
|
}
|
|
1954
2044
|
const streamed = {};
|
|
2045
|
+
const noteDetails = (u) => {
|
|
2046
|
+
const d = anthropicUsageDetails(u);
|
|
2047
|
+
const cacheRead = providerInteger(d.cacheRead);
|
|
2048
|
+
const cacheWrite = providerInteger(d.cacheWrite);
|
|
2049
|
+
const reasoning = providerInteger(d.reasoning);
|
|
2050
|
+
if (cacheRead !== void 0) streamed.cacheRead = cacheRead;
|
|
2051
|
+
if (cacheWrite !== void 0) streamed.cacheWrite = cacheWrite;
|
|
2052
|
+
if (reasoning !== void 0) streamed.reasoning = reasoning;
|
|
2053
|
+
};
|
|
1955
2054
|
return observeProviderCall(
|
|
1956
2055
|
span,
|
|
1957
2056
|
{
|
|
@@ -1972,19 +2071,29 @@ function createMessagesProxy(originalCreate) {
|
|
|
1972
2071
|
streamed.id = e.message.id;
|
|
1973
2072
|
const u = e.message.usage;
|
|
1974
2073
|
if (typeof u?.input_tokens === "number") streamed.input = u.input_tokens;
|
|
2074
|
+
noteDetails(u);
|
|
1975
2075
|
} else if (e?.type === "message_delta") {
|
|
1976
2076
|
if (e.delta?.stop_reason) streamed.stop_reason = e.delta.stop_reason;
|
|
1977
2077
|
if (typeof e.usage?.output_tokens === "number") streamed.output = e.usage.output_tokens;
|
|
2078
|
+
noteDetails(e.usage);
|
|
1978
2079
|
}
|
|
1979
2080
|
},
|
|
1980
2081
|
beforeEnd: () => {
|
|
1981
|
-
if (streamed.model === void 0 && streamed.input === void 0 && streamed.output === void 0)
|
|
2082
|
+
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) {
|
|
2083
|
+
return;
|
|
2084
|
+
}
|
|
1982
2085
|
enrichSpanFromResponse(span, {
|
|
1983
2086
|
model: streamed.model,
|
|
1984
2087
|
id: streamed.id,
|
|
1985
2088
|
stop_reason: streamed.stop_reason,
|
|
1986
2089
|
// A count the stream did not give stays unknown (token-usage.ts).
|
|
1987
|
-
usage: {
|
|
2090
|
+
usage: {
|
|
2091
|
+
input_tokens: streamed.input,
|
|
2092
|
+
output_tokens: streamed.output,
|
|
2093
|
+
cache_read_input_tokens: streamed.cacheRead,
|
|
2094
|
+
cache_creation_input_tokens: streamed.cacheWrite,
|
|
2095
|
+
output_tokens_details: streamed.reasoning === void 0 ? void 0 : { thinking_tokens: streamed.reasoning }
|
|
2096
|
+
}
|
|
1988
2097
|
});
|
|
1989
2098
|
}
|
|
1990
2099
|
},
|