braintrust 3.26.0 → 3.28.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 (61) hide show
  1. package/dev/dist/index.d.mts +519 -186
  2. package/dev/dist/index.d.ts +519 -186
  3. package/dev/dist/index.js +3727 -1526
  4. package/dev/dist/index.mjs +2815 -614
  5. package/dist/apply-auto-instrumentation.js +372 -261
  6. package/dist/apply-auto-instrumentation.mjs +171 -60
  7. package/dist/auto-instrumentations/bundler/esbuild.cjs +458 -61
  8. package/dist/auto-instrumentations/bundler/esbuild.mjs +5 -4
  9. package/dist/auto-instrumentations/bundler/next.cjs +460 -63
  10. package/dist/auto-instrumentations/bundler/next.mjs +6 -5
  11. package/dist/auto-instrumentations/bundler/rollup.cjs +458 -61
  12. package/dist/auto-instrumentations/bundler/rollup.mjs +5 -4
  13. package/dist/auto-instrumentations/bundler/vite.cjs +487 -62
  14. package/dist/auto-instrumentations/bundler/vite.mjs +34 -5
  15. package/dist/auto-instrumentations/bundler/webpack-loader.cjs +444 -61
  16. package/dist/auto-instrumentations/bundler/webpack.cjs +458 -61
  17. package/dist/auto-instrumentations/bundler/webpack.mjs +6 -5
  18. package/dist/auto-instrumentations/{chunk-6E22MYSW.mjs → chunk-26PKVUKB.mjs} +109 -5
  19. package/dist/auto-instrumentations/{chunk-AKKPLXTP.mjs → chunk-2AMDGD65.mjs} +160 -57
  20. package/dist/auto-instrumentations/{chunk-V5LEODRX.mjs → chunk-HD35AM3M.mjs} +1 -1
  21. package/dist/auto-instrumentations/{chunk-XYN63IG5.mjs → chunk-I55G56ZL.mjs} +21 -58
  22. package/dist/auto-instrumentations/{chunk-NRE4QUQR.mjs → chunk-JPUFNW7X.mjs} +140 -0
  23. package/dist/auto-instrumentations/{chunk-XZHHE4Y3.mjs → chunk-NP7V4XB2.mjs} +157 -3
  24. package/dist/auto-instrumentations/hook.mjs +396 -32
  25. package/dist/auto-instrumentations/index.cjs +298 -2
  26. package/dist/auto-instrumentations/index.d.mts +5 -1
  27. package/dist/auto-instrumentations/index.d.ts +5 -1
  28. package/dist/auto-instrumentations/index.mjs +6 -2
  29. package/dist/auto-instrumentations/loader/cjs-patch.cjs +105 -57
  30. package/dist/auto-instrumentations/loader/cjs-patch.mjs +2 -2
  31. package/dist/auto-instrumentations/loader/esm-hook.mjs +1 -1
  32. package/dist/browser.d.mts +683 -56
  33. package/dist/browser.d.ts +683 -56
  34. package/dist/browser.js +4242 -655
  35. package/dist/browser.mjs +4242 -655
  36. package/dist/{chunk-VYNNEKSA.js → chunk-BBE7SNRV.js} +248 -10
  37. package/dist/{chunk-VRZZQPAA.js → chunk-OBBWQW6K.js} +3351 -1392
  38. package/dist/{chunk-XIZOM2HO.mjs → chunk-UPFNQCGB.mjs} +2419 -460
  39. package/dist/{chunk-PN7EWK66.mjs → chunk-ZHUHZWFY.mjs} +241 -3
  40. package/dist/cli.js +2867 -668
  41. package/dist/edge-light.d.mts +1 -1
  42. package/dist/edge-light.d.ts +1 -1
  43. package/dist/edge-light.js +4242 -655
  44. package/dist/edge-light.mjs +4242 -655
  45. package/dist/index.d.mts +1267 -640
  46. package/dist/index.d.ts +1267 -640
  47. package/dist/index.js +2107 -630
  48. package/dist/index.mjs +1649 -172
  49. package/dist/instrumentation/index.d.mts +198 -6
  50. package/dist/instrumentation/index.d.ts +198 -6
  51. package/dist/instrumentation/index.js +2661 -581
  52. package/dist/instrumentation/index.mjs +2661 -581
  53. package/dist/vitest-evals-reporter.js +45 -43
  54. package/dist/vitest-evals-reporter.mjs +5 -3
  55. package/dist/workerd.d.mts +1 -1
  56. package/dist/workerd.d.ts +1 -1
  57. package/dist/workerd.js +4242 -655
  58. package/dist/workerd.mjs +4242 -655
  59. package/package.json +2 -3
  60. package/util/dist/index.d.mts +1545 -100
  61. package/util/dist/index.d.ts +1545 -100
@@ -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",
@@ -1113,7 +1218,10 @@ var envIntegrationAliases = {
1113
1218
  "langchain-js": "langchain",
1114
1219
  "@langchain": "langchain",
1115
1220
  langgraph: "langgraph",
1116
- langsmith: "langsmith"
1221
+ langsmith: "langsmith",
1222
+ voyage: "voyageai",
1223
+ "voyage-ai": "voyageai",
1224
+ voyageai: "voyageai"
1117
1225
  };
1118
1226
  function readDisabledInstrumentationEnvConfig(disabledList) {
1119
1227
  const integrations = {};
@@ -1178,11 +1286,21 @@ function defineChannels(pkg, channels, options) {
1178
1286
  const tracingChannel2 = () => isomorph_default.newTracingChannel(
1179
1287
  fullChannelName
1180
1288
  );
1289
+ const intercept2 = (interceptor) => {
1290
+ const hook = tracingChannel2();
1291
+ return typeof hook.intercept === "function" ? hook.intercept(interceptor) : () => {
1292
+ };
1293
+ };
1181
1294
  return [
1182
1295
  key,
1183
1296
  {
1184
1297
  ...asyncSpec,
1185
1298
  instrumentationName,
1299
+ intercept: intercept2,
1300
+ invoke: (target, thisArg, args, additional) => {
1301
+ const hook = tracingChannel2();
1302
+ return typeof hook.invoke === "function" ? hook.invoke(target, thisArg, args, additional) : Reflect.apply(target, thisArg, args);
1303
+ },
1186
1304
  tracingChannel: tracingChannel2,
1187
1305
  tracePromise: (fn, context) => tracingChannel2().tracePromise(
1188
1306
  fn,
@@ -1196,11 +1314,21 @@ function defineChannels(pkg, channels, options) {
1196
1314
  const tracingChannel = () => isomorph_default.newTracingChannel(
1197
1315
  fullChannelName
1198
1316
  );
1317
+ const intercept = (interceptor) => {
1318
+ const hook = tracingChannel();
1319
+ return typeof hook.intercept === "function" ? hook.intercept(interceptor) : () => {
1320
+ };
1321
+ };
1199
1322
  return [
1200
1323
  key,
1201
1324
  {
1202
1325
  ...syncSpec,
1203
1326
  instrumentationName,
1327
+ intercept,
1328
+ invoke: (target, thisArg, args, additional) => {
1329
+ const hook = tracingChannel();
1330
+ return typeof hook.invoke === "function" ? hook.invoke(target, thisArg, args, additional) : Reflect.apply(target, thisArg, args);
1331
+ },
1204
1332
  tracingChannel,
1205
1333
  traceSync: (fn, context) => tracingChannel().traceSync(
1206
1334
  fn,
@@ -1222,6 +1350,7 @@ var INSTRUMENTATION_NAMES = {
1222
1350
  CLAUDE_AGENT_SDK: "claude-agent-sdk",
1223
1351
  CLOUDFLARE_AI_CHAT: "cloudflare-ai-chat",
1224
1352
  CLOUDFLARE_AGENTS: "cloudflare-agents",
1353
+ CLOUDFLARE_THINK: "cloudflare-think",
1225
1354
  COHERE: "cohere",
1226
1355
  CURSOR_SDK: "cursor-sdk",
1227
1356
  EVE: "eve",
@@ -1236,13 +1365,15 @@ var INSTRUMENTATION_NAMES = {
1236
1365
  LANGSMITH: "langsmith",
1237
1366
  MASTRA: "mastra",
1238
1367
  MISTRAL: "mistral",
1368
+ OLLAMA: "ollama",
1239
1369
  OPENAI: "openai",
1240
1370
  OPENAI_AGENTS: "openai-agents",
1241
1371
  OPENAI_CODEX: "openai-codex",
1242
1372
  OPENROUTER: "openrouter",
1243
1373
  OPENROUTER_AGENT: "openrouter-agent",
1244
1374
  PI_CODING_AGENT: "pi-coding-agent",
1245
- STRANDS_AGENT_SDK: "strands-agent-sdk"
1375
+ STRANDS_AGENT_SDK: "strands-agent-sdk",
1376
+ VOYAGEAI: "voyageai"
1246
1377
  };
1247
1378
 
1248
1379
  // src/instrumentation/plugins/ai-sdk-channels.ts
@@ -1752,6 +1883,14 @@ var anthropicChannels = defineChannels(
1752
1883
  betaMessagesToolRunner: channel({
1753
1884
  channelName: "beta.messages.toolRunner",
1754
1885
  kind: "sync-stream"
1886
+ }),
1887
+ betaSessionsEventsStream: channel({
1888
+ channelName: "beta.sessions.events.stream",
1889
+ kind: "async"
1890
+ }),
1891
+ betaSessionsThreadsEventsStream: channel({
1892
+ channelName: "beta.sessions.threads.events.stream",
1893
+ kind: "async"
1755
1894
  })
1756
1895
  },
1757
1896
  { instrumentationName: INSTRUMENTATION_NAMES.ANTHROPIC }
@@ -1870,7 +2009,40 @@ var anthropicConfigs = [
1870
2009
  methodName: "toolRunner",
1871
2010
  kind: "Sync"
1872
2011
  }
1873
- }
2012
+ },
2013
+ // Managed Agents Sessions event streams are discovered automatically, but
2014
+ // remain passive until the user calls collectAnthropicSession() on the
2015
+ // returned stream.
2016
+ ...["mjs", "js"].map(
2017
+ (extension) => ({
2018
+ channelName: anthropicChannels.betaSessionsEventsStream.channelName,
2019
+ module: {
2020
+ name: "@anthropic-ai/sdk",
2021
+ versionRange: ">=0.86.0",
2022
+ filePath: `resources/beta/sessions/events.${extension}`
2023
+ },
2024
+ functionQuery: {
2025
+ className: "Events",
2026
+ methodName: "stream",
2027
+ kind: "Async"
2028
+ }
2029
+ })
2030
+ ),
2031
+ ...["mjs", "js"].map(
2032
+ (extension) => ({
2033
+ channelName: anthropicChannels.betaSessionsThreadsEventsStream.channelName,
2034
+ module: {
2035
+ name: "@anthropic-ai/sdk",
2036
+ versionRange: ">=0.86.0",
2037
+ filePath: `resources/beta/sessions/threads/events.${extension}`
2038
+ },
2039
+ functionQuery: {
2040
+ className: "Events",
2041
+ methodName: "stream",
2042
+ kind: "Async"
2043
+ }
2044
+ })
2045
+ )
1874
2046
  ];
1875
2047
 
1876
2048
  // src/instrumentation/plugins/bedrock-runtime-channels.ts
@@ -2067,6 +2239,36 @@ var cloudflareAgentsConfigs = [
2067
2239
  }
2068
2240
  ];
2069
2241
 
2242
+ // src/instrumentation/plugins/cloudflare-think-channels.ts
2243
+ var cloudflareThinkChannels = defineChannels(
2244
+ "@cloudflare/think",
2245
+ {
2246
+ runInferenceLoop: channel({
2247
+ channelName: "Think.runInferenceLoop",
2248
+ kind: "async"
2249
+ })
2250
+ },
2251
+ { instrumentationName: INSTRUMENTATION_NAMES.CLOUDFLARE_THINK }
2252
+ );
2253
+
2254
+ // src/auto-instrumentations/configs/cloudflare-think.ts
2255
+ var cloudflareThinkVersionRange = ">=0.13.0 <0.14.0";
2256
+ var cloudflareThinkConfigs = [
2257
+ {
2258
+ channelName: cloudflareThinkChannels.runInferenceLoop.channelName,
2259
+ module: {
2260
+ name: "@cloudflare/think",
2261
+ versionRange: cloudflareThinkVersionRange,
2262
+ filePath: "dist/think.js"
2263
+ },
2264
+ functionQuery: {
2265
+ className: "Think",
2266
+ methodName: "_runInferenceLoop",
2267
+ kind: "Async"
2268
+ }
2269
+ }
2270
+ ];
2271
+
2070
2272
  // src/instrumentation/plugins/cohere-channels.ts
2071
2273
  var cohereChannels = defineChannels(
2072
2274
  "cohere-ai",
@@ -3950,6 +4152,51 @@ var mistralConfigs = [
3950
4152
  }
3951
4153
  ];
3952
4154
 
4155
+ // src/instrumentation/plugins/ollama-channels.ts
4156
+ var ollamaChannels = defineChannels(
4157
+ "ollama",
4158
+ {
4159
+ chat: channel({
4160
+ channelName: "chat",
4161
+ kind: "async"
4162
+ }),
4163
+ generate: channel({
4164
+ channelName: "generate",
4165
+ kind: "async"
4166
+ }),
4167
+ embed: channel({
4168
+ channelName: "embed",
4169
+ kind: "async"
4170
+ })
4171
+ },
4172
+ { instrumentationName: INSTRUMENTATION_NAMES.OLLAMA }
4173
+ );
4174
+
4175
+ // src/auto-instrumentations/configs/ollama.ts
4176
+ var methods = [
4177
+ ["chat", ollamaChannels.chat.channelName],
4178
+ ["generate", ollamaChannels.generate.channelName],
4179
+ ["embed", ollamaChannels.embed.channelName]
4180
+ ];
4181
+ var implementationFiles = ["dist/browser.mjs", "dist/browser.cjs"];
4182
+ var ollamaConfigs = [
4183
+ ...implementationFiles.flatMap(
4184
+ (filePath) => methods.map(([methodName, channelName]) => ({
4185
+ channelName,
4186
+ module: {
4187
+ name: "ollama",
4188
+ versionRange: ">=0.6.0 <0.7.0",
4189
+ filePath
4190
+ },
4191
+ functionQuery: {
4192
+ className: "Ollama",
4193
+ methodName,
4194
+ kind: "Async"
4195
+ }
4196
+ }))
4197
+ )
4198
+ ];
4199
+
3953
4200
  // src/instrumentation/plugins/openai-agents-channels.ts
3954
4201
  var openAIAgentsCoreChannels = defineChannels(
3955
4202
  "@openai/agents-core",
@@ -4359,6 +4606,19 @@ var openRouterConfigs = [
4359
4606
  kind: "Async"
4360
4607
  }
4361
4608
  },
4609
+ {
4610
+ channelName: openRouterChannels.betaResponsesSend.channelName,
4611
+ module: {
4612
+ name: "@openrouter/sdk",
4613
+ versionRange: ">=1.1.2 <2.0.0",
4614
+ filePath: "esm/sdk/betaresponses.js"
4615
+ },
4616
+ functionQuery: {
4617
+ className: "BetaResponses",
4618
+ methodName: "send",
4619
+ kind: "Async"
4620
+ }
4621
+ },
4362
4622
  {
4363
4623
  channelName: openRouterChannels.callModel.channelName,
4364
4624
  module: {
@@ -4504,6 +4764,77 @@ var strandsAgentSDKConfigs = [
4504
4764
  }
4505
4765
  ];
4506
4766
 
4767
+ // src/instrumentation/plugins/voyageai-channels.ts
4768
+ var voyageAIChannels = defineChannels(
4769
+ "voyageai",
4770
+ {
4771
+ embed: channel({
4772
+ channelName: "embed",
4773
+ kind: "async"
4774
+ }),
4775
+ multimodalEmbed: channel({
4776
+ channelName: "multimodalEmbed",
4777
+ kind: "async"
4778
+ }),
4779
+ rerank: channel({
4780
+ channelName: "rerank",
4781
+ kind: "async"
4782
+ }),
4783
+ contextualizedEmbed: channel({
4784
+ channelName: "contextualizedEmbed",
4785
+ kind: "async"
4786
+ })
4787
+ },
4788
+ { instrumentationName: INSTRUMENTATION_NAMES.VOYAGEAI }
4789
+ );
4790
+
4791
+ // src/auto-instrumentations/configs/voyageai.ts
4792
+ var GENERATED_CLIENT_MODULES = [
4793
+ "dist/cjs/Client.js",
4794
+ "dist/esm/Client.mjs"
4795
+ ];
4796
+ var generatedClientOperations = [
4797
+ {
4798
+ channelName: voyageAIChannels.embed.channelName,
4799
+ methodName: "embed",
4800
+ versionRange: ">=0.2.0 <1.0.0"
4801
+ },
4802
+ {
4803
+ channelName: voyageAIChannels.multimodalEmbed.channelName,
4804
+ methodName: "multimodalEmbed",
4805
+ versionRange: ">=0.2.0 <1.0.0"
4806
+ },
4807
+ {
4808
+ channelName: voyageAIChannels.rerank.channelName,
4809
+ methodName: "rerank",
4810
+ versionRange: ">=0.2.0 <1.0.0"
4811
+ },
4812
+ {
4813
+ channelName: voyageAIChannels.contextualizedEmbed.channelName,
4814
+ methodName: "contextualizedEmbed",
4815
+ versionRange: ">=0.2.0 <1.0.0"
4816
+ }
4817
+ ];
4818
+ var voyageAIConfigs = [
4819
+ ...GENERATED_CLIENT_MODULES.flatMap(
4820
+ (filePath) => generatedClientOperations.map(
4821
+ ({ channelName, methodName, versionRange: versionRange2 }) => ({
4822
+ channelName,
4823
+ module: {
4824
+ name: "voyageai",
4825
+ versionRange: versionRange2,
4826
+ filePath
4827
+ },
4828
+ functionQuery: {
4829
+ className: "VoyageAIClient",
4830
+ methodName,
4831
+ kind: "Async"
4832
+ }
4833
+ })
4834
+ )
4835
+ )
4836
+ ];
4837
+
4507
4838
  // src/auto-instrumentations/configs/all.ts
4508
4839
  var defaultInstrumentationConfigGroups = [
4509
4840
  { integrations: ["openai"], configs: openaiConfigs },
@@ -4532,6 +4863,10 @@ var defaultInstrumentationConfigGroups = [
4532
4863
  integrations: ["cloudflareAgents"],
4533
4864
  configs: cloudflareAgentsConfigs
4534
4865
  },
4866
+ {
4867
+ integrations: ["cloudflareThink"],
4868
+ configs: cloudflareThinkConfigs
4869
+ },
4535
4870
  { integrations: ["cursor", "cursorSDK"], configs: cursorSDKConfigs },
4536
4871
  {
4537
4872
  integrations: ["openAIAgents"],
@@ -4556,6 +4891,7 @@ var defaultInstrumentationConfigGroups = [
4556
4891
  configs: openRouterAgentConfigs
4557
4892
  },
4558
4893
  { integrations: ["mistral"], configs: mistralConfigs },
4894
+ { integrations: ["ollama"], configs: ollamaConfigs },
4559
4895
  { integrations: ["googleADK"], configs: googleADKConfigs },
4560
4896
  { integrations: ["cohere"], configs: cohereConfigs },
4561
4897
  { integrations: ["groq"], configs: groqConfigs },
@@ -4578,6 +4914,10 @@ var defaultInstrumentationConfigGroups = [
4578
4914
  {
4579
4915
  integrations: ["flue"],
4580
4916
  configs: flueConfigs
4917
+ },
4918
+ {
4919
+ integrations: ["voyageai"],
4920
+ configs: voyageAIConfigs
4581
4921
  }
4582
4922
  // Note: `@mastra/core` is not listed here because its instrumentation
4583
4923
  // doesn't go through the AST `code-transformer` matcher — Mastra's
@@ -4811,6 +5151,49 @@ function applySpecialCasePatch(input) {
4811
5151
  return null;
4812
5152
  }
4813
5153
 
5154
+ // src/auto-instrumentations/loader/get-package-version.ts
5155
+ var import_node_fs = require("fs");
5156
+ var import_node_path = require("path");
5157
+ var packageNames = /* @__PURE__ */ new Map();
5158
+ function readPackageJson(baseDir) {
5159
+ try {
5160
+ const packageJsonPath = (0, import_node_path.join)(baseDir, "package.json");
5161
+ const jsonFile = (0, import_node_fs.readFileSync)(packageJsonPath, "utf8");
5162
+ return JSON.parse(jsonFile);
5163
+ } catch {
5164
+ return void 0;
5165
+ }
5166
+ }
5167
+ function resolvePackageBaseDir(baseDir) {
5168
+ try {
5169
+ return (0, import_node_fs.realpathSync)(baseDir);
5170
+ } catch {
5171
+ return baseDir;
5172
+ }
5173
+ }
5174
+ function readPackageJsonWithFallback(baseDir) {
5175
+ const packageJson = readPackageJson(baseDir);
5176
+ if (packageJson) {
5177
+ return packageJson;
5178
+ }
5179
+ const resolvedBaseDir = resolvePackageBaseDir(baseDir);
5180
+ if (resolvedBaseDir === baseDir) {
5181
+ return void 0;
5182
+ }
5183
+ return readPackageJson(resolvedBaseDir);
5184
+ }
5185
+ function getPackageName(baseDir) {
5186
+ if (packageNames.has(baseDir)) {
5187
+ return packageNames.get(baseDir);
5188
+ }
5189
+ const packageJson = readPackageJsonWithFallback(baseDir);
5190
+ if (typeof packageJson?.name === "string") {
5191
+ packageNames.set(baseDir, packageJson.name);
5192
+ return packageJson.name;
5193
+ }
5194
+ return void 0;
5195
+ }
5196
+
4814
5197
  // src/auto-instrumentations/bundler/plugin.ts
4815
5198
  function getModuleVersion(basedir) {
4816
5199
  try {
@@ -4832,6 +5215,20 @@ var unplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
4832
5215
  return {
4833
5216
  name: "code-transformer",
4834
5217
  enforce: "pre",
5218
+ transformInclude(id) {
5219
+ const pathWithoutQuery = id.split("?", 1)[0];
5220
+ if (!pathWithoutQuery) {
5221
+ return false;
5222
+ }
5223
+ if (pathWithoutQuery.startsWith("file:")) {
5224
+ try {
5225
+ return (0, import_path.isAbsolute)((0, import_url.fileURLToPath)(pathWithoutQuery));
5226
+ } catch {
5227
+ return false;
5228
+ }
5229
+ }
5230
+ return (0, import_path.isAbsolute)(pathWithoutQuery);
5231
+ },
4835
5232
  transform(code, id) {
4836
5233
  if (!id) {
4837
5234
  return null;
@@ -4848,7 +5245,7 @@ var unplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
4848
5245
  if (!moduleDetails) {
4849
5246
  return null;
4850
5247
  }
4851
- const moduleName = moduleDetails.name;
5248
+ const moduleName = getPackageName(moduleDetails.basedir) ?? moduleDetails.name;
4852
5249
  const normalizedModulePath = moduleDetails.path.replace(/\\/g, "/");
4853
5250
  const moduleVersion = getModuleVersion(moduleDetails.basedir);
4854
5251
  const patched = applySpecialCasePatch({