braintrust 0.4.2 → 0.4.3

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.
@@ -7652,6 +7652,7 @@ declare class Logger<IsAsyncFlush extends boolean> implements Exportable {
7652
7652
  get org_id(): Promise<string>;
7653
7653
  get project(): Promise<ObjectMetadata>;
7654
7654
  get id(): Promise<string>;
7655
+ get loggingState(): BraintrustState;
7655
7656
  private parentObjectType;
7656
7657
  /**
7657
7658
  * Log a single event. The event will be batched and uploaded behind the scenes if `logOptions.asyncFlush` is true.
@@ -7868,6 +7869,7 @@ declare class Experiment extends ObjectFetcher<ExperimentEvent> implements Expor
7868
7869
  kind: "experiment";
7869
7870
  constructor(state: BraintrustState, lazyMetadata: LazyValue<ProjectExperimentMetadata>, dataset?: AnyDataset);
7870
7871
  get id(): Promise<string>;
7872
+ get loggingState(): BraintrustState;
7871
7873
  /**
7872
7874
  * Wait for the experiment ID to be resolved. This is useful for ensuring the ID
7873
7875
  * is available synchronously in child spans (for OTEL parent attributes).
@@ -7979,6 +7981,7 @@ declare class Dataset<IsLegacyDataset extends boolean = typeof DEFAULT_IS_LEGACY
7979
7981
  get id(): Promise<string>;
7980
7982
  get name(): Promise<string>;
7981
7983
  get project(): Promise<ObjectMetadata>;
7984
+ get loggingState(): BraintrustState;
7982
7985
  protected getState(): Promise<BraintrustState>;
7983
7986
  private validateEvent;
7984
7987
  private createArgs;
@@ -7652,6 +7652,7 @@ declare class Logger<IsAsyncFlush extends boolean> implements Exportable {
7652
7652
  get org_id(): Promise<string>;
7653
7653
  get project(): Promise<ObjectMetadata>;
7654
7654
  get id(): Promise<string>;
7655
+ get loggingState(): BraintrustState;
7655
7656
  private parentObjectType;
7656
7657
  /**
7657
7658
  * Log a single event. The event will be batched and uploaded behind the scenes if `logOptions.asyncFlush` is true.
@@ -7868,6 +7869,7 @@ declare class Experiment extends ObjectFetcher<ExperimentEvent> implements Expor
7868
7869
  kind: "experiment";
7869
7870
  constructor(state: BraintrustState, lazyMetadata: LazyValue<ProjectExperimentMetadata>, dataset?: AnyDataset);
7870
7871
  get id(): Promise<string>;
7872
+ get loggingState(): BraintrustState;
7871
7873
  /**
7872
7874
  * Wait for the experiment ID to be resolved. This is useful for ensuring the ID
7873
7875
  * is available synchronously in child spans (for OTEL parent attributes).
@@ -7979,6 +7981,7 @@ declare class Dataset<IsLegacyDataset extends boolean = typeof DEFAULT_IS_LEGACY
7979
7981
  get id(): Promise<string>;
7980
7982
  get name(): Promise<string>;
7981
7983
  get project(): Promise<ObjectMetadata>;
7984
+ get loggingState(): BraintrustState;
7982
7985
  protected getState(): Promise<BraintrustState>;
7983
7986
  private validateEvent;
7984
7987
  private createArgs;
package/dev/dist/index.js CHANGED
@@ -7226,6 +7226,9 @@ with a Blob/ArrayBuffer, or run the program on Node.js.`
7226
7226
  get id() {
7227
7227
  return (async () => (await this.project).id)();
7228
7228
  }
7229
+ get loggingState() {
7230
+ return this.state;
7231
+ }
7229
7232
  parentObjectType() {
7230
7233
  return 2 /* PROJECT_LOGS */;
7231
7234
  }
@@ -7886,6 +7889,9 @@ Error: ${errorText}`;
7886
7889
  return (await this.lazyMetadata.get()).experiment.id;
7887
7890
  })();
7888
7891
  }
7892
+ get loggingState() {
7893
+ return this.state;
7894
+ }
7889
7895
  /**
7890
7896
  * Wait for the experiment ID to be resolved. This is useful for ensuring the ID
7891
7897
  * is available synchronously in child spans (for OTEL parent attributes).
@@ -8151,6 +8157,9 @@ View complete results in Braintrust or run experiment.summarize() again.`
8151
8157
  return (await this.lazyMetadata.get()).experiment.name;
8152
8158
  })();
8153
8159
  }
8160
+ get loggingState() {
8161
+ return this.state;
8162
+ }
8154
8163
  async getState() {
8155
8164
  await this.lazyMetadata.get();
8156
8165
  return this.state;
@@ -8539,6 +8548,9 @@ View complete results in Braintrust or run experiment.summarize() again.`
8539
8548
  return (await this.lazyMetadata.get()).project;
8540
8549
  })();
8541
8550
  }
8551
+ get loggingState() {
8552
+ return this.state;
8553
+ }
8542
8554
  async getState() {
8543
8555
  await this.lazyMetadata.get();
8544
8556
  return this.state;
@@ -7226,6 +7226,9 @@ with a Blob/ArrayBuffer, or run the program on Node.js.`
7226
7226
  get id() {
7227
7227
  return (async () => (await this.project).id)();
7228
7228
  }
7229
+ get loggingState() {
7230
+ return this.state;
7231
+ }
7229
7232
  parentObjectType() {
7230
7233
  return 2 /* PROJECT_LOGS */;
7231
7234
  }
@@ -7886,6 +7889,9 @@ Error: ${errorText}`;
7886
7889
  return (await this.lazyMetadata.get()).experiment.id;
7887
7890
  })();
7888
7891
  }
7892
+ get loggingState() {
7893
+ return this.state;
7894
+ }
7889
7895
  /**
7890
7896
  * Wait for the experiment ID to be resolved. This is useful for ensuring the ID
7891
7897
  * is available synchronously in child spans (for OTEL parent attributes).
@@ -8151,6 +8157,9 @@ View complete results in Braintrust or run experiment.summarize() again.`
8151
8157
  return (await this.lazyMetadata.get()).experiment.name;
8152
8158
  })();
8153
8159
  }
8160
+ get loggingState() {
8161
+ return this.state;
8162
+ }
8154
8163
  async getState() {
8155
8164
  await this.lazyMetadata.get();
8156
8165
  return this.state;
@@ -8539,6 +8548,9 @@ View complete results in Braintrust or run experiment.summarize() again.`
8539
8548
  return (await this.lazyMetadata.get()).project;
8540
8549
  })();
8541
8550
  }
8551
+ get loggingState() {
8552
+ return this.state;
8553
+ }
8542
8554
  async getState() {
8543
8555
  await this.lazyMetadata.get();
8544
8556
  return this.state;
@@ -8427,6 +8427,48 @@ declare class ReadonlyAttachment {
8427
8427
  status(): Promise<AttachmentStatusType>;
8428
8428
  private initDownloader;
8429
8429
  }
8430
+ /**
8431
+ * Represents a JSON object that should be stored as an attachment.
8432
+ *
8433
+ * `JSONAttachment` is a convenience function that creates an `Attachment`
8434
+ * from JSON data. It's particularly useful for large JSON objects that
8435
+ * would otherwise bloat the trace size.
8436
+ *
8437
+ * The JSON data is automatically serialized and stored as an attachment
8438
+ * with content type "application/json".
8439
+ */
8440
+ declare class JSONAttachment extends Attachment {
8441
+ /**
8442
+ * Construct a JSONAttachment from a JSON-serializable object.
8443
+ *
8444
+ * @param data The JSON object to attach. Must be JSON-serializable.
8445
+ * @param options Additional options:
8446
+ * - `filename`: The filename for the attachment (defaults to "data.json")
8447
+ * - `pretty`: Whether to pretty-print the JSON (defaults to false)
8448
+ * - `state`: (Optional) For internal use.
8449
+ *
8450
+ * @example
8451
+ * ```typescript
8452
+ * const largeTranscript = [
8453
+ * { role: "user", content: "..." },
8454
+ * { role: "assistant", content: "..." },
8455
+ * // ... many more messages
8456
+ * ];
8457
+ *
8458
+ * logger.log({
8459
+ * input: {
8460
+ * type: "chat",
8461
+ * transcript: new JSONAttachment(largeTranscript, { filename: "transcript.json" })
8462
+ * }
8463
+ * });
8464
+ * ```
8465
+ */
8466
+ constructor(data: unknown, options?: {
8467
+ filename?: string;
8468
+ pretty?: boolean;
8469
+ state?: BraintrustState;
8470
+ });
8471
+ }
8430
8472
  /**
8431
8473
  * Update a span using the output of `span.export()`. It is important that you only resume updating
8432
8474
  * to a span once the original span has been fully written and flushed, since otherwise updates to
@@ -8486,6 +8528,7 @@ declare class Logger<IsAsyncFlush extends boolean> implements Exportable {
8486
8528
  get org_id(): Promise<string>;
8487
8529
  get project(): Promise<ObjectMetadata>;
8488
8530
  get id(): Promise<string>;
8531
+ get loggingState(): BraintrustState;
8489
8532
  private parentObjectType;
8490
8533
  /**
8491
8534
  * Log a single event. The event will be batched and uploaded behind the scenes if `logOptions.asyncFlush` is true.
@@ -9037,6 +9080,7 @@ declare class Experiment extends ObjectFetcher<ExperimentEvent> implements Expor
9037
9080
  kind: "experiment";
9038
9081
  constructor(state: BraintrustState, lazyMetadata: LazyValue<ProjectExperimentMetadata>, dataset?: AnyDataset);
9039
9082
  get id(): Promise<string>;
9083
+ get loggingState(): BraintrustState;
9040
9084
  /**
9041
9085
  * Wait for the experiment ID to be resolved. This is useful for ensuring the ID
9042
9086
  * is available synchronously in child spans (for OTEL parent attributes).
@@ -9141,6 +9185,7 @@ declare class ReadonlyExperiment extends ObjectFetcher<ExperimentEvent> {
9141
9185
  constructor(state: BraintrustState, lazyMetadata: LazyValue<ProjectExperimentMetadata>);
9142
9186
  get id(): Promise<string>;
9143
9187
  get name(): Promise<string>;
9188
+ get loggingState(): BraintrustState;
9144
9189
  protected getState(): Promise<BraintrustState>;
9145
9190
  asDataset<Input, Expected, Metadata = DefaultMetadataType>(): AsyncGenerator<EvalCase<Input, Expected, Metadata>>;
9146
9191
  }
@@ -9216,6 +9261,7 @@ declare class Dataset<IsLegacyDataset extends boolean = typeof DEFAULT_IS_LEGACY
9216
9261
  get id(): Promise<string>;
9217
9262
  get name(): Promise<string>;
9218
9263
  get project(): Promise<ObjectMetadata>;
9264
+ get loggingState(): BraintrustState;
9219
9265
  protected getState(): Promise<BraintrustState>;
9220
9266
  private validateEvent;
9221
9267
  private createArgs;
@@ -19924,6 +19970,7 @@ type braintrust_AnyDataset = AnyDataset;
19924
19970
  type braintrust_Attachment = Attachment;
19925
19971
  declare const braintrust_Attachment: typeof Attachment;
19926
19972
  type braintrust_AttachmentParams = AttachmentParams;
19973
+ declare const braintrust_AttachmentReference: typeof AttachmentReference;
19927
19974
  type braintrust_BackgroundLoggerOpts = BackgroundLoggerOpts;
19928
19975
  type braintrust_BaseAttachment = BaseAttachment;
19929
19976
  declare const braintrust_BaseAttachment: typeof BaseAttachment;
@@ -19975,6 +20022,8 @@ type braintrust_InitOptions<IsOpen extends boolean> = InitOptions<IsOpen>;
19975
20022
  type braintrust_InputField = InputField;
19976
20023
  type braintrust_InvokeFunctionArgs<Input, Output, Stream extends boolean = false> = InvokeFunctionArgs<Input, Output, Stream>;
19977
20024
  type braintrust_InvokeReturn<Stream extends boolean, Output> = InvokeReturn<Stream, Output>;
20025
+ type braintrust_JSONAttachment = JSONAttachment;
20026
+ declare const braintrust_JSONAttachment: typeof JSONAttachment;
19978
20027
  declare const braintrust_LEGACY_CACHED_HEADER: typeof LEGACY_CACHED_HEADER;
19979
20028
  type braintrust_LazyValue<T> = LazyValue<T>;
19980
20029
  declare const braintrust_LazyValue: typeof LazyValue;
@@ -20062,7 +20111,7 @@ declare const braintrust_wrapOpenAI: typeof wrapOpenAI;
20062
20111
  declare const braintrust_wrapOpenAIv4: typeof wrapOpenAIv4;
20063
20112
  declare const braintrust_wrapTraced: typeof wrapTraced;
20064
20113
  declare namespace braintrust {
20065
- export { type braintrust_AnyDataset as AnyDataset, braintrust_Attachment as Attachment, type braintrust_AttachmentParams as AttachmentParams, type braintrust_BackgroundLoggerOpts as BackgroundLoggerOpts, braintrust_BaseAttachment as BaseAttachment, 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_CommentEvent as CommentEvent, type braintrust_CompiledPrompt as CompiledPrompt, type braintrust_CompiledPromptParams as CompiledPromptParams, type braintrust_CompletionPrompt as CompletionPrompt, braintrust_ContextManager as ContextManager, type braintrust_ContextParentSpanIds as ContextParentSpanIds, type braintrust_DataSummary as DataSummary, braintrust_Dataset as Dataset, type braintrust_DatasetRecord as DatasetRecord, type braintrust_DatasetSummary as DatasetSummary, type braintrust_DefaultMetadataType as DefaultMetadataType, type braintrust_DefaultPromptArgs as DefaultPromptArgs, braintrust_ERR_PERMALINK as ERR_PERMALINK, type braintrust_EndSpanArgs as EndSpanArgs, type braintrust_EvalCase as EvalCase, type braintrust_EvalParameterSerializedSchema as EvalParameterSerializedSchema, type braintrust_EvalParameters as EvalParameters, type braintrust_EvaluatorDefinition as EvaluatorDefinition, type braintrust_EvaluatorDefinitions as EvaluatorDefinitions, type braintrust_EvaluatorManifest as EvaluatorManifest, braintrust_Experiment as Experiment, type braintrust_ExperimentLogFullArgs as ExperimentLogFullArgs, type braintrust_ExperimentLogPartialArgs as ExperimentLogPartialArgs, type braintrust_ExperimentSummary as ExperimentSummary, type braintrust_Exportable as Exportable, braintrust_ExternalAttachment as ExternalAttachment, type braintrust_ExternalAttachmentParams as ExternalAttachmentParams, braintrust_FailedHTTPResponse as FailedHTTPResponse, type braintrust_FullInitOptions as FullInitOptions, type braintrust_FullLoginOptions as FullLoginOptions, braintrust_INTERNAL_BTQL_LIMIT as INTERNAL_BTQL_LIMIT, type braintrust_IdField as IdField, type braintrust_InitOptions as InitOptions, type 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, type braintrust_LogCommentFullArgs as LogCommentFullArgs, type 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_NOOP_SPAN_PERMALINK as NOOP_SPAN_PERMALINK, braintrust_NoopSpan as NoopSpan, type braintrust_ObjectMetadata as ObjectMetadata, type braintrust_OtherExperimentLogFields as OtherExperimentLogFields, type braintrust_ParentExperimentIds as ParentExperimentIds, type braintrust_ParentProjectLogIds as ParentProjectLogIds, type braintrust_PromiseUnless as PromiseUnless, braintrust_Prompt as Prompt, type braintrust_PromptRowWithId as PromptRowWithId, braintrust_ReadonlyAttachment as ReadonlyAttachment, 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, braintrust_TestBackgroundLogger as TestBackgroundLogger, 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_deepCopyEvent as deepCopyEvent, braintrust_deserializePlainStringAsJSON as deserializePlainStringAsJSON, braintrust_devNullWritableStream as devNullWritableStream, braintrust_evaluatorDefinitionSchema as evaluatorDefinitionSchema, braintrust_evaluatorDefinitionsSchema as evaluatorDefinitionsSchema, braintrust_flush as flush, braintrust_getContextManager as getContextManager, braintrust_getPromptVersions as getPromptVersions, braintrust_getSpanParentObject as getSpanParentObject, braintrust_init as init, braintrust_initDataset as initDataset, braintrust_initExperiment as initExperiment, braintrust_initFunction as initFunction, 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_renderPromptParams as renderPromptParams, braintrust_setFetch as setFetch, braintrust_setMaskingFunction as setMaskingFunction, 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_withParent as withParent, braintrust_wrapOpenAI as wrapOpenAI, braintrust_wrapOpenAIv4 as wrapOpenAIv4, braintrust_wrapTraced as wrapTraced };
20114
+ export { type braintrust_AnyDataset as AnyDataset, braintrust_Attachment as Attachment, type braintrust_AttachmentParams as AttachmentParams, braintrust_AttachmentReference as AttachmentReference, type braintrust_BackgroundLoggerOpts as BackgroundLoggerOpts, braintrust_BaseAttachment as BaseAttachment, 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_CommentEvent as CommentEvent, type braintrust_CompiledPrompt as CompiledPrompt, type braintrust_CompiledPromptParams as CompiledPromptParams, type braintrust_CompletionPrompt as CompletionPrompt, braintrust_ContextManager as ContextManager, type braintrust_ContextParentSpanIds as ContextParentSpanIds, type braintrust_DataSummary as DataSummary, braintrust_Dataset as Dataset, type braintrust_DatasetRecord as DatasetRecord, type braintrust_DatasetSummary as DatasetSummary, type braintrust_DefaultMetadataType as DefaultMetadataType, type braintrust_DefaultPromptArgs as DefaultPromptArgs, braintrust_ERR_PERMALINK as ERR_PERMALINK, type braintrust_EndSpanArgs as EndSpanArgs, type braintrust_EvalCase as EvalCase, type braintrust_EvalParameterSerializedSchema as EvalParameterSerializedSchema, type braintrust_EvalParameters as EvalParameters, type braintrust_EvaluatorDefinition as EvaluatorDefinition, type braintrust_EvaluatorDefinitions as EvaluatorDefinitions, type braintrust_EvaluatorManifest as EvaluatorManifest, braintrust_Experiment as Experiment, type braintrust_ExperimentLogFullArgs as ExperimentLogFullArgs, type braintrust_ExperimentLogPartialArgs as ExperimentLogPartialArgs, type braintrust_ExperimentSummary as ExperimentSummary, type braintrust_Exportable as Exportable, braintrust_ExternalAttachment as ExternalAttachment, type braintrust_ExternalAttachmentParams as ExternalAttachmentParams, braintrust_FailedHTTPResponse as FailedHTTPResponse, type braintrust_FullInitOptions as FullInitOptions, type braintrust_FullLoginOptions as FullLoginOptions, braintrust_INTERNAL_BTQL_LIMIT as INTERNAL_BTQL_LIMIT, type braintrust_IdField as IdField, type braintrust_InitOptions as InitOptions, type braintrust_InputField as InputField, type braintrust_InvokeFunctionArgs as InvokeFunctionArgs, type braintrust_InvokeReturn as InvokeReturn, braintrust_JSONAttachment as JSONAttachment, braintrust_LEGACY_CACHED_HEADER as LEGACY_CACHED_HEADER, braintrust_LazyValue as LazyValue, type braintrust_LogCommentFullArgs as LogCommentFullArgs, type 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_NOOP_SPAN_PERMALINK as NOOP_SPAN_PERMALINK, braintrust_NoopSpan as NoopSpan, type braintrust_ObjectMetadata as ObjectMetadata, type braintrust_OtherExperimentLogFields as OtherExperimentLogFields, type braintrust_ParentExperimentIds as ParentExperimentIds, type braintrust_ParentProjectLogIds as ParentProjectLogIds, type braintrust_PromiseUnless as PromiseUnless, braintrust_Prompt as Prompt, type braintrust_PromptRowWithId as PromptRowWithId, braintrust_ReadonlyAttachment as ReadonlyAttachment, 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, braintrust_TestBackgroundLogger as TestBackgroundLogger, 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_deepCopyEvent as deepCopyEvent, braintrust_deserializePlainStringAsJSON as deserializePlainStringAsJSON, braintrust_devNullWritableStream as devNullWritableStream, braintrust_evaluatorDefinitionSchema as evaluatorDefinitionSchema, braintrust_evaluatorDefinitionsSchema as evaluatorDefinitionsSchema, braintrust_flush as flush, braintrust_getContextManager as getContextManager, braintrust_getPromptVersions as getPromptVersions, braintrust_getSpanParentObject as getSpanParentObject, braintrust_init as init, braintrust_initDataset as initDataset, braintrust_initExperiment as initExperiment, braintrust_initFunction as initFunction, 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_renderPromptParams as renderPromptParams, braintrust_setFetch as setFetch, braintrust_setMaskingFunction as setMaskingFunction, 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_withParent as withParent, braintrust_wrapOpenAI as wrapOpenAI, braintrust_wrapOpenAIv4 as wrapOpenAIv4, braintrust_wrapTraced as wrapTraced };
20066
20115
  }
20067
20116
 
20068
- export { type AnyDataset, Attachment, type AttachmentParams, type BackgroundLoggerOpts, BaseAttachment, type BaseMetadata, BraintrustState, BraintrustStream, type BraintrustStreamChunk, type ChatPrompt, type CommentEvent, type CompiledPrompt, type CompiledPromptParams, type CompletionPrompt, ContextManager, type ContextParentSpanIds, type DataSummary, Dataset, type DatasetRecord, type DatasetSummary, type DefaultMetadataType, type DefaultPromptArgs, ERR_PERMALINK, type EndSpanArgs, type EvalCase, type EvalParameterSerializedSchema, type EvalParameters, type EvaluatorDefinition, type EvaluatorDefinitions, type EvaluatorManifest, Experiment, type ExperimentLogFullArgs, type ExperimentLogPartialArgs, type ExperimentSummary, type Exportable, ExternalAttachment, type ExternalAttachmentParams, FailedHTTPResponse, type FullInitOptions, type FullLoginOptions, INTERNAL_BTQL_LIMIT, type IdField, type InitOptions, type InputField, type InvokeFunctionArgs, type InvokeReturn, LEGACY_CACHED_HEADER, LazyValue, type LogCommentFullArgs, type LogFeedbackFullArgs, type LogOptions, Logger, type LoginOptions, type MetricSummary, NOOP_SPAN, NOOP_SPAN_PERMALINK, NoopSpan, type ObjectMetadata, type OtherExperimentLogFields, type ParentExperimentIds, type ParentProjectLogIds, type PromiseUnless, Prompt, type PromptRowWithId, ReadonlyAttachment, ReadonlyExperiment, type ScoreSummary, type SerializedBraintrustState, type SetCurrentArg, type Span, SpanImpl, type StartSpanArgs, TestBackgroundLogger, type WithTransactionId, X_CACHED_HEADER, _exportsForTestingOnly, _internalGetGlobalState, _internalSetInitialState, braintrustStreamChunkSchema, createFinalValuePassThroughStream, currentExperiment, currentLogger, currentSpan, deepCopyEvent, braintrust as default, deserializePlainStringAsJSON, devNullWritableStream, evaluatorDefinitionSchema, evaluatorDefinitionsSchema, flush, getContextManager, getPromptVersions, getSpanParentObject, init, initDataset, initExperiment, initFunction, initLogger, invoke, loadPrompt, log, logError, login, loginToState, newId, parseCachedHeader, permalink, renderMessage, renderPromptParams, setFetch, setMaskingFunction, spanComponentsToObjectId, startSpan, summarize, traceable, traced, updateSpan, withCurrent, withDataset, withExperiment, withLogger, withParent, wrapOpenAI, wrapOpenAIv4, wrapTraced };
20117
+ export { type AnyDataset, Attachment, type AttachmentParams, AttachmentReference, type BackgroundLoggerOpts, BaseAttachment, type BaseMetadata, BraintrustState, BraintrustStream, type BraintrustStreamChunk, type ChatPrompt, type CommentEvent, type CompiledPrompt, type CompiledPromptParams, type CompletionPrompt, ContextManager, type ContextParentSpanIds, type DataSummary, Dataset, type DatasetRecord, type DatasetSummary, type DefaultMetadataType, type DefaultPromptArgs, ERR_PERMALINK, type EndSpanArgs, type EvalCase, type EvalParameterSerializedSchema, type EvalParameters, type EvaluatorDefinition, type EvaluatorDefinitions, type EvaluatorManifest, Experiment, type ExperimentLogFullArgs, type ExperimentLogPartialArgs, type ExperimentSummary, type Exportable, ExternalAttachment, type ExternalAttachmentParams, FailedHTTPResponse, type FullInitOptions, type FullLoginOptions, INTERNAL_BTQL_LIMIT, type IdField, type InitOptions, type InputField, type InvokeFunctionArgs, type InvokeReturn, JSONAttachment, LEGACY_CACHED_HEADER, LazyValue, type LogCommentFullArgs, type LogFeedbackFullArgs, type LogOptions, Logger, type LoginOptions, type MetricSummary, NOOP_SPAN, NOOP_SPAN_PERMALINK, NoopSpan, type ObjectMetadata, type OtherExperimentLogFields, type ParentExperimentIds, type ParentProjectLogIds, type PromiseUnless, Prompt, type PromptRowWithId, ReadonlyAttachment, ReadonlyExperiment, type ScoreSummary, type SerializedBraintrustState, type SetCurrentArg, type Span, SpanImpl, type StartSpanArgs, TestBackgroundLogger, type WithTransactionId, X_CACHED_HEADER, _exportsForTestingOnly, _internalGetGlobalState, _internalSetInitialState, braintrustStreamChunkSchema, createFinalValuePassThroughStream, currentExperiment, currentLogger, currentSpan, deepCopyEvent, braintrust as default, deserializePlainStringAsJSON, devNullWritableStream, evaluatorDefinitionSchema, evaluatorDefinitionsSchema, flush, getContextManager, getPromptVersions, getSpanParentObject, init, initDataset, initExperiment, initFunction, initLogger, invoke, loadPrompt, log, logError, login, loginToState, newId, parseCachedHeader, permalink, renderMessage, renderPromptParams, setFetch, setMaskingFunction, spanComponentsToObjectId, startSpan, summarize, traceable, traced, updateSpan, withCurrent, withDataset, withExperiment, withLogger, withParent, wrapOpenAI, wrapOpenAIv4, wrapTraced };
package/dist/browser.d.ts CHANGED
@@ -8427,6 +8427,48 @@ declare class ReadonlyAttachment {
8427
8427
  status(): Promise<AttachmentStatusType>;
8428
8428
  private initDownloader;
8429
8429
  }
8430
+ /**
8431
+ * Represents a JSON object that should be stored as an attachment.
8432
+ *
8433
+ * `JSONAttachment` is a convenience function that creates an `Attachment`
8434
+ * from JSON data. It's particularly useful for large JSON objects that
8435
+ * would otherwise bloat the trace size.
8436
+ *
8437
+ * The JSON data is automatically serialized and stored as an attachment
8438
+ * with content type "application/json".
8439
+ */
8440
+ declare class JSONAttachment extends Attachment {
8441
+ /**
8442
+ * Construct a JSONAttachment from a JSON-serializable object.
8443
+ *
8444
+ * @param data The JSON object to attach. Must be JSON-serializable.
8445
+ * @param options Additional options:
8446
+ * - `filename`: The filename for the attachment (defaults to "data.json")
8447
+ * - `pretty`: Whether to pretty-print the JSON (defaults to false)
8448
+ * - `state`: (Optional) For internal use.
8449
+ *
8450
+ * @example
8451
+ * ```typescript
8452
+ * const largeTranscript = [
8453
+ * { role: "user", content: "..." },
8454
+ * { role: "assistant", content: "..." },
8455
+ * // ... many more messages
8456
+ * ];
8457
+ *
8458
+ * logger.log({
8459
+ * input: {
8460
+ * type: "chat",
8461
+ * transcript: new JSONAttachment(largeTranscript, { filename: "transcript.json" })
8462
+ * }
8463
+ * });
8464
+ * ```
8465
+ */
8466
+ constructor(data: unknown, options?: {
8467
+ filename?: string;
8468
+ pretty?: boolean;
8469
+ state?: BraintrustState;
8470
+ });
8471
+ }
8430
8472
  /**
8431
8473
  * Update a span using the output of `span.export()`. It is important that you only resume updating
8432
8474
  * to a span once the original span has been fully written and flushed, since otherwise updates to
@@ -8486,6 +8528,7 @@ declare class Logger<IsAsyncFlush extends boolean> implements Exportable {
8486
8528
  get org_id(): Promise<string>;
8487
8529
  get project(): Promise<ObjectMetadata>;
8488
8530
  get id(): Promise<string>;
8531
+ get loggingState(): BraintrustState;
8489
8532
  private parentObjectType;
8490
8533
  /**
8491
8534
  * Log a single event. The event will be batched and uploaded behind the scenes if `logOptions.asyncFlush` is true.
@@ -9037,6 +9080,7 @@ declare class Experiment extends ObjectFetcher<ExperimentEvent> implements Expor
9037
9080
  kind: "experiment";
9038
9081
  constructor(state: BraintrustState, lazyMetadata: LazyValue<ProjectExperimentMetadata>, dataset?: AnyDataset);
9039
9082
  get id(): Promise<string>;
9083
+ get loggingState(): BraintrustState;
9040
9084
  /**
9041
9085
  * Wait for the experiment ID to be resolved. This is useful for ensuring the ID
9042
9086
  * is available synchronously in child spans (for OTEL parent attributes).
@@ -9141,6 +9185,7 @@ declare class ReadonlyExperiment extends ObjectFetcher<ExperimentEvent> {
9141
9185
  constructor(state: BraintrustState, lazyMetadata: LazyValue<ProjectExperimentMetadata>);
9142
9186
  get id(): Promise<string>;
9143
9187
  get name(): Promise<string>;
9188
+ get loggingState(): BraintrustState;
9144
9189
  protected getState(): Promise<BraintrustState>;
9145
9190
  asDataset<Input, Expected, Metadata = DefaultMetadataType>(): AsyncGenerator<EvalCase<Input, Expected, Metadata>>;
9146
9191
  }
@@ -9216,6 +9261,7 @@ declare class Dataset<IsLegacyDataset extends boolean = typeof DEFAULT_IS_LEGACY
9216
9261
  get id(): Promise<string>;
9217
9262
  get name(): Promise<string>;
9218
9263
  get project(): Promise<ObjectMetadata>;
9264
+ get loggingState(): BraintrustState;
9219
9265
  protected getState(): Promise<BraintrustState>;
9220
9266
  private validateEvent;
9221
9267
  private createArgs;
@@ -19924,6 +19970,7 @@ type braintrust_AnyDataset = AnyDataset;
19924
19970
  type braintrust_Attachment = Attachment;
19925
19971
  declare const braintrust_Attachment: typeof Attachment;
19926
19972
  type braintrust_AttachmentParams = AttachmentParams;
19973
+ declare const braintrust_AttachmentReference: typeof AttachmentReference;
19927
19974
  type braintrust_BackgroundLoggerOpts = BackgroundLoggerOpts;
19928
19975
  type braintrust_BaseAttachment = BaseAttachment;
19929
19976
  declare const braintrust_BaseAttachment: typeof BaseAttachment;
@@ -19975,6 +20022,8 @@ type braintrust_InitOptions<IsOpen extends boolean> = InitOptions<IsOpen>;
19975
20022
  type braintrust_InputField = InputField;
19976
20023
  type braintrust_InvokeFunctionArgs<Input, Output, Stream extends boolean = false> = InvokeFunctionArgs<Input, Output, Stream>;
19977
20024
  type braintrust_InvokeReturn<Stream extends boolean, Output> = InvokeReturn<Stream, Output>;
20025
+ type braintrust_JSONAttachment = JSONAttachment;
20026
+ declare const braintrust_JSONAttachment: typeof JSONAttachment;
19978
20027
  declare const braintrust_LEGACY_CACHED_HEADER: typeof LEGACY_CACHED_HEADER;
19979
20028
  type braintrust_LazyValue<T> = LazyValue<T>;
19980
20029
  declare const braintrust_LazyValue: typeof LazyValue;
@@ -20062,7 +20111,7 @@ declare const braintrust_wrapOpenAI: typeof wrapOpenAI;
20062
20111
  declare const braintrust_wrapOpenAIv4: typeof wrapOpenAIv4;
20063
20112
  declare const braintrust_wrapTraced: typeof wrapTraced;
20064
20113
  declare namespace braintrust {
20065
- export { type braintrust_AnyDataset as AnyDataset, braintrust_Attachment as Attachment, type braintrust_AttachmentParams as AttachmentParams, type braintrust_BackgroundLoggerOpts as BackgroundLoggerOpts, braintrust_BaseAttachment as BaseAttachment, 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_CommentEvent as CommentEvent, type braintrust_CompiledPrompt as CompiledPrompt, type braintrust_CompiledPromptParams as CompiledPromptParams, type braintrust_CompletionPrompt as CompletionPrompt, braintrust_ContextManager as ContextManager, type braintrust_ContextParentSpanIds as ContextParentSpanIds, type braintrust_DataSummary as DataSummary, braintrust_Dataset as Dataset, type braintrust_DatasetRecord as DatasetRecord, type braintrust_DatasetSummary as DatasetSummary, type braintrust_DefaultMetadataType as DefaultMetadataType, type braintrust_DefaultPromptArgs as DefaultPromptArgs, braintrust_ERR_PERMALINK as ERR_PERMALINK, type braintrust_EndSpanArgs as EndSpanArgs, type braintrust_EvalCase as EvalCase, type braintrust_EvalParameterSerializedSchema as EvalParameterSerializedSchema, type braintrust_EvalParameters as EvalParameters, type braintrust_EvaluatorDefinition as EvaluatorDefinition, type braintrust_EvaluatorDefinitions as EvaluatorDefinitions, type braintrust_EvaluatorManifest as EvaluatorManifest, braintrust_Experiment as Experiment, type braintrust_ExperimentLogFullArgs as ExperimentLogFullArgs, type braintrust_ExperimentLogPartialArgs as ExperimentLogPartialArgs, type braintrust_ExperimentSummary as ExperimentSummary, type braintrust_Exportable as Exportable, braintrust_ExternalAttachment as ExternalAttachment, type braintrust_ExternalAttachmentParams as ExternalAttachmentParams, braintrust_FailedHTTPResponse as FailedHTTPResponse, type braintrust_FullInitOptions as FullInitOptions, type braintrust_FullLoginOptions as FullLoginOptions, braintrust_INTERNAL_BTQL_LIMIT as INTERNAL_BTQL_LIMIT, type braintrust_IdField as IdField, type braintrust_InitOptions as InitOptions, type 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, type braintrust_LogCommentFullArgs as LogCommentFullArgs, type 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_NOOP_SPAN_PERMALINK as NOOP_SPAN_PERMALINK, braintrust_NoopSpan as NoopSpan, type braintrust_ObjectMetadata as ObjectMetadata, type braintrust_OtherExperimentLogFields as OtherExperimentLogFields, type braintrust_ParentExperimentIds as ParentExperimentIds, type braintrust_ParentProjectLogIds as ParentProjectLogIds, type braintrust_PromiseUnless as PromiseUnless, braintrust_Prompt as Prompt, type braintrust_PromptRowWithId as PromptRowWithId, braintrust_ReadonlyAttachment as ReadonlyAttachment, 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, braintrust_TestBackgroundLogger as TestBackgroundLogger, 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_deepCopyEvent as deepCopyEvent, braintrust_deserializePlainStringAsJSON as deserializePlainStringAsJSON, braintrust_devNullWritableStream as devNullWritableStream, braintrust_evaluatorDefinitionSchema as evaluatorDefinitionSchema, braintrust_evaluatorDefinitionsSchema as evaluatorDefinitionsSchema, braintrust_flush as flush, braintrust_getContextManager as getContextManager, braintrust_getPromptVersions as getPromptVersions, braintrust_getSpanParentObject as getSpanParentObject, braintrust_init as init, braintrust_initDataset as initDataset, braintrust_initExperiment as initExperiment, braintrust_initFunction as initFunction, 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_renderPromptParams as renderPromptParams, braintrust_setFetch as setFetch, braintrust_setMaskingFunction as setMaskingFunction, 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_withParent as withParent, braintrust_wrapOpenAI as wrapOpenAI, braintrust_wrapOpenAIv4 as wrapOpenAIv4, braintrust_wrapTraced as wrapTraced };
20114
+ export { type braintrust_AnyDataset as AnyDataset, braintrust_Attachment as Attachment, type braintrust_AttachmentParams as AttachmentParams, braintrust_AttachmentReference as AttachmentReference, type braintrust_BackgroundLoggerOpts as BackgroundLoggerOpts, braintrust_BaseAttachment as BaseAttachment, 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_CommentEvent as CommentEvent, type braintrust_CompiledPrompt as CompiledPrompt, type braintrust_CompiledPromptParams as CompiledPromptParams, type braintrust_CompletionPrompt as CompletionPrompt, braintrust_ContextManager as ContextManager, type braintrust_ContextParentSpanIds as ContextParentSpanIds, type braintrust_DataSummary as DataSummary, braintrust_Dataset as Dataset, type braintrust_DatasetRecord as DatasetRecord, type braintrust_DatasetSummary as DatasetSummary, type braintrust_DefaultMetadataType as DefaultMetadataType, type braintrust_DefaultPromptArgs as DefaultPromptArgs, braintrust_ERR_PERMALINK as ERR_PERMALINK, type braintrust_EndSpanArgs as EndSpanArgs, type braintrust_EvalCase as EvalCase, type braintrust_EvalParameterSerializedSchema as EvalParameterSerializedSchema, type braintrust_EvalParameters as EvalParameters, type braintrust_EvaluatorDefinition as EvaluatorDefinition, type braintrust_EvaluatorDefinitions as EvaluatorDefinitions, type braintrust_EvaluatorManifest as EvaluatorManifest, braintrust_Experiment as Experiment, type braintrust_ExperimentLogFullArgs as ExperimentLogFullArgs, type braintrust_ExperimentLogPartialArgs as ExperimentLogPartialArgs, type braintrust_ExperimentSummary as ExperimentSummary, type braintrust_Exportable as Exportable, braintrust_ExternalAttachment as ExternalAttachment, type braintrust_ExternalAttachmentParams as ExternalAttachmentParams, braintrust_FailedHTTPResponse as FailedHTTPResponse, type braintrust_FullInitOptions as FullInitOptions, type braintrust_FullLoginOptions as FullLoginOptions, braintrust_INTERNAL_BTQL_LIMIT as INTERNAL_BTQL_LIMIT, type braintrust_IdField as IdField, type braintrust_InitOptions as InitOptions, type braintrust_InputField as InputField, type braintrust_InvokeFunctionArgs as InvokeFunctionArgs, type braintrust_InvokeReturn as InvokeReturn, braintrust_JSONAttachment as JSONAttachment, braintrust_LEGACY_CACHED_HEADER as LEGACY_CACHED_HEADER, braintrust_LazyValue as LazyValue, type braintrust_LogCommentFullArgs as LogCommentFullArgs, type 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_NOOP_SPAN_PERMALINK as NOOP_SPAN_PERMALINK, braintrust_NoopSpan as NoopSpan, type braintrust_ObjectMetadata as ObjectMetadata, type braintrust_OtherExperimentLogFields as OtherExperimentLogFields, type braintrust_ParentExperimentIds as ParentExperimentIds, type braintrust_ParentProjectLogIds as ParentProjectLogIds, type braintrust_PromiseUnless as PromiseUnless, braintrust_Prompt as Prompt, type braintrust_PromptRowWithId as PromptRowWithId, braintrust_ReadonlyAttachment as ReadonlyAttachment, 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, braintrust_TestBackgroundLogger as TestBackgroundLogger, 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_deepCopyEvent as deepCopyEvent, braintrust_deserializePlainStringAsJSON as deserializePlainStringAsJSON, braintrust_devNullWritableStream as devNullWritableStream, braintrust_evaluatorDefinitionSchema as evaluatorDefinitionSchema, braintrust_evaluatorDefinitionsSchema as evaluatorDefinitionsSchema, braintrust_flush as flush, braintrust_getContextManager as getContextManager, braintrust_getPromptVersions as getPromptVersions, braintrust_getSpanParentObject as getSpanParentObject, braintrust_init as init, braintrust_initDataset as initDataset, braintrust_initExperiment as initExperiment, braintrust_initFunction as initFunction, 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_renderPromptParams as renderPromptParams, braintrust_setFetch as setFetch, braintrust_setMaskingFunction as setMaskingFunction, 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_withParent as withParent, braintrust_wrapOpenAI as wrapOpenAI, braintrust_wrapOpenAIv4 as wrapOpenAIv4, braintrust_wrapTraced as wrapTraced };
20066
20115
  }
20067
20116
 
20068
- export { type AnyDataset, Attachment, type AttachmentParams, type BackgroundLoggerOpts, BaseAttachment, type BaseMetadata, BraintrustState, BraintrustStream, type BraintrustStreamChunk, type ChatPrompt, type CommentEvent, type CompiledPrompt, type CompiledPromptParams, type CompletionPrompt, ContextManager, type ContextParentSpanIds, type DataSummary, Dataset, type DatasetRecord, type DatasetSummary, type DefaultMetadataType, type DefaultPromptArgs, ERR_PERMALINK, type EndSpanArgs, type EvalCase, type EvalParameterSerializedSchema, type EvalParameters, type EvaluatorDefinition, type EvaluatorDefinitions, type EvaluatorManifest, Experiment, type ExperimentLogFullArgs, type ExperimentLogPartialArgs, type ExperimentSummary, type Exportable, ExternalAttachment, type ExternalAttachmentParams, FailedHTTPResponse, type FullInitOptions, type FullLoginOptions, INTERNAL_BTQL_LIMIT, type IdField, type InitOptions, type InputField, type InvokeFunctionArgs, type InvokeReturn, LEGACY_CACHED_HEADER, LazyValue, type LogCommentFullArgs, type LogFeedbackFullArgs, type LogOptions, Logger, type LoginOptions, type MetricSummary, NOOP_SPAN, NOOP_SPAN_PERMALINK, NoopSpan, type ObjectMetadata, type OtherExperimentLogFields, type ParentExperimentIds, type ParentProjectLogIds, type PromiseUnless, Prompt, type PromptRowWithId, ReadonlyAttachment, ReadonlyExperiment, type ScoreSummary, type SerializedBraintrustState, type SetCurrentArg, type Span, SpanImpl, type StartSpanArgs, TestBackgroundLogger, type WithTransactionId, X_CACHED_HEADER, _exportsForTestingOnly, _internalGetGlobalState, _internalSetInitialState, braintrustStreamChunkSchema, createFinalValuePassThroughStream, currentExperiment, currentLogger, currentSpan, deepCopyEvent, braintrust as default, deserializePlainStringAsJSON, devNullWritableStream, evaluatorDefinitionSchema, evaluatorDefinitionsSchema, flush, getContextManager, getPromptVersions, getSpanParentObject, init, initDataset, initExperiment, initFunction, initLogger, invoke, loadPrompt, log, logError, login, loginToState, newId, parseCachedHeader, permalink, renderMessage, renderPromptParams, setFetch, setMaskingFunction, spanComponentsToObjectId, startSpan, summarize, traceable, traced, updateSpan, withCurrent, withDataset, withExperiment, withLogger, withParent, wrapOpenAI, wrapOpenAIv4, wrapTraced };
20117
+ export { type AnyDataset, Attachment, type AttachmentParams, AttachmentReference, type BackgroundLoggerOpts, BaseAttachment, type BaseMetadata, BraintrustState, BraintrustStream, type BraintrustStreamChunk, type ChatPrompt, type CommentEvent, type CompiledPrompt, type CompiledPromptParams, type CompletionPrompt, ContextManager, type ContextParentSpanIds, type DataSummary, Dataset, type DatasetRecord, type DatasetSummary, type DefaultMetadataType, type DefaultPromptArgs, ERR_PERMALINK, type EndSpanArgs, type EvalCase, type EvalParameterSerializedSchema, type EvalParameters, type EvaluatorDefinition, type EvaluatorDefinitions, type EvaluatorManifest, Experiment, type ExperimentLogFullArgs, type ExperimentLogPartialArgs, type ExperimentSummary, type Exportable, ExternalAttachment, type ExternalAttachmentParams, FailedHTTPResponse, type FullInitOptions, type FullLoginOptions, INTERNAL_BTQL_LIMIT, type IdField, type InitOptions, type InputField, type InvokeFunctionArgs, type InvokeReturn, JSONAttachment, LEGACY_CACHED_HEADER, LazyValue, type LogCommentFullArgs, type LogFeedbackFullArgs, type LogOptions, Logger, type LoginOptions, type MetricSummary, NOOP_SPAN, NOOP_SPAN_PERMALINK, NoopSpan, type ObjectMetadata, type OtherExperimentLogFields, type ParentExperimentIds, type ParentProjectLogIds, type PromiseUnless, Prompt, type PromptRowWithId, ReadonlyAttachment, ReadonlyExperiment, type ScoreSummary, type SerializedBraintrustState, type SetCurrentArg, type Span, SpanImpl, type StartSpanArgs, TestBackgroundLogger, type WithTransactionId, X_CACHED_HEADER, _exportsForTestingOnly, _internalGetGlobalState, _internalSetInitialState, braintrustStreamChunkSchema, createFinalValuePassThroughStream, currentExperiment, currentLogger, currentSpan, deepCopyEvent, braintrust as default, deserializePlainStringAsJSON, devNullWritableStream, evaluatorDefinitionSchema, evaluatorDefinitionsSchema, flush, getContextManager, getPromptVersions, getSpanParentObject, init, initDataset, initExperiment, initFunction, initLogger, invoke, loadPrompt, log, logError, login, loginToState, newId, parseCachedHeader, permalink, renderMessage, renderPromptParams, setFetch, setMaskingFunction, spanComponentsToObjectId, startSpan, summarize, traceable, traced, updateSpan, withCurrent, withDataset, withExperiment, withLogger, withParent, wrapOpenAI, wrapOpenAIv4, wrapTraced };
package/dist/browser.js CHANGED
@@ -6906,7 +6906,7 @@ function resetIdGenStateForTests() {
6906
6906
  state.resetIdGenState();
6907
6907
  }
6908
6908
  }
6909
- var BRAINTRUST_ATTACHMENT, EXTERNAL_ATTACHMENT, BRAINTRUST_PARAMS, REDACTION_FIELDS, MaskingError, ContextManager, BraintrustContextManager, NoopSpan, NOOP_SPAN, NOOP_SPAN_PERMALINK, loginSchema, stateNonce, BraintrustState, _globalState, _internalGetGlobalState, FailedHTTPResponse, HTTPConnection, BaseAttachment, Attachment, ExternalAttachment, attachmentMetadataSchema, ReadonlyAttachment, ERR_PERMALINK, Logger, TestBackgroundLogger, BACKGROUND_LOGGER_BASE_SLEEP_TIME_S, HTTPBackgroundLogger, traceable, INTERNAL_BTQL_LIMIT, MAX_BTQL_ITERATIONS, ObjectFetcher, Experiment2, ReadonlyExperiment, executionCounter, SpanImpl, Dataset2, Prompt2, TEST_API_KEY, _exportsForTestingOnly;
6909
+ var BRAINTRUST_ATTACHMENT, EXTERNAL_ATTACHMENT, BRAINTRUST_PARAMS, REDACTION_FIELDS, MaskingError, ContextManager, BraintrustContextManager, NoopSpan, NOOP_SPAN, NOOP_SPAN_PERMALINK, loginSchema, stateNonce, BraintrustState, _globalState, _internalGetGlobalState, FailedHTTPResponse, HTTPConnection, BaseAttachment, Attachment, ExternalAttachment, attachmentMetadataSchema, ReadonlyAttachment, JSONAttachment, ERR_PERMALINK, Logger, TestBackgroundLogger, BACKGROUND_LOGGER_BASE_SLEEP_TIME_S, HTTPBackgroundLogger, traceable, INTERNAL_BTQL_LIMIT, MAX_BTQL_ITERATIONS, ObjectFetcher, Experiment2, ReadonlyExperiment, executionCounter, SpanImpl, Dataset2, Prompt2, TEST_API_KEY, _exportsForTestingOnly;
6910
6910
  var init_logger = __esm({
6911
6911
  "src/logger.ts"() {
6912
6912
  "use strict";
@@ -7779,6 +7779,44 @@ with a Blob/ArrayBuffer, or run the program on Node.js.`
7779
7779
  return new LazyValue(download);
7780
7780
  }
7781
7781
  };
7782
+ JSONAttachment = exports.JSONAttachment = class extends Attachment {
7783
+ /**
7784
+ * Construct a JSONAttachment from a JSON-serializable object.
7785
+ *
7786
+ * @param data The JSON object to attach. Must be JSON-serializable.
7787
+ * @param options Additional options:
7788
+ * - `filename`: The filename for the attachment (defaults to "data.json")
7789
+ * - `pretty`: Whether to pretty-print the JSON (defaults to false)
7790
+ * - `state`: (Optional) For internal use.
7791
+ *
7792
+ * @example
7793
+ * ```typescript
7794
+ * const largeTranscript = [
7795
+ * { role: "user", content: "..." },
7796
+ * { role: "assistant", content: "..." },
7797
+ * // ... many more messages
7798
+ * ];
7799
+ *
7800
+ * logger.log({
7801
+ * input: {
7802
+ * type: "chat",
7803
+ * transcript: new JSONAttachment(largeTranscript, { filename: "transcript.json" })
7804
+ * }
7805
+ * });
7806
+ * ```
7807
+ */
7808
+ constructor(data, options) {
7809
+ const { filename = "data.json", pretty = false, state } = _nullishCoalesce(options, () => ( {}));
7810
+ const jsonString = pretty ? JSON.stringify(data, null, 2) : JSON.stringify(data);
7811
+ const blob = new Blob([jsonString], { type: "application/json" });
7812
+ super({
7813
+ data: blob,
7814
+ filename,
7815
+ contentType: "application/json",
7816
+ state
7817
+ });
7818
+ }
7819
+ };
7782
7820
  ERR_PERMALINK = exports.ERR_PERMALINK = "https://braintrust.dev/error-generating-link";
7783
7821
  Logger = exports.Logger = (_class6 = class {
7784
7822
 
@@ -7812,6 +7850,9 @@ with a Blob/ArrayBuffer, or run the program on Node.js.`
7812
7850
  get id() {
7813
7851
  return (async () => (await this.project).id)();
7814
7852
  }
7853
+ get loggingState() {
7854
+ return this.state;
7855
+ }
7815
7856
  parentObjectType() {
7816
7857
  return 2 /* PROJECT_LOGS */;
7817
7858
  }
@@ -8525,6 +8566,9 @@ Error: ${errorText}`;
8525
8566
  return (await this.lazyMetadata.get()).experiment.id;
8526
8567
  })();
8527
8568
  }
8569
+ get loggingState() {
8570
+ return this.state;
8571
+ }
8528
8572
  /**
8529
8573
  * Wait for the experiment ID to be resolved. This is useful for ensuring the ID
8530
8574
  * is available synchronously in child spans (for OTEL parent attributes).
@@ -8790,6 +8834,9 @@ View complete results in Braintrust or run experiment.summarize() again.`
8790
8834
  return (await this.lazyMetadata.get()).experiment.name;
8791
8835
  })();
8792
8836
  }
8837
+ get loggingState() {
8838
+ return this.state;
8839
+ }
8793
8840
  async getState() {
8794
8841
  await this.lazyMetadata.get();
8795
8842
  return this.state;
@@ -9178,6 +9225,9 @@ View complete results in Braintrust or run experiment.summarize() again.`
9178
9225
  return (await this.lazyMetadata.get()).project;
9179
9226
  })();
9180
9227
  }
9228
+ get loggingState() {
9229
+ return this.state;
9230
+ }
9181
9231
  async getState() {
9182
9232
  await this.lazyMetadata.get();
9183
9233
  return this.state;
@@ -9668,6 +9718,7 @@ __export(exports_browser_exports, {
9668
9718
  ExternalAttachment: () => ExternalAttachment,
9669
9719
  FailedHTTPResponse: () => FailedHTTPResponse,
9670
9720
  INTERNAL_BTQL_LIMIT: () => INTERNAL_BTQL_LIMIT,
9721
+ JSONAttachment: () => JSONAttachment,
9671
9722
  LEGACY_CACHED_HEADER: () => LEGACY_CACHED_HEADER,
9672
9723
  LazyValue: () => LazyValue,
9673
9724
  Logger: () => Logger,
@@ -10697,4 +10748,5 @@ var browser_default = exports_browser_exports;
10697
10748
 
10698
10749
 
10699
10750
 
10700
- exports.Attachment = Attachment; exports.BaseAttachment = BaseAttachment; exports.BraintrustState = BraintrustState; exports.BraintrustStream = BraintrustStream; exports.ContextManager = ContextManager; exports.Dataset = Dataset2; exports.ERR_PERMALINK = ERR_PERMALINK; exports.Experiment = Experiment2; exports.ExternalAttachment = ExternalAttachment; exports.FailedHTTPResponse = FailedHTTPResponse; exports.INTERNAL_BTQL_LIMIT = INTERNAL_BTQL_LIMIT; exports.LEGACY_CACHED_HEADER = LEGACY_CACHED_HEADER; exports.LazyValue = LazyValue; exports.Logger = Logger; exports.NOOP_SPAN = NOOP_SPAN; exports.NOOP_SPAN_PERMALINK = NOOP_SPAN_PERMALINK; exports.NoopSpan = NoopSpan; exports.Prompt = Prompt2; exports.ReadonlyAttachment = ReadonlyAttachment; exports.ReadonlyExperiment = ReadonlyExperiment; exports.SpanImpl = SpanImpl; exports.TestBackgroundLogger = TestBackgroundLogger; exports.X_CACHED_HEADER = X_CACHED_HEADER; exports._exportsForTestingOnly = _exportsForTestingOnly; exports._internalGetGlobalState = _internalGetGlobalState; exports._internalSetInitialState = _internalSetInitialState; exports.braintrustStreamChunkSchema = braintrustStreamChunkSchema; exports.createFinalValuePassThroughStream = createFinalValuePassThroughStream; exports.currentExperiment = currentExperiment; exports.currentLogger = currentLogger; exports.currentSpan = currentSpan; exports.deepCopyEvent = deepCopyEvent; exports.default = browser_default; exports.deserializePlainStringAsJSON = deserializePlainStringAsJSON; exports.devNullWritableStream = devNullWritableStream; exports.evaluatorDefinitionSchema = evaluatorDefinitionSchema; exports.evaluatorDefinitionsSchema = evaluatorDefinitionsSchema; exports.flush = flush; exports.getContextManager = getContextManager; exports.getPromptVersions = getPromptVersions; exports.getSpanParentObject = getSpanParentObject; exports.init = init; exports.initDataset = initDataset; exports.initExperiment = initExperiment; exports.initFunction = initFunction; exports.initLogger = initLogger; exports.invoke = invoke; exports.loadPrompt = loadPrompt; exports.log = log; exports.logError = logError; exports.login = login; exports.loginToState = loginToState; exports.newId = newId; exports.parseCachedHeader = parseCachedHeader; exports.permalink = permalink; exports.renderMessage = renderMessage; exports.renderPromptParams = renderPromptParams; exports.setFetch = setFetch; exports.setMaskingFunction = setMaskingFunction; exports.spanComponentsToObjectId = spanComponentsToObjectId; exports.startSpan = startSpan; exports.summarize = summarize; exports.traceable = traceable; exports.traced = traced; exports.updateSpan = updateSpan; exports.withCurrent = withCurrent; exports.withDataset = withDataset; exports.withExperiment = withExperiment; exports.withLogger = withLogger; exports.withParent = withParent; exports.wrapOpenAI = wrapOpenAI; exports.wrapOpenAIv4 = wrapOpenAIv4; exports.wrapTraced = wrapTraced;
10751
+
10752
+ exports.Attachment = Attachment; exports.BaseAttachment = BaseAttachment; exports.BraintrustState = BraintrustState; exports.BraintrustStream = BraintrustStream; exports.ContextManager = ContextManager; exports.Dataset = Dataset2; exports.ERR_PERMALINK = ERR_PERMALINK; exports.Experiment = Experiment2; exports.ExternalAttachment = ExternalAttachment; exports.FailedHTTPResponse = FailedHTTPResponse; exports.INTERNAL_BTQL_LIMIT = INTERNAL_BTQL_LIMIT; exports.JSONAttachment = JSONAttachment; exports.LEGACY_CACHED_HEADER = LEGACY_CACHED_HEADER; exports.LazyValue = LazyValue; exports.Logger = Logger; exports.NOOP_SPAN = NOOP_SPAN; exports.NOOP_SPAN_PERMALINK = NOOP_SPAN_PERMALINK; exports.NoopSpan = NoopSpan; exports.Prompt = Prompt2; exports.ReadonlyAttachment = ReadonlyAttachment; exports.ReadonlyExperiment = ReadonlyExperiment; exports.SpanImpl = SpanImpl; exports.TestBackgroundLogger = TestBackgroundLogger; exports.X_CACHED_HEADER = X_CACHED_HEADER; exports._exportsForTestingOnly = _exportsForTestingOnly; exports._internalGetGlobalState = _internalGetGlobalState; exports._internalSetInitialState = _internalSetInitialState; exports.braintrustStreamChunkSchema = braintrustStreamChunkSchema; exports.createFinalValuePassThroughStream = createFinalValuePassThroughStream; exports.currentExperiment = currentExperiment; exports.currentLogger = currentLogger; exports.currentSpan = currentSpan; exports.deepCopyEvent = deepCopyEvent; exports.default = browser_default; exports.deserializePlainStringAsJSON = deserializePlainStringAsJSON; exports.devNullWritableStream = devNullWritableStream; exports.evaluatorDefinitionSchema = evaluatorDefinitionSchema; exports.evaluatorDefinitionsSchema = evaluatorDefinitionsSchema; exports.flush = flush; exports.getContextManager = getContextManager; exports.getPromptVersions = getPromptVersions; exports.getSpanParentObject = getSpanParentObject; exports.init = init; exports.initDataset = initDataset; exports.initExperiment = initExperiment; exports.initFunction = initFunction; exports.initLogger = initLogger; exports.invoke = invoke; exports.loadPrompt = loadPrompt; exports.log = log; exports.logError = logError; exports.login = login; exports.loginToState = loginToState; exports.newId = newId; exports.parseCachedHeader = parseCachedHeader; exports.permalink = permalink; exports.renderMessage = renderMessage; exports.renderPromptParams = renderPromptParams; exports.setFetch = setFetch; exports.setMaskingFunction = setMaskingFunction; exports.spanComponentsToObjectId = spanComponentsToObjectId; exports.startSpan = startSpan; exports.summarize = summarize; exports.traceable = traceable; exports.traced = traced; exports.updateSpan = updateSpan; exports.withCurrent = withCurrent; exports.withDataset = withDataset; exports.withExperiment = withExperiment; exports.withLogger = withLogger; exports.withParent = withParent; exports.wrapOpenAI = wrapOpenAI; exports.wrapOpenAIv4 = wrapOpenAIv4; exports.wrapTraced = wrapTraced;
package/dist/browser.mjs CHANGED
@@ -6906,7 +6906,7 @@ function resetIdGenStateForTests() {
6906
6906
  state.resetIdGenState();
6907
6907
  }
6908
6908
  }
6909
- var BRAINTRUST_ATTACHMENT, EXTERNAL_ATTACHMENT, BRAINTRUST_PARAMS, REDACTION_FIELDS, MaskingError, ContextManager, BraintrustContextManager, NoopSpan, NOOP_SPAN, NOOP_SPAN_PERMALINK, loginSchema, stateNonce, BraintrustState, _globalState, _internalGetGlobalState, FailedHTTPResponse, HTTPConnection, BaseAttachment, Attachment, ExternalAttachment, attachmentMetadataSchema, ReadonlyAttachment, ERR_PERMALINK, Logger, TestBackgroundLogger, BACKGROUND_LOGGER_BASE_SLEEP_TIME_S, HTTPBackgroundLogger, traceable, INTERNAL_BTQL_LIMIT, MAX_BTQL_ITERATIONS, ObjectFetcher, Experiment2, ReadonlyExperiment, executionCounter, SpanImpl, Dataset2, Prompt2, TEST_API_KEY, _exportsForTestingOnly;
6909
+ var BRAINTRUST_ATTACHMENT, EXTERNAL_ATTACHMENT, BRAINTRUST_PARAMS, REDACTION_FIELDS, MaskingError, ContextManager, BraintrustContextManager, NoopSpan, NOOP_SPAN, NOOP_SPAN_PERMALINK, loginSchema, stateNonce, BraintrustState, _globalState, _internalGetGlobalState, FailedHTTPResponse, HTTPConnection, BaseAttachment, Attachment, ExternalAttachment, attachmentMetadataSchema, ReadonlyAttachment, JSONAttachment, ERR_PERMALINK, Logger, TestBackgroundLogger, BACKGROUND_LOGGER_BASE_SLEEP_TIME_S, HTTPBackgroundLogger, traceable, INTERNAL_BTQL_LIMIT, MAX_BTQL_ITERATIONS, ObjectFetcher, Experiment2, ReadonlyExperiment, executionCounter, SpanImpl, Dataset2, Prompt2, TEST_API_KEY, _exportsForTestingOnly;
6910
6910
  var init_logger = __esm({
6911
6911
  "src/logger.ts"() {
6912
6912
  "use strict";
@@ -7779,6 +7779,44 @@ with a Blob/ArrayBuffer, or run the program on Node.js.`
7779
7779
  return new LazyValue(download);
7780
7780
  }
7781
7781
  };
7782
+ JSONAttachment = class extends Attachment {
7783
+ /**
7784
+ * Construct a JSONAttachment from a JSON-serializable object.
7785
+ *
7786
+ * @param data The JSON object to attach. Must be JSON-serializable.
7787
+ * @param options Additional options:
7788
+ * - `filename`: The filename for the attachment (defaults to "data.json")
7789
+ * - `pretty`: Whether to pretty-print the JSON (defaults to false)
7790
+ * - `state`: (Optional) For internal use.
7791
+ *
7792
+ * @example
7793
+ * ```typescript
7794
+ * const largeTranscript = [
7795
+ * { role: "user", content: "..." },
7796
+ * { role: "assistant", content: "..." },
7797
+ * // ... many more messages
7798
+ * ];
7799
+ *
7800
+ * logger.log({
7801
+ * input: {
7802
+ * type: "chat",
7803
+ * transcript: new JSONAttachment(largeTranscript, { filename: "transcript.json" })
7804
+ * }
7805
+ * });
7806
+ * ```
7807
+ */
7808
+ constructor(data, options) {
7809
+ const { filename = "data.json", pretty = false, state } = options ?? {};
7810
+ const jsonString = pretty ? JSON.stringify(data, null, 2) : JSON.stringify(data);
7811
+ const blob = new Blob([jsonString], { type: "application/json" });
7812
+ super({
7813
+ data: blob,
7814
+ filename,
7815
+ contentType: "application/json",
7816
+ state
7817
+ });
7818
+ }
7819
+ };
7782
7820
  ERR_PERMALINK = "https://braintrust.dev/error-generating-link";
7783
7821
  Logger = class {
7784
7822
  state;
@@ -7812,6 +7850,9 @@ with a Blob/ArrayBuffer, or run the program on Node.js.`
7812
7850
  get id() {
7813
7851
  return (async () => (await this.project).id)();
7814
7852
  }
7853
+ get loggingState() {
7854
+ return this.state;
7855
+ }
7815
7856
  parentObjectType() {
7816
7857
  return 2 /* PROJECT_LOGS */;
7817
7858
  }
@@ -8525,6 +8566,9 @@ Error: ${errorText}`;
8525
8566
  return (await this.lazyMetadata.get()).experiment.id;
8526
8567
  })();
8527
8568
  }
8569
+ get loggingState() {
8570
+ return this.state;
8571
+ }
8528
8572
  /**
8529
8573
  * Wait for the experiment ID to be resolved. This is useful for ensuring the ID
8530
8574
  * is available synchronously in child spans (for OTEL parent attributes).
@@ -8790,6 +8834,9 @@ View complete results in Braintrust or run experiment.summarize() again.`
8790
8834
  return (await this.lazyMetadata.get()).experiment.name;
8791
8835
  })();
8792
8836
  }
8837
+ get loggingState() {
8838
+ return this.state;
8839
+ }
8793
8840
  async getState() {
8794
8841
  await this.lazyMetadata.get();
8795
8842
  return this.state;
@@ -9178,6 +9225,9 @@ View complete results in Braintrust or run experiment.summarize() again.`
9178
9225
  return (await this.lazyMetadata.get()).project;
9179
9226
  })();
9180
9227
  }
9228
+ get loggingState() {
9229
+ return this.state;
9230
+ }
9181
9231
  async getState() {
9182
9232
  await this.lazyMetadata.get();
9183
9233
  return this.state;
@@ -9668,6 +9718,7 @@ __export(exports_browser_exports, {
9668
9718
  ExternalAttachment: () => ExternalAttachment,
9669
9719
  FailedHTTPResponse: () => FailedHTTPResponse,
9670
9720
  INTERNAL_BTQL_LIMIT: () => INTERNAL_BTQL_LIMIT,
9721
+ JSONAttachment: () => JSONAttachment,
9671
9722
  LEGACY_CACHED_HEADER: () => LEGACY_CACHED_HEADER,
9672
9723
  LazyValue: () => LazyValue,
9673
9724
  Logger: () => Logger,
@@ -10635,6 +10686,7 @@ export {
10635
10686
  ExternalAttachment,
10636
10687
  FailedHTTPResponse,
10637
10688
  INTERNAL_BTQL_LIMIT,
10689
+ JSONAttachment,
10638
10690
  LEGACY_CACHED_HEADER,
10639
10691
  LazyValue,
10640
10692
  Logger,
package/dist/cli.js CHANGED
@@ -8449,6 +8449,9 @@ with a Blob/ArrayBuffer, or run the program on Node.js.`
8449
8449
  get id() {
8450
8450
  return (async () => (await this.project).id)();
8451
8451
  }
8452
+ get loggingState() {
8453
+ return this.state;
8454
+ }
8452
8455
  parentObjectType() {
8453
8456
  return 2 /* PROJECT_LOGS */;
8454
8457
  }
@@ -9109,6 +9112,9 @@ Error: ${errorText}`;
9109
9112
  return (await this.lazyMetadata.get()).experiment.id;
9110
9113
  })();
9111
9114
  }
9115
+ get loggingState() {
9116
+ return this.state;
9117
+ }
9112
9118
  /**
9113
9119
  * Wait for the experiment ID to be resolved. This is useful for ensuring the ID
9114
9120
  * is available synchronously in child spans (for OTEL parent attributes).
@@ -9374,6 +9380,9 @@ View complete results in Braintrust or run experiment.summarize() again.`
9374
9380
  return (await this.lazyMetadata.get()).experiment.name;
9375
9381
  })();
9376
9382
  }
9383
+ get loggingState() {
9384
+ return this.state;
9385
+ }
9377
9386
  async getState() {
9378
9387
  await this.lazyMetadata.get();
9379
9388
  return this.state;
@@ -9762,6 +9771,9 @@ View complete results in Braintrust or run experiment.summarize() again.`
9762
9771
  return (await this.lazyMetadata.get()).project;
9763
9772
  })();
9764
9773
  }
9774
+ get loggingState() {
9775
+ return this.state;
9776
+ }
9765
9777
  async getState() {
9766
9778
  await this.lazyMetadata.get();
9767
9779
  return this.state;
@@ -10196,7 +10208,7 @@ var require_package = __commonJS({
10196
10208
  "package.json"(exports2, module2) {
10197
10209
  module2.exports = {
10198
10210
  name: "braintrust",
10199
- version: "0.4.2",
10211
+ version: "0.4.3",
10200
10212
  description: "SDK for integrating Braintrust",
10201
10213
  repository: {
10202
10214
  type: "git",
package/dist/index.d.mts CHANGED
@@ -14876,6 +14876,48 @@ declare class ReadonlyAttachment {
14876
14876
  status(): Promise<AttachmentStatusType>;
14877
14877
  private initDownloader;
14878
14878
  }
14879
+ /**
14880
+ * Represents a JSON object that should be stored as an attachment.
14881
+ *
14882
+ * `JSONAttachment` is a convenience function that creates an `Attachment`
14883
+ * from JSON data. It's particularly useful for large JSON objects that
14884
+ * would otherwise bloat the trace size.
14885
+ *
14886
+ * The JSON data is automatically serialized and stored as an attachment
14887
+ * with content type "application/json".
14888
+ */
14889
+ declare class JSONAttachment extends Attachment {
14890
+ /**
14891
+ * Construct a JSONAttachment from a JSON-serializable object.
14892
+ *
14893
+ * @param data The JSON object to attach. Must be JSON-serializable.
14894
+ * @param options Additional options:
14895
+ * - `filename`: The filename for the attachment (defaults to "data.json")
14896
+ * - `pretty`: Whether to pretty-print the JSON (defaults to false)
14897
+ * - `state`: (Optional) For internal use.
14898
+ *
14899
+ * @example
14900
+ * ```typescript
14901
+ * const largeTranscript = [
14902
+ * { role: "user", content: "..." },
14903
+ * { role: "assistant", content: "..." },
14904
+ * // ... many more messages
14905
+ * ];
14906
+ *
14907
+ * logger.log({
14908
+ * input: {
14909
+ * type: "chat",
14910
+ * transcript: new JSONAttachment(largeTranscript, { filename: "transcript.json" })
14911
+ * }
14912
+ * });
14913
+ * ```
14914
+ */
14915
+ constructor(data: unknown, options?: {
14916
+ filename?: string;
14917
+ pretty?: boolean;
14918
+ state?: BraintrustState;
14919
+ });
14920
+ }
14879
14921
  /**
14880
14922
  * Update a span using the output of `span.export()`. It is important that you only resume updating
14881
14923
  * to a span once the original span has been fully written and flushed, since otherwise updates to
@@ -14935,6 +14977,7 @@ declare class Logger<IsAsyncFlush extends boolean> implements Exportable {
14935
14977
  get org_id(): Promise<string>;
14936
14978
  get project(): Promise<ObjectMetadata>;
14937
14979
  get id(): Promise<string>;
14980
+ get loggingState(): BraintrustState;
14938
14981
  private parentObjectType;
14939
14982
  /**
14940
14983
  * Log a single event. The event will be batched and uploaded behind the scenes if `logOptions.asyncFlush` is true.
@@ -15486,6 +15529,7 @@ declare class Experiment extends ObjectFetcher<ExperimentEvent> implements Expor
15486
15529
  kind: "experiment";
15487
15530
  constructor(state: BraintrustState, lazyMetadata: LazyValue<ProjectExperimentMetadata>, dataset?: AnyDataset);
15488
15531
  get id(): Promise<string>;
15532
+ get loggingState(): BraintrustState;
15489
15533
  /**
15490
15534
  * Wait for the experiment ID to be resolved. This is useful for ensuring the ID
15491
15535
  * is available synchronously in child spans (for OTEL parent attributes).
@@ -15590,6 +15634,7 @@ declare class ReadonlyExperiment extends ObjectFetcher<ExperimentEvent> {
15590
15634
  constructor(state: BraintrustState, lazyMetadata: LazyValue<ProjectExperimentMetadata>);
15591
15635
  get id(): Promise<string>;
15592
15636
  get name(): Promise<string>;
15637
+ get loggingState(): BraintrustState;
15593
15638
  protected getState(): Promise<BraintrustState>;
15594
15639
  asDataset<Input, Expected, Metadata = DefaultMetadataType>(): AsyncGenerator<EvalCase<Input, Expected, Metadata>>;
15595
15640
  }
@@ -15665,6 +15710,7 @@ declare class Dataset<IsLegacyDataset extends boolean = typeof DEFAULT_IS_LEGACY
15665
15710
  get id(): Promise<string>;
15666
15711
  get name(): Promise<string>;
15667
15712
  get project(): Promise<ObjectMetadata>;
15713
+ get loggingState(): BraintrustState;
15668
15714
  protected getState(): Promise<BraintrustState>;
15669
15715
  private validateEvent;
15670
15716
  private createArgs;
@@ -21702,6 +21748,8 @@ declare const braintrust_INTERNAL_BTQL_LIMIT: typeof INTERNAL_BTQL_LIMIT;
21702
21748
  type braintrust_InitOptions<IsOpen extends boolean> = InitOptions<IsOpen>;
21703
21749
  type braintrust_InvokeFunctionArgs<Input, Output, Stream extends boolean = false> = InvokeFunctionArgs<Input, Output, Stream>;
21704
21750
  type braintrust_InvokeReturn<Stream extends boolean, Output> = InvokeReturn<Stream, Output>;
21751
+ type braintrust_JSONAttachment = JSONAttachment;
21752
+ declare const braintrust_JSONAttachment: typeof JSONAttachment;
21705
21753
  declare const braintrust_LEGACY_CACHED_HEADER: typeof LEGACY_CACHED_HEADER;
21706
21754
  type braintrust_LazyValue<T> = LazyValue<T>;
21707
21755
  declare const braintrust_LazyValue: typeof LazyValue;
@@ -21818,7 +21866,7 @@ declare const braintrust_wrapOpenAI: typeof wrapOpenAI;
21818
21866
  declare const braintrust_wrapOpenAIv4: typeof wrapOpenAIv4;
21819
21867
  declare const braintrust_wrapTraced: typeof wrapTraced;
21820
21868
  declare namespace braintrust {
21821
- export { braintrust_AISpanProcessor as AISpanProcessor, type braintrust_AnyDataset as AnyDataset, braintrust_Attachment as Attachment, type braintrust_AttachmentParams as AttachmentParams, type braintrust_BackgroundLoggerOpts as BackgroundLoggerOpts, braintrust_BaseAttachment as BaseAttachment, braintrust_BaseExperiment as BaseExperiment, type braintrust_BaseMetadata as BaseMetadata, braintrust_BraintrustExporter as BraintrustExporter, braintrust_BraintrustMiddleware as BraintrustMiddleware, braintrust_BraintrustSpanProcessor as BraintrustSpanProcessor, braintrust_BraintrustState as BraintrustState, braintrust_BraintrustStream as BraintrustStream, type braintrust_BraintrustStreamChunk as BraintrustStreamChunk, type braintrust_ChatPrompt as ChatPrompt, braintrust_CodeFunction as CodeFunction, type braintrust_CodeOpts as CodeOpts, braintrust_CodePrompt as CodePrompt, type braintrust_CompiledPrompt as CompiledPrompt, type braintrust_CompiledPromptParams as CompiledPromptParams, type braintrust_CompletionPrompt as CompletionPrompt, braintrust_ContextManager as ContextManager, type braintrust_ContextParentSpanIds as ContextParentSpanIds, type braintrust_CreateProjectOpts as CreateProjectOpts, type braintrust_DataSummary as DataSummary, braintrust_Dataset as Dataset, type braintrust_DatasetSummary as DatasetSummary, type braintrust_DefaultMetadataType as DefaultMetadataType, type braintrust_DefaultPromptArgs as DefaultPromptArgs, braintrust_ERR_PERMALINK as ERR_PERMALINK, type braintrust_EndSpanArgs as EndSpanArgs, braintrust_Eval as Eval, type braintrust_EvalCase as EvalCase, type braintrust_EvalHooks as EvalHooks, type braintrust_EvalResult as EvalResult, braintrust_EvalResultWithSummary as EvalResultWithSummary, 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, type braintrust_ExperimentSummary as ExperimentSummary, type braintrust_Exportable as Exportable, braintrust_ExternalAttachment as ExternalAttachment, type braintrust_ExternalAttachmentParams as ExternalAttachmentParams, braintrust_FailedHTTPResponse as FailedHTTPResponse, type braintrust_FullInitOptions as FullInitOptions, type braintrust_FullLoginOptions as FullLoginOptions, type braintrust_FunctionEvent as FunctionEvent, braintrust_IDGenerator as IDGenerator, braintrust_INTERNAL_BTQL_LIMIT as INTERNAL_BTQL_LIMIT, type braintrust_InitOptions as InitOptions, type braintrust_InvokeFunctionArgs as InvokeFunctionArgs, type braintrust_InvokeReturn as InvokeReturn, braintrust_LEGACY_CACHED_HEADER as LEGACY_CACHED_HEADER, braintrust_LazyValue as LazyValue, 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_NOOP_SPAN_PERMALINK as NOOP_SPAN_PERMALINK, braintrust_NoopSpan as NoopSpan, braintrust_OTELIDGenerator as OTELIDGenerator, type braintrust_ObjectMetadata as ObjectMetadata, braintrust_Project as Project, braintrust_ProjectNameIdMap as ProjectNameIdMap, type braintrust_PromiseUnless as PromiseUnless, braintrust_Prompt as Prompt, braintrust_PromptBuilder as PromptBuilder, type braintrust_PromptContents as PromptContents, type braintrust_PromptDefinition as PromptDefinition, type braintrust_PromptDefinitionWithTools as PromptDefinitionWithTools, type braintrust_PromptOpts as PromptOpts, type braintrust_PromptRowWithId as PromptRowWithId, braintrust_ReadonlyAttachment as ReadonlyAttachment, braintrust_ReadonlyExperiment as ReadonlyExperiment, braintrust_Reporter as Reporter, type braintrust_ReporterBody as ReporterBody, type braintrust_ScoreSummary as ScoreSummary, braintrust_ScorerBuilder as ScorerBuilder, type braintrust_ScorerOpts as ScorerOpts, type braintrust_SerializedBraintrustState as SerializedBraintrustState, type braintrust_SetCurrentArg as SetCurrentArg, type Span$1 as Span, type braintrust_SpanContext as SpanContext, braintrust_SpanImpl as SpanImpl, type braintrust_StartSpanArgs as StartSpanArgs, braintrust_TestBackgroundLogger as TestBackgroundLogger, braintrust_ToolBuilder as ToolBuilder, braintrust_UUIDGenerator as UUIDGenerator, 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_deepCopyEvent as deepCopyEvent, braintrust_defaultErrorScoreHandler as defaultErrorScoreHandler, braintrust_deserializePlainStringAsJSON as deserializePlainStringAsJSON, braintrust_devNullWritableStream as devNullWritableStream, braintrust_flush as flush, braintrust_getContextManager as getContextManager, braintrust_getIdGenerator as getIdGenerator, braintrust_getPromptVersions as getPromptVersions, braintrust_getSpanParentObject as getSpanParentObject, graphFramework as graph, braintrust_init as init, braintrust_initDataset as initDataset, braintrust_initExperiment as initExperiment, braintrust_initFunction as initFunction, 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_promptContentsSchema as promptContentsSchema, braintrust_promptDefinitionSchema as promptDefinitionSchema, braintrust_promptDefinitionToPromptData as promptDefinitionToPromptData, braintrust_promptDefinitionWithToolsSchema as promptDefinitionWithToolsSchema, braintrust_renderMessage as renderMessage, braintrust_renderPromptParams as renderPromptParams, braintrust_reportFailures as reportFailures, braintrust_runEvaluator as runEvaluator, braintrust_setFetch as setFetch, braintrust_setMaskingFunction as setMaskingFunction, braintrust_spanComponentsToObjectId as spanComponentsToObjectId, braintrust_startSpan as startSpan, braintrust_summarize as summarize, ToolFunctionDefinition 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_withParent as withParent, braintrust_wrapAISDK as wrapAISDK, braintrust_wrapAISDKModel as wrapAISDKModel, braintrust_wrapAnthropic as wrapAnthropic, braintrust_wrapClaudeAgentSDK as wrapClaudeAgentSDK, braintrust_wrapMastraAgent as wrapMastraAgent, braintrust_wrapOpenAI as wrapOpenAI, braintrust_wrapOpenAIv4 as wrapOpenAIv4, braintrust_wrapTraced as wrapTraced };
21869
+ export { braintrust_AISpanProcessor as AISpanProcessor, type braintrust_AnyDataset as AnyDataset, braintrust_Attachment as Attachment, type braintrust_AttachmentParams as AttachmentParams, type braintrust_BackgroundLoggerOpts as BackgroundLoggerOpts, braintrust_BaseAttachment as BaseAttachment, braintrust_BaseExperiment as BaseExperiment, type braintrust_BaseMetadata as BaseMetadata, braintrust_BraintrustExporter as BraintrustExporter, braintrust_BraintrustMiddleware as BraintrustMiddleware, braintrust_BraintrustSpanProcessor as BraintrustSpanProcessor, braintrust_BraintrustState as BraintrustState, braintrust_BraintrustStream as BraintrustStream, type braintrust_BraintrustStreamChunk as BraintrustStreamChunk, type braintrust_ChatPrompt as ChatPrompt, braintrust_CodeFunction as CodeFunction, type braintrust_CodeOpts as CodeOpts, braintrust_CodePrompt as CodePrompt, type braintrust_CompiledPrompt as CompiledPrompt, type braintrust_CompiledPromptParams as CompiledPromptParams, type braintrust_CompletionPrompt as CompletionPrompt, braintrust_ContextManager as ContextManager, type braintrust_ContextParentSpanIds as ContextParentSpanIds, type braintrust_CreateProjectOpts as CreateProjectOpts, type braintrust_DataSummary as DataSummary, braintrust_Dataset as Dataset, type braintrust_DatasetSummary as DatasetSummary, type braintrust_DefaultMetadataType as DefaultMetadataType, type braintrust_DefaultPromptArgs as DefaultPromptArgs, braintrust_ERR_PERMALINK as ERR_PERMALINK, type braintrust_EndSpanArgs as EndSpanArgs, braintrust_Eval as Eval, type braintrust_EvalCase as EvalCase, type braintrust_EvalHooks as EvalHooks, type braintrust_EvalResult as EvalResult, braintrust_EvalResultWithSummary as EvalResultWithSummary, 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, type braintrust_ExperimentSummary as ExperimentSummary, type braintrust_Exportable as Exportable, braintrust_ExternalAttachment as ExternalAttachment, type braintrust_ExternalAttachmentParams as ExternalAttachmentParams, braintrust_FailedHTTPResponse as FailedHTTPResponse, type braintrust_FullInitOptions as FullInitOptions, type braintrust_FullLoginOptions as FullLoginOptions, type braintrust_FunctionEvent as FunctionEvent, braintrust_IDGenerator as IDGenerator, braintrust_INTERNAL_BTQL_LIMIT as INTERNAL_BTQL_LIMIT, type braintrust_InitOptions as InitOptions, type braintrust_InvokeFunctionArgs as InvokeFunctionArgs, type braintrust_InvokeReturn as InvokeReturn, braintrust_JSONAttachment as JSONAttachment, braintrust_LEGACY_CACHED_HEADER as LEGACY_CACHED_HEADER, braintrust_LazyValue as LazyValue, 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_NOOP_SPAN_PERMALINK as NOOP_SPAN_PERMALINK, braintrust_NoopSpan as NoopSpan, braintrust_OTELIDGenerator as OTELIDGenerator, type braintrust_ObjectMetadata as ObjectMetadata, braintrust_Project as Project, braintrust_ProjectNameIdMap as ProjectNameIdMap, type braintrust_PromiseUnless as PromiseUnless, braintrust_Prompt as Prompt, braintrust_PromptBuilder as PromptBuilder, type braintrust_PromptContents as PromptContents, type braintrust_PromptDefinition as PromptDefinition, type braintrust_PromptDefinitionWithTools as PromptDefinitionWithTools, type braintrust_PromptOpts as PromptOpts, type braintrust_PromptRowWithId as PromptRowWithId, braintrust_ReadonlyAttachment as ReadonlyAttachment, braintrust_ReadonlyExperiment as ReadonlyExperiment, braintrust_Reporter as Reporter, type braintrust_ReporterBody as ReporterBody, type braintrust_ScoreSummary as ScoreSummary, braintrust_ScorerBuilder as ScorerBuilder, type braintrust_ScorerOpts as ScorerOpts, type braintrust_SerializedBraintrustState as SerializedBraintrustState, type braintrust_SetCurrentArg as SetCurrentArg, type Span$1 as Span, type braintrust_SpanContext as SpanContext, braintrust_SpanImpl as SpanImpl, type braintrust_StartSpanArgs as StartSpanArgs, braintrust_TestBackgroundLogger as TestBackgroundLogger, braintrust_ToolBuilder as ToolBuilder, braintrust_UUIDGenerator as UUIDGenerator, 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_deepCopyEvent as deepCopyEvent, braintrust_defaultErrorScoreHandler as defaultErrorScoreHandler, braintrust_deserializePlainStringAsJSON as deserializePlainStringAsJSON, braintrust_devNullWritableStream as devNullWritableStream, braintrust_flush as flush, braintrust_getContextManager as getContextManager, braintrust_getIdGenerator as getIdGenerator, braintrust_getPromptVersions as getPromptVersions, braintrust_getSpanParentObject as getSpanParentObject, graphFramework as graph, braintrust_init as init, braintrust_initDataset as initDataset, braintrust_initExperiment as initExperiment, braintrust_initFunction as initFunction, 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_promptContentsSchema as promptContentsSchema, braintrust_promptDefinitionSchema as promptDefinitionSchema, braintrust_promptDefinitionToPromptData as promptDefinitionToPromptData, braintrust_promptDefinitionWithToolsSchema as promptDefinitionWithToolsSchema, braintrust_renderMessage as renderMessage, braintrust_renderPromptParams as renderPromptParams, braintrust_reportFailures as reportFailures, braintrust_runEvaluator as runEvaluator, braintrust_setFetch as setFetch, braintrust_setMaskingFunction as setMaskingFunction, braintrust_spanComponentsToObjectId as spanComponentsToObjectId, braintrust_startSpan as startSpan, braintrust_summarize as summarize, ToolFunctionDefinition 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_withParent as withParent, braintrust_wrapAISDK as wrapAISDK, braintrust_wrapAISDKModel as wrapAISDKModel, braintrust_wrapAnthropic as wrapAnthropic, braintrust_wrapClaudeAgentSDK as wrapClaudeAgentSDK, braintrust_wrapMastraAgent as wrapMastraAgent, braintrust_wrapOpenAI as wrapOpenAI, braintrust_wrapOpenAIv4 as wrapOpenAIv4, braintrust_wrapTraced as wrapTraced };
21822
21870
  }
21823
21871
 
21824
21872
  type EvaluatorManifest = Record<string, EvaluatorDef<unknown, unknown, unknown, BaseMetadata>>;
@@ -28875,4 +28923,4 @@ type EvaluatorDefinitions = z.infer<typeof evaluatorDefinitionsSchema>;
28875
28923
  * @module braintrust
28876
28924
  */
28877
28925
 
28878
- export { AISpanProcessor, type AnyDataset, Attachment, type AttachmentParams, type BackgroundLoggerOpts, BaseAttachment, BaseExperiment, type BaseMetadata, BraintrustExporter, BraintrustMiddleware, BraintrustSpanProcessor, BraintrustState, BraintrustStream, type BraintrustStreamChunk, type ChatPrompt, CodeFunction, type CodeOpts, CodePrompt, type CommentEvent, type CompiledPrompt, type CompiledPromptParams, type CompletionPrompt, ContextManager, type ContextParentSpanIds, type CreateProjectOpts, type DataSummary, Dataset, type DatasetRecord, type DatasetSummary, type DefaultMetadataType, type DefaultPromptArgs, ERR_PERMALINK, type EndSpanArgs, Eval, type EvalCase, type EvalHooks, type EvalParameterSerializedSchema, type EvalParameters, type EvalResult, EvalResultWithSummary, type EvalScorer, type EvalScorerArgs, type EvalTask, type Evaluator, type EvaluatorDef, type EvaluatorDefinition, type EvaluatorDefinitions, type EvaluatorFile, type EvaluatorManifest, Experiment, type ExperimentLogFullArgs, type ExperimentLogPartialArgs, type ExperimentSummary, type Exportable, ExternalAttachment, type ExternalAttachmentParams, FailedHTTPResponse, type FullInitOptions, type FullLoginOptions, type FunctionEvent, IDGenerator, INTERNAL_BTQL_LIMIT, type IdField, type InitOptions, type InputField, type InvokeFunctionArgs, type InvokeReturn, LEGACY_CACHED_HEADER, LazyValue, type LogCommentFullArgs, type LogFeedbackFullArgs, type LogOptions, Logger, type LoginOptions, type MetricSummary, NOOP_SPAN, NOOP_SPAN_PERMALINK, NoopSpan, OTELIDGenerator, type ObjectMetadata, type OtherExperimentLogFields, type ParentExperimentIds, type ParentProjectLogIds, Project, ProjectNameIdMap, type PromiseUnless, Prompt, PromptBuilder, type PromptContents, type PromptDefinition, type PromptDefinitionWithTools, type PromptOpts, type PromptRowWithId, ReadonlyAttachment, ReadonlyExperiment, Reporter, type ReporterBody, type ScoreSummary, ScorerBuilder, type ScorerOpts, type SerializedBraintrustState, type SetCurrentArg, type Span$1 as Span, type SpanContext, SpanImpl, type StartSpanArgs, TestBackgroundLogger, ToolBuilder, UUIDGenerator, type WithTransactionId, X_CACHED_HEADER, _exportsForTestingOnly, _internalGetGlobalState, _internalSetInitialState, braintrustStreamChunkSchema, buildLocalSummary, createFinalValuePassThroughStream, currentExperiment, currentLogger, currentSpan, deepCopyEvent, braintrust as default, defaultErrorScoreHandler, deserializePlainStringAsJSON, devNullWritableStream, evaluatorDefinitionSchema, evaluatorDefinitionsSchema, flush, getContextManager, getIdGenerator, getPromptVersions, getSpanParentObject, graphFramework as graph, init, initDataset, initExperiment, initFunction, initLogger, invoke, loadPrompt, log, logError, login, loginToState, newId, parseCachedHeader, permalink, projects, promptContentsSchema, promptDefinitionSchema, promptDefinitionToPromptData, promptDefinitionWithToolsSchema, renderMessage, renderPromptParams, reportFailures, runEvaluator, setFetch, setMaskingFunction, spanComponentsToObjectId, startSpan, summarize, ToolFunctionDefinition as toolFunctionDefinitionSchema, traceable, traced, updateSpan, withCurrent, withDataset, withExperiment, withLogger, withParent, wrapAISDK, wrapAISDKModel, wrapAnthropic, wrapClaudeAgentSDK, wrapMastraAgent, wrapOpenAI, wrapOpenAIv4, wrapTraced };
28926
+ export { AISpanProcessor, type AnyDataset, Attachment, type AttachmentParams, AttachmentReference, type BackgroundLoggerOpts, BaseAttachment, BaseExperiment, type BaseMetadata, BraintrustExporter, BraintrustMiddleware, BraintrustSpanProcessor, BraintrustState, BraintrustStream, type BraintrustStreamChunk, type ChatPrompt, CodeFunction, type CodeOpts, CodePrompt, type CommentEvent, type CompiledPrompt, type CompiledPromptParams, type CompletionPrompt, ContextManager, type ContextParentSpanIds, type CreateProjectOpts, type DataSummary, Dataset, type DatasetRecord, type DatasetSummary, type DefaultMetadataType, type DefaultPromptArgs, ERR_PERMALINK, type EndSpanArgs, Eval, type EvalCase, type EvalHooks, type EvalParameterSerializedSchema, type EvalParameters, type EvalResult, EvalResultWithSummary, type EvalScorer, type EvalScorerArgs, type EvalTask, type Evaluator, type EvaluatorDef, type EvaluatorDefinition, type EvaluatorDefinitions, type EvaluatorFile, type EvaluatorManifest, Experiment, type ExperimentLogFullArgs, type ExperimentLogPartialArgs, type ExperimentSummary, type Exportable, ExternalAttachment, type ExternalAttachmentParams, FailedHTTPResponse, type FullInitOptions, type FullLoginOptions, type FunctionEvent, IDGenerator, INTERNAL_BTQL_LIMIT, type IdField, type InitOptions, type InputField, type InvokeFunctionArgs, type InvokeReturn, JSONAttachment, LEGACY_CACHED_HEADER, LazyValue, type LogCommentFullArgs, type LogFeedbackFullArgs, type LogOptions, Logger, type LoginOptions, type MetricSummary, NOOP_SPAN, NOOP_SPAN_PERMALINK, NoopSpan, OTELIDGenerator, type ObjectMetadata, type OtherExperimentLogFields, type ParentExperimentIds, type ParentProjectLogIds, Project, ProjectNameIdMap, type PromiseUnless, Prompt, PromptBuilder, type PromptContents, type PromptDefinition, type PromptDefinitionWithTools, type PromptOpts, type PromptRowWithId, ReadonlyAttachment, ReadonlyExperiment, Reporter, type ReporterBody, type ScoreSummary, ScorerBuilder, type ScorerOpts, type SerializedBraintrustState, type SetCurrentArg, type Span$1 as Span, type SpanContext, SpanImpl, type StartSpanArgs, TestBackgroundLogger, ToolBuilder, UUIDGenerator, type WithTransactionId, X_CACHED_HEADER, _exportsForTestingOnly, _internalGetGlobalState, _internalSetInitialState, braintrustStreamChunkSchema, buildLocalSummary, createFinalValuePassThroughStream, currentExperiment, currentLogger, currentSpan, deepCopyEvent, braintrust as default, defaultErrorScoreHandler, deserializePlainStringAsJSON, devNullWritableStream, evaluatorDefinitionSchema, evaluatorDefinitionsSchema, flush, getContextManager, getIdGenerator, getPromptVersions, getSpanParentObject, graphFramework as graph, init, initDataset, initExperiment, initFunction, initLogger, invoke, loadPrompt, log, logError, login, loginToState, newId, parseCachedHeader, permalink, projects, promptContentsSchema, promptDefinitionSchema, promptDefinitionToPromptData, promptDefinitionWithToolsSchema, renderMessage, renderPromptParams, reportFailures, runEvaluator, setFetch, setMaskingFunction, spanComponentsToObjectId, startSpan, summarize, ToolFunctionDefinition as toolFunctionDefinitionSchema, traceable, traced, updateSpan, withCurrent, withDataset, withExperiment, withLogger, withParent, wrapAISDK, wrapAISDKModel, wrapAnthropic, wrapClaudeAgentSDK, wrapMastraAgent, wrapOpenAI, wrapOpenAIv4, wrapTraced };
package/dist/index.d.ts CHANGED
@@ -14876,6 +14876,48 @@ declare class ReadonlyAttachment {
14876
14876
  status(): Promise<AttachmentStatusType>;
14877
14877
  private initDownloader;
14878
14878
  }
14879
+ /**
14880
+ * Represents a JSON object that should be stored as an attachment.
14881
+ *
14882
+ * `JSONAttachment` is a convenience function that creates an `Attachment`
14883
+ * from JSON data. It's particularly useful for large JSON objects that
14884
+ * would otherwise bloat the trace size.
14885
+ *
14886
+ * The JSON data is automatically serialized and stored as an attachment
14887
+ * with content type "application/json".
14888
+ */
14889
+ declare class JSONAttachment extends Attachment {
14890
+ /**
14891
+ * Construct a JSONAttachment from a JSON-serializable object.
14892
+ *
14893
+ * @param data The JSON object to attach. Must be JSON-serializable.
14894
+ * @param options Additional options:
14895
+ * - `filename`: The filename for the attachment (defaults to "data.json")
14896
+ * - `pretty`: Whether to pretty-print the JSON (defaults to false)
14897
+ * - `state`: (Optional) For internal use.
14898
+ *
14899
+ * @example
14900
+ * ```typescript
14901
+ * const largeTranscript = [
14902
+ * { role: "user", content: "..." },
14903
+ * { role: "assistant", content: "..." },
14904
+ * // ... many more messages
14905
+ * ];
14906
+ *
14907
+ * logger.log({
14908
+ * input: {
14909
+ * type: "chat",
14910
+ * transcript: new JSONAttachment(largeTranscript, { filename: "transcript.json" })
14911
+ * }
14912
+ * });
14913
+ * ```
14914
+ */
14915
+ constructor(data: unknown, options?: {
14916
+ filename?: string;
14917
+ pretty?: boolean;
14918
+ state?: BraintrustState;
14919
+ });
14920
+ }
14879
14921
  /**
14880
14922
  * Update a span using the output of `span.export()`. It is important that you only resume updating
14881
14923
  * to a span once the original span has been fully written and flushed, since otherwise updates to
@@ -14935,6 +14977,7 @@ declare class Logger<IsAsyncFlush extends boolean> implements Exportable {
14935
14977
  get org_id(): Promise<string>;
14936
14978
  get project(): Promise<ObjectMetadata>;
14937
14979
  get id(): Promise<string>;
14980
+ get loggingState(): BraintrustState;
14938
14981
  private parentObjectType;
14939
14982
  /**
14940
14983
  * Log a single event. The event will be batched and uploaded behind the scenes if `logOptions.asyncFlush` is true.
@@ -15486,6 +15529,7 @@ declare class Experiment extends ObjectFetcher<ExperimentEvent> implements Expor
15486
15529
  kind: "experiment";
15487
15530
  constructor(state: BraintrustState, lazyMetadata: LazyValue<ProjectExperimentMetadata>, dataset?: AnyDataset);
15488
15531
  get id(): Promise<string>;
15532
+ get loggingState(): BraintrustState;
15489
15533
  /**
15490
15534
  * Wait for the experiment ID to be resolved. This is useful for ensuring the ID
15491
15535
  * is available synchronously in child spans (for OTEL parent attributes).
@@ -15590,6 +15634,7 @@ declare class ReadonlyExperiment extends ObjectFetcher<ExperimentEvent> {
15590
15634
  constructor(state: BraintrustState, lazyMetadata: LazyValue<ProjectExperimentMetadata>);
15591
15635
  get id(): Promise<string>;
15592
15636
  get name(): Promise<string>;
15637
+ get loggingState(): BraintrustState;
15593
15638
  protected getState(): Promise<BraintrustState>;
15594
15639
  asDataset<Input, Expected, Metadata = DefaultMetadataType>(): AsyncGenerator<EvalCase<Input, Expected, Metadata>>;
15595
15640
  }
@@ -15665,6 +15710,7 @@ declare class Dataset<IsLegacyDataset extends boolean = typeof DEFAULT_IS_LEGACY
15665
15710
  get id(): Promise<string>;
15666
15711
  get name(): Promise<string>;
15667
15712
  get project(): Promise<ObjectMetadata>;
15713
+ get loggingState(): BraintrustState;
15668
15714
  protected getState(): Promise<BraintrustState>;
15669
15715
  private validateEvent;
15670
15716
  private createArgs;
@@ -21702,6 +21748,8 @@ declare const braintrust_INTERNAL_BTQL_LIMIT: typeof INTERNAL_BTQL_LIMIT;
21702
21748
  type braintrust_InitOptions<IsOpen extends boolean> = InitOptions<IsOpen>;
21703
21749
  type braintrust_InvokeFunctionArgs<Input, Output, Stream extends boolean = false> = InvokeFunctionArgs<Input, Output, Stream>;
21704
21750
  type braintrust_InvokeReturn<Stream extends boolean, Output> = InvokeReturn<Stream, Output>;
21751
+ type braintrust_JSONAttachment = JSONAttachment;
21752
+ declare const braintrust_JSONAttachment: typeof JSONAttachment;
21705
21753
  declare const braintrust_LEGACY_CACHED_HEADER: typeof LEGACY_CACHED_HEADER;
21706
21754
  type braintrust_LazyValue<T> = LazyValue<T>;
21707
21755
  declare const braintrust_LazyValue: typeof LazyValue;
@@ -21818,7 +21866,7 @@ declare const braintrust_wrapOpenAI: typeof wrapOpenAI;
21818
21866
  declare const braintrust_wrapOpenAIv4: typeof wrapOpenAIv4;
21819
21867
  declare const braintrust_wrapTraced: typeof wrapTraced;
21820
21868
  declare namespace braintrust {
21821
- export { braintrust_AISpanProcessor as AISpanProcessor, type braintrust_AnyDataset as AnyDataset, braintrust_Attachment as Attachment, type braintrust_AttachmentParams as AttachmentParams, type braintrust_BackgroundLoggerOpts as BackgroundLoggerOpts, braintrust_BaseAttachment as BaseAttachment, braintrust_BaseExperiment as BaseExperiment, type braintrust_BaseMetadata as BaseMetadata, braintrust_BraintrustExporter as BraintrustExporter, braintrust_BraintrustMiddleware as BraintrustMiddleware, braintrust_BraintrustSpanProcessor as BraintrustSpanProcessor, braintrust_BraintrustState as BraintrustState, braintrust_BraintrustStream as BraintrustStream, type braintrust_BraintrustStreamChunk as BraintrustStreamChunk, type braintrust_ChatPrompt as ChatPrompt, braintrust_CodeFunction as CodeFunction, type braintrust_CodeOpts as CodeOpts, braintrust_CodePrompt as CodePrompt, type braintrust_CompiledPrompt as CompiledPrompt, type braintrust_CompiledPromptParams as CompiledPromptParams, type braintrust_CompletionPrompt as CompletionPrompt, braintrust_ContextManager as ContextManager, type braintrust_ContextParentSpanIds as ContextParentSpanIds, type braintrust_CreateProjectOpts as CreateProjectOpts, type braintrust_DataSummary as DataSummary, braintrust_Dataset as Dataset, type braintrust_DatasetSummary as DatasetSummary, type braintrust_DefaultMetadataType as DefaultMetadataType, type braintrust_DefaultPromptArgs as DefaultPromptArgs, braintrust_ERR_PERMALINK as ERR_PERMALINK, type braintrust_EndSpanArgs as EndSpanArgs, braintrust_Eval as Eval, type braintrust_EvalCase as EvalCase, type braintrust_EvalHooks as EvalHooks, type braintrust_EvalResult as EvalResult, braintrust_EvalResultWithSummary as EvalResultWithSummary, 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, type braintrust_ExperimentSummary as ExperimentSummary, type braintrust_Exportable as Exportable, braintrust_ExternalAttachment as ExternalAttachment, type braintrust_ExternalAttachmentParams as ExternalAttachmentParams, braintrust_FailedHTTPResponse as FailedHTTPResponse, type braintrust_FullInitOptions as FullInitOptions, type braintrust_FullLoginOptions as FullLoginOptions, type braintrust_FunctionEvent as FunctionEvent, braintrust_IDGenerator as IDGenerator, braintrust_INTERNAL_BTQL_LIMIT as INTERNAL_BTQL_LIMIT, type braintrust_InitOptions as InitOptions, type braintrust_InvokeFunctionArgs as InvokeFunctionArgs, type braintrust_InvokeReturn as InvokeReturn, braintrust_LEGACY_CACHED_HEADER as LEGACY_CACHED_HEADER, braintrust_LazyValue as LazyValue, 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_NOOP_SPAN_PERMALINK as NOOP_SPAN_PERMALINK, braintrust_NoopSpan as NoopSpan, braintrust_OTELIDGenerator as OTELIDGenerator, type braintrust_ObjectMetadata as ObjectMetadata, braintrust_Project as Project, braintrust_ProjectNameIdMap as ProjectNameIdMap, type braintrust_PromiseUnless as PromiseUnless, braintrust_Prompt as Prompt, braintrust_PromptBuilder as PromptBuilder, type braintrust_PromptContents as PromptContents, type braintrust_PromptDefinition as PromptDefinition, type braintrust_PromptDefinitionWithTools as PromptDefinitionWithTools, type braintrust_PromptOpts as PromptOpts, type braintrust_PromptRowWithId as PromptRowWithId, braintrust_ReadonlyAttachment as ReadonlyAttachment, braintrust_ReadonlyExperiment as ReadonlyExperiment, braintrust_Reporter as Reporter, type braintrust_ReporterBody as ReporterBody, type braintrust_ScoreSummary as ScoreSummary, braintrust_ScorerBuilder as ScorerBuilder, type braintrust_ScorerOpts as ScorerOpts, type braintrust_SerializedBraintrustState as SerializedBraintrustState, type braintrust_SetCurrentArg as SetCurrentArg, type Span$1 as Span, type braintrust_SpanContext as SpanContext, braintrust_SpanImpl as SpanImpl, type braintrust_StartSpanArgs as StartSpanArgs, braintrust_TestBackgroundLogger as TestBackgroundLogger, braintrust_ToolBuilder as ToolBuilder, braintrust_UUIDGenerator as UUIDGenerator, 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_deepCopyEvent as deepCopyEvent, braintrust_defaultErrorScoreHandler as defaultErrorScoreHandler, braintrust_deserializePlainStringAsJSON as deserializePlainStringAsJSON, braintrust_devNullWritableStream as devNullWritableStream, braintrust_flush as flush, braintrust_getContextManager as getContextManager, braintrust_getIdGenerator as getIdGenerator, braintrust_getPromptVersions as getPromptVersions, braintrust_getSpanParentObject as getSpanParentObject, graphFramework as graph, braintrust_init as init, braintrust_initDataset as initDataset, braintrust_initExperiment as initExperiment, braintrust_initFunction as initFunction, 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_promptContentsSchema as promptContentsSchema, braintrust_promptDefinitionSchema as promptDefinitionSchema, braintrust_promptDefinitionToPromptData as promptDefinitionToPromptData, braintrust_promptDefinitionWithToolsSchema as promptDefinitionWithToolsSchema, braintrust_renderMessage as renderMessage, braintrust_renderPromptParams as renderPromptParams, braintrust_reportFailures as reportFailures, braintrust_runEvaluator as runEvaluator, braintrust_setFetch as setFetch, braintrust_setMaskingFunction as setMaskingFunction, braintrust_spanComponentsToObjectId as spanComponentsToObjectId, braintrust_startSpan as startSpan, braintrust_summarize as summarize, ToolFunctionDefinition 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_withParent as withParent, braintrust_wrapAISDK as wrapAISDK, braintrust_wrapAISDKModel as wrapAISDKModel, braintrust_wrapAnthropic as wrapAnthropic, braintrust_wrapClaudeAgentSDK as wrapClaudeAgentSDK, braintrust_wrapMastraAgent as wrapMastraAgent, braintrust_wrapOpenAI as wrapOpenAI, braintrust_wrapOpenAIv4 as wrapOpenAIv4, braintrust_wrapTraced as wrapTraced };
21869
+ export { braintrust_AISpanProcessor as AISpanProcessor, type braintrust_AnyDataset as AnyDataset, braintrust_Attachment as Attachment, type braintrust_AttachmentParams as AttachmentParams, type braintrust_BackgroundLoggerOpts as BackgroundLoggerOpts, braintrust_BaseAttachment as BaseAttachment, braintrust_BaseExperiment as BaseExperiment, type braintrust_BaseMetadata as BaseMetadata, braintrust_BraintrustExporter as BraintrustExporter, braintrust_BraintrustMiddleware as BraintrustMiddleware, braintrust_BraintrustSpanProcessor as BraintrustSpanProcessor, braintrust_BraintrustState as BraintrustState, braintrust_BraintrustStream as BraintrustStream, type braintrust_BraintrustStreamChunk as BraintrustStreamChunk, type braintrust_ChatPrompt as ChatPrompt, braintrust_CodeFunction as CodeFunction, type braintrust_CodeOpts as CodeOpts, braintrust_CodePrompt as CodePrompt, type braintrust_CompiledPrompt as CompiledPrompt, type braintrust_CompiledPromptParams as CompiledPromptParams, type braintrust_CompletionPrompt as CompletionPrompt, braintrust_ContextManager as ContextManager, type braintrust_ContextParentSpanIds as ContextParentSpanIds, type braintrust_CreateProjectOpts as CreateProjectOpts, type braintrust_DataSummary as DataSummary, braintrust_Dataset as Dataset, type braintrust_DatasetSummary as DatasetSummary, type braintrust_DefaultMetadataType as DefaultMetadataType, type braintrust_DefaultPromptArgs as DefaultPromptArgs, braintrust_ERR_PERMALINK as ERR_PERMALINK, type braintrust_EndSpanArgs as EndSpanArgs, braintrust_Eval as Eval, type braintrust_EvalCase as EvalCase, type braintrust_EvalHooks as EvalHooks, type braintrust_EvalResult as EvalResult, braintrust_EvalResultWithSummary as EvalResultWithSummary, 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, type braintrust_ExperimentSummary as ExperimentSummary, type braintrust_Exportable as Exportable, braintrust_ExternalAttachment as ExternalAttachment, type braintrust_ExternalAttachmentParams as ExternalAttachmentParams, braintrust_FailedHTTPResponse as FailedHTTPResponse, type braintrust_FullInitOptions as FullInitOptions, type braintrust_FullLoginOptions as FullLoginOptions, type braintrust_FunctionEvent as FunctionEvent, braintrust_IDGenerator as IDGenerator, braintrust_INTERNAL_BTQL_LIMIT as INTERNAL_BTQL_LIMIT, type braintrust_InitOptions as InitOptions, type braintrust_InvokeFunctionArgs as InvokeFunctionArgs, type braintrust_InvokeReturn as InvokeReturn, braintrust_JSONAttachment as JSONAttachment, braintrust_LEGACY_CACHED_HEADER as LEGACY_CACHED_HEADER, braintrust_LazyValue as LazyValue, 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_NOOP_SPAN_PERMALINK as NOOP_SPAN_PERMALINK, braintrust_NoopSpan as NoopSpan, braintrust_OTELIDGenerator as OTELIDGenerator, type braintrust_ObjectMetadata as ObjectMetadata, braintrust_Project as Project, braintrust_ProjectNameIdMap as ProjectNameIdMap, type braintrust_PromiseUnless as PromiseUnless, braintrust_Prompt as Prompt, braintrust_PromptBuilder as PromptBuilder, type braintrust_PromptContents as PromptContents, type braintrust_PromptDefinition as PromptDefinition, type braintrust_PromptDefinitionWithTools as PromptDefinitionWithTools, type braintrust_PromptOpts as PromptOpts, type braintrust_PromptRowWithId as PromptRowWithId, braintrust_ReadonlyAttachment as ReadonlyAttachment, braintrust_ReadonlyExperiment as ReadonlyExperiment, braintrust_Reporter as Reporter, type braintrust_ReporterBody as ReporterBody, type braintrust_ScoreSummary as ScoreSummary, braintrust_ScorerBuilder as ScorerBuilder, type braintrust_ScorerOpts as ScorerOpts, type braintrust_SerializedBraintrustState as SerializedBraintrustState, type braintrust_SetCurrentArg as SetCurrentArg, type Span$1 as Span, type braintrust_SpanContext as SpanContext, braintrust_SpanImpl as SpanImpl, type braintrust_StartSpanArgs as StartSpanArgs, braintrust_TestBackgroundLogger as TestBackgroundLogger, braintrust_ToolBuilder as ToolBuilder, braintrust_UUIDGenerator as UUIDGenerator, 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_deepCopyEvent as deepCopyEvent, braintrust_defaultErrorScoreHandler as defaultErrorScoreHandler, braintrust_deserializePlainStringAsJSON as deserializePlainStringAsJSON, braintrust_devNullWritableStream as devNullWritableStream, braintrust_flush as flush, braintrust_getContextManager as getContextManager, braintrust_getIdGenerator as getIdGenerator, braintrust_getPromptVersions as getPromptVersions, braintrust_getSpanParentObject as getSpanParentObject, graphFramework as graph, braintrust_init as init, braintrust_initDataset as initDataset, braintrust_initExperiment as initExperiment, braintrust_initFunction as initFunction, 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_promptContentsSchema as promptContentsSchema, braintrust_promptDefinitionSchema as promptDefinitionSchema, braintrust_promptDefinitionToPromptData as promptDefinitionToPromptData, braintrust_promptDefinitionWithToolsSchema as promptDefinitionWithToolsSchema, braintrust_renderMessage as renderMessage, braintrust_renderPromptParams as renderPromptParams, braintrust_reportFailures as reportFailures, braintrust_runEvaluator as runEvaluator, braintrust_setFetch as setFetch, braintrust_setMaskingFunction as setMaskingFunction, braintrust_spanComponentsToObjectId as spanComponentsToObjectId, braintrust_startSpan as startSpan, braintrust_summarize as summarize, ToolFunctionDefinition 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_withParent as withParent, braintrust_wrapAISDK as wrapAISDK, braintrust_wrapAISDKModel as wrapAISDKModel, braintrust_wrapAnthropic as wrapAnthropic, braintrust_wrapClaudeAgentSDK as wrapClaudeAgentSDK, braintrust_wrapMastraAgent as wrapMastraAgent, braintrust_wrapOpenAI as wrapOpenAI, braintrust_wrapOpenAIv4 as wrapOpenAIv4, braintrust_wrapTraced as wrapTraced };
21822
21870
  }
21823
21871
 
21824
21872
  type EvaluatorManifest = Record<string, EvaluatorDef<unknown, unknown, unknown, BaseMetadata>>;
@@ -28875,4 +28923,4 @@ type EvaluatorDefinitions = z.infer<typeof evaluatorDefinitionsSchema>;
28875
28923
  * @module braintrust
28876
28924
  */
28877
28925
 
28878
- export { AISpanProcessor, type AnyDataset, Attachment, type AttachmentParams, type BackgroundLoggerOpts, BaseAttachment, BaseExperiment, type BaseMetadata, BraintrustExporter, BraintrustMiddleware, BraintrustSpanProcessor, BraintrustState, BraintrustStream, type BraintrustStreamChunk, type ChatPrompt, CodeFunction, type CodeOpts, CodePrompt, type CommentEvent, type CompiledPrompt, type CompiledPromptParams, type CompletionPrompt, ContextManager, type ContextParentSpanIds, type CreateProjectOpts, type DataSummary, Dataset, type DatasetRecord, type DatasetSummary, type DefaultMetadataType, type DefaultPromptArgs, ERR_PERMALINK, type EndSpanArgs, Eval, type EvalCase, type EvalHooks, type EvalParameterSerializedSchema, type EvalParameters, type EvalResult, EvalResultWithSummary, type EvalScorer, type EvalScorerArgs, type EvalTask, type Evaluator, type EvaluatorDef, type EvaluatorDefinition, type EvaluatorDefinitions, type EvaluatorFile, type EvaluatorManifest, Experiment, type ExperimentLogFullArgs, type ExperimentLogPartialArgs, type ExperimentSummary, type Exportable, ExternalAttachment, type ExternalAttachmentParams, FailedHTTPResponse, type FullInitOptions, type FullLoginOptions, type FunctionEvent, IDGenerator, INTERNAL_BTQL_LIMIT, type IdField, type InitOptions, type InputField, type InvokeFunctionArgs, type InvokeReturn, LEGACY_CACHED_HEADER, LazyValue, type LogCommentFullArgs, type LogFeedbackFullArgs, type LogOptions, Logger, type LoginOptions, type MetricSummary, NOOP_SPAN, NOOP_SPAN_PERMALINK, NoopSpan, OTELIDGenerator, type ObjectMetadata, type OtherExperimentLogFields, type ParentExperimentIds, type ParentProjectLogIds, Project, ProjectNameIdMap, type PromiseUnless, Prompt, PromptBuilder, type PromptContents, type PromptDefinition, type PromptDefinitionWithTools, type PromptOpts, type PromptRowWithId, ReadonlyAttachment, ReadonlyExperiment, Reporter, type ReporterBody, type ScoreSummary, ScorerBuilder, type ScorerOpts, type SerializedBraintrustState, type SetCurrentArg, type Span$1 as Span, type SpanContext, SpanImpl, type StartSpanArgs, TestBackgroundLogger, ToolBuilder, UUIDGenerator, type WithTransactionId, X_CACHED_HEADER, _exportsForTestingOnly, _internalGetGlobalState, _internalSetInitialState, braintrustStreamChunkSchema, buildLocalSummary, createFinalValuePassThroughStream, currentExperiment, currentLogger, currentSpan, deepCopyEvent, braintrust as default, defaultErrorScoreHandler, deserializePlainStringAsJSON, devNullWritableStream, evaluatorDefinitionSchema, evaluatorDefinitionsSchema, flush, getContextManager, getIdGenerator, getPromptVersions, getSpanParentObject, graphFramework as graph, init, initDataset, initExperiment, initFunction, initLogger, invoke, loadPrompt, log, logError, login, loginToState, newId, parseCachedHeader, permalink, projects, promptContentsSchema, promptDefinitionSchema, promptDefinitionToPromptData, promptDefinitionWithToolsSchema, renderMessage, renderPromptParams, reportFailures, runEvaluator, setFetch, setMaskingFunction, spanComponentsToObjectId, startSpan, summarize, ToolFunctionDefinition as toolFunctionDefinitionSchema, traceable, traced, updateSpan, withCurrent, withDataset, withExperiment, withLogger, withParent, wrapAISDK, wrapAISDKModel, wrapAnthropic, wrapClaudeAgentSDK, wrapMastraAgent, wrapOpenAI, wrapOpenAIv4, wrapTraced };
28926
+ export { AISpanProcessor, type AnyDataset, Attachment, type AttachmentParams, AttachmentReference, type BackgroundLoggerOpts, BaseAttachment, BaseExperiment, type BaseMetadata, BraintrustExporter, BraintrustMiddleware, BraintrustSpanProcessor, BraintrustState, BraintrustStream, type BraintrustStreamChunk, type ChatPrompt, CodeFunction, type CodeOpts, CodePrompt, type CommentEvent, type CompiledPrompt, type CompiledPromptParams, type CompletionPrompt, ContextManager, type ContextParentSpanIds, type CreateProjectOpts, type DataSummary, Dataset, type DatasetRecord, type DatasetSummary, type DefaultMetadataType, type DefaultPromptArgs, ERR_PERMALINK, type EndSpanArgs, Eval, type EvalCase, type EvalHooks, type EvalParameterSerializedSchema, type EvalParameters, type EvalResult, EvalResultWithSummary, type EvalScorer, type EvalScorerArgs, type EvalTask, type Evaluator, type EvaluatorDef, type EvaluatorDefinition, type EvaluatorDefinitions, type EvaluatorFile, type EvaluatorManifest, Experiment, type ExperimentLogFullArgs, type ExperimentLogPartialArgs, type ExperimentSummary, type Exportable, ExternalAttachment, type ExternalAttachmentParams, FailedHTTPResponse, type FullInitOptions, type FullLoginOptions, type FunctionEvent, IDGenerator, INTERNAL_BTQL_LIMIT, type IdField, type InitOptions, type InputField, type InvokeFunctionArgs, type InvokeReturn, JSONAttachment, LEGACY_CACHED_HEADER, LazyValue, type LogCommentFullArgs, type LogFeedbackFullArgs, type LogOptions, Logger, type LoginOptions, type MetricSummary, NOOP_SPAN, NOOP_SPAN_PERMALINK, NoopSpan, OTELIDGenerator, type ObjectMetadata, type OtherExperimentLogFields, type ParentExperimentIds, type ParentProjectLogIds, Project, ProjectNameIdMap, type PromiseUnless, Prompt, PromptBuilder, type PromptContents, type PromptDefinition, type PromptDefinitionWithTools, type PromptOpts, type PromptRowWithId, ReadonlyAttachment, ReadonlyExperiment, Reporter, type ReporterBody, type ScoreSummary, ScorerBuilder, type ScorerOpts, type SerializedBraintrustState, type SetCurrentArg, type Span$1 as Span, type SpanContext, SpanImpl, type StartSpanArgs, TestBackgroundLogger, ToolBuilder, UUIDGenerator, type WithTransactionId, X_CACHED_HEADER, _exportsForTestingOnly, _internalGetGlobalState, _internalSetInitialState, braintrustStreamChunkSchema, buildLocalSummary, createFinalValuePassThroughStream, currentExperiment, currentLogger, currentSpan, deepCopyEvent, braintrust as default, defaultErrorScoreHandler, deserializePlainStringAsJSON, devNullWritableStream, evaluatorDefinitionSchema, evaluatorDefinitionsSchema, flush, getContextManager, getIdGenerator, getPromptVersions, getSpanParentObject, graphFramework as graph, init, initDataset, initExperiment, initFunction, initLogger, invoke, loadPrompt, log, logError, login, loginToState, newId, parseCachedHeader, permalink, projects, promptContentsSchema, promptDefinitionSchema, promptDefinitionToPromptData, promptDefinitionWithToolsSchema, renderMessage, renderPromptParams, reportFailures, runEvaluator, setFetch, setMaskingFunction, spanComponentsToObjectId, startSpan, summarize, ToolFunctionDefinition as toolFunctionDefinitionSchema, traceable, traced, updateSpan, withCurrent, withDataset, withExperiment, withLogger, withParent, wrapAISDK, wrapAISDKModel, wrapAnthropic, wrapClaudeAgentSDK, wrapMastraAgent, wrapOpenAI, wrapOpenAIv4, wrapTraced };
package/dist/index.js CHANGED
@@ -5247,7 +5247,7 @@ function resetIdGenStateForTests() {
5247
5247
  state.resetIdGenState();
5248
5248
  }
5249
5249
  }
5250
- var BRAINTRUST_ATTACHMENT, EXTERNAL_ATTACHMENT, BRAINTRUST_PARAMS, REDACTION_FIELDS, MaskingError, ContextManager, BraintrustContextManager, NoopSpan, NOOP_SPAN, NOOP_SPAN_PERMALINK, loginSchema, stateNonce, BraintrustState, _globalState, _internalGetGlobalState, FailedHTTPResponse, HTTPConnection, BaseAttachment, Attachment, ExternalAttachment, attachmentMetadataSchema, ReadonlyAttachment, ERR_PERMALINK, Logger, TestBackgroundLogger, BACKGROUND_LOGGER_BASE_SLEEP_TIME_S, HTTPBackgroundLogger, traceable, INTERNAL_BTQL_LIMIT, MAX_BTQL_ITERATIONS, ObjectFetcher, Experiment2, ReadonlyExperiment, executionCounter, SpanImpl, Dataset2, Prompt2, TEST_API_KEY, _exportsForTestingOnly;
5250
+ var BRAINTRUST_ATTACHMENT, EXTERNAL_ATTACHMENT, BRAINTRUST_PARAMS, REDACTION_FIELDS, MaskingError, ContextManager, BraintrustContextManager, NoopSpan, NOOP_SPAN, NOOP_SPAN_PERMALINK, loginSchema, stateNonce, BraintrustState, _globalState, _internalGetGlobalState, FailedHTTPResponse, HTTPConnection, BaseAttachment, Attachment, ExternalAttachment, attachmentMetadataSchema, ReadonlyAttachment, JSONAttachment, ERR_PERMALINK, Logger, TestBackgroundLogger, BACKGROUND_LOGGER_BASE_SLEEP_TIME_S, HTTPBackgroundLogger, traceable, INTERNAL_BTQL_LIMIT, MAX_BTQL_ITERATIONS, ObjectFetcher, Experiment2, ReadonlyExperiment, executionCounter, SpanImpl, Dataset2, Prompt2, TEST_API_KEY, _exportsForTestingOnly;
5251
5251
  var init_logger = _chunkCDBUTZMHjs.__esm.call(void 0, {
5252
5252
  "src/logger.ts"() {
5253
5253
  "use strict";
@@ -6120,6 +6120,44 @@ with a Blob/ArrayBuffer, or run the program on Node.js.`
6120
6120
  return new LazyValue(download);
6121
6121
  }
6122
6122
  };
6123
+ JSONAttachment = exports.JSONAttachment = class extends Attachment {
6124
+ /**
6125
+ * Construct a JSONAttachment from a JSON-serializable object.
6126
+ *
6127
+ * @param data The JSON object to attach. Must be JSON-serializable.
6128
+ * @param options Additional options:
6129
+ * - `filename`: The filename for the attachment (defaults to "data.json")
6130
+ * - `pretty`: Whether to pretty-print the JSON (defaults to false)
6131
+ * - `state`: (Optional) For internal use.
6132
+ *
6133
+ * @example
6134
+ * ```typescript
6135
+ * const largeTranscript = [
6136
+ * { role: "user", content: "..." },
6137
+ * { role: "assistant", content: "..." },
6138
+ * // ... many more messages
6139
+ * ];
6140
+ *
6141
+ * logger.log({
6142
+ * input: {
6143
+ * type: "chat",
6144
+ * transcript: new JSONAttachment(largeTranscript, { filename: "transcript.json" })
6145
+ * }
6146
+ * });
6147
+ * ```
6148
+ */
6149
+ constructor(data, options) {
6150
+ const { filename = "data.json", pretty = false, state } = _nullishCoalesce(options, () => ( {}));
6151
+ const jsonString = pretty ? JSON.stringify(data, null, 2) : JSON.stringify(data);
6152
+ const blob = new Blob([jsonString], { type: "application/json" });
6153
+ super({
6154
+ data: blob,
6155
+ filename,
6156
+ contentType: "application/json",
6157
+ state
6158
+ });
6159
+ }
6160
+ };
6123
6161
  ERR_PERMALINK = exports.ERR_PERMALINK = "https://braintrust.dev/error-generating-link";
6124
6162
  Logger = exports.Logger = (_class6 = class {
6125
6163
 
@@ -6153,6 +6191,9 @@ with a Blob/ArrayBuffer, or run the program on Node.js.`
6153
6191
  get id() {
6154
6192
  return (async () => (await this.project).id)();
6155
6193
  }
6194
+ get loggingState() {
6195
+ return this.state;
6196
+ }
6156
6197
  parentObjectType() {
6157
6198
  return 2 /* PROJECT_LOGS */;
6158
6199
  }
@@ -6866,6 +6907,9 @@ Error: ${errorText}`;
6866
6907
  return (await this.lazyMetadata.get()).experiment.id;
6867
6908
  })();
6868
6909
  }
6910
+ get loggingState() {
6911
+ return this.state;
6912
+ }
6869
6913
  /**
6870
6914
  * Wait for the experiment ID to be resolved. This is useful for ensuring the ID
6871
6915
  * is available synchronously in child spans (for OTEL parent attributes).
@@ -7131,6 +7175,9 @@ View complete results in Braintrust or run experiment.summarize() again.`
7131
7175
  return (await this.lazyMetadata.get()).experiment.name;
7132
7176
  })();
7133
7177
  }
7178
+ get loggingState() {
7179
+ return this.state;
7180
+ }
7134
7181
  async getState() {
7135
7182
  await this.lazyMetadata.get();
7136
7183
  return this.state;
@@ -7519,6 +7566,9 @@ View complete results in Braintrust or run experiment.summarize() again.`
7519
7566
  return (await this.lazyMetadata.get()).project;
7520
7567
  })();
7521
7568
  }
7569
+ get loggingState() {
7570
+ return this.state;
7571
+ }
7522
7572
  async getState() {
7523
7573
  await this.lazyMetadata.get();
7524
7574
  return this.state;
@@ -11481,6 +11531,7 @@ _chunkCDBUTZMHjs.__export.call(void 0, exports_node_exports, {
11481
11531
  FailedHTTPResponse: () => FailedHTTPResponse,
11482
11532
  IDGenerator: () => IDGenerator,
11483
11533
  INTERNAL_BTQL_LIMIT: () => INTERNAL_BTQL_LIMIT,
11534
+ JSONAttachment: () => JSONAttachment,
11484
11535
  LEGACY_CACHED_HEADER: () => LEGACY_CACHED_HEADER,
11485
11536
  LazyValue: () => LazyValue,
11486
11537
  Logger: () => Logger,
@@ -16886,4 +16937,5 @@ var index_default = exports_node_exports;
16886
16937
 
16887
16938
 
16888
16939
 
16889
- exports.AISpanProcessor = AISpanProcessor; exports.Attachment = Attachment; exports.BaseAttachment = BaseAttachment; exports.BaseExperiment = BaseExperiment; exports.BraintrustExporter = BraintrustExporter; exports.BraintrustMiddleware = BraintrustMiddleware; exports.BraintrustSpanProcessor = BraintrustSpanProcessor; exports.BraintrustState = BraintrustState; exports.BraintrustStream = BraintrustStream; exports.CodeFunction = CodeFunction; exports.CodePrompt = CodePrompt; exports.ContextManager = ContextManager; exports.Dataset = Dataset2; exports.ERR_PERMALINK = ERR_PERMALINK; exports.Eval = Eval; exports.EvalResultWithSummary = EvalResultWithSummary; exports.Experiment = Experiment2; exports.ExternalAttachment = ExternalAttachment; exports.FailedHTTPResponse = FailedHTTPResponse; exports.IDGenerator = IDGenerator; exports.INTERNAL_BTQL_LIMIT = INTERNAL_BTQL_LIMIT; exports.LEGACY_CACHED_HEADER = LEGACY_CACHED_HEADER; exports.LazyValue = LazyValue; exports.Logger = Logger; exports.NOOP_SPAN = NOOP_SPAN; exports.NOOP_SPAN_PERMALINK = NOOP_SPAN_PERMALINK; exports.NoopSpan = NoopSpan; exports.OTELIDGenerator = OTELIDGenerator; exports.Project = Project2; exports.ProjectNameIdMap = ProjectNameIdMap; exports.Prompt = Prompt2; exports.PromptBuilder = PromptBuilder; exports.ReadonlyAttachment = ReadonlyAttachment; exports.ReadonlyExperiment = ReadonlyExperiment; exports.Reporter = Reporter; exports.ScorerBuilder = ScorerBuilder; exports.SpanImpl = SpanImpl; exports.TestBackgroundLogger = TestBackgroundLogger; exports.ToolBuilder = ToolBuilder; exports.UUIDGenerator = UUIDGenerator; exports.X_CACHED_HEADER = X_CACHED_HEADER; exports._exportsForTestingOnly = _exportsForTestingOnly; exports._internalGetGlobalState = _internalGetGlobalState; exports._internalSetInitialState = _internalSetInitialState; exports.braintrustStreamChunkSchema = braintrustStreamChunkSchema; exports.buildLocalSummary = buildLocalSummary; exports.createFinalValuePassThroughStream = createFinalValuePassThroughStream; exports.currentExperiment = currentExperiment; exports.currentLogger = currentLogger; exports.currentSpan = currentSpan; exports.deepCopyEvent = deepCopyEvent; exports.default = index_default; exports.defaultErrorScoreHandler = defaultErrorScoreHandler; exports.deserializePlainStringAsJSON = deserializePlainStringAsJSON; exports.devNullWritableStream = devNullWritableStream; exports.evaluatorDefinitionSchema = evaluatorDefinitionSchema; exports.evaluatorDefinitionsSchema = evaluatorDefinitionsSchema; exports.flush = flush; exports.getContextManager = getContextManager; exports.getIdGenerator = getIdGenerator; exports.getPromptVersions = getPromptVersions; exports.getSpanParentObject = getSpanParentObject; exports.graph = graph_framework_exports; exports.init = init; exports.initDataset = initDataset; exports.initExperiment = initExperiment; exports.initFunction = initFunction; exports.initLogger = initLogger; exports.invoke = invoke; exports.loadPrompt = loadPrompt; exports.log = log; exports.logError = logError; exports.login = login; exports.loginToState = loginToState; exports.newId = newId; exports.parseCachedHeader = parseCachedHeader; exports.permalink = permalink; exports.projects = projects; exports.promptContentsSchema = promptContentsSchema; exports.promptDefinitionSchema = promptDefinitionSchema; exports.promptDefinitionToPromptData = promptDefinitionToPromptData; exports.promptDefinitionWithToolsSchema = promptDefinitionWithToolsSchema; exports.renderMessage = renderMessage; exports.renderPromptParams = renderPromptParams; exports.reportFailures = reportFailures; exports.runEvaluator = runEvaluator; exports.setFetch = setFetch; exports.setMaskingFunction = setMaskingFunction; exports.spanComponentsToObjectId = spanComponentsToObjectId; exports.startSpan = startSpan; exports.summarize = summarize; exports.toolFunctionDefinitionSchema = ToolFunctionDefinition; exports.traceable = traceable; exports.traced = traced; exports.updateSpan = updateSpan; exports.withCurrent = withCurrent; exports.withDataset = withDataset; exports.withExperiment = withExperiment; exports.withLogger = withLogger; exports.withParent = withParent; exports.wrapAISDK = wrapAISDK; exports.wrapAISDKModel = wrapAISDKModel; exports.wrapAnthropic = wrapAnthropic; exports.wrapClaudeAgentSDK = wrapClaudeAgentSDK; exports.wrapMastraAgent = wrapMastraAgent; exports.wrapOpenAI = wrapOpenAI; exports.wrapOpenAIv4 = wrapOpenAIv4; exports.wrapTraced = wrapTraced;
16940
+
16941
+ exports.AISpanProcessor = AISpanProcessor; exports.Attachment = Attachment; exports.BaseAttachment = BaseAttachment; exports.BaseExperiment = BaseExperiment; exports.BraintrustExporter = BraintrustExporter; exports.BraintrustMiddleware = BraintrustMiddleware; exports.BraintrustSpanProcessor = BraintrustSpanProcessor; exports.BraintrustState = BraintrustState; exports.BraintrustStream = BraintrustStream; exports.CodeFunction = CodeFunction; exports.CodePrompt = CodePrompt; exports.ContextManager = ContextManager; exports.Dataset = Dataset2; exports.ERR_PERMALINK = ERR_PERMALINK; exports.Eval = Eval; exports.EvalResultWithSummary = EvalResultWithSummary; exports.Experiment = Experiment2; exports.ExternalAttachment = ExternalAttachment; exports.FailedHTTPResponse = FailedHTTPResponse; exports.IDGenerator = IDGenerator; exports.INTERNAL_BTQL_LIMIT = INTERNAL_BTQL_LIMIT; exports.JSONAttachment = JSONAttachment; exports.LEGACY_CACHED_HEADER = LEGACY_CACHED_HEADER; exports.LazyValue = LazyValue; exports.Logger = Logger; exports.NOOP_SPAN = NOOP_SPAN; exports.NOOP_SPAN_PERMALINK = NOOP_SPAN_PERMALINK; exports.NoopSpan = NoopSpan; exports.OTELIDGenerator = OTELIDGenerator; exports.Project = Project2; exports.ProjectNameIdMap = ProjectNameIdMap; exports.Prompt = Prompt2; exports.PromptBuilder = PromptBuilder; exports.ReadonlyAttachment = ReadonlyAttachment; exports.ReadonlyExperiment = ReadonlyExperiment; exports.Reporter = Reporter; exports.ScorerBuilder = ScorerBuilder; exports.SpanImpl = SpanImpl; exports.TestBackgroundLogger = TestBackgroundLogger; exports.ToolBuilder = ToolBuilder; exports.UUIDGenerator = UUIDGenerator; exports.X_CACHED_HEADER = X_CACHED_HEADER; exports._exportsForTestingOnly = _exportsForTestingOnly; exports._internalGetGlobalState = _internalGetGlobalState; exports._internalSetInitialState = _internalSetInitialState; exports.braintrustStreamChunkSchema = braintrustStreamChunkSchema; exports.buildLocalSummary = buildLocalSummary; exports.createFinalValuePassThroughStream = createFinalValuePassThroughStream; exports.currentExperiment = currentExperiment; exports.currentLogger = currentLogger; exports.currentSpan = currentSpan; exports.deepCopyEvent = deepCopyEvent; exports.default = index_default; exports.defaultErrorScoreHandler = defaultErrorScoreHandler; exports.deserializePlainStringAsJSON = deserializePlainStringAsJSON; exports.devNullWritableStream = devNullWritableStream; exports.evaluatorDefinitionSchema = evaluatorDefinitionSchema; exports.evaluatorDefinitionsSchema = evaluatorDefinitionsSchema; exports.flush = flush; exports.getContextManager = getContextManager; exports.getIdGenerator = getIdGenerator; exports.getPromptVersions = getPromptVersions; exports.getSpanParentObject = getSpanParentObject; exports.graph = graph_framework_exports; exports.init = init; exports.initDataset = initDataset; exports.initExperiment = initExperiment; exports.initFunction = initFunction; exports.initLogger = initLogger; exports.invoke = invoke; exports.loadPrompt = loadPrompt; exports.log = log; exports.logError = logError; exports.login = login; exports.loginToState = loginToState; exports.newId = newId; exports.parseCachedHeader = parseCachedHeader; exports.permalink = permalink; exports.projects = projects; exports.promptContentsSchema = promptContentsSchema; exports.promptDefinitionSchema = promptDefinitionSchema; exports.promptDefinitionToPromptData = promptDefinitionToPromptData; exports.promptDefinitionWithToolsSchema = promptDefinitionWithToolsSchema; exports.renderMessage = renderMessage; exports.renderPromptParams = renderPromptParams; exports.reportFailures = reportFailures; exports.runEvaluator = runEvaluator; exports.setFetch = setFetch; exports.setMaskingFunction = setMaskingFunction; exports.spanComponentsToObjectId = spanComponentsToObjectId; exports.startSpan = startSpan; exports.summarize = summarize; exports.toolFunctionDefinitionSchema = ToolFunctionDefinition; exports.traceable = traceable; exports.traced = traced; exports.updateSpan = updateSpan; exports.withCurrent = withCurrent; exports.withDataset = withDataset; exports.withExperiment = withExperiment; exports.withLogger = withLogger; exports.withParent = withParent; exports.wrapAISDK = wrapAISDK; exports.wrapAISDKModel = wrapAISDKModel; exports.wrapAnthropic = wrapAnthropic; exports.wrapClaudeAgentSDK = wrapClaudeAgentSDK; exports.wrapMastraAgent = wrapMastraAgent; exports.wrapOpenAI = wrapOpenAI; exports.wrapOpenAIv4 = wrapOpenAIv4; exports.wrapTraced = wrapTraced;
package/dist/index.mjs CHANGED
@@ -5247,7 +5247,7 @@ function resetIdGenStateForTests() {
5247
5247
  state.resetIdGenState();
5248
5248
  }
5249
5249
  }
5250
- var BRAINTRUST_ATTACHMENT, EXTERNAL_ATTACHMENT, BRAINTRUST_PARAMS, REDACTION_FIELDS, MaskingError, ContextManager, BraintrustContextManager, NoopSpan, NOOP_SPAN, NOOP_SPAN_PERMALINK, loginSchema, stateNonce, BraintrustState, _globalState, _internalGetGlobalState, FailedHTTPResponse, HTTPConnection, BaseAttachment, Attachment, ExternalAttachment, attachmentMetadataSchema, ReadonlyAttachment, ERR_PERMALINK, Logger, TestBackgroundLogger, BACKGROUND_LOGGER_BASE_SLEEP_TIME_S, HTTPBackgroundLogger, traceable, INTERNAL_BTQL_LIMIT, MAX_BTQL_ITERATIONS, ObjectFetcher, Experiment2, ReadonlyExperiment, executionCounter, SpanImpl, Dataset2, Prompt2, TEST_API_KEY, _exportsForTestingOnly;
5250
+ var BRAINTRUST_ATTACHMENT, EXTERNAL_ATTACHMENT, BRAINTRUST_PARAMS, REDACTION_FIELDS, MaskingError, ContextManager, BraintrustContextManager, NoopSpan, NOOP_SPAN, NOOP_SPAN_PERMALINK, loginSchema, stateNonce, BraintrustState, _globalState, _internalGetGlobalState, FailedHTTPResponse, HTTPConnection, BaseAttachment, Attachment, ExternalAttachment, attachmentMetadataSchema, ReadonlyAttachment, JSONAttachment, ERR_PERMALINK, Logger, TestBackgroundLogger, BACKGROUND_LOGGER_BASE_SLEEP_TIME_S, HTTPBackgroundLogger, traceable, INTERNAL_BTQL_LIMIT, MAX_BTQL_ITERATIONS, ObjectFetcher, Experiment2, ReadonlyExperiment, executionCounter, SpanImpl, Dataset2, Prompt2, TEST_API_KEY, _exportsForTestingOnly;
5251
5251
  var init_logger = __esm({
5252
5252
  "src/logger.ts"() {
5253
5253
  "use strict";
@@ -6120,6 +6120,44 @@ with a Blob/ArrayBuffer, or run the program on Node.js.`
6120
6120
  return new LazyValue(download);
6121
6121
  }
6122
6122
  };
6123
+ JSONAttachment = class extends Attachment {
6124
+ /**
6125
+ * Construct a JSONAttachment from a JSON-serializable object.
6126
+ *
6127
+ * @param data The JSON object to attach. Must be JSON-serializable.
6128
+ * @param options Additional options:
6129
+ * - `filename`: The filename for the attachment (defaults to "data.json")
6130
+ * - `pretty`: Whether to pretty-print the JSON (defaults to false)
6131
+ * - `state`: (Optional) For internal use.
6132
+ *
6133
+ * @example
6134
+ * ```typescript
6135
+ * const largeTranscript = [
6136
+ * { role: "user", content: "..." },
6137
+ * { role: "assistant", content: "..." },
6138
+ * // ... many more messages
6139
+ * ];
6140
+ *
6141
+ * logger.log({
6142
+ * input: {
6143
+ * type: "chat",
6144
+ * transcript: new JSONAttachment(largeTranscript, { filename: "transcript.json" })
6145
+ * }
6146
+ * });
6147
+ * ```
6148
+ */
6149
+ constructor(data, options) {
6150
+ const { filename = "data.json", pretty = false, state } = options ?? {};
6151
+ const jsonString = pretty ? JSON.stringify(data, null, 2) : JSON.stringify(data);
6152
+ const blob = new Blob([jsonString], { type: "application/json" });
6153
+ super({
6154
+ data: blob,
6155
+ filename,
6156
+ contentType: "application/json",
6157
+ state
6158
+ });
6159
+ }
6160
+ };
6123
6161
  ERR_PERMALINK = "https://braintrust.dev/error-generating-link";
6124
6162
  Logger = class {
6125
6163
  state;
@@ -6153,6 +6191,9 @@ with a Blob/ArrayBuffer, or run the program on Node.js.`
6153
6191
  get id() {
6154
6192
  return (async () => (await this.project).id)();
6155
6193
  }
6194
+ get loggingState() {
6195
+ return this.state;
6196
+ }
6156
6197
  parentObjectType() {
6157
6198
  return 2 /* PROJECT_LOGS */;
6158
6199
  }
@@ -6866,6 +6907,9 @@ Error: ${errorText}`;
6866
6907
  return (await this.lazyMetadata.get()).experiment.id;
6867
6908
  })();
6868
6909
  }
6910
+ get loggingState() {
6911
+ return this.state;
6912
+ }
6869
6913
  /**
6870
6914
  * Wait for the experiment ID to be resolved. This is useful for ensuring the ID
6871
6915
  * is available synchronously in child spans (for OTEL parent attributes).
@@ -7131,6 +7175,9 @@ View complete results in Braintrust or run experiment.summarize() again.`
7131
7175
  return (await this.lazyMetadata.get()).experiment.name;
7132
7176
  })();
7133
7177
  }
7178
+ get loggingState() {
7179
+ return this.state;
7180
+ }
7134
7181
  async getState() {
7135
7182
  await this.lazyMetadata.get();
7136
7183
  return this.state;
@@ -7519,6 +7566,9 @@ View complete results in Braintrust or run experiment.summarize() again.`
7519
7566
  return (await this.lazyMetadata.get()).project;
7520
7567
  })();
7521
7568
  }
7569
+ get loggingState() {
7570
+ return this.state;
7571
+ }
7522
7572
  async getState() {
7523
7573
  await this.lazyMetadata.get();
7524
7574
  return this.state;
@@ -11481,6 +11531,7 @@ __export(exports_node_exports, {
11481
11531
  FailedHTTPResponse: () => FailedHTTPResponse,
11482
11532
  IDGenerator: () => IDGenerator,
11483
11533
  INTERNAL_BTQL_LIMIT: () => INTERNAL_BTQL_LIMIT,
11534
+ JSONAttachment: () => JSONAttachment,
11484
11535
  LEGACY_CACHED_HEADER: () => LEGACY_CACHED_HEADER,
11485
11536
  LazyValue: () => LazyValue,
11486
11537
  Logger: () => Logger,
@@ -16799,6 +16850,7 @@ export {
16799
16850
  FailedHTTPResponse,
16800
16851
  IDGenerator,
16801
16852
  INTERNAL_BTQL_LIMIT,
16853
+ JSONAttachment,
16802
16854
  LEGACY_CACHED_HEADER,
16803
16855
  LazyValue,
16804
16856
  Logger,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "braintrust",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "description": "SDK for integrating Braintrust",
5
5
  "repository": {
6
6
  "type": "git",