braintrust 0.0.166 → 0.0.168

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.
@@ -1,5 +1,5 @@
1
1
  import { LogFeedbackFullArgs, ExperimentEvent, BackgroundLogEvent, ExperimentLogFullArgs, ExperimentLogPartialArgs, IdField, SpanType, SpanComponentsV3, DEFAULT_IS_LEGACY_DATASET, TRANSACTION_ID_FIELD, TransactionId, SpanObjectTypeV3, DatasetRecord } from '@braintrust/core';
2
- import { GitMetadataSettings, RepoInfo, PromptData, OpenAIMessage, Tools, AnyModelParam, Message, Prompt as Prompt$1, PromptSessionEvent, StreamingMode } from '@braintrust/core/typespecs';
2
+ import { GitMetadataSettings, AttachmentReference, RepoInfo, PromptData, OpenAIMessage, Tools, AnyModelParam, Message, Prompt as Prompt$1, PromptSessionEvent, StreamingMode } from '@braintrust/core/typespecs';
3
3
  import { z } from 'zod';
4
4
 
5
5
  interface IsoAsyncLocalStorage<T> {
@@ -34,16 +34,14 @@ type EndSpanArgs = {
34
34
  };
35
35
  interface Exportable {
36
36
  /**
37
- * Return a serialized representation of the object that can be used to start subspans in other places. See `Span.traced` for more details.
37
+ * Return a serialized representation of the object that can be used to start subspans in other places. See {@link Span.traced} for more details.
38
38
  */
39
39
  export(): Promise<string>;
40
40
  }
41
41
  /**
42
42
  * A Span encapsulates logged data and metrics for a unit of work. This interface is shared by all span implementations.
43
43
  *
44
- * We suggest using one of the various `traced` methods, instead of creating Spans directly.
45
- *
46
- * See `Span.traced` for full details.
44
+ * We suggest using one of the various `traced` methods, instead of creating Spans directly. See {@link Span.traced} for full details.
47
45
  */
48
46
  interface Span extends Exportable {
49
47
  /**
@@ -53,13 +51,13 @@ interface Span extends Exportable {
53
51
  /**
54
52
  * Incrementally update the current span with new data. The event will be batched and uploaded behind the scenes.
55
53
  *
56
- * @param event: Data to be logged. See `Experiment.log` for full details.
54
+ * @param event: Data to be logged. See {@link Experiment.log} for full details.
57
55
  */
58
56
  log(event: ExperimentLogPartialArgs): void;
59
57
  /**
60
58
  * Add feedback to the current span. Unlike `Experiment.logFeedback` and `Logger.logFeedback`, this method does not accept an id parameter, because it logs feedback to the current span.
61
59
  *
62
- * @param event: Data to be logged. See `Experiment.logFeedback` for full details.
60
+ * @param event: Data to be logged. See {@link Experiment.logFeedback} for full details.
63
61
  */
64
62
  logFeedback(event: Omit<LogFeedbackFullArgs, "id">): void;
65
63
  /**
@@ -74,8 +72,8 @@ interface Span extends Exportable {
74
72
  * @param args.start_time Optional start time of the span, as a timestamp in seconds.
75
73
  * @param args.setCurrent If true (the default), the span will be marked as the currently-active span for the duration of the callback.
76
74
  * @param args.parent Optional parent info string for the span. The string can be generated from `[Span,Experiment,Logger].export`. If not provided, the current span will be used (depending on context). This is useful for adding spans to an existing trace.
77
- * @param args.event Data to be logged. See `Experiment.log` for full details.
78
- * @Returns The result of running `callback`.
75
+ * @param args.event Data to be logged. See {@link Experiment.log} for full details.
76
+ * @returns The result of running `callback`.
79
77
  */
80
78
  traced<R>(callback: (span: Span) => R, args?: StartSpanArgs & SetCurrentArg): R;
81
79
  /**
@@ -83,7 +81,7 @@ interface Span extends Exportable {
83
81
  * where you cannot use callbacks. However, spans started with `startSpan` will not be marked as the "current span",
84
82
  * so `currentSpan()` and `traced()` will be no-ops. If you want to mark a span as current, use `traced` instead.
85
83
  *
86
- * See `traced` for full details.
84
+ * See {@link Span.traced} for full details.
87
85
  *
88
86
  * @returns The newly-created `Span`
89
87
  */
@@ -97,6 +95,28 @@ interface Span extends Exportable {
97
95
  * @returns The end time logged to the span metrics.
98
96
  */
99
97
  end(args?: EndSpanArgs): number;
98
+ /**
99
+ * Serialize the identifiers of this span. The return value can be used to
100
+ * identify this span when starting a subspan elsewhere, such as another
101
+ * process or service, without needing to access this `Span` object. See the
102
+ * parameters of {@link Span.startSpan} for usage details.
103
+ *
104
+ * Callers should treat the return value as opaque. The serialization format
105
+ * may change from time to time. If parsing is needed, use
106
+ * `SpanComponentsV3.fromStr`.
107
+ *
108
+ * @returns Serialized representation of this span's identifiers.
109
+ */
110
+ export(): Promise<string>;
111
+ /**
112
+ * Format a permalink to the Braintrust application for viewing this span.
113
+ *
114
+ * Links can be generated at any time, but they will only become viewable
115
+ * after the span and its root have been flushed to the server and ingested.
116
+ *
117
+ * @returns A permalink to the span.
118
+ */
119
+ permalink(): Promise<string>;
100
120
  /**
101
121
  * Flush any pending rows to the server.
102
122
  */
@@ -124,6 +144,7 @@ declare class NoopSpan implements Span {
124
144
  startSpan(_1?: StartSpanArgs): this;
125
145
  end(args?: EndSpanArgs): number;
126
146
  export(): Promise<string>;
147
+ permalink(): Promise<string>;
127
148
  flush(): Promise<void>;
128
149
  close(args?: EndSpanArgs): number;
129
150
  setAttributes(_args: Omit<StartSpanArgs, "event">): void;
@@ -211,7 +232,15 @@ declare class BraintrustState {
211
232
  bgLogger(): BackgroundLogger;
212
233
  loginReplaceApiConn(apiConn: HTTPConnection): void;
213
234
  }
235
+ /**
236
+ * This function should be invoked exactly once after configuring the `iso`
237
+ * object based on the platform. See js/src/node.ts for an example.
238
+ * @internal
239
+ */
214
240
  declare function _internalSetInitialState(): void;
241
+ /**
242
+ * @internal
243
+ */
215
244
  declare const _internalGetGlobalState: () => BraintrustState;
216
245
  declare class FailedHTTPResponse extends Error {
217
246
  status: number;
@@ -258,13 +287,72 @@ interface LogOptions<IsAsyncFlush> {
258
287
  computeMetadataArgs?: Record<string, any>;
259
288
  }
260
289
  type PromiseUnless<B, R> = B extends true ? R : Promise<Awaited<R>>;
290
+ interface AttachmentParams {
291
+ data: string | Blob | ArrayBuffer;
292
+ filename: string;
293
+ contentType: string;
294
+ state?: BraintrustState;
295
+ }
296
+ /**
297
+ * Represents an attachment to be uploaded and the associated metadata.
298
+ * `Attachment` objects can be inserted anywhere in an event, allowing you to
299
+ * log arbitrary file data. The SDK will asynchronously upload the file to
300
+ * object storage and replace the `Attachment` object with an
301
+ * `AttachmentReference`.
302
+ */
303
+ declare class Attachment {
304
+ /**
305
+ * The object that replaces this `Attachment` at upload time.
306
+ */
307
+ readonly reference: AttachmentReference;
308
+ private readonly uploader;
309
+ private readonly data;
310
+ private readonly state?;
311
+ private readonly dataDebugString;
312
+ /**
313
+ * Construct an attachment.
314
+ *
315
+ * @param data A string representing the path of the file on disk, or a
316
+ * `Blob`/`ArrayBuffer` with the file's contents. The caller is responsible
317
+ * for ensuring the file/blob/buffer is not modified until upload is complete.
318
+ *
319
+ * @param filename The desired name of the file in Braintrust after uploading.
320
+ * This parameter is for visualization purposes only and has no effect on
321
+ * attachment storage.
322
+ *
323
+ * @param contentType The MIME type of the file.
324
+ *
325
+ * @param state (Optional) For internal use.
326
+ */
327
+ constructor({ data, filename, contentType, state }: AttachmentParams);
328
+ /**
329
+ * On first access, (1) reads the attachment from disk if needed, (2)
330
+ * authenticates with the data plane to request a signed URL, (3) uploads to
331
+ * object store, and (4) updates the attachment.
332
+ *
333
+ * @returns The attachment status.
334
+ */
335
+ upload(): Promise<{
336
+ upload_status: "error" | "done" | "uploading";
337
+ error_message?: string | undefined;
338
+ }>;
339
+ /**
340
+ * A human-readable description for logging and debugging.
341
+ *
342
+ * @returns The debug object. The return type is not stable and may change in
343
+ * a future release.
344
+ */
345
+ debugInfo(): Record<string, unknown>;
346
+ private initUploader;
347
+ private initData;
348
+ }
261
349
  /**
262
350
  * Update a span using the output of `span.export()`. It is important that you only resume updating
263
351
  * to a span once the original span has been fully written and flushed, since otherwise updates to
264
352
  * the span may conflict with the original span.
265
353
  *
266
354
  * @param exported The output of `span.export()`.
267
- * @param event The event data to update the span with. See `Experiment.log` for a full list of valid fields.
355
+ * @param event The event data to update the span with. See {@link Experiment.log} for a full list of valid fields.
268
356
  * @param state (optional) Login state to use. If not provided, the global state will be used.
269
357
  */
270
358
  declare function updateSpan({ exported, state, ...event }: {
@@ -278,6 +366,22 @@ declare function spanComponentsToObjectId({ components, state, }: {
278
366
  components: SpanComponentsV3;
279
367
  state?: BraintrustState;
280
368
  }): Promise<string>;
369
+ /**
370
+ * Format a permalink to the Braintrust application for viewing the span
371
+ * represented by the provided `slug`.
372
+ *
373
+ * Links can be generated at any time, but they will only become viewable after
374
+ * the span and its root have been flushed to the server and ingested.
375
+ *
376
+ * If you have a `Span` object, use {@link Span.permalink} instead.
377
+ *
378
+ * @param slug The identifier generated from {@link Span.export}.
379
+ * @param opts Optional arguments.
380
+ * @param opts.state The login state to use. If not provided, the global state will be used.
381
+ * @param opts.orgName The org name to use. If not provided, the org name will be inferred from the state.
382
+ * @param opts.appUrl The app URL to use. If not provided, the app URL will be inferred from the state.
383
+ * @returns A permalink to the exported span.
384
+ */
281
385
  declare function permalink(slug: string, opts?: {
282
386
  state?: BraintrustState;
283
387
  orgName?: string;
@@ -311,7 +415,7 @@ declare class Logger<IsAsyncFlush extends boolean> implements Exportable {
311
415
  * @param event.id: (Optional) a unique identifier for the event. If you don't provide one, BrainTrust will generate one for you.
312
416
  * @param options Additional logging options
313
417
  * @param options.allowConcurrentWithSpans in rare cases where you need to log at the top level separately from spans on the logger elsewhere, set this to true.
314
- * :returns: The `id` of the logged event.
418
+ * @returns The `id` of the logged event.
315
419
  */
316
420
  log(event: Readonly<StartSpanEventArgs>, options?: {
317
421
  allowConcurrentWithSpans?: boolean;
@@ -319,7 +423,7 @@ declare class Logger<IsAsyncFlush extends boolean> implements Exportable {
319
423
  /**
320
424
  * Create a new toplevel span underneath the logger. The name defaults to "root".
321
425
  *
322
- * See `Span.traced` for full details.
426
+ * See {@link Span.traced} for full details.
323
427
  */
324
428
  traced<R>(callback: (span: Span) => R, args?: StartSpanArgs & SetCurrentArg): PromiseUnless<IsAsyncFlush, R>;
325
429
  /**
@@ -327,7 +431,7 @@ declare class Logger<IsAsyncFlush extends boolean> implements Exportable {
327
431
  * where you cannot use callbacks. However, spans started with `startSpan` will not be marked as the "current span",
328
432
  * so `currentSpan()` and `traced()` will be no-ops. If you want to mark a span as current, use `traced` instead.
329
433
  *
330
- * See `traced` for full details.
434
+ * See {@link traced} for full details.
331
435
  */
332
436
  startSpan(args?: StartSpanArgs): Span;
333
437
  private startSpanImpl;
@@ -347,11 +451,13 @@ declare class Logger<IsAsyncFlush extends boolean> implements Exportable {
347
451
  * Update a span in the experiment using its id. It is important that you only update a span once the original span has been fully written and flushed,
348
452
  * since otherwise updates to the span may conflict with the original span.
349
453
  *
350
- * @param event The event data to update the span with. Must include `id`. See `Experiment.log` for a full list of valid fields.
454
+ * @param event The event data to update the span with. Must include `id`. See {@link Experiment.log} for a full list of valid fields.
351
455
  */
352
456
  updateSpan(event: Omit<Partial<ExperimentEvent>, "id"> & Required<Pick<ExperimentEvent, "id">>): void;
353
457
  /**
354
- * Return a serialized representation of the logger that can be used to start subspans in other places. See `Span.start_span` for more details.
458
+ * Return a serialized representation of the logger that can be used to start subspans in other places.
459
+ *
460
+ * See {@link Span.startSpan} for more details.
355
461
  */
356
462
  export(): Promise<string>;
357
463
  flush(): Promise<void>;
@@ -359,6 +465,7 @@ declare class Logger<IsAsyncFlush extends boolean> implements Exportable {
359
465
  }
360
466
  interface BackgroundLoggerOpts {
361
467
  noExitFlush?: boolean;
468
+ onFlushError?: (error: unknown) => void;
362
469
  }
363
470
  declare class BackgroundLogger {
364
471
  private apiConn;
@@ -366,6 +473,7 @@ declare class BackgroundLogger {
366
473
  private activeFlush;
367
474
  private activeFlushResolved;
368
475
  private activeFlushError;
476
+ private onFlushError?;
369
477
  syncFlush: boolean;
370
478
  maxRequestSize: number;
371
479
  defaultBatchSize: number;
@@ -448,11 +556,11 @@ declare function initExperiment<IsOpen extends boolean = false>(options: Readonl
448
556
  */
449
557
  declare function initExperiment<IsOpen extends boolean = false>(project: string, options?: Readonly<InitOptions<IsOpen>>): InitializedExperiment<IsOpen>;
450
558
  /**
451
- * This function is deprecated. Use `init` instead.
559
+ * @deprecated Use {@link init} instead.
452
560
  */
453
561
  declare function withExperiment<R>(project: string, callback: (experiment: Experiment) => R, options?: Readonly<InitOptions<false> & SetCurrentArg>): R;
454
562
  /**
455
- * This function is deprecated. Use `initLogger` instead.
563
+ * @deprecated Use {@link initLogger} instead.
456
564
  */
457
565
  declare function withLogger<IsAsyncFlush extends boolean = false, R = void>(callback: (logger: Logger<IsAsyncFlush>) => R, options?: Readonly<InitLoggerOptions<IsAsyncFlush> & SetCurrentArg>): R;
458
566
  type UseOutputOption<IsLegacyDataset extends boolean> = {
@@ -487,12 +595,13 @@ type FullInitDatasetOptions<IsLegacyDataset extends boolean> = {
487
595
  declare function initDataset<IsLegacyDataset extends boolean = typeof DEFAULT_IS_LEGACY_DATASET>(options: Readonly<FullInitDatasetOptions<IsLegacyDataset>>): Dataset<IsLegacyDataset>;
488
596
  /**
489
597
  * Legacy form of `initDataset` which accepts the project name as the first
490
- * parameter, separately from the remaining options. See
491
- * `initDataset(options)` for full details.
598
+ * parameter, separately from the remaining options.
599
+ *
600
+ * See `initDataset(options)` for full details.
492
601
  */
493
602
  declare function initDataset<IsLegacyDataset extends boolean = typeof DEFAULT_IS_LEGACY_DATASET>(project: string, options?: Readonly<InitDatasetOptions<IsLegacyDataset>>): Dataset<IsLegacyDataset>;
494
603
  /**
495
- * This function is deprecated. Use `initDataset` instead.
604
+ * @deprecated Use {@link initDataset} instead.
496
605
  */
497
606
  declare function withDataset<R, IsLegacyDataset extends boolean = typeof DEFAULT_IS_LEGACY_DATASET>(project: string, callback: (dataset: Dataset<IsLegacyDataset>) => R, options?: Readonly<InitDatasetOptions<IsLegacyDataset>>): R;
498
607
  type AsyncFlushArg<IsAsyncFlush> = {
@@ -583,6 +692,10 @@ interface LoginOptions {
583
692
  * If true, this event handler will _not_ be installed.
584
693
  */
585
694
  noExitFlush?: boolean;
695
+ /**
696
+ * Calls this function if there's an error in the background flusher.
697
+ */
698
+ onFlushError?: (error: unknown) => void;
586
699
  }
587
700
  type FullLoginOptions = LoginOptions & {
588
701
  forceLogin?: boolean;
@@ -605,7 +718,7 @@ declare function loginToState(options?: LoginOptions): Promise<BraintrustState>;
605
718
  /**
606
719
  * Log a single event to the current experiment. The event will be batched and uploaded behind the scenes.
607
720
  *
608
- * @param event The event to log. See `Experiment.log` for full details.
721
+ * @param event The event to log. See {@link Experiment.log} for full details.
609
722
  * @returns The `id` of the logged event.
610
723
  */
611
724
  declare function log(event: ExperimentLogFullArgs): string;
@@ -625,17 +738,17 @@ type OptionalStateArg = {
625
738
  state?: BraintrustState;
626
739
  };
627
740
  /**
628
- * Returns the currently-active experiment (set by `braintrust.init`). Returns undefined if no current experiment has been set.
741
+ * Returns the currently-active experiment (set by {@link init}). Returns undefined if no current experiment has been set.
629
742
  */
630
743
  declare function currentExperiment(options?: OptionalStateArg): Experiment | undefined;
631
744
  /**
632
- * Returns the currently-active logger (set by `braintrust.initLogger`). Returns undefined if no current logger has been set.
745
+ * Returns the currently-active logger (set by {@link initLogger}). Returns undefined if no current logger has been set.
633
746
  */
634
747
  declare function currentLogger<IsAsyncFlush extends boolean>(options?: AsyncFlushArg<IsAsyncFlush> & OptionalStateArg): Logger<IsAsyncFlush> | undefined;
635
748
  /**
636
749
  * Return the currently-active span for logging (set by one of the `traced` methods). If there is no active span, returns a no-op span object, which supports the same interface as spans but does no logging.
637
750
  *
638
- * See `Span` for full details.
751
+ * See {@link Span} for full details.
639
752
  */
640
753
  declare function currentSpan(options?: OptionalStateArg): Span;
641
754
  /**
@@ -651,7 +764,7 @@ declare function logError(span: Span, error: unknown): void;
651
764
  *
652
765
  * and creates a span under the first one that is active. Alternatively, if `parent` is specified, it creates a span under the specified parent row. If none of these are active, it returns a no-op span object.
653
766
  *
654
- * See `Span.traced` for full details.
767
+ * See {@link Span.traced} for full details.
655
768
  */
656
769
  declare function traced<IsAsyncFlush extends boolean = false, R = void>(callback: (span: Span) => R, args?: StartSpanArgs & SetCurrentArg & AsyncFlushArg<IsAsyncFlush> & OptionalStateArg): PromiseUnless<IsAsyncFlush, R>;
657
770
  /**
@@ -687,7 +800,7 @@ declare const traceable: typeof wrapTraced;
687
800
  * where you cannot use callbacks. However, spans started with `startSpan` will not be marked as the "current span",
688
801
  * so `currentSpan()` and `traced()` will be no-ops. If you want to mark a span as current, use `traced` instead.
689
802
  *
690
- * See `traced` for full details.
803
+ * See {@link traced} for full details.
691
804
  */
692
805
  declare function startSpan<IsAsyncFlush extends boolean = false>(args?: StartSpanArgs & AsyncFlushArg<IsAsyncFlush> & OptionalStateArg): Span;
693
806
  /**
@@ -705,6 +818,20 @@ declare function setFetch(fetch: typeof globalThis.fetch): void;
705
818
  * Runs the provided callback with the span as the current span.
706
819
  */
707
820
  declare function withCurrent<R>(span: Span, callback: (span: Span) => R, state?: BraintrustState): R;
821
+ /**
822
+ * Creates a deep copy of the given event. Replaces references to user objects
823
+ * with placeholder strings to ensure serializability, except for
824
+ * {@link Attachment} objects, which are preserved and not deep-copied.
825
+ */
826
+ declare function deepCopyEvent<T extends Partial<BackgroundLogEvent>>(event: T): T;
827
+ /**
828
+ * Helper function for uploading attachments. Recursively extracts `Attachment`
829
+ * values and replaces them with their associated `AttachmentReference` objects.
830
+ *
831
+ * @param event The event to filter. Will be modified in-place.
832
+ * @param attachments Flat array of extracted attachments (output parameter).
833
+ */
834
+ declare function extractAttachments(event: Record<string, any>, attachments: Attachment[]): void;
708
835
  type WithTransactionId<R> = R & {
709
836
  [TRANSACTION_ID_FIELD]: TransactionId;
710
837
  };
@@ -727,9 +854,11 @@ type DefaultMetadataType = void;
727
854
  type EvalCase<Input, Expected, Metadata> = {
728
855
  input: Input;
729
856
  tags?: string[];
730
- } & (Expected extends void ? {} : {
857
+ id?: string;
858
+ _xact_id?: TransactionId;
859
+ } & (Expected extends void ? object : {
731
860
  expected: Expected;
732
- }) & (Metadata extends void ? {} : {
861
+ }) & (Metadata extends void ? object : {
733
862
  metadata: Metadata;
734
863
  });
735
864
  /**
@@ -771,10 +900,9 @@ declare class Experiment extends ObjectFetcher<ExperimentEvent> implements Expor
771
900
  * @param event.metrics: (Optional) a dictionary of metrics to log. The following keys are populated automatically: "start", "end".
772
901
  * @param event.id: (Optional) a unique identifier for the event. If you don't provide one, BrainTrust will generate one for you.
773
902
  * @param event.dataset_record_id: (Optional) the id of the dataset record that this event is associated with. This field is required if and only if the experiment is associated with a dataset.
774
- * @param event.inputs: (Deprecated) the same as `input` (will be removed in a future version).
775
903
  * @param options Additional logging options
776
904
  * @param options.allowConcurrentWithSpans in rare cases where you need to log at the top level separately from spans on the experiment elsewhere, set this to true.
777
- * :returns: The `id` of the logged event.
905
+ * @returns The `id` of the logged event.
778
906
  */
779
907
  log(event: Readonly<ExperimentLogFullArgs>, options?: {
780
908
  allowConcurrentWithSpans?: boolean;
@@ -782,7 +910,7 @@ declare class Experiment extends ObjectFetcher<ExperimentEvent> implements Expor
782
910
  /**
783
911
  * Create a new toplevel span underneath the experiment. The name defaults to "root".
784
912
  *
785
- * See `Span.traced` for full details.
913
+ * See {@link Span.traced} for full details.
786
914
  */
787
915
  traced<R>(callback: (span: Span) => R, args?: StartSpanArgs & SetCurrentArg): R;
788
916
  /**
@@ -790,7 +918,7 @@ declare class Experiment extends ObjectFetcher<ExperimentEvent> implements Expor
790
918
  * where you cannot use callbacks. However, spans started with `startSpan` will not be marked as the "current span",
791
919
  * so `currentSpan()` and `traced()` will be no-ops. If you want to mark a span as current, use `traced` instead.
792
920
  *
793
- * See `traced` for full details.
921
+ * See {@link traced} for full details.
794
922
  */
795
923
  startSpan(args?: StartSpanArgs): Span;
796
924
  private startSpanImpl;
@@ -826,11 +954,13 @@ declare class Experiment extends ObjectFetcher<ExperimentEvent> implements Expor
826
954
  * Update a span in the experiment using its id. It is important that you only update a span once the original span has been fully written and flushed,
827
955
  * since otherwise updates to the span may conflict with the original span.
828
956
  *
829
- * @param event The event data to update the span with. Must include `id`. See `Experiment.log` for a full list of valid fields.
957
+ * @param event The event data to update the span with. Must include `id`. See {@link Experiment.log} for a full list of valid fields.
830
958
  */
831
959
  updateSpan(event: Omit<Partial<ExperimentEvent>, "id"> & Required<Pick<ExperimentEvent, "id">>): void;
832
960
  /**
833
- * Return a serialized representation of the experiment that can be used to start subspans in other places. See `Span.start_span` for more details.
961
+ * Return a serialized representation of the experiment that can be used to start subspans in other places.
962
+ *
963
+ * See {@link Span.startSpan} for more details.
834
964
  */
835
965
  export(): Promise<string>;
836
966
  /**
@@ -838,7 +968,7 @@ declare class Experiment extends ObjectFetcher<ExperimentEvent> implements Expor
838
968
  */
839
969
  flush(): Promise<void>;
840
970
  /**
841
- * This function is deprecated. You can simply remove it from your code.
971
+ * @deprecated This function is deprecated. You can simply remove it from your code.
842
972
  */
843
973
  close(): Promise<string>;
844
974
  }
@@ -856,9 +986,9 @@ declare class ReadonlyExperiment extends ObjectFetcher<ExperimentEvent> {
856
986
  }
857
987
  declare function newId(): string;
858
988
  /**
859
- * Primary implementation of the `Span` interface. See the `Span` interface for full details on each method.
989
+ * Primary implementation of the `Span` interface. See {@link Span} for full details on each method.
860
990
  *
861
- * We suggest using one of the various `traced` methods, instead of creating Spans directly. See `Span.startSpan` for full details.
991
+ * We suggest using one of the various `traced` methods, instead of creating Spans directly. See {@link Span.startSpan} for full details.
862
992
  */
863
993
  declare class SpanImpl implements Span {
864
994
  private state;
@@ -890,6 +1020,7 @@ declare class SpanImpl implements Span {
890
1020
  startSpan(args?: StartSpanArgs): Span;
891
1021
  end(args?: EndSpanArgs): number;
892
1022
  export(): Promise<string>;
1023
+ permalink(): Promise<string>;
893
1024
  flush(): Promise<void>;
894
1025
  close(args?: EndSpanArgs): number;
895
1026
  }
@@ -969,7 +1100,7 @@ declare class Dataset<IsLegacyDataset extends boolean = typeof DEFAULT_IS_LEGACY
969
1100
  */
970
1101
  flush(): Promise<void>;
971
1102
  /**
972
- * This function is deprecated. You can simply remove it from your code.
1103
+ * @deprecated This function is deprecated. You can simply remove it from your code.
973
1104
  */
974
1105
  close(): Promise<string>;
975
1106
  }
@@ -1108,6 +1239,14 @@ interface DatasetSummary {
1108
1239
  datasetUrl: string;
1109
1240
  dataSummary: DataSummary;
1110
1241
  }
1242
+ /**
1243
+ * Allows accessing helper functions for testing.
1244
+ * @internal
1245
+ */
1246
+ declare const _exportsForTestingOnly: {
1247
+ extractAttachments: typeof extractAttachments;
1248
+ deepCopyEvent: typeof deepCopyEvent;
1249
+ };
1111
1250
 
1112
1251
  declare const braintrustStreamChunkSchema: z.ZodUnion<[z.ZodObject<{
1113
1252
  type: z.ZodLiteral<"text_delta">;
@@ -1411,6 +1550,9 @@ declare const X_CACHED_HEADER = "x-bt-cached";
1411
1550
  declare function parseCachedHeader(value: string | null | undefined): number | undefined;
1412
1551
 
1413
1552
  type braintrust_AnyDataset = AnyDataset;
1553
+ type braintrust_Attachment = Attachment;
1554
+ declare const braintrust_Attachment: typeof Attachment;
1555
+ type braintrust_AttachmentParams = AttachmentParams;
1414
1556
  type braintrust_BackgroundLoggerOpts = BackgroundLoggerOpts;
1415
1557
  type braintrust_BaseMetadata = BaseMetadata;
1416
1558
  type braintrust_BraintrustState = BraintrustState;
@@ -1466,6 +1608,7 @@ declare const braintrust_SpanImpl: typeof SpanImpl;
1466
1608
  type braintrust_StartSpanArgs = StartSpanArgs;
1467
1609
  type braintrust_WithTransactionId<R> = WithTransactionId<R>;
1468
1610
  declare const braintrust_X_CACHED_HEADER: typeof X_CACHED_HEADER;
1611
+ declare const braintrust__exportsForTestingOnly: typeof _exportsForTestingOnly;
1469
1612
  declare const braintrust__internalGetGlobalState: typeof _internalGetGlobalState;
1470
1613
  declare const braintrust__internalSetInitialState: typeof _internalSetInitialState;
1471
1614
  declare const braintrust_braintrustStreamChunkSchema: typeof braintrustStreamChunkSchema;
@@ -1505,7 +1648,7 @@ declare const braintrust_wrapOpenAI: typeof wrapOpenAI;
1505
1648
  declare const braintrust_wrapOpenAIv4: typeof wrapOpenAIv4;
1506
1649
  declare const braintrust_wrapTraced: typeof wrapTraced;
1507
1650
  declare namespace braintrust {
1508
- export { type braintrust_AnyDataset as AnyDataset, type braintrust_BackgroundLoggerOpts as BackgroundLoggerOpts, type braintrust_BaseMetadata as BaseMetadata, braintrust_BraintrustState as BraintrustState, braintrust_BraintrustStream as BraintrustStream, type braintrust_BraintrustStreamChunk as BraintrustStreamChunk, type braintrust_ChatPrompt as ChatPrompt, type braintrust_CompiledPrompt as CompiledPrompt, type braintrust_CompiledPromptParams as CompiledPromptParams, type braintrust_CompletionPrompt as CompletionPrompt, type braintrust_DataSummary as DataSummary, braintrust_Dataset as Dataset, type braintrust_DatasetSummary as DatasetSummary, type braintrust_DefaultMetadataType as DefaultMetadataType, type braintrust_DefaultPromptArgs as DefaultPromptArgs, type braintrust_EndSpanArgs as EndSpanArgs, type braintrust_EvalCase as EvalCase, braintrust_Experiment as Experiment, type braintrust_ExperimentSummary as ExperimentSummary, type braintrust_Exportable as Exportable, braintrust_FailedHTTPResponse as FailedHTTPResponse, type braintrust_FullInitOptions as FullInitOptions, type braintrust_FullLoginOptions as FullLoginOptions, type braintrust_InitOptions as InitOptions, type braintrust_InvokeFunctionArgs as InvokeFunctionArgs, type braintrust_InvokeReturn as InvokeReturn, braintrust_LEGACY_CACHED_HEADER as LEGACY_CACHED_HEADER, type braintrust_LogOptions as LogOptions, braintrust_Logger as Logger, type braintrust_LoginOptions as LoginOptions, type braintrust_MetricSummary as MetricSummary, braintrust_NOOP_SPAN as NOOP_SPAN, braintrust_NoopSpan as NoopSpan, type braintrust_ObjectMetadata as ObjectMetadata, type braintrust_PromiseUnless as PromiseUnless, braintrust_Prompt as Prompt, type braintrust_PromptRowWithId as PromptRowWithId, braintrust_ReadonlyExperiment as ReadonlyExperiment, type braintrust_ScoreSummary as ScoreSummary, type braintrust_SerializedBraintrustState as SerializedBraintrustState, type braintrust_SetCurrentArg as SetCurrentArg, type braintrust_Span as Span, braintrust_SpanImpl as SpanImpl, type braintrust_StartSpanArgs as StartSpanArgs, type braintrust_WithTransactionId as WithTransactionId, braintrust_X_CACHED_HEADER as X_CACHED_HEADER, braintrust__internalGetGlobalState as _internalGetGlobalState, braintrust__internalSetInitialState as _internalSetInitialState, braintrust_braintrustStreamChunkSchema as braintrustStreamChunkSchema, braintrust_createFinalValuePassThroughStream as createFinalValuePassThroughStream, braintrust_currentExperiment as currentExperiment, braintrust_currentLogger as currentLogger, braintrust_currentSpan as currentSpan, braintrust_devNullWritableStream as devNullWritableStream, braintrust_flush as flush, braintrust_getSpanParentObject as getSpanParentObject, braintrust_init as init, braintrust_initDataset as initDataset, braintrust_initExperiment as initExperiment, braintrust_initLogger as initLogger, braintrust_invoke as invoke, braintrust_loadPrompt as loadPrompt, braintrust_log as log, braintrust_logError as logError, braintrust_login as login, braintrust_loginToState as loginToState, braintrust_newId as newId, braintrust_parseCachedHeader as parseCachedHeader, braintrust_permalink as permalink, braintrust_renderMessage as renderMessage, braintrust_setFetch as setFetch, braintrust_spanComponentsToObjectId as spanComponentsToObjectId, braintrust_startSpan as startSpan, braintrust_summarize as summarize, braintrust_traceable as traceable, braintrust_traced as traced, braintrust_updateSpan as updateSpan, braintrust_withCurrent as withCurrent, braintrust_withDataset as withDataset, braintrust_withExperiment as withExperiment, braintrust_withLogger as withLogger, braintrust_wrapOpenAI as wrapOpenAI, braintrust_wrapOpenAIv4 as wrapOpenAIv4, braintrust_wrapTraced as wrapTraced };
1651
+ export { type braintrust_AnyDataset as AnyDataset, braintrust_Attachment as Attachment, type braintrust_AttachmentParams as AttachmentParams, type braintrust_BackgroundLoggerOpts as BackgroundLoggerOpts, type braintrust_BaseMetadata as BaseMetadata, braintrust_BraintrustState as BraintrustState, braintrust_BraintrustStream as BraintrustStream, type braintrust_BraintrustStreamChunk as BraintrustStreamChunk, type braintrust_ChatPrompt as ChatPrompt, type braintrust_CompiledPrompt as CompiledPrompt, type braintrust_CompiledPromptParams as CompiledPromptParams, type braintrust_CompletionPrompt as CompletionPrompt, type braintrust_DataSummary as DataSummary, braintrust_Dataset as Dataset, type braintrust_DatasetSummary as DatasetSummary, type braintrust_DefaultMetadataType as DefaultMetadataType, type braintrust_DefaultPromptArgs as DefaultPromptArgs, type braintrust_EndSpanArgs as EndSpanArgs, type braintrust_EvalCase as EvalCase, braintrust_Experiment as Experiment, type braintrust_ExperimentSummary as ExperimentSummary, type braintrust_Exportable as Exportable, braintrust_FailedHTTPResponse as FailedHTTPResponse, type braintrust_FullInitOptions as FullInitOptions, type braintrust_FullLoginOptions as FullLoginOptions, type braintrust_InitOptions as InitOptions, type braintrust_InvokeFunctionArgs as InvokeFunctionArgs, type braintrust_InvokeReturn as InvokeReturn, braintrust_LEGACY_CACHED_HEADER as LEGACY_CACHED_HEADER, type braintrust_LogOptions as LogOptions, braintrust_Logger as Logger, type braintrust_LoginOptions as LoginOptions, type braintrust_MetricSummary as MetricSummary, braintrust_NOOP_SPAN as NOOP_SPAN, braintrust_NoopSpan as NoopSpan, type braintrust_ObjectMetadata as ObjectMetadata, type braintrust_PromiseUnless as PromiseUnless, braintrust_Prompt as Prompt, type braintrust_PromptRowWithId as PromptRowWithId, braintrust_ReadonlyExperiment as ReadonlyExperiment, type braintrust_ScoreSummary as ScoreSummary, type braintrust_SerializedBraintrustState as SerializedBraintrustState, type braintrust_SetCurrentArg as SetCurrentArg, type braintrust_Span as Span, braintrust_SpanImpl as SpanImpl, type braintrust_StartSpanArgs as StartSpanArgs, type braintrust_WithTransactionId as WithTransactionId, braintrust_X_CACHED_HEADER as X_CACHED_HEADER, braintrust__exportsForTestingOnly as _exportsForTestingOnly, braintrust__internalGetGlobalState as _internalGetGlobalState, braintrust__internalSetInitialState as _internalSetInitialState, braintrust_braintrustStreamChunkSchema as braintrustStreamChunkSchema, braintrust_createFinalValuePassThroughStream as createFinalValuePassThroughStream, braintrust_currentExperiment as currentExperiment, braintrust_currentLogger as currentLogger, braintrust_currentSpan as currentSpan, braintrust_devNullWritableStream as devNullWritableStream, braintrust_flush as flush, braintrust_getSpanParentObject as getSpanParentObject, braintrust_init as init, braintrust_initDataset as initDataset, braintrust_initExperiment as initExperiment, braintrust_initLogger as initLogger, braintrust_invoke as invoke, braintrust_loadPrompt as loadPrompt, braintrust_log as log, braintrust_logError as logError, braintrust_login as login, braintrust_loginToState as loginToState, braintrust_newId as newId, braintrust_parseCachedHeader as parseCachedHeader, braintrust_permalink as permalink, braintrust_renderMessage as renderMessage, braintrust_setFetch as setFetch, braintrust_spanComponentsToObjectId as spanComponentsToObjectId, braintrust_startSpan as startSpan, braintrust_summarize as summarize, braintrust_traceable as traceable, braintrust_traced as traced, braintrust_updateSpan as updateSpan, braintrust_withCurrent as withCurrent, braintrust_withDataset as withDataset, braintrust_withExperiment as withExperiment, braintrust_withLogger as withLogger, braintrust_wrapOpenAI as wrapOpenAI, braintrust_wrapOpenAIv4 as wrapOpenAIv4, braintrust_wrapTraced as wrapTraced };
1509
1652
  }
1510
1653
 
1511
- export { type AnyDataset, type BackgroundLoggerOpts, type BaseMetadata, BraintrustState, BraintrustStream, type BraintrustStreamChunk, type ChatPrompt, type CompiledPrompt, type CompiledPromptParams, type CompletionPrompt, type DataSummary, Dataset, type DatasetSummary, type DefaultMetadataType, type DefaultPromptArgs, type EndSpanArgs, type EvalCase, Experiment, type ExperimentSummary, type Exportable, FailedHTTPResponse, type FullInitOptions, type FullLoginOptions, type InitOptions, type InvokeFunctionArgs, type InvokeReturn, LEGACY_CACHED_HEADER, type LogOptions, Logger, type LoginOptions, type MetricSummary, NOOP_SPAN, NoopSpan, type ObjectMetadata, type PromiseUnless, Prompt, type PromptRowWithId, ReadonlyExperiment, type ScoreSummary, type SerializedBraintrustState, type SetCurrentArg, type Span, SpanImpl, type StartSpanArgs, type WithTransactionId, X_CACHED_HEADER, _internalGetGlobalState, _internalSetInitialState, braintrustStreamChunkSchema, createFinalValuePassThroughStream, currentExperiment, currentLogger, currentSpan, braintrust as default, devNullWritableStream, flush, getSpanParentObject, init, initDataset, initExperiment, initLogger, invoke, loadPrompt, log, logError, login, loginToState, newId, parseCachedHeader, permalink, renderMessage, setFetch, spanComponentsToObjectId, startSpan, summarize, traceable, traced, updateSpan, withCurrent, withDataset, withExperiment, withLogger, wrapOpenAI, wrapOpenAIv4, wrapTraced };
1654
+ export { type AnyDataset, Attachment, type AttachmentParams, type BackgroundLoggerOpts, type BaseMetadata, BraintrustState, BraintrustStream, type BraintrustStreamChunk, type ChatPrompt, type CompiledPrompt, type CompiledPromptParams, type CompletionPrompt, type DataSummary, Dataset, type DatasetSummary, type DefaultMetadataType, type DefaultPromptArgs, type EndSpanArgs, type EvalCase, Experiment, type ExperimentSummary, type Exportable, FailedHTTPResponse, type FullInitOptions, type FullLoginOptions, type InitOptions, type InvokeFunctionArgs, type InvokeReturn, LEGACY_CACHED_HEADER, type LogOptions, Logger, type LoginOptions, type MetricSummary, NOOP_SPAN, NoopSpan, type ObjectMetadata, type PromiseUnless, Prompt, type PromptRowWithId, ReadonlyExperiment, type ScoreSummary, type SerializedBraintrustState, type SetCurrentArg, type Span, SpanImpl, type StartSpanArgs, type WithTransactionId, X_CACHED_HEADER, _exportsForTestingOnly, _internalGetGlobalState, _internalSetInitialState, braintrustStreamChunkSchema, createFinalValuePassThroughStream, currentExperiment, currentLogger, currentSpan, braintrust as default, devNullWritableStream, flush, getSpanParentObject, init, initDataset, initExperiment, initLogger, invoke, loadPrompt, log, logError, login, loginToState, newId, parseCachedHeader, permalink, renderMessage, setFetch, spanComponentsToObjectId, startSpan, summarize, traceable, traced, updateSpan, withCurrent, withDataset, withExperiment, withLogger, wrapOpenAI, wrapOpenAIv4, wrapTraced };