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
@@ -34,7 +34,7 @@ __export(next_exports, {
34
34
  });
35
35
  module.exports = __toCommonJS(next_exports);
36
36
  var import_node_module = require("module");
37
- var import_node_path = require("path");
37
+ var import_node_path2 = require("path");
38
38
 
39
39
  // src/auto-instrumentations/bundler/plugin.ts
40
40
  var import_unplugin = require("unplugin");
@@ -57,8 +57,10 @@ var GLOBAL_INSTRUMENTATION_HOOKS_KEY = "__braintrust_instrumentation_hooks";
57
57
  var GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION = 1;
58
58
  var GLOBAL_INSTRUMENTATION_HOOKS_REGISTRY_BRAND = "braintrust.global-instrumentation-hooks.registry";
59
59
  var GLOBAL_INSTRUMENTATION_HOOK_BRAND = "braintrust.global-instrumentation-hooks.hook";
60
+ var GLOBAL_INVOCATION_HOOK_BRAND = "braintrust.global-instrumentation-hooks.invocation-hook";
60
61
  var registryBrand = Symbol.for(GLOBAL_INSTRUMENTATION_HOOKS_REGISTRY_BRAND);
61
62
  var hookBrand = Symbol.for(GLOBAL_INSTRUMENTATION_HOOK_BRAND);
63
+ var invocationHookBrand = Symbol.for(GLOBAL_INVOCATION_HOOK_BRAND);
62
64
  var errorReporter;
63
65
  function reportError(error) {
64
66
  try {
@@ -194,12 +196,69 @@ var traceEvents = [
194
196
  "asyncEnd",
195
197
  "error"
196
198
  ];
199
+ function traceInvocation(hook, operator, target, thisArg, args, additional, callbackIndex = -1) {
200
+ const context = {
201
+ ...additional,
202
+ arguments: args,
203
+ self: thisArg
204
+ };
205
+ const invoke = () => hook.invoke(target, thisArg, args, additional);
206
+ if (operator === "traceCallback") {
207
+ return hook.traceCallback(invoke, callbackIndex, context);
208
+ }
209
+ if (operator === "tracePromise") {
210
+ return hook.tracePromise(invoke, context);
211
+ }
212
+ return hook.traceSync(invoke, context);
213
+ }
214
+ var InvocationHook = class {
215
+ interceptors = [];
216
+ get hasInterceptors() {
217
+ return this.interceptors.length > 0;
218
+ }
219
+ intercept(interceptor) {
220
+ if (typeof interceptor !== "function") {
221
+ throw new TypeError("interceptor must be a function");
222
+ }
223
+ this.interceptors = [...this.interceptors, interceptor];
224
+ let active = true;
225
+ return () => {
226
+ if (!active) {
227
+ return;
228
+ }
229
+ active = false;
230
+ const index = this.interceptors.indexOf(interceptor);
231
+ if (index !== -1) {
232
+ this.interceptors = [
233
+ ...this.interceptors.slice(0, index),
234
+ ...this.interceptors.slice(index + 1)
235
+ ];
236
+ }
237
+ };
238
+ }
239
+ invoke(target, thisArg, args, additional) {
240
+ const interceptors = this.interceptors;
241
+ if (interceptors.length === 0) {
242
+ return Reflect.apply(target, thisArg, args);
243
+ }
244
+ let next = target;
245
+ for (let index = interceptors.length - 1; index >= 0; index -= 1) {
246
+ const interceptor = interceptors[index];
247
+ const downstream = next;
248
+ next = function(...nextArgs) {
249
+ return interceptor(downstream, this, nextArgs, additional);
250
+ };
251
+ }
252
+ return Reflect.apply(next, thisArg, args);
253
+ }
254
+ };
197
255
  var TracingHook = class {
198
256
  start;
199
257
  end;
200
258
  asyncStart;
201
259
  asyncEnd;
202
260
  error;
261
+ invocationHook = new InvocationHook();
203
262
  constructor(nameOrChannels) {
204
263
  Object.defineProperty(this, hookBrand, {
205
264
  configurable: false,
@@ -207,6 +266,12 @@ var TracingHook = class {
207
266
  value: GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION,
208
267
  writable: false
209
268
  });
269
+ Object.defineProperty(this, invocationHookBrand, {
270
+ configurable: false,
271
+ enumerable: false,
272
+ value: GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION,
273
+ writable: false
274
+ });
210
275
  if (typeof nameOrChannels === "string") {
211
276
  this.start = new HookChannel(`tracing:${nameOrChannels}:start`);
212
277
  this.end = new HookChannel(`tracing:${nameOrChannels}:end`);
@@ -224,6 +289,26 @@ var TracingHook = class {
224
289
  get hasSubscribers() {
225
290
  return this.start.hasSubscribers || this.end.hasSubscribers || this.asyncStart.hasSubscribers || this.asyncEnd.hasSubscribers || this.error.hasSubscribers;
226
291
  }
292
+ get hasInterceptors() {
293
+ return this.invocationHook.hasInterceptors;
294
+ }
295
+ intercept(interceptor) {
296
+ return this.invocationHook.intercept(interceptor);
297
+ }
298
+ invoke(target, thisArg, args, additional) {
299
+ return this.invocationHook.invoke(target, thisArg, args, additional);
300
+ }
301
+ traceInvocation(operator, target, thisArg, args, additional, callbackIndex = -1) {
302
+ return traceInvocation(
303
+ this,
304
+ operator,
305
+ target,
306
+ thisArg,
307
+ args,
308
+ additional,
309
+ callbackIndex
310
+ );
311
+ }
227
312
  subscribe(handlers) {
228
313
  for (const eventName of traceEvents) {
229
314
  const handler = handlers[eventName];
@@ -445,6 +530,60 @@ function hasTracingHookShape(value) {
445
530
  return false;
446
531
  }
447
532
  }
533
+ function hasInvocationHookShape(value) {
534
+ if (typeof value !== "object" && typeof value !== "function" || value === null) {
535
+ return false;
536
+ }
537
+ try {
538
+ const hook = value;
539
+ return value[invocationHookBrand] === GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION && typeof hook.hasInterceptors === "boolean" && typeof hook.intercept === "function" && typeof hook.invoke === "function";
540
+ } catch {
541
+ return false;
542
+ }
543
+ }
544
+ function installInvocationHook(value) {
545
+ const hasInvocationHook = hasInvocationHookShape(value);
546
+ const invocationHook = new InvocationHook();
547
+ try {
548
+ if (!hasInvocationHook) {
549
+ Object.defineProperties(value, {
550
+ [invocationHookBrand]: {
551
+ configurable: false,
552
+ enumerable: false,
553
+ value: GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION,
554
+ writable: false
555
+ },
556
+ hasInterceptors: {
557
+ configurable: false,
558
+ enumerable: false,
559
+ get: () => invocationHook.hasInterceptors
560
+ },
561
+ intercept: {
562
+ configurable: false,
563
+ enumerable: false,
564
+ value: invocationHook.intercept.bind(invocationHook),
565
+ writable: false
566
+ },
567
+ invoke: {
568
+ configurable: false,
569
+ enumerable: false,
570
+ value: invocationHook.invoke.bind(invocationHook),
571
+ writable: false
572
+ }
573
+ });
574
+ }
575
+ if (typeof value.traceInvocation !== "function") {
576
+ Object.defineProperty(value, "traceInvocation", {
577
+ configurable: false,
578
+ enumerable: false,
579
+ value: traceInvocation.bind(void 0, value),
580
+ writable: false
581
+ });
582
+ }
583
+ } catch (error) {
584
+ reportError(error);
585
+ }
586
+ }
448
587
  function isCompatibleTracingHook(value) {
449
588
  try {
450
589
  return value[hookBrand] === GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION && hasTracingHookShape(value);
@@ -531,6 +670,7 @@ function newGlobalTracingChannel(nameOrChannels) {
531
670
  return inertTracingHook;
532
671
  }
533
672
  if (isCompatibleTracingHook(existing)) {
673
+ installInvocationHook(existing);
534
674
  return existing;
535
675
  }
536
676
  if (existing !== void 0) {
@@ -567,8 +707,7 @@ var transforms = {
567
707
  tracingHookDeclaration(state, node) {
568
708
  const {
569
709
  channelName,
570
- module: { name },
571
- operator
710
+ module: { name }
572
711
  } = state;
573
712
  const channelVariable = formatChannelVariable(channelName);
574
713
  const channelGetter = formatChannelGetter(channelName);
@@ -581,7 +720,7 @@ var transforms = {
581
720
  return;
582
721
  }
583
722
  const sharedHookLookup = hasSharedHookLookup ? "" : `
584
- const ${SHARED_HOOK_LOOKUP} = (__bt$hookName, __bt$operator) => {
723
+ const ${SHARED_HOOK_LOOKUP} = (__bt$hookName) => {
585
724
  try {
586
725
  const __bt$hooks = globalThis[${JSON.stringify(
587
726
  GLOBAL_INSTRUMENTATION_HOOKS_KEY
@@ -603,8 +742,7 @@ var transforms = {
603
742
  __bt$hook[Symbol.for(${JSON.stringify(
604
743
  GLOBAL_INSTRUMENTATION_HOOK_BRAND
605
744
  )})] !== ${GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION} ||
606
- typeof __bt$hook.hasSubscribers !== "boolean" ||
607
- typeof __bt$hook[__bt$operator] !== "function"
745
+ typeof __bt$hook.traceInvocation !== "function"
608
746
  ) return undefined;
609
747
  return __bt$hook;
610
748
  } catch {
@@ -617,8 +755,7 @@ var transforms = {
617
755
  let ${channelVariable};
618
756
  const ${channelGetter} = () =>
619
757
  ${channelVariable} ??= ${SHARED_HOOK_LOOKUP}(
620
- ${JSON.stringify(`orchestrion:${name}:${channelName}`)},
621
- ${JSON.stringify(operator)}
758
+ ${JSON.stringify(`orchestrion:${name}:${channelName}`)}
622
759
  );
623
760
  `;
624
761
  const sharedHookLookupIndex = node.body.findIndex(
@@ -693,28 +830,18 @@ function traceInstanceMethod(state, node, program) {
693
830
  ctor.value.body.body.push(...ctorBody);
694
831
  }
695
832
  function wrap(state, node) {
696
- const { operator, moduleVersion } = state;
697
- const wrapper = operator === "traceCallback" ? wrapCallback(state) : operator === "tracePromise" ? wrapPromise(state) : wrapSync(state);
833
+ const wrapper = wrapInvocation(state);
698
834
  const block = wrapper.body[0].body;
699
835
  const common = (0, import_meriyah.parse)(
700
836
  node.type === "ArrowFunctionExpression" ? `
701
- const __bt$ctx = {
702
- arguments,
703
- moduleVersion: ${JSON.stringify(moduleVersion)}
704
- };
705
- const __bt$traced = () => {
837
+ const __bt$target = (...__bt$args) => {
706
838
  const __bt$wrapped = () => {};
707
- return __bt$wrapped(...arguments);
839
+ return __bt$wrapped(...__bt$args);
708
840
  };
709
841
  ` : `
710
- const __bt$ctx = {
711
- arguments,
712
- self: this,
713
- moduleVersion: ${JSON.stringify(moduleVersion)}
714
- };
715
- const __bt$traced = () => {
842
+ const __bt$target = function (...__bt$args) {
716
843
  const __bt$wrapped = () => {};
717
- return __bt$wrapped.apply(this, arguments);
844
+ return __bt$wrapped.apply(this, __bt$args);
718
845
  };
719
846
  `
720
847
  ).body;
@@ -756,49 +883,25 @@ function wrapSuper(node) {
756
883
  node.body.body.unshift((0, import_meriyah.parse)("const __bt$super = {}").body[0]);
757
884
  }
758
885
  }
759
- function wrapCallback(state) {
760
- const {
761
- channelName,
762
- functionQuery: { callbackIndex = -1 }
763
- } = state;
886
+ function wrapInvocation(state) {
887
+ const { channelName, moduleVersion, operator, functionQuery } = state;
764
888
  const channelGetter = formatChannelGetter(channelName);
889
+ const callbackIndex = functionQuery.callbackIndex ?? -1;
765
890
  return (0, import_meriyah.parse)(`
766
891
  function wrapper () {
767
892
  const __bt$hook = ${channelGetter}();
768
- if (!__bt$hook?.hasSubscribers) return __bt$traced();
769
- __bt$ctx.self ??= this;
770
- return __bt$hook.traceCallback(
771
- __bt$traced,
772
- ${callbackIndex},
773
- __bt$ctx
893
+ if (!__bt$hook) return __bt$target.apply(this, arguments);
894
+ return __bt$hook.traceInvocation(
895
+ ${JSON.stringify(operator)},
896
+ __bt$target,
897
+ this,
898
+ arguments,
899
+ { moduleVersion: ${JSON.stringify(moduleVersion)} },
900
+ ${callbackIndex}
774
901
  );
775
902
  }
776
903
  `);
777
904
  }
778
- function wrapPromise(state) {
779
- const { channelName } = state;
780
- const channelGetter = formatChannelGetter(channelName);
781
- return (0, import_meriyah.parse)(`
782
- function wrapper () {
783
- const __bt$hook = ${channelGetter}();
784
- if (!__bt$hook?.hasSubscribers) return __bt$traced();
785
- __bt$ctx.self ??= this;
786
- return __bt$hook.tracePromise(__bt$traced, __bt$ctx);
787
- }
788
- `);
789
- }
790
- function wrapSync(state) {
791
- const { channelName } = state;
792
- const channelGetter = formatChannelGetter(channelName);
793
- return (0, import_meriyah.parse)(`
794
- function wrapper () {
795
- const __bt$hook = ${channelGetter}();
796
- if (!__bt$hook?.hasSubscribers) return __bt$traced();
797
- __bt$ctx.self ??= this;
798
- return __bt$hook.traceSync(__bt$traced, __bt$ctx);
799
- }
800
- `);
801
- }
802
905
 
803
906
  // src/auto-instrumentations/orchestrion-js/transformer.ts
804
907
  var Transformer = class {
@@ -1074,6 +1177,7 @@ var envIntegrationAliases = {
1074
1177
  cloudflareaichat: "cloudflareAIChat",
1075
1178
  "cloudflare-ai-chat": "cloudflareAIChat",
1076
1179
  "@cloudflare/ai-chat": "cloudflareAIChat",
1180
+ cloudflarethink: "cloudflareThink",
1077
1181
  cursor: "cursor",
1078
1182
  "cursor-sdk": "cursorSDK",
1079
1183
  cursorsdk: "cursorSDK",
@@ -1094,6 +1198,7 @@ var envIntegrationAliases = {
1094
1198
  openrouteragent: "openrouterAgent",
1095
1199
  "openrouter-agent": "openrouterAgent",
1096
1200
  mistral: "mistral",
1201
+ ollama: "ollama",
1097
1202
  googleadk: "googleADK",
1098
1203
  "google-adk": "googleADK",
1099
1204
  cohere: "cohere",
@@ -1179,11 +1284,21 @@ function defineChannels(pkg, channels, options) {
1179
1284
  const tracingChannel2 = () => isomorph_default.newTracingChannel(
1180
1285
  fullChannelName
1181
1286
  );
1287
+ const intercept2 = (interceptor) => {
1288
+ const hook = tracingChannel2();
1289
+ return typeof hook.intercept === "function" ? hook.intercept(interceptor) : () => {
1290
+ };
1291
+ };
1182
1292
  return [
1183
1293
  key,
1184
1294
  {
1185
1295
  ...asyncSpec,
1186
1296
  instrumentationName,
1297
+ intercept: intercept2,
1298
+ invoke: (target, thisArg, args, additional) => {
1299
+ const hook = tracingChannel2();
1300
+ return typeof hook.invoke === "function" ? hook.invoke(target, thisArg, args, additional) : Reflect.apply(target, thisArg, args);
1301
+ },
1187
1302
  tracingChannel: tracingChannel2,
1188
1303
  tracePromise: (fn, context) => tracingChannel2().tracePromise(
1189
1304
  fn,
@@ -1197,11 +1312,21 @@ function defineChannels(pkg, channels, options) {
1197
1312
  const tracingChannel = () => isomorph_default.newTracingChannel(
1198
1313
  fullChannelName
1199
1314
  );
1315
+ const intercept = (interceptor) => {
1316
+ const hook = tracingChannel();
1317
+ return typeof hook.intercept === "function" ? hook.intercept(interceptor) : () => {
1318
+ };
1319
+ };
1200
1320
  return [
1201
1321
  key,
1202
1322
  {
1203
1323
  ...syncSpec,
1204
1324
  instrumentationName,
1325
+ intercept,
1326
+ invoke: (target, thisArg, args, additional) => {
1327
+ const hook = tracingChannel();
1328
+ return typeof hook.invoke === "function" ? hook.invoke(target, thisArg, args, additional) : Reflect.apply(target, thisArg, args);
1329
+ },
1205
1330
  tracingChannel,
1206
1331
  traceSync: (fn, context) => tracingChannel().traceSync(
1207
1332
  fn,
@@ -1223,6 +1348,7 @@ var INSTRUMENTATION_NAMES = {
1223
1348
  CLAUDE_AGENT_SDK: "claude-agent-sdk",
1224
1349
  CLOUDFLARE_AI_CHAT: "cloudflare-ai-chat",
1225
1350
  CLOUDFLARE_AGENTS: "cloudflare-agents",
1351
+ CLOUDFLARE_THINK: "cloudflare-think",
1226
1352
  COHERE: "cohere",
1227
1353
  CURSOR_SDK: "cursor-sdk",
1228
1354
  EVE: "eve",
@@ -1237,6 +1363,7 @@ var INSTRUMENTATION_NAMES = {
1237
1363
  LANGSMITH: "langsmith",
1238
1364
  MASTRA: "mastra",
1239
1365
  MISTRAL: "mistral",
1366
+ OLLAMA: "ollama",
1240
1367
  OPENAI: "openai",
1241
1368
  OPENAI_AGENTS: "openai-agents",
1242
1369
  OPENAI_CODEX: "openai-codex",
@@ -1753,6 +1880,14 @@ var anthropicChannels = defineChannels(
1753
1880
  betaMessagesToolRunner: channel({
1754
1881
  channelName: "beta.messages.toolRunner",
1755
1882
  kind: "sync-stream"
1883
+ }),
1884
+ betaSessionsEventsStream: channel({
1885
+ channelName: "beta.sessions.events.stream",
1886
+ kind: "async"
1887
+ }),
1888
+ betaSessionsThreadsEventsStream: channel({
1889
+ channelName: "beta.sessions.threads.events.stream",
1890
+ kind: "async"
1756
1891
  })
1757
1892
  },
1758
1893
  { instrumentationName: INSTRUMENTATION_NAMES.ANTHROPIC }
@@ -1871,7 +2006,40 @@ var anthropicConfigs = [
1871
2006
  methodName: "toolRunner",
1872
2007
  kind: "Sync"
1873
2008
  }
1874
- }
2009
+ },
2010
+ // Managed Agents Sessions event streams are discovered automatically, but
2011
+ // remain passive until the user calls collectAnthropicSession() on the
2012
+ // returned stream.
2013
+ ...["mjs", "js"].map(
2014
+ (extension) => ({
2015
+ channelName: anthropicChannels.betaSessionsEventsStream.channelName,
2016
+ module: {
2017
+ name: "@anthropic-ai/sdk",
2018
+ versionRange: ">=0.86.0",
2019
+ filePath: `resources/beta/sessions/events.${extension}`
2020
+ },
2021
+ functionQuery: {
2022
+ className: "Events",
2023
+ methodName: "stream",
2024
+ kind: "Async"
2025
+ }
2026
+ })
2027
+ ),
2028
+ ...["mjs", "js"].map(
2029
+ (extension) => ({
2030
+ channelName: anthropicChannels.betaSessionsThreadsEventsStream.channelName,
2031
+ module: {
2032
+ name: "@anthropic-ai/sdk",
2033
+ versionRange: ">=0.86.0",
2034
+ filePath: `resources/beta/sessions/threads/events.${extension}`
2035
+ },
2036
+ functionQuery: {
2037
+ className: "Events",
2038
+ methodName: "stream",
2039
+ kind: "Async"
2040
+ }
2041
+ })
2042
+ )
1875
2043
  ];
1876
2044
 
1877
2045
  // src/instrumentation/plugins/bedrock-runtime-channels.ts
@@ -2068,6 +2236,36 @@ var cloudflareAgentsConfigs = [
2068
2236
  }
2069
2237
  ];
2070
2238
 
2239
+ // src/instrumentation/plugins/cloudflare-think-channels.ts
2240
+ var cloudflareThinkChannels = defineChannels(
2241
+ "@cloudflare/think",
2242
+ {
2243
+ runInferenceLoop: channel({
2244
+ channelName: "Think.runInferenceLoop",
2245
+ kind: "async"
2246
+ })
2247
+ },
2248
+ { instrumentationName: INSTRUMENTATION_NAMES.CLOUDFLARE_THINK }
2249
+ );
2250
+
2251
+ // src/auto-instrumentations/configs/cloudflare-think.ts
2252
+ var cloudflareThinkVersionRange = ">=0.13.0 <0.14.0";
2253
+ var cloudflareThinkConfigs = [
2254
+ {
2255
+ channelName: cloudflareThinkChannels.runInferenceLoop.channelName,
2256
+ module: {
2257
+ name: "@cloudflare/think",
2258
+ versionRange: cloudflareThinkVersionRange,
2259
+ filePath: "dist/think.js"
2260
+ },
2261
+ functionQuery: {
2262
+ className: "Think",
2263
+ methodName: "_runInferenceLoop",
2264
+ kind: "Async"
2265
+ }
2266
+ }
2267
+ ];
2268
+
2071
2269
  // src/instrumentation/plugins/cohere-channels.ts
2072
2270
  var cohereChannels = defineChannels(
2073
2271
  "cohere-ai",
@@ -3951,6 +4149,51 @@ var mistralConfigs = [
3951
4149
  }
3952
4150
  ];
3953
4151
 
4152
+ // src/instrumentation/plugins/ollama-channels.ts
4153
+ var ollamaChannels = defineChannels(
4154
+ "ollama",
4155
+ {
4156
+ chat: channel({
4157
+ channelName: "chat",
4158
+ kind: "async"
4159
+ }),
4160
+ generate: channel({
4161
+ channelName: "generate",
4162
+ kind: "async"
4163
+ }),
4164
+ embed: channel({
4165
+ channelName: "embed",
4166
+ kind: "async"
4167
+ })
4168
+ },
4169
+ { instrumentationName: INSTRUMENTATION_NAMES.OLLAMA }
4170
+ );
4171
+
4172
+ // src/auto-instrumentations/configs/ollama.ts
4173
+ var methods = [
4174
+ ["chat", ollamaChannels.chat.channelName],
4175
+ ["generate", ollamaChannels.generate.channelName],
4176
+ ["embed", ollamaChannels.embed.channelName]
4177
+ ];
4178
+ var implementationFiles = ["dist/browser.mjs", "dist/browser.cjs"];
4179
+ var ollamaConfigs = [
4180
+ ...implementationFiles.flatMap(
4181
+ (filePath) => methods.map(([methodName, channelName]) => ({
4182
+ channelName,
4183
+ module: {
4184
+ name: "ollama",
4185
+ versionRange: ">=0.6.0 <0.7.0",
4186
+ filePath
4187
+ },
4188
+ functionQuery: {
4189
+ className: "Ollama",
4190
+ methodName,
4191
+ kind: "Async"
4192
+ }
4193
+ }))
4194
+ )
4195
+ ];
4196
+
3954
4197
  // src/instrumentation/plugins/openai-agents-channels.ts
3955
4198
  var openAIAgentsCoreChannels = defineChannels(
3956
4199
  "@openai/agents-core",
@@ -4360,6 +4603,19 @@ var openRouterConfigs = [
4360
4603
  kind: "Async"
4361
4604
  }
4362
4605
  },
4606
+ {
4607
+ channelName: openRouterChannels.betaResponsesSend.channelName,
4608
+ module: {
4609
+ name: "@openrouter/sdk",
4610
+ versionRange: ">=1.1.2 <2.0.0",
4611
+ filePath: "esm/sdk/betaresponses.js"
4612
+ },
4613
+ functionQuery: {
4614
+ className: "BetaResponses",
4615
+ methodName: "send",
4616
+ kind: "Async"
4617
+ }
4618
+ },
4363
4619
  {
4364
4620
  channelName: openRouterChannels.callModel.channelName,
4365
4621
  module: {
@@ -4533,6 +4789,10 @@ var defaultInstrumentationConfigGroups = [
4533
4789
  integrations: ["cloudflareAgents"],
4534
4790
  configs: cloudflareAgentsConfigs
4535
4791
  },
4792
+ {
4793
+ integrations: ["cloudflareThink"],
4794
+ configs: cloudflareThinkConfigs
4795
+ },
4536
4796
  { integrations: ["cursor", "cursorSDK"], configs: cursorSDKConfigs },
4537
4797
  {
4538
4798
  integrations: ["openAIAgents"],
@@ -4557,6 +4817,7 @@ var defaultInstrumentationConfigGroups = [
4557
4817
  configs: openRouterAgentConfigs
4558
4818
  },
4559
4819
  { integrations: ["mistral"], configs: mistralConfigs },
4820
+ { integrations: ["ollama"], configs: ollamaConfigs },
4560
4821
  { integrations: ["googleADK"], configs: googleADKConfigs },
4561
4822
  { integrations: ["cohere"], configs: cohereConfigs },
4562
4823
  { integrations: ["groq"], configs: groqConfigs },
@@ -4812,6 +5073,49 @@ function applySpecialCasePatch(input) {
4812
5073
  return null;
4813
5074
  }
4814
5075
 
5076
+ // src/auto-instrumentations/loader/get-package-version.ts
5077
+ var import_node_fs = require("fs");
5078
+ var import_node_path = require("path");
5079
+ var packageNames = /* @__PURE__ */ new Map();
5080
+ function readPackageJson(baseDir) {
5081
+ try {
5082
+ const packageJsonPath = (0, import_node_path.join)(baseDir, "package.json");
5083
+ const jsonFile = (0, import_node_fs.readFileSync)(packageJsonPath, "utf8");
5084
+ return JSON.parse(jsonFile);
5085
+ } catch {
5086
+ return void 0;
5087
+ }
5088
+ }
5089
+ function resolvePackageBaseDir(baseDir) {
5090
+ try {
5091
+ return (0, import_node_fs.realpathSync)(baseDir);
5092
+ } catch {
5093
+ return baseDir;
5094
+ }
5095
+ }
5096
+ function readPackageJsonWithFallback(baseDir) {
5097
+ const packageJson = readPackageJson(baseDir);
5098
+ if (packageJson) {
5099
+ return packageJson;
5100
+ }
5101
+ const resolvedBaseDir = resolvePackageBaseDir(baseDir);
5102
+ if (resolvedBaseDir === baseDir) {
5103
+ return void 0;
5104
+ }
5105
+ return readPackageJson(resolvedBaseDir);
5106
+ }
5107
+ function getPackageName(baseDir) {
5108
+ if (packageNames.has(baseDir)) {
5109
+ return packageNames.get(baseDir);
5110
+ }
5111
+ const packageJson = readPackageJsonWithFallback(baseDir);
5112
+ if (typeof packageJson?.name === "string") {
5113
+ packageNames.set(baseDir, packageJson.name);
5114
+ return packageJson.name;
5115
+ }
5116
+ return void 0;
5117
+ }
5118
+
4815
5119
  // src/auto-instrumentations/bundler/plugin.ts
4816
5120
  function getModuleVersion(basedir) {
4817
5121
  try {
@@ -4833,6 +5137,20 @@ var unplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
4833
5137
  return {
4834
5138
  name: "code-transformer",
4835
5139
  enforce: "pre",
5140
+ transformInclude(id) {
5141
+ const pathWithoutQuery = id.split("?", 1)[0];
5142
+ if (!pathWithoutQuery) {
5143
+ return false;
5144
+ }
5145
+ if (pathWithoutQuery.startsWith("file:")) {
5146
+ try {
5147
+ return (0, import_path.isAbsolute)((0, import_url.fileURLToPath)(pathWithoutQuery));
5148
+ } catch {
5149
+ return false;
5150
+ }
5151
+ }
5152
+ return (0, import_path.isAbsolute)(pathWithoutQuery);
5153
+ },
4836
5154
  transform(code, id) {
4837
5155
  if (!id) {
4838
5156
  return null;
@@ -4849,7 +5167,7 @@ var unplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
4849
5167
  if (!moduleDetails) {
4850
5168
  return null;
4851
5169
  }
4852
- const moduleName = moduleDetails.name;
5170
+ const moduleName = getPackageName(moduleDetails.basedir) ?? moduleDetails.name;
4853
5171
  const normalizedModulePath = moduleDetails.path.replace(/\\/g, "/");
4854
5172
  const moduleVersion = getModuleVersion(moduleDetails.basedir);
4855
5173
  const patched = applySpecialCasePatch({
@@ -4895,7 +5213,7 @@ var unplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
4895
5213
  var webpackPlugin = unplugin.webpack;
4896
5214
 
4897
5215
  // src/auto-instrumentations/bundler/next.ts
4898
- var requireFromProject = (0, import_node_module.createRequire)((0, import_node_path.join)(process.cwd(), "package.json"));
5216
+ var requireFromProject = (0, import_node_module.createRequire)((0, import_node_path2.join)(process.cwd(), "package.json"));
4899
5217
  var TURBOPACK_RULE_MATCHER = "*.{js,mjs,cjs}";
4900
5218
  function wrapNextjsConfigWithBraintrust(nextConfig) {
4901
5219
  const castNextConfig = nextConfig ?? {};
@@ -1,10 +1,11 @@
1
1
  import {
2
2
  webpackPlugin
3
- } from "../chunk-V5LEODRX.mjs";
4
- import "../chunk-6E22MYSW.mjs";
5
- import "../chunk-XZHHE4Y3.mjs";
6
- import "../chunk-XYN63IG5.mjs";
7
- import "../chunk-NRE4QUQR.mjs";
3
+ } from "../chunk-BW33ULMW.mjs";
4
+ import "../chunk-XEYKUBLY.mjs";
5
+ import "../chunk-ZNHTSSGI.mjs";
6
+ import "../chunk-I55G56ZL.mjs";
7
+ import "../chunk-JPUFNW7X.mjs";
8
+ import "../chunk-P5YLNB2A.mjs";
8
9
 
9
10
  // src/auto-instrumentations/bundler/next.ts
10
11
  import { createRequire } from "module";