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,401 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/auto-instrumentations/bundler/esbuild.ts
31
+ var esbuild_exports = {};
32
+ __export(esbuild_exports, {
33
+ esbuildPlugin: () => esbuildPlugin
34
+ });
35
+ module.exports = __toCommonJS(esbuild_exports);
36
+
37
+ // src/auto-instrumentations/bundler/plugin.ts
38
+ var import_unplugin = require("unplugin");
39
+ var import_code_transformer = require("@apm-js-collab/code-transformer");
40
+ var import_path = require("path");
41
+ var import_fs = require("fs");
42
+ var import_url = require("url");
43
+ var import_module_details_from_path = __toESM(require("module-details-from-path"));
44
+
45
+ // src/auto-instrumentations/configs/openai.ts
46
+ var openaiConfigs = [
47
+ // Chat Completions
48
+ {
49
+ channelName: "chat.completions.create",
50
+ module: {
51
+ name: "openai",
52
+ versionRange: ">=4.0.0",
53
+ filePath: "resources/chat/completions.mjs"
54
+ },
55
+ functionQuery: {
56
+ className: "Completions",
57
+ methodName: "create",
58
+ kind: "Async"
59
+ }
60
+ },
61
+ // Embeddings
62
+ {
63
+ channelName: "embeddings.create",
64
+ module: {
65
+ name: "openai",
66
+ versionRange: ">=4.0.0",
67
+ filePath: "resources/embeddings.mjs"
68
+ },
69
+ functionQuery: {
70
+ className: "Embeddings",
71
+ methodName: "create",
72
+ kind: "Async"
73
+ }
74
+ },
75
+ // Beta Chat Completions Parse
76
+ {
77
+ channelName: "beta.chat.completions.parse",
78
+ module: {
79
+ name: "openai",
80
+ versionRange: ">=4.0.0",
81
+ filePath: "resources/beta/chat/completions.mjs"
82
+ },
83
+ functionQuery: {
84
+ className: "Completions",
85
+ methodName: "parse",
86
+ kind: "Async"
87
+ }
88
+ },
89
+ // Moderations
90
+ {
91
+ channelName: "moderations.create",
92
+ module: {
93
+ name: "openai",
94
+ versionRange: ">=4.0.0",
95
+ filePath: "resources/moderations.mjs"
96
+ },
97
+ functionQuery: {
98
+ className: "Moderations",
99
+ methodName: "create",
100
+ kind: "Async"
101
+ }
102
+ },
103
+ // Beta Chat Completions Stream
104
+ {
105
+ channelName: "beta.chat.completions.stream",
106
+ module: {
107
+ name: "openai",
108
+ versionRange: ">=4.0.0",
109
+ filePath: "resources/beta/chat/completions.mjs"
110
+ },
111
+ functionQuery: {
112
+ className: "Completions",
113
+ methodName: "stream",
114
+ kind: "Sync"
115
+ }
116
+ },
117
+ // Responses API (v4.87.0+)
118
+ {
119
+ channelName: "responses.create",
120
+ module: {
121
+ name: "openai",
122
+ versionRange: ">=4.87.0",
123
+ filePath: "resources/responses/responses.mjs"
124
+ },
125
+ functionQuery: {
126
+ className: "Responses",
127
+ methodName: "create",
128
+ kind: "Async"
129
+ }
130
+ },
131
+ {
132
+ channelName: "responses.stream",
133
+ module: {
134
+ name: "openai",
135
+ versionRange: ">=4.87.0",
136
+ filePath: "resources/responses/responses.mjs"
137
+ },
138
+ functionQuery: {
139
+ className: "Responses",
140
+ methodName: "stream",
141
+ kind: "Sync"
142
+ }
143
+ },
144
+ {
145
+ channelName: "responses.parse",
146
+ module: {
147
+ name: "openai",
148
+ versionRange: ">=4.87.0",
149
+ filePath: "resources/responses/responses.mjs"
150
+ },
151
+ functionQuery: {
152
+ className: "Responses",
153
+ methodName: "parse",
154
+ kind: "Async"
155
+ }
156
+ }
157
+ ];
158
+
159
+ // src/auto-instrumentations/configs/anthropic.ts
160
+ var anthropicConfigs = [
161
+ // Messages API - create (supports streaming via stream=true parameter)
162
+ {
163
+ channelName: "messages.create",
164
+ module: {
165
+ name: "@anthropic-ai/sdk",
166
+ versionRange: ">=0.60.0",
167
+ filePath: "resources/messages.mjs"
168
+ },
169
+ functionQuery: {
170
+ className: "Messages",
171
+ methodName: "create",
172
+ kind: "Async"
173
+ }
174
+ },
175
+ // Beta Messages API - create (supports streaming via stream=true parameter)
176
+ {
177
+ channelName: "beta.messages.create",
178
+ module: {
179
+ name: "@anthropic-ai/sdk",
180
+ versionRange: ">=0.60.0",
181
+ filePath: "resources/beta/messages/messages.mjs"
182
+ },
183
+ functionQuery: {
184
+ className: "Messages",
185
+ methodName: "create",
186
+ kind: "Async"
187
+ }
188
+ }
189
+ ];
190
+
191
+ // src/auto-instrumentations/configs/ai-sdk.ts
192
+ var aiSDKConfigs = [
193
+ // generateText - async function
194
+ {
195
+ channelName: "generateText",
196
+ module: {
197
+ name: "ai",
198
+ versionRange: ">=3.0.0",
199
+ filePath: "dist/index.mjs"
200
+ },
201
+ functionQuery: {
202
+ functionName: "generateText",
203
+ kind: "Async"
204
+ }
205
+ },
206
+ // streamText - async function
207
+ {
208
+ channelName: "streamText",
209
+ module: {
210
+ name: "ai",
211
+ versionRange: ">=3.0.0",
212
+ filePath: "dist/index.mjs"
213
+ },
214
+ functionQuery: {
215
+ functionName: "streamText",
216
+ kind: "Async"
217
+ }
218
+ },
219
+ // generateObject - async function
220
+ {
221
+ channelName: "generateObject",
222
+ module: {
223
+ name: "ai",
224
+ versionRange: ">=3.0.0",
225
+ filePath: "dist/index.mjs"
226
+ },
227
+ functionQuery: {
228
+ functionName: "generateObject",
229
+ kind: "Async"
230
+ }
231
+ },
232
+ // streamObject - async function
233
+ {
234
+ channelName: "streamObject",
235
+ module: {
236
+ name: "ai",
237
+ versionRange: ">=3.0.0",
238
+ filePath: "dist/index.mjs"
239
+ },
240
+ functionQuery: {
241
+ functionName: "streamObject",
242
+ kind: "Async"
243
+ }
244
+ },
245
+ // Agent.generate - async method (v3-v5 only, Agent structure changed in v6)
246
+ {
247
+ channelName: "Agent.generate",
248
+ module: {
249
+ name: "ai",
250
+ versionRange: ">=3.0.0 <6.0.0",
251
+ filePath: "dist/index.mjs"
252
+ },
253
+ functionQuery: {
254
+ className: "Agent",
255
+ methodName: "generate",
256
+ kind: "Async"
257
+ }
258
+ },
259
+ // Agent.stream - async method (v3-v5 only, Agent structure changed in v6)
260
+ {
261
+ channelName: "Agent.stream",
262
+ module: {
263
+ name: "ai",
264
+ versionRange: ">=3.0.0 <6.0.0",
265
+ filePath: "dist/index.mjs"
266
+ },
267
+ functionQuery: {
268
+ className: "Agent",
269
+ methodName: "stream",
270
+ kind: "Async"
271
+ }
272
+ }
273
+ ];
274
+
275
+ // src/auto-instrumentations/configs/claude-agent-sdk.ts
276
+ var claudeAgentSDKConfigs = [
277
+ // query - Main entry point for agent interactions (top-level exported async generator function)
278
+ {
279
+ channelName: "query",
280
+ module: {
281
+ name: "@anthropic-ai/claude-agent-sdk",
282
+ versionRange: ">=0.1.0",
283
+ filePath: "sdk.mjs"
284
+ },
285
+ functionQuery: {
286
+ functionName: "query",
287
+ kind: "Async"
288
+ }
289
+ }
290
+ ];
291
+
292
+ // src/auto-instrumentations/configs/google-genai.ts
293
+ var googleGenAIConfigs = [
294
+ // Models.generateContentInternal - The actual class method (Node.js entry point)
295
+ // Note: generateContent is an arrow function property that calls this internal method
296
+ {
297
+ channelName: "models.generateContent",
298
+ module: {
299
+ name: "@google/genai",
300
+ versionRange: ">=1.0.0",
301
+ filePath: "dist/node/index.mjs"
302
+ },
303
+ functionQuery: {
304
+ className: "Models",
305
+ methodName: "generateContentInternal",
306
+ kind: "Async"
307
+ }
308
+ },
309
+ // Models.generateContentStreamInternal - The actual class method (Node.js entry point)
310
+ // Note: generateContentStream is an arrow function property that calls this internal method
311
+ {
312
+ channelName: "models.generateContentStream",
313
+ module: {
314
+ name: "@google/genai",
315
+ versionRange: ">=1.0.0",
316
+ filePath: "dist/node/index.mjs"
317
+ },
318
+ functionQuery: {
319
+ className: "Models",
320
+ methodName: "generateContentStreamInternal",
321
+ kind: "Async"
322
+ }
323
+ }
324
+ ];
325
+
326
+ // src/auto-instrumentations/bundler/plugin.ts
327
+ function getModuleVersion(basedir) {
328
+ try {
329
+ const packageJsonPath = (0, import_path.join)(basedir, "package.json");
330
+ const packageJson = JSON.parse((0, import_fs.readFileSync)(packageJsonPath, "utf8"));
331
+ if (packageJson.version) {
332
+ return packageJson.version;
333
+ }
334
+ } catch (error) {
335
+ }
336
+ return void 0;
337
+ }
338
+ var unplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
339
+ const allInstrumentations = [
340
+ ...openaiConfigs,
341
+ ...anthropicConfigs,
342
+ ...aiSDKConfigs,
343
+ ...claudeAgentSDKConfigs,
344
+ ...googleGenAIConfigs,
345
+ ...options.instrumentations || []
346
+ ];
347
+ const dcModule = options.browser === false ? void 0 : "dc-browser";
348
+ const instrumentationMatcher = (0, import_code_transformer.create)(allInstrumentations, dcModule);
349
+ return {
350
+ name: "code-transformer",
351
+ enforce: "pre",
352
+ transform(code, id) {
353
+ const filePath = id.startsWith("file:") ? (0, import_url.fileURLToPath)(id) : id;
354
+ const ext = (0, import_path.extname)(filePath);
355
+ let isModule = ext === ".mjs" || ext === ".ts" || ext === ".tsx";
356
+ if (ext === ".js") {
357
+ isModule = code.includes("export ") || code.includes("import ");
358
+ }
359
+ const normalizedForPlatform = filePath.split("/").join(import_path.sep);
360
+ const moduleDetails = (0, import_module_details_from_path.default)(normalizedForPlatform);
361
+ if (!moduleDetails) {
362
+ return null;
363
+ }
364
+ const moduleName = moduleDetails.name;
365
+ const moduleVersion = getModuleVersion(moduleDetails.basedir);
366
+ if (!moduleVersion) {
367
+ console.warn(
368
+ `No 'package.json' version found for module ${moduleName} at ${moduleDetails.basedir}. Skipping transformation.`
369
+ );
370
+ return null;
371
+ }
372
+ const normalizedModulePath = moduleDetails.path.replace(/\\/g, "/");
373
+ const transformer = instrumentationMatcher.getTransformer(
374
+ moduleName,
375
+ moduleVersion,
376
+ normalizedModulePath
377
+ );
378
+ if (!transformer) {
379
+ return null;
380
+ }
381
+ try {
382
+ const moduleType = isModule ? "esm" : "cjs";
383
+ const result = transformer.transform(code, moduleType);
384
+ return {
385
+ code: result.code,
386
+ map: result.map
387
+ };
388
+ } catch (error) {
389
+ console.warn(`Code transformation failed for ${id}: ${error}`);
390
+ return null;
391
+ }
392
+ }
393
+ };
394
+ });
395
+
396
+ // src/auto-instrumentations/bundler/esbuild.ts
397
+ var esbuildPlugin = unplugin.esbuild;
398
+ // Annotate the CommonJS export names for ESM import in node:
399
+ 0 && (module.exports = {
400
+ esbuildPlugin
401
+ });
@@ -0,0 +1,8 @@
1
+ import * as esbuild from 'esbuild';
2
+ import { B as BundlerPluginOptions } from '../plugin-Df3qKIl2.mjs';
3
+ import '@apm-js-collab/code-transformer';
4
+
5
+ type EsbuildPluginOptions = BundlerPluginOptions;
6
+ declare const esbuildPlugin: (options: BundlerPluginOptions) => esbuild.Plugin;
7
+
8
+ export { type EsbuildPluginOptions, esbuildPlugin };
@@ -0,0 +1,8 @@
1
+ import * as esbuild from 'esbuild';
2
+ import { B as BundlerPluginOptions } from '../plugin-Df3qKIl2.js';
3
+ import '@apm-js-collab/code-transformer';
4
+
5
+ type EsbuildPluginOptions = BundlerPluginOptions;
6
+ declare const esbuildPlugin: (options: BundlerPluginOptions) => esbuild.Plugin;
7
+
8
+ export { type EsbuildPluginOptions, esbuildPlugin };
@@ -0,0 +1,10 @@
1
+ import {
2
+ unplugin
3
+ } from "../chunk-OLOPGWTJ.mjs";
4
+ import "../chunk-KVX7OFPD.mjs";
5
+
6
+ // src/auto-instrumentations/bundler/esbuild.ts
7
+ var esbuildPlugin = unplugin.esbuild;
8
+ export {
9
+ esbuildPlugin
10
+ };