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
@@ -9,8 +9,10 @@ var GLOBAL_INSTRUMENTATION_HOOKS_KEY = "__braintrust_instrumentation_hooks";
9
9
  var GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION = 1;
10
10
  var GLOBAL_INSTRUMENTATION_HOOKS_REGISTRY_BRAND = "braintrust.global-instrumentation-hooks.registry";
11
11
  var GLOBAL_INSTRUMENTATION_HOOK_BRAND = "braintrust.global-instrumentation-hooks.hook";
12
+ var GLOBAL_INVOCATION_HOOK_BRAND = "braintrust.global-instrumentation-hooks.invocation-hook";
12
13
  var registryBrand = Symbol.for(GLOBAL_INSTRUMENTATION_HOOKS_REGISTRY_BRAND);
13
14
  var hookBrand = Symbol.for(GLOBAL_INSTRUMENTATION_HOOK_BRAND);
15
+ var invocationHookBrand = Symbol.for(GLOBAL_INVOCATION_HOOK_BRAND);
14
16
  var errorReporter;
15
17
  function setGlobalHookErrorReporter(reporter) {
16
18
  const previousReporter = errorReporter;
@@ -155,12 +157,69 @@ var traceEvents = [
155
157
  "asyncEnd",
156
158
  "error"
157
159
  ];
160
+ function traceInvocation(hook, operator, target, thisArg, args, additional, callbackIndex = -1) {
161
+ const context = {
162
+ ...additional,
163
+ arguments: args,
164
+ self: thisArg
165
+ };
166
+ const invoke = () => hook.invoke(target, thisArg, args, additional);
167
+ if (operator === "traceCallback") {
168
+ return hook.traceCallback(invoke, callbackIndex, context);
169
+ }
170
+ if (operator === "tracePromise") {
171
+ return hook.tracePromise(invoke, context);
172
+ }
173
+ return hook.traceSync(invoke, context);
174
+ }
175
+ var InvocationHook = class {
176
+ interceptors = [];
177
+ get hasInterceptors() {
178
+ return this.interceptors.length > 0;
179
+ }
180
+ intercept(interceptor) {
181
+ if (typeof interceptor !== "function") {
182
+ throw new TypeError("interceptor must be a function");
183
+ }
184
+ this.interceptors = [...this.interceptors, interceptor];
185
+ let active = true;
186
+ return () => {
187
+ if (!active) {
188
+ return;
189
+ }
190
+ active = false;
191
+ const index = this.interceptors.indexOf(interceptor);
192
+ if (index !== -1) {
193
+ this.interceptors = [
194
+ ...this.interceptors.slice(0, index),
195
+ ...this.interceptors.slice(index + 1)
196
+ ];
197
+ }
198
+ };
199
+ }
200
+ invoke(target, thisArg, args, additional) {
201
+ const interceptors = this.interceptors;
202
+ if (interceptors.length === 0) {
203
+ return Reflect.apply(target, thisArg, args);
204
+ }
205
+ let next = target;
206
+ for (let index = interceptors.length - 1; index >= 0; index -= 1) {
207
+ const interceptor = interceptors[index];
208
+ const downstream = next;
209
+ next = function(...nextArgs) {
210
+ return interceptor(downstream, this, nextArgs, additional);
211
+ };
212
+ }
213
+ return Reflect.apply(next, thisArg, args);
214
+ }
215
+ };
158
216
  var TracingHook = class {
159
217
  start;
160
218
  end;
161
219
  asyncStart;
162
220
  asyncEnd;
163
221
  error;
222
+ invocationHook = new InvocationHook();
164
223
  constructor(nameOrChannels) {
165
224
  Object.defineProperty(this, hookBrand, {
166
225
  configurable: false,
@@ -168,6 +227,12 @@ var TracingHook = class {
168
227
  value: GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION,
169
228
  writable: false
170
229
  });
230
+ Object.defineProperty(this, invocationHookBrand, {
231
+ configurable: false,
232
+ enumerable: false,
233
+ value: GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION,
234
+ writable: false
235
+ });
171
236
  if (typeof nameOrChannels === "string") {
172
237
  this.start = new HookChannel(`tracing:${nameOrChannels}:start`);
173
238
  this.end = new HookChannel(`tracing:${nameOrChannels}:end`);
@@ -185,6 +250,26 @@ var TracingHook = class {
185
250
  get hasSubscribers() {
186
251
  return this.start.hasSubscribers || this.end.hasSubscribers || this.asyncStart.hasSubscribers || this.asyncEnd.hasSubscribers || this.error.hasSubscribers;
187
252
  }
253
+ get hasInterceptors() {
254
+ return this.invocationHook.hasInterceptors;
255
+ }
256
+ intercept(interceptor) {
257
+ return this.invocationHook.intercept(interceptor);
258
+ }
259
+ invoke(target, thisArg, args, additional) {
260
+ return this.invocationHook.invoke(target, thisArg, args, additional);
261
+ }
262
+ traceInvocation(operator, target, thisArg, args, additional, callbackIndex = -1) {
263
+ return traceInvocation(
264
+ this,
265
+ operator,
266
+ target,
267
+ thisArg,
268
+ args,
269
+ additional,
270
+ callbackIndex
271
+ );
272
+ }
188
273
  subscribe(handlers) {
189
274
  for (const eventName of traceEvents) {
190
275
  const handler = handlers[eventName];
@@ -406,6 +491,60 @@ function hasTracingHookShape(value) {
406
491
  return false;
407
492
  }
408
493
  }
494
+ function hasInvocationHookShape(value) {
495
+ if (typeof value !== "object" && typeof value !== "function" || value === null) {
496
+ return false;
497
+ }
498
+ try {
499
+ const hook = value;
500
+ return value[invocationHookBrand] === GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION && typeof hook.hasInterceptors === "boolean" && typeof hook.intercept === "function" && typeof hook.invoke === "function";
501
+ } catch {
502
+ return false;
503
+ }
504
+ }
505
+ function installInvocationHook(value) {
506
+ const hasInvocationHook = hasInvocationHookShape(value);
507
+ const invocationHook = new InvocationHook();
508
+ try {
509
+ if (!hasInvocationHook) {
510
+ Object.defineProperties(value, {
511
+ [invocationHookBrand]: {
512
+ configurable: false,
513
+ enumerable: false,
514
+ value: GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION,
515
+ writable: false
516
+ },
517
+ hasInterceptors: {
518
+ configurable: false,
519
+ enumerable: false,
520
+ get: () => invocationHook.hasInterceptors
521
+ },
522
+ intercept: {
523
+ configurable: false,
524
+ enumerable: false,
525
+ value: invocationHook.intercept.bind(invocationHook),
526
+ writable: false
527
+ },
528
+ invoke: {
529
+ configurable: false,
530
+ enumerable: false,
531
+ value: invocationHook.invoke.bind(invocationHook),
532
+ writable: false
533
+ }
534
+ });
535
+ }
536
+ if (typeof value.traceInvocation !== "function") {
537
+ Object.defineProperty(value, "traceInvocation", {
538
+ configurable: false,
539
+ enumerable: false,
540
+ value: traceInvocation.bind(void 0, value),
541
+ writable: false
542
+ });
543
+ }
544
+ } catch (error) {
545
+ reportError(error);
546
+ }
547
+ }
409
548
  function isCompatibleTracingHook(value) {
410
549
  try {
411
550
  return value[hookBrand] === GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION && hasTracingHookShape(value);
@@ -492,6 +631,7 @@ function newGlobalTracingChannel(nameOrChannels) {
492
631
  return inertTracingHook;
493
632
  }
494
633
  if (isCompatibleTracingHook(existing)) {
634
+ installInvocationHook(existing);
495
635
  return existing;
496
636
  }
497
637
  if (existing !== void 0) {
@@ -556,6 +696,7 @@ var INSTRUMENTATION_NAMES = {
556
696
  CLAUDE_AGENT_SDK: "claude-agent-sdk",
557
697
  CLOUDFLARE_AI_CHAT: "cloudflare-ai-chat",
558
698
  CLOUDFLARE_AGENTS: "cloudflare-agents",
699
+ CLOUDFLARE_THINK: "cloudflare-think",
559
700
  COHERE: "cohere",
560
701
  CURSOR_SDK: "cursor-sdk",
561
702
  EVE: "eve",
@@ -570,18 +711,20 @@ var INSTRUMENTATION_NAMES = {
570
711
  LANGSMITH: "langsmith",
571
712
  MASTRA: "mastra",
572
713
  MISTRAL: "mistral",
714
+ OLLAMA: "ollama",
573
715
  OPENAI: "openai",
574
716
  OPENAI_AGENTS: "openai-agents",
575
717
  OPENAI_CODEX: "openai-codex",
576
718
  OPENROUTER: "openrouter",
577
719
  OPENROUTER_AGENT: "openrouter-agent",
578
720
  PI_CODING_AGENT: "pi-coding-agent",
579
- STRANDS_AGENT_SDK: "strands-agent-sdk"
721
+ STRANDS_AGENT_SDK: "strands-agent-sdk",
722
+ VOYAGEAI: "voyageai"
580
723
  };
581
724
  var INTERNAL_SPAN_INSTRUMENTATION_NAME = /* @__PURE__ */ Symbol.for(
582
725
  "braintrust.spanInstrumentationName"
583
726
  );
584
- var SDK_VERSION = true ? "3.26.0" : "0.0.0";
727
+ var SDK_VERSION = true ? "3.28.0" : "0.0.0";
585
728
  function withSpanInstrumentationName(args, instrumentationName) {
586
729
  return {
587
730
  ...args,
@@ -701,11 +844,21 @@ function defineChannels(pkg, channels, options) {
701
844
  const tracingChannel2 = () => isomorph_default.newTracingChannel(
702
845
  fullChannelName
703
846
  );
847
+ const intercept2 = (interceptor) => {
848
+ const hook = tracingChannel2();
849
+ return typeof hook.intercept === "function" ? hook.intercept(interceptor) : () => {
850
+ };
851
+ };
704
852
  return [
705
853
  key,
706
854
  {
707
855
  ...asyncSpec,
708
856
  instrumentationName,
857
+ intercept: intercept2,
858
+ invoke: (target, thisArg, args, additional) => {
859
+ const hook = tracingChannel2();
860
+ return typeof hook.invoke === "function" ? hook.invoke(target, thisArg, args, additional) : Reflect.apply(target, thisArg, args);
861
+ },
709
862
  tracingChannel: tracingChannel2,
710
863
  tracePromise: (fn, context) => tracingChannel2().tracePromise(
711
864
  fn,
@@ -719,11 +872,21 @@ function defineChannels(pkg, channels, options) {
719
872
  const tracingChannel = () => isomorph_default.newTracingChannel(
720
873
  fullChannelName
721
874
  );
875
+ const intercept = (interceptor) => {
876
+ const hook = tracingChannel();
877
+ return typeof hook.intercept === "function" ? hook.intercept(interceptor) : () => {
878
+ };
879
+ };
722
880
  return [
723
881
  key,
724
882
  {
725
883
  ...syncSpec,
726
884
  instrumentationName,
885
+ intercept,
886
+ invoke: (target, thisArg, args, additional) => {
887
+ const hook = tracingChannel();
888
+ return typeof hook.invoke === "function" ? hook.invoke(target, thisArg, args, additional) : Reflect.apply(target, thisArg, args);
889
+ },
727
890
  tracingChannel,
728
891
  traceSync: (fn, context) => tracingChannel().traceSync(
729
892
  fn,
@@ -811,6 +974,14 @@ var anthropicChannels = defineChannels(
811
974
  betaMessagesToolRunner: channel({
812
975
  channelName: "beta.messages.toolRunner",
813
976
  kind: "sync-stream"
977
+ }),
978
+ betaSessionsEventsStream: channel({
979
+ channelName: "beta.sessions.events.stream",
980
+ kind: "async"
981
+ }),
982
+ betaSessionsThreadsEventsStream: channel({
983
+ channelName: "beta.sessions.threads.events.stream",
984
+ kind: "async"
814
985
  })
815
986
  },
816
987
  { instrumentationName: INSTRUMENTATION_NAMES.ANTHROPIC }
@@ -926,6 +1097,18 @@ var claudeAgentSDKChannels = defineChannels(
926
1097
  { instrumentationName: INSTRUMENTATION_NAMES.CLAUDE_AGENT_SDK }
927
1098
  );
928
1099
 
1100
+ // src/instrumentation/plugins/cloudflare-think-channels.ts
1101
+ var cloudflareThinkChannels = defineChannels(
1102
+ "@cloudflare/think",
1103
+ {
1104
+ runInferenceLoop: channel({
1105
+ channelName: "Think.runInferenceLoop",
1106
+ kind: "async"
1107
+ })
1108
+ },
1109
+ { instrumentationName: INSTRUMENTATION_NAMES.CLOUDFLARE_THINK }
1110
+ );
1111
+
929
1112
  // src/instrumentation/plugins/cursor-sdk-channels.ts
930
1113
  var cursorSDKChannels = defineChannels(
931
1114
  "@cursor/sdk",
@@ -1150,6 +1333,26 @@ var mistralChannels = defineChannels(
1150
1333
  { instrumentationName: INSTRUMENTATION_NAMES.MISTRAL }
1151
1334
  );
1152
1335
 
1336
+ // src/instrumentation/plugins/ollama-channels.ts
1337
+ var ollamaChannels = defineChannels(
1338
+ "ollama",
1339
+ {
1340
+ chat: channel({
1341
+ channelName: "chat",
1342
+ kind: "async"
1343
+ }),
1344
+ generate: channel({
1345
+ channelName: "generate",
1346
+ kind: "async"
1347
+ }),
1348
+ embed: channel({
1349
+ channelName: "embed",
1350
+ kind: "async"
1351
+ })
1352
+ },
1353
+ { instrumentationName: INSTRUMENTATION_NAMES.OLLAMA }
1354
+ );
1355
+
1153
1356
  // src/instrumentation/plugins/google-adk-channels.ts
1154
1357
  var googleADKChannels = defineChannels(
1155
1358
  "@google/adk",
@@ -1363,6 +1566,30 @@ var strandsAgentSDKChannels = defineChannels(
1363
1566
  { instrumentationName: INSTRUMENTATION_NAMES.STRANDS_AGENT_SDK }
1364
1567
  );
1365
1568
 
1569
+ // src/instrumentation/plugins/voyageai-channels.ts
1570
+ var voyageAIChannels = defineChannels(
1571
+ "voyageai",
1572
+ {
1573
+ embed: channel({
1574
+ channelName: "embed",
1575
+ kind: "async"
1576
+ }),
1577
+ multimodalEmbed: channel({
1578
+ channelName: "multimodalEmbed",
1579
+ kind: "async"
1580
+ }),
1581
+ rerank: channel({
1582
+ channelName: "rerank",
1583
+ kind: "async"
1584
+ }),
1585
+ contextualizedEmbed: channel({
1586
+ channelName: "contextualizedEmbed",
1587
+ kind: "async"
1588
+ })
1589
+ },
1590
+ { instrumentationName: INSTRUMENTATION_NAMES.VOYAGEAI }
1591
+ );
1592
+
1366
1593
  // src/instrumentation/plugins/cloudflare-agents-channels.ts
1367
1594
  var cloudflareAgentsChannels = defineChannels(
1368
1595
  "agents",
@@ -1405,6 +1632,7 @@ var envIntegrationAliases = {
1405
1632
  cloudflareaichat: "cloudflareAIChat",
1406
1633
  "cloudflare-ai-chat": "cloudflareAIChat",
1407
1634
  "@cloudflare/ai-chat": "cloudflareAIChat",
1635
+ cloudflarethink: "cloudflareThink",
1408
1636
  cursor: "cursor",
1409
1637
  "cursor-sdk": "cursorSDK",
1410
1638
  cursorsdk: "cursorSDK",
@@ -1425,6 +1653,7 @@ var envIntegrationAliases = {
1425
1653
  openrouteragent: "openrouterAgent",
1426
1654
  "openrouter-agent": "openrouterAgent",
1427
1655
  mistral: "mistral",
1656
+ ollama: "ollama",
1428
1657
  googleadk: "googleADK",
1429
1658
  "google-adk": "googleADK",
1430
1659
  cohere: "cohere",
@@ -1445,7 +1674,10 @@ var envIntegrationAliases = {
1445
1674
  "langchain-js": "langchain",
1446
1675
  "@langchain": "langchain",
1447
1676
  langgraph: "langgraph",
1448
- langsmith: "langsmith"
1677
+ langsmith: "langsmith",
1678
+ voyage: "voyageai",
1679
+ "voyage-ai": "voyageai",
1680
+ voyageai: "voyageai"
1449
1681
  };
1450
1682
  function getDefaultInstrumentationIntegrations() {
1451
1683
  return {
@@ -1460,6 +1692,7 @@ function getDefaultInstrumentationIntegrations() {
1460
1692
  huggingface: true,
1461
1693
  claudeAgentSDK: true,
1462
1694
  cloudflareAIChat: true,
1695
+ cloudflareThink: true,
1463
1696
  cursor: true,
1464
1697
  cursorSDK: true,
1465
1698
  flue: true,
@@ -1468,6 +1701,7 @@ function getDefaultInstrumentationIntegrations() {
1468
1701
  openrouter: true,
1469
1702
  openrouterAgent: true,
1470
1703
  mistral: true,
1704
+ ollama: true,
1471
1705
  cohere: true,
1472
1706
  groq: true,
1473
1707
  bedrock: true,
@@ -1478,6 +1712,7 @@ function getDefaultInstrumentationIntegrations() {
1478
1712
  langchain: true,
1479
1713
  langgraph: true,
1480
1714
  langsmith: true,
1715
+ voyageai: true,
1481
1716
  piCodingAgent: true,
1482
1717
  strandsAgentSDK: true,
1483
1718
  cloudflareAgents: true
@@ -1748,6 +1983,7 @@ export {
1748
1983
  aiSDKChannels,
1749
1984
  harnessAgentChannels,
1750
1985
  claudeAgentSDKChannels,
1986
+ cloudflareThinkChannels,
1751
1987
  cursorSDKChannels,
1752
1988
  openAIAgentsCoreChannels,
1753
1989
  googleGenAIChannels,
@@ -1759,6 +1995,7 @@ export {
1759
1995
  openRouterAgentChannels,
1760
1996
  openRouterChannels,
1761
1997
  mistralChannels,
1998
+ ollamaChannels,
1762
1999
  googleADKChannels,
1763
2000
  cohereChannels,
1764
2001
  groqChannels,
@@ -1773,6 +2010,7 @@ export {
1773
2010
  langSmithChannels,
1774
2011
  piCodingAgentChannels,
1775
2012
  strandsAgentSDKChannels,
2013
+ voyageAIChannels,
1776
2014
  cloudflareAIChatChannels,
1777
2015
  cloudflareAgentsChannels,
1778
2016
  getDefaultInstrumentationIntegrations,