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.
Files changed (80) hide show
  1. package/README.md +30 -0
  2. package/dist/frameworks/instructor.cjs +93 -73
  3. package/dist/frameworks/instructor.cjs.map +1 -1
  4. package/dist/frameworks/instructor.d.cts +19 -7
  5. package/dist/frameworks/instructor.d.ts +19 -7
  6. package/dist/frameworks/instructor.js +85 -67
  7. package/dist/frameworks/instructor.js.map +1 -1
  8. package/dist/frameworks/langchain.cjs +192 -94
  9. package/dist/frameworks/langchain.cjs.map +1 -1
  10. package/dist/frameworks/langchain.d.cts +97 -3
  11. package/dist/frameworks/langchain.d.ts +97 -3
  12. package/dist/frameworks/langchain.js +190 -88
  13. package/dist/frameworks/langchain.js.map +1 -1
  14. package/dist/frameworks/langgraph.cjs +192 -94
  15. package/dist/frameworks/langgraph.cjs.map +1 -1
  16. package/dist/frameworks/langgraph.js +190 -88
  17. package/dist/frameworks/langgraph.js.map +1 -1
  18. package/dist/frameworks/llamaindex.cjs +94 -69
  19. package/dist/frameworks/llamaindex.cjs.map +1 -1
  20. package/dist/frameworks/llamaindex.d.cts +33 -17
  21. package/dist/frameworks/llamaindex.d.ts +33 -17
  22. package/dist/frameworks/llamaindex.js +85 -62
  23. package/dist/frameworks/llamaindex.js.map +1 -1
  24. package/dist/index.cjs +2684 -1934
  25. package/dist/index.cjs.map +1 -1
  26. package/dist/index.d.cts +234 -46
  27. package/dist/index.d.ts +234 -46
  28. package/dist/index.js +2492 -1762
  29. package/dist/index.js.map +1 -1
  30. package/dist/providers/anthropic/index.cjs +33 -34
  31. package/dist/providers/anthropic/index.cjs.map +1 -1
  32. package/dist/providers/anthropic/index.js +25 -28
  33. package/dist/providers/anthropic/index.js.map +1 -1
  34. package/dist/providers/bedrock/index.cjs +56 -44
  35. package/dist/providers/bedrock/index.cjs.map +1 -1
  36. package/dist/providers/bedrock/index.d.cts +13 -1
  37. package/dist/providers/bedrock/index.d.ts +13 -1
  38. package/dist/providers/bedrock/index.js +47 -38
  39. package/dist/providers/bedrock/index.js.map +1 -1
  40. package/dist/providers/cerebras/index.cjs +33 -34
  41. package/dist/providers/cerebras/index.cjs.map +1 -1
  42. package/dist/providers/cerebras/index.js +25 -28
  43. package/dist/providers/cerebras/index.js.map +1 -1
  44. package/dist/providers/cohere/index.cjs +35 -36
  45. package/dist/providers/cohere/index.cjs.map +1 -1
  46. package/dist/providers/cohere/index.js +27 -30
  47. package/dist/providers/cohere/index.js.map +1 -1
  48. package/dist/providers/google/index.cjs +33 -34
  49. package/dist/providers/google/index.cjs.map +1 -1
  50. package/dist/providers/google/index.js +25 -28
  51. package/dist/providers/google/index.js.map +1 -1
  52. package/dist/providers/groq/index.cjs +33 -34
  53. package/dist/providers/groq/index.cjs.map +1 -1
  54. package/dist/providers/groq/index.js +25 -28
  55. package/dist/providers/groq/index.js.map +1 -1
  56. package/dist/providers/huggingface/index.cjs +33 -34
  57. package/dist/providers/huggingface/index.cjs.map +1 -1
  58. package/dist/providers/huggingface/index.js +25 -28
  59. package/dist/providers/huggingface/index.js.map +1 -1
  60. package/dist/providers/mistral/index.cjs +37 -38
  61. package/dist/providers/mistral/index.cjs.map +1 -1
  62. package/dist/providers/mistral/index.js +29 -32
  63. package/dist/providers/mistral/index.js.map +1 -1
  64. package/dist/providers/ollama/index.cjs +41 -34
  65. package/dist/providers/ollama/index.cjs.map +1 -1
  66. package/dist/providers/ollama/index.js +33 -28
  67. package/dist/providers/ollama/index.js.map +1 -1
  68. package/dist/providers/openai/index.cjs +36 -35
  69. package/dist/providers/openai/index.cjs.map +1 -1
  70. package/dist/providers/openai/index.js +28 -29
  71. package/dist/providers/openai/index.js.map +1 -1
  72. package/dist/providers/together/index.cjs +33 -34
  73. package/dist/providers/together/index.cjs.map +1 -1
  74. package/dist/providers/together/index.js +25 -28
  75. package/dist/providers/together/index.js.map +1 -1
  76. package/dist/providers/vercel-ai/index.cjs +27 -35
  77. package/dist/providers/vercel-ai/index.cjs.map +1 -1
  78. package/dist/providers/vercel-ai/index.js +19 -29
  79. package/dist/providers/vercel-ai/index.js.map +1 -1
  80. package/package.json +94 -33
@@ -1,10 +1,10 @@
1
- var __getOwnPropNames = Object.getOwnPropertyNames;
2
- var __esm = (fn, res) => function __init() {
3
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
4
- };
1
+ // src/client.ts
2
+ import { createHash as createHash2 } from "crypto";
5
3
 
6
4
  // src/globals.ts
7
5
  import { AsyncLocalStorage } from "async_hooks";
6
+ var G = globalThis;
7
+ var PREFIX = "__risicare_";
8
8
  function getTracer() {
9
9
  return G[PREFIX + "tracer"];
10
10
  }
@@ -17,14 +17,6 @@ function getContextStorage() {
17
17
  function getDebug() {
18
18
  return G[PREFIX + "debug"] ?? false;
19
19
  }
20
- var G, PREFIX;
21
- var init_globals = __esm({
22
- "src/globals.ts"() {
23
- "use strict";
24
- G = globalThis;
25
- PREFIX = "__risicare_";
26
- }
27
- });
28
20
 
29
21
  // src/utils/log.ts
30
22
  function debug(msg) {
@@ -33,12 +25,10 @@ function debug(msg) {
33
25
  `);
34
26
  }
35
27
  }
36
- var init_log = __esm({
37
- "src/utils/log.ts"() {
38
- "use strict";
39
- init_globals();
40
- }
41
- });
28
+
29
+ // src/exporters/batch.ts
30
+ var MAX_BATCH_BYTES = 8 * 1024 * 1024;
31
+ var utf8ByteLength = typeof Buffer !== "undefined" && typeof Buffer.byteLength === "function" ? (s) => Buffer.byteLength(s, "utf8") : (s) => s.length * 3;
42
32
 
43
33
  // src/ids.ts
44
34
  import { randomBytes } from "crypto";
@@ -114,7 +104,6 @@ var NOOP_SPAN = Object.freeze({
114
104
  });
115
105
 
116
106
  // src/context/storage.ts
117
- init_globals();
118
107
  function storage() {
119
108
  return getContextStorage();
120
109
  }
@@ -122,15 +111,10 @@ function getContext() {
122
111
  return storage().getStore() ?? {};
123
112
  }
124
113
 
125
- // src/exporters/batch.ts
126
- init_log();
127
-
128
- // src/exporters/http.ts
129
- init_log();
114
+ // src/runtime/applier.ts
115
+ import { createHash } from "crypto";
130
116
 
131
117
  // src/client.ts
132
- init_log();
133
- init_globals();
134
118
  function requireTracer() {
135
119
  const tracer = getTracer();
136
120
  if (!tracer) {
@@ -188,8 +172,20 @@ function calculateCost(model, promptTokens, completionTokens) {
188
172
  return inputCost + outputCost;
189
173
  }
190
174
 
191
- // src/providers/bedrock/patch.ts
192
- init_log();
175
+ // src/utils/assert-client.ts
176
+ function assertClient(patcherName, client) {
177
+ if (client === null || client === void 0) {
178
+ throw new TypeError(
179
+ `${patcherName} requires a client object, got ${client === null ? "null" : "undefined"}`
180
+ );
181
+ }
182
+ const t = typeof client;
183
+ if (t !== "object" && t !== "function") {
184
+ throw new TypeError(
185
+ `${patcherName} requires a client object, got ${t}`
186
+ );
187
+ }
188
+ }
193
189
 
194
190
  // src/context/dedup.ts
195
191
  function isProviderInstrumentationSuppressed() {
@@ -202,17 +198,26 @@ var INSTRUMENTED_COMMANDS = /* @__PURE__ */ new Set([
202
198
  "ConverseStreamCommand",
203
199
  "InvokeModelCommand"
204
200
  ]);
205
- function deriveProvider(modelId) {
206
- const dotIndex = modelId.indexOf(".");
201
+ function deriveModelFamily(modelId) {
202
+ const KNOWN_REGION_PREFIXES = ["us.", "eu.", "apac."];
203
+ let id = modelId;
204
+ for (const p of KNOWN_REGION_PREFIXES) {
205
+ if (id.startsWith(p)) {
206
+ id = id.slice(p.length);
207
+ break;
208
+ }
209
+ }
210
+ const dotIndex = id.indexOf(".");
207
211
  if (dotIndex > 0) {
208
- return modelId.substring(0, dotIndex);
212
+ return id.substring(0, dotIndex);
209
213
  }
210
- return "bedrock";
214
+ return "unknown";
211
215
  }
212
- function enrichSpanFromRequest(span, input, provider) {
216
+ function enrichSpanFromRequest(span, input, modelFamily) {
213
217
  const modelId = input.modelId;
214
218
  if (modelId) {
215
- span.setAttribute("gen_ai.system", provider);
219
+ span.setAttribute("gen_ai.system", "bedrock");
220
+ span.setAttribute("bedrock.model_family", modelFamily);
216
221
  span.setAttribute("gen_ai.request.model", modelId);
217
222
  }
218
223
  const inferenceConfig = input.inferenceConfig;
@@ -315,7 +320,7 @@ function createSendProxy(originalSend) {
315
320
  }
316
321
  const input = getCommandInput(command);
317
322
  const modelId = input.modelId ?? "unknown";
318
- const provider = deriveProvider(modelId);
323
+ const modelFamily = deriveModelFamily(modelId);
319
324
  const isStream = commandName === "ConverseStreamCommand";
320
325
  const spanName = `bedrock.${commandName.replace("Command", "").toLowerCase()}`;
321
326
  return tracer.startSpan(
@@ -324,14 +329,16 @@ function createSendProxy(originalSend) {
324
329
  kind: "llm_call" /* LLM_CALL */,
325
330
  attributes: {
326
331
  "llm.request.model": modelId,
327
- "gen_ai.system": provider,
332
+ // F-630: provider is the SERVICE for AWS-spend filtering.
333
+ "gen_ai.system": "bedrock",
334
+ "bedrock.model_family": modelFamily,
328
335
  "bedrock.command": commandName,
329
336
  ...isStream ? { "llm.stream": true } : {}
330
337
  }
331
338
  },
332
339
  (span) => {
333
- span.setLlmFields({ provider, model: modelId });
334
- enrichSpanFromRequest(span, input, provider);
340
+ span.setLlmFields({ provider: "bedrock", model: modelId });
341
+ enrichSpanFromRequest(span, input, modelFamily);
335
342
  const result = originalSend.apply(this, args);
336
343
  if (result && typeof result.then === "function") {
337
344
  return result.then((response) => {
@@ -350,6 +357,7 @@ function createSendProxy(originalSend) {
350
357
  };
351
358
  }
352
359
  function patchBedrock(client) {
360
+ assertClient("patchBedrock", client);
353
361
  return new Proxy(client, {
354
362
  get(target, prop, receiver) {
355
363
  const value = Reflect.get(target, prop, receiver);
@@ -361,6 +369,7 @@ function patchBedrock(client) {
361
369
  });
362
370
  }
363
371
  export {
372
+ deriveModelFamily,
364
373
  patchBedrock
365
374
  };
366
375
  //# sourceMappingURL=index.js.map