braintrust 3.25.0 → 3.27.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 (79) hide show
  1. package/NOTICE +6 -0
  2. package/dev/dist/index.d.mts +130 -2
  3. package/dev/dist/index.d.ts +130 -2
  4. package/dev/dist/index.js +4133 -1421
  5. package/dev/dist/index.mjs +3242 -530
  6. package/dist/apply-auto-instrumentation.js +526 -426
  7. package/dist/apply-auto-instrumentation.mjs +329 -229
  8. package/dist/auto-instrumentations/bundler/esbuild.cjs +1198 -364
  9. package/dist/auto-instrumentations/bundler/esbuild.d.mts +4 -4
  10. package/dist/auto-instrumentations/bundler/esbuild.d.ts +4 -4
  11. package/dist/auto-instrumentations/bundler/esbuild.mjs +6 -8
  12. package/dist/auto-instrumentations/bundler/next.cjs +1227 -413
  13. package/dist/auto-instrumentations/bundler/next.mjs +7 -29
  14. package/dist/auto-instrumentations/bundler/rollup.cjs +1198 -364
  15. package/dist/auto-instrumentations/bundler/rollup.d.mts +4 -4
  16. package/dist/auto-instrumentations/bundler/rollup.d.ts +4 -4
  17. package/dist/auto-instrumentations/bundler/rollup.mjs +6 -8
  18. package/dist/auto-instrumentations/bundler/vite.cjs +1249 -387
  19. package/dist/auto-instrumentations/bundler/vite.d.mts +4 -4
  20. package/dist/auto-instrumentations/bundler/vite.d.ts +4 -4
  21. package/dist/auto-instrumentations/bundler/vite.mjs +34 -8
  22. package/dist/auto-instrumentations/bundler/webpack-loader.cjs +1368 -324
  23. package/dist/auto-instrumentations/bundler/webpack-loader.d.ts +20 -12
  24. package/dist/auto-instrumentations/bundler/webpack.cjs +1198 -364
  25. package/dist/auto-instrumentations/bundler/webpack.d.mts +4 -4
  26. package/dist/auto-instrumentations/bundler/webpack.d.ts +4 -4
  27. package/dist/auto-instrumentations/bundler/webpack.mjs +6 -4
  28. package/dist/auto-instrumentations/chunk-2AMDGD65.mjs +1396 -0
  29. package/dist/auto-instrumentations/{chunk-7P6563SW.mjs → chunk-BW33ULMW.mjs} +2 -6
  30. package/dist/auto-instrumentations/{chunk-M6DLIJ2Z.mjs → chunk-I55G56ZL.mjs} +114 -221
  31. package/dist/auto-instrumentations/chunk-JPUFNW7X.mjs +649 -0
  32. package/dist/auto-instrumentations/{chunk-JPVCUKTY.mjs → chunk-XEYKUBLY.mjs} +191 -73
  33. package/dist/auto-instrumentations/{chunk-CZ24KNHT.mjs → chunk-ZNHTSSGI.mjs} +231 -69
  34. package/dist/auto-instrumentations/hook.mjs +406 -183
  35. package/dist/auto-instrumentations/index.cjs +853 -49
  36. package/dist/auto-instrumentations/index.d.mts +10 -2
  37. package/dist/auto-instrumentations/index.d.ts +10 -2
  38. package/dist/auto-instrumentations/index.mjs +10 -1
  39. package/dist/auto-instrumentations/loader/cjs-patch.cjs +566 -221
  40. package/dist/auto-instrumentations/loader/cjs-patch.d.mts +2 -2
  41. package/dist/auto-instrumentations/loader/cjs-patch.d.ts +2 -2
  42. package/dist/auto-instrumentations/loader/cjs-patch.mjs +3 -2
  43. package/dist/auto-instrumentations/loader/esm-hook.mjs +1 -1
  44. package/dist/auto-instrumentations/plugin-B-aZh7EP.d.ts +30 -0
  45. package/dist/auto-instrumentations/plugin-Bnj4E_6B.d.mts +30 -0
  46. package/dist/auto-instrumentations/{types-RNPaKi9o.d.mts → types-C1fVeiCp.d.mts} +1 -1
  47. package/dist/auto-instrumentations/{types-RNPaKi9o.d.ts → types-C1fVeiCp.d.ts} +1 -1
  48. package/dist/browser.d.mts +871 -199
  49. package/dist/browser.d.ts +871 -199
  50. package/dist/browser.js +3737 -549
  51. package/dist/browser.mjs +3737 -549
  52. package/dist/{chunk-ABR2QWDP.mjs → chunk-CZM5JIQL.mjs} +788 -132
  53. package/dist/{chunk-P25IOOU4.js → chunk-MF7NU6BT.js} +795 -139
  54. package/dist/{chunk-GSIDVFE6.js → chunk-QRHGVBKU.js} +3580 -1463
  55. package/dist/{chunk-2SANLSWX.mjs → chunk-YKD22IMR.mjs} +2505 -388
  56. package/dist/cli.js +3244 -533
  57. package/dist/edge-light.d.mts +1 -1
  58. package/dist/edge-light.d.ts +1 -1
  59. package/dist/edge-light.js +3737 -552
  60. package/dist/edge-light.mjs +3737 -552
  61. package/dist/index.d.mts +871 -199
  62. package/dist/index.d.ts +871 -199
  63. package/dist/index.js +893 -446
  64. package/dist/index.mjs +463 -16
  65. package/dist/instrumentation/index.d.mts +138 -6
  66. package/dist/instrumentation/index.d.ts +138 -6
  67. package/dist/instrumentation/index.js +3362 -559
  68. package/dist/instrumentation/index.mjs +3362 -559
  69. package/dist/vitest-evals-reporter.js +45 -43
  70. package/dist/vitest-evals-reporter.mjs +5 -3
  71. package/dist/workerd.d.mts +1 -1
  72. package/dist/workerd.d.ts +1 -1
  73. package/dist/workerd.js +3737 -552
  74. package/dist/workerd.mjs +3737 -552
  75. package/licenses/node-diagnostics-channel/LICENSE +19 -0
  76. package/package.json +34 -35
  77. package/dist/auto-instrumentations/chunk-VT6DDNKM.mjs +0 -856
  78. package/dist/auto-instrumentations/plugin-D0KHwSJv.d.mts +0 -44
  79. package/dist/auto-instrumentations/plugin-G6fgxk1b.d.ts +0 -44
@@ -1,3 +1,7 @@
1
+ import {
2
+ newGlobalTracingChannel
3
+ } from "./chunk-JPUFNW7X.mjs";
4
+
1
5
  // src/isomorph.ts
2
6
  var DefaultAsyncLocalStorage = class {
3
7
  constructor() {
@@ -11,73 +15,6 @@ var DefaultAsyncLocalStorage = class {
11
15
  return void 0;
12
16
  }
13
17
  };
14
- var DefaultChannel = class {
15
- constructor(name) {
16
- this.name = name;
17
- }
18
- name;
19
- hasSubscribers = false;
20
- subscribe(_subscription) {
21
- }
22
- unsubscribe(_subscription) {
23
- return false;
24
- }
25
- bindStore(_store, _transform) {
26
- }
27
- unbindStore(_store) {
28
- return false;
29
- }
30
- publish(_message) {
31
- }
32
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
33
- runStores(_message, fn, thisArg, ...args) {
34
- return fn.apply(thisArg, args);
35
- }
36
- };
37
- var DefaultTracingChannel = class {
38
- start;
39
- end;
40
- asyncStart;
41
- asyncEnd;
42
- error;
43
- constructor(nameOrChannels) {
44
- if (typeof nameOrChannels === "string") {
45
- this.start = new DefaultChannel(`tracing:${nameOrChannels}:start`);
46
- this.end = new DefaultChannel(`tracing:${nameOrChannels}:end`);
47
- this.asyncStart = new DefaultChannel(
48
- `tracing:${nameOrChannels}:asyncStart`
49
- );
50
- this.asyncEnd = new DefaultChannel(`tracing:${nameOrChannels}:asyncEnd`);
51
- this.error = new DefaultChannel(`tracing:${nameOrChannels}:error`);
52
- return;
53
- }
54
- this.start = nameOrChannels.start ?? new DefaultChannel("tracing:start");
55
- this.end = nameOrChannels.end ?? new DefaultChannel("tracing:end");
56
- this.asyncStart = nameOrChannels.asyncStart ?? new DefaultChannel("tracing:asyncStart");
57
- this.asyncEnd = nameOrChannels.asyncEnd ?? new DefaultChannel("tracing:asyncEnd");
58
- this.error = nameOrChannels.error ?? new DefaultChannel("tracing:error");
59
- }
60
- get hasSubscribers() {
61
- return this.start.hasSubscribers || this.end.hasSubscribers || this.asyncStart.hasSubscribers || this.asyncEnd.hasSubscribers || this.error.hasSubscribers;
62
- }
63
- subscribe(_handlers) {
64
- }
65
- unsubscribe(_handlers) {
66
- return false;
67
- }
68
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
69
- traceSync(fn, _message, thisArg, ...args) {
70
- return fn.apply(thisArg, args);
71
- }
72
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
73
- tracePromise(fn, _message, thisArg, ...args) {
74
- return fn.apply(thisArg, args);
75
- }
76
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
77
- traceCallback(fn, _position, _message, thisArg, ...args) {
78
- return fn.apply(thisArg, args);
79
- }
80
- };
81
18
  var iso = {
82
19
  buildType: "unknown",
83
20
  // Will be set by configureBrowser() or configureNode()
@@ -88,7 +25,7 @@ var iso = {
88
25
  getCallerLocation: () => void 0,
89
26
  newAsyncLocalStorage: () => new DefaultAsyncLocalStorage(),
90
27
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
91
- newTracingChannel: (nameOrChannels) => new DefaultTracingChannel(nameOrChannels),
28
+ newTracingChannel: (nameOrChannels) => newGlobalTracingChannel(nameOrChannels),
92
29
  processOn: (_0, _1) => {
93
30
  },
94
31
  basename: (filepath) => filepath.split(/[\\/]/).pop() || filepath,
@@ -111,11 +48,21 @@ function defineChannels(pkg, channels, options) {
111
48
  const tracingChannel2 = () => isomorph_default.newTracingChannel(
112
49
  fullChannelName
113
50
  );
51
+ const intercept2 = (interceptor) => {
52
+ const hook = tracingChannel2();
53
+ return typeof hook.intercept === "function" ? hook.intercept(interceptor) : () => {
54
+ };
55
+ };
114
56
  return [
115
57
  key,
116
58
  {
117
59
  ...asyncSpec,
118
60
  instrumentationName,
61
+ intercept: intercept2,
62
+ invoke: (target, thisArg, args, additional) => {
63
+ const hook = tracingChannel2();
64
+ return typeof hook.invoke === "function" ? hook.invoke(target, thisArg, args, additional) : Reflect.apply(target, thisArg, args);
65
+ },
119
66
  tracingChannel: tracingChannel2,
120
67
  tracePromise: (fn, context) => tracingChannel2().tracePromise(
121
68
  fn,
@@ -129,11 +76,21 @@ function defineChannels(pkg, channels, options) {
129
76
  const tracingChannel = () => isomorph_default.newTracingChannel(
130
77
  fullChannelName
131
78
  );
79
+ const intercept = (interceptor) => {
80
+ const hook = tracingChannel();
81
+ return typeof hook.intercept === "function" ? hook.intercept(interceptor) : () => {
82
+ };
83
+ };
132
84
  return [
133
85
  key,
134
86
  {
135
87
  ...syncSpec,
136
88
  instrumentationName,
89
+ intercept,
90
+ invoke: (target, thisArg, args, additional) => {
91
+ const hook = tracingChannel();
92
+ return typeof hook.invoke === "function" ? hook.invoke(target, thisArg, args, additional) : Reflect.apply(target, thisArg, args);
93
+ },
137
94
  tracingChannel,
138
95
  traceSync: (fn, context) => tracingChannel().traceSync(
139
96
  fn,
@@ -153,6 +110,9 @@ var INSTRUMENTATION_NAMES = {
153
110
  BEDROCK_RUNTIME: "bedrock-runtime",
154
111
  BRAINTRUST_JS_LOGGER: "braintrust-js-logger",
155
112
  CLAUDE_AGENT_SDK: "claude-agent-sdk",
113
+ CLOUDFLARE_AI_CHAT: "cloudflare-ai-chat",
114
+ CLOUDFLARE_AGENTS: "cloudflare-agents",
115
+ CLOUDFLARE_THINK: "cloudflare-think",
156
116
  COHERE: "cohere",
157
117
  CURSOR_SDK: "cursor-sdk",
158
118
  EVE: "eve",
@@ -167,6 +127,7 @@ var INSTRUMENTATION_NAMES = {
167
127
  LANGSMITH: "langsmith",
168
128
  MASTRA: "mastra",
169
129
  MISTRAL: "mistral",
130
+ OLLAMA: "ollama",
170
131
  OPENAI: "openai",
171
132
  OPENAI_AGENTS: "openai-agents",
172
133
  OPENAI_CODEX: "openai-codex",
@@ -461,6 +422,14 @@ var anthropicChannels = defineChannels(
461
422
  betaMessagesToolRunner: channel({
462
423
  channelName: "beta.messages.toolRunner",
463
424
  kind: "sync-stream"
425
+ }),
426
+ betaSessionsEventsStream: channel({
427
+ channelName: "beta.sessions.events.stream",
428
+ kind: "async"
429
+ }),
430
+ betaSessionsThreadsEventsStream: channel({
431
+ channelName: "beta.sessions.threads.events.stream",
432
+ kind: "async"
464
433
  })
465
434
  },
466
435
  { instrumentationName: INSTRUMENTATION_NAMES.ANTHROPIC }
@@ -579,7 +548,40 @@ var anthropicConfigs = [
579
548
  methodName: "toolRunner",
580
549
  kind: "Sync"
581
550
  }
582
- }
551
+ },
552
+ // Managed Agents Sessions event streams are discovered automatically, but
553
+ // remain passive until the user calls collectAnthropicSession() on the
554
+ // returned stream.
555
+ ...["mjs", "js"].map(
556
+ (extension) => ({
557
+ channelName: anthropicChannels.betaSessionsEventsStream.channelName,
558
+ module: {
559
+ name: "@anthropic-ai/sdk",
560
+ versionRange: ">=0.86.0",
561
+ filePath: `resources/beta/sessions/events.${extension}`
562
+ },
563
+ functionQuery: {
564
+ className: "Events",
565
+ methodName: "stream",
566
+ kind: "Async"
567
+ }
568
+ })
569
+ ),
570
+ ...["mjs", "js"].map(
571
+ (extension) => ({
572
+ channelName: anthropicChannels.betaSessionsThreadsEventsStream.channelName,
573
+ module: {
574
+ name: "@anthropic-ai/sdk",
575
+ versionRange: ">=0.86.0",
576
+ filePath: `resources/beta/sessions/threads/events.${extension}`
577
+ },
578
+ functionQuery: {
579
+ className: "Events",
580
+ methodName: "stream",
581
+ kind: "Async"
582
+ }
583
+ })
584
+ )
583
585
  ];
584
586
 
585
587
  // src/instrumentation/plugins/bedrock-runtime-channels.ts
@@ -1200,6 +1202,66 @@ var claudeAgentSDKConfigs = [
1200
1202
  }
1201
1203
  ];
1202
1204
 
1205
+ // src/instrumentation/plugins/cloudflare-agents-channels.ts
1206
+ var cloudflareAgentsChannels = defineChannels(
1207
+ "agents",
1208
+ {
1209
+ runAgentTool: channel({
1210
+ channelName: "Agent.runAgentTool",
1211
+ kind: "async"
1212
+ })
1213
+ },
1214
+ { instrumentationName: INSTRUMENTATION_NAMES.CLOUDFLARE_AGENTS }
1215
+ );
1216
+
1217
+ // src/auto-instrumentations/configs/cloudflare-agents.ts
1218
+ var cloudflareAgentsVersionRange = ">=0.17.0 <0.18.0";
1219
+ var cloudflareAgentsConfigs = [
1220
+ {
1221
+ channelName: cloudflareAgentsChannels.runAgentTool.channelName,
1222
+ module: {
1223
+ name: "agents",
1224
+ versionRange: cloudflareAgentsVersionRange,
1225
+ filePath: "dist/index.js"
1226
+ },
1227
+ functionQuery: {
1228
+ className: "Agent",
1229
+ methodName: "runAgentTool",
1230
+ kind: "Async"
1231
+ }
1232
+ }
1233
+ ];
1234
+
1235
+ // src/instrumentation/plugins/cloudflare-think-channels.ts
1236
+ var cloudflareThinkChannels = defineChannels(
1237
+ "@cloudflare/think",
1238
+ {
1239
+ runInferenceLoop: channel({
1240
+ channelName: "Think.runInferenceLoop",
1241
+ kind: "async"
1242
+ })
1243
+ },
1244
+ { instrumentationName: INSTRUMENTATION_NAMES.CLOUDFLARE_THINK }
1245
+ );
1246
+
1247
+ // src/auto-instrumentations/configs/cloudflare-think.ts
1248
+ var cloudflareThinkVersionRange = ">=0.13.0 <0.14.0";
1249
+ var cloudflareThinkConfigs = [
1250
+ {
1251
+ channelName: cloudflareThinkChannels.runInferenceLoop.channelName,
1252
+ module: {
1253
+ name: "@cloudflare/think",
1254
+ versionRange: cloudflareThinkVersionRange,
1255
+ filePath: "dist/think.js"
1256
+ },
1257
+ functionQuery: {
1258
+ className: "Think",
1259
+ methodName: "_runInferenceLoop",
1260
+ kind: "Async"
1261
+ }
1262
+ }
1263
+ ];
1264
+
1203
1265
  // src/instrumentation/plugins/cursor-sdk-channels.ts
1204
1266
  var cursorSDKChannels = defineChannels(
1205
1267
  "@cursor/sdk",
@@ -1817,6 +1879,19 @@ var openRouterConfigs = [
1817
1879
  kind: "Async"
1818
1880
  }
1819
1881
  },
1882
+ {
1883
+ channelName: openRouterChannels.betaResponsesSend.channelName,
1884
+ module: {
1885
+ name: "@openrouter/sdk",
1886
+ versionRange: ">=1.1.2 <2.0.0",
1887
+ filePath: "esm/sdk/betaresponses.js"
1888
+ },
1889
+ functionQuery: {
1890
+ className: "BetaResponses",
1891
+ methodName: "send",
1892
+ kind: "Async"
1893
+ }
1894
+ },
1820
1895
  {
1821
1896
  channelName: openRouterChannels.callModel.channelName,
1822
1897
  module: {
@@ -2174,6 +2249,51 @@ var mistralConfigs = [
2174
2249
  }
2175
2250
  ];
2176
2251
 
2252
+ // src/instrumentation/plugins/ollama-channels.ts
2253
+ var ollamaChannels = defineChannels(
2254
+ "ollama",
2255
+ {
2256
+ chat: channel({
2257
+ channelName: "chat",
2258
+ kind: "async"
2259
+ }),
2260
+ generate: channel({
2261
+ channelName: "generate",
2262
+ kind: "async"
2263
+ }),
2264
+ embed: channel({
2265
+ channelName: "embed",
2266
+ kind: "async"
2267
+ })
2268
+ },
2269
+ { instrumentationName: INSTRUMENTATION_NAMES.OLLAMA }
2270
+ );
2271
+
2272
+ // src/auto-instrumentations/configs/ollama.ts
2273
+ var methods = [
2274
+ ["chat", ollamaChannels.chat.channelName],
2275
+ ["generate", ollamaChannels.generate.channelName],
2276
+ ["embed", ollamaChannels.embed.channelName]
2277
+ ];
2278
+ var implementationFiles = ["dist/browser.mjs", "dist/browser.cjs"];
2279
+ var ollamaConfigs = [
2280
+ ...implementationFiles.flatMap(
2281
+ (filePath) => methods.map(([methodName, channelName]) => ({
2282
+ channelName,
2283
+ module: {
2284
+ name: "ollama",
2285
+ versionRange: ">=0.6.0 <0.7.0",
2286
+ filePath
2287
+ },
2288
+ functionQuery: {
2289
+ className: "Ollama",
2290
+ methodName,
2291
+ kind: "Async"
2292
+ }
2293
+ }))
2294
+ )
2295
+ ];
2296
+
2177
2297
  // src/instrumentation/plugins/google-adk-channels.ts
2178
2298
  var googleADKChannels = defineChannels(
2179
2299
  "@google/adk",
@@ -2422,6 +2542,44 @@ var googleADKConfigs = [
2422
2542
  }
2423
2543
  ];
2424
2544
 
2545
+ // src/instrumentation/plugins/cloudflare-ai-chat-channels.ts
2546
+ var cloudflareAIChatChannels = defineChannels(
2547
+ "@cloudflare/ai-chat",
2548
+ {
2549
+ runExclusiveChatTurn: channel({
2550
+ channelName: "AIChatAgent._runExclusiveChatTurn",
2551
+ kind: "async"
2552
+ }),
2553
+ onChatResponse: channel({
2554
+ channelName: "AIChatAgent.onChatResponse",
2555
+ kind: "sync-stream"
2556
+ })
2557
+ },
2558
+ { instrumentationName: INSTRUMENTATION_NAMES.CLOUDFLARE_AI_CHAT }
2559
+ );
2560
+
2561
+ // src/auto-instrumentations/configs/cloudflare-ai-chat.ts
2562
+ var cloudflareAIChatVersionRange = ">=0.9.0 <0.10.0";
2563
+ var cloudflareAIChatConfigs = [
2564
+ {
2565
+ // AIChatAgent subclasses replace onChatMessage, so there is no stable
2566
+ // public implementation for the transformer to target. This runner is
2567
+ // the narrowest shared boundary around every chat turn; keep the version
2568
+ // range tight because it is an internal method.
2569
+ channelName: cloudflareAIChatChannels.runExclusiveChatTurn.channelName,
2570
+ module: {
2571
+ name: "@cloudflare/ai-chat",
2572
+ versionRange: cloudflareAIChatVersionRange,
2573
+ filePath: "dist/index.js"
2574
+ },
2575
+ functionQuery: {
2576
+ className: "AIChatAgent",
2577
+ methodName: "_runExclusiveChatTurn",
2578
+ kind: "Async"
2579
+ }
2580
+ }
2581
+ ];
2582
+
2425
2583
  // src/instrumentation/plugins/cohere-channels.ts
2426
2584
  var cohereChannels = defineChannels(
2427
2585
  "cohere-ai",
@@ -3207,6 +3365,8 @@ export {
3207
3365
  bedrockRuntimeConfigs,
3208
3366
  aiSDKConfigs,
3209
3367
  claudeAgentSDKConfigs,
3368
+ cloudflareAgentsConfigs,
3369
+ cloudflareThinkConfigs,
3210
3370
  cursorSDKConfigs,
3211
3371
  openAIAgentsCoreConfigs,
3212
3372
  googleGenAIConfigs,
@@ -3214,7 +3374,9 @@ export {
3214
3374
  openRouterAgentConfigs,
3215
3375
  openRouterConfigs,
3216
3376
  mistralConfigs,
3377
+ ollamaConfigs,
3217
3378
  googleADKConfigs,
3379
+ cloudflareAIChatConfigs,
3218
3380
  cohereConfigs,
3219
3381
  groqConfigs,
3220
3382
  genkitConfigs,