braintrust 3.8.0 → 3.9.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 (48) hide show
  1. package/dev/dist/index.d.mts +84 -3
  2. package/dev/dist/index.d.ts +84 -3
  3. package/dev/dist/index.js +3687 -691
  4. package/dev/dist/index.mjs +3399 -403
  5. package/dist/auto-instrumentations/bundler/esbuild.cjs +575 -2
  6. package/dist/auto-instrumentations/bundler/esbuild.mjs +2 -2
  7. package/dist/auto-instrumentations/bundler/rollup.cjs +575 -2
  8. package/dist/auto-instrumentations/bundler/rollup.mjs +2 -2
  9. package/dist/auto-instrumentations/bundler/vite.cjs +575 -2
  10. package/dist/auto-instrumentations/bundler/vite.mjs +2 -2
  11. package/dist/auto-instrumentations/bundler/webpack-loader.cjs +575 -2
  12. package/dist/auto-instrumentations/bundler/webpack.cjs +575 -2
  13. package/dist/auto-instrumentations/bundler/webpack.mjs +2 -2
  14. package/dist/auto-instrumentations/{chunk-MD7W27YH.mjs → chunk-G7F6HZGE.mjs} +5 -1
  15. package/dist/auto-instrumentations/{chunk-OLBMPZXE.mjs → chunk-KIMMUFAK.mjs} +578 -3
  16. package/dist/auto-instrumentations/hook.mjs +757 -10
  17. package/dist/auto-instrumentations/index.cjs +739 -2
  18. package/dist/auto-instrumentations/index.d.mts +18 -1
  19. package/dist/auto-instrumentations/index.d.ts +18 -1
  20. package/dist/auto-instrumentations/index.mjs +168 -1
  21. package/dist/auto-instrumentations/loader/esm-hook.mjs +2 -1
  22. package/dist/browser.d.mts +312 -6
  23. package/dist/browser.d.ts +312 -6
  24. package/dist/browser.js +5335 -1892
  25. package/dist/browser.mjs +5335 -1892
  26. package/dist/cli.js +3514 -489
  27. package/dist/edge-light.d.mts +1 -1
  28. package/dist/edge-light.d.ts +1 -1
  29. package/dist/edge-light.js +5335 -1892
  30. package/dist/edge-light.mjs +5335 -1892
  31. package/dist/index.d.mts +312 -6
  32. package/dist/index.d.ts +312 -6
  33. package/dist/index.js +4244 -801
  34. package/dist/index.mjs +5335 -1892
  35. package/dist/instrumentation/index.d.mts +10 -0
  36. package/dist/instrumentation/index.d.ts +10 -0
  37. package/dist/instrumentation/index.js +3160 -286
  38. package/dist/instrumentation/index.mjs +3160 -286
  39. package/dist/workerd.d.mts +1 -1
  40. package/dist/workerd.d.ts +1 -1
  41. package/dist/workerd.js +5335 -1892
  42. package/dist/workerd.mjs +5335 -1892
  43. package/package.json +52 -47
  44. package/util/dist/index.d.mts +42 -1
  45. package/util/dist/index.d.ts +42 -1
  46. package/util/dist/index.js +5 -1
  47. package/util/dist/index.mjs +4 -0
  48. package/LICENSE +0 -201
@@ -131,6 +131,10 @@ type OtherExperimentLogFields = {
131
131
  error: unknown;
132
132
  tags: string[];
133
133
  scores: Record<string, number | null>;
134
+ classifications?: Record<string, {
135
+ id: string;
136
+ label?: string;
137
+ }[]>;
134
138
  metadata: Record<string, unknown>;
135
139
  metrics: Record<string, unknown>;
136
140
  datasetRecordId: string;
@@ -287,6 +291,42 @@ declare class SpanComponentsV3 {
287
291
  private static fromJsonObj;
288
292
  }
289
293
 
294
+ /**
295
+ * The result returned by a classifier function. Unlike `Score`, `id` is
296
+ * required and the span will be recorded as a classifier span.
297
+ */
298
+ interface Classification {
299
+ /**
300
+ * The name of this classification result. Used as the key in the
301
+ * `classifications` log record. If omitted, defaults to the classifier
302
+ * function's name.
303
+ */
304
+ name: string;
305
+ /**
306
+ * A machine-readable identifier for the classification outcome
307
+ * (e.g. `"positive"`, `"negative"`, `"neutral"`). This value is stored
308
+ * in the log and used for programmatic analysis.
309
+ */
310
+ id: string;
311
+ /**
312
+ * An optional human-readable display label for this outcome. If omitted,
313
+ * defaults to `id`. Use this when you want a friendlier label in the UI
314
+ * while keeping a stable `id` for programmatic use.
315
+ */
316
+ label?: string;
317
+ /**
318
+ * Optional arbitrary metadata to attach to this classification result.
319
+ */
320
+ metadata?: Record<string, unknown>;
321
+ }
322
+ /**
323
+ * The serialized form of a classification stored in the `classifications` log record.
324
+ */
325
+ interface ClassificationItem {
326
+ id: string;
327
+ label: string;
328
+ metadata?: Record<string, unknown>;
329
+ }
290
330
  interface Score {
291
331
  name: string;
292
332
  score: number | null;
@@ -2114,6 +2154,15 @@ declare const FunctionData: z.ZodUnion<[z.ZodObject<{
2114
2154
  }, {
2115
2155
  type: "scorer";
2116
2156
  index: number;
2157
+ }>, z.ZodObject<{
2158
+ type: z.ZodLiteral<"classifier">;
2159
+ index: z.ZodNumber;
2160
+ }, "strip", z.ZodTypeAny, {
2161
+ type: "classifier";
2162
+ index: number;
2163
+ }, {
2164
+ type: "classifier";
2165
+ index: number;
2117
2166
  }>]>;
2118
2167
  }, "strip", z.ZodTypeAny, {
2119
2168
  type: "experiment";
@@ -2123,6 +2172,9 @@ declare const FunctionData: z.ZodUnion<[z.ZodObject<{
2123
2172
  } | {
2124
2173
  type: "scorer";
2125
2174
  index: number;
2175
+ } | {
2176
+ type: "classifier";
2177
+ index: number;
2126
2178
  };
2127
2179
  }, {
2128
2180
  type: "experiment";
@@ -2132,6 +2184,9 @@ declare const FunctionData: z.ZodUnion<[z.ZodObject<{
2132
2184
  } | {
2133
2185
  type: "scorer";
2134
2186
  index: number;
2187
+ } | {
2188
+ type: "classifier";
2189
+ index: number;
2135
2190
  };
2136
2191
  }>, z.ZodObject<{
2137
2192
  type: z.ZodLiteral<"function">;
@@ -2204,6 +2259,9 @@ declare const FunctionData: z.ZodUnion<[z.ZodObject<{
2204
2259
  } | {
2205
2260
  type: "scorer";
2206
2261
  index: number;
2262
+ } | {
2263
+ type: "classifier";
2264
+ index: number;
2207
2265
  };
2208
2266
  } | {
2209
2267
  type: "function";
@@ -2236,6 +2294,9 @@ declare const FunctionData: z.ZodUnion<[z.ZodObject<{
2236
2294
  } | {
2237
2295
  type: "scorer";
2238
2296
  index: number;
2297
+ } | {
2298
+ type: "classifier";
2299
+ index: number;
2239
2300
  };
2240
2301
  } | {
2241
2302
  type: "function";
@@ -2303,6 +2364,9 @@ declare const FunctionData: z.ZodUnion<[z.ZodObject<{
2303
2364
  } | {
2304
2365
  type: "scorer";
2305
2366
  index: number;
2367
+ } | {
2368
+ type: "classifier";
2369
+ index: number;
2306
2370
  };
2307
2371
  } | {
2308
2372
  type: "function";
@@ -2348,6 +2412,9 @@ declare const FunctionData: z.ZodUnion<[z.ZodObject<{
2348
2412
  } | {
2349
2413
  type: "scorer";
2350
2414
  index: number;
2415
+ } | {
2416
+ type: "classifier";
2417
+ index: number;
2351
2418
  };
2352
2419
  } | {
2353
2420
  type: "function";
@@ -11306,6 +11373,7 @@ type EvalCase<Input, Expected, Metadata> = {
11306
11373
  _xact_id?: TransactionId;
11307
11374
  created?: string | null;
11308
11375
  upsert_id?: string;
11376
+ trialCount?: number;
11309
11377
  } & (Expected extends void ? object : {
11310
11378
  expected: Expected;
11311
11379
  }) & (Metadata extends void ? object : {
@@ -13226,17 +13294,23 @@ type EvalScorerArgs<Input, Output, Expected, Metadata extends BaseMetadata = Def
13226
13294
  };
13227
13295
  type OneOrMoreScores = Score | number | null | Array<Score>;
13228
13296
  type EvalScorer<Input, Output, Expected, Metadata extends BaseMetadata = DefaultMetadataType> = (args: EvalScorerArgs<Input, Output, Expected, Metadata>) => OneOrMoreScores | Promise<OneOrMoreScores>;
13297
+ type OneOrMoreClassifications = Classification | Classification[] | null;
13298
+ type EvalClassifier<Input, Output, Expected, Metadata extends BaseMetadata = DefaultMetadataType> = (args: EvalScorerArgs<Input, Output, Expected, Metadata>) => OneOrMoreClassifications | Promise<OneOrMoreClassifications>;
13229
13299
  type EvalResult<Input, Output, Expected, Metadata extends BaseMetadata = DefaultMetadataType> = EvalCase<Input, Expected, Metadata> & {
13230
13300
  output: Output;
13231
- scores: Record<string, number | null>;
13232
13301
  error: unknown;
13233
13302
  origin?: ObjectReferenceType;
13303
+ scores: Record<string, number | null>;
13304
+ classifications?: Record<string, ClassificationItem[]>;
13234
13305
  };
13235
13306
  type ErrorScoreHandler = (args: {
13236
13307
  rootSpan: Span;
13237
13308
  data: EvalCase<any, any, any>;
13238
13309
  unhandledScores: string[];
13239
13310
  }) => Record<string, number> | undefined | void;
13311
+ /**
13312
+ * Defines an evaluator. At least one of `scores` or `classifiers` must be provided.
13313
+ */
13240
13314
  interface Evaluator<Input, Output, Expected, Metadata extends BaseMetadata = DefaultMetadataType, Parameters extends EvalParameters = EvalParameters> {
13241
13315
  /**
13242
13316
  * A function that returns a list of inputs, expected outputs, and metadata.
@@ -13247,9 +13321,16 @@ interface Evaluator<Input, Output, Expected, Metadata extends BaseMetadata = Def
13247
13321
  */
13248
13322
  task: EvalTask<Input, Output, Expected, Metadata, Parameters>;
13249
13323
  /**
13250
- * A set of functions that take an input, output, and expected value and return a score.
13324
+ * A set of functions that take an input, output, and expected value and return a {@link Score}.
13325
+ * At least one of `scores` or `classifiers` must be provided.
13326
+ */
13327
+ scores?: EvalScorer<Input, Output, Expected, Metadata>[];
13328
+ /**
13329
+ * A set of functions that take an input, output, and expected value and return a
13330
+ * {@link Classification}. Results are recorded under the `classifications` column.
13331
+ * At least one of `scores` or `classifiers` must be provided.
13251
13332
  */
13252
- scores: EvalScorer<Input, Output, Expected, Metadata>[];
13333
+ classifiers?: EvalClassifier<Input, Output, Expected, Metadata>[];
13253
13334
  /**
13254
13335
  * A set of parameters that will be passed to the evaluator.
13255
13336
  * Can be:
@@ -131,6 +131,10 @@ type OtherExperimentLogFields = {
131
131
  error: unknown;
132
132
  tags: string[];
133
133
  scores: Record<string, number | null>;
134
+ classifications?: Record<string, {
135
+ id: string;
136
+ label?: string;
137
+ }[]>;
134
138
  metadata: Record<string, unknown>;
135
139
  metrics: Record<string, unknown>;
136
140
  datasetRecordId: string;
@@ -287,6 +291,42 @@ declare class SpanComponentsV3 {
287
291
  private static fromJsonObj;
288
292
  }
289
293
 
294
+ /**
295
+ * The result returned by a classifier function. Unlike `Score`, `id` is
296
+ * required and the span will be recorded as a classifier span.
297
+ */
298
+ interface Classification {
299
+ /**
300
+ * The name of this classification result. Used as the key in the
301
+ * `classifications` log record. If omitted, defaults to the classifier
302
+ * function's name.
303
+ */
304
+ name: string;
305
+ /**
306
+ * A machine-readable identifier for the classification outcome
307
+ * (e.g. `"positive"`, `"negative"`, `"neutral"`). This value is stored
308
+ * in the log and used for programmatic analysis.
309
+ */
310
+ id: string;
311
+ /**
312
+ * An optional human-readable display label for this outcome. If omitted,
313
+ * defaults to `id`. Use this when you want a friendlier label in the UI
314
+ * while keeping a stable `id` for programmatic use.
315
+ */
316
+ label?: string;
317
+ /**
318
+ * Optional arbitrary metadata to attach to this classification result.
319
+ */
320
+ metadata?: Record<string, unknown>;
321
+ }
322
+ /**
323
+ * The serialized form of a classification stored in the `classifications` log record.
324
+ */
325
+ interface ClassificationItem {
326
+ id: string;
327
+ label: string;
328
+ metadata?: Record<string, unknown>;
329
+ }
290
330
  interface Score {
291
331
  name: string;
292
332
  score: number | null;
@@ -2114,6 +2154,15 @@ declare const FunctionData: z.ZodUnion<[z.ZodObject<{
2114
2154
  }, {
2115
2155
  type: "scorer";
2116
2156
  index: number;
2157
+ }>, z.ZodObject<{
2158
+ type: z.ZodLiteral<"classifier">;
2159
+ index: z.ZodNumber;
2160
+ }, "strip", z.ZodTypeAny, {
2161
+ type: "classifier";
2162
+ index: number;
2163
+ }, {
2164
+ type: "classifier";
2165
+ index: number;
2117
2166
  }>]>;
2118
2167
  }, "strip", z.ZodTypeAny, {
2119
2168
  type: "experiment";
@@ -2123,6 +2172,9 @@ declare const FunctionData: z.ZodUnion<[z.ZodObject<{
2123
2172
  } | {
2124
2173
  type: "scorer";
2125
2174
  index: number;
2175
+ } | {
2176
+ type: "classifier";
2177
+ index: number;
2126
2178
  };
2127
2179
  }, {
2128
2180
  type: "experiment";
@@ -2132,6 +2184,9 @@ declare const FunctionData: z.ZodUnion<[z.ZodObject<{
2132
2184
  } | {
2133
2185
  type: "scorer";
2134
2186
  index: number;
2187
+ } | {
2188
+ type: "classifier";
2189
+ index: number;
2135
2190
  };
2136
2191
  }>, z.ZodObject<{
2137
2192
  type: z.ZodLiteral<"function">;
@@ -2204,6 +2259,9 @@ declare const FunctionData: z.ZodUnion<[z.ZodObject<{
2204
2259
  } | {
2205
2260
  type: "scorer";
2206
2261
  index: number;
2262
+ } | {
2263
+ type: "classifier";
2264
+ index: number;
2207
2265
  };
2208
2266
  } | {
2209
2267
  type: "function";
@@ -2236,6 +2294,9 @@ declare const FunctionData: z.ZodUnion<[z.ZodObject<{
2236
2294
  } | {
2237
2295
  type: "scorer";
2238
2296
  index: number;
2297
+ } | {
2298
+ type: "classifier";
2299
+ index: number;
2239
2300
  };
2240
2301
  } | {
2241
2302
  type: "function";
@@ -2303,6 +2364,9 @@ declare const FunctionData: z.ZodUnion<[z.ZodObject<{
2303
2364
  } | {
2304
2365
  type: "scorer";
2305
2366
  index: number;
2367
+ } | {
2368
+ type: "classifier";
2369
+ index: number;
2306
2370
  };
2307
2371
  } | {
2308
2372
  type: "function";
@@ -2348,6 +2412,9 @@ declare const FunctionData: z.ZodUnion<[z.ZodObject<{
2348
2412
  } | {
2349
2413
  type: "scorer";
2350
2414
  index: number;
2415
+ } | {
2416
+ type: "classifier";
2417
+ index: number;
2351
2418
  };
2352
2419
  } | {
2353
2420
  type: "function";
@@ -11306,6 +11373,7 @@ type EvalCase<Input, Expected, Metadata> = {
11306
11373
  _xact_id?: TransactionId;
11307
11374
  created?: string | null;
11308
11375
  upsert_id?: string;
11376
+ trialCount?: number;
11309
11377
  } & (Expected extends void ? object : {
11310
11378
  expected: Expected;
11311
11379
  }) & (Metadata extends void ? object : {
@@ -13226,17 +13294,23 @@ type EvalScorerArgs<Input, Output, Expected, Metadata extends BaseMetadata = Def
13226
13294
  };
13227
13295
  type OneOrMoreScores = Score | number | null | Array<Score>;
13228
13296
  type EvalScorer<Input, Output, Expected, Metadata extends BaseMetadata = DefaultMetadataType> = (args: EvalScorerArgs<Input, Output, Expected, Metadata>) => OneOrMoreScores | Promise<OneOrMoreScores>;
13297
+ type OneOrMoreClassifications = Classification | Classification[] | null;
13298
+ type EvalClassifier<Input, Output, Expected, Metadata extends BaseMetadata = DefaultMetadataType> = (args: EvalScorerArgs<Input, Output, Expected, Metadata>) => OneOrMoreClassifications | Promise<OneOrMoreClassifications>;
13229
13299
  type EvalResult<Input, Output, Expected, Metadata extends BaseMetadata = DefaultMetadataType> = EvalCase<Input, Expected, Metadata> & {
13230
13300
  output: Output;
13231
- scores: Record<string, number | null>;
13232
13301
  error: unknown;
13233
13302
  origin?: ObjectReferenceType;
13303
+ scores: Record<string, number | null>;
13304
+ classifications?: Record<string, ClassificationItem[]>;
13234
13305
  };
13235
13306
  type ErrorScoreHandler = (args: {
13236
13307
  rootSpan: Span;
13237
13308
  data: EvalCase<any, any, any>;
13238
13309
  unhandledScores: string[];
13239
13310
  }) => Record<string, number> | undefined | void;
13311
+ /**
13312
+ * Defines an evaluator. At least one of `scores` or `classifiers` must be provided.
13313
+ */
13240
13314
  interface Evaluator<Input, Output, Expected, Metadata extends BaseMetadata = DefaultMetadataType, Parameters extends EvalParameters = EvalParameters> {
13241
13315
  /**
13242
13316
  * A function that returns a list of inputs, expected outputs, and metadata.
@@ -13247,9 +13321,16 @@ interface Evaluator<Input, Output, Expected, Metadata extends BaseMetadata = Def
13247
13321
  */
13248
13322
  task: EvalTask<Input, Output, Expected, Metadata, Parameters>;
13249
13323
  /**
13250
- * A set of functions that take an input, output, and expected value and return a score.
13324
+ * A set of functions that take an input, output, and expected value and return a {@link Score}.
13325
+ * At least one of `scores` or `classifiers` must be provided.
13326
+ */
13327
+ scores?: EvalScorer<Input, Output, Expected, Metadata>[];
13328
+ /**
13329
+ * A set of functions that take an input, output, and expected value and return a
13330
+ * {@link Classification}. Results are recorded under the `classifications` column.
13331
+ * At least one of `scores` or `classifiers` must be provided.
13251
13332
  */
13252
- scores: EvalScorer<Input, Output, Expected, Metadata>[];
13333
+ classifiers?: EvalClassifier<Input, Output, Expected, Metadata>[];
13253
13334
  /**
13254
13335
  * A set of parameters that will be passed to the evaluator.
13255
13336
  * Can be: