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
package/README.md CHANGED
@@ -61,40 +61,40 @@ Use a bundler plugin:
61
61
  Vite:
62
62
 
63
63
  ```ts
64
- import { vitePlugin } from "braintrust/vite";
64
+ import { braintrustVitePlugin } from "braintrust/vite";
65
65
 
66
66
  export default {
67
- plugins: [vitePlugin()],
67
+ plugins: [braintrustVitePlugin()],
68
68
  };
69
69
  ```
70
70
 
71
71
  Webpack:
72
72
 
73
73
  ```js
74
- const { webpackPlugin } = require("braintrust/webpack");
74
+ const { braintrustWebpackPlugin } = require("braintrust/webpack");
75
75
 
76
76
  module.exports = {
77
- plugins: [webpackPlugin()],
77
+ plugins: [braintrustWebpackPlugin()],
78
78
  };
79
79
  ```
80
80
 
81
81
  esbuild:
82
82
 
83
83
  ```ts
84
- import { esbuildPlugin } from "braintrust/esbuild";
84
+ import { braintrustEsbuildPlugin } from "braintrust/esbuild";
85
85
 
86
86
  await esbuild.build({
87
- plugins: [esbuildPlugin()],
87
+ plugins: [braintrustEsbuildPlugin()],
88
88
  });
89
89
  ```
90
90
 
91
91
  Rollup:
92
92
 
93
93
  ```ts
94
- import { rollupPlugin } from "braintrust/rollup";
94
+ import { braintrustRollupPlugin } from "braintrust/rollup";
95
95
 
96
96
  export default {
97
- plugins: [rollupPlugin()],
97
+ plugins: [braintrustRollupPlugin()],
98
98
  };
99
99
  ```
100
100
 
@@ -118,6 +118,7 @@ declare const ObjectReference$1: z.ZodObject<{
118
118
  created?: string | null | undefined;
119
119
  _xact_id?: string | null | undefined;
120
120
  }>;
121
+ type ObjectReferenceType$1 = z.infer<typeof ObjectReference$1>;
121
122
 
122
123
  type IdField = {
123
124
  id: string;
@@ -138,7 +139,7 @@ type OtherExperimentLogFields = {
138
139
  metadata: Record<string, unknown>;
139
140
  metrics: Record<string, unknown>;
140
141
  datasetRecordId: string;
141
- origin: z.infer<typeof ObjectReference$1>;
142
+ origin: ObjectReferenceType$1;
142
143
  span_attributes: Record<string, unknown>;
143
144
  [ASYNC_SCORING_CONTROL_FIELD]: AsyncScoringControlType;
144
145
  [MERGE_PATHS_FIELD]: string[][];
@@ -180,6 +181,7 @@ type DatasetEvent = {
180
181
  tags?: string[];
181
182
  metadata?: unknown;
182
183
  created?: string;
184
+ origin?: ObjectReferenceType$1;
183
185
  id: string;
184
186
  dataset_id: string;
185
187
  } & ({
@@ -8921,9 +8923,15 @@ declare class ParametersCache {
8921
8923
  interface CachedSpan {
8922
8924
  input?: unknown;
8923
8925
  output?: unknown;
8926
+ expected?: unknown;
8927
+ error?: unknown;
8928
+ scores?: Record<string, unknown>;
8929
+ metrics?: Record<string, unknown>;
8924
8930
  metadata?: Record<string, unknown>;
8931
+ tags?: string[];
8925
8932
  span_id: string;
8926
8933
  span_parents?: string[];
8934
+ is_root?: boolean | null;
8927
8935
  span_attributes?: {
8928
8936
  name?: string;
8929
8937
  type?: string;
@@ -11212,6 +11220,13 @@ interface LogOptions<IsAsyncFlush> {
11212
11220
  linkArgs?: LinkArgs;
11213
11221
  }
11214
11222
  type PromiseUnless<B, R> = B extends true ? R : Promise<Awaited<R>>;
11223
+ type DatasetPipelineDeferredJSONAttachmentHook = (data: unknown, options?: {
11224
+ filename?: string;
11225
+ pretty?: boolean;
11226
+ }) => object;
11227
+ declare global {
11228
+ var __BT_DATASET_PIPELINE_DEFER_JSON_ATTACHMENT__: DatasetPipelineDeferredJSONAttachmentHook | undefined;
11229
+ }
11215
11230
  interface ParentSpanIds {
11216
11231
  spanId: string;
11217
11232
  rootSpanId: string;
@@ -11385,7 +11400,7 @@ interface LoginOptions {
11385
11400
  */
11386
11401
  appUrl?: string;
11387
11402
  /**
11388
- * The API key to use. If the parameter is not specified, will try to use the `BRAINTRUST_API_KEY` environment variable.
11403
+ * The API key to use. If the parameter is not specified, will try to use the `BRAINTRUST_API_KEY` environment variable. In Node.js, if that is unset, will try the nearest `.env.braintrust` file in the current working directory or parent directories.
11389
11404
  */
11390
11405
  apiKey?: string;
11391
11406
  /**
@@ -11660,17 +11675,19 @@ declare class Dataset<IsLegacyDataset extends boolean = typeof DEFAULT_IS_LEGACY
11660
11675
  * about anything else that's relevant, that you can use to help find and analyze examples later. For example, you could log the
11661
11676
  * `prompt`, example's `id`, or anything else that would be useful to slice/dice later. The values in `metadata` can be any
11662
11677
  * JSON-serializable type, but its keys must be strings.
11678
+ * @param event.origin (Optional) a reference to the source object this dataset record was derived from.
11663
11679
  * @param event.id (Optional) a unique identifier for the event. If you don't provide one, Braintrust will generate one for you.
11664
11680
  * @param event.output: (Deprecated) The output of your application. Use `expected` instead.
11665
11681
  * @returns The `id` of the logged record.
11666
11682
  */
11667
- insert({ input, expected, metadata, tags, id, output, }: {
11683
+ insert({ input, expected, metadata, tags, id, output, origin, }: {
11668
11684
  readonly input?: unknown;
11669
11685
  readonly expected?: unknown;
11670
11686
  readonly tags?: string[];
11671
11687
  readonly metadata?: Record<string, unknown>;
11672
11688
  readonly id?: string;
11673
11689
  readonly output?: unknown;
11690
+ readonly origin?: ObjectReferenceType;
11674
11691
  }): string;
11675
11692
  /**
11676
11693
  * Update fields of a single record in the dataset. The updated fields will be batched and uploaded behind the scenes.
@@ -11952,6 +11969,10 @@ interface GetThreadOptions {
11952
11969
  */
11953
11970
  preprocessor?: string;
11954
11971
  }
11972
+ interface GetSpansOptions {
11973
+ spanType?: string[];
11974
+ includeScorers?: boolean;
11975
+ }
11955
11976
  /**
11956
11977
  * Interface for trace objects that can be used by scorers.
11957
11978
  * Both the SDK's LocalTrace class and the API wrapper's WrapperTrace implement this.
@@ -11962,9 +11983,7 @@ interface Trace {
11962
11983
  object_id: string;
11963
11984
  root_span_id: string;
11964
11985
  };
11965
- getSpans(options?: {
11966
- spanType?: string[];
11967
- }): Promise<SpanData[]>;
11986
+ getSpans(options?: GetSpansOptions): Promise<SpanData[]>;
11968
11987
  /**
11969
11988
  * Get the thread (preprocessed messages) for this trace.
11970
11989
  * Uses the project default preprocessor, falling back to the global "thread" preprocessor.
@@ -13557,7 +13576,7 @@ interface Evaluator<Input, Output, Expected, Metadata extends BaseMetadata = Def
13557
13576
  */
13558
13577
  baseExperimentId?: string;
13559
13578
  /**
13560
- * Optional settings for collecting git metadata. By default, will collect all git metadata fields allowed in org-level settings.
13579
+ * Optional settings for collecting git metadata. By default, Braintrust collects the git metadata fields allowed by your organization's git metadata settings. If those settings are absent, git metadata is not collected unless this option is set.
13561
13580
  */
13562
13581
  gitMetadataSettings?: GitMetadataSettingsType;
13563
13582
  /**
@@ -118,6 +118,7 @@ declare const ObjectReference$1: z.ZodObject<{
118
118
  created?: string | null | undefined;
119
119
  _xact_id?: string | null | undefined;
120
120
  }>;
121
+ type ObjectReferenceType$1 = z.infer<typeof ObjectReference$1>;
121
122
 
122
123
  type IdField = {
123
124
  id: string;
@@ -138,7 +139,7 @@ type OtherExperimentLogFields = {
138
139
  metadata: Record<string, unknown>;
139
140
  metrics: Record<string, unknown>;
140
141
  datasetRecordId: string;
141
- origin: z.infer<typeof ObjectReference$1>;
142
+ origin: ObjectReferenceType$1;
142
143
  span_attributes: Record<string, unknown>;
143
144
  [ASYNC_SCORING_CONTROL_FIELD]: AsyncScoringControlType;
144
145
  [MERGE_PATHS_FIELD]: string[][];
@@ -180,6 +181,7 @@ type DatasetEvent = {
180
181
  tags?: string[];
181
182
  metadata?: unknown;
182
183
  created?: string;
184
+ origin?: ObjectReferenceType$1;
183
185
  id: string;
184
186
  dataset_id: string;
185
187
  } & ({
@@ -8921,9 +8923,15 @@ declare class ParametersCache {
8921
8923
  interface CachedSpan {
8922
8924
  input?: unknown;
8923
8925
  output?: unknown;
8926
+ expected?: unknown;
8927
+ error?: unknown;
8928
+ scores?: Record<string, unknown>;
8929
+ metrics?: Record<string, unknown>;
8924
8930
  metadata?: Record<string, unknown>;
8931
+ tags?: string[];
8925
8932
  span_id: string;
8926
8933
  span_parents?: string[];
8934
+ is_root?: boolean | null;
8927
8935
  span_attributes?: {
8928
8936
  name?: string;
8929
8937
  type?: string;
@@ -11212,6 +11220,13 @@ interface LogOptions<IsAsyncFlush> {
11212
11220
  linkArgs?: LinkArgs;
11213
11221
  }
11214
11222
  type PromiseUnless<B, R> = B extends true ? R : Promise<Awaited<R>>;
11223
+ type DatasetPipelineDeferredJSONAttachmentHook = (data: unknown, options?: {
11224
+ filename?: string;
11225
+ pretty?: boolean;
11226
+ }) => object;
11227
+ declare global {
11228
+ var __BT_DATASET_PIPELINE_DEFER_JSON_ATTACHMENT__: DatasetPipelineDeferredJSONAttachmentHook | undefined;
11229
+ }
11215
11230
  interface ParentSpanIds {
11216
11231
  spanId: string;
11217
11232
  rootSpanId: string;
@@ -11385,7 +11400,7 @@ interface LoginOptions {
11385
11400
  */
11386
11401
  appUrl?: string;
11387
11402
  /**
11388
- * The API key to use. If the parameter is not specified, will try to use the `BRAINTRUST_API_KEY` environment variable.
11403
+ * The API key to use. If the parameter is not specified, will try to use the `BRAINTRUST_API_KEY` environment variable. In Node.js, if that is unset, will try the nearest `.env.braintrust` file in the current working directory or parent directories.
11389
11404
  */
11390
11405
  apiKey?: string;
11391
11406
  /**
@@ -11660,17 +11675,19 @@ declare class Dataset<IsLegacyDataset extends boolean = typeof DEFAULT_IS_LEGACY
11660
11675
  * about anything else that's relevant, that you can use to help find and analyze examples later. For example, you could log the
11661
11676
  * `prompt`, example's `id`, or anything else that would be useful to slice/dice later. The values in `metadata` can be any
11662
11677
  * JSON-serializable type, but its keys must be strings.
11678
+ * @param event.origin (Optional) a reference to the source object this dataset record was derived from.
11663
11679
  * @param event.id (Optional) a unique identifier for the event. If you don't provide one, Braintrust will generate one for you.
11664
11680
  * @param event.output: (Deprecated) The output of your application. Use `expected` instead.
11665
11681
  * @returns The `id` of the logged record.
11666
11682
  */
11667
- insert({ input, expected, metadata, tags, id, output, }: {
11683
+ insert({ input, expected, metadata, tags, id, output, origin, }: {
11668
11684
  readonly input?: unknown;
11669
11685
  readonly expected?: unknown;
11670
11686
  readonly tags?: string[];
11671
11687
  readonly metadata?: Record<string, unknown>;
11672
11688
  readonly id?: string;
11673
11689
  readonly output?: unknown;
11690
+ readonly origin?: ObjectReferenceType;
11674
11691
  }): string;
11675
11692
  /**
11676
11693
  * Update fields of a single record in the dataset. The updated fields will be batched and uploaded behind the scenes.
@@ -11952,6 +11969,10 @@ interface GetThreadOptions {
11952
11969
  */
11953
11970
  preprocessor?: string;
11954
11971
  }
11972
+ interface GetSpansOptions {
11973
+ spanType?: string[];
11974
+ includeScorers?: boolean;
11975
+ }
11955
11976
  /**
11956
11977
  * Interface for trace objects that can be used by scorers.
11957
11978
  * Both the SDK's LocalTrace class and the API wrapper's WrapperTrace implement this.
@@ -11962,9 +11983,7 @@ interface Trace {
11962
11983
  object_id: string;
11963
11984
  root_span_id: string;
11964
11985
  };
11965
- getSpans(options?: {
11966
- spanType?: string[];
11967
- }): Promise<SpanData[]>;
11986
+ getSpans(options?: GetSpansOptions): Promise<SpanData[]>;
11968
11987
  /**
11969
11988
  * Get the thread (preprocessed messages) for this trace.
11970
11989
  * Uses the project default preprocessor, falling back to the global "thread" preprocessor.
@@ -13557,7 +13576,7 @@ interface Evaluator<Input, Output, Expected, Metadata extends BaseMetadata = Def
13557
13576
  */
13558
13577
  baseExperimentId?: string;
13559
13578
  /**
13560
- * Optional settings for collecting git metadata. By default, will collect all git metadata fields allowed in org-level settings.
13579
+ * Optional settings for collecting git metadata. By default, Braintrust collects the git metadata fields allowed by your organization's git metadata settings. If those settings are absent, git metadata is not collected unless this option is set.
13561
13580
  */
13562
13581
  gitMetadataSettings?: GitMetadataSettingsType;
13563
13582
  /**