braintrust 3.11.0 → 3.13.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 (77) hide show
  1. package/README.md +8 -8
  2. package/dev/dist/index.d.mts +26 -7
  3. package/dev/dist/index.d.ts +26 -7
  4. package/dev/dist/index.js +2717 -335
  5. package/dev/dist/index.mjs +2499 -117
  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 +1803 -1283
  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 +3269 -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 +1803 -1283
  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 +1803 -1283
  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 +1861 -1308
  31. package/dist/auto-instrumentations/bundler/webpack-loader.d.ts +3 -3
  32. package/dist/auto-instrumentations/bundler/webpack.cjs +1803 -1283
  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-DIV5TO4S.mjs → chunk-E5DUYJWK.mjs} +338 -1
  37. package/dist/auto-instrumentations/chunk-GJOO4ESL.mjs +300 -0
  38. package/dist/auto-instrumentations/chunk-WFEUJACP.mjs +18 -0
  39. package/dist/auto-instrumentations/hook.mjs +1713 -1460
  40. package/dist/auto-instrumentations/index.cjs +94 -0
  41. package/dist/auto-instrumentations/index.d.mts +5 -1
  42. package/dist/auto-instrumentations/index.d.ts +5 -1
  43. package/dist/auto-instrumentations/index.mjs +6 -247
  44. package/dist/auto-instrumentations/loader/esm-hook.mjs +19 -2
  45. package/dist/auto-instrumentations/plugin-D7nDswtC.d.mts +44 -0
  46. package/dist/auto-instrumentations/plugin-D7nDswtC.d.ts +44 -0
  47. package/dist/browser.d.mts +264 -47
  48. package/dist/browser.d.ts +264 -47
  49. package/dist/browser.js +2521 -159
  50. package/dist/browser.mjs +2521 -159
  51. package/dist/chunk-26JGOELH.js +817 -0
  52. package/dist/chunk-75IQCUB2.mjs +817 -0
  53. package/dist/cli.js +2510 -122
  54. package/dist/edge-light.d.mts +1 -1
  55. package/dist/edge-light.d.ts +1 -1
  56. package/dist/edge-light.js +2521 -159
  57. package/dist/edge-light.mjs +2521 -159
  58. package/dist/index.d.mts +264 -47
  59. package/dist/index.d.ts +264 -47
  60. package/dist/index.js +3498 -1850
  61. package/dist/index.mjs +2635 -987
  62. package/dist/instrumentation/index.d.mts +7897 -48
  63. package/dist/instrumentation/index.d.ts +7897 -48
  64. package/dist/instrumentation/index.js +2408 -95
  65. package/dist/instrumentation/index.mjs +2407 -95
  66. package/dist/workerd.d.mts +1 -1
  67. package/dist/workerd.d.ts +1 -1
  68. package/dist/workerd.js +2521 -159
  69. package/dist/workerd.mjs +2521 -159
  70. package/package.json +23 -17
  71. package/util/dist/index.d.mts +3 -1
  72. package/util/dist/index.d.ts +3 -1
  73. package/util/dist/index.js +6 -0
  74. package/util/dist/index.mjs +6 -0
  75. package/dist/auto-instrumentations/chunk-G6ZWXGZB.mjs +0 -116
  76. package/dist/auto-instrumentations/plugin-Df3qKIl2.d.mts +0 -22
  77. 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-E5DUYJWK.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-GJOO4ESL.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
+ };