risicare 0.4.0 → 0.5.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/README.md +30 -0
- package/dist/frameworks/instructor.cjs +93 -73
- package/dist/frameworks/instructor.cjs.map +1 -1
- package/dist/frameworks/instructor.d.cts +19 -7
- package/dist/frameworks/instructor.d.ts +19 -7
- package/dist/frameworks/instructor.js +85 -67
- package/dist/frameworks/instructor.js.map +1 -1
- package/dist/frameworks/langchain.cjs +192 -94
- package/dist/frameworks/langchain.cjs.map +1 -1
- package/dist/frameworks/langchain.d.cts +97 -3
- package/dist/frameworks/langchain.d.ts +97 -3
- package/dist/frameworks/langchain.js +190 -88
- package/dist/frameworks/langchain.js.map +1 -1
- package/dist/frameworks/langgraph.cjs +192 -94
- package/dist/frameworks/langgraph.cjs.map +1 -1
- package/dist/frameworks/langgraph.js +190 -88
- package/dist/frameworks/langgraph.js.map +1 -1
- package/dist/frameworks/llamaindex.cjs +94 -69
- package/dist/frameworks/llamaindex.cjs.map +1 -1
- package/dist/frameworks/llamaindex.d.cts +33 -17
- package/dist/frameworks/llamaindex.d.ts +33 -17
- package/dist/frameworks/llamaindex.js +85 -62
- package/dist/frameworks/llamaindex.js.map +1 -1
- package/dist/index.cjs +2684 -1934
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +234 -46
- package/dist/index.d.ts +234 -46
- package/dist/index.js +2492 -1762
- package/dist/index.js.map +1 -1
- package/dist/providers/anthropic/index.cjs +33 -34
- package/dist/providers/anthropic/index.cjs.map +1 -1
- package/dist/providers/anthropic/index.js +25 -28
- package/dist/providers/anthropic/index.js.map +1 -1
- package/dist/providers/bedrock/index.cjs +56 -44
- package/dist/providers/bedrock/index.cjs.map +1 -1
- package/dist/providers/bedrock/index.d.cts +13 -1
- package/dist/providers/bedrock/index.d.ts +13 -1
- package/dist/providers/bedrock/index.js +47 -38
- package/dist/providers/bedrock/index.js.map +1 -1
- package/dist/providers/cerebras/index.cjs +33 -34
- package/dist/providers/cerebras/index.cjs.map +1 -1
- package/dist/providers/cerebras/index.js +25 -28
- package/dist/providers/cerebras/index.js.map +1 -1
- package/dist/providers/cohere/index.cjs +35 -36
- package/dist/providers/cohere/index.cjs.map +1 -1
- package/dist/providers/cohere/index.js +27 -30
- package/dist/providers/cohere/index.js.map +1 -1
- package/dist/providers/google/index.cjs +33 -34
- package/dist/providers/google/index.cjs.map +1 -1
- package/dist/providers/google/index.js +25 -28
- package/dist/providers/google/index.js.map +1 -1
- package/dist/providers/groq/index.cjs +33 -34
- package/dist/providers/groq/index.cjs.map +1 -1
- package/dist/providers/groq/index.js +25 -28
- package/dist/providers/groq/index.js.map +1 -1
- package/dist/providers/huggingface/index.cjs +33 -34
- package/dist/providers/huggingface/index.cjs.map +1 -1
- package/dist/providers/huggingface/index.js +25 -28
- package/dist/providers/huggingface/index.js.map +1 -1
- package/dist/providers/mistral/index.cjs +37 -38
- package/dist/providers/mistral/index.cjs.map +1 -1
- package/dist/providers/mistral/index.js +29 -32
- package/dist/providers/mistral/index.js.map +1 -1
- package/dist/providers/ollama/index.cjs +41 -34
- package/dist/providers/ollama/index.cjs.map +1 -1
- package/dist/providers/ollama/index.js +33 -28
- package/dist/providers/ollama/index.js.map +1 -1
- package/dist/providers/openai/index.cjs +36 -35
- package/dist/providers/openai/index.cjs.map +1 -1
- package/dist/providers/openai/index.js +28 -29
- package/dist/providers/openai/index.js.map +1 -1
- package/dist/providers/together/index.cjs +33 -34
- package/dist/providers/together/index.cjs.map +1 -1
- package/dist/providers/together/index.js +25 -28
- package/dist/providers/together/index.js.map +1 -1
- package/dist/providers/vercel-ai/index.cjs +27 -35
- package/dist/providers/vercel-ai/index.cjs.map +1 -1
- package/dist/providers/vercel-ai/index.js +19 -29
- package/dist/providers/vercel-ai/index.js.map +1 -1
- package/package.json +94 -33
package/README.md
CHANGED
|
@@ -172,6 +172,36 @@ const result = await session(
|
|
|
172
172
|
);
|
|
173
173
|
```
|
|
174
174
|
|
|
175
|
+
## Known limitation — span loss during a backend outage
|
|
176
|
+
|
|
177
|
+
The SDK does **not** currently survive a sustained outage of the Risicare
|
|
178
|
+
backend, and the loss is silent to your application (it is warned about, but
|
|
179
|
+
nothing throws and `flush()` will not fail your request path).
|
|
180
|
+
|
|
181
|
+
The HTTP exporter opens a circuit breaker after **5 consecutive failed export
|
|
182
|
+
calls** and holds it open for **60 seconds**, returning failure immediately
|
|
183
|
+
without touching the network. Queued spans get 3 re-queue attempts, which against
|
|
184
|
+
an open breaker resolve in microseconds — so they are dropped — and for the
|
|
185
|
+
remainder of the cooldown the SDK will not retry even after your backend is
|
|
186
|
+
healthy again.
|
|
187
|
+
|
|
188
|
+
Measured, for a 1,000-span cohort emitted during the outage: **4 s → all
|
|
189
|
+
delivered; 5 s → half; 6 s and beyond → none.** The thresholds are counted in
|
|
190
|
+
**failed calls, not seconds** — where the 5th consecutive failure falls in
|
|
191
|
+
wall-clock time depends on your span rate and on how fast your endpoint fails.
|
|
192
|
+
|
|
193
|
+
Nothing is lost on a clean `shutdown()`, and short blips that stay under the
|
|
194
|
+
5-failure threshold are fully survivable. Tracked as `F-SDKBLIP-001`.
|
|
195
|
+
|
|
196
|
+
## A note on running without an API key
|
|
197
|
+
|
|
198
|
+
If tracing is enabled but no API key is configured, the SDK emits a one-time
|
|
199
|
+
`console.warn` and **drops** the spans. It deliberately does **not** print span
|
|
200
|
+
payloads to your console: the SDK performs no redaction of its own, so printing
|
|
201
|
+
would put prompts, completions and anything else in your attributes onto your
|
|
202
|
+
stderr. If you want console output for local development, pass `debug: true`
|
|
203
|
+
explicitly.
|
|
204
|
+
|
|
175
205
|
## Requirements
|
|
176
206
|
|
|
177
207
|
- Node.js 18+
|
|
@@ -3,9 +3,6 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __esm = (fn, res) => function __init() {
|
|
7
|
-
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
8
|
-
};
|
|
9
6
|
var __export = (target, all) => {
|
|
10
7
|
for (var name in all)
|
|
11
8
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -20,22 +17,26 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
20
17
|
};
|
|
21
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
19
|
|
|
20
|
+
// src/frameworks/instructor.ts
|
|
21
|
+
var instructor_exports = {};
|
|
22
|
+
__export(instructor_exports, {
|
|
23
|
+
patchInstructor: () => patchInstructor
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(instructor_exports);
|
|
26
|
+
|
|
27
|
+
// src/client.ts
|
|
28
|
+
var import_node_crypto3 = require("crypto");
|
|
29
|
+
|
|
23
30
|
// src/globals.ts
|
|
31
|
+
var import_node_async_hooks = require("async_hooks");
|
|
32
|
+
var G = globalThis;
|
|
33
|
+
var PREFIX = "__risicare_";
|
|
24
34
|
function getTracer() {
|
|
25
35
|
return G[PREFIX + "tracer"];
|
|
26
36
|
}
|
|
27
37
|
function getDebug() {
|
|
28
38
|
return G[PREFIX + "debug"] ?? false;
|
|
29
39
|
}
|
|
30
|
-
var import_node_async_hooks, G, PREFIX;
|
|
31
|
-
var init_globals = __esm({
|
|
32
|
-
"src/globals.ts"() {
|
|
33
|
-
"use strict";
|
|
34
|
-
import_node_async_hooks = require("async_hooks");
|
|
35
|
-
G = globalThis;
|
|
36
|
-
PREFIX = "__risicare_";
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
40
|
|
|
40
41
|
// src/utils/log.ts
|
|
41
42
|
function debug(msg) {
|
|
@@ -44,19 +45,10 @@ function debug(msg) {
|
|
|
44
45
|
`);
|
|
45
46
|
}
|
|
46
47
|
}
|
|
47
|
-
var init_log = __esm({
|
|
48
|
-
"src/utils/log.ts"() {
|
|
49
|
-
"use strict";
|
|
50
|
-
init_globals();
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
48
|
|
|
54
|
-
// src/
|
|
55
|
-
var
|
|
56
|
-
|
|
57
|
-
patchInstructor: () => patchInstructor
|
|
58
|
-
});
|
|
59
|
-
module.exports = __toCommonJS(instructor_exports);
|
|
49
|
+
// src/exporters/batch.ts
|
|
50
|
+
var MAX_BATCH_BYTES = 8 * 1024 * 1024;
|
|
51
|
+
var utf8ByteLength = typeof Buffer !== "undefined" && typeof Buffer.byteLength === "function" ? (s) => Buffer.byteLength(s, "utf8") : (s) => s.length * 3;
|
|
60
52
|
|
|
61
53
|
// src/ids.ts
|
|
62
54
|
var import_node_crypto = require("crypto");
|
|
@@ -131,69 +123,97 @@ var NOOP_SPAN = Object.freeze({
|
|
|
131
123
|
}
|
|
132
124
|
});
|
|
133
125
|
|
|
134
|
-
// src/
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
// src/exporters/batch.ts
|
|
138
|
-
init_log();
|
|
139
|
-
|
|
140
|
-
// src/exporters/http.ts
|
|
141
|
-
init_log();
|
|
126
|
+
// src/runtime/applier.ts
|
|
127
|
+
var import_node_crypto2 = require("crypto");
|
|
142
128
|
|
|
143
129
|
// src/client.ts
|
|
144
|
-
init_log();
|
|
145
|
-
init_globals();
|
|
146
130
|
function getTracer2() {
|
|
147
131
|
return getTracer();
|
|
148
132
|
}
|
|
149
133
|
var _ERROR_DEDUP_TTL_MS = 5 * 60 * 1e3;
|
|
150
134
|
|
|
135
|
+
// src/utils/assert-client.ts
|
|
136
|
+
function assertClient(patcherName, client) {
|
|
137
|
+
if (client === null || client === void 0) {
|
|
138
|
+
throw new TypeError(
|
|
139
|
+
`${patcherName} requires a client object, got ${client === null ? "null" : "undefined"}`
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
const t = typeof client;
|
|
143
|
+
if (t !== "object" && t !== "function") {
|
|
144
|
+
throw new TypeError(
|
|
145
|
+
`${patcherName} requires a client object, got ${t}`
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
151
150
|
// src/frameworks/instructor.ts
|
|
152
|
-
|
|
151
|
+
function makePatchedCreate(originalCreate) {
|
|
152
|
+
return function patchedCreate(...args) {
|
|
153
|
+
const tracer = getTracer2();
|
|
154
|
+
if (!tracer?.enabled) {
|
|
155
|
+
debug("Tracer not initialized \u2014 call init() before using patchInstructor()");
|
|
156
|
+
return originalCreate.apply(this, args);
|
|
157
|
+
}
|
|
158
|
+
const params = args[0] ?? {};
|
|
159
|
+
const responseModel = params.response_model ?? params.responseModel;
|
|
160
|
+
let modelName = "unknown";
|
|
161
|
+
if (responseModel && typeof responseModel === "function") {
|
|
162
|
+
modelName = responseModel.name || "unknown";
|
|
163
|
+
} else if (responseModel && typeof responseModel === "object") {
|
|
164
|
+
const rm = responseModel;
|
|
165
|
+
modelName = rm.name ?? rm.description ?? rm.schema?.name ?? "schema";
|
|
166
|
+
} else if (typeof responseModel === "string") {
|
|
167
|
+
modelName = responseModel;
|
|
168
|
+
}
|
|
169
|
+
return tracer.startSpan(
|
|
170
|
+
{
|
|
171
|
+
name: "instructor.create",
|
|
172
|
+
kind: "llm_call" /* LLM_CALL */,
|
|
173
|
+
attributes: {
|
|
174
|
+
framework: "instructor",
|
|
175
|
+
"framework.span_kind": "extraction",
|
|
176
|
+
"instructor.response_model": modelName,
|
|
177
|
+
...params.max_retries != null ? { "instructor.max_retries": params.max_retries } : {},
|
|
178
|
+
...params.model != null ? { "gen_ai.request.model": params.model } : {}
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
(_span) => {
|
|
182
|
+
const result = originalCreate.apply(this, args);
|
|
183
|
+
if (result && typeof result.then === "function") {
|
|
184
|
+
return result.then((r) => r);
|
|
185
|
+
}
|
|
186
|
+
return result;
|
|
187
|
+
}
|
|
188
|
+
);
|
|
189
|
+
};
|
|
190
|
+
}
|
|
153
191
|
function patchInstructor(client) {
|
|
192
|
+
assertClient("patchInstructor", client);
|
|
154
193
|
return new Proxy(client, {
|
|
155
194
|
get(target, prop, receiver) {
|
|
156
195
|
const value = Reflect.get(target, prop, receiver);
|
|
157
196
|
if (prop === "create" && typeof value === "function") {
|
|
158
|
-
return
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
);
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
modelName = responseModel;
|
|
175
|
-
}
|
|
176
|
-
return tracer.startSpan(
|
|
177
|
-
{
|
|
178
|
-
name: "instructor.create",
|
|
179
|
-
kind: "llm_call" /* LLM_CALL */,
|
|
180
|
-
attributes: {
|
|
181
|
-
framework: "instructor",
|
|
182
|
-
"framework.span_kind": "extraction",
|
|
183
|
-
"instructor.response_model": modelName,
|
|
184
|
-
...params.max_retries != null ? { "instructor.max_retries": params.max_retries } : {},
|
|
185
|
-
...params.model != null ? { "gen_ai.request.model": params.model } : {}
|
|
186
|
-
}
|
|
187
|
-
},
|
|
188
|
-
(_span) => {
|
|
189
|
-
const result = value.apply(this, args);
|
|
190
|
-
if (result && typeof result.then === "function") {
|
|
191
|
-
return result.then((r) => r);
|
|
192
|
-
}
|
|
193
|
-
return result;
|
|
197
|
+
return makePatchedCreate(value.bind(target));
|
|
198
|
+
}
|
|
199
|
+
if (prop === "chat" && value && typeof value === "object") {
|
|
200
|
+
return new Proxy(value, {
|
|
201
|
+
get(chatTarget, chatProp, chatReceiver) {
|
|
202
|
+
const chatValue = Reflect.get(chatTarget, chatProp, chatReceiver);
|
|
203
|
+
if (chatProp === "completions" && chatValue && typeof chatValue === "object") {
|
|
204
|
+
return new Proxy(chatValue, {
|
|
205
|
+
get(compTarget, compProp, compReceiver) {
|
|
206
|
+
const compValue = Reflect.get(compTarget, compProp, compReceiver);
|
|
207
|
+
if (compProp === "create" && typeof compValue === "function") {
|
|
208
|
+
return makePatchedCreate(compValue.bind(compTarget));
|
|
209
|
+
}
|
|
210
|
+
return compValue;
|
|
211
|
+
}
|
|
212
|
+
});
|
|
194
213
|
}
|
|
195
|
-
|
|
196
|
-
|
|
214
|
+
return chatValue;
|
|
215
|
+
}
|
|
216
|
+
});
|
|
197
217
|
}
|
|
198
218
|
return value;
|
|
199
219
|
}
|