braintrust 0.0.190 → 0.0.192
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.d.mts +81 -9
- package/dist/browser.d.ts +81 -9
- package/dist/browser.js +91 -12
- package/dist/browser.mjs +91 -13
- package/dist/cli.js +90 -328
- package/dist/index.d.mts +81 -9
- package/dist/index.d.ts +81 -9
- package/dist/index.js +163 -150
- package/dist/index.mjs +164 -152
- package/package.json +5 -5
package/dist/browser.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { GitMetadataSettings,
|
|
1
|
+
import { TRANSACTION_ID_FIELD, TransactionId, ExperimentEvent, DEFAULT_IS_LEGACY_DATASET, DatasetRecord, ExperimentLogFullArgs, ExperimentLogPartialArgs, LogFeedbackFullArgs, SpanType, IdField, BackgroundLogEvent, SpanComponentsV3, SpanObjectTypeV3 } from '@braintrust/core';
|
|
2
|
+
import { GitMetadataSettings, Prompt as Prompt$1, PromptSessionEvent, PromptData, AnyModelParam, OpenAIMessage, Tools, Message, AttachmentReference, AttachmentStatus, BraintrustAttachmentReference, ExternalAttachmentReference, RepoInfo, ModelParams, CallEventSchema, StreamingMode } from '@braintrust/core/typespecs';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
5
5
|
interface IsoAsyncLocalStorage<T> {
|
|
@@ -477,6 +477,18 @@ interface AttachmentParams {
|
|
|
477
477
|
contentType: string;
|
|
478
478
|
state?: BraintrustState;
|
|
479
479
|
}
|
|
480
|
+
interface ExternalAttachmentParams {
|
|
481
|
+
url: string;
|
|
482
|
+
filename: string;
|
|
483
|
+
contentType: string;
|
|
484
|
+
state?: BraintrustState;
|
|
485
|
+
}
|
|
486
|
+
declare abstract class BaseAttachment {
|
|
487
|
+
readonly reference: AttachmentReference;
|
|
488
|
+
abstract upload(): Promise<AttachmentStatus>;
|
|
489
|
+
abstract data(): Promise<Blob>;
|
|
490
|
+
abstract debugInfo(): Record<string, unknown>;
|
|
491
|
+
}
|
|
480
492
|
/**
|
|
481
493
|
* Represents an attachment to be uploaded and the associated metadata.
|
|
482
494
|
* `Attachment` objects can be inserted anywhere in an event, allowing you to
|
|
@@ -484,11 +496,11 @@ interface AttachmentParams {
|
|
|
484
496
|
* object storage and replace the `Attachment` object with an
|
|
485
497
|
* `AttachmentReference`.
|
|
486
498
|
*/
|
|
487
|
-
declare class Attachment {
|
|
499
|
+
declare class Attachment extends BaseAttachment {
|
|
488
500
|
/**
|
|
489
501
|
* The object that replaces this `Attachment` at upload time.
|
|
490
502
|
*/
|
|
491
|
-
readonly reference:
|
|
503
|
+
readonly reference: BraintrustAttachmentReference;
|
|
492
504
|
private readonly uploader;
|
|
493
505
|
private readonly _data;
|
|
494
506
|
private readonly state?;
|
|
@@ -536,6 +548,59 @@ declare class Attachment {
|
|
|
536
548
|
private initUploader;
|
|
537
549
|
private initData;
|
|
538
550
|
}
|
|
551
|
+
/**
|
|
552
|
+
* Represents an attachment that resides in an external object store and the associated metadata.
|
|
553
|
+
*
|
|
554
|
+
* `ExternalAttachment` objects can be inserted anywhere in an event, similar to
|
|
555
|
+
* `Attachment` objects, but they reference files that already exist in an external
|
|
556
|
+
* object store rather than requiring upload. The SDK will replace the `ExternalAttachment`
|
|
557
|
+
* object with an `AttachmentReference` during logging.
|
|
558
|
+
*/
|
|
559
|
+
declare class ExternalAttachment extends BaseAttachment {
|
|
560
|
+
/**
|
|
561
|
+
* The object that replaces this `ExternalAttachment` at upload time.
|
|
562
|
+
*/
|
|
563
|
+
readonly reference: ExternalAttachmentReference;
|
|
564
|
+
private readonly _data;
|
|
565
|
+
private readonly state?;
|
|
566
|
+
/**
|
|
567
|
+
* Construct an external attachment.
|
|
568
|
+
*
|
|
569
|
+
* @param param A parameter object with:
|
|
570
|
+
*
|
|
571
|
+
* `url`: The fully qualified URL of the file in the external object store.
|
|
572
|
+
*
|
|
573
|
+
* `filename`: The desired name of the file in Braintrust after uploading.
|
|
574
|
+
* This parameter is for visualization purposes only and has no effect on
|
|
575
|
+
* attachment storage.
|
|
576
|
+
*
|
|
577
|
+
* `contentType`: The MIME type of the file.
|
|
578
|
+
*
|
|
579
|
+
* `state`: (Optional) For internal use.
|
|
580
|
+
*/
|
|
581
|
+
constructor({ url, filename, contentType, state }: ExternalAttachmentParams);
|
|
582
|
+
/**
|
|
583
|
+
* For ExternalAttachment, this is a no-op since the data already resides
|
|
584
|
+
* in the external object store. It marks the attachment as already uploaded.
|
|
585
|
+
*
|
|
586
|
+
* @returns The attachment status, which will always indicate success.
|
|
587
|
+
*/
|
|
588
|
+
upload(): Promise<{
|
|
589
|
+
upload_status: "done";
|
|
590
|
+
}>;
|
|
591
|
+
/**
|
|
592
|
+
* The attachment contents. This is a lazy value that will read the attachment contents from the external object store on first access.
|
|
593
|
+
*/
|
|
594
|
+
data(): Promise<Blob>;
|
|
595
|
+
/**
|
|
596
|
+
* A human-readable description for logging and debugging.
|
|
597
|
+
*
|
|
598
|
+
* @returns The debug object. The return type is not stable and may change in
|
|
599
|
+
* a future release.
|
|
600
|
+
*/
|
|
601
|
+
debugInfo(): Record<string, unknown>;
|
|
602
|
+
private initData;
|
|
603
|
+
}
|
|
539
604
|
declare const attachmentMetadataSchema: z.ZodObject<{
|
|
540
605
|
downloadUrl: z.ZodString;
|
|
541
606
|
status: z.ZodObject<{
|
|
@@ -1076,17 +1141,19 @@ declare function withParent<R>(parent: string, callback: () => R, state?: Braint
|
|
|
1076
1141
|
/**
|
|
1077
1142
|
* Creates a deep copy of the given event. Replaces references to user objects
|
|
1078
1143
|
* with placeholder strings to ensure serializability, except for
|
|
1079
|
-
* {@link Attachment} objects, which are preserved
|
|
1144
|
+
* {@link Attachment} and {@link ExternalAttachment} objects, which are preserved
|
|
1145
|
+
* and not deep-copied.
|
|
1080
1146
|
*/
|
|
1081
1147
|
declare function deepCopyEvent<T extends Partial<BackgroundLogEvent>>(event: T): T;
|
|
1082
1148
|
/**
|
|
1083
1149
|
* Helper function for uploading attachments. Recursively extracts `Attachment`
|
|
1084
|
-
*
|
|
1150
|
+
* and `ExternalAttachment` objects and replaces them with their associated
|
|
1151
|
+
* `AttachmentReference` objects.
|
|
1085
1152
|
*
|
|
1086
1153
|
* @param event The event to filter. Will be modified in-place.
|
|
1087
1154
|
* @param attachments Flat array of extracted attachments (output parameter).
|
|
1088
1155
|
*/
|
|
1089
|
-
declare function extractAttachments(event: Record<string, any>, attachments:
|
|
1156
|
+
declare function extractAttachments(event: Record<string, any>, attachments: BaseAttachment[]): void;
|
|
1090
1157
|
type WithTransactionId<R> = R & {
|
|
1091
1158
|
[TRANSACTION_ID_FIELD]: TransactionId;
|
|
1092
1159
|
};
|
|
@@ -1915,6 +1982,8 @@ type braintrust_Attachment = Attachment;
|
|
|
1915
1982
|
declare const braintrust_Attachment: typeof Attachment;
|
|
1916
1983
|
type braintrust_AttachmentParams = AttachmentParams;
|
|
1917
1984
|
type braintrust_BackgroundLoggerOpts = BackgroundLoggerOpts;
|
|
1985
|
+
type braintrust_BaseAttachment = BaseAttachment;
|
|
1986
|
+
declare const braintrust_BaseAttachment: typeof BaseAttachment;
|
|
1918
1987
|
type braintrust_BaseMetadata = BaseMetadata;
|
|
1919
1988
|
type braintrust_BraintrustState = BraintrustState;
|
|
1920
1989
|
declare const braintrust_BraintrustState: typeof BraintrustState;
|
|
@@ -1937,6 +2006,9 @@ type braintrust_Experiment = Experiment;
|
|
|
1937
2006
|
declare const braintrust_Experiment: typeof Experiment;
|
|
1938
2007
|
type braintrust_ExperimentSummary = ExperimentSummary;
|
|
1939
2008
|
type braintrust_Exportable = Exportable;
|
|
2009
|
+
type braintrust_ExternalAttachment = ExternalAttachment;
|
|
2010
|
+
declare const braintrust_ExternalAttachment: typeof ExternalAttachment;
|
|
2011
|
+
type braintrust_ExternalAttachmentParams = ExternalAttachmentParams;
|
|
1940
2012
|
type braintrust_FailedHTTPResponse = FailedHTTPResponse;
|
|
1941
2013
|
declare const braintrust_FailedHTTPResponse: typeof FailedHTTPResponse;
|
|
1942
2014
|
type braintrust_FullInitOptions<IsOpen extends boolean> = FullInitOptions<IsOpen>;
|
|
@@ -2015,7 +2087,7 @@ declare const braintrust_wrapOpenAI: typeof wrapOpenAI;
|
|
|
2015
2087
|
declare const braintrust_wrapOpenAIv4: typeof wrapOpenAIv4;
|
|
2016
2088
|
declare const braintrust_wrapTraced: typeof wrapTraced;
|
|
2017
2089
|
declare namespace braintrust {
|
|
2018
|
-
export { type braintrust_AnyDataset as AnyDataset, braintrust_Attachment as Attachment, type braintrust_AttachmentParams as AttachmentParams, type braintrust_BackgroundLoggerOpts as BackgroundLoggerOpts, type braintrust_BaseMetadata as BaseMetadata, braintrust_BraintrustState as BraintrustState, braintrust_BraintrustStream as BraintrustStream, type braintrust_BraintrustStreamChunk as BraintrustStreamChunk, type braintrust_ChatPrompt as ChatPrompt, type braintrust_CompiledPrompt as CompiledPrompt, type braintrust_CompiledPromptParams as CompiledPromptParams, type braintrust_CompletionPrompt as CompletionPrompt, type braintrust_DataSummary as DataSummary, braintrust_Dataset as Dataset, type braintrust_DatasetSummary as DatasetSummary, type braintrust_DefaultMetadataType as DefaultMetadataType, type braintrust_DefaultPromptArgs as DefaultPromptArgs, type braintrust_EndSpanArgs as EndSpanArgs, type braintrust_EvalCase as EvalCase, braintrust_Experiment as Experiment, type braintrust_ExperimentSummary as ExperimentSummary, type braintrust_Exportable as Exportable, braintrust_FailedHTTPResponse as FailedHTTPResponse, type braintrust_FullInitOptions as FullInitOptions, type braintrust_FullLoginOptions as FullLoginOptions, type braintrust_InitOptions as InitOptions, type braintrust_InvokeFunctionArgs as InvokeFunctionArgs, type braintrust_InvokeReturn as InvokeReturn, braintrust_LEGACY_CACHED_HEADER as LEGACY_CACHED_HEADER, type braintrust_LogOptions as LogOptions, braintrust_Logger as Logger, type braintrust_LoginOptions as LoginOptions, type braintrust_MetricSummary as MetricSummary, braintrust_NOOP_SPAN as NOOP_SPAN, braintrust_NoopSpan as NoopSpan, type braintrust_ObjectMetadata as ObjectMetadata, type braintrust_PromiseUnless as PromiseUnless, braintrust_Prompt as Prompt, type braintrust_PromptRowWithId as PromptRowWithId, braintrust_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, 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_deserializePlainStringAsJSON as deserializePlainStringAsJSON, braintrust_devNullWritableStream as devNullWritableStream, braintrust_flush as flush, braintrust_getSpanParentObject as getSpanParentObject, braintrust_init as init, braintrust_initDataset as initDataset, braintrust_initExperiment as initExperiment, braintrust_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_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 };
|
|
2090
|
+
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_CompiledPrompt as CompiledPrompt, type braintrust_CompiledPromptParams as CompiledPromptParams, type braintrust_CompletionPrompt as CompletionPrompt, type braintrust_DataSummary as DataSummary, braintrust_Dataset as Dataset, type braintrust_DatasetSummary as DatasetSummary, type braintrust_DefaultMetadataType as DefaultMetadataType, type braintrust_DefaultPromptArgs as DefaultPromptArgs, type braintrust_EndSpanArgs as EndSpanArgs, type braintrust_EvalCase as EvalCase, braintrust_Experiment as Experiment, type braintrust_ExperimentSummary as ExperimentSummary, type braintrust_Exportable as Exportable, braintrust_ExternalAttachment as ExternalAttachment, type braintrust_ExternalAttachmentParams as ExternalAttachmentParams, braintrust_FailedHTTPResponse as FailedHTTPResponse, type braintrust_FullInitOptions as FullInitOptions, type braintrust_FullLoginOptions as FullLoginOptions, type braintrust_InitOptions as InitOptions, type braintrust_InvokeFunctionArgs as InvokeFunctionArgs, type braintrust_InvokeReturn as InvokeReturn, braintrust_LEGACY_CACHED_HEADER as LEGACY_CACHED_HEADER, type braintrust_LogOptions as LogOptions, braintrust_Logger as Logger, type braintrust_LoginOptions as LoginOptions, type braintrust_MetricSummary as MetricSummary, braintrust_NOOP_SPAN as NOOP_SPAN, braintrust_NoopSpan as NoopSpan, type braintrust_ObjectMetadata as ObjectMetadata, type braintrust_PromiseUnless as PromiseUnless, braintrust_Prompt as Prompt, type braintrust_PromptRowWithId as PromptRowWithId, braintrust_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, 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_deserializePlainStringAsJSON as deserializePlainStringAsJSON, braintrust_devNullWritableStream as devNullWritableStream, braintrust_flush as flush, braintrust_getSpanParentObject as getSpanParentObject, braintrust_init as init, braintrust_initDataset as initDataset, braintrust_initExperiment as initExperiment, braintrust_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_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 };
|
|
2019
2091
|
}
|
|
2020
2092
|
|
|
2021
|
-
export { type AnyDataset, Attachment, type AttachmentParams, type BackgroundLoggerOpts, type BaseMetadata, BraintrustState, BraintrustStream, type BraintrustStreamChunk, type ChatPrompt, type CompiledPrompt, type CompiledPromptParams, type CompletionPrompt, type DataSummary, Dataset, type DatasetSummary, type DefaultMetadataType, type DefaultPromptArgs, type EndSpanArgs, type EvalCase, Experiment, type ExperimentSummary, type Exportable, FailedHTTPResponse, type FullInitOptions, type FullLoginOptions, type InitOptions, type InvokeFunctionArgs, type InvokeReturn, LEGACY_CACHED_HEADER, type LogOptions, Logger, type LoginOptions, type MetricSummary, NOOP_SPAN, NoopSpan, type ObjectMetadata, type PromiseUnless, Prompt, type PromptRowWithId, ReadonlyAttachment, ReadonlyExperiment, type ScoreSummary, type SerializedBraintrustState, type SetCurrentArg, type Span, SpanImpl, type StartSpanArgs, type WithTransactionId, X_CACHED_HEADER, _exportsForTestingOnly, _internalGetGlobalState, _internalSetInitialState, braintrustStreamChunkSchema, createFinalValuePassThroughStream, currentExperiment, currentLogger, currentSpan, braintrust as default, deserializePlainStringAsJSON, devNullWritableStream, flush, getSpanParentObject, init, initDataset, initExperiment, initFunction, initLogger, invoke, loadPrompt, log, logError, login, loginToState, newId, parseCachedHeader, permalink, renderMessage, renderPromptParams, setFetch, spanComponentsToObjectId, startSpan, summarize, traceable, traced, updateSpan, withCurrent, withDataset, withExperiment, withLogger, withParent, wrapOpenAI, wrapOpenAIv4, wrapTraced };
|
|
2093
|
+
export { type AnyDataset, Attachment, type AttachmentParams, type BackgroundLoggerOpts, BaseAttachment, type BaseMetadata, BraintrustState, BraintrustStream, type BraintrustStreamChunk, type ChatPrompt, type CompiledPrompt, type CompiledPromptParams, type CompletionPrompt, type DataSummary, Dataset, type DatasetSummary, type DefaultMetadataType, type DefaultPromptArgs, type EndSpanArgs, type EvalCase, Experiment, type ExperimentSummary, type Exportable, ExternalAttachment, type ExternalAttachmentParams, FailedHTTPResponse, type FullInitOptions, type FullLoginOptions, type InitOptions, type InvokeFunctionArgs, type InvokeReturn, LEGACY_CACHED_HEADER, type LogOptions, Logger, type LoginOptions, type MetricSummary, NOOP_SPAN, NoopSpan, type ObjectMetadata, type PromiseUnless, Prompt, type PromptRowWithId, ReadonlyAttachment, ReadonlyExperiment, type ScoreSummary, type SerializedBraintrustState, type SetCurrentArg, type Span, SpanImpl, type StartSpanArgs, type WithTransactionId, X_CACHED_HEADER, _exportsForTestingOnly, _internalGetGlobalState, _internalSetInitialState, braintrustStreamChunkSchema, createFinalValuePassThroughStream, currentExperiment, currentLogger, currentSpan, braintrust as default, deserializePlainStringAsJSON, devNullWritableStream, flush, getSpanParentObject, init, initDataset, initExperiment, initFunction, initLogger, invoke, loadPrompt, log, logError, login, loginToState, newId, parseCachedHeader, permalink, renderMessage, renderPromptParams, setFetch, spanComponentsToObjectId, startSpan, summarize, traceable, traced, updateSpan, withCurrent, withDataset, withExperiment, withLogger, withParent, wrapOpenAI, wrapOpenAIv4, wrapTraced };
|
package/dist/browser.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { GitMetadataSettings,
|
|
1
|
+
import { TRANSACTION_ID_FIELD, TransactionId, ExperimentEvent, DEFAULT_IS_LEGACY_DATASET, DatasetRecord, ExperimentLogFullArgs, ExperimentLogPartialArgs, LogFeedbackFullArgs, SpanType, IdField, BackgroundLogEvent, SpanComponentsV3, SpanObjectTypeV3 } from '@braintrust/core';
|
|
2
|
+
import { GitMetadataSettings, Prompt as Prompt$1, PromptSessionEvent, PromptData, AnyModelParam, OpenAIMessage, Tools, Message, AttachmentReference, AttachmentStatus, BraintrustAttachmentReference, ExternalAttachmentReference, RepoInfo, ModelParams, CallEventSchema, StreamingMode } from '@braintrust/core/typespecs';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
5
5
|
interface IsoAsyncLocalStorage<T> {
|
|
@@ -477,6 +477,18 @@ interface AttachmentParams {
|
|
|
477
477
|
contentType: string;
|
|
478
478
|
state?: BraintrustState;
|
|
479
479
|
}
|
|
480
|
+
interface ExternalAttachmentParams {
|
|
481
|
+
url: string;
|
|
482
|
+
filename: string;
|
|
483
|
+
contentType: string;
|
|
484
|
+
state?: BraintrustState;
|
|
485
|
+
}
|
|
486
|
+
declare abstract class BaseAttachment {
|
|
487
|
+
readonly reference: AttachmentReference;
|
|
488
|
+
abstract upload(): Promise<AttachmentStatus>;
|
|
489
|
+
abstract data(): Promise<Blob>;
|
|
490
|
+
abstract debugInfo(): Record<string, unknown>;
|
|
491
|
+
}
|
|
480
492
|
/**
|
|
481
493
|
* Represents an attachment to be uploaded and the associated metadata.
|
|
482
494
|
* `Attachment` objects can be inserted anywhere in an event, allowing you to
|
|
@@ -484,11 +496,11 @@ interface AttachmentParams {
|
|
|
484
496
|
* object storage and replace the `Attachment` object with an
|
|
485
497
|
* `AttachmentReference`.
|
|
486
498
|
*/
|
|
487
|
-
declare class Attachment {
|
|
499
|
+
declare class Attachment extends BaseAttachment {
|
|
488
500
|
/**
|
|
489
501
|
* The object that replaces this `Attachment` at upload time.
|
|
490
502
|
*/
|
|
491
|
-
readonly reference:
|
|
503
|
+
readonly reference: BraintrustAttachmentReference;
|
|
492
504
|
private readonly uploader;
|
|
493
505
|
private readonly _data;
|
|
494
506
|
private readonly state?;
|
|
@@ -536,6 +548,59 @@ declare class Attachment {
|
|
|
536
548
|
private initUploader;
|
|
537
549
|
private initData;
|
|
538
550
|
}
|
|
551
|
+
/**
|
|
552
|
+
* Represents an attachment that resides in an external object store and the associated metadata.
|
|
553
|
+
*
|
|
554
|
+
* `ExternalAttachment` objects can be inserted anywhere in an event, similar to
|
|
555
|
+
* `Attachment` objects, but they reference files that already exist in an external
|
|
556
|
+
* object store rather than requiring upload. The SDK will replace the `ExternalAttachment`
|
|
557
|
+
* object with an `AttachmentReference` during logging.
|
|
558
|
+
*/
|
|
559
|
+
declare class ExternalAttachment extends BaseAttachment {
|
|
560
|
+
/**
|
|
561
|
+
* The object that replaces this `ExternalAttachment` at upload time.
|
|
562
|
+
*/
|
|
563
|
+
readonly reference: ExternalAttachmentReference;
|
|
564
|
+
private readonly _data;
|
|
565
|
+
private readonly state?;
|
|
566
|
+
/**
|
|
567
|
+
* Construct an external attachment.
|
|
568
|
+
*
|
|
569
|
+
* @param param A parameter object with:
|
|
570
|
+
*
|
|
571
|
+
* `url`: The fully qualified URL of the file in the external object store.
|
|
572
|
+
*
|
|
573
|
+
* `filename`: The desired name of the file in Braintrust after uploading.
|
|
574
|
+
* This parameter is for visualization purposes only and has no effect on
|
|
575
|
+
* attachment storage.
|
|
576
|
+
*
|
|
577
|
+
* `contentType`: The MIME type of the file.
|
|
578
|
+
*
|
|
579
|
+
* `state`: (Optional) For internal use.
|
|
580
|
+
*/
|
|
581
|
+
constructor({ url, filename, contentType, state }: ExternalAttachmentParams);
|
|
582
|
+
/**
|
|
583
|
+
* For ExternalAttachment, this is a no-op since the data already resides
|
|
584
|
+
* in the external object store. It marks the attachment as already uploaded.
|
|
585
|
+
*
|
|
586
|
+
* @returns The attachment status, which will always indicate success.
|
|
587
|
+
*/
|
|
588
|
+
upload(): Promise<{
|
|
589
|
+
upload_status: "done";
|
|
590
|
+
}>;
|
|
591
|
+
/**
|
|
592
|
+
* The attachment contents. This is a lazy value that will read the attachment contents from the external object store on first access.
|
|
593
|
+
*/
|
|
594
|
+
data(): Promise<Blob>;
|
|
595
|
+
/**
|
|
596
|
+
* A human-readable description for logging and debugging.
|
|
597
|
+
*
|
|
598
|
+
* @returns The debug object. The return type is not stable and may change in
|
|
599
|
+
* a future release.
|
|
600
|
+
*/
|
|
601
|
+
debugInfo(): Record<string, unknown>;
|
|
602
|
+
private initData;
|
|
603
|
+
}
|
|
539
604
|
declare const attachmentMetadataSchema: z.ZodObject<{
|
|
540
605
|
downloadUrl: z.ZodString;
|
|
541
606
|
status: z.ZodObject<{
|
|
@@ -1076,17 +1141,19 @@ declare function withParent<R>(parent: string, callback: () => R, state?: Braint
|
|
|
1076
1141
|
/**
|
|
1077
1142
|
* Creates a deep copy of the given event. Replaces references to user objects
|
|
1078
1143
|
* with placeholder strings to ensure serializability, except for
|
|
1079
|
-
* {@link Attachment} objects, which are preserved
|
|
1144
|
+
* {@link Attachment} and {@link ExternalAttachment} objects, which are preserved
|
|
1145
|
+
* and not deep-copied.
|
|
1080
1146
|
*/
|
|
1081
1147
|
declare function deepCopyEvent<T extends Partial<BackgroundLogEvent>>(event: T): T;
|
|
1082
1148
|
/**
|
|
1083
1149
|
* Helper function for uploading attachments. Recursively extracts `Attachment`
|
|
1084
|
-
*
|
|
1150
|
+
* and `ExternalAttachment` objects and replaces them with their associated
|
|
1151
|
+
* `AttachmentReference` objects.
|
|
1085
1152
|
*
|
|
1086
1153
|
* @param event The event to filter. Will be modified in-place.
|
|
1087
1154
|
* @param attachments Flat array of extracted attachments (output parameter).
|
|
1088
1155
|
*/
|
|
1089
|
-
declare function extractAttachments(event: Record<string, any>, attachments:
|
|
1156
|
+
declare function extractAttachments(event: Record<string, any>, attachments: BaseAttachment[]): void;
|
|
1090
1157
|
type WithTransactionId<R> = R & {
|
|
1091
1158
|
[TRANSACTION_ID_FIELD]: TransactionId;
|
|
1092
1159
|
};
|
|
@@ -1915,6 +1982,8 @@ type braintrust_Attachment = Attachment;
|
|
|
1915
1982
|
declare const braintrust_Attachment: typeof Attachment;
|
|
1916
1983
|
type braintrust_AttachmentParams = AttachmentParams;
|
|
1917
1984
|
type braintrust_BackgroundLoggerOpts = BackgroundLoggerOpts;
|
|
1985
|
+
type braintrust_BaseAttachment = BaseAttachment;
|
|
1986
|
+
declare const braintrust_BaseAttachment: typeof BaseAttachment;
|
|
1918
1987
|
type braintrust_BaseMetadata = BaseMetadata;
|
|
1919
1988
|
type braintrust_BraintrustState = BraintrustState;
|
|
1920
1989
|
declare const braintrust_BraintrustState: typeof BraintrustState;
|
|
@@ -1937,6 +2006,9 @@ type braintrust_Experiment = Experiment;
|
|
|
1937
2006
|
declare const braintrust_Experiment: typeof Experiment;
|
|
1938
2007
|
type braintrust_ExperimentSummary = ExperimentSummary;
|
|
1939
2008
|
type braintrust_Exportable = Exportable;
|
|
2009
|
+
type braintrust_ExternalAttachment = ExternalAttachment;
|
|
2010
|
+
declare const braintrust_ExternalAttachment: typeof ExternalAttachment;
|
|
2011
|
+
type braintrust_ExternalAttachmentParams = ExternalAttachmentParams;
|
|
1940
2012
|
type braintrust_FailedHTTPResponse = FailedHTTPResponse;
|
|
1941
2013
|
declare const braintrust_FailedHTTPResponse: typeof FailedHTTPResponse;
|
|
1942
2014
|
type braintrust_FullInitOptions<IsOpen extends boolean> = FullInitOptions<IsOpen>;
|
|
@@ -2015,7 +2087,7 @@ declare const braintrust_wrapOpenAI: typeof wrapOpenAI;
|
|
|
2015
2087
|
declare const braintrust_wrapOpenAIv4: typeof wrapOpenAIv4;
|
|
2016
2088
|
declare const braintrust_wrapTraced: typeof wrapTraced;
|
|
2017
2089
|
declare namespace braintrust {
|
|
2018
|
-
export { type braintrust_AnyDataset as AnyDataset, braintrust_Attachment as Attachment, type braintrust_AttachmentParams as AttachmentParams, type braintrust_BackgroundLoggerOpts as BackgroundLoggerOpts, type braintrust_BaseMetadata as BaseMetadata, braintrust_BraintrustState as BraintrustState, braintrust_BraintrustStream as BraintrustStream, type braintrust_BraintrustStreamChunk as BraintrustStreamChunk, type braintrust_ChatPrompt as ChatPrompt, type braintrust_CompiledPrompt as CompiledPrompt, type braintrust_CompiledPromptParams as CompiledPromptParams, type braintrust_CompletionPrompt as CompletionPrompt, type braintrust_DataSummary as DataSummary, braintrust_Dataset as Dataset, type braintrust_DatasetSummary as DatasetSummary, type braintrust_DefaultMetadataType as DefaultMetadataType, type braintrust_DefaultPromptArgs as DefaultPromptArgs, type braintrust_EndSpanArgs as EndSpanArgs, type braintrust_EvalCase as EvalCase, braintrust_Experiment as Experiment, type braintrust_ExperimentSummary as ExperimentSummary, type braintrust_Exportable as Exportable, braintrust_FailedHTTPResponse as FailedHTTPResponse, type braintrust_FullInitOptions as FullInitOptions, type braintrust_FullLoginOptions as FullLoginOptions, type braintrust_InitOptions as InitOptions, type braintrust_InvokeFunctionArgs as InvokeFunctionArgs, type braintrust_InvokeReturn as InvokeReturn, braintrust_LEGACY_CACHED_HEADER as LEGACY_CACHED_HEADER, type braintrust_LogOptions as LogOptions, braintrust_Logger as Logger, type braintrust_LoginOptions as LoginOptions, type braintrust_MetricSummary as MetricSummary, braintrust_NOOP_SPAN as NOOP_SPAN, braintrust_NoopSpan as NoopSpan, type braintrust_ObjectMetadata as ObjectMetadata, type braintrust_PromiseUnless as PromiseUnless, braintrust_Prompt as Prompt, type braintrust_PromptRowWithId as PromptRowWithId, braintrust_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, 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_deserializePlainStringAsJSON as deserializePlainStringAsJSON, braintrust_devNullWritableStream as devNullWritableStream, braintrust_flush as flush, braintrust_getSpanParentObject as getSpanParentObject, braintrust_init as init, braintrust_initDataset as initDataset, braintrust_initExperiment as initExperiment, braintrust_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_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 };
|
|
2090
|
+
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_CompiledPrompt as CompiledPrompt, type braintrust_CompiledPromptParams as CompiledPromptParams, type braintrust_CompletionPrompt as CompletionPrompt, type braintrust_DataSummary as DataSummary, braintrust_Dataset as Dataset, type braintrust_DatasetSummary as DatasetSummary, type braintrust_DefaultMetadataType as DefaultMetadataType, type braintrust_DefaultPromptArgs as DefaultPromptArgs, type braintrust_EndSpanArgs as EndSpanArgs, type braintrust_EvalCase as EvalCase, braintrust_Experiment as Experiment, type braintrust_ExperimentSummary as ExperimentSummary, type braintrust_Exportable as Exportable, braintrust_ExternalAttachment as ExternalAttachment, type braintrust_ExternalAttachmentParams as ExternalAttachmentParams, braintrust_FailedHTTPResponse as FailedHTTPResponse, type braintrust_FullInitOptions as FullInitOptions, type braintrust_FullLoginOptions as FullLoginOptions, type braintrust_InitOptions as InitOptions, type braintrust_InvokeFunctionArgs as InvokeFunctionArgs, type braintrust_InvokeReturn as InvokeReturn, braintrust_LEGACY_CACHED_HEADER as LEGACY_CACHED_HEADER, type braintrust_LogOptions as LogOptions, braintrust_Logger as Logger, type braintrust_LoginOptions as LoginOptions, type braintrust_MetricSummary as MetricSummary, braintrust_NOOP_SPAN as NOOP_SPAN, braintrust_NoopSpan as NoopSpan, type braintrust_ObjectMetadata as ObjectMetadata, type braintrust_PromiseUnless as PromiseUnless, braintrust_Prompt as Prompt, type braintrust_PromptRowWithId as PromptRowWithId, braintrust_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, 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_deserializePlainStringAsJSON as deserializePlainStringAsJSON, braintrust_devNullWritableStream as devNullWritableStream, braintrust_flush as flush, braintrust_getSpanParentObject as getSpanParentObject, braintrust_init as init, braintrust_initDataset as initDataset, braintrust_initExperiment as initExperiment, braintrust_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_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 };
|
|
2019
2091
|
}
|
|
2020
2092
|
|
|
2021
|
-
export { type AnyDataset, Attachment, type AttachmentParams, type BackgroundLoggerOpts, type BaseMetadata, BraintrustState, BraintrustStream, type BraintrustStreamChunk, type ChatPrompt, type CompiledPrompt, type CompiledPromptParams, type CompletionPrompt, type DataSummary, Dataset, type DatasetSummary, type DefaultMetadataType, type DefaultPromptArgs, type EndSpanArgs, type EvalCase, Experiment, type ExperimentSummary, type Exportable, FailedHTTPResponse, type FullInitOptions, type FullLoginOptions, type InitOptions, type InvokeFunctionArgs, type InvokeReturn, LEGACY_CACHED_HEADER, type LogOptions, Logger, type LoginOptions, type MetricSummary, NOOP_SPAN, NoopSpan, type ObjectMetadata, type PromiseUnless, Prompt, type PromptRowWithId, ReadonlyAttachment, ReadonlyExperiment, type ScoreSummary, type SerializedBraintrustState, type SetCurrentArg, type Span, SpanImpl, type StartSpanArgs, type WithTransactionId, X_CACHED_HEADER, _exportsForTestingOnly, _internalGetGlobalState, _internalSetInitialState, braintrustStreamChunkSchema, createFinalValuePassThroughStream, currentExperiment, currentLogger, currentSpan, braintrust as default, deserializePlainStringAsJSON, devNullWritableStream, flush, getSpanParentObject, init, initDataset, initExperiment, initFunction, initLogger, invoke, loadPrompt, log, logError, login, loginToState, newId, parseCachedHeader, permalink, renderMessage, renderPromptParams, setFetch, spanComponentsToObjectId, startSpan, summarize, traceable, traced, updateSpan, withCurrent, withDataset, withExperiment, withLogger, withParent, wrapOpenAI, wrapOpenAIv4, wrapTraced };
|
|
2093
|
+
export { type AnyDataset, Attachment, type AttachmentParams, type BackgroundLoggerOpts, BaseAttachment, type BaseMetadata, BraintrustState, BraintrustStream, type BraintrustStreamChunk, type ChatPrompt, type CompiledPrompt, type CompiledPromptParams, type CompletionPrompt, type DataSummary, Dataset, type DatasetSummary, type DefaultMetadataType, type DefaultPromptArgs, type EndSpanArgs, type EvalCase, Experiment, type ExperimentSummary, type Exportable, ExternalAttachment, type ExternalAttachmentParams, FailedHTTPResponse, type FullInitOptions, type FullLoginOptions, type InitOptions, type InvokeFunctionArgs, type InvokeReturn, LEGACY_CACHED_HEADER, type LogOptions, Logger, type LoginOptions, type MetricSummary, NOOP_SPAN, NoopSpan, type ObjectMetadata, type PromiseUnless, Prompt, type PromptRowWithId, ReadonlyAttachment, ReadonlyExperiment, type ScoreSummary, type SerializedBraintrustState, type SetCurrentArg, type Span, SpanImpl, type StartSpanArgs, type WithTransactionId, X_CACHED_HEADER, _exportsForTestingOnly, _internalGetGlobalState, _internalSetInitialState, braintrustStreamChunkSchema, createFinalValuePassThroughStream, currentExperiment, currentLogger, currentSpan, braintrust as default, deserializePlainStringAsJSON, devNullWritableStream, flush, getSpanParentObject, init, initDataset, initExperiment, initFunction, initLogger, invoke, loadPrompt, log, logError, login, loginToState, newId, parseCachedHeader, permalink, renderMessage, renderPromptParams, setFetch, spanComponentsToObjectId, startSpan, summarize, traceable, traced, updateSpan, withCurrent, withDataset, withExperiment, withLogger, withParent, wrapOpenAI, wrapOpenAIv4, wrapTraced };
|
package/dist/browser.js
CHANGED
|
@@ -31,10 +31,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var browser_exports = {};
|
|
32
32
|
__export(browser_exports, {
|
|
33
33
|
Attachment: () => Attachment,
|
|
34
|
+
BaseAttachment: () => BaseAttachment,
|
|
34
35
|
BraintrustState: () => BraintrustState,
|
|
35
36
|
BraintrustStream: () => BraintrustStream,
|
|
36
37
|
Dataset: () => Dataset,
|
|
37
38
|
Experiment: () => Experiment,
|
|
39
|
+
ExternalAttachment: () => ExternalAttachment,
|
|
38
40
|
FailedHTTPResponse: () => FailedHTTPResponse,
|
|
39
41
|
LEGACY_CACHED_HEADER: () => LEGACY_CACHED_HEADER,
|
|
40
42
|
Logger: () => Logger,
|
|
@@ -1006,7 +1008,10 @@ var HTTPConnection = class _HTTPConnection {
|
|
|
1006
1008
|
return await resp.json();
|
|
1007
1009
|
}
|
|
1008
1010
|
};
|
|
1009
|
-
var
|
|
1011
|
+
var BaseAttachment = class {
|
|
1012
|
+
reference;
|
|
1013
|
+
};
|
|
1014
|
+
var Attachment = class extends BaseAttachment {
|
|
1010
1015
|
/**
|
|
1011
1016
|
* The object that replaces this `Attachment` at upload time.
|
|
1012
1017
|
*/
|
|
@@ -1034,6 +1039,7 @@ var Attachment = class {
|
|
|
1034
1039
|
* `state`: (Optional) For internal use.
|
|
1035
1040
|
*/
|
|
1036
1041
|
constructor({ data, filename, contentType, state }) {
|
|
1042
|
+
super();
|
|
1037
1043
|
this.reference = {
|
|
1038
1044
|
type: import_typespecs2.BRAINTRUST_ATTACHMENT,
|
|
1039
1045
|
filename,
|
|
@@ -1176,6 +1182,73 @@ with a Blob/ArrayBuffer, or run the program on Node.js.`
|
|
|
1176
1182
|
}
|
|
1177
1183
|
}
|
|
1178
1184
|
};
|
|
1185
|
+
var ExternalAttachment = class extends BaseAttachment {
|
|
1186
|
+
/**
|
|
1187
|
+
* The object that replaces this `ExternalAttachment` at upload time.
|
|
1188
|
+
*/
|
|
1189
|
+
reference;
|
|
1190
|
+
_data;
|
|
1191
|
+
state;
|
|
1192
|
+
/**
|
|
1193
|
+
* Construct an external attachment.
|
|
1194
|
+
*
|
|
1195
|
+
* @param param A parameter object with:
|
|
1196
|
+
*
|
|
1197
|
+
* `url`: The fully qualified URL of the file in the external object store.
|
|
1198
|
+
*
|
|
1199
|
+
* `filename`: The desired name of the file in Braintrust after uploading.
|
|
1200
|
+
* This parameter is for visualization purposes only and has no effect on
|
|
1201
|
+
* attachment storage.
|
|
1202
|
+
*
|
|
1203
|
+
* `contentType`: The MIME type of the file.
|
|
1204
|
+
*
|
|
1205
|
+
* `state`: (Optional) For internal use.
|
|
1206
|
+
*/
|
|
1207
|
+
constructor({ url, filename, contentType, state }) {
|
|
1208
|
+
super();
|
|
1209
|
+
this.reference = {
|
|
1210
|
+
type: import_typespecs2.EXTERNAL_ATTACHMENT,
|
|
1211
|
+
filename,
|
|
1212
|
+
content_type: contentType,
|
|
1213
|
+
url
|
|
1214
|
+
};
|
|
1215
|
+
this._data = this.initData();
|
|
1216
|
+
}
|
|
1217
|
+
/**
|
|
1218
|
+
* For ExternalAttachment, this is a no-op since the data already resides
|
|
1219
|
+
* in the external object store. It marks the attachment as already uploaded.
|
|
1220
|
+
*
|
|
1221
|
+
* @returns The attachment status, which will always indicate success.
|
|
1222
|
+
*/
|
|
1223
|
+
async upload() {
|
|
1224
|
+
return { upload_status: "done" };
|
|
1225
|
+
}
|
|
1226
|
+
/**
|
|
1227
|
+
* The attachment contents. This is a lazy value that will read the attachment contents from the external object store on first access.
|
|
1228
|
+
*/
|
|
1229
|
+
async data() {
|
|
1230
|
+
return this._data.get();
|
|
1231
|
+
}
|
|
1232
|
+
/**
|
|
1233
|
+
* A human-readable description for logging and debugging.
|
|
1234
|
+
*
|
|
1235
|
+
* @returns The debug object. The return type is not stable and may change in
|
|
1236
|
+
* a future release.
|
|
1237
|
+
*/
|
|
1238
|
+
debugInfo() {
|
|
1239
|
+
return {
|
|
1240
|
+
url: this.reference.url,
|
|
1241
|
+
reference: this.reference,
|
|
1242
|
+
state: this.state
|
|
1243
|
+
};
|
|
1244
|
+
}
|
|
1245
|
+
initData() {
|
|
1246
|
+
return new LazyValue(async () => {
|
|
1247
|
+
const readonly = new ReadonlyAttachment(this.reference, this.state);
|
|
1248
|
+
return await readonly.data();
|
|
1249
|
+
});
|
|
1250
|
+
}
|
|
1251
|
+
};
|
|
1179
1252
|
var attachmentMetadataSchema = import_zod2.z.object({
|
|
1180
1253
|
downloadUrl: import_zod2.z.string(),
|
|
1181
1254
|
status: import_typespecs2.attachmentStatusSchema
|
|
@@ -1214,12 +1287,17 @@ var ReadonlyAttachment = class {
|
|
|
1214
1287
|
async metadata() {
|
|
1215
1288
|
const state = this.state ?? _globalState;
|
|
1216
1289
|
await state.login({});
|
|
1217
|
-
|
|
1218
|
-
key: this.reference.key,
|
|
1290
|
+
let params = {
|
|
1219
1291
|
filename: this.reference.filename,
|
|
1220
1292
|
content_type: this.reference.content_type,
|
|
1221
1293
|
org_id: state.orgId || ""
|
|
1222
|
-
}
|
|
1294
|
+
};
|
|
1295
|
+
if (this.reference.type === "braintrust_attachment") {
|
|
1296
|
+
params.key = this.reference.key;
|
|
1297
|
+
} else if (this.reference.type === "external_attachment") {
|
|
1298
|
+
params.url = this.reference.url;
|
|
1299
|
+
}
|
|
1300
|
+
const resp = await state.apiConn().get("/attachment", params);
|
|
1223
1301
|
if (!resp.ok) {
|
|
1224
1302
|
const errorStr = JSON.stringify(resp);
|
|
1225
1303
|
throw new Error(`Invalid response from API server: ${errorStr}`);
|
|
@@ -1668,8 +1746,7 @@ var Logger = class {
|
|
|
1668
1746
|
}
|
|
1669
1747
|
};
|
|
1670
1748
|
function castLogger(logger, asyncFlush) {
|
|
1671
|
-
if (logger === void 0)
|
|
1672
|
-
return void 0;
|
|
1749
|
+
if (logger === void 0) return void 0;
|
|
1673
1750
|
if (asyncFlush !== void 0 && !!asyncFlush !== !!logger.asyncFlush) {
|
|
1674
1751
|
throw new Error(
|
|
1675
1752
|
`Asserted asyncFlush setting ${asyncFlush} does not match stored logger's setting ${logger.asyncFlush}`
|
|
@@ -2818,7 +2895,7 @@ function deepCopyEvent(event) {
|
|
|
2818
2895
|
return `<dataset>`;
|
|
2819
2896
|
} else if (v instanceof Logger) {
|
|
2820
2897
|
return `<logger>`;
|
|
2821
|
-
} else if (v instanceof
|
|
2898
|
+
} else if (v instanceof BaseAttachment) {
|
|
2822
2899
|
const idx = attachments.push(v);
|
|
2823
2900
|
return { [IDENTIFIER]: idx - 1 };
|
|
2824
2901
|
} else if (v instanceof ReadonlyAttachment) {
|
|
@@ -2837,7 +2914,7 @@ function deepCopyEvent(event) {
|
|
|
2837
2914
|
}
|
|
2838
2915
|
function extractAttachments(event, attachments) {
|
|
2839
2916
|
for (const [key, value] of Object.entries(event)) {
|
|
2840
|
-
if (value instanceof
|
|
2917
|
+
if (value instanceof BaseAttachment) {
|
|
2841
2918
|
attachments.push(value);
|
|
2842
2919
|
event[key] = value.reference;
|
|
2843
2920
|
continue;
|
|
@@ -3300,10 +3377,8 @@ var SpanImpl = class _SpanImpl {
|
|
|
3300
3377
|
const { id: eventId, ...event } = rawEvent;
|
|
3301
3378
|
const callerLocation = isomorph_default.getCallerLocation();
|
|
3302
3379
|
const name = (() => {
|
|
3303
|
-
if (args.name)
|
|
3304
|
-
|
|
3305
|
-
if (!args.parentSpanIds)
|
|
3306
|
-
return "root";
|
|
3380
|
+
if (args.name) return args.name;
|
|
3381
|
+
if (!args.parentSpanIds) return "root";
|
|
3307
3382
|
if (callerLocation) {
|
|
3308
3383
|
const pathComponents = callerLocation.caller_filename.split("/");
|
|
3309
3384
|
const filename = pathComponents[pathComponents.length - 1];
|
|
@@ -3992,10 +4067,12 @@ function configureBrowser() {
|
|
|
3992
4067
|
var exports_browser_exports = {};
|
|
3993
4068
|
__export(exports_browser_exports, {
|
|
3994
4069
|
Attachment: () => Attachment,
|
|
4070
|
+
BaseAttachment: () => BaseAttachment,
|
|
3995
4071
|
BraintrustState: () => BraintrustState,
|
|
3996
4072
|
BraintrustStream: () => BraintrustStream,
|
|
3997
4073
|
Dataset: () => Dataset,
|
|
3998
4074
|
Experiment: () => Experiment,
|
|
4075
|
+
ExternalAttachment: () => ExternalAttachment,
|
|
3999
4076
|
FailedHTTPResponse: () => FailedHTTPResponse,
|
|
4000
4077
|
LEGACY_CACHED_HEADER: () => LEGACY_CACHED_HEADER,
|
|
4001
4078
|
Logger: () => Logger,
|
|
@@ -4533,10 +4610,12 @@ var browser_default = exports_browser_exports;
|
|
|
4533
4610
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4534
4611
|
0 && (module.exports = {
|
|
4535
4612
|
Attachment,
|
|
4613
|
+
BaseAttachment,
|
|
4536
4614
|
BraintrustState,
|
|
4537
4615
|
BraintrustStream,
|
|
4538
4616
|
Dataset,
|
|
4539
4617
|
Experiment,
|
|
4618
|
+
ExternalAttachment,
|
|
4540
4619
|
FailedHTTPResponse,
|
|
4541
4620
|
LEGACY_CACHED_HEADER,
|
|
4542
4621
|
Logger,
|