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
|
@@ -20,6 +20,9 @@
|
|
|
20
20
|
* Returns a Proxy that intercepts chat and generate.
|
|
21
21
|
* The original client is NOT modified.
|
|
22
22
|
*
|
|
23
|
+
* Patching a proxy that this function returned gives back the same proxy, so the
|
|
24
|
+
* second patch adds no second span.
|
|
25
|
+
*
|
|
23
26
|
* @param client - An Ollama client instance
|
|
24
27
|
* @returns A proxied client with automatic tracing
|
|
25
28
|
*/
|
|
@@ -20,6 +20,9 @@
|
|
|
20
20
|
* Returns a Proxy that intercepts chat and generate.
|
|
21
21
|
* The original client is NOT modified.
|
|
22
22
|
*
|
|
23
|
+
* Patching a proxy that this function returned gives back the same proxy, so the
|
|
24
|
+
* second patch adds no second span.
|
|
25
|
+
*
|
|
23
26
|
* @param client - An Ollama client instance
|
|
24
27
|
* @returns A proxied client with automatic tracing
|
|
25
28
|
*/
|
|
@@ -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";
|
|
@@ -605,6 +650,8 @@ var HttpExporter = class {
|
|
|
605
650
|
_calls = /* @__PURE__ */ new Map();
|
|
606
651
|
/** The ack of each finished call, by its batch. Read once by `takeAck(spans)`. */
|
|
607
652
|
_acks = /* @__PURE__ */ new WeakMap();
|
|
653
|
+
/** The requests that each finished call sent, by its batch. Read once by `takeAttempts(spans)`. */
|
|
654
|
+
_requests = /* @__PURE__ */ new WeakMap();
|
|
608
655
|
/** The batch processor dropped span(s) from a full queue in the quota pause (S-1). */
|
|
609
656
|
noteQuotaDrop(count = 1) {
|
|
610
657
|
this._quota.addDrops(count);
|
|
@@ -656,6 +703,18 @@ var HttpExporter = class {
|
|
|
656
703
|
get attemptsPerExport() {
|
|
657
704
|
return this._maxRetries;
|
|
658
705
|
}
|
|
706
|
+
/**
|
|
707
|
+
* Returns the number of HTTP requests that the `export()` call for `spans` sent, and clears
|
|
708
|
+
* it. This is the number that was sent, not the most that the call may send
|
|
709
|
+
* (`attemptsPerExport`): a 401 or 403 stops the loop after one request, and an open circuit
|
|
710
|
+
* breaker sends none. Returns `null` when no call is on record for `spans`. The answer is
|
|
711
|
+
* kept per batch, as `takeAck` keeps the ack.
|
|
712
|
+
*/
|
|
713
|
+
takeAttempts(spans) {
|
|
714
|
+
const n = this._requests.get(spans) ?? null;
|
|
715
|
+
this._requests.delete(spans);
|
|
716
|
+
return n;
|
|
717
|
+
}
|
|
659
718
|
/**
|
|
660
719
|
* Returns the counts of the ack that the `export()` call for `spans` received, and clears
|
|
661
720
|
* them. The answer is kept per batch, not on the instance: two processors that share this
|
|
@@ -700,13 +759,15 @@ var HttpExporter = class {
|
|
|
700
759
|
misroute: null,
|
|
701
760
|
noRetry: false,
|
|
702
761
|
status: null,
|
|
703
|
-
error: null
|
|
762
|
+
error: null,
|
|
763
|
+
attempts: 0
|
|
704
764
|
};
|
|
705
765
|
this._calls.set(spans, call);
|
|
706
766
|
try {
|
|
707
767
|
return await this._export(spans, call);
|
|
708
768
|
} finally {
|
|
709
769
|
this._calls.delete(spans);
|
|
770
|
+
this._requests.set(spans, this._endpointHasCredentials ? 0 : call.attempts);
|
|
710
771
|
}
|
|
711
772
|
}
|
|
712
773
|
async _export(spans, call) {
|
|
@@ -746,14 +807,13 @@ var HttpExporter = class {
|
|
|
746
807
|
isHalfOpen = true;
|
|
747
808
|
}
|
|
748
809
|
const maxAttempts = isHalfOpen ? 1 : this._maxRetries;
|
|
749
|
-
let attempts = 0;
|
|
750
810
|
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
751
811
|
call.refusalAfterMs = null;
|
|
752
812
|
call.misroute = null;
|
|
753
813
|
call.noRetry = false;
|
|
754
814
|
call.status = null;
|
|
755
815
|
call.error = null;
|
|
756
|
-
attempts++;
|
|
816
|
+
call.attempts++;
|
|
757
817
|
const result = await this._sendRequest(payload, parts.length, call, spans);
|
|
758
818
|
if (cancelled.aborted) {
|
|
759
819
|
this._acks.delete(spans);
|
|
@@ -775,7 +835,7 @@ var HttpExporter = class {
|
|
|
775
835
|
}
|
|
776
836
|
if (call.refusalAfterMs !== null) {
|
|
777
837
|
warn(
|
|
778
|
-
`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.`
|
|
838
|
+
`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.`
|
|
779
839
|
);
|
|
780
840
|
return "failure" /* FAILURE */;
|
|
781
841
|
}
|
|
@@ -1046,7 +1106,7 @@ function className(error) {
|
|
|
1046
1106
|
}
|
|
1047
1107
|
return typeof error;
|
|
1048
1108
|
}
|
|
1049
|
-
function responseReadFailed(provider, site, error, span) {
|
|
1109
|
+
function responseReadFailed(provider, site, error, span, part = "response") {
|
|
1050
1110
|
try {
|
|
1051
1111
|
const cls = className(error);
|
|
1052
1112
|
span?.setAttribute("risicare.observer_error", cls);
|
|
@@ -1054,7 +1114,7 @@ function responseReadFailed(provider, site, error, span) {
|
|
|
1054
1114
|
const key = `${provider}\0${site}\0${cls}`;
|
|
1055
1115
|
if (logged.has(key) || logged.size >= LOGGED_MAX) return;
|
|
1056
1116
|
logged.add(key);
|
|
1057
|
-
debug(`could not read the ${provider}
|
|
1117
|
+
debug(`could not read the ${provider} ${part} in ${site} (${cls}); the span keeps fewer facts`);
|
|
1058
1118
|
} catch {
|
|
1059
1119
|
}
|
|
1060
1120
|
}
|
|
@@ -1809,7 +1869,21 @@ function calculateCost(model, promptTokens, completionTokens) {
|
|
|
1809
1869
|
function tokenCount(value) {
|
|
1810
1870
|
return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : void 0;
|
|
1811
1871
|
}
|
|
1812
|
-
|
|
1872
|
+
var CACHE_READ_TOKENS_KEY = "gen_ai.usage.cache_read.input_tokens";
|
|
1873
|
+
var CACHE_WRITE_TOKENS_KEY = "gen_ai.usage.cache_write.input_tokens";
|
|
1874
|
+
var REASONING_TOKENS_KEY = "gen_ai.usage.reasoning.output_tokens";
|
|
1875
|
+
function providerInteger(value) {
|
|
1876
|
+
return typeof value === "number" && Number.isInteger(value) && value >= 0 ? value : void 0;
|
|
1877
|
+
}
|
|
1878
|
+
function recordUsageDetails(span, details) {
|
|
1879
|
+
const cacheRead = providerInteger(details.cacheRead);
|
|
1880
|
+
const cacheWrite = providerInteger(details.cacheWrite);
|
|
1881
|
+
const reasoning = providerInteger(details.reasoning);
|
|
1882
|
+
if (cacheRead !== void 0) span.setAttribute(CACHE_READ_TOKENS_KEY, cacheRead);
|
|
1883
|
+
if (cacheWrite !== void 0) span.setAttribute(CACHE_WRITE_TOKENS_KEY, cacheWrite);
|
|
1884
|
+
if (reasoning !== void 0) span.setAttribute(REASONING_TOKENS_KEY, reasoning);
|
|
1885
|
+
}
|
|
1886
|
+
function recordTokenUsage(span, counts, model, details) {
|
|
1813
1887
|
const promptTokens = tokenCount(counts.prompt);
|
|
1814
1888
|
const completionTokens = tokenCount(counts.completion);
|
|
1815
1889
|
const bothKnown = promptTokens !== void 0 && completionTokens !== void 0;
|
|
@@ -1820,6 +1894,7 @@ function recordTokenUsage(span, counts, model) {
|
|
|
1820
1894
|
if (completionTokens !== void 0) span.setAttribute("gen_ai.usage.completion_tokens", completionTokens);
|
|
1821
1895
|
if (totalTokens !== void 0) span.setAttribute("gen_ai.usage.total_tokens", totalTokens);
|
|
1822
1896
|
if (costUsd !== void 0) span.setAttribute("llm.cost.total_usd", costUsd);
|
|
1897
|
+
if (details) recordUsageDetails(span, details);
|
|
1823
1898
|
}
|
|
1824
1899
|
|
|
1825
1900
|
// src/utils/assert-client.ts
|
|
@@ -2000,9 +2075,11 @@ function createGenerateProxy(originalGenerate) {
|
|
|
2000
2075
|
);
|
|
2001
2076
|
};
|
|
2002
2077
|
}
|
|
2078
|
+
var PATCHED = /* @__PURE__ */ new WeakSet();
|
|
2003
2079
|
function patchOllama(client) {
|
|
2004
2080
|
assertClient("patchOllama", client);
|
|
2005
|
-
|
|
2081
|
+
if (PATCHED.has(client)) return client;
|
|
2082
|
+
const proxy = new Proxy(client, {
|
|
2006
2083
|
get(target, prop, receiver) {
|
|
2007
2084
|
const value = Reflect.get(target, prop, receiver);
|
|
2008
2085
|
if (prop === "chat" && typeof value === "function") {
|
|
@@ -2014,6 +2091,8 @@ function patchOllama(client) {
|
|
|
2014
2091
|
return value;
|
|
2015
2092
|
}
|
|
2016
2093
|
});
|
|
2094
|
+
PATCHED.add(proxy);
|
|
2095
|
+
return proxy;
|
|
2017
2096
|
}
|
|
2018
2097
|
export {
|
|
2019
2098
|
patchOllama
|