braintrust 3.10.0 → 3.12.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 (78) hide show
  1. package/README.md +8 -8
  2. package/dev/dist/index.d.mts +51 -3
  3. package/dev/dist/index.d.ts +51 -3
  4. package/dev/dist/index.js +13138 -8915
  5. package/dev/dist/index.mjs +13015 -8792
  6. package/dist/apply-auto-instrumentation.browser.d.mts +2 -0
  7. package/dist/apply-auto-instrumentation.browser.d.ts +2 -0
  8. package/dist/apply-auto-instrumentation.browser.js +18 -0
  9. package/dist/apply-auto-instrumentation.browser.mjs +0 -0
  10. package/dist/apply-auto-instrumentation.d.mts +2 -0
  11. package/dist/apply-auto-instrumentation.d.ts +2 -0
  12. package/dist/apply-auto-instrumentation.js +2534 -0
  13. package/dist/apply-auto-instrumentation.mjs +2534 -0
  14. package/dist/auto-instrumentations/bundler/esbuild.cjs +1775 -737
  15. package/dist/auto-instrumentations/bundler/esbuild.d.mts +9 -5
  16. package/dist/auto-instrumentations/bundler/esbuild.d.ts +9 -5
  17. package/dist/auto-instrumentations/bundler/esbuild.mjs +10 -2
  18. package/dist/auto-instrumentations/bundler/next.cjs +3268 -0
  19. package/dist/auto-instrumentations/bundler/next.d.mts +3 -0
  20. package/dist/auto-instrumentations/bundler/next.d.ts +3 -0
  21. package/dist/auto-instrumentations/bundler/next.mjs +189 -0
  22. package/dist/auto-instrumentations/bundler/rollup.cjs +1775 -737
  23. package/dist/auto-instrumentations/bundler/rollup.d.mts +9 -5
  24. package/dist/auto-instrumentations/bundler/rollup.d.ts +9 -5
  25. package/dist/auto-instrumentations/bundler/rollup.mjs +10 -2
  26. package/dist/auto-instrumentations/bundler/vite.cjs +1775 -737
  27. package/dist/auto-instrumentations/bundler/vite.d.mts +9 -5
  28. package/dist/auto-instrumentations/bundler/vite.d.ts +9 -5
  29. package/dist/auto-instrumentations/bundler/vite.mjs +10 -2
  30. package/dist/auto-instrumentations/bundler/webpack-loader.cjs +1713 -690
  31. package/dist/auto-instrumentations/bundler/webpack-loader.d.ts +3 -3
  32. package/dist/auto-instrumentations/bundler/webpack.cjs +1775 -737
  33. package/dist/auto-instrumentations/bundler/webpack.d.mts +9 -5
  34. package/dist/auto-instrumentations/bundler/webpack.d.ts +9 -5
  35. package/dist/auto-instrumentations/bundler/webpack.mjs +6 -6
  36. package/dist/auto-instrumentations/{chunk-GZNXBBPU.mjs → chunk-2DPA74KK.mjs} +856 -5
  37. package/dist/auto-instrumentations/chunk-73BZUKVI.mjs +300 -0
  38. package/dist/auto-instrumentations/chunk-AFXRW7I7.mjs +18 -0
  39. package/dist/auto-instrumentations/{chunk-ITP7RAUY.mjs → chunk-MWZXZQUO.mjs} +23 -1
  40. package/dist/auto-instrumentations/hook.mjs +1912 -1125
  41. package/dist/auto-instrumentations/index.cjs +615 -4
  42. package/dist/auto-instrumentations/index.d.mts +18 -1
  43. package/dist/auto-instrumentations/index.d.ts +18 -1
  44. package/dist/auto-instrumentations/index.mjs +12 -247
  45. package/dist/auto-instrumentations/loader/cjs-patch.cjs +26 -1
  46. package/dist/auto-instrumentations/loader/cjs-patch.mjs +28 -1
  47. package/dist/auto-instrumentations/loader/esm-hook.mjs +35 -3
  48. package/dist/auto-instrumentations/plugin-D7nDswtC.d.mts +44 -0
  49. package/dist/auto-instrumentations/plugin-D7nDswtC.d.ts +44 -0
  50. package/dist/browser.d.mts +577 -287
  51. package/dist/browser.d.ts +577 -287
  52. package/dist/browser.js +10221 -5524
  53. package/dist/browser.mjs +10221 -5524
  54. package/dist/chunk-BW4DF4CY.js +816 -0
  55. package/dist/chunk-MSLBGITU.mjs +816 -0
  56. package/dist/cli.js +13143 -8892
  57. package/dist/edge-light.d.mts +1 -1
  58. package/dist/edge-light.d.ts +1 -1
  59. package/dist/edge-light.js +10221 -5524
  60. package/dist/edge-light.mjs +10221 -5524
  61. package/dist/index.d.mts +590 -300
  62. package/dist/index.d.ts +590 -300
  63. package/dist/index.js +9309 -5371
  64. package/dist/index.mjs +10340 -6402
  65. package/dist/instrumentation/index.d.mts +7863 -39
  66. package/dist/instrumentation/index.d.ts +7863 -39
  67. package/dist/instrumentation/index.js +10263 -6034
  68. package/dist/instrumentation/index.mjs +10262 -6034
  69. package/dist/workerd.d.mts +1 -1
  70. package/dist/workerd.d.ts +1 -1
  71. package/dist/workerd.js +10221 -5524
  72. package/dist/workerd.mjs +10221 -5524
  73. package/package.json +33 -19
  74. package/util/dist/index.js +6 -0
  75. package/util/dist/index.mjs +6 -0
  76. package/dist/auto-instrumentations/chunk-XWEQQOQH.mjs +0 -106
  77. package/dist/auto-instrumentations/plugin-Df3qKIl2.d.mts +0 -22
  78. package/dist/auto-instrumentations/plugin-Df3qKIl2.d.ts +0 -22
@@ -0,0 +1,3 @@
1
+ declare function wrapNextjsConfigWithBraintrust<C>(nextConfig: C): C;
2
+
3
+ export { wrapNextjsConfigWithBraintrust };
@@ -0,0 +1,3 @@
1
+ declare function wrapNextjsConfigWithBraintrust<C>(nextConfig: C): C;
2
+
3
+ export { wrapNextjsConfigWithBraintrust };
@@ -0,0 +1,189 @@
1
+ import {
2
+ webpackPlugin
3
+ } from "../chunk-AFXRW7I7.mjs";
4
+ import "../chunk-73BZUKVI.mjs";
5
+ import "../chunk-2DPA74KK.mjs";
6
+
7
+ // src/auto-instrumentations/bundler/next.ts
8
+ import { createRequire } from "module";
9
+ import { isAbsolute, join, relative } from "path";
10
+ var requireFromProject = createRequire(join(process.cwd(), "package.json"));
11
+ var TURBOPACK_RULE_MATCHER = "*.{js,mjs,cjs}";
12
+ function wrapNextjsConfigWithBraintrust(nextConfig) {
13
+ const castNextConfig = nextConfig ?? {};
14
+ if (typeof castNextConfig === "function") {
15
+ return function(...args) {
16
+ const maybeConfig = castNextConfig.apply(this, args);
17
+ if (isThenable(maybeConfig)) {
18
+ return maybeConfig.then(
19
+ (resolvedConfig) => createConfigObject(resolvedConfig)
20
+ );
21
+ }
22
+ return createConfigObject(maybeConfig);
23
+ };
24
+ }
25
+ return createConfigObject(castNextConfig);
26
+ }
27
+ function createConfigObject(nextConfig) {
28
+ const config = { ...nextConfig ?? {} };
29
+ const activeBundler = detectBundler();
30
+ if (activeBundler === "turbopack") {
31
+ if (config.turbopack || !config.experimental?.turbo) {
32
+ return {
33
+ ...config,
34
+ turbopack: wrapTurbopackConfig(config.turbopack)
35
+ };
36
+ }
37
+ return {
38
+ ...config,
39
+ experimental: {
40
+ ...config.experimental,
41
+ turbo: wrapTurbopackConfig(config.experimental.turbo)
42
+ }
43
+ };
44
+ }
45
+ return {
46
+ ...config,
47
+ webpack: wrapWebpackConfig(config.webpack)
48
+ };
49
+ }
50
+ function detectBundler() {
51
+ if (process.argv.includes("--webpack")) {
52
+ return "webpack";
53
+ }
54
+ const turbopackEnv = process.env.TURBOPACK?.trim().toLowerCase();
55
+ if (turbopackEnv && turbopackEnv !== "0" && turbopackEnv !== "false" || process.argv.includes("--turbo") || process.argv.includes("--turbopack")) {
56
+ return "turbopack";
57
+ }
58
+ const nextMajorVersion = getNextMajorVersion();
59
+ if (nextMajorVersion !== void 0 && nextMajorVersion >= 16) {
60
+ return "turbopack";
61
+ }
62
+ return "webpack";
63
+ }
64
+ function wrapWebpackConfig(userWebpack) {
65
+ return (incomingConfig, buildContext) => {
66
+ const rawConfig = typeof userWebpack === "function" ? userWebpack(incomingConfig, buildContext) : incomingConfig;
67
+ const config = rawConfig ?? incomingConfig;
68
+ const existingPlugins = Array.isArray(config.plugins) ? config.plugins : [];
69
+ const runtime = buildContext.isServer ? buildContext.nextRuntime === "edge" || buildContext.nextRuntime === "experimental-edge" ? "edge" : "server" : "client";
70
+ const plugin = webpackPlugin({
71
+ browser: runtime === "client" || runtime === "edge"
72
+ });
73
+ return {
74
+ ...config,
75
+ plugins: [...existingPlugins, plugin]
76
+ };
77
+ };
78
+ }
79
+ function wrapTurbopackConfig(turbopackConfig) {
80
+ const config = { ...turbopackConfig ?? {} };
81
+ const resolveAlias = config.resolveAlias && typeof config.resolveAlias === "object" && !Array.isArray(config.resolveAlias) ? config.resolveAlias : {};
82
+ const rules = config.rules && typeof config.rules === "object" && !Array.isArray(config.rules) ? config.rules : {};
83
+ let dcBrowserPath;
84
+ try {
85
+ dcBrowserPath = createRequire(
86
+ requireFromProject.resolve("braintrust/package.json")
87
+ ).resolve("dc-browser");
88
+ } catch {
89
+ try {
90
+ dcBrowserPath = requireFromProject.resolve("dc-browser");
91
+ } catch {
92
+ dcBrowserPath = void 0;
93
+ }
94
+ }
95
+ if (dcBrowserPath && isAbsolute(dcBrowserPath)) {
96
+ const relativeDcBrowserPath = relative(
97
+ process.cwd(),
98
+ dcBrowserPath
99
+ ).replace(/\\/g, "/");
100
+ dcBrowserPath = relativeDcBrowserPath.startsWith(".") ? relativeDcBrowserPath : `./${relativeDcBrowserPath}`;
101
+ }
102
+ return {
103
+ ...config,
104
+ // Turbopack resolves modules emitted by our loader from the app graph. The
105
+ // browser diagnostics-channel shim is Braintrust's dependency, so alias it
106
+ // to the copy installed with Braintrust while still letting user aliases win.
107
+ resolveAlias: dcBrowserPath && resolveAlias["dc-browser"] === void 0 ? { ...resolveAlias, "dc-browser": dcBrowserPath } : config.resolveAlias,
108
+ rules: addBraintrustTurbopackRule(rules)
109
+ };
110
+ }
111
+ function addBraintrustTurbopackRule(rules) {
112
+ const loaderPath = getWebpackLoaderPath();
113
+ const braintrustRules = [
114
+ {
115
+ condition: { all: ["foreign", "browser"] },
116
+ loaders: [
117
+ {
118
+ loader: loaderPath,
119
+ options: { browser: true }
120
+ }
121
+ ]
122
+ },
123
+ {
124
+ condition: { all: ["foreign", "edge-light"] },
125
+ loaders: [
126
+ {
127
+ loader: loaderPath,
128
+ options: { browser: true }
129
+ }
130
+ ]
131
+ },
132
+ {
133
+ condition: { all: ["foreign", "node"] },
134
+ loaders: [
135
+ {
136
+ loader: loaderPath,
137
+ options: { browser: false }
138
+ }
139
+ ]
140
+ }
141
+ ];
142
+ const existingRule = rules[TURBOPACK_RULE_MATCHER];
143
+ if (!existingRule) {
144
+ return {
145
+ ...rules,
146
+ // Turbopack exposes the active runtime through rule conditions, so keep
147
+ // client, edge, and node transforms separate instead of inferring later.
148
+ [TURBOPACK_RULE_MATCHER]: braintrustRules
149
+ };
150
+ }
151
+ if (Array.isArray(existingRule)) {
152
+ return {
153
+ ...rules,
154
+ [TURBOPACK_RULE_MATCHER]: [...existingRule, ...braintrustRules]
155
+ };
156
+ }
157
+ if (typeof existingRule === "object" && existingRule !== null) {
158
+ return {
159
+ ...rules,
160
+ [TURBOPACK_RULE_MATCHER]: [existingRule, ...braintrustRules]
161
+ };
162
+ }
163
+ return rules;
164
+ }
165
+ function getWebpackLoaderPath() {
166
+ try {
167
+ return requireFromProject.resolve("braintrust/webpack-loader");
168
+ } catch {
169
+ return "braintrust/webpack-loader";
170
+ }
171
+ }
172
+ function getNextMajorVersion() {
173
+ try {
174
+ const nextPackageJson = requireFromProject("next/package.json");
175
+ if (typeof nextPackageJson.version !== "string") {
176
+ return void 0;
177
+ }
178
+ const major = Number.parseInt(nextPackageJson.version.split(".")[0] ?? "");
179
+ return Number.isFinite(major) ? major : void 0;
180
+ } catch {
181
+ return void 0;
182
+ }
183
+ }
184
+ function isThenable(value) {
185
+ return value !== null && value !== void 0 && (typeof value === "object" || typeof value === "function") && "then" in value && typeof value.then === "function";
186
+ }
187
+ export {
188
+ wrapNextjsConfigWithBraintrust
189
+ };