braintrust 3.3.0 → 3.5.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 (60) hide show
  1. package/README.md +52 -67
  2. package/dev/dist/index.d.mts +98 -14
  3. package/dev/dist/index.d.ts +98 -14
  4. package/dev/dist/index.js +2751 -1463
  5. package/dev/dist/index.mjs +2383 -1095
  6. package/dist/auto-instrumentations/bundler/esbuild.cjs +476 -31
  7. package/dist/auto-instrumentations/bundler/esbuild.d.mts +2 -2
  8. package/dist/auto-instrumentations/bundler/esbuild.d.ts +2 -2
  9. package/dist/auto-instrumentations/bundler/esbuild.mjs +2 -2
  10. package/dist/auto-instrumentations/bundler/rollup.cjs +476 -31
  11. package/dist/auto-instrumentations/bundler/rollup.mjs +2 -2
  12. package/dist/auto-instrumentations/bundler/vite.cjs +476 -31
  13. package/dist/auto-instrumentations/bundler/vite.d.mts +2 -2
  14. package/dist/auto-instrumentations/bundler/vite.d.ts +2 -2
  15. package/dist/auto-instrumentations/bundler/vite.mjs +2 -2
  16. package/dist/auto-instrumentations/bundler/webpack.cjs +476 -31
  17. package/dist/auto-instrumentations/bundler/webpack.d.mts +2 -2
  18. package/dist/auto-instrumentations/bundler/webpack.d.ts +2 -2
  19. package/dist/auto-instrumentations/bundler/webpack.mjs +2 -2
  20. package/dist/auto-instrumentations/chunk-DQTPSXJB.mjs +733 -0
  21. package/dist/auto-instrumentations/chunk-EVUKFMHG.mjs +41 -0
  22. package/dist/auto-instrumentations/{chunk-OLOPGWTJ.mjs → chunk-F3TJZ3Z2.mjs} +1 -1
  23. package/dist/auto-instrumentations/chunk-VLEJ5AEK.mjs +41 -0
  24. package/dist/auto-instrumentations/hook.mjs +540 -37
  25. package/dist/auto-instrumentations/index.cjs +476 -31
  26. package/dist/auto-instrumentations/index.d.mts +5 -5
  27. package/dist/auto-instrumentations/index.d.ts +5 -5
  28. package/dist/auto-instrumentations/index.mjs +1 -1
  29. package/dist/auto-instrumentations/loader/cjs-patch.cjs +32 -10
  30. package/dist/auto-instrumentations/loader/cjs-patch.mjs +10 -5
  31. package/dist/auto-instrumentations/loader/esm-hook.mjs +11 -12
  32. package/dist/auto-instrumentations/loader/get-package-version.cjs +28 -8
  33. package/dist/auto-instrumentations/loader/get-package-version.d.mts +2 -1
  34. package/dist/auto-instrumentations/loader/get-package-version.d.ts +2 -1
  35. package/dist/auto-instrumentations/loader/get-package-version.mjs +3 -1
  36. package/dist/browser.d.mts +806 -306
  37. package/dist/browser.d.ts +806 -306
  38. package/dist/browser.js +3235 -2317
  39. package/dist/browser.mjs +3235 -2317
  40. package/dist/cli.js +2672 -1347
  41. package/dist/edge-light.d.mts +1 -1
  42. package/dist/edge-light.d.ts +1 -1
  43. package/dist/edge-light.js +3035 -2087
  44. package/dist/edge-light.mjs +3035 -2087
  45. package/dist/index.d.mts +806 -306
  46. package/dist/index.d.ts +806 -306
  47. package/dist/index.js +3570 -2654
  48. package/dist/index.mjs +3235 -2319
  49. package/dist/instrumentation/index.d.mts +16 -22
  50. package/dist/instrumentation/index.d.ts +16 -22
  51. package/dist/instrumentation/index.js +2241 -1077
  52. package/dist/instrumentation/index.mjs +2241 -1077
  53. package/dist/workerd.d.mts +1 -1
  54. package/dist/workerd.d.ts +1 -1
  55. package/dist/workerd.js +3035 -2087
  56. package/dist/workerd.mjs +3035 -2087
  57. package/package.json +26 -7
  58. package/dist/auto-instrumentations/chunk-KVX7OFPD.mjs +0 -288
  59. package/dist/auto-instrumentations/chunk-XDBPUTVE.mjs +0 -22
  60. package/dist/auto-instrumentations/chunk-ZEC7BCL4.mjs +0 -22
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "braintrust",
3
- "version": "3.3.0",
3
+ "version": "3.5.0",
4
4
  "description": "SDK for integrating Braintrust",
5
5
  "repository": {
6
6
  "type": "git",
@@ -107,10 +107,22 @@
107
107
  ],
108
108
  "scripts": {
109
109
  "build": "cross-env NODE_OPTIONS=\"--max-old-space-size=8192\" tsup",
110
+ "check:typings": "tsc --noEmit",
110
111
  "watch": "tsup --watch",
111
112
  "clean": "rm -r dist/* && rm -r dev/dist/*",
112
113
  "docs": "npx typedoc --options typedoc.json src/node/index.ts",
113
114
  "test": "vitest run --exclude \"src/wrappers/**/*.test.ts\" --exclude \"src/otel/**/*.test.ts\" --exclude \"smoke/**/*.test.ts\" --exclude \"src/zod/**/*.test.ts\" --exclude \"tests/api-compatibility/**\"",
115
+ "test:core": "pnpm prune && pnpm test",
116
+ "test:checks": "pnpm run test:core && pnpm run test:vitest",
117
+ "test:external": "pnpm run test:external:openai && pnpm run test:external:anthropic && pnpm run test:external:google-genai && pnpm run test:external:ai-sdk && pnpm run test:external:claude-agent-sdk",
118
+ "test:external:openai": "bash scripts/test-provider.sh test:openai openai",
119
+ "test:external:anthropic": "bash scripts/test-provider.sh test:anthropic @anthropic-ai/sdk",
120
+ "test:external:google-genai": "bash scripts/test-provider.sh test:google-genai @google/genai",
121
+ "test:external:ai-sdk": "pnpm run test:external:ai-sdk-v5 && pnpm run test:external:ai-sdk-v6",
122
+ "test:external:ai-sdk-v5": "cd src/wrappers/ai-sdk/tests/v5 && pnpm install --ignore-workspace && pnpm test",
123
+ "test:external:ai-sdk-v6": "cd src/wrappers/ai-sdk/tests/v6 && pnpm install --ignore-workspace && pnpm test",
124
+ "test:external:claude-agent-sdk": "cd src/wrappers/claude-agent-sdk && pnpm install && pnpm test",
125
+ "test:all": "pnpm run test:checks && pnpm run test:external",
114
126
  "test:api-compat": "vitest run tests/api-compatibility/api-compatibility.test.ts",
115
127
  "test:anthropic": "vitest run src/wrappers/anthropic.test.ts",
116
128
  "test:openai": "vitest run src/wrappers/oai.test.ts",
@@ -126,8 +138,14 @@
126
138
  "test:claude-agent-sdk": "pnpm --filter @braintrust/claude-agent-sdk-tests test",
127
139
  "test:vitest": "pnpm --filter @braintrust/vitest-wrapper-tests test",
128
140
  "test:output": "tsx scripts/test-output.ts --with-comparison --with-metrics --with-progress",
141
+ "bench": "npx tsx src/queue.bench.ts",
142
+ "publish:validate": "./scripts/validate-release.sh && pnpm install --frozen-lockfile && pnpm run build && npm publish",
129
143
  "lint": "eslint .",
130
- "fix:eslint": "eslint --fix ."
144
+ "fix:lint": "eslint --fix .",
145
+ "playground": "tsx playground.ts",
146
+ "playground:auto": "mkdir -p .context && pnpm exec esbuild playground.ts --platform=node --format=esm --outfile=.context/playground.auto.mjs && node --import ./dist/auto-instrumentations/hook.mjs ./.context/playground.auto.mjs",
147
+ "playground:cli:push": "node dist/cli.js push playground.ts",
148
+ "playground:cli:eval": "node dist/cli.js eval playground.ts"
131
149
  },
132
150
  "author": "",
133
151
  "license": "MIT",
@@ -158,20 +176,21 @@
158
176
  "cross-env": "^7.0.3",
159
177
  "eslint-plugin-node-import": "^1.0.5",
160
178
  "jiti": "^2.6.1",
179
+ "openai": "6.25.0",
161
180
  "openapi-zod-client": "^1.18.3",
162
181
  "rollup": "^4.28.1",
163
- "vite": "^5.4.14",
164
- "webpack": "^5.97.1",
165
182
  "tar": "^7.5.2",
166
183
  "tinybench": "^4.0.1",
167
184
  "ts-jest": "^29.1.4",
168
185
  "tsup": "^8.5.1",
169
- "tsx": "^3.14.0",
186
+ "tsx": "^4.21.0",
170
187
  "typedoc": "^0.25.13",
171
188
  "typedoc-plugin-markdown": "^3.17.1",
172
189
  "typescript": "5.4.4",
190
+ "vite": "^6.4.1",
173
191
  "vite-tsconfig-paths": "^4.3.2",
174
- "vitest": "^2.1.9",
192
+ "vitest": "^4.1.0",
193
+ "webpack": "^5.97.1",
175
194
  "zod": "^3.25.34"
176
195
  },
177
196
  "dependencies": {
@@ -186,7 +205,7 @@
186
205
  "cli-progress": "^3.12.0",
187
206
  "cli-table3": "^0.6.5",
188
207
  "cors": "^2.8.5",
189
- "dc-browser": "^1.0.2",
208
+ "dc-browser": "^1.0.3",
190
209
  "dotenv": "^16.4.5",
191
210
  "esbuild": "^0.27.0",
192
211
  "eventsource-parser": "^1.1.2",
@@ -1,288 +0,0 @@
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
- };
@@ -1,22 +0,0 @@
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
- };
@@ -1,22 +0,0 @@
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
- };