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
package/README.md
CHANGED
|
@@ -43,8 +43,10 @@ await shutdown();
|
|
|
43
43
|
```
|
|
44
44
|
|
|
45
45
|
The SDK sends one span for the agent function and one span for the LLM call,
|
|
46
|
-
in the same trace. The LLM span has the model, the latency, the token counts
|
|
47
|
-
|
|
46
|
+
in the same trace. The LLM span has the model, the latency, the token counts,
|
|
47
|
+
the cost and, by default, the prompt and completion text (see
|
|
48
|
+
[Prompt content is captured by default](#prompt-content-is-captured-by-default)).
|
|
49
|
+
You see them in the [Risicare dashboard](https://app.risicare.ai).
|
|
48
50
|
|
|
49
51
|
## Two hosts
|
|
50
52
|
|
|
@@ -99,21 +101,31 @@ import * as risicare from 'risicare';
|
|
|
99
101
|
import type { Span, Tracer } from 'risicare';
|
|
100
102
|
```
|
|
101
103
|
|
|
102
|
-
## Prompt content is
|
|
104
|
+
## Prompt content is captured by default
|
|
103
105
|
|
|
104
|
-
**`traceContent` defaults to `
|
|
105
|
-
|
|
106
|
-
errors, and any attributes you set — is captured
|
|
107
|
-
dashboard, cost tracking and error diagnosis all work
|
|
106
|
+
**`traceContent` defaults to `true`.** The SDK sends your prompts and
|
|
107
|
+
completions to Risicare, and Risicare stores them. Everything else — model,
|
|
108
|
+
token counts, latency, cost, errors, and any attributes you set — is captured
|
|
109
|
+
as normal, so the dashboard, cost tracking and error diagnosis all work.
|
|
108
110
|
|
|
109
|
-
To
|
|
111
|
+
To stop the capture of prompt and completion text, set it off in your code or
|
|
112
|
+
in the environment:
|
|
110
113
|
|
|
111
114
|
```typescript
|
|
112
|
-
init({ apiKey: 'rsk-...', traceContent:
|
|
113
|
-
// or set RISICARE_TRACE_CONTENT=
|
|
115
|
+
init({ apiKey: 'rsk-...', traceContent: false });
|
|
116
|
+
// or set RISICARE_TRACE_CONTENT=false
|
|
114
117
|
```
|
|
115
118
|
|
|
116
|
-
|
|
119
|
+
The argument wins over the environment variable. You can also turn off content
|
|
120
|
+
capture in the project settings. The gateway then drops content for that
|
|
121
|
+
project, also when the SDK still sends it.
|
|
122
|
+
|
|
123
|
+
With `traceContent: false`, the SDK still sends the status message, the
|
|
124
|
+
exception message, the stack trace (which repeats the message), `error.message`
|
|
125
|
+
and `exception.message`. Only the project switch masks them, at the gateway.
|
|
126
|
+
Error diagnosis needs them, and an error message can contain part of a prompt.
|
|
127
|
+
|
|
128
|
+
**Which providers capture text.** With `traceContent` on (the default):
|
|
117
129
|
|
|
118
130
|
- `patchOpenAI` and `patchAnthropic` capture the prompt and the completion text.
|
|
119
131
|
They write the first 10 messages to `gen_ai.prompt.N.role` and
|
|
@@ -129,14 +141,20 @@ init({ apiKey: 'rsk-...', traceContent: true });
|
|
|
129
141
|
|
|
130
142
|
**Error text is not covered by this switch.** The error message from a
|
|
131
143
|
provider can contain your prompt text. For example, a 400 error can repeat
|
|
132
|
-
part of the prompt.
|
|
133
|
-
|
|
144
|
+
part of the prompt.
|
|
145
|
+
With `traceContent: false`, the SDK still sends the status message, the
|
|
146
|
+
exception message, the stack trace (which repeats the message), `error.message`
|
|
147
|
+
and `exception.message`. Only the project switch masks them, at the gateway.
|
|
148
|
+
|
|
149
|
+
**Upgrading from 0.9.2 or earlier?** This is a behaviour change. From 0.5.2
|
|
150
|
+
to 0.9.2 the default was `false`: prompts and completions stayed in your
|
|
151
|
+
process unless you opted in. Now they are sent unless you stop them. To keep
|
|
152
|
+
the old behaviour, add `traceContent: false` or set
|
|
153
|
+
`RISICARE_TRACE_CONTENT=false`.
|
|
134
154
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
stop a `span.setAttribute('gen_ai.prompt.0.content', ...)` from reaching us.
|
|
139
|
-
Both are fixed together.
|
|
155
|
+
The flag covers content that you set by hand too (since 0.5.2). For example,
|
|
156
|
+
`traceContent: false` stops a `span.setAttribute('gen_ai.prompt.0.content', ...)`
|
|
157
|
+
from reaching us. In 0.5.0 and earlier the flag did not do this.
|
|
140
158
|
|
|
141
159
|
When capture is off, content-bearing attributes are **replaced** with
|
|
142
160
|
`<risicare:content-omitted>` rather than removed, so "no prompt was sent" stays
|
|
@@ -151,7 +169,7 @@ on every content-bearing field of every span before export, for every
|
|
|
151
169
|
exporter:
|
|
152
170
|
|
|
153
171
|
```typescript
|
|
154
|
-
init({ apiKey: 'rsk-...',
|
|
172
|
+
init({ apiKey: 'rsk-...', mask: (key, value) => value });
|
|
155
173
|
```
|
|
156
174
|
|
|
157
175
|
|
|
@@ -131,6 +131,51 @@ function hasCredentials(url) {
|
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
+
// src/masking.ts
|
|
135
|
+
var CONTENT_IN_JSON_OBJECT = /* @__PURE__ */ new Map([
|
|
136
|
+
[
|
|
137
|
+
"llm.invocation_parameters",
|
|
138
|
+
/* @__PURE__ */ new Set([
|
|
139
|
+
"additionalinstructions",
|
|
140
|
+
// OpenAI assistants run
|
|
141
|
+
"chathistory",
|
|
142
|
+
// Cohere
|
|
143
|
+
"contents",
|
|
144
|
+
// Gemini
|
|
145
|
+
"documents",
|
|
146
|
+
// Cohere RAG
|
|
147
|
+
"functions",
|
|
148
|
+
"input",
|
|
149
|
+
"inputtext",
|
|
150
|
+
// Bedrock Titan
|
|
151
|
+
"instructions",
|
|
152
|
+
"message",
|
|
153
|
+
// Cohere
|
|
154
|
+
"messages",
|
|
155
|
+
"preamble",
|
|
156
|
+
// Cohere
|
|
157
|
+
"prediction",
|
|
158
|
+
// OpenAI predicted output
|
|
159
|
+
"prompt",
|
|
160
|
+
"system",
|
|
161
|
+
// Anthropic
|
|
162
|
+
"systeminstruction",
|
|
163
|
+
// Gemini
|
|
164
|
+
"texts",
|
|
165
|
+
// Cohere embed
|
|
166
|
+
"toolconfig",
|
|
167
|
+
// Gemini
|
|
168
|
+
"tools"
|
|
169
|
+
])
|
|
170
|
+
]
|
|
171
|
+
]);
|
|
172
|
+
var VALUE_RULE_PREFIXES = new Set(
|
|
173
|
+
[...CONTENT_IN_JSON_OBJECT.keys()].flatMap((key) => {
|
|
174
|
+
const segments = key.split(".");
|
|
175
|
+
return segments.slice(1).map((_, i) => segments.slice(0, i + 1).join("."));
|
|
176
|
+
})
|
|
177
|
+
);
|
|
178
|
+
|
|
134
179
|
// src/exporters/batch.ts
|
|
135
180
|
var MAX_TIMEOUT_MS = 2 ** 31 - 1;
|
|
136
181
|
var MAX_BATCH_BYTES = 8 * 1024 * 1024;
|
|
@@ -267,7 +312,7 @@ var SUPPLEMENTAL_RULES = [
|
|
|
267
312
|
];
|
|
268
313
|
|
|
269
314
|
// src/version.ts
|
|
270
|
-
var SDK_VERSION = "0.
|
|
315
|
+
var SDK_VERSION = "0.10.0";
|
|
271
316
|
|
|
272
317
|
// src/exporters/quota.ts
|
|
273
318
|
var QUOTA_REASON = "monthly_quota_exceeded";
|
|
@@ -412,6 +457,8 @@ var HttpExporter = class {
|
|
|
412
457
|
_calls = /* @__PURE__ */ new Map();
|
|
413
458
|
/** The ack of each finished call, by its batch. Read once by `takeAck(spans)`. */
|
|
414
459
|
_acks = /* @__PURE__ */ new WeakMap();
|
|
460
|
+
/** The requests that each finished call sent, by its batch. Read once by `takeAttempts(spans)`. */
|
|
461
|
+
_requests = /* @__PURE__ */ new WeakMap();
|
|
415
462
|
/** The batch processor dropped span(s) from a full queue in the quota pause (S-1). */
|
|
416
463
|
noteQuotaDrop(count = 1) {
|
|
417
464
|
this._quota.addDrops(count);
|
|
@@ -463,6 +510,18 @@ var HttpExporter = class {
|
|
|
463
510
|
get attemptsPerExport() {
|
|
464
511
|
return this._maxRetries;
|
|
465
512
|
}
|
|
513
|
+
/**
|
|
514
|
+
* Returns the number of HTTP requests that the `export()` call for `spans` sent, and clears
|
|
515
|
+
* it. This is the number that was sent, not the most that the call may send
|
|
516
|
+
* (`attemptsPerExport`): a 401 or 403 stops the loop after one request, and an open circuit
|
|
517
|
+
* breaker sends none. Returns `null` when no call is on record for `spans`. The answer is
|
|
518
|
+
* kept per batch, as `takeAck` keeps the ack.
|
|
519
|
+
*/
|
|
520
|
+
takeAttempts(spans) {
|
|
521
|
+
const n = this._requests.get(spans) ?? null;
|
|
522
|
+
this._requests.delete(spans);
|
|
523
|
+
return n;
|
|
524
|
+
}
|
|
466
525
|
/**
|
|
467
526
|
* Returns the counts of the ack that the `export()` call for `spans` received, and clears
|
|
468
527
|
* them. The answer is kept per batch, not on the instance: two processors that share this
|
|
@@ -507,13 +566,15 @@ var HttpExporter = class {
|
|
|
507
566
|
misroute: null,
|
|
508
567
|
noRetry: false,
|
|
509
568
|
status: null,
|
|
510
|
-
error: null
|
|
569
|
+
error: null,
|
|
570
|
+
attempts: 0
|
|
511
571
|
};
|
|
512
572
|
this._calls.set(spans, call);
|
|
513
573
|
try {
|
|
514
574
|
return await this._export(spans, call);
|
|
515
575
|
} finally {
|
|
516
576
|
this._calls.delete(spans);
|
|
577
|
+
this._requests.set(spans, this._endpointHasCredentials ? 0 : call.attempts);
|
|
517
578
|
}
|
|
518
579
|
}
|
|
519
580
|
async _export(spans, call) {
|
|
@@ -553,14 +614,13 @@ var HttpExporter = class {
|
|
|
553
614
|
isHalfOpen = true;
|
|
554
615
|
}
|
|
555
616
|
const maxAttempts = isHalfOpen ? 1 : this._maxRetries;
|
|
556
|
-
let attempts = 0;
|
|
557
617
|
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
558
618
|
call.refusalAfterMs = null;
|
|
559
619
|
call.misroute = null;
|
|
560
620
|
call.noRetry = false;
|
|
561
621
|
call.status = null;
|
|
562
622
|
call.error = null;
|
|
563
|
-
attempts++;
|
|
623
|
+
call.attempts++;
|
|
564
624
|
const result = await this._sendRequest(payload, parts.length, call, spans);
|
|
565
625
|
if (cancelled.aborted) {
|
|
566
626
|
this._acks.delete(spans);
|
|
@@ -582,7 +642,7 @@ var HttpExporter = class {
|
|
|
582
642
|
}
|
|
583
643
|
if (call.refusalAfterMs !== null) {
|
|
584
644
|
warn(
|
|
585
|
-
`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.`
|
|
645
|
+
`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.`
|
|
586
646
|
);
|
|
587
647
|
return "failure" /* FAILURE */;
|
|
588
648
|
}
|