braintrust 3.12.0 → 3.14.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 (55) hide show
  1. package/dev/dist/index.d.mts +31 -14
  2. package/dev/dist/index.d.ts +31 -14
  3. package/dev/dist/index.js +919 -485
  4. package/dev/dist/index.mjs +480 -46
  5. package/dist/apply-auto-instrumentation.js +204 -174
  6. package/dist/apply-auto-instrumentation.mjs +35 -5
  7. package/dist/auto-instrumentations/bundler/esbuild.cjs +226 -1
  8. package/dist/auto-instrumentations/bundler/esbuild.mjs +3 -2
  9. package/dist/auto-instrumentations/bundler/next.cjs +226 -1
  10. package/dist/auto-instrumentations/bundler/next.mjs +4 -3
  11. package/dist/auto-instrumentations/bundler/rollup.cjs +226 -1
  12. package/dist/auto-instrumentations/bundler/rollup.mjs +3 -2
  13. package/dist/auto-instrumentations/bundler/vite.cjs +226 -1
  14. package/dist/auto-instrumentations/bundler/vite.mjs +3 -2
  15. package/dist/auto-instrumentations/bundler/webpack-loader.cjs +9 -0
  16. package/dist/auto-instrumentations/bundler/webpack.cjs +226 -1
  17. package/dist/auto-instrumentations/bundler/webpack.mjs +4 -3
  18. package/dist/auto-instrumentations/{chunk-2DPA74KK.mjs → chunk-E5DUYJWK.mjs} +1 -0
  19. package/dist/auto-instrumentations/chunk-J57YF7WS.mjs +208 -0
  20. package/dist/auto-instrumentations/{chunk-AFXRW7I7.mjs → chunk-OTUQ7KH5.mjs} +1 -1
  21. package/dist/auto-instrumentations/chunk-QFMACSOL.mjs +280 -0
  22. package/dist/auto-instrumentations/{chunk-73BZUKVI.mjs → chunk-XKAAVWT6.mjs} +24 -2
  23. package/dist/auto-instrumentations/hook.mjs +7981 -7
  24. package/dist/auto-instrumentations/index.cjs +1 -0
  25. package/dist/auto-instrumentations/index.mjs +1 -1
  26. package/dist/auto-instrumentations/loader/cjs-patch.cjs +194 -4
  27. package/dist/auto-instrumentations/loader/cjs-patch.mjs +13 -27
  28. package/dist/auto-instrumentations/loader/esm-hook.mjs +24 -10
  29. package/dist/browser.d.mts +274 -30
  30. package/dist/browser.d.ts +274 -30
  31. package/dist/browser.js +407 -48
  32. package/dist/browser.mjs +407 -48
  33. package/dist/{chunk-BW4DF4CY.js → chunk-NKD77KGB.js} +180 -1
  34. package/dist/{chunk-MSLBGITU.mjs → chunk-NU2GSPHX.mjs} +180 -1
  35. package/dist/cli.js +494 -94
  36. package/dist/edge-light.d.mts +1 -1
  37. package/dist/edge-light.d.ts +1 -1
  38. package/dist/edge-light.js +407 -48
  39. package/dist/edge-light.mjs +407 -48
  40. package/dist/index.d.mts +274 -30
  41. package/dist/index.d.ts +274 -30
  42. package/dist/index.js +1267 -857
  43. package/dist/index.mjs +465 -55
  44. package/dist/instrumentation/index.d.mts +47 -11
  45. package/dist/instrumentation/index.d.ts +47 -11
  46. package/dist/instrumentation/index.js +116 -26
  47. package/dist/instrumentation/index.mjs +116 -26
  48. package/dist/workerd.d.mts +1 -1
  49. package/dist/workerd.d.ts +1 -1
  50. package/dist/workerd.js +407 -48
  51. package/dist/workerd.mjs +407 -48
  52. package/package.json +3 -23
  53. package/util/dist/index.d.mts +3 -1
  54. package/util/dist/index.d.ts +3 -1
  55. package/dist/auto-instrumentations/chunk-MWZXZQUO.mjs +0 -81
@@ -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
  } & ({
@@ -8861,17 +8863,15 @@ interface PromptKey {
8861
8863
  id?: string;
8862
8864
  }
8863
8865
  /**
8864
- * A two-layer cache for Braintrust prompts with both in-memory and filesystem storage.
8866
+ * A configurable cache for Braintrust prompts with optional in-memory and filesystem storage.
8865
8867
  *
8866
- * This cache implements either a one or two-layer caching strategy:
8867
- * 1. A fast in-memory LRU cache for frequently accessed prompts.
8868
- * 2. An optional persistent filesystem-based cache that serves as a backing store.
8868
+ * This cache can use either layer independently, both layers together, or no layers.
8869
8869
  */
8870
8870
  declare class PromptCache {
8871
- private readonly memoryCache;
8871
+ private readonly memoryCache?;
8872
8872
  private readonly diskCache?;
8873
8873
  constructor(options: {
8874
- memoryCache: LRUCache<string, Prompt>;
8874
+ memoryCache?: LRUCache<string, Prompt>;
8875
8875
  diskCache?: DiskCache<Prompt>;
8876
8876
  });
8877
8877
  /**
@@ -8898,10 +8898,10 @@ interface ParametersKey {
8898
8898
  id?: string;
8899
8899
  }
8900
8900
  declare class ParametersCache {
8901
- private readonly memoryCache;
8901
+ private readonly memoryCache?;
8902
8902
  private readonly diskCache?;
8903
8903
  constructor(options: {
8904
- memoryCache: LRUCache<string, RemoteEvalParameters>;
8904
+ memoryCache?: LRUCache<string, RemoteEvalParameters>;
8905
8905
  diskCache?: DiskCache<RemoteEvalParameters>;
8906
8906
  });
8907
8907
  get(key: ParametersKey): Promise<RemoteEvalParameters | undefined>;
@@ -8921,9 +8921,15 @@ declare class ParametersCache {
8921
8921
  interface CachedSpan {
8922
8922
  input?: unknown;
8923
8923
  output?: unknown;
8924
+ expected?: unknown;
8925
+ error?: unknown;
8926
+ scores?: Record<string, unknown>;
8927
+ metrics?: Record<string, unknown>;
8924
8928
  metadata?: Record<string, unknown>;
8929
+ tags?: string[];
8925
8930
  span_id: string;
8926
8931
  span_parents?: string[];
8932
+ is_root?: boolean | null;
8927
8933
  span_attributes?: {
8928
8934
  name?: string;
8929
8935
  type?: string;
@@ -11212,6 +11218,13 @@ interface LogOptions<IsAsyncFlush> {
11212
11218
  linkArgs?: LinkArgs;
11213
11219
  }
11214
11220
  type PromiseUnless<B, R> = B extends true ? R : Promise<Awaited<R>>;
11221
+ type DatasetPipelineDeferredJSONAttachmentHook = (data: unknown, options?: {
11222
+ filename?: string;
11223
+ pretty?: boolean;
11224
+ }) => object;
11225
+ declare global {
11226
+ var __BT_DATASET_PIPELINE_DEFER_JSON_ATTACHMENT__: DatasetPipelineDeferredJSONAttachmentHook | undefined;
11227
+ }
11215
11228
  interface ParentSpanIds {
11216
11229
  spanId: string;
11217
11230
  rootSpanId: string;
@@ -11385,7 +11398,7 @@ interface LoginOptions {
11385
11398
  */
11386
11399
  appUrl?: string;
11387
11400
  /**
11388
- * The API key to use. If the parameter is not specified, will try to use the `BRAINTRUST_API_KEY` environment variable.
11401
+ * 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
11402
  */
11390
11403
  apiKey?: string;
11391
11404
  /**
@@ -11660,17 +11673,19 @@ declare class Dataset<IsLegacyDataset extends boolean = typeof DEFAULT_IS_LEGACY
11660
11673
  * about anything else that's relevant, that you can use to help find and analyze examples later. For example, you could log the
11661
11674
  * `prompt`, example's `id`, or anything else that would be useful to slice/dice later. The values in `metadata` can be any
11662
11675
  * JSON-serializable type, but its keys must be strings.
11676
+ * @param event.origin (Optional) a reference to the source object this dataset record was derived from.
11663
11677
  * @param event.id (Optional) a unique identifier for the event. If you don't provide one, Braintrust will generate one for you.
11664
11678
  * @param event.output: (Deprecated) The output of your application. Use `expected` instead.
11665
11679
  * @returns The `id` of the logged record.
11666
11680
  */
11667
- insert({ input, expected, metadata, tags, id, output, }: {
11681
+ insert({ input, expected, metadata, tags, id, output, origin, }: {
11668
11682
  readonly input?: unknown;
11669
11683
  readonly expected?: unknown;
11670
11684
  readonly tags?: string[];
11671
11685
  readonly metadata?: Record<string, unknown>;
11672
11686
  readonly id?: string;
11673
11687
  readonly output?: unknown;
11688
+ readonly origin?: ObjectReferenceType;
11674
11689
  }): string;
11675
11690
  /**
11676
11691
  * Update fields of a single record in the dataset. The updated fields will be batched and uploaded behind the scenes.
@@ -11952,6 +11967,10 @@ interface GetThreadOptions {
11952
11967
  */
11953
11968
  preprocessor?: string;
11954
11969
  }
11970
+ interface GetSpansOptions {
11971
+ spanType?: string[];
11972
+ includeScorers?: boolean;
11973
+ }
11955
11974
  /**
11956
11975
  * Interface for trace objects that can be used by scorers.
11957
11976
  * Both the SDK's LocalTrace class and the API wrapper's WrapperTrace implement this.
@@ -11962,9 +11981,7 @@ interface Trace {
11962
11981
  object_id: string;
11963
11982
  root_span_id: string;
11964
11983
  };
11965
- getSpans(options?: {
11966
- spanType?: string[];
11967
- }): Promise<SpanData[]>;
11984
+ getSpans(options?: GetSpansOptions): Promise<SpanData[]>;
11968
11985
  /**
11969
11986
  * Get the thread (preprocessed messages) for this trace.
11970
11987
  * Uses the project default preprocessor, falling back to the global "thread" preprocessor.
@@ -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
  } & ({
@@ -8861,17 +8863,15 @@ interface PromptKey {
8861
8863
  id?: string;
8862
8864
  }
8863
8865
  /**
8864
- * A two-layer cache for Braintrust prompts with both in-memory and filesystem storage.
8866
+ * A configurable cache for Braintrust prompts with optional in-memory and filesystem storage.
8865
8867
  *
8866
- * This cache implements either a one or two-layer caching strategy:
8867
- * 1. A fast in-memory LRU cache for frequently accessed prompts.
8868
- * 2. An optional persistent filesystem-based cache that serves as a backing store.
8868
+ * This cache can use either layer independently, both layers together, or no layers.
8869
8869
  */
8870
8870
  declare class PromptCache {
8871
- private readonly memoryCache;
8871
+ private readonly memoryCache?;
8872
8872
  private readonly diskCache?;
8873
8873
  constructor(options: {
8874
- memoryCache: LRUCache<string, Prompt>;
8874
+ memoryCache?: LRUCache<string, Prompt>;
8875
8875
  diskCache?: DiskCache<Prompt>;
8876
8876
  });
8877
8877
  /**
@@ -8898,10 +8898,10 @@ interface ParametersKey {
8898
8898
  id?: string;
8899
8899
  }
8900
8900
  declare class ParametersCache {
8901
- private readonly memoryCache;
8901
+ private readonly memoryCache?;
8902
8902
  private readonly diskCache?;
8903
8903
  constructor(options: {
8904
- memoryCache: LRUCache<string, RemoteEvalParameters>;
8904
+ memoryCache?: LRUCache<string, RemoteEvalParameters>;
8905
8905
  diskCache?: DiskCache<RemoteEvalParameters>;
8906
8906
  });
8907
8907
  get(key: ParametersKey): Promise<RemoteEvalParameters | undefined>;
@@ -8921,9 +8921,15 @@ declare class ParametersCache {
8921
8921
  interface CachedSpan {
8922
8922
  input?: unknown;
8923
8923
  output?: unknown;
8924
+ expected?: unknown;
8925
+ error?: unknown;
8926
+ scores?: Record<string, unknown>;
8927
+ metrics?: Record<string, unknown>;
8924
8928
  metadata?: Record<string, unknown>;
8929
+ tags?: string[];
8925
8930
  span_id: string;
8926
8931
  span_parents?: string[];
8932
+ is_root?: boolean | null;
8927
8933
  span_attributes?: {
8928
8934
  name?: string;
8929
8935
  type?: string;
@@ -11212,6 +11218,13 @@ interface LogOptions<IsAsyncFlush> {
11212
11218
  linkArgs?: LinkArgs;
11213
11219
  }
11214
11220
  type PromiseUnless<B, R> = B extends true ? R : Promise<Awaited<R>>;
11221
+ type DatasetPipelineDeferredJSONAttachmentHook = (data: unknown, options?: {
11222
+ filename?: string;
11223
+ pretty?: boolean;
11224
+ }) => object;
11225
+ declare global {
11226
+ var __BT_DATASET_PIPELINE_DEFER_JSON_ATTACHMENT__: DatasetPipelineDeferredJSONAttachmentHook | undefined;
11227
+ }
11215
11228
  interface ParentSpanIds {
11216
11229
  spanId: string;
11217
11230
  rootSpanId: string;
@@ -11385,7 +11398,7 @@ interface LoginOptions {
11385
11398
  */
11386
11399
  appUrl?: string;
11387
11400
  /**
11388
- * The API key to use. If the parameter is not specified, will try to use the `BRAINTRUST_API_KEY` environment variable.
11401
+ * 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
11402
  */
11390
11403
  apiKey?: string;
11391
11404
  /**
@@ -11660,17 +11673,19 @@ declare class Dataset<IsLegacyDataset extends boolean = typeof DEFAULT_IS_LEGACY
11660
11673
  * about anything else that's relevant, that you can use to help find and analyze examples later. For example, you could log the
11661
11674
  * `prompt`, example's `id`, or anything else that would be useful to slice/dice later. The values in `metadata` can be any
11662
11675
  * JSON-serializable type, but its keys must be strings.
11676
+ * @param event.origin (Optional) a reference to the source object this dataset record was derived from.
11663
11677
  * @param event.id (Optional) a unique identifier for the event. If you don't provide one, Braintrust will generate one for you.
11664
11678
  * @param event.output: (Deprecated) The output of your application. Use `expected` instead.
11665
11679
  * @returns The `id` of the logged record.
11666
11680
  */
11667
- insert({ input, expected, metadata, tags, id, output, }: {
11681
+ insert({ input, expected, metadata, tags, id, output, origin, }: {
11668
11682
  readonly input?: unknown;
11669
11683
  readonly expected?: unknown;
11670
11684
  readonly tags?: string[];
11671
11685
  readonly metadata?: Record<string, unknown>;
11672
11686
  readonly id?: string;
11673
11687
  readonly output?: unknown;
11688
+ readonly origin?: ObjectReferenceType;
11674
11689
  }): string;
11675
11690
  /**
11676
11691
  * Update fields of a single record in the dataset. The updated fields will be batched and uploaded behind the scenes.
@@ -11952,6 +11967,10 @@ interface GetThreadOptions {
11952
11967
  */
11953
11968
  preprocessor?: string;
11954
11969
  }
11970
+ interface GetSpansOptions {
11971
+ spanType?: string[];
11972
+ includeScorers?: boolean;
11973
+ }
11955
11974
  /**
11956
11975
  * Interface for trace objects that can be used by scorers.
11957
11976
  * Both the SDK's LocalTrace class and the API wrapper's WrapperTrace implement this.
@@ -11962,9 +11981,7 @@ interface Trace {
11962
11981
  object_id: string;
11963
11982
  root_span_id: string;
11964
11983
  };
11965
- getSpans(options?: {
11966
- spanType?: string[];
11967
- }): Promise<SpanData[]>;
11984
+ getSpans(options?: GetSpansOptions): Promise<SpanData[]>;
11968
11985
  /**
11969
11986
  * Get the thread (preprocessed messages) for this trace.
11970
11987
  * Uses the project default preprocessor, falling back to the global "thread" preprocessor.