braintrust 2.2.0 → 3.0.0-rc.29

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.
package/README.md CHANGED
@@ -50,3 +50,22 @@ async function main() {
50
50
 
51
51
  main().catch(console.error);
52
52
  ```
53
+
54
+ ### Browser Support
55
+
56
+ **For browser-only applications, use the dedicated browser package:**
57
+
58
+ ```bash
59
+ npm install @braintrust/browser
60
+ ```
61
+
62
+ The `@braintrust/browser` package is optimized for browser environments and includes the `als-browser` polyfill for AsyncLocalStorage support. It's a standalone package with no peer dependencies.
63
+
64
+ **When to use each package:**
65
+
66
+ - **`braintrust`** (this package) - For Node.js applications, full-stack frameworks (Next.js, etc.), and edge runtimes with native AsyncLocalStorage (Cloudflare Workers, Vercel Edge)
67
+ - **`@braintrust/browser`** - For browser-only applications that need AsyncLocalStorage support in standard browsers
68
+
69
+ See the [@braintrust/browser README](../integrations/browser-js/README.md) for more details.
70
+
71
+ **Breaking change in v3.0.0:** The `braintrust/browser` subpath export has been deprecated. Browser users should migrate to the `@braintrust/browser` package.
@@ -8109,6 +8109,12 @@ type ToolFunctionDefinitionType = z.infer<typeof ToolFunctionDefinition>;
8109
8109
 
8110
8110
  type GenericFunction<Input, Output> = ((input: Input) => Output) | ((input: Input) => Promise<Output>);
8111
8111
 
8112
+ interface IsoAsyncLocalStorage<T> {
8113
+ enterWith(store: T): void;
8114
+ run<R>(store: T | undefined, callback: () => R): R;
8115
+ getStore(): T | undefined;
8116
+ }
8117
+
8112
8118
  /**
8113
8119
  * Abstract base class for ID generators
8114
8120
  */
@@ -8129,12 +8135,6 @@ declare abstract class IDGenerator {
8129
8135
 
8130
8136
  type TemplateFormat = "mustache" | "nunjucks" | "none";
8131
8137
 
8132
- interface IsoAsyncLocalStorage<T> {
8133
- enterWith(store: T): void;
8134
- run<R>(store: T | undefined, callback: () => R): R;
8135
- getStore(): T | undefined;
8136
- }
8137
-
8138
8138
  /**
8139
8139
  * Options for configuring an LRUCache instance.
8140
8140
  */
@@ -8438,8 +8438,6 @@ declare class SpanCache {
8438
8438
  dispose(): void;
8439
8439
  }
8440
8440
 
8441
- /// <reference lib="dom" />
8442
-
8443
8441
  interface ContextParentSpanIds {
8444
8442
  rootSpanId: string;
8445
8443
  spanParents: string[];
@@ -8903,7 +8901,8 @@ declare class HTTPBackgroundLogger implements BackgroundLogger {
8903
8901
  private onFlushError?;
8904
8902
  private maskingFunction;
8905
8903
  syncFlush: boolean;
8906
- maxRequestSize: number;
8904
+ private maxRequestSizeOverride;
8905
+ private _maxRequestSizePromise;
8907
8906
  defaultBatchSize: number;
8908
8907
  numTries: number;
8909
8908
  queueDropExceedingMaxsize: number;
@@ -8916,10 +8915,13 @@ declare class HTTPBackgroundLogger implements BackgroundLogger {
8916
8915
  constructor(apiConn: LazyValue<HTTPConnection>, opts?: BackgroundLoggerOpts);
8917
8916
  setMaskingFunction(maskingFunction: ((value: unknown) => unknown) | null): void;
8918
8917
  log(items: LazyValue<BackgroundLogEvent>[]): void;
8918
+ private getMaxRequestSize;
8919
8919
  flush(): Promise<void>;
8920
8920
  private flushOnce;
8921
8921
  private flushWrappedItemsChunk;
8922
8922
  private unwrapLazyValues;
8923
+ private requestLogs3OverflowUpload;
8924
+ private _uploadLogs3OverflowPayload;
8923
8925
  private submitLogsRequest;
8924
8926
  private registerDroppedItemCount;
8925
8927
  private dumpDroppedEvents;
@@ -9426,6 +9428,17 @@ interface SpanData {
9426
9428
  };
9427
9429
  [key: string]: unknown;
9428
9430
  }
9431
+ /**
9432
+ * Options for getThread().
9433
+ */
9434
+ interface GetThreadOptions {
9435
+ /**
9436
+ * The preprocessor to use for extracting the thread.
9437
+ * If not specified, uses the project default preprocessor,
9438
+ * falling back to the global "thread" preprocessor.
9439
+ */
9440
+ preprocessor?: string;
9441
+ }
9429
9442
  /**
9430
9443
  * Interface for trace objects that can be used by scorers.
9431
9444
  * Both the SDK's LocalTrace class and the API wrapper's WrapperTrace implement this.
@@ -9439,6 +9452,13 @@ interface Trace {
9439
9452
  getSpans(options?: {
9440
9453
  spanType?: string[];
9441
9454
  }): Promise<SpanData[]>;
9455
+ /**
9456
+ * Get the thread (preprocessed messages) for this trace.
9457
+ * Uses the project default preprocessor, falling back to the global "thread" preprocessor.
9458
+ * @param options Options for the thread extraction.
9459
+ * @returns The preprocessed thread as an array of messages.
9460
+ */
9461
+ getThread(options?: GetThreadOptions): Promise<unknown[]>;
9442
9462
  }
9443
9463
 
9444
9464
  interface BaseFnOpts {
@@ -12682,6 +12702,10 @@ interface Evaluator<Input, Output, Expected, Metadata extends BaseMetadata = Def
12682
12702
  * Defaults to true.
12683
12703
  */
12684
12704
  summarizeScores?: boolean;
12705
+ /**
12706
+ * Flushes spans before calling scoring functions
12707
+ */
12708
+ flushBeforeScoring?: boolean;
12685
12709
  }
12686
12710
  declare class EvalResultWithSummary<Input, Output, Expected, Metadata extends BaseMetadata = DefaultMetadataType> {
12687
12711
  summary: ExperimentSummary;
@@ -8109,6 +8109,12 @@ type ToolFunctionDefinitionType = z.infer<typeof ToolFunctionDefinition>;
8109
8109
 
8110
8110
  type GenericFunction<Input, Output> = ((input: Input) => Output) | ((input: Input) => Promise<Output>);
8111
8111
 
8112
+ interface IsoAsyncLocalStorage<T> {
8113
+ enterWith(store: T): void;
8114
+ run<R>(store: T | undefined, callback: () => R): R;
8115
+ getStore(): T | undefined;
8116
+ }
8117
+
8112
8118
  /**
8113
8119
  * Abstract base class for ID generators
8114
8120
  */
@@ -8129,12 +8135,6 @@ declare abstract class IDGenerator {
8129
8135
 
8130
8136
  type TemplateFormat = "mustache" | "nunjucks" | "none";
8131
8137
 
8132
- interface IsoAsyncLocalStorage<T> {
8133
- enterWith(store: T): void;
8134
- run<R>(store: T | undefined, callback: () => R): R;
8135
- getStore(): T | undefined;
8136
- }
8137
-
8138
8138
  /**
8139
8139
  * Options for configuring an LRUCache instance.
8140
8140
  */
@@ -8438,8 +8438,6 @@ declare class SpanCache {
8438
8438
  dispose(): void;
8439
8439
  }
8440
8440
 
8441
- /// <reference lib="dom" />
8442
-
8443
8441
  interface ContextParentSpanIds {
8444
8442
  rootSpanId: string;
8445
8443
  spanParents: string[];
@@ -8903,7 +8901,8 @@ declare class HTTPBackgroundLogger implements BackgroundLogger {
8903
8901
  private onFlushError?;
8904
8902
  private maskingFunction;
8905
8903
  syncFlush: boolean;
8906
- maxRequestSize: number;
8904
+ private maxRequestSizeOverride;
8905
+ private _maxRequestSizePromise;
8907
8906
  defaultBatchSize: number;
8908
8907
  numTries: number;
8909
8908
  queueDropExceedingMaxsize: number;
@@ -8916,10 +8915,13 @@ declare class HTTPBackgroundLogger implements BackgroundLogger {
8916
8915
  constructor(apiConn: LazyValue<HTTPConnection>, opts?: BackgroundLoggerOpts);
8917
8916
  setMaskingFunction(maskingFunction: ((value: unknown) => unknown) | null): void;
8918
8917
  log(items: LazyValue<BackgroundLogEvent>[]): void;
8918
+ private getMaxRequestSize;
8919
8919
  flush(): Promise<void>;
8920
8920
  private flushOnce;
8921
8921
  private flushWrappedItemsChunk;
8922
8922
  private unwrapLazyValues;
8923
+ private requestLogs3OverflowUpload;
8924
+ private _uploadLogs3OverflowPayload;
8923
8925
  private submitLogsRequest;
8924
8926
  private registerDroppedItemCount;
8925
8927
  private dumpDroppedEvents;
@@ -9426,6 +9428,17 @@ interface SpanData {
9426
9428
  };
9427
9429
  [key: string]: unknown;
9428
9430
  }
9431
+ /**
9432
+ * Options for getThread().
9433
+ */
9434
+ interface GetThreadOptions {
9435
+ /**
9436
+ * The preprocessor to use for extracting the thread.
9437
+ * If not specified, uses the project default preprocessor,
9438
+ * falling back to the global "thread" preprocessor.
9439
+ */
9440
+ preprocessor?: string;
9441
+ }
9429
9442
  /**
9430
9443
  * Interface for trace objects that can be used by scorers.
9431
9444
  * Both the SDK's LocalTrace class and the API wrapper's WrapperTrace implement this.
@@ -9439,6 +9452,13 @@ interface Trace {
9439
9452
  getSpans(options?: {
9440
9453
  spanType?: string[];
9441
9454
  }): Promise<SpanData[]>;
9455
+ /**
9456
+ * Get the thread (preprocessed messages) for this trace.
9457
+ * Uses the project default preprocessor, falling back to the global "thread" preprocessor.
9458
+ * @param options Options for the thread extraction.
9459
+ * @returns The preprocessed thread as an array of messages.
9460
+ */
9461
+ getThread(options?: GetThreadOptions): Promise<unknown[]>;
9442
9462
  }
9443
9463
 
9444
9464
  interface BaseFnOpts {
@@ -12682,6 +12702,10 @@ interface Evaluator<Input, Output, Expected, Metadata extends BaseMetadata = Def
12682
12702
  * Defaults to true.
12683
12703
  */
12684
12704
  summarizeScores?: boolean;
12705
+ /**
12706
+ * Flushes spans before calling scoring functions
12707
+ */
12708
+ flushBeforeScoring?: boolean;
12685
12709
  }
12686
12710
  declare class EvalResultWithSummary<Input, Output, Expected, Metadata extends BaseMetadata = DefaultMetadataType> {
12687
12711
  summary: ExperimentSummary;