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