braintrust 3.1.0 → 3.2.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 (63) hide show
  1. package/README.md +73 -0
  2. package/dev/dist/index.d.mts +187 -903
  3. package/dev/dist/index.d.ts +187 -903
  4. package/dev/dist/index.js +2942 -323
  5. package/dev/dist/index.mjs +2704 -85
  6. package/dist/auto-instrumentations/bundler/esbuild.cjs +401 -0
  7. package/dist/auto-instrumentations/bundler/esbuild.d.mts +8 -0
  8. package/dist/auto-instrumentations/bundler/esbuild.d.ts +8 -0
  9. package/dist/auto-instrumentations/bundler/esbuild.mjs +10 -0
  10. package/dist/auto-instrumentations/bundler/rollup.cjs +401 -0
  11. package/dist/auto-instrumentations/bundler/rollup.d.mts +8 -0
  12. package/dist/auto-instrumentations/bundler/rollup.d.ts +8 -0
  13. package/dist/auto-instrumentations/bundler/rollup.mjs +10 -0
  14. package/dist/auto-instrumentations/bundler/vite.cjs +401 -0
  15. package/dist/auto-instrumentations/bundler/vite.d.mts +8 -0
  16. package/dist/auto-instrumentations/bundler/vite.d.ts +8 -0
  17. package/dist/auto-instrumentations/bundler/vite.mjs +10 -0
  18. package/dist/auto-instrumentations/bundler/webpack.cjs +401 -0
  19. package/dist/auto-instrumentations/bundler/webpack.d.mts +8 -0
  20. package/dist/auto-instrumentations/bundler/webpack.d.ts +8 -0
  21. package/dist/auto-instrumentations/bundler/webpack.mjs +10 -0
  22. package/dist/auto-instrumentations/chunk-KVX7OFPD.mjs +288 -0
  23. package/dist/auto-instrumentations/chunk-OLOPGWTJ.mjs +89 -0
  24. package/dist/auto-instrumentations/chunk-XDBPUTVE.mjs +22 -0
  25. package/dist/auto-instrumentations/chunk-ZEC7BCL4.mjs +22 -0
  26. package/dist/auto-instrumentations/hook.mjs +378 -0
  27. package/dist/auto-instrumentations/index.cjs +318 -0
  28. package/dist/auto-instrumentations/index.d.mts +69 -0
  29. package/dist/auto-instrumentations/index.d.ts +69 -0
  30. package/dist/auto-instrumentations/index.mjs +14 -0
  31. package/dist/auto-instrumentations/loader/cjs-patch.cjs +116 -0
  32. package/dist/auto-instrumentations/loader/cjs-patch.d.mts +28 -0
  33. package/dist/auto-instrumentations/loader/cjs-patch.d.ts +28 -0
  34. package/dist/auto-instrumentations/loader/cjs-patch.mjs +66 -0
  35. package/dist/auto-instrumentations/loader/esm-hook.mjs +72 -0
  36. package/dist/auto-instrumentations/loader/get-package-version.cjs +46 -0
  37. package/dist/auto-instrumentations/loader/get-package-version.d.mts +7 -0
  38. package/dist/auto-instrumentations/loader/get-package-version.d.ts +7 -0
  39. package/dist/auto-instrumentations/loader/get-package-version.mjs +6 -0
  40. package/dist/auto-instrumentations/plugin-Df3qKIl2.d.mts +22 -0
  41. package/dist/auto-instrumentations/plugin-Df3qKIl2.d.ts +22 -0
  42. package/dist/browser.d.mts +484 -980
  43. package/dist/browser.d.ts +484 -980
  44. package/dist/browser.js +3437 -386
  45. package/dist/browser.mjs +3437 -386
  46. package/dist/cli.js +2890 -228
  47. package/dist/edge-light.d.mts +1 -1
  48. package/dist/edge-light.d.ts +1 -1
  49. package/dist/edge-light.js +3134 -86
  50. package/dist/edge-light.mjs +3134 -86
  51. package/dist/index.d.mts +484 -980
  52. package/dist/index.d.ts +484 -980
  53. package/dist/index.js +3754 -703
  54. package/dist/index.mjs +3615 -564
  55. package/dist/instrumentation/index.d.mts +323 -0
  56. package/dist/instrumentation/index.d.ts +323 -0
  57. package/dist/instrumentation/index.js +9942 -0
  58. package/dist/instrumentation/index.mjs +9902 -0
  59. package/dist/workerd.d.mts +1 -1
  60. package/dist/workerd.d.ts +1 -1
  61. package/dist/workerd.js +3134 -86
  62. package/dist/workerd.mjs +3134 -86
  63. package/package.json +46 -7
@@ -0,0 +1,288 @@
1
+ // src/auto-instrumentations/configs/openai.ts
2
+ var openaiConfigs = [
3
+ // Chat Completions
4
+ {
5
+ channelName: "chat.completions.create",
6
+ module: {
7
+ name: "openai",
8
+ versionRange: ">=4.0.0",
9
+ filePath: "resources/chat/completions.mjs"
10
+ },
11
+ functionQuery: {
12
+ className: "Completions",
13
+ methodName: "create",
14
+ kind: "Async"
15
+ }
16
+ },
17
+ // Embeddings
18
+ {
19
+ channelName: "embeddings.create",
20
+ module: {
21
+ name: "openai",
22
+ versionRange: ">=4.0.0",
23
+ filePath: "resources/embeddings.mjs"
24
+ },
25
+ functionQuery: {
26
+ className: "Embeddings",
27
+ methodName: "create",
28
+ kind: "Async"
29
+ }
30
+ },
31
+ // Beta Chat Completions Parse
32
+ {
33
+ channelName: "beta.chat.completions.parse",
34
+ module: {
35
+ name: "openai",
36
+ versionRange: ">=4.0.0",
37
+ filePath: "resources/beta/chat/completions.mjs"
38
+ },
39
+ functionQuery: {
40
+ className: "Completions",
41
+ methodName: "parse",
42
+ kind: "Async"
43
+ }
44
+ },
45
+ // Moderations
46
+ {
47
+ channelName: "moderations.create",
48
+ module: {
49
+ name: "openai",
50
+ versionRange: ">=4.0.0",
51
+ filePath: "resources/moderations.mjs"
52
+ },
53
+ functionQuery: {
54
+ className: "Moderations",
55
+ methodName: "create",
56
+ kind: "Async"
57
+ }
58
+ },
59
+ // Beta Chat Completions Stream
60
+ {
61
+ channelName: "beta.chat.completions.stream",
62
+ module: {
63
+ name: "openai",
64
+ versionRange: ">=4.0.0",
65
+ filePath: "resources/beta/chat/completions.mjs"
66
+ },
67
+ functionQuery: {
68
+ className: "Completions",
69
+ methodName: "stream",
70
+ kind: "Sync"
71
+ }
72
+ },
73
+ // Responses API (v4.87.0+)
74
+ {
75
+ channelName: "responses.create",
76
+ module: {
77
+ name: "openai",
78
+ versionRange: ">=4.87.0",
79
+ filePath: "resources/responses/responses.mjs"
80
+ },
81
+ functionQuery: {
82
+ className: "Responses",
83
+ methodName: "create",
84
+ kind: "Async"
85
+ }
86
+ },
87
+ {
88
+ channelName: "responses.stream",
89
+ module: {
90
+ name: "openai",
91
+ versionRange: ">=4.87.0",
92
+ filePath: "resources/responses/responses.mjs"
93
+ },
94
+ functionQuery: {
95
+ className: "Responses",
96
+ methodName: "stream",
97
+ kind: "Sync"
98
+ }
99
+ },
100
+ {
101
+ channelName: "responses.parse",
102
+ module: {
103
+ name: "openai",
104
+ versionRange: ">=4.87.0",
105
+ filePath: "resources/responses/responses.mjs"
106
+ },
107
+ functionQuery: {
108
+ className: "Responses",
109
+ methodName: "parse",
110
+ kind: "Async"
111
+ }
112
+ }
113
+ ];
114
+
115
+ // src/auto-instrumentations/configs/anthropic.ts
116
+ var anthropicConfigs = [
117
+ // Messages API - create (supports streaming via stream=true parameter)
118
+ {
119
+ channelName: "messages.create",
120
+ module: {
121
+ name: "@anthropic-ai/sdk",
122
+ versionRange: ">=0.60.0",
123
+ filePath: "resources/messages.mjs"
124
+ },
125
+ functionQuery: {
126
+ className: "Messages",
127
+ methodName: "create",
128
+ kind: "Async"
129
+ }
130
+ },
131
+ // Beta Messages API - create (supports streaming via stream=true parameter)
132
+ {
133
+ channelName: "beta.messages.create",
134
+ module: {
135
+ name: "@anthropic-ai/sdk",
136
+ versionRange: ">=0.60.0",
137
+ filePath: "resources/beta/messages/messages.mjs"
138
+ },
139
+ functionQuery: {
140
+ className: "Messages",
141
+ methodName: "create",
142
+ kind: "Async"
143
+ }
144
+ }
145
+ ];
146
+
147
+ // src/auto-instrumentations/configs/ai-sdk.ts
148
+ var aiSDKConfigs = [
149
+ // generateText - async function
150
+ {
151
+ channelName: "generateText",
152
+ module: {
153
+ name: "ai",
154
+ versionRange: ">=3.0.0",
155
+ filePath: "dist/index.mjs"
156
+ },
157
+ functionQuery: {
158
+ functionName: "generateText",
159
+ kind: "Async"
160
+ }
161
+ },
162
+ // streamText - async function
163
+ {
164
+ channelName: "streamText",
165
+ module: {
166
+ name: "ai",
167
+ versionRange: ">=3.0.0",
168
+ filePath: "dist/index.mjs"
169
+ },
170
+ functionQuery: {
171
+ functionName: "streamText",
172
+ kind: "Async"
173
+ }
174
+ },
175
+ // generateObject - async function
176
+ {
177
+ channelName: "generateObject",
178
+ module: {
179
+ name: "ai",
180
+ versionRange: ">=3.0.0",
181
+ filePath: "dist/index.mjs"
182
+ },
183
+ functionQuery: {
184
+ functionName: "generateObject",
185
+ kind: "Async"
186
+ }
187
+ },
188
+ // streamObject - async function
189
+ {
190
+ channelName: "streamObject",
191
+ module: {
192
+ name: "ai",
193
+ versionRange: ">=3.0.0",
194
+ filePath: "dist/index.mjs"
195
+ },
196
+ functionQuery: {
197
+ functionName: "streamObject",
198
+ kind: "Async"
199
+ }
200
+ },
201
+ // Agent.generate - async method (v3-v5 only, Agent structure changed in v6)
202
+ {
203
+ channelName: "Agent.generate",
204
+ module: {
205
+ name: "ai",
206
+ versionRange: ">=3.0.0 <6.0.0",
207
+ filePath: "dist/index.mjs"
208
+ },
209
+ functionQuery: {
210
+ className: "Agent",
211
+ methodName: "generate",
212
+ kind: "Async"
213
+ }
214
+ },
215
+ // Agent.stream - async method (v3-v5 only, Agent structure changed in v6)
216
+ {
217
+ channelName: "Agent.stream",
218
+ module: {
219
+ name: "ai",
220
+ versionRange: ">=3.0.0 <6.0.0",
221
+ filePath: "dist/index.mjs"
222
+ },
223
+ functionQuery: {
224
+ className: "Agent",
225
+ methodName: "stream",
226
+ kind: "Async"
227
+ }
228
+ }
229
+ ];
230
+
231
+ // src/auto-instrumentations/configs/claude-agent-sdk.ts
232
+ var claudeAgentSDKConfigs = [
233
+ // query - Main entry point for agent interactions (top-level exported async generator function)
234
+ {
235
+ channelName: "query",
236
+ module: {
237
+ name: "@anthropic-ai/claude-agent-sdk",
238
+ versionRange: ">=0.1.0",
239
+ filePath: "sdk.mjs"
240
+ },
241
+ functionQuery: {
242
+ functionName: "query",
243
+ kind: "Async"
244
+ }
245
+ }
246
+ ];
247
+
248
+ // src/auto-instrumentations/configs/google-genai.ts
249
+ var googleGenAIConfigs = [
250
+ // Models.generateContentInternal - The actual class method (Node.js entry point)
251
+ // Note: generateContent is an arrow function property that calls this internal method
252
+ {
253
+ channelName: "models.generateContent",
254
+ module: {
255
+ name: "@google/genai",
256
+ versionRange: ">=1.0.0",
257
+ filePath: "dist/node/index.mjs"
258
+ },
259
+ functionQuery: {
260
+ className: "Models",
261
+ methodName: "generateContentInternal",
262
+ kind: "Async"
263
+ }
264
+ },
265
+ // Models.generateContentStreamInternal - The actual class method (Node.js entry point)
266
+ // Note: generateContentStream is an arrow function property that calls this internal method
267
+ {
268
+ channelName: "models.generateContentStream",
269
+ module: {
270
+ name: "@google/genai",
271
+ versionRange: ">=1.0.0",
272
+ filePath: "dist/node/index.mjs"
273
+ },
274
+ functionQuery: {
275
+ className: "Models",
276
+ methodName: "generateContentStreamInternal",
277
+ kind: "Async"
278
+ }
279
+ }
280
+ ];
281
+
282
+ export {
283
+ openaiConfigs,
284
+ anthropicConfigs,
285
+ aiSDKConfigs,
286
+ claudeAgentSDKConfigs,
287
+ googleGenAIConfigs
288
+ };
@@ -0,0 +1,89 @@
1
+ import {
2
+ aiSDKConfigs,
3
+ anthropicConfigs,
4
+ claudeAgentSDKConfigs,
5
+ googleGenAIConfigs,
6
+ openaiConfigs
7
+ } from "./chunk-KVX7OFPD.mjs";
8
+
9
+ // src/auto-instrumentations/bundler/plugin.ts
10
+ import { createUnplugin } from "unplugin";
11
+ import {
12
+ create
13
+ } from "@apm-js-collab/code-transformer";
14
+ import { extname, join, sep } from "path";
15
+ import { readFileSync } from "fs";
16
+ import { fileURLToPath } from "url";
17
+ import moduleDetailsFromPath from "module-details-from-path";
18
+ function getModuleVersion(basedir) {
19
+ try {
20
+ const packageJsonPath = join(basedir, "package.json");
21
+ const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8"));
22
+ if (packageJson.version) {
23
+ return packageJson.version;
24
+ }
25
+ } catch (error) {
26
+ }
27
+ return void 0;
28
+ }
29
+ var unplugin = createUnplugin((options = {}) => {
30
+ const allInstrumentations = [
31
+ ...openaiConfigs,
32
+ ...anthropicConfigs,
33
+ ...aiSDKConfigs,
34
+ ...claudeAgentSDKConfigs,
35
+ ...googleGenAIConfigs,
36
+ ...options.instrumentations || []
37
+ ];
38
+ const dcModule = options.browser === false ? void 0 : "dc-browser";
39
+ const instrumentationMatcher = create(allInstrumentations, dcModule);
40
+ return {
41
+ name: "code-transformer",
42
+ enforce: "pre",
43
+ transform(code, id) {
44
+ const filePath = id.startsWith("file:") ? fileURLToPath(id) : id;
45
+ const ext = extname(filePath);
46
+ let isModule = ext === ".mjs" || ext === ".ts" || ext === ".tsx";
47
+ if (ext === ".js") {
48
+ isModule = code.includes("export ") || code.includes("import ");
49
+ }
50
+ const normalizedForPlatform = filePath.split("/").join(sep);
51
+ const moduleDetails = moduleDetailsFromPath(normalizedForPlatform);
52
+ if (!moduleDetails) {
53
+ return null;
54
+ }
55
+ const moduleName = moduleDetails.name;
56
+ const moduleVersion = getModuleVersion(moduleDetails.basedir);
57
+ if (!moduleVersion) {
58
+ console.warn(
59
+ `No 'package.json' version found for module ${moduleName} at ${moduleDetails.basedir}. Skipping transformation.`
60
+ );
61
+ return null;
62
+ }
63
+ const normalizedModulePath = moduleDetails.path.replace(/\\/g, "/");
64
+ const transformer = instrumentationMatcher.getTransformer(
65
+ moduleName,
66
+ moduleVersion,
67
+ normalizedModulePath
68
+ );
69
+ if (!transformer) {
70
+ return null;
71
+ }
72
+ try {
73
+ const moduleType = isModule ? "esm" : "cjs";
74
+ const result = transformer.transform(code, moduleType);
75
+ return {
76
+ code: result.code,
77
+ map: result.map
78
+ };
79
+ } catch (error) {
80
+ console.warn(`Code transformation failed for ${id}: ${error}`);
81
+ return null;
82
+ }
83
+ }
84
+ };
85
+ });
86
+
87
+ export {
88
+ unplugin
89
+ };
@@ -0,0 +1,22 @@
1
+ // src/auto-instrumentations/loader/get-package-version.ts
2
+ import { readFileSync } from "node:fs";
3
+ import { join } from "node:path";
4
+ var packageVersions = /* @__PURE__ */ new Map();
5
+ function getPackageVersion(baseDir) {
6
+ if (packageVersions.has(baseDir)) {
7
+ return packageVersions.get(baseDir);
8
+ }
9
+ try {
10
+ const packageJsonPath = join(baseDir, "package.json");
11
+ const jsonFile = readFileSync(packageJsonPath, "utf8");
12
+ const { version } = JSON.parse(jsonFile);
13
+ packageVersions.set(baseDir, version);
14
+ return version;
15
+ } catch {
16
+ return process.version.slice(1);
17
+ }
18
+ }
19
+
20
+ export {
21
+ getPackageVersion
22
+ };
@@ -0,0 +1,22 @@
1
+ // src/auto-instrumentations/loader/get-package-version.ts
2
+ import { readFileSync } from "node:fs";
3
+ import { join } from "node:path";
4
+ var packageVersions = /* @__PURE__ */ new Map();
5
+ function getPackageVersion(baseDir) {
6
+ if (packageVersions.has(baseDir)) {
7
+ return packageVersions.get(baseDir);
8
+ }
9
+ try {
10
+ const packageJsonPath = join(baseDir, "package.json");
11
+ const jsonFile = readFileSync(packageJsonPath, "utf8");
12
+ const { version } = JSON.parse(jsonFile);
13
+ packageVersions.set(baseDir, version);
14
+ return version;
15
+ } catch {
16
+ return process.version.slice(1);
17
+ }
18
+ }
19
+
20
+ export {
21
+ getPackageVersion
22
+ };