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,300 @@
1
+ import {
2
+ aiSDKConfigs,
3
+ anthropicConfigs,
4
+ channel,
5
+ claudeAgentSDKConfigs,
6
+ cohereConfigs,
7
+ cursorSDKConfigs,
8
+ defineChannels,
9
+ genkitConfigs,
10
+ gitHubCopilotConfigs,
11
+ googleADKConfigs,
12
+ googleGenAIConfigs,
13
+ groqConfigs,
14
+ huggingFaceConfigs,
15
+ langchainConfigs,
16
+ mistralConfigs,
17
+ openAIAgentsCoreConfigs,
18
+ openAICodexConfigs,
19
+ openRouterAgentConfigs,
20
+ openRouterConfigs,
21
+ openaiConfigs
22
+ } from "./chunk-2DPA74KK.mjs";
23
+
24
+ // src/auto-instrumentations/bundler/plugin.ts
25
+ import { createUnplugin } from "unplugin";
26
+ import {
27
+ create
28
+ } from "@apm-js-collab/code-transformer";
29
+ import { extname, join, sep } from "path";
30
+ import { readFileSync } from "fs";
31
+ import { fileURLToPath } from "url";
32
+ import moduleDetailsFromPath from "module-details-from-path";
33
+
34
+ // src/instrumentation/config.ts
35
+ var envIntegrationAliases = {
36
+ openai: "openai",
37
+ "openai-codex": "openaiCodexSDK",
38
+ "openai-codex-sdk": "openaiCodexSDK",
39
+ openaicodexsdk: "openaiCodexSDK",
40
+ codex: "openaiCodexSDK",
41
+ "codex-sdk": "openaiCodexSDK",
42
+ anthropic: "anthropic",
43
+ aisdk: "aisdk",
44
+ "ai-sdk": "aisdk",
45
+ "vercel-ai": "aisdk",
46
+ vercel: "vercel",
47
+ claudeagentsdk: "claudeAgentSDK",
48
+ "claude-agent-sdk": "claudeAgentSDK",
49
+ cursor: "cursor",
50
+ "cursor-sdk": "cursorSDK",
51
+ cursorsdk: "cursorSDK",
52
+ flue: "flue",
53
+ "flue-runtime": "flue",
54
+ "openai-agents": "openAIAgents",
55
+ openaiagents: "openAIAgents",
56
+ "openai-agents-core": "openAIAgents",
57
+ openaiagentscore: "openAIAgents",
58
+ google: "google",
59
+ "google-genai": "googleGenAI",
60
+ googlegenai: "googleGenAI",
61
+ huggingface: "huggingface",
62
+ openrouter: "openrouter",
63
+ openrouteragent: "openrouterAgent",
64
+ "openrouter-agent": "openrouterAgent",
65
+ mistral: "mistral",
66
+ googleadk: "googleADK",
67
+ "google-adk": "googleADK",
68
+ cohere: "cohere",
69
+ groq: "groq",
70
+ "groq-sdk": "groq",
71
+ genkit: "genkit",
72
+ "firebase-genkit": "genkit",
73
+ githubcopilot: "gitHubCopilot",
74
+ "github-copilot": "gitHubCopilot",
75
+ "copilot-sdk": "gitHubCopilot",
76
+ langchain: "langchain",
77
+ "langchain-js": "langchain",
78
+ "@langchain": "langchain",
79
+ langgraph: "langgraph"
80
+ };
81
+ function readDisabledInstrumentationEnvConfig(disabledList) {
82
+ const integrations = {};
83
+ if (disabledList) {
84
+ for (const value of disabledList.split(",")) {
85
+ const sdk = value.trim().toLowerCase();
86
+ if (sdk.length > 0) {
87
+ integrations[envIntegrationAliases[sdk] ?? sdk] = false;
88
+ }
89
+ }
90
+ }
91
+ return { integrations };
92
+ }
93
+ function isInstrumentationIntegrationDisabled(integrations, ...names) {
94
+ return names.some((name) => integrations?.[name] === false);
95
+ }
96
+
97
+ // src/instrumentation/plugins/flue-channels.ts
98
+ var flueChannels = defineChannels("@flue/runtime", {
99
+ createContext: channel({
100
+ channelName: "createFlueContext",
101
+ kind: "sync-stream"
102
+ }),
103
+ openSession: channel({
104
+ channelName: "Harness.openSession",
105
+ kind: "async"
106
+ }),
107
+ contextEvent: channel({
108
+ channelName: "context.event",
109
+ kind: "sync-stream"
110
+ }),
111
+ prompt: channel({
112
+ channelName: "session.prompt",
113
+ kind: "async"
114
+ }),
115
+ skill: channel({
116
+ channelName: "session.skill",
117
+ kind: "async"
118
+ }),
119
+ task: channel({
120
+ channelName: "session.task",
121
+ kind: "async"
122
+ }),
123
+ compact: channel({
124
+ channelName: "session.compact",
125
+ kind: "async"
126
+ })
127
+ });
128
+
129
+ // src/auto-instrumentations/configs/flue.ts
130
+ var flueVersionRange = ">=0.7.0 <0.8.0";
131
+ var flueConfigs = [
132
+ {
133
+ channelName: flueChannels.createContext.channelName,
134
+ module: {
135
+ name: "@flue/runtime",
136
+ versionRange: flueVersionRange,
137
+ filePath: "dist/internal.mjs"
138
+ },
139
+ functionQuery: {
140
+ functionName: "createFlueContext",
141
+ kind: "Sync"
142
+ }
143
+ },
144
+ {
145
+ channelName: flueChannels.openSession.channelName,
146
+ module: {
147
+ name: "@flue/runtime",
148
+ versionRange: flueVersionRange,
149
+ filePath: "dist/internal.mjs"
150
+ },
151
+ functionQuery: {
152
+ className: "Harness",
153
+ methodName: "openSession",
154
+ kind: "Async"
155
+ }
156
+ }
157
+ ];
158
+
159
+ // src/auto-instrumentations/configs/all.ts
160
+ var defaultInstrumentationConfigGroups = [
161
+ { integrations: ["openai"], configs: openaiConfigs },
162
+ {
163
+ integrations: ["openaiCodexSDK"],
164
+ configs: openAICodexConfigs
165
+ },
166
+ { integrations: ["anthropic"], configs: anthropicConfigs },
167
+ {
168
+ integrations: ["aisdk", "vercel"],
169
+ configs: aiSDKConfigs
170
+ },
171
+ {
172
+ integrations: ["claudeAgentSDK"],
173
+ configs: claudeAgentSDKConfigs
174
+ },
175
+ { integrations: ["cursor", "cursorSDK"], configs: cursorSDKConfigs },
176
+ { integrations: ["flue"], configs: flueConfigs },
177
+ {
178
+ integrations: ["openAIAgents"],
179
+ configs: openAIAgentsCoreConfigs
180
+ },
181
+ {
182
+ integrations: ["google", "googleGenAI"],
183
+ configs: googleGenAIConfigs
184
+ },
185
+ { integrations: ["huggingface"], configs: huggingFaceConfigs },
186
+ {
187
+ integrations: ["langchain", "langgraph"],
188
+ configs: langchainConfigs
189
+ },
190
+ { integrations: ["openrouter"], configs: openRouterConfigs },
191
+ {
192
+ integrations: ["openrouterAgent"],
193
+ configs: openRouterAgentConfigs
194
+ },
195
+ { integrations: ["mistral"], configs: mistralConfigs },
196
+ { integrations: ["googleADK"], configs: googleADKConfigs },
197
+ { integrations: ["cohere"], configs: cohereConfigs },
198
+ { integrations: ["groq"], configs: groqConfigs },
199
+ {
200
+ integrations: ["genkit"],
201
+ configs: genkitConfigs
202
+ },
203
+ {
204
+ integrations: ["gitHubCopilot"],
205
+ configs: gitHubCopilotConfigs
206
+ }
207
+ ];
208
+ function getDefaultInstrumentationConfigs({
209
+ additionalInstrumentations,
210
+ disabledIntegrationConfig,
211
+ disabledIntegrations
212
+ } = {}) {
213
+ const disabledConfig = disabledIntegrationConfig ?? (disabledIntegrations ? readDisabledInstrumentationEnvConfig(
214
+ [...disabledIntegrations].join(",")
215
+ ).integrations : void 0);
216
+ return [
217
+ ...defaultInstrumentationConfigGroups.flatMap(
218
+ ({ configs, integrations }) => isInstrumentationIntegrationDisabled(disabledConfig, ...integrations) ? [] : configs
219
+ ),
220
+ ...additionalInstrumentations ?? []
221
+ ];
222
+ }
223
+
224
+ // src/auto-instrumentations/bundler/plugin.ts
225
+ function getModuleVersion(basedir) {
226
+ try {
227
+ const packageJsonPath = join(basedir, "package.json");
228
+ const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8"));
229
+ if (packageJson.version) {
230
+ return packageJson.version;
231
+ }
232
+ } catch (error) {
233
+ }
234
+ return void 0;
235
+ }
236
+ var unplugin = createUnplugin(
237
+ (options = {}) => {
238
+ const allInstrumentations = getDefaultInstrumentationConfigs({
239
+ additionalInstrumentations: options.instrumentations
240
+ });
241
+ const dcModule = options.browser === false ? void 0 : "dc-browser";
242
+ const instrumentationMatcher = create(allInstrumentations, dcModule);
243
+ return {
244
+ name: "code-transformer",
245
+ enforce: "pre",
246
+ transform(code, id) {
247
+ if (!id) {
248
+ return null;
249
+ }
250
+ const filePath = id.startsWith("file:") ? fileURLToPath(id) : id;
251
+ const ext = extname(filePath);
252
+ let isModule = ext === ".mjs" || ext === ".ts" || ext === ".tsx";
253
+ if (ext === ".js") {
254
+ isModule = code.includes("export ") || code.includes("import ");
255
+ }
256
+ const normalizedForPlatform = filePath.split("/").join(sep);
257
+ const moduleDetails = moduleDetailsFromPath(normalizedForPlatform);
258
+ if (!moduleDetails) {
259
+ return null;
260
+ }
261
+ const moduleName = moduleDetails.name;
262
+ const moduleVersion = getModuleVersion(moduleDetails.basedir);
263
+ if (!moduleVersion) {
264
+ console.warn(
265
+ `No 'package.json' version found for module ${moduleName} at ${moduleDetails.basedir}. Skipping transformation.`
266
+ );
267
+ return null;
268
+ }
269
+ const normalizedModulePath = moduleDetails.path.replace(/\\/g, "/");
270
+ const transformer = instrumentationMatcher.getTransformer(
271
+ moduleName,
272
+ moduleVersion,
273
+ normalizedModulePath
274
+ );
275
+ if (!transformer) {
276
+ return null;
277
+ }
278
+ try {
279
+ const moduleType = isModule ? "esm" : "cjs";
280
+ const result = transformer.transform(code, moduleType);
281
+ const transformedCode = result.code.replace(
282
+ /const \{tracingChannel: ([A-Za-z_$][\w$]*)\} = ([A-Za-z_$][\w$]*);/g,
283
+ "const $1 = $2.tracingChannel;"
284
+ );
285
+ return {
286
+ code: transformedCode,
287
+ map: result.map
288
+ };
289
+ } catch (error) {
290
+ console.warn(`Code transformation failed for ${id}: ${error}`);
291
+ return null;
292
+ }
293
+ }
294
+ };
295
+ }
296
+ );
297
+
298
+ export {
299
+ unplugin
300
+ };
@@ -0,0 +1,18 @@
1
+ import {
2
+ unplugin
3
+ } from "./chunk-73BZUKVI.mjs";
4
+
5
+ // src/auto-instrumentations/bundler/webpack.ts
6
+ function braintrustWebpackPlugin(options = {}) {
7
+ const { useDiagnosticChannelCompatShim = false, ...pluginOptions } = options;
8
+ return unplugin.webpack({
9
+ ...pluginOptions,
10
+ browser: useDiagnosticChannelCompatShim
11
+ });
12
+ }
13
+ var webpackPlugin = unplugin.webpack;
14
+
15
+ export {
16
+ braintrustWebpackPlugin,
17
+ webpackPlugin
18
+ };
@@ -53,7 +53,29 @@ function getPackageName(baseDir) {
53
53
  return void 0;
54
54
  }
55
55
 
56
+ // src/auto-instrumentations/loader/openai-api-promise-patch.ts
57
+ var OPENAI_API_PROMISE_PATCH = `
58
+ ;(function __btPatchAPIPromise() {
59
+ if (typeof APIPromise === "undefined" || APIPromise.prototype.__btParsePatched) return;
60
+ APIPromise.prototype.__btParsePatched = true;
61
+ var _origThen = APIPromise.prototype.then;
62
+ APIPromise.prototype.then = function __btThen(onfulfilled, onrejected) {
63
+ if (!this.__btParseWrapped && Object.prototype.hasOwnProperty.call(this, "parseResponse")) {
64
+ this.__btParseWrapped = true;
65
+ var _origParse = this.parseResponse;
66
+ var _cached;
67
+ this.parseResponse = function() {
68
+ if (!_cached) _cached = _origParse.apply(this, arguments);
69
+ return _cached;
70
+ };
71
+ }
72
+ return _origThen.call(this, onfulfilled, onrejected);
73
+ };
74
+ })();
75
+ `;
76
+
56
77
  export {
57
78
  getPackageVersion,
58
- getPackageName
79
+ getPackageName,
80
+ OPENAI_API_PROMISE_PATCH
59
81
  };