braintrust 3.26.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 (57) hide show
  1. package/dev/dist/index.js +2440 -1067
  2. package/dev/dist/index.mjs +1644 -271
  3. package/dist/apply-auto-instrumentation.js +320 -261
  4. package/dist/apply-auto-instrumentation.mjs +118 -59
  5. package/dist/auto-instrumentations/bundler/esbuild.cjs +377 -59
  6. package/dist/auto-instrumentations/bundler/esbuild.mjs +5 -4
  7. package/dist/auto-instrumentations/bundler/next.cjs +379 -61
  8. package/dist/auto-instrumentations/bundler/next.mjs +6 -5
  9. package/dist/auto-instrumentations/bundler/rollup.cjs +377 -59
  10. package/dist/auto-instrumentations/bundler/rollup.mjs +5 -4
  11. package/dist/auto-instrumentations/bundler/vite.cjs +406 -60
  12. package/dist/auto-instrumentations/bundler/vite.mjs +34 -5
  13. package/dist/auto-instrumentations/bundler/webpack-loader.cjs +363 -59
  14. package/dist/auto-instrumentations/bundler/webpack.cjs +377 -59
  15. package/dist/auto-instrumentations/bundler/webpack.mjs +6 -5
  16. package/dist/auto-instrumentations/{chunk-AKKPLXTP.mjs → chunk-2AMDGD65.mjs} +160 -57
  17. package/dist/auto-instrumentations/{chunk-V5LEODRX.mjs → chunk-BW33ULMW.mjs} +1 -1
  18. package/dist/auto-instrumentations/{chunk-XYN63IG5.mjs → chunk-I55G56ZL.mjs} +21 -58
  19. package/dist/auto-instrumentations/{chunk-NRE4QUQR.mjs → chunk-JPUFNW7X.mjs} +140 -0
  20. package/dist/auto-instrumentations/{chunk-6E22MYSW.mjs → chunk-XEYKUBLY.mjs} +30 -4
  21. package/dist/auto-instrumentations/{chunk-XZHHE4Y3.mjs → chunk-ZNHTSSGI.mjs} +155 -2
  22. package/dist/auto-instrumentations/hook.mjs +161 -3
  23. package/dist/auto-instrumentations/index.cjs +296 -1
  24. package/dist/auto-instrumentations/index.d.mts +5 -1
  25. package/dist/auto-instrumentations/index.d.ts +5 -1
  26. package/dist/auto-instrumentations/index.mjs +6 -2
  27. package/dist/auto-instrumentations/loader/cjs-patch.cjs +105 -57
  28. package/dist/auto-instrumentations/loader/cjs-patch.mjs +2 -2
  29. package/dist/auto-instrumentations/loader/esm-hook.mjs +1 -1
  30. package/dist/browser.d.mts +57 -5
  31. package/dist/browser.d.ts +57 -5
  32. package/dist/browser.js +1855 -285
  33. package/dist/browser.mjs +1855 -285
  34. package/dist/{chunk-PN7EWK66.mjs → chunk-CZM5JIQL.mjs} +209 -1
  35. package/dist/{chunk-VYNNEKSA.js → chunk-MF7NU6BT.js} +216 -8
  36. package/dist/{chunk-VRZZQPAA.js → chunk-QRHGVBKU.js} +2403 -1220
  37. package/dist/{chunk-XIZOM2HO.mjs → chunk-YKD22IMR.mjs} +1454 -271
  38. package/dist/cli.js +1645 -272
  39. package/dist/edge-light.d.mts +1 -1
  40. package/dist/edge-light.d.ts +1 -1
  41. package/dist/edge-light.js +1855 -285
  42. package/dist/edge-light.mjs +1855 -285
  43. package/dist/index.d.mts +57 -5
  44. package/dist/index.d.ts +57 -5
  45. package/dist/index.js +600 -413
  46. package/dist/index.mjs +201 -14
  47. package/dist/instrumentation/index.d.mts +8 -0
  48. package/dist/instrumentation/index.d.ts +8 -0
  49. package/dist/instrumentation/index.js +1839 -466
  50. package/dist/instrumentation/index.mjs +1839 -466
  51. package/dist/vitest-evals-reporter.js +45 -43
  52. package/dist/vitest-evals-reporter.mjs +5 -3
  53. package/dist/workerd.d.mts +1 -1
  54. package/dist/workerd.d.ts +1 -1
  55. package/dist/workerd.js +1855 -285
  56. package/dist/workerd.mjs +1855 -285
  57. package/package.json +1 -1
@@ -1,13 +1,42 @@
1
1
  import {
2
2
  unplugin
3
- } from "../chunk-6E22MYSW.mjs";
4
- import "../chunk-XZHHE4Y3.mjs";
5
- import "../chunk-XYN63IG5.mjs";
6
- import "../chunk-NRE4QUQR.mjs";
3
+ } from "../chunk-XEYKUBLY.mjs";
4
+ import "../chunk-ZNHTSSGI.mjs";
5
+ import "../chunk-I55G56ZL.mjs";
6
+ import "../chunk-JPUFNW7X.mjs";
7
+ import "../chunk-P5YLNB2A.mjs";
7
8
 
8
9
  // src/auto-instrumentations/bundler/vite.ts
9
10
  function braintrustVitePlugin(options = {}) {
10
- return unplugin.vite(options);
11
+ const transformPlugin = unplugin.vite(options);
12
+ const optimizeDepsPlugin = {
13
+ name: "braintrust:optimize-deps",
14
+ config() {
15
+ return {
16
+ optimizeDeps: {
17
+ esbuildOptions: {
18
+ plugins: [unplugin.esbuild(options)]
19
+ }
20
+ }
21
+ };
22
+ },
23
+ configEnvironment(name) {
24
+ if (name === "client") {
25
+ return;
26
+ }
27
+ return {
28
+ optimizeDeps: {
29
+ esbuildOptions: {
30
+ plugins: [unplugin.esbuild(options)]
31
+ }
32
+ }
33
+ };
34
+ }
35
+ };
36
+ return [
37
+ optimizeDepsPlugin,
38
+ ...Array.isArray(transformPlugin) ? transformPlugin : [transformPlugin]
39
+ ];
11
40
  }
12
41
  var vitePlugin = unplugin.vite;
13
42
  export {
@@ -40,8 +40,10 @@ var GLOBAL_INSTRUMENTATION_HOOKS_KEY = "__braintrust_instrumentation_hooks";
40
40
  var GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION = 1;
41
41
  var GLOBAL_INSTRUMENTATION_HOOKS_REGISTRY_BRAND = "braintrust.global-instrumentation-hooks.registry";
42
42
  var GLOBAL_INSTRUMENTATION_HOOK_BRAND = "braintrust.global-instrumentation-hooks.hook";
43
+ var GLOBAL_INVOCATION_HOOK_BRAND = "braintrust.global-instrumentation-hooks.invocation-hook";
43
44
  var registryBrand = Symbol.for(GLOBAL_INSTRUMENTATION_HOOKS_REGISTRY_BRAND);
44
45
  var hookBrand = Symbol.for(GLOBAL_INSTRUMENTATION_HOOK_BRAND);
46
+ var invocationHookBrand = Symbol.for(GLOBAL_INVOCATION_HOOK_BRAND);
45
47
  var errorReporter;
46
48
  function reportError(error) {
47
49
  try {
@@ -177,12 +179,69 @@ var traceEvents = [
177
179
  "asyncEnd",
178
180
  "error"
179
181
  ];
182
+ function traceInvocation(hook, operator, target, thisArg, args, additional, callbackIndex = -1) {
183
+ const context = {
184
+ ...additional,
185
+ arguments: args,
186
+ self: thisArg
187
+ };
188
+ const invoke = () => hook.invoke(target, thisArg, args, additional);
189
+ if (operator === "traceCallback") {
190
+ return hook.traceCallback(invoke, callbackIndex, context);
191
+ }
192
+ if (operator === "tracePromise") {
193
+ return hook.tracePromise(invoke, context);
194
+ }
195
+ return hook.traceSync(invoke, context);
196
+ }
197
+ var InvocationHook = class {
198
+ interceptors = [];
199
+ get hasInterceptors() {
200
+ return this.interceptors.length > 0;
201
+ }
202
+ intercept(interceptor) {
203
+ if (typeof interceptor !== "function") {
204
+ throw new TypeError("interceptor must be a function");
205
+ }
206
+ this.interceptors = [...this.interceptors, interceptor];
207
+ let active = true;
208
+ return () => {
209
+ if (!active) {
210
+ return;
211
+ }
212
+ active = false;
213
+ const index = this.interceptors.indexOf(interceptor);
214
+ if (index !== -1) {
215
+ this.interceptors = [
216
+ ...this.interceptors.slice(0, index),
217
+ ...this.interceptors.slice(index + 1)
218
+ ];
219
+ }
220
+ };
221
+ }
222
+ invoke(target, thisArg, args, additional) {
223
+ const interceptors = this.interceptors;
224
+ if (interceptors.length === 0) {
225
+ return Reflect.apply(target, thisArg, args);
226
+ }
227
+ let next = target;
228
+ for (let index = interceptors.length - 1; index >= 0; index -= 1) {
229
+ const interceptor = interceptors[index];
230
+ const downstream = next;
231
+ next = function(...nextArgs) {
232
+ return interceptor(downstream, this, nextArgs, additional);
233
+ };
234
+ }
235
+ return Reflect.apply(next, thisArg, args);
236
+ }
237
+ };
180
238
  var TracingHook = class {
181
239
  start;
182
240
  end;
183
241
  asyncStart;
184
242
  asyncEnd;
185
243
  error;
244
+ invocationHook = new InvocationHook();
186
245
  constructor(nameOrChannels) {
187
246
  Object.defineProperty(this, hookBrand, {
188
247
  configurable: false,
@@ -190,6 +249,12 @@ var TracingHook = class {
190
249
  value: GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION,
191
250
  writable: false
192
251
  });
252
+ Object.defineProperty(this, invocationHookBrand, {
253
+ configurable: false,
254
+ enumerable: false,
255
+ value: GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION,
256
+ writable: false
257
+ });
193
258
  if (typeof nameOrChannels === "string") {
194
259
  this.start = new HookChannel(`tracing:${nameOrChannels}:start`);
195
260
  this.end = new HookChannel(`tracing:${nameOrChannels}:end`);
@@ -207,6 +272,26 @@ var TracingHook = class {
207
272
  get hasSubscribers() {
208
273
  return this.start.hasSubscribers || this.end.hasSubscribers || this.asyncStart.hasSubscribers || this.asyncEnd.hasSubscribers || this.error.hasSubscribers;
209
274
  }
275
+ get hasInterceptors() {
276
+ return this.invocationHook.hasInterceptors;
277
+ }
278
+ intercept(interceptor) {
279
+ return this.invocationHook.intercept(interceptor);
280
+ }
281
+ invoke(target, thisArg, args, additional) {
282
+ return this.invocationHook.invoke(target, thisArg, args, additional);
283
+ }
284
+ traceInvocation(operator, target, thisArg, args, additional, callbackIndex = -1) {
285
+ return traceInvocation(
286
+ this,
287
+ operator,
288
+ target,
289
+ thisArg,
290
+ args,
291
+ additional,
292
+ callbackIndex
293
+ );
294
+ }
210
295
  subscribe(handlers) {
211
296
  for (const eventName of traceEvents) {
212
297
  const handler = handlers[eventName];
@@ -428,6 +513,60 @@ function hasTracingHookShape(value) {
428
513
  return false;
429
514
  }
430
515
  }
516
+ function hasInvocationHookShape(value) {
517
+ if (typeof value !== "object" && typeof value !== "function" || value === null) {
518
+ return false;
519
+ }
520
+ try {
521
+ const hook = value;
522
+ return value[invocationHookBrand] === GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION && typeof hook.hasInterceptors === "boolean" && typeof hook.intercept === "function" && typeof hook.invoke === "function";
523
+ } catch {
524
+ return false;
525
+ }
526
+ }
527
+ function installInvocationHook(value) {
528
+ const hasInvocationHook = hasInvocationHookShape(value);
529
+ const invocationHook = new InvocationHook();
530
+ try {
531
+ if (!hasInvocationHook) {
532
+ Object.defineProperties(value, {
533
+ [invocationHookBrand]: {
534
+ configurable: false,
535
+ enumerable: false,
536
+ value: GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION,
537
+ writable: false
538
+ },
539
+ hasInterceptors: {
540
+ configurable: false,
541
+ enumerable: false,
542
+ get: () => invocationHook.hasInterceptors
543
+ },
544
+ intercept: {
545
+ configurable: false,
546
+ enumerable: false,
547
+ value: invocationHook.intercept.bind(invocationHook),
548
+ writable: false
549
+ },
550
+ invoke: {
551
+ configurable: false,
552
+ enumerable: false,
553
+ value: invocationHook.invoke.bind(invocationHook),
554
+ writable: false
555
+ }
556
+ });
557
+ }
558
+ if (typeof value.traceInvocation !== "function") {
559
+ Object.defineProperty(value, "traceInvocation", {
560
+ configurable: false,
561
+ enumerable: false,
562
+ value: traceInvocation.bind(void 0, value),
563
+ writable: false
564
+ });
565
+ }
566
+ } catch (error) {
567
+ reportError(error);
568
+ }
569
+ }
431
570
  function isCompatibleTracingHook(value) {
432
571
  try {
433
572
  return value[hookBrand] === GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION && hasTracingHookShape(value);
@@ -514,6 +653,7 @@ function newGlobalTracingChannel(nameOrChannels) {
514
653
  return inertTracingHook;
515
654
  }
516
655
  if (isCompatibleTracingHook(existing)) {
656
+ installInvocationHook(existing);
517
657
  return existing;
518
658
  }
519
659
  if (existing !== void 0) {
@@ -550,8 +690,7 @@ var transforms = {
550
690
  tracingHookDeclaration(state, node) {
551
691
  const {
552
692
  channelName,
553
- module: { name },
554
- operator
693
+ module: { name }
555
694
  } = state;
556
695
  const channelVariable = formatChannelVariable(channelName);
557
696
  const channelGetter = formatChannelGetter(channelName);
@@ -564,7 +703,7 @@ var transforms = {
564
703
  return;
565
704
  }
566
705
  const sharedHookLookup = hasSharedHookLookup ? "" : `
567
- const ${SHARED_HOOK_LOOKUP} = (__bt$hookName, __bt$operator) => {
706
+ const ${SHARED_HOOK_LOOKUP} = (__bt$hookName) => {
568
707
  try {
569
708
  const __bt$hooks = globalThis[${JSON.stringify(
570
709
  GLOBAL_INSTRUMENTATION_HOOKS_KEY
@@ -586,8 +725,7 @@ var transforms = {
586
725
  __bt$hook[Symbol.for(${JSON.stringify(
587
726
  GLOBAL_INSTRUMENTATION_HOOK_BRAND
588
727
  )})] !== ${GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION} ||
589
- typeof __bt$hook.hasSubscribers !== "boolean" ||
590
- typeof __bt$hook[__bt$operator] !== "function"
728
+ typeof __bt$hook.traceInvocation !== "function"
591
729
  ) return undefined;
592
730
  return __bt$hook;
593
731
  } catch {
@@ -600,8 +738,7 @@ var transforms = {
600
738
  let ${channelVariable};
601
739
  const ${channelGetter} = () =>
602
740
  ${channelVariable} ??= ${SHARED_HOOK_LOOKUP}(
603
- ${JSON.stringify(`orchestrion:${name}:${channelName}`)},
604
- ${JSON.stringify(operator)}
741
+ ${JSON.stringify(`orchestrion:${name}:${channelName}`)}
605
742
  );
606
743
  `;
607
744
  const sharedHookLookupIndex = node.body.findIndex(
@@ -676,28 +813,18 @@ function traceInstanceMethod(state, node, program) {
676
813
  ctor.value.body.body.push(...ctorBody);
677
814
  }
678
815
  function wrap(state, node) {
679
- const { operator, moduleVersion } = state;
680
- const wrapper = operator === "traceCallback" ? wrapCallback(state) : operator === "tracePromise" ? wrapPromise(state) : wrapSync(state);
816
+ const wrapper = wrapInvocation(state);
681
817
  const block = wrapper.body[0].body;
682
818
  const common = (0, import_meriyah.parse)(
683
819
  node.type === "ArrowFunctionExpression" ? `
684
- const __bt$ctx = {
685
- arguments,
686
- moduleVersion: ${JSON.stringify(moduleVersion)}
687
- };
688
- const __bt$traced = () => {
820
+ const __bt$target = (...__bt$args) => {
689
821
  const __bt$wrapped = () => {};
690
- return __bt$wrapped(...arguments);
822
+ return __bt$wrapped(...__bt$args);
691
823
  };
692
824
  ` : `
693
- const __bt$ctx = {
694
- arguments,
695
- self: this,
696
- moduleVersion: ${JSON.stringify(moduleVersion)}
697
- };
698
- const __bt$traced = () => {
825
+ const __bt$target = function (...__bt$args) {
699
826
  const __bt$wrapped = () => {};
700
- return __bt$wrapped.apply(this, arguments);
827
+ return __bt$wrapped.apply(this, __bt$args);
701
828
  };
702
829
  `
703
830
  ).body;
@@ -739,49 +866,25 @@ function wrapSuper(node) {
739
866
  node.body.body.unshift((0, import_meriyah.parse)("const __bt$super = {}").body[0]);
740
867
  }
741
868
  }
742
- function wrapCallback(state) {
743
- const {
744
- channelName,
745
- functionQuery: { callbackIndex = -1 }
746
- } = state;
869
+ function wrapInvocation(state) {
870
+ const { channelName, moduleVersion, operator, functionQuery } = state;
747
871
  const channelGetter = formatChannelGetter(channelName);
872
+ const callbackIndex = functionQuery.callbackIndex ?? -1;
748
873
  return (0, import_meriyah.parse)(`
749
874
  function wrapper () {
750
875
  const __bt$hook = ${channelGetter}();
751
- if (!__bt$hook?.hasSubscribers) return __bt$traced();
752
- __bt$ctx.self ??= this;
753
- return __bt$hook.traceCallback(
754
- __bt$traced,
755
- ${callbackIndex},
756
- __bt$ctx
876
+ if (!__bt$hook) return __bt$target.apply(this, arguments);
877
+ return __bt$hook.traceInvocation(
878
+ ${JSON.stringify(operator)},
879
+ __bt$target,
880
+ this,
881
+ arguments,
882
+ { moduleVersion: ${JSON.stringify(moduleVersion)} },
883
+ ${callbackIndex}
757
884
  );
758
885
  }
759
886
  `);
760
887
  }
761
- function wrapPromise(state) {
762
- const { channelName } = state;
763
- const channelGetter = formatChannelGetter(channelName);
764
- return (0, import_meriyah.parse)(`
765
- function wrapper () {
766
- const __bt$hook = ${channelGetter}();
767
- if (!__bt$hook?.hasSubscribers) return __bt$traced();
768
- __bt$ctx.self ??= this;
769
- return __bt$hook.tracePromise(__bt$traced, __bt$ctx);
770
- }
771
- `);
772
- }
773
- function wrapSync(state) {
774
- const { channelName } = state;
775
- const channelGetter = formatChannelGetter(channelName);
776
- return (0, import_meriyah.parse)(`
777
- function wrapper () {
778
- const __bt$hook = ${channelGetter}();
779
- if (!__bt$hook?.hasSubscribers) return __bt$traced();
780
- __bt$ctx.self ??= this;
781
- return __bt$hook.traceSync(__bt$traced, __bt$ctx);
782
- }
783
- `);
784
- }
785
888
 
786
889
  // src/auto-instrumentations/orchestrion-js/transformer.ts
787
890
  var Transformer = class {
@@ -1056,6 +1159,7 @@ var envIntegrationAliases = {
1056
1159
  cloudflareaichat: "cloudflareAIChat",
1057
1160
  "cloudflare-ai-chat": "cloudflareAIChat",
1058
1161
  "@cloudflare/ai-chat": "cloudflareAIChat",
1162
+ cloudflarethink: "cloudflareThink",
1059
1163
  cursor: "cursor",
1060
1164
  "cursor-sdk": "cursorSDK",
1061
1165
  cursorsdk: "cursorSDK",
@@ -1076,6 +1180,7 @@ var envIntegrationAliases = {
1076
1180
  openrouteragent: "openrouterAgent",
1077
1181
  "openrouter-agent": "openrouterAgent",
1078
1182
  mistral: "mistral",
1183
+ ollama: "ollama",
1079
1184
  googleadk: "googleADK",
1080
1185
  "google-adk": "googleADK",
1081
1186
  cohere: "cohere",
@@ -1161,11 +1266,21 @@ function defineChannels(pkg, channels, options) {
1161
1266
  const tracingChannel2 = () => isomorph_default.newTracingChannel(
1162
1267
  fullChannelName
1163
1268
  );
1269
+ const intercept2 = (interceptor) => {
1270
+ const hook = tracingChannel2();
1271
+ return typeof hook.intercept === "function" ? hook.intercept(interceptor) : () => {
1272
+ };
1273
+ };
1164
1274
  return [
1165
1275
  key,
1166
1276
  {
1167
1277
  ...asyncSpec,
1168
1278
  instrumentationName,
1279
+ intercept: intercept2,
1280
+ invoke: (target, thisArg, args, additional) => {
1281
+ const hook = tracingChannel2();
1282
+ return typeof hook.invoke === "function" ? hook.invoke(target, thisArg, args, additional) : Reflect.apply(target, thisArg, args);
1283
+ },
1169
1284
  tracingChannel: tracingChannel2,
1170
1285
  tracePromise: (fn, context) => tracingChannel2().tracePromise(
1171
1286
  fn,
@@ -1179,11 +1294,21 @@ function defineChannels(pkg, channels, options) {
1179
1294
  const tracingChannel = () => isomorph_default.newTracingChannel(
1180
1295
  fullChannelName
1181
1296
  );
1297
+ const intercept = (interceptor) => {
1298
+ const hook = tracingChannel();
1299
+ return typeof hook.intercept === "function" ? hook.intercept(interceptor) : () => {
1300
+ };
1301
+ };
1182
1302
  return [
1183
1303
  key,
1184
1304
  {
1185
1305
  ...syncSpec,
1186
1306
  instrumentationName,
1307
+ intercept,
1308
+ invoke: (target, thisArg, args, additional) => {
1309
+ const hook = tracingChannel();
1310
+ return typeof hook.invoke === "function" ? hook.invoke(target, thisArg, args, additional) : Reflect.apply(target, thisArg, args);
1311
+ },
1187
1312
  tracingChannel,
1188
1313
  traceSync: (fn, context) => tracingChannel().traceSync(
1189
1314
  fn,
@@ -1205,6 +1330,7 @@ var INSTRUMENTATION_NAMES = {
1205
1330
  CLAUDE_AGENT_SDK: "claude-agent-sdk",
1206
1331
  CLOUDFLARE_AI_CHAT: "cloudflare-ai-chat",
1207
1332
  CLOUDFLARE_AGENTS: "cloudflare-agents",
1333
+ CLOUDFLARE_THINK: "cloudflare-think",
1208
1334
  COHERE: "cohere",
1209
1335
  CURSOR_SDK: "cursor-sdk",
1210
1336
  EVE: "eve",
@@ -1219,6 +1345,7 @@ var INSTRUMENTATION_NAMES = {
1219
1345
  LANGSMITH: "langsmith",
1220
1346
  MASTRA: "mastra",
1221
1347
  MISTRAL: "mistral",
1348
+ OLLAMA: "ollama",
1222
1349
  OPENAI: "openai",
1223
1350
  OPENAI_AGENTS: "openai-agents",
1224
1351
  OPENAI_CODEX: "openai-codex",
@@ -1735,6 +1862,14 @@ var anthropicChannels = defineChannels(
1735
1862
  betaMessagesToolRunner: channel({
1736
1863
  channelName: "beta.messages.toolRunner",
1737
1864
  kind: "sync-stream"
1865
+ }),
1866
+ betaSessionsEventsStream: channel({
1867
+ channelName: "beta.sessions.events.stream",
1868
+ kind: "async"
1869
+ }),
1870
+ betaSessionsThreadsEventsStream: channel({
1871
+ channelName: "beta.sessions.threads.events.stream",
1872
+ kind: "async"
1738
1873
  })
1739
1874
  },
1740
1875
  { instrumentationName: INSTRUMENTATION_NAMES.ANTHROPIC }
@@ -1853,7 +1988,40 @@ var anthropicConfigs = [
1853
1988
  methodName: "toolRunner",
1854
1989
  kind: "Sync"
1855
1990
  }
1856
- }
1991
+ },
1992
+ // Managed Agents Sessions event streams are discovered automatically, but
1993
+ // remain passive until the user calls collectAnthropicSession() on the
1994
+ // returned stream.
1995
+ ...["mjs", "js"].map(
1996
+ (extension) => ({
1997
+ channelName: anthropicChannels.betaSessionsEventsStream.channelName,
1998
+ module: {
1999
+ name: "@anthropic-ai/sdk",
2000
+ versionRange: ">=0.86.0",
2001
+ filePath: `resources/beta/sessions/events.${extension}`
2002
+ },
2003
+ functionQuery: {
2004
+ className: "Events",
2005
+ methodName: "stream",
2006
+ kind: "Async"
2007
+ }
2008
+ })
2009
+ ),
2010
+ ...["mjs", "js"].map(
2011
+ (extension) => ({
2012
+ channelName: anthropicChannels.betaSessionsThreadsEventsStream.channelName,
2013
+ module: {
2014
+ name: "@anthropic-ai/sdk",
2015
+ versionRange: ">=0.86.0",
2016
+ filePath: `resources/beta/sessions/threads/events.${extension}`
2017
+ },
2018
+ functionQuery: {
2019
+ className: "Events",
2020
+ methodName: "stream",
2021
+ kind: "Async"
2022
+ }
2023
+ })
2024
+ )
1857
2025
  ];
1858
2026
 
1859
2027
  // src/instrumentation/plugins/bedrock-runtime-channels.ts
@@ -2050,6 +2218,36 @@ var cloudflareAgentsConfigs = [
2050
2218
  }
2051
2219
  ];
2052
2220
 
2221
+ // src/instrumentation/plugins/cloudflare-think-channels.ts
2222
+ var cloudflareThinkChannels = defineChannels(
2223
+ "@cloudflare/think",
2224
+ {
2225
+ runInferenceLoop: channel({
2226
+ channelName: "Think.runInferenceLoop",
2227
+ kind: "async"
2228
+ })
2229
+ },
2230
+ { instrumentationName: INSTRUMENTATION_NAMES.CLOUDFLARE_THINK }
2231
+ );
2232
+
2233
+ // src/auto-instrumentations/configs/cloudflare-think.ts
2234
+ var cloudflareThinkVersionRange = ">=0.13.0 <0.14.0";
2235
+ var cloudflareThinkConfigs = [
2236
+ {
2237
+ channelName: cloudflareThinkChannels.runInferenceLoop.channelName,
2238
+ module: {
2239
+ name: "@cloudflare/think",
2240
+ versionRange: cloudflareThinkVersionRange,
2241
+ filePath: "dist/think.js"
2242
+ },
2243
+ functionQuery: {
2244
+ className: "Think",
2245
+ methodName: "_runInferenceLoop",
2246
+ kind: "Async"
2247
+ }
2248
+ }
2249
+ ];
2250
+
2053
2251
  // src/instrumentation/plugins/cohere-channels.ts
2054
2252
  var cohereChannels = defineChannels(
2055
2253
  "cohere-ai",
@@ -3933,6 +4131,51 @@ var mistralConfigs = [
3933
4131
  }
3934
4132
  ];
3935
4133
 
4134
+ // src/instrumentation/plugins/ollama-channels.ts
4135
+ var ollamaChannels = defineChannels(
4136
+ "ollama",
4137
+ {
4138
+ chat: channel({
4139
+ channelName: "chat",
4140
+ kind: "async"
4141
+ }),
4142
+ generate: channel({
4143
+ channelName: "generate",
4144
+ kind: "async"
4145
+ }),
4146
+ embed: channel({
4147
+ channelName: "embed",
4148
+ kind: "async"
4149
+ })
4150
+ },
4151
+ { instrumentationName: INSTRUMENTATION_NAMES.OLLAMA }
4152
+ );
4153
+
4154
+ // src/auto-instrumentations/configs/ollama.ts
4155
+ var methods = [
4156
+ ["chat", ollamaChannels.chat.channelName],
4157
+ ["generate", ollamaChannels.generate.channelName],
4158
+ ["embed", ollamaChannels.embed.channelName]
4159
+ ];
4160
+ var implementationFiles = ["dist/browser.mjs", "dist/browser.cjs"];
4161
+ var ollamaConfigs = [
4162
+ ...implementationFiles.flatMap(
4163
+ (filePath) => methods.map(([methodName, channelName]) => ({
4164
+ channelName,
4165
+ module: {
4166
+ name: "ollama",
4167
+ versionRange: ">=0.6.0 <0.7.0",
4168
+ filePath
4169
+ },
4170
+ functionQuery: {
4171
+ className: "Ollama",
4172
+ methodName,
4173
+ kind: "Async"
4174
+ }
4175
+ }))
4176
+ )
4177
+ ];
4178
+
3936
4179
  // src/instrumentation/plugins/openai-agents-channels.ts
3937
4180
  var openAIAgentsCoreChannels = defineChannels(
3938
4181
  "@openai/agents-core",
@@ -4342,6 +4585,19 @@ var openRouterConfigs = [
4342
4585
  kind: "Async"
4343
4586
  }
4344
4587
  },
4588
+ {
4589
+ channelName: openRouterChannels.betaResponsesSend.channelName,
4590
+ module: {
4591
+ name: "@openrouter/sdk",
4592
+ versionRange: ">=1.1.2 <2.0.0",
4593
+ filePath: "esm/sdk/betaresponses.js"
4594
+ },
4595
+ functionQuery: {
4596
+ className: "BetaResponses",
4597
+ methodName: "send",
4598
+ kind: "Async"
4599
+ }
4600
+ },
4345
4601
  {
4346
4602
  channelName: openRouterChannels.callModel.channelName,
4347
4603
  module: {
@@ -4515,6 +4771,10 @@ var defaultInstrumentationConfigGroups = [
4515
4771
  integrations: ["cloudflareAgents"],
4516
4772
  configs: cloudflareAgentsConfigs
4517
4773
  },
4774
+ {
4775
+ integrations: ["cloudflareThink"],
4776
+ configs: cloudflareThinkConfigs
4777
+ },
4518
4778
  { integrations: ["cursor", "cursorSDK"], configs: cursorSDKConfigs },
4519
4779
  {
4520
4780
  integrations: ["openAIAgents"],
@@ -4539,6 +4799,7 @@ var defaultInstrumentationConfigGroups = [
4539
4799
  configs: openRouterAgentConfigs
4540
4800
  },
4541
4801
  { integrations: ["mistral"], configs: mistralConfigs },
4802
+ { integrations: ["ollama"], configs: ollamaConfigs },
4542
4803
  { integrations: ["googleADK"], configs: googleADKConfigs },
4543
4804
  { integrations: ["cohere"], configs: cohereConfigs },
4544
4805
  { integrations: ["groq"], configs: groqConfigs },
@@ -4794,6 +5055,49 @@ function applySpecialCasePatch(input) {
4794
5055
  return null;
4795
5056
  }
4796
5057
 
5058
+ // src/auto-instrumentations/loader/get-package-version.ts
5059
+ var import_node_fs = require("fs");
5060
+ var import_node_path = require("path");
5061
+ var packageNames = /* @__PURE__ */ new Map();
5062
+ function readPackageJson(baseDir) {
5063
+ try {
5064
+ const packageJsonPath = (0, import_node_path.join)(baseDir, "package.json");
5065
+ const jsonFile = (0, import_node_fs.readFileSync)(packageJsonPath, "utf8");
5066
+ return JSON.parse(jsonFile);
5067
+ } catch {
5068
+ return void 0;
5069
+ }
5070
+ }
5071
+ function resolvePackageBaseDir(baseDir) {
5072
+ try {
5073
+ return (0, import_node_fs.realpathSync)(baseDir);
5074
+ } catch {
5075
+ return baseDir;
5076
+ }
5077
+ }
5078
+ function readPackageJsonWithFallback(baseDir) {
5079
+ const packageJson = readPackageJson(baseDir);
5080
+ if (packageJson) {
5081
+ return packageJson;
5082
+ }
5083
+ const resolvedBaseDir = resolvePackageBaseDir(baseDir);
5084
+ if (resolvedBaseDir === baseDir) {
5085
+ return void 0;
5086
+ }
5087
+ return readPackageJson(resolvedBaseDir);
5088
+ }
5089
+ function getPackageName(baseDir) {
5090
+ if (packageNames.has(baseDir)) {
5091
+ return packageNames.get(baseDir);
5092
+ }
5093
+ const packageJson = readPackageJsonWithFallback(baseDir);
5094
+ if (typeof packageJson?.name === "string") {
5095
+ packageNames.set(baseDir, packageJson.name);
5096
+ return packageJson.name;
5097
+ }
5098
+ return void 0;
5099
+ }
5100
+
4797
5101
  // src/auto-instrumentations/bundler/webpack-loader.ts
4798
5102
  function getModuleVersion(basedir) {
4799
5103
  try {
@@ -4844,7 +5148,7 @@ function codeTransformerLoader(code, inputSourceMap) {
4844
5148
  if (!moduleDetails) {
4845
5149
  return callback(null, code, inputSourceMap);
4846
5150
  }
4847
- const moduleName = moduleDetails.name;
5151
+ const moduleName = getPackageName(moduleDetails.basedir) ?? moduleDetails.name;
4848
5152
  const normalizedModulePath = moduleDetails.path.replace(/\\/g, "/");
4849
5153
  const patched = applySpecialCasePatch({
4850
5154
  packageName: moduleName,