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.
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
- import { LogFeedbackFullArgs, ExperimentEvent, BackgroundLogEvent, ExperimentLogFullArgs, ExperimentLogPartialArgs, IdField, SpanType, SpanComponentsV3, DEFAULT_IS_LEGACY_DATASET, TRANSACTION_ID_FIELD, TransactionId, SpanObjectTypeV3, DatasetRecord, Score, CommentEvent, InputField, InputsField, LogCommentFullArgs, OtherExperimentLogFields, ParentExperimentIds, ParentProjectLogIds } from '@braintrust/core';
2
- export { CommentEvent, DatasetRecord, ExperimentLogFullArgs, ExperimentLogPartialArgs, IdField, InputField, InputsField, LogCommentFullArgs, LogFeedbackFullArgs, OtherExperimentLogFields, ParentExperimentIds, ParentProjectLogIds } from '@braintrust/core';
3
- import { GitMetadataSettings, RepoInfo, PromptData, OpenAIMessage, Tools, AnyModelParam, Message, Prompt as Prompt$1, PromptSessionEvent, StreamingMode, FunctionType, IfExists, SavedFunctionId, ModelParams } from '@braintrust/core/typespecs';
1
+ import { LogFeedbackFullArgs, ExperimentEvent, BackgroundLogEvent, ExperimentLogFullArgs, ExperimentLogPartialArgs, IdField, SpanType, SpanComponentsV3, DEFAULT_IS_LEGACY_DATASET, TRANSACTION_ID_FIELD, TransactionId, SpanObjectTypeV3, DatasetRecord, Score, CommentEvent, InputField, LogCommentFullArgs, OtherExperimentLogFields, ParentExperimentIds, ParentProjectLogIds } from '@braintrust/core';
2
+ export { CommentEvent, DatasetRecord, ExperimentLogFullArgs, ExperimentLogPartialArgs, IdField, InputField, LogCommentFullArgs, LogFeedbackFullArgs, OtherExperimentLogFields, ParentExperimentIds, ParentProjectLogIds } from '@braintrust/core';
3
+ import { GitMetadataSettings, AttachmentReference, RepoInfo, PromptData, OpenAIMessage, Tools, AnyModelParam, Message, Prompt as Prompt$1, PromptSessionEvent, StreamingMode, FunctionType, IfExists, SavedFunctionId, ModelParams } from '@braintrust/core/typespecs';
4
4
  import { z } from 'zod';
5
5
 
6
6
  interface IsoAsyncLocalStorage<T> {
@@ -35,16 +35,14 @@ type EndSpanArgs = {
35
35
  };
36
36
  interface Exportable {
37
37
  /**
38
- * Return a serialized representation of the object that can be used to start subspans in other places. See `Span.traced` for more details.
38
+ * Return a serialized representation of the object that can be used to start subspans in other places. See {@link Span.traced} for more details.
39
39
  */
40
40
  export(): Promise<string>;
41
41
  }
42
42
  /**
43
43
  * A Span encapsulates logged data and metrics for a unit of work. This interface is shared by all span implementations.
44
44
  *
45
- * We suggest using one of the various `traced` methods, instead of creating Spans directly.
46
- *
47
- * See `Span.traced` for full details.
45
+ * We suggest using one of the various `traced` methods, instead of creating Spans directly. See {@link Span.traced} for full details.
48
46
  */
49
47
  interface Span extends Exportable {
50
48
  /**
@@ -54,13 +52,13 @@ interface Span extends Exportable {
54
52
  /**
55
53
  * Incrementally update the current span with new data. The event will be batched and uploaded behind the scenes.
56
54
  *
57
- * @param event: Data to be logged. See `Experiment.log` for full details.
55
+ * @param event: Data to be logged. See {@link Experiment.log} for full details.
58
56
  */
59
57
  log(event: ExperimentLogPartialArgs): void;
60
58
  /**
61
59
  * 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.
62
60
  *
63
- * @param event: Data to be logged. See `Experiment.logFeedback` for full details.
61
+ * @param event: Data to be logged. See {@link Experiment.logFeedback} for full details.
64
62
  */
65
63
  logFeedback(event: Omit<LogFeedbackFullArgs, "id">): void;
66
64
  /**
@@ -75,8 +73,8 @@ interface Span extends Exportable {
75
73
  * @param args.start_time Optional start time of the span, as a timestamp in seconds.
76
74
  * @param args.setCurrent If true (the default), the span will be marked as the currently-active span for the duration of the callback.
77
75
  * @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.
78
- * @param args.event Data to be logged. See `Experiment.log` for full details.
79
- * @Returns The result of running `callback`.
76
+ * @param args.event Data to be logged. See {@link Experiment.log} for full details.
77
+ * @returns The result of running `callback`.
80
78
  */
81
79
  traced<R>(callback: (span: Span) => R, args?: StartSpanArgs & SetCurrentArg): R;
82
80
  /**
@@ -84,7 +82,7 @@ interface Span extends Exportable {
84
82
  * where you cannot use callbacks. However, spans started with `startSpan` will not be marked as the "current span",
85
83
  * so `currentSpan()` and `traced()` will be no-ops. If you want to mark a span as current, use `traced` instead.
86
84
  *
87
- * See `traced` for full details.
85
+ * See {@link Span.traced} for full details.
88
86
  *
89
87
  * @returns The newly-created `Span`
90
88
  */
@@ -98,6 +96,28 @@ interface Span extends Exportable {
98
96
  * @returns The end time logged to the span metrics.
99
97
  */
100
98
  end(args?: EndSpanArgs): number;
99
+ /**
100
+ * Serialize the identifiers of this span. The return value can be used to
101
+ * identify this span when starting a subspan elsewhere, such as another
102
+ * process or service, without needing to access this `Span` object. See the
103
+ * parameters of {@link Span.startSpan} for usage details.
104
+ *
105
+ * Callers should treat the return value as opaque. The serialization format
106
+ * may change from time to time. If parsing is needed, use
107
+ * `SpanComponentsV3.fromStr`.
108
+ *
109
+ * @returns Serialized representation of this span's identifiers.
110
+ */
111
+ export(): Promise<string>;
112
+ /**
113
+ * Format a permalink to the Braintrust application for viewing this span.
114
+ *
115
+ * Links can be generated at any time, but they will only become viewable
116
+ * after the span and its root have been flushed to the server and ingested.
117
+ *
118
+ * @returns A permalink to the span.
119
+ */
120
+ permalink(): Promise<string>;
101
121
  /**
102
122
  * Flush any pending rows to the server.
103
123
  */
@@ -125,6 +145,7 @@ declare class NoopSpan implements Span {
125
145
  startSpan(_1?: StartSpanArgs): this;
126
146
  end(args?: EndSpanArgs): number;
127
147
  export(): Promise<string>;
148
+ permalink(): Promise<string>;
128
149
  flush(): Promise<void>;
129
150
  close(args?: EndSpanArgs): number;
130
151
  setAttributes(_args: Omit<StartSpanArgs, "event">): void;
@@ -212,7 +233,15 @@ declare class BraintrustState {
212
233
  bgLogger(): BackgroundLogger;
213
234
  loginReplaceApiConn(apiConn: HTTPConnection): void;
214
235
  }
236
+ /**
237
+ * This function should be invoked exactly once after configuring the `iso`
238
+ * object based on the platform. See js/src/node.ts for an example.
239
+ * @internal
240
+ */
215
241
  declare function _internalSetInitialState(): void;
242
+ /**
243
+ * @internal
244
+ */
216
245
  declare const _internalGetGlobalState: () => BraintrustState;
217
246
  declare class FailedHTTPResponse extends Error {
218
247
  status: number;
@@ -259,13 +288,72 @@ interface LogOptions<IsAsyncFlush> {
259
288
  computeMetadataArgs?: Record<string, any>;
260
289
  }
261
290
  type PromiseUnless<B, R> = B extends true ? R : Promise<Awaited<R>>;
291
+ interface AttachmentParams {
292
+ data: string | Blob | ArrayBuffer;
293
+ filename: string;
294
+ contentType: string;
295
+ state?: BraintrustState;
296
+ }
297
+ /**
298
+ * Represents an attachment to be uploaded and the associated metadata.
299
+ * `Attachment` objects can be inserted anywhere in an event, allowing you to
300
+ * log arbitrary file data. The SDK will asynchronously upload the file to
301
+ * object storage and replace the `Attachment` object with an
302
+ * `AttachmentReference`.
303
+ */
304
+ declare class Attachment {
305
+ /**
306
+ * The object that replaces this `Attachment` at upload time.
307
+ */
308
+ readonly reference: AttachmentReference;
309
+ private readonly uploader;
310
+ private readonly data;
311
+ private readonly state?;
312
+ private readonly dataDebugString;
313
+ /**
314
+ * Construct an attachment.
315
+ *
316
+ * @param data A string representing the path of the file on disk, or a
317
+ * `Blob`/`ArrayBuffer` with the file's contents. The caller is responsible
318
+ * for ensuring the file/blob/buffer is not modified until upload is complete.
319
+ *
320
+ * @param filename The desired name of the file in Braintrust after uploading.
321
+ * This parameter is for visualization purposes only and has no effect on
322
+ * attachment storage.
323
+ *
324
+ * @param contentType The MIME type of the file.
325
+ *
326
+ * @param state (Optional) For internal use.
327
+ */
328
+ constructor({ data, filename, contentType, state }: AttachmentParams);
329
+ /**
330
+ * On first access, (1) reads the attachment from disk if needed, (2)
331
+ * authenticates with the data plane to request a signed URL, (3) uploads to
332
+ * object store, and (4) updates the attachment.
333
+ *
334
+ * @returns The attachment status.
335
+ */
336
+ upload(): Promise<{
337
+ upload_status: "error" | "done" | "uploading";
338
+ error_message?: string | undefined;
339
+ }>;
340
+ /**
341
+ * A human-readable description for logging and debugging.
342
+ *
343
+ * @returns The debug object. The return type is not stable and may change in
344
+ * a future release.
345
+ */
346
+ debugInfo(): Record<string, unknown>;
347
+ private initUploader;
348
+ private initData;
349
+ }
262
350
  /**
263
351
  * Update a span using the output of `span.export()`. It is important that you only resume updating
264
352
  * to a span once the original span has been fully written and flushed, since otherwise updates to
265
353
  * the span may conflict with the original span.
266
354
  *
267
355
  * @param exported The output of `span.export()`.
268
- * @param event The event data to update the span with. See `Experiment.log` for a full list of valid fields.
356
+ * @param event The event data to update the span with. See {@link Experiment.log} for a full list of valid fields.
269
357
  * @param state (optional) Login state to use. If not provided, the global state will be used.
270
358
  */
271
359
  declare function updateSpan({ exported, state, ...event }: {
@@ -279,6 +367,22 @@ declare function spanComponentsToObjectId({ components, state, }: {
279
367
  components: SpanComponentsV3;
280
368
  state?: BraintrustState;
281
369
  }): Promise<string>;
370
+ /**
371
+ * Format a permalink to the Braintrust application for viewing the span
372
+ * represented by the provided `slug`.
373
+ *
374
+ * Links can be generated at any time, but they will only become viewable after
375
+ * the span and its root have been flushed to the server and ingested.
376
+ *
377
+ * If you have a `Span` object, use {@link Span.permalink} instead.
378
+ *
379
+ * @param slug The identifier generated from {@link Span.export}.
380
+ * @param opts Optional arguments.
381
+ * @param opts.state The login state to use. If not provided, the global state will be used.
382
+ * @param opts.orgName The org name to use. If not provided, the org name will be inferred from the state.
383
+ * @param opts.appUrl The app URL to use. If not provided, the app URL will be inferred from the state.
384
+ * @returns A permalink to the exported span.
385
+ */
282
386
  declare function permalink(slug: string, opts?: {
283
387
  state?: BraintrustState;
284
388
  orgName?: string;
@@ -312,7 +416,7 @@ declare class Logger<IsAsyncFlush extends boolean> implements Exportable {
312
416
  * @param event.id: (Optional) a unique identifier for the event. If you don't provide one, BrainTrust will generate one for you.
313
417
  * @param options Additional logging options
314
418
  * @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.
315
- * :returns: The `id` of the logged event.
419
+ * @returns The `id` of the logged event.
316
420
  */
317
421
  log(event: Readonly<StartSpanEventArgs>, options?: {
318
422
  allowConcurrentWithSpans?: boolean;
@@ -320,7 +424,7 @@ declare class Logger<IsAsyncFlush extends boolean> implements Exportable {
320
424
  /**
321
425
  * Create a new toplevel span underneath the logger. The name defaults to "root".
322
426
  *
323
- * See `Span.traced` for full details.
427
+ * See {@link Span.traced} for full details.
324
428
  */
325
429
  traced<R>(callback: (span: Span) => R, args?: StartSpanArgs & SetCurrentArg): PromiseUnless<IsAsyncFlush, R>;
326
430
  /**
@@ -328,7 +432,7 @@ declare class Logger<IsAsyncFlush extends boolean> implements Exportable {
328
432
  * where you cannot use callbacks. However, spans started with `startSpan` will not be marked as the "current span",
329
433
  * so `currentSpan()` and `traced()` will be no-ops. If you want to mark a span as current, use `traced` instead.
330
434
  *
331
- * See `traced` for full details.
435
+ * See {@link traced} for full details.
332
436
  */
333
437
  startSpan(args?: StartSpanArgs): Span;
334
438
  private startSpanImpl;
@@ -348,11 +452,13 @@ declare class Logger<IsAsyncFlush extends boolean> implements Exportable {
348
452
  * 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,
349
453
  * since otherwise updates to the span may conflict with the original span.
350
454
  *
351
- * @param event The event data to update the span with. Must include `id`. See `Experiment.log` for a full list of valid fields.
455
+ * @param event The event data to update the span with. Must include `id`. See {@link Experiment.log} for a full list of valid fields.
352
456
  */
353
457
  updateSpan(event: Omit<Partial<ExperimentEvent>, "id"> & Required<Pick<ExperimentEvent, "id">>): void;
354
458
  /**
355
- * Return a serialized representation of the logger that can be used to start subspans in other places. See `Span.start_span` for more details.
459
+ * Return a serialized representation of the logger that can be used to start subspans in other places.
460
+ *
461
+ * See {@link Span.startSpan} for more details.
356
462
  */
357
463
  export(): Promise<string>;
358
464
  flush(): Promise<void>;
@@ -360,6 +466,7 @@ declare class Logger<IsAsyncFlush extends boolean> implements Exportable {
360
466
  }
361
467
  interface BackgroundLoggerOpts {
362
468
  noExitFlush?: boolean;
469
+ onFlushError?: (error: unknown) => void;
363
470
  }
364
471
  declare class BackgroundLogger {
365
472
  private apiConn;
@@ -367,6 +474,7 @@ declare class BackgroundLogger {
367
474
  private activeFlush;
368
475
  private activeFlushResolved;
369
476
  private activeFlushError;
477
+ private onFlushError?;
370
478
  syncFlush: boolean;
371
479
  maxRequestSize: number;
372
480
  defaultBatchSize: number;
@@ -449,11 +557,11 @@ declare function initExperiment<IsOpen extends boolean = false>(options: Readonl
449
557
  */
450
558
  declare function initExperiment<IsOpen extends boolean = false>(project: string, options?: Readonly<InitOptions<IsOpen>>): InitializedExperiment<IsOpen>;
451
559
  /**
452
- * This function is deprecated. Use `init` instead.
560
+ * @deprecated Use {@link init} instead.
453
561
  */
454
562
  declare function withExperiment<R>(project: string, callback: (experiment: Experiment) => R, options?: Readonly<InitOptions<false> & SetCurrentArg>): R;
455
563
  /**
456
- * This function is deprecated. Use `initLogger` instead.
564
+ * @deprecated Use {@link initLogger} instead.
457
565
  */
458
566
  declare function withLogger<IsAsyncFlush extends boolean = false, R = void>(callback: (logger: Logger<IsAsyncFlush>) => R, options?: Readonly<InitLoggerOptions<IsAsyncFlush> & SetCurrentArg>): R;
459
567
  type UseOutputOption<IsLegacyDataset extends boolean> = {
@@ -488,12 +596,13 @@ type FullInitDatasetOptions<IsLegacyDataset extends boolean> = {
488
596
  declare function initDataset<IsLegacyDataset extends boolean = typeof DEFAULT_IS_LEGACY_DATASET>(options: Readonly<FullInitDatasetOptions<IsLegacyDataset>>): Dataset<IsLegacyDataset>;
489
597
  /**
490
598
  * Legacy form of `initDataset` which accepts the project name as the first
491
- * parameter, separately from the remaining options. See
492
- * `initDataset(options)` for full details.
599
+ * parameter, separately from the remaining options.
600
+ *
601
+ * See `initDataset(options)` for full details.
493
602
  */
494
603
  declare function initDataset<IsLegacyDataset extends boolean = typeof DEFAULT_IS_LEGACY_DATASET>(project: string, options?: Readonly<InitDatasetOptions<IsLegacyDataset>>): Dataset<IsLegacyDataset>;
495
604
  /**
496
- * This function is deprecated. Use `initDataset` instead.
605
+ * @deprecated Use {@link initDataset} instead.
497
606
  */
498
607
  declare function withDataset<R, IsLegacyDataset extends boolean = typeof DEFAULT_IS_LEGACY_DATASET>(project: string, callback: (dataset: Dataset<IsLegacyDataset>) => R, options?: Readonly<InitDatasetOptions<IsLegacyDataset>>): R;
499
608
  type AsyncFlushArg<IsAsyncFlush> = {
@@ -584,6 +693,10 @@ interface LoginOptions {
584
693
  * If true, this event handler will _not_ be installed.
585
694
  */
586
695
  noExitFlush?: boolean;
696
+ /**
697
+ * Calls this function if there's an error in the background flusher.
698
+ */
699
+ onFlushError?: (error: unknown) => void;
587
700
  }
588
701
  type FullLoginOptions = LoginOptions & {
589
702
  forceLogin?: boolean;
@@ -606,7 +719,7 @@ declare function loginToState(options?: LoginOptions): Promise<BraintrustState>;
606
719
  /**
607
720
  * Log a single event to the current experiment. The event will be batched and uploaded behind the scenes.
608
721
  *
609
- * @param event The event to log. See `Experiment.log` for full details.
722
+ * @param event The event to log. See {@link Experiment.log} for full details.
610
723
  * @returns The `id` of the logged event.
611
724
  */
612
725
  declare function log(event: ExperimentLogFullArgs): string;
@@ -626,17 +739,17 @@ type OptionalStateArg = {
626
739
  state?: BraintrustState;
627
740
  };
628
741
  /**
629
- * Returns the currently-active experiment (set by `braintrust.init`). Returns undefined if no current experiment has been set.
742
+ * Returns the currently-active experiment (set by {@link init}). Returns undefined if no current experiment has been set.
630
743
  */
631
744
  declare function currentExperiment(options?: OptionalStateArg): Experiment | undefined;
632
745
  /**
633
- * Returns the currently-active logger (set by `braintrust.initLogger`). Returns undefined if no current logger has been set.
746
+ * Returns the currently-active logger (set by {@link initLogger}). Returns undefined if no current logger has been set.
634
747
  */
635
748
  declare function currentLogger<IsAsyncFlush extends boolean>(options?: AsyncFlushArg<IsAsyncFlush> & OptionalStateArg): Logger<IsAsyncFlush> | undefined;
636
749
  /**
637
750
  * 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.
638
751
  *
639
- * See `Span` for full details.
752
+ * See {@link Span} for full details.
640
753
  */
641
754
  declare function currentSpan(options?: OptionalStateArg): Span;
642
755
  /**
@@ -652,7 +765,7 @@ declare function logError(span: Span, error: unknown): void;
652
765
  *
653
766
  * 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.
654
767
  *
655
- * See `Span.traced` for full details.
768
+ * See {@link Span.traced} for full details.
656
769
  */
657
770
  declare function traced<IsAsyncFlush extends boolean = false, R = void>(callback: (span: Span) => R, args?: StartSpanArgs & SetCurrentArg & AsyncFlushArg<IsAsyncFlush> & OptionalStateArg): PromiseUnless<IsAsyncFlush, R>;
658
771
  /**
@@ -688,7 +801,7 @@ declare const traceable: typeof wrapTraced;
688
801
  * where you cannot use callbacks. However, spans started with `startSpan` will not be marked as the "current span",
689
802
  * so `currentSpan()` and `traced()` will be no-ops. If you want to mark a span as current, use `traced` instead.
690
803
  *
691
- * See `traced` for full details.
804
+ * See {@link traced} for full details.
692
805
  */
693
806
  declare function startSpan<IsAsyncFlush extends boolean = false>(args?: StartSpanArgs & AsyncFlushArg<IsAsyncFlush> & OptionalStateArg): Span;
694
807
  /**
@@ -706,6 +819,20 @@ declare function setFetch(fetch: typeof globalThis.fetch): void;
706
819
  * Runs the provided callback with the span as the current span.
707
820
  */
708
821
  declare function withCurrent<R>(span: Span, callback: (span: Span) => R, state?: BraintrustState): R;
822
+ /**
823
+ * Creates a deep copy of the given event. Replaces references to user objects
824
+ * with placeholder strings to ensure serializability, except for
825
+ * {@link Attachment} objects, which are preserved and not deep-copied.
826
+ */
827
+ declare function deepCopyEvent<T extends Partial<BackgroundLogEvent>>(event: T): T;
828
+ /**
829
+ * Helper function for uploading attachments. Recursively extracts `Attachment`
830
+ * values and replaces them with their associated `AttachmentReference` objects.
831
+ *
832
+ * @param event The event to filter. Will be modified in-place.
833
+ * @param attachments Flat array of extracted attachments (output parameter).
834
+ */
835
+ declare function extractAttachments(event: Record<string, any>, attachments: Attachment[]): void;
709
836
  type WithTransactionId<R> = R & {
710
837
  [TRANSACTION_ID_FIELD]: TransactionId;
711
838
  };
@@ -728,9 +855,11 @@ type DefaultMetadataType = void;
728
855
  type EvalCase<Input, Expected, Metadata> = {
729
856
  input: Input;
730
857
  tags?: string[];
731
- } & (Expected extends void ? {} : {
858
+ id?: string;
859
+ _xact_id?: TransactionId;
860
+ } & (Expected extends void ? object : {
732
861
  expected: Expected;
733
- }) & (Metadata extends void ? {} : {
862
+ }) & (Metadata extends void ? object : {
734
863
  metadata: Metadata;
735
864
  });
736
865
  /**
@@ -772,10 +901,9 @@ declare class Experiment extends ObjectFetcher<ExperimentEvent> implements Expor
772
901
  * @param event.metrics: (Optional) a dictionary of metrics to log. The following keys are populated automatically: "start", "end".
773
902
  * @param event.id: (Optional) a unique identifier for the event. If you don't provide one, BrainTrust will generate one for you.
774
903
  * @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.
775
- * @param event.inputs: (Deprecated) the same as `input` (will be removed in a future version).
776
904
  * @param options Additional logging options
777
905
  * @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.
778
- * :returns: The `id` of the logged event.
906
+ * @returns The `id` of the logged event.
779
907
  */
780
908
  log(event: Readonly<ExperimentLogFullArgs>, options?: {
781
909
  allowConcurrentWithSpans?: boolean;
@@ -783,7 +911,7 @@ declare class Experiment extends ObjectFetcher<ExperimentEvent> implements Expor
783
911
  /**
784
912
  * Create a new toplevel span underneath the experiment. The name defaults to "root".
785
913
  *
786
- * See `Span.traced` for full details.
914
+ * See {@link Span.traced} for full details.
787
915
  */
788
916
  traced<R>(callback: (span: Span) => R, args?: StartSpanArgs & SetCurrentArg): R;
789
917
  /**
@@ -791,7 +919,7 @@ declare class Experiment extends ObjectFetcher<ExperimentEvent> implements Expor
791
919
  * where you cannot use callbacks. However, spans started with `startSpan` will not be marked as the "current span",
792
920
  * so `currentSpan()` and `traced()` will be no-ops. If you want to mark a span as current, use `traced` instead.
793
921
  *
794
- * See `traced` for full details.
922
+ * See {@link traced} for full details.
795
923
  */
796
924
  startSpan(args?: StartSpanArgs): Span;
797
925
  private startSpanImpl;
@@ -827,11 +955,13 @@ declare class Experiment extends ObjectFetcher<ExperimentEvent> implements Expor
827
955
  * 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,
828
956
  * since otherwise updates to the span may conflict with the original span.
829
957
  *
830
- * @param event The event data to update the span with. Must include `id`. See `Experiment.log` for a full list of valid fields.
958
+ * @param event The event data to update the span with. Must include `id`. See {@link Experiment.log} for a full list of valid fields.
831
959
  */
832
960
  updateSpan(event: Omit<Partial<ExperimentEvent>, "id"> & Required<Pick<ExperimentEvent, "id">>): void;
833
961
  /**
834
- * Return a serialized representation of the experiment that can be used to start subspans in other places. See `Span.start_span` for more details.
962
+ * Return a serialized representation of the experiment that can be used to start subspans in other places.
963
+ *
964
+ * See {@link Span.startSpan} for more details.
835
965
  */
836
966
  export(): Promise<string>;
837
967
  /**
@@ -839,7 +969,7 @@ declare class Experiment extends ObjectFetcher<ExperimentEvent> implements Expor
839
969
  */
840
970
  flush(): Promise<void>;
841
971
  /**
842
- * This function is deprecated. You can simply remove it from your code.
972
+ * @deprecated This function is deprecated. You can simply remove it from your code.
843
973
  */
844
974
  close(): Promise<string>;
845
975
  }
@@ -857,9 +987,9 @@ declare class ReadonlyExperiment extends ObjectFetcher<ExperimentEvent> {
857
987
  }
858
988
  declare function newId(): string;
859
989
  /**
860
- * Primary implementation of the `Span` interface. See the `Span` interface for full details on each method.
990
+ * Primary implementation of the `Span` interface. See {@link Span} for full details on each method.
861
991
  *
862
- * We suggest using one of the various `traced` methods, instead of creating Spans directly. See `Span.startSpan` for full details.
992
+ * We suggest using one of the various `traced` methods, instead of creating Spans directly. See {@link Span.startSpan} for full details.
863
993
  */
864
994
  declare class SpanImpl implements Span {
865
995
  private state;
@@ -891,6 +1021,7 @@ declare class SpanImpl implements Span {
891
1021
  startSpan(args?: StartSpanArgs): Span;
892
1022
  end(args?: EndSpanArgs): number;
893
1023
  export(): Promise<string>;
1024
+ permalink(): Promise<string>;
894
1025
  flush(): Promise<void>;
895
1026
  close(args?: EndSpanArgs): number;
896
1027
  }
@@ -970,7 +1101,7 @@ declare class Dataset<IsLegacyDataset extends boolean = typeof DEFAULT_IS_LEGACY
970
1101
  */
971
1102
  flush(): Promise<void>;
972
1103
  /**
973
- * This function is deprecated. You can simply remove it from your code.
1104
+ * @deprecated This function is deprecated. You can simply remove it from your code.
974
1105
  */
975
1106
  close(): Promise<string>;
976
1107
  }
@@ -1109,6 +1240,14 @@ interface DatasetSummary {
1109
1240
  datasetUrl: string;
1110
1241
  dataSummary: DataSummary;
1111
1242
  }
1243
+ /**
1244
+ * Allows accessing helper functions for testing.
1245
+ * @internal
1246
+ */
1247
+ declare const _exportsForTestingOnly: {
1248
+ extractAttachments: typeof extractAttachments;
1249
+ deepCopyEvent: typeof deepCopyEvent;
1250
+ };
1112
1251
 
1113
1252
  declare const braintrustStreamChunkSchema: z.ZodUnion<[z.ZodObject<{
1114
1253
  type: z.ZodLiteral<"text_delta">;
@@ -1731,6 +1870,9 @@ declare function parseCachedHeader(value: string | null | undefined): number | u
1731
1870
  declare function wrapAISDKModel<T extends object>(model: T): T;
1732
1871
 
1733
1872
  type braintrust_AnyDataset = AnyDataset;
1873
+ type braintrust_Attachment = Attachment;
1874
+ declare const braintrust_Attachment: typeof Attachment;
1875
+ type braintrust_AttachmentParams = AttachmentParams;
1734
1876
  type braintrust_BackgroundLoggerOpts = BackgroundLoggerOpts;
1735
1877
  declare const braintrust_BaseExperiment: typeof BaseExperiment;
1736
1878
  type braintrust_BaseMetadata = BaseMetadata;
@@ -1779,7 +1921,6 @@ type braintrust_FullLoginOptions = FullLoginOptions;
1779
1921
  declare const braintrust_IdField: typeof IdField;
1780
1922
  type braintrust_InitOptions<IsOpen extends boolean> = InitOptions<IsOpen>;
1781
1923
  declare const braintrust_InputField: typeof InputField;
1782
- declare const braintrust_InputsField: typeof InputsField;
1783
1924
  type braintrust_InvokeFunctionArgs<Input, Output, Stream extends boolean = false> = InvokeFunctionArgs<Input, Output, Stream>;
1784
1925
  type braintrust_InvokeReturn<Stream extends boolean, Output> = InvokeReturn<Stream, Output>;
1785
1926
  declare const braintrust_LEGACY_CACHED_HEADER: typeof LEGACY_CACHED_HEADER;
@@ -1826,6 +1967,7 @@ type braintrust_ToolFunctionDefinition = ToolFunctionDefinition;
1826
1967
  type braintrust_ToolOpts<Params, Returns, Fn extends GenericFunction<Params, Returns>> = ToolOpts<Params, Returns, Fn>;
1827
1968
  type braintrust_WithTransactionId<R> = WithTransactionId<R>;
1828
1969
  declare const braintrust_X_CACHED_HEADER: typeof X_CACHED_HEADER;
1970
+ declare const braintrust__exportsForTestingOnly: typeof _exportsForTestingOnly;
1829
1971
  declare const braintrust__internalGetGlobalState: typeof _internalGetGlobalState;
1830
1972
  declare const braintrust__internalSetInitialState: typeof _internalSetInitialState;
1831
1973
  declare const braintrust_braintrustStreamChunkSchema: typeof braintrustStreamChunkSchema;
@@ -1870,7 +2012,7 @@ declare const braintrust_wrapOpenAI: typeof wrapOpenAI;
1870
2012
  declare const braintrust_wrapOpenAIv4: typeof wrapOpenAIv4;
1871
2013
  declare const braintrust_wrapTraced: typeof wrapTraced;
1872
2014
  declare namespace braintrust {
1873
- export { type braintrust_AnyDataset as AnyDataset, type braintrust_BackgroundLoggerOpts as BackgroundLoggerOpts, braintrust_BaseExperiment as BaseExperiment, type braintrust_BaseMetadata as BaseMetadata, braintrust_BraintrustState as BraintrustState, braintrust_BraintrustStream as BraintrustStream, type braintrust_BraintrustStreamChunk as BraintrustStreamChunk, type braintrust_ChatPrompt as ChatPrompt, braintrust_CodeFunction as CodeFunction, braintrust_CodePrompt as CodePrompt, braintrust_CommentEvent as CommentEvent, type braintrust_CompiledPrompt as CompiledPrompt, type braintrust_CompiledPromptParams as CompiledPromptParams, type braintrust_CompletionPrompt as CompletionPrompt, type braintrust_CreateProjectOpts as CreateProjectOpts, type braintrust_DataSummary as DataSummary, braintrust_Dataset as Dataset, braintrust_DatasetRecord as DatasetRecord, type braintrust_DatasetSummary as DatasetSummary, type braintrust_DefaultMetadataType as DefaultMetadataType, type braintrust_DefaultPromptArgs as DefaultPromptArgs, type braintrust_EndSpanArgs as EndSpanArgs, braintrust_Eval as Eval, type braintrust_EvalCase as EvalCase, type braintrust_EvalResult as EvalResult, type braintrust_EvalScorer as EvalScorer, type braintrust_EvalScorerArgs as EvalScorerArgs, type braintrust_EvalTask as EvalTask, type braintrust_Evaluator as Evaluator, type braintrust_EvaluatorDef as EvaluatorDef, type braintrust_EvaluatorFile as EvaluatorFile, braintrust_Experiment as Experiment, braintrust_ExperimentLogFullArgs as ExperimentLogFullArgs, braintrust_ExperimentLogPartialArgs as ExperimentLogPartialArgs, type braintrust_ExperimentSummary as ExperimentSummary, type braintrust_Exportable as Exportable, braintrust_FailedHTTPResponse as FailedHTTPResponse, type braintrust_FullInitOptions as FullInitOptions, type braintrust_FullLoginOptions as FullLoginOptions, braintrust_IdField as IdField, type braintrust_InitOptions as InitOptions, braintrust_InputField as InputField, braintrust_InputsField as InputsField, type braintrust_InvokeFunctionArgs as InvokeFunctionArgs, type braintrust_InvokeReturn as InvokeReturn, braintrust_LEGACY_CACHED_HEADER as LEGACY_CACHED_HEADER, braintrust_LazyValue as LazyValue, braintrust_LogCommentFullArgs as LogCommentFullArgs, braintrust_LogFeedbackFullArgs as LogFeedbackFullArgs, 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, braintrust_OtherExperimentLogFields as OtherExperimentLogFields, braintrust_ParentExperimentIds as ParentExperimentIds, braintrust_ParentProjectLogIds as ParentProjectLogIds, braintrust_Project as Project, type braintrust_PromiseUnless as PromiseUnless, braintrust_Prompt as Prompt, braintrust_PromptBuilder as PromptBuilder, type braintrust_PromptOpts as PromptOpts, type braintrust_PromptRowWithId as PromptRowWithId, braintrust_ReadonlyExperiment as ReadonlyExperiment, braintrust_Reporter as Reporter, type braintrust_ReporterBody as ReporterBody, type braintrust_ScoreSummary as ScoreSummary, type braintrust_SerializedBraintrustState as SerializedBraintrustState, type braintrust_SetCurrentArg as SetCurrentArg, type braintrust_Span as Span, type braintrust_SpanContext as SpanContext, braintrust_SpanImpl as SpanImpl, type braintrust_StartSpanArgs as StartSpanArgs, braintrust_ToolBuilder as ToolBuilder, type braintrust_ToolFunctionDefinition as ToolFunctionDefinition, type braintrust_ToolOpts as ToolOpts, 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_buildLocalSummary as buildLocalSummary, 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_projects as projects, braintrust_renderMessage as renderMessage, braintrust_reportFailures as reportFailures, braintrust_setFetch as setFetch, braintrust_spanComponentsToObjectId as spanComponentsToObjectId, braintrust_startSpan as startSpan, braintrust_summarize as summarize, braintrust_toolFunctionDefinitionSchema as toolFunctionDefinitionSchema, 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_wrapAISDKModel as wrapAISDKModel, braintrust_wrapOpenAI as wrapOpenAI, braintrust_wrapOpenAIv4 as wrapOpenAIv4, braintrust_wrapTraced as wrapTraced };
2015
+ export { type braintrust_AnyDataset as AnyDataset, braintrust_Attachment as Attachment, type braintrust_AttachmentParams as AttachmentParams, type braintrust_BackgroundLoggerOpts as BackgroundLoggerOpts, braintrust_BaseExperiment as BaseExperiment, type braintrust_BaseMetadata as BaseMetadata, braintrust_BraintrustState as BraintrustState, braintrust_BraintrustStream as BraintrustStream, type braintrust_BraintrustStreamChunk as BraintrustStreamChunk, type braintrust_ChatPrompt as ChatPrompt, braintrust_CodeFunction as CodeFunction, braintrust_CodePrompt as CodePrompt, braintrust_CommentEvent as CommentEvent, type braintrust_CompiledPrompt as CompiledPrompt, type braintrust_CompiledPromptParams as CompiledPromptParams, type braintrust_CompletionPrompt as CompletionPrompt, type braintrust_CreateProjectOpts as CreateProjectOpts, type braintrust_DataSummary as DataSummary, braintrust_Dataset as Dataset, braintrust_DatasetRecord as DatasetRecord, type braintrust_DatasetSummary as DatasetSummary, type braintrust_DefaultMetadataType as DefaultMetadataType, type braintrust_DefaultPromptArgs as DefaultPromptArgs, type braintrust_EndSpanArgs as EndSpanArgs, braintrust_Eval as Eval, type braintrust_EvalCase as EvalCase, type braintrust_EvalResult as EvalResult, type braintrust_EvalScorer as EvalScorer, type braintrust_EvalScorerArgs as EvalScorerArgs, type braintrust_EvalTask as EvalTask, type braintrust_Evaluator as Evaluator, type braintrust_EvaluatorDef as EvaluatorDef, type braintrust_EvaluatorFile as EvaluatorFile, braintrust_Experiment as Experiment, braintrust_ExperimentLogFullArgs as ExperimentLogFullArgs, braintrust_ExperimentLogPartialArgs as ExperimentLogPartialArgs, type braintrust_ExperimentSummary as ExperimentSummary, type braintrust_Exportable as Exportable, braintrust_FailedHTTPResponse as FailedHTTPResponse, type braintrust_FullInitOptions as FullInitOptions, type braintrust_FullLoginOptions as FullLoginOptions, braintrust_IdField as IdField, type braintrust_InitOptions as InitOptions, braintrust_InputField as InputField, type braintrust_InvokeFunctionArgs as InvokeFunctionArgs, type braintrust_InvokeReturn as InvokeReturn, braintrust_LEGACY_CACHED_HEADER as LEGACY_CACHED_HEADER, braintrust_LazyValue as LazyValue, braintrust_LogCommentFullArgs as LogCommentFullArgs, braintrust_LogFeedbackFullArgs as LogFeedbackFullArgs, 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, braintrust_OtherExperimentLogFields as OtherExperimentLogFields, braintrust_ParentExperimentIds as ParentExperimentIds, braintrust_ParentProjectLogIds as ParentProjectLogIds, braintrust_Project as Project, type braintrust_PromiseUnless as PromiseUnless, braintrust_Prompt as Prompt, braintrust_PromptBuilder as PromptBuilder, type braintrust_PromptOpts as PromptOpts, type braintrust_PromptRowWithId as PromptRowWithId, braintrust_ReadonlyExperiment as ReadonlyExperiment, braintrust_Reporter as Reporter, type braintrust_ReporterBody as ReporterBody, type braintrust_ScoreSummary as ScoreSummary, type braintrust_SerializedBraintrustState as SerializedBraintrustState, type braintrust_SetCurrentArg as SetCurrentArg, type braintrust_Span as Span, type braintrust_SpanContext as SpanContext, braintrust_SpanImpl as SpanImpl, type braintrust_StartSpanArgs as StartSpanArgs, braintrust_ToolBuilder as ToolBuilder, type braintrust_ToolFunctionDefinition as ToolFunctionDefinition, type braintrust_ToolOpts as ToolOpts, 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_buildLocalSummary as buildLocalSummary, 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_projects as projects, braintrust_renderMessage as renderMessage, braintrust_reportFailures as reportFailures, braintrust_setFetch as setFetch, braintrust_spanComponentsToObjectId as spanComponentsToObjectId, braintrust_startSpan as startSpan, braintrust_summarize as summarize, braintrust_toolFunctionDefinitionSchema as toolFunctionDefinitionSchema, 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_wrapAISDKModel as wrapAISDKModel, braintrust_wrapOpenAI as wrapOpenAI, braintrust_wrapOpenAIv4 as wrapOpenAIv4, braintrust_wrapTraced as wrapTraced };
1874
2016
  }
1875
2017
 
1876
2018
  /**
@@ -1926,4 +2068,4 @@ declare namespace braintrust {
1926
2068
  * @module braintrust
1927
2069
  */
1928
2070
 
1929
- export { type AnyDataset, type BackgroundLoggerOpts, BaseExperiment, type BaseMetadata, BraintrustState, BraintrustStream, type BraintrustStreamChunk, type ChatPrompt, CodeFunction, CodePrompt, type CompiledPrompt, type CompiledPromptParams, type CompletionPrompt, type CreateProjectOpts, type DataSummary, Dataset, type DatasetSummary, type DefaultMetadataType, type DefaultPromptArgs, type EndSpanArgs, Eval, type EvalCase, type EvalResult, type EvalScorer, type EvalScorerArgs, type EvalTask, type Evaluator, type EvaluatorDef, type EvaluatorFile, Experiment, type ExperimentSummary, type Exportable, FailedHTTPResponse, type FullInitOptions, type FullLoginOptions, type InitOptions, type InvokeFunctionArgs, type InvokeReturn, LEGACY_CACHED_HEADER, LazyValue, type LogOptions, Logger, type LoginOptions, type MetricSummary, NOOP_SPAN, NoopSpan, type ObjectMetadata, Project, type PromiseUnless, Prompt, PromptBuilder, type PromptOpts, type PromptRowWithId, ReadonlyExperiment, Reporter, type ReporterBody, type ScoreSummary, type SerializedBraintrustState, type SetCurrentArg, type Span, type SpanContext, SpanImpl, type StartSpanArgs, ToolBuilder, type ToolFunctionDefinition, type ToolOpts, type WithTransactionId, X_CACHED_HEADER, _internalGetGlobalState, _internalSetInitialState, braintrustStreamChunkSchema, buildLocalSummary, createFinalValuePassThroughStream, currentExperiment, currentLogger, currentSpan, braintrust as default, devNullWritableStream, flush, getSpanParentObject, init, initDataset, initExperiment, initLogger, invoke, loadPrompt, log, logError, login, loginToState, newId, parseCachedHeader, permalink, projects, renderMessage, reportFailures, setFetch, spanComponentsToObjectId, startSpan, summarize, toolFunctionDefinitionSchema, traceable, traced, updateSpan, withCurrent, withDataset, withExperiment, withLogger, wrapAISDKModel, wrapOpenAI, wrapOpenAIv4, wrapTraced };
2071
+ export { type AnyDataset, Attachment, type AttachmentParams, type BackgroundLoggerOpts, BaseExperiment, type BaseMetadata, BraintrustState, BraintrustStream, type BraintrustStreamChunk, type ChatPrompt, CodeFunction, CodePrompt, type CompiledPrompt, type CompiledPromptParams, type CompletionPrompt, type CreateProjectOpts, type DataSummary, Dataset, type DatasetSummary, type DefaultMetadataType, type DefaultPromptArgs, type EndSpanArgs, Eval, type EvalCase, type EvalResult, type EvalScorer, type EvalScorerArgs, type EvalTask, type Evaluator, type EvaluatorDef, type EvaluatorFile, Experiment, type ExperimentSummary, type Exportable, FailedHTTPResponse, type FullInitOptions, type FullLoginOptions, type InitOptions, type InvokeFunctionArgs, type InvokeReturn, LEGACY_CACHED_HEADER, LazyValue, type LogOptions, Logger, type LoginOptions, type MetricSummary, NOOP_SPAN, NoopSpan, type ObjectMetadata, Project, type PromiseUnless, Prompt, PromptBuilder, type PromptOpts, type PromptRowWithId, ReadonlyExperiment, Reporter, type ReporterBody, type ScoreSummary, type SerializedBraintrustState, type SetCurrentArg, type Span, type SpanContext, SpanImpl, type StartSpanArgs, ToolBuilder, type ToolFunctionDefinition, type ToolOpts, type WithTransactionId, X_CACHED_HEADER, _exportsForTestingOnly, _internalGetGlobalState, _internalSetInitialState, braintrustStreamChunkSchema, buildLocalSummary, createFinalValuePassThroughStream, currentExperiment, currentLogger, currentSpan, braintrust as default, devNullWritableStream, flush, getSpanParentObject, init, initDataset, initExperiment, initLogger, invoke, loadPrompt, log, logError, login, loginToState, newId, parseCachedHeader, permalink, projects, renderMessage, reportFailures, setFetch, spanComponentsToObjectId, startSpan, summarize, toolFunctionDefinitionSchema, traceable, traced, updateSpan, withCurrent, withDataset, withExperiment, withLogger, wrapAISDKModel, wrapOpenAI, wrapOpenAIv4, wrapTraced };