braintrust 3.6.0 → 3.7.1

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 (33) hide show
  1. package/dev/dist/index.js +2692 -1472
  2. package/dev/dist/index.mjs +2616 -1396
  3. package/dist/auto-instrumentations/bundler/esbuild.cjs +46 -21
  4. package/dist/auto-instrumentations/bundler/esbuild.mjs +2 -2
  5. package/dist/auto-instrumentations/bundler/rollup.cjs +46 -21
  6. package/dist/auto-instrumentations/bundler/rollup.mjs +2 -2
  7. package/dist/auto-instrumentations/bundler/vite.cjs +46 -21
  8. package/dist/auto-instrumentations/bundler/vite.mjs +2 -2
  9. package/dist/auto-instrumentations/bundler/webpack-loader.cjs +952 -0
  10. package/dist/auto-instrumentations/bundler/webpack-loader.d.ts +53 -0
  11. package/dist/auto-instrumentations/bundler/webpack.cjs +46 -21
  12. package/dist/auto-instrumentations/bundler/webpack.mjs +2 -2
  13. package/dist/auto-instrumentations/{chunk-WOUC73KB.mjs → chunk-NY4CGTN6.mjs} +1 -1
  14. package/dist/auto-instrumentations/{chunk-F7WAXFNM.mjs → chunk-YCKND42U.mjs} +46 -21
  15. package/dist/auto-instrumentations/hook.mjs +77 -26
  16. package/dist/auto-instrumentations/index.cjs +46 -21
  17. package/dist/auto-instrumentations/index.mjs +1 -1
  18. package/dist/browser.d.mts +8 -30
  19. package/dist/browser.d.ts +8 -30
  20. package/dist/browser.js +5051 -6344
  21. package/dist/browser.mjs +5051 -6344
  22. package/dist/cli.js +2622 -1398
  23. package/dist/edge-light.js +9456 -10773
  24. package/dist/edge-light.mjs +9456 -10773
  25. package/dist/index.d.mts +8 -30
  26. package/dist/index.d.ts +8 -30
  27. package/dist/index.js +5078 -6371
  28. package/dist/index.mjs +4870 -6163
  29. package/dist/instrumentation/index.js +2491 -1319
  30. package/dist/instrumentation/index.mjs +2491 -1319
  31. package/dist/workerd.js +9456 -10773
  32. package/dist/workerd.mjs +9456 -10773
  33. package/package.json +6 -2
@@ -101,7 +101,7 @@ var DefaultTracingChannel = class {
101
101
  }
102
102
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
103
103
  tracePromise(fn, _message, thisArg, ...args) {
104
- return Promise.resolve(fn.apply(thisArg, args));
104
+ return fn.apply(thisArg, args);
105
105
  }
106
106
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
107
107
  traceCallback(fn, _position, _message, thisArg, ...args) {
@@ -121,6 +121,7 @@ var iso = {
121
121
  processOn: (_0, _1) => {
122
122
  },
123
123
  basename: (filepath) => filepath.split(/[\\/]/).pop() || filepath,
124
+ // eslint-disable-next-line no-restricted-properties -- preserving intentional console usage.
124
125
  writeln: (text) => console.log(text)
125
126
  };
126
127
  var isomorph_default = iso;
@@ -387,12 +388,26 @@ var anthropicChannels = defineChannels("@anthropic-ai/sdk", {
387
388
 
388
389
  // src/auto-instrumentations/configs/anthropic.ts
389
390
  var anthropicConfigs = [
391
+ // Messages API - create in older SDK layouts (supports streaming via stream=true parameter)
392
+ {
393
+ channelName: anthropicChannels.messagesCreate.channelName,
394
+ module: {
395
+ name: "@anthropic-ai/sdk",
396
+ versionRange: ">=0.27.0 <0.39.0",
397
+ filePath: "resources/messages.mjs"
398
+ },
399
+ functionQuery: {
400
+ className: "Messages",
401
+ methodName: "create",
402
+ kind: "Async"
403
+ }
404
+ },
390
405
  // Messages API - create (supports streaming via stream=true parameter)
391
406
  {
392
407
  channelName: anthropicChannels.messagesCreate.channelName,
393
408
  module: {
394
409
  name: "@anthropic-ai/sdk",
395
- versionRange: ">=0.60.0",
410
+ versionRange: ">=0.39.0",
396
411
  filePath: "resources/messages/messages.mjs"
397
412
  },
398
413
  functionQuery: {
@@ -406,7 +421,7 @@ var anthropicConfigs = [
406
421
  channelName: anthropicChannels.betaMessagesCreate.channelName,
407
422
  module: {
408
423
  name: "@anthropic-ai/sdk",
409
- versionRange: ">=0.60.0",
424
+ versionRange: ">=0.39.0",
410
425
  filePath: "resources/beta/messages/messages.mjs"
411
426
  },
412
427
  functionQuery: {
@@ -427,10 +442,6 @@ var aiSDKChannels = defineChannels("ai", {
427
442
  channelName: "streamText",
428
443
  kind: "async"
429
444
  }),
430
- streamTextSync: channel({
431
- channelName: "streamText.sync",
432
- kind: "sync-stream"
433
- }),
434
445
  generateObject: channel({
435
446
  channelName: "generateObject",
436
447
  kind: "async"
@@ -439,10 +450,6 @@ var aiSDKChannels = defineChannels("ai", {
439
450
  channelName: "streamObject",
440
451
  kind: "async"
441
452
  }),
442
- streamObjectSync: channel({
443
- channelName: "streamObject.sync",
444
- kind: "sync-stream"
445
- }),
446
453
  agentGenerate: channel({
447
454
  channelName: "Agent.generate",
448
455
  kind: "async"
@@ -488,7 +495,7 @@ var aiSDKConfigs = [
488
495
  kind: "Async"
489
496
  }
490
497
  },
491
- // streamText - async function
498
+ // streamText - function returning stream
492
499
  {
493
500
  channelName: aiSDKChannels.streamText.channelName,
494
501
  module: {
@@ -502,7 +509,7 @@ var aiSDKConfigs = [
502
509
  }
503
510
  },
504
511
  {
505
- channelName: aiSDKChannels.streamTextSync.channelName,
512
+ channelName: aiSDKChannels.streamText.channelName,
506
513
  module: {
507
514
  name: "ai",
508
515
  versionRange: ">=3.0.0",
@@ -510,7 +517,7 @@ var aiSDKConfigs = [
510
517
  },
511
518
  functionQuery: {
512
519
  functionName: "streamText",
513
- kind: "Sync"
520
+ kind: "Async"
514
521
  }
515
522
  },
516
523
  // generateObject - async function
@@ -538,7 +545,7 @@ var aiSDKConfigs = [
538
545
  kind: "Async"
539
546
  }
540
547
  },
541
- // streamObject - async function
548
+ // streamObject - function returning stream
542
549
  {
543
550
  channelName: aiSDKChannels.streamObject.channelName,
544
551
  module: {
@@ -552,7 +559,7 @@ var aiSDKConfigs = [
552
559
  }
553
560
  },
554
561
  {
555
- channelName: aiSDKChannels.streamObjectSync.channelName,
562
+ channelName: aiSDKChannels.streamObject.channelName,
556
563
  module: {
557
564
  name: "ai",
558
565
  versionRange: ">=3.0.0",
@@ -560,7 +567,7 @@ var aiSDKConfigs = [
560
567
  },
561
568
  functionQuery: {
562
569
  functionName: "streamObject",
563
- kind: "Sync"
570
+ kind: "Async"
564
571
  }
565
572
  },
566
573
  // Agent.generate - async method (v5 only)
@@ -687,24 +694,38 @@ var claudeAgentSDKChannels = defineChannels(
687
694
  {
688
695
  query: channel({
689
696
  channelName: "query",
690
- kind: "async"
697
+ kind: "sync-stream"
691
698
  })
692
699
  }
693
700
  );
694
701
 
695
702
  // src/auto-instrumentations/configs/claude-agent-sdk.ts
696
703
  var claudeAgentSDKConfigs = [
697
- // query - Main entry point for agent interactions (top-level exported async generator function)
704
+ // query - Main entry point for agent interactions. The SDK returns an async
705
+ // iterable, but the exported query function itself is synchronous.
698
706
  {
699
707
  channelName: claudeAgentSDKChannels.query.channelName,
700
708
  module: {
701
709
  name: "@anthropic-ai/claude-agent-sdk",
702
- versionRange: ">=0.1.0",
710
+ versionRange: ">=0.1.0 <0.2.0",
703
711
  filePath: "sdk.mjs"
704
712
  },
705
713
  functionQuery: {
706
714
  functionName: "query",
707
- kind: "Async"
715
+ kind: "Sync"
716
+ }
717
+ },
718
+ {
719
+ channelName: claudeAgentSDKChannels.query.channelName,
720
+ module: {
721
+ name: "@anthropic-ai/claude-agent-sdk",
722
+ versionRange: ">=0.2.0",
723
+ filePath: "sdk.mjs"
724
+ },
725
+ functionQuery: {
726
+ functionName: "query",
727
+ kind: "Sync",
728
+ isExportAlias: true
708
729
  }
709
730
  }
710
731
  ];
@@ -773,6 +794,10 @@ var openRouterChannels = defineChannels("@openrouter/sdk", {
773
794
  channelName: "callModel",
774
795
  kind: "sync-stream"
775
796
  }),
797
+ callModelTurn: channel({
798
+ channelName: "callModel.turn",
799
+ kind: "async"
800
+ }),
776
801
  toolExecute: channel({
777
802
  channelName: "tool.execute",
778
803
  kind: "async"
@@ -5,7 +5,7 @@ import {
5
5
  googleGenAIConfigs,
6
6
  openRouterConfigs,
7
7
  openaiConfigs
8
- } from "./chunk-F7WAXFNM.mjs";
8
+ } from "./chunk-YCKND42U.mjs";
9
9
  export {
10
10
  aiSDKConfigs,
11
11
  anthropicConfigs,
@@ -15756,7 +15756,7 @@ interface IsoTracingChannel<M = any> extends IsoTracingChannelCollection<M> {
15756
15756
  subscribe(handlers: IsoChannelHandlers<M>): void;
15757
15757
  unsubscribe(handlers: IsoChannelHandlers<M>): boolean;
15758
15758
  traceSync<F extends (...args: any[]) => any>(fn: F, message?: M, thisArg?: ThisParameterType<F>, ...args: Parameters<F>): ReturnType<F>;
15759
- tracePromise<F extends (...args: any[]) => any>(fn: F, message?: M, thisArg?: ThisParameterType<F>, ...args: Parameters<F>): Promise<Awaited<ReturnType<F>>>;
15759
+ tracePromise<F extends (...args: any[]) => PromiseLike<any>>(fn: F, message?: M, thisArg?: ThisParameterType<F>, ...args: Parameters<F>): ReturnType<F>;
15760
15760
  traceCallback<F extends (...args: any[]) => any>(fn: F, position?: number, message?: M, thisArg?: ThisParameterType<F>, ...args: Parameters<F>): ReturnType<F>;
15761
15761
  }
15762
15762
  interface IsoChannelHandlers<M = any> {
@@ -20988,12 +20988,10 @@ interface WrapAISDKOptions {
20988
20988
  denyOutputPaths?: string[];
20989
20989
  }
20990
20990
  /**
20991
- * Wraps Vercel AI SDK methods with Braintrust tracing. Returns wrapped versions
20992
- * of generateText, streamText, generateObject, streamObject, Agent, experimental_Agent,
20993
- * and ToolLoopAgent that automatically create spans and log inputs, outputs, and metrics.
20991
+ * Wraps Vercel AI SDK methods with Braintrust tracing.
20994
20992
  *
20995
20993
  * @param ai - The AI SDK namespace (e.g., import * as ai from "ai")
20996
- * @returns Object with AI SDK methods with Braintrust tracing
20994
+ * @returns AI SDK with Braintrust tracing.
20997
20995
  *
20998
20996
  * @example
20999
20997
  * ```typescript
@@ -21074,9 +21072,8 @@ interface MiddlewareConfig {
21074
21072
  declare function BraintrustMiddleware(config?: MiddlewareConfig): LanguageModelV2Middleware<any, any>;
21075
21073
 
21076
21074
  /**
21077
- * Wrap an `Anthropic` object (created with `new Anthropic(...)`) to add tracing. If Braintrust is
21078
- * not configured, nothing will be traced. If this is not an `Anthropic` object, this function is
21079
- * a no-op.
21075
+ * Wrap an `Anthropic` object (created with `new Anthropic(...)`) so calls emit
21076
+ * tracing-channel events that Braintrust plugins can consume.
21080
21077
  *
21081
21078
  * Currently, this only supports the `v4` API.
21082
21079
  *
@@ -21094,31 +21091,12 @@ declare function wrapMastraAgent<T>(agent: T, _options?: {
21094
21091
  }): T;
21095
21092
 
21096
21093
  /**
21097
- * Wraps the Claude Agent SDK with Braintrust tracing. This returns wrapped versions
21098
- * of query and tool that automatically trace all agent interactions.
21094
+ * Wraps the Claude Agent SDK with Braintrust tracing. Query calls only publish
21095
+ * tracing-channel events; the Claude Agent SDK plugin owns all span lifecycle
21096
+ * work, including root/task spans, LLM spans, tool spans, and sub-agent spans.
21099
21097
  *
21100
21098
  * @param sdk - The Claude Agent SDK module
21101
21099
  * @returns Object with wrapped query, tool, and createSdkMcpServer functions
21102
- *
21103
- * @example
21104
- * ```typescript
21105
- * import * as claudeSDK from "@anthropic-ai/claude-agent-sdk";
21106
- * import { wrapClaudeAgentSDK } from "braintrust";
21107
- *
21108
- * // Wrap once - returns { query, tool, createSdkMcpServer } with tracing built-in
21109
- * const { query, tool, createSdkMcpServer } = wrapClaudeAgentSDK(claudeSDK);
21110
- *
21111
- * // Use normally - tracing is automatic
21112
- * for await (const message of query({
21113
- * prompt: "Hello, Claude!",
21114
- * options: { model: "claude-haiku-4-5-20251001" }
21115
- * })) {
21116
- * console.log(message);
21117
- * }
21118
- *
21119
- * // Tools created with wrapped tool() are automatically traced
21120
- * const calculator = tool("calculator", "Does math", schema, handler);
21121
- * ```
21122
21100
  */
21123
21101
  declare function wrapClaudeAgentSDK<T extends object>(sdk: T): T;
21124
21102
 
package/dist/browser.d.ts CHANGED
@@ -15756,7 +15756,7 @@ interface IsoTracingChannel<M = any> extends IsoTracingChannelCollection<M> {
15756
15756
  subscribe(handlers: IsoChannelHandlers<M>): void;
15757
15757
  unsubscribe(handlers: IsoChannelHandlers<M>): boolean;
15758
15758
  traceSync<F extends (...args: any[]) => any>(fn: F, message?: M, thisArg?: ThisParameterType<F>, ...args: Parameters<F>): ReturnType<F>;
15759
- tracePromise<F extends (...args: any[]) => any>(fn: F, message?: M, thisArg?: ThisParameterType<F>, ...args: Parameters<F>): Promise<Awaited<ReturnType<F>>>;
15759
+ tracePromise<F extends (...args: any[]) => PromiseLike<any>>(fn: F, message?: M, thisArg?: ThisParameterType<F>, ...args: Parameters<F>): ReturnType<F>;
15760
15760
  traceCallback<F extends (...args: any[]) => any>(fn: F, position?: number, message?: M, thisArg?: ThisParameterType<F>, ...args: Parameters<F>): ReturnType<F>;
15761
15761
  }
15762
15762
  interface IsoChannelHandlers<M = any> {
@@ -20988,12 +20988,10 @@ interface WrapAISDKOptions {
20988
20988
  denyOutputPaths?: string[];
20989
20989
  }
20990
20990
  /**
20991
- * Wraps Vercel AI SDK methods with Braintrust tracing. Returns wrapped versions
20992
- * of generateText, streamText, generateObject, streamObject, Agent, experimental_Agent,
20993
- * and ToolLoopAgent that automatically create spans and log inputs, outputs, and metrics.
20991
+ * Wraps Vercel AI SDK methods with Braintrust tracing.
20994
20992
  *
20995
20993
  * @param ai - The AI SDK namespace (e.g., import * as ai from "ai")
20996
- * @returns Object with AI SDK methods with Braintrust tracing
20994
+ * @returns AI SDK with Braintrust tracing.
20997
20995
  *
20998
20996
  * @example
20999
20997
  * ```typescript
@@ -21074,9 +21072,8 @@ interface MiddlewareConfig {
21074
21072
  declare function BraintrustMiddleware(config?: MiddlewareConfig): LanguageModelV2Middleware<any, any>;
21075
21073
 
21076
21074
  /**
21077
- * Wrap an `Anthropic` object (created with `new Anthropic(...)`) to add tracing. If Braintrust is
21078
- * not configured, nothing will be traced. If this is not an `Anthropic` object, this function is
21079
- * a no-op.
21075
+ * Wrap an `Anthropic` object (created with `new Anthropic(...)`) so calls emit
21076
+ * tracing-channel events that Braintrust plugins can consume.
21080
21077
  *
21081
21078
  * Currently, this only supports the `v4` API.
21082
21079
  *
@@ -21094,31 +21091,12 @@ declare function wrapMastraAgent<T>(agent: T, _options?: {
21094
21091
  }): T;
21095
21092
 
21096
21093
  /**
21097
- * Wraps the Claude Agent SDK with Braintrust tracing. This returns wrapped versions
21098
- * of query and tool that automatically trace all agent interactions.
21094
+ * Wraps the Claude Agent SDK with Braintrust tracing. Query calls only publish
21095
+ * tracing-channel events; the Claude Agent SDK plugin owns all span lifecycle
21096
+ * work, including root/task spans, LLM spans, tool spans, and sub-agent spans.
21099
21097
  *
21100
21098
  * @param sdk - The Claude Agent SDK module
21101
21099
  * @returns Object with wrapped query, tool, and createSdkMcpServer functions
21102
- *
21103
- * @example
21104
- * ```typescript
21105
- * import * as claudeSDK from "@anthropic-ai/claude-agent-sdk";
21106
- * import { wrapClaudeAgentSDK } from "braintrust";
21107
- *
21108
- * // Wrap once - returns { query, tool, createSdkMcpServer } with tracing built-in
21109
- * const { query, tool, createSdkMcpServer } = wrapClaudeAgentSDK(claudeSDK);
21110
- *
21111
- * // Use normally - tracing is automatic
21112
- * for await (const message of query({
21113
- * prompt: "Hello, Claude!",
21114
- * options: { model: "claude-haiku-4-5-20251001" }
21115
- * })) {
21116
- * console.log(message);
21117
- * }
21118
- *
21119
- * // Tools created with wrapped tool() are automatically traced
21120
- * const calculator = tool("calculator", "Does math", schema, handler);
21121
- * ```
21122
21100
  */
21123
21101
  declare function wrapClaudeAgentSDK<T extends object>(sdk: T): T;
21124
21102