braintrust 3.28.0 → 3.30.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 (54) hide show
  1. package/README.md +1 -1
  2. package/dev/dist/index.d.mts +356 -7
  3. package/dev/dist/index.d.ts +356 -7
  4. package/dev/dist/index.js +2679 -1828
  5. package/dev/dist/index.mjs +1862 -1011
  6. package/dist/apply-auto-instrumentation.js +298 -265
  7. package/dist/apply-auto-instrumentation.mjs +85 -52
  8. package/dist/auto-instrumentations/bundler/esbuild.cjs +56 -6
  9. package/dist/auto-instrumentations/bundler/esbuild.mjs +2 -2
  10. package/dist/auto-instrumentations/bundler/next.cjs +56 -6
  11. package/dist/auto-instrumentations/bundler/next.mjs +3 -3
  12. package/dist/auto-instrumentations/bundler/rollup.cjs +56 -6
  13. package/dist/auto-instrumentations/bundler/rollup.mjs +2 -2
  14. package/dist/auto-instrumentations/bundler/vite.cjs +56 -6
  15. package/dist/auto-instrumentations/bundler/vite.mjs +2 -2
  16. package/dist/auto-instrumentations/bundler/webpack-loader.cjs +56 -6
  17. package/dist/auto-instrumentations/bundler/webpack.cjs +56 -6
  18. package/dist/auto-instrumentations/bundler/webpack.mjs +3 -3
  19. package/dist/auto-instrumentations/{chunk-26PKVUKB.mjs → chunk-LW4HDHXT.mjs} +12 -4
  20. package/dist/auto-instrumentations/{chunk-HD35AM3M.mjs → chunk-OXINGIEZ.mjs} +1 -1
  21. package/dist/auto-instrumentations/{chunk-NP7V4XB2.mjs → chunk-U64OYU4Q.mjs} +45 -3
  22. package/dist/auto-instrumentations/hook.mjs +967 -136
  23. package/dist/auto-instrumentations/index.cjs +45 -3
  24. package/dist/auto-instrumentations/index.mjs +1 -1
  25. package/dist/browser.d.mts +893 -24
  26. package/dist/browser.d.ts +893 -24
  27. package/dist/browser.js +2795 -1136
  28. package/dist/browser.mjs +2795 -1136
  29. package/dist/{chunk-BBE7SNRV.js → chunk-2XDW3UCG.js} +155 -23
  30. package/dist/{chunk-UPFNQCGB.mjs → chunk-BU6SM54N.mjs} +1830 -1045
  31. package/dist/{chunk-ZHUHZWFY.mjs → chunk-N3JKQ3D3.mjs} +152 -20
  32. package/dist/{chunk-OBBWQW6K.js → chunk-TWCDSYJN.js} +2890 -2105
  33. package/dist/cli.js +5976 -1348
  34. package/dist/edge-light.d.mts +1 -1
  35. package/dist/edge-light.d.ts +1 -1
  36. package/dist/edge-light.js +2795 -1136
  37. package/dist/edge-light.mjs +2795 -1136
  38. package/dist/index.d.mts +893 -24
  39. package/dist/index.d.ts +893 -24
  40. package/dist/index.js +1448 -699
  41. package/dist/index.mjs +848 -99
  42. package/dist/instrumentation/index.d.mts +563 -9
  43. package/dist/instrumentation/index.d.ts +563 -9
  44. package/dist/instrumentation/index.js +2794 -989
  45. package/dist/instrumentation/index.mjs +2794 -989
  46. package/dist/vitest-evals-reporter.js +16 -16
  47. package/dist/vitest-evals-reporter.mjs +2 -2
  48. package/dist/workerd.d.mts +1 -1
  49. package/dist/workerd.d.ts +1 -1
  50. package/dist/workerd.js +2795 -1136
  51. package/dist/workerd.mjs +2795 -1136
  52. package/package.json +1 -1
  53. package/util/dist/index.d.mts +42 -0
  54. package/util/dist/index.d.ts +42 -0
@@ -659,8 +659,6 @@ function newGlobalTracingChannel(nameOrChannels) {
659
659
  var DefaultAsyncLocalStorage = class {
660
660
  constructor() {
661
661
  }
662
- enterWith(_) {
663
- }
664
662
  run(_, callback) {
665
663
  return callback();
666
664
  }
@@ -687,6 +685,118 @@ var iso = {
687
685
  };
688
686
  var isomorph_default = iso;
689
687
 
688
+ // src/debug-logger.ts
689
+ var PREFIX = "[braintrust]";
690
+ var DEBUG_LOG_LEVEL_SYMBOL = /* @__PURE__ */ Symbol.for("braintrust-debug-log-level");
691
+ var LOG_LEVEL_PRIORITY = {
692
+ error: 0,
693
+ warn: 1,
694
+ info: 2,
695
+ debug: 3
696
+ };
697
+ var hasWarnedAboutInvalidEnvValue = false;
698
+ var debugLogStateResolver = void 0;
699
+ function warnInvalidEnvValue(value) {
700
+ if (hasWarnedAboutInvalidEnvValue) {
701
+ return;
702
+ }
703
+ hasWarnedAboutInvalidEnvValue = true;
704
+ console.warn(
705
+ PREFIX,
706
+ `Invalid BRAINTRUST_DEBUG_LOG_LEVEL value "${value}". Expected "error", "warn", "info", or "debug".`
707
+ );
708
+ }
709
+ function normalizeDebugLogLevelOption(option) {
710
+ if (option === false) {
711
+ return void 0;
712
+ }
713
+ if (option === "error" || option === "warn" || option === "info" || option === "debug") {
714
+ return option;
715
+ }
716
+ throw new Error(
717
+ `Invalid debugLogLevel value "${option}". Expected false, "error", "warn", "info", or "debug".`
718
+ );
719
+ }
720
+ function parseDebugLogLevelEnv(value) {
721
+ if (!value) {
722
+ return void 0;
723
+ }
724
+ if (value === "error" || value === "warn" || value === "info" || value === "debug") {
725
+ return value;
726
+ }
727
+ warnInvalidEnvValue(value);
728
+ return void 0;
729
+ }
730
+ function getEnvDebugLogLevel() {
731
+ return parseDebugLogLevelEnv(isomorph_default.getEnv("BRAINTRUST_DEBUG_LOG_LEVEL"));
732
+ }
733
+ function setGlobalDebugLogLevel(level) {
734
+ globalThis[DEBUG_LOG_LEVEL_SYMBOL] = level;
735
+ }
736
+ function resetDebugLoggerForTests() {
737
+ hasWarnedAboutInvalidEnvValue = false;
738
+ setGlobalDebugLogLevel(void 0);
739
+ }
740
+ function setDebugLogStateResolver(resolver) {
741
+ debugLogStateResolver = resolver;
742
+ }
743
+ function resolveDebugLogLevel(state) {
744
+ const stateLevel = state?.getDebugLogLevel?.();
745
+ const hasStateOverride = state?.hasDebugLogLevelOverride?.() ?? false;
746
+ if (hasStateOverride) {
747
+ return stateLevel;
748
+ }
749
+ const globalLevel = (
750
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
751
+ globalThis[DEBUG_LOG_LEVEL_SYMBOL]
752
+ );
753
+ if (globalLevel !== void 0) {
754
+ return globalLevel === false ? void 0 : globalLevel;
755
+ }
756
+ return getEnvDebugLogLevel();
757
+ }
758
+ function emit(method, state, args) {
759
+ const level = resolveDebugLogLevel(state);
760
+ if (!level || LOG_LEVEL_PRIORITY[method] > LOG_LEVEL_PRIORITY[level]) {
761
+ return;
762
+ }
763
+ if (method === "info") {
764
+ console.log(PREFIX, ...args);
765
+ } else if (method === "debug") {
766
+ console.debug(PREFIX, ...args);
767
+ } else if (method === "warn") {
768
+ console.warn(PREFIX, ...args);
769
+ } else {
770
+ console.error(PREFIX, ...args);
771
+ }
772
+ }
773
+ function createDebugLogger(state) {
774
+ const resolveState = () => state ?? debugLogStateResolver?.();
775
+ return {
776
+ info(...args) {
777
+ emit("info", resolveState(), args);
778
+ },
779
+ debug(...args) {
780
+ emit("debug", resolveState(), args);
781
+ },
782
+ warn(...args) {
783
+ emit("warn", resolveState(), args);
784
+ },
785
+ error(...args) {
786
+ emit("error", resolveState(), args);
787
+ }
788
+ };
789
+ }
790
+ var debugLogger = {
791
+ ...createDebugLogger(),
792
+ forState(state) {
793
+ return createDebugLogger(state);
794
+ }
795
+ };
796
+ setGlobalHookErrorReporter((error) => {
797
+ debugLogger.error("Global instrumentation hook error:", error);
798
+ });
799
+
690
800
  // src/span-origin.ts
691
801
  var INSTRUMENTATION_NAMES = {
692
802
  AI_SDK: "ai-sdk",
@@ -699,6 +809,7 @@ var INSTRUMENTATION_NAMES = {
699
809
  CLOUDFLARE_THINK: "cloudflare-think",
700
810
  COHERE: "cohere",
701
811
  CURSOR_SDK: "cursor-sdk",
812
+ DEEPSEEK_HARNESS: "deepseek-harness",
702
813
  EVE: "eve",
703
814
  FLUE: "flue",
704
815
  GENKIT: "genkit",
@@ -724,7 +835,7 @@ var INSTRUMENTATION_NAMES = {
724
835
  var INTERNAL_SPAN_INSTRUMENTATION_NAME = /* @__PURE__ */ Symbol.for(
725
836
  "braintrust.spanInstrumentationName"
726
837
  );
727
- var SDK_VERSION = true ? "3.28.0" : "0.0.0";
838
+ var SDK_VERSION = true ? "3.30.0" : "0.0.0";
728
839
  function withSpanInstrumentationName(args, instrumentationName) {
729
840
  return {
730
841
  ...args,
@@ -903,6 +1014,18 @@ function defineChannels(pkg, channels, options) {
903
1014
  var openAIChannels = defineChannels(
904
1015
  "openai",
905
1016
  {
1017
+ filesCreateTraced: channel({
1018
+ channelName: "files.create-traced",
1019
+ kind: "async"
1020
+ }),
1021
+ batchesRetrieveTraced: channel({
1022
+ channelName: "batches.retrieve-traced",
1023
+ kind: "async"
1024
+ }),
1025
+ batchesCompleteTrace: channel({
1026
+ channelName: "batches.complete-trace",
1027
+ kind: "async"
1028
+ }),
906
1029
  chatCompletionsCreate: channel({
907
1030
  channelName: "chat.completions.create",
908
1031
  kind: "async"
@@ -995,6 +1118,10 @@ var aiSDKChannels = defineChannels(
995
1118
  channelName: "generateText",
996
1119
  kind: "async"
997
1120
  }),
1121
+ generateImage: channel({
1122
+ channelName: "generateImage",
1123
+ kind: "async"
1124
+ }),
998
1125
  streamText: channel({
999
1126
  channelName: "streamText",
1000
1127
  kind: "async"
@@ -1908,6 +2035,22 @@ function patchMastraSource(source, target, format) {
1908
2035
  return source + OBSERVABILITY_APPEND_BODY;
1909
2036
  }
1910
2037
 
2038
+ // src/instrumentation/plugins/cloudflare-ai-chat-channels.ts
2039
+ var cloudflareAIChatChannels = defineChannels(
2040
+ "@cloudflare/ai-chat",
2041
+ {
2042
+ runExclusiveChatTurn: channel({
2043
+ channelName: "AIChatAgent._runExclusiveChatTurn",
2044
+ kind: "async"
2045
+ }),
2046
+ onChatResponse: channel({
2047
+ channelName: "AIChatAgent.onChatResponse",
2048
+ kind: "sync-stream"
2049
+ })
2050
+ },
2051
+ { instrumentationName: INSTRUMENTATION_NAMES.CLOUDFLARE_AI_CHAT }
2052
+ );
2053
+
1911
2054
  // src/instrumentation/plugins/openai-agents-channels.ts
1912
2055
  var openAIAgentsCoreChannels = defineChannels(
1913
2056
  "@openai/agents-core",
@@ -1948,30 +2091,19 @@ var langChainChannels = defineChannels(
1948
2091
  { instrumentationName: INSTRUMENTATION_NAMES.LANGCHAIN }
1949
2092
  );
1950
2093
 
1951
- // src/instrumentation/plugins/cloudflare-ai-chat-channels.ts
1952
- var cloudflareAIChatChannels = defineChannels(
1953
- "@cloudflare/ai-chat",
1954
- {
1955
- runExclusiveChatTurn: channel({
1956
- channelName: "AIChatAgent._runExclusiveChatTurn",
1957
- kind: "async"
1958
- }),
1959
- onChatResponse: channel({
1960
- channelName: "AIChatAgent.onChatResponse",
1961
- kind: "sync-stream"
1962
- })
1963
- },
1964
- { instrumentationName: INSTRUMENTATION_NAMES.CLOUDFLARE_AI_CHAT }
1965
- );
1966
-
1967
2094
  export {
1968
2095
  __export,
1969
2096
  GLOBAL_INSTRUMENTATION_HOOKS_KEY,
1970
2097
  GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION,
1971
2098
  GLOBAL_INSTRUMENTATION_HOOKS_REGISTRY_BRAND,
1972
2099
  GLOBAL_INSTRUMENTATION_HOOK_BRAND,
1973
- setGlobalHookErrorReporter,
1974
2100
  isomorph_default,
2101
+ normalizeDebugLogLevelOption,
2102
+ getEnvDebugLogLevel,
2103
+ setGlobalDebugLogLevel,
2104
+ resetDebugLoggerForTests,
2105
+ setDebugLogStateResolver,
2106
+ debugLogger,
1975
2107
  INSTRUMENTATION_NAMES,
1976
2108
  withSpanInstrumentationName,
1977
2109
  getSpanInstrumentationName,