braintrust 0.0.172 → 0.0.174
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 +46 -7
- package/dist/browser.d.ts +46 -7
- package/dist/browser.js +97 -7
- package/dist/browser.mjs +99 -8
- package/dist/cli.js +239 -65
- package/dist/index.d.mts +50 -11
- package/dist/index.d.ts +50 -11
- package/dist/index.js +268 -13
- package/dist/index.mjs +270 -14
- package/package.json +3 -3
package/dist/browser.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LogFeedbackFullArgs, ExperimentEvent, BackgroundLogEvent, ExperimentLogFullArgs, ExperimentLogPartialArgs, IdField, SpanType, SpanComponentsV3, DEFAULT_IS_LEGACY_DATASET, TRANSACTION_ID_FIELD, TransactionId, SpanObjectTypeV3, DatasetRecord } from '@braintrust/core';
|
|
2
|
-
import { GitMetadataSettings, AttachmentReference, RepoInfo, PromptData, OpenAIMessage, Tools, AnyModelParam, Message, Prompt as Prompt$1, PromptSessionEvent, StreamingMode } from '@braintrust/core/typespecs';
|
|
2
|
+
import { GitMetadataSettings, AttachmentReference, AttachmentStatus, RepoInfo, PromptData, OpenAIMessage, Tools, AnyModelParam, Message, Prompt as Prompt$1, PromptSessionEvent, StreamingMode } from '@braintrust/core/typespecs';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
5
5
|
interface IsoAsyncLocalStorage<T> {
|
|
@@ -16,6 +16,8 @@ declare class LazyValue<T> {
|
|
|
16
16
|
get hasComputed(): boolean;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
/// <reference lib="dom" />
|
|
20
|
+
|
|
19
21
|
type SetCurrentArg = {
|
|
20
22
|
setCurrent?: boolean;
|
|
21
23
|
};
|
|
@@ -312,17 +314,19 @@ declare class Attachment {
|
|
|
312
314
|
/**
|
|
313
315
|
* Construct an attachment.
|
|
314
316
|
*
|
|
315
|
-
* @param
|
|
317
|
+
* @param param A parameter object with:
|
|
318
|
+
*
|
|
319
|
+
* `data`: A string representing the path of the file on disk, or a
|
|
316
320
|
* `Blob`/`ArrayBuffer` with the file's contents. The caller is responsible
|
|
317
321
|
* for ensuring the file/blob/buffer is not modified until upload is complete.
|
|
318
322
|
*
|
|
319
|
-
*
|
|
323
|
+
* `filename`: The desired name of the file in Braintrust after uploading.
|
|
320
324
|
* This parameter is for visualization purposes only and has no effect on
|
|
321
325
|
* attachment storage.
|
|
322
326
|
*
|
|
323
|
-
*
|
|
327
|
+
* `contentType`: The MIME type of the file.
|
|
324
328
|
*
|
|
325
|
-
*
|
|
329
|
+
* `state`: (Optional) For internal use.
|
|
326
330
|
*/
|
|
327
331
|
constructor({ data, filename, contentType, state }: AttachmentParams);
|
|
328
332
|
/**
|
|
@@ -350,6 +354,39 @@ declare class Attachment {
|
|
|
350
354
|
private initUploader;
|
|
351
355
|
private initData;
|
|
352
356
|
}
|
|
357
|
+
/**
|
|
358
|
+
* A readonly alternative to `Attachment`, which can be used for fetching
|
|
359
|
+
* already-uploaded Attachments.
|
|
360
|
+
*/
|
|
361
|
+
declare class ReadonlyAttachment {
|
|
362
|
+
/**
|
|
363
|
+
* Attachment metadata.
|
|
364
|
+
*/
|
|
365
|
+
readonly reference: AttachmentReference;
|
|
366
|
+
private readonly _data;
|
|
367
|
+
private readonly state?;
|
|
368
|
+
/**
|
|
369
|
+
* Construct a ReadonlyAttachment.
|
|
370
|
+
*
|
|
371
|
+
* @param reference The `AttachmentReference` that should be read by the
|
|
372
|
+
* `ReadonlyAttachment` object.
|
|
373
|
+
* @param state (Optional) For internal use.
|
|
374
|
+
* @returns The new `ReadonlyAttachment` object.
|
|
375
|
+
*/
|
|
376
|
+
constructor(reference: AttachmentReference, state?: BraintrustState);
|
|
377
|
+
/**
|
|
378
|
+
* The attachment contents. This is a lazy value that will read the attachment
|
|
379
|
+
* contents from the object store on first access.
|
|
380
|
+
*/
|
|
381
|
+
data(): Promise<Blob>;
|
|
382
|
+
/**
|
|
383
|
+
* Fetch the attachment upload status. This will re-fetch the status each time
|
|
384
|
+
* in case it changes over time.
|
|
385
|
+
*/
|
|
386
|
+
status(): Promise<AttachmentStatus>;
|
|
387
|
+
private initDownloader;
|
|
388
|
+
private fetchMetadata;
|
|
389
|
+
}
|
|
353
390
|
/**
|
|
354
391
|
* Update a span using the output of `span.export()`. It is important that you only resume updating
|
|
355
392
|
* to a span once the original span has been fully written and flushed, since otherwise updates to
|
|
@@ -1601,6 +1638,8 @@ type braintrust_PromiseUnless<B, R> = PromiseUnless<B, R>;
|
|
|
1601
1638
|
type braintrust_Prompt<HasId extends boolean = true, HasVersion extends boolean = true> = Prompt<HasId, HasVersion>;
|
|
1602
1639
|
declare const braintrust_Prompt: typeof Prompt;
|
|
1603
1640
|
type braintrust_PromptRowWithId<HasId extends boolean = true, HasVersion extends boolean = true> = PromptRowWithId<HasId, HasVersion>;
|
|
1641
|
+
type braintrust_ReadonlyAttachment = ReadonlyAttachment;
|
|
1642
|
+
declare const braintrust_ReadonlyAttachment: typeof ReadonlyAttachment;
|
|
1604
1643
|
type braintrust_ReadonlyExperiment = ReadonlyExperiment;
|
|
1605
1644
|
declare const braintrust_ReadonlyExperiment: typeof ReadonlyExperiment;
|
|
1606
1645
|
type braintrust_ScoreSummary = ScoreSummary;
|
|
@@ -1652,7 +1691,7 @@ declare const braintrust_wrapOpenAI: typeof wrapOpenAI;
|
|
|
1652
1691
|
declare const braintrust_wrapOpenAIv4: typeof wrapOpenAIv4;
|
|
1653
1692
|
declare const braintrust_wrapTraced: typeof wrapTraced;
|
|
1654
1693
|
declare namespace braintrust {
|
|
1655
|
-
export { type braintrust_AnyDataset as AnyDataset, braintrust_Attachment as Attachment, type braintrust_AttachmentParams as AttachmentParams, type braintrust_BackgroundLoggerOpts as BackgroundLoggerOpts, type braintrust_BaseMetadata as BaseMetadata, braintrust_BraintrustState as BraintrustState, braintrust_BraintrustStream as BraintrustStream, type braintrust_BraintrustStreamChunk as BraintrustStreamChunk, type braintrust_ChatPrompt as ChatPrompt, type braintrust_CompiledPrompt as CompiledPrompt, type braintrust_CompiledPromptParams as CompiledPromptParams, type braintrust_CompletionPrompt as CompletionPrompt, type braintrust_DataSummary as DataSummary, braintrust_Dataset as Dataset, type braintrust_DatasetSummary as DatasetSummary, type braintrust_DefaultMetadataType as DefaultMetadataType, type braintrust_DefaultPromptArgs as DefaultPromptArgs, type braintrust_EndSpanArgs as EndSpanArgs, type braintrust_EvalCase as EvalCase, braintrust_Experiment as Experiment, type braintrust_ExperimentSummary as ExperimentSummary, type braintrust_Exportable as Exportable, braintrust_FailedHTTPResponse as FailedHTTPResponse, type braintrust_FullInitOptions as FullInitOptions, type braintrust_FullLoginOptions as FullLoginOptions, type braintrust_InitOptions as InitOptions, type braintrust_InvokeFunctionArgs as InvokeFunctionArgs, type braintrust_InvokeReturn as InvokeReturn, braintrust_LEGACY_CACHED_HEADER as LEGACY_CACHED_HEADER, type braintrust_LogOptions as LogOptions, braintrust_Logger as Logger, type braintrust_LoginOptions as LoginOptions, type braintrust_MetricSummary as MetricSummary, braintrust_NOOP_SPAN as NOOP_SPAN, braintrust_NoopSpan as NoopSpan, type braintrust_ObjectMetadata as ObjectMetadata, type braintrust_PromiseUnless as PromiseUnless, braintrust_Prompt as Prompt, type braintrust_PromptRowWithId as PromptRowWithId, braintrust_ReadonlyExperiment as ReadonlyExperiment, type braintrust_ScoreSummary as ScoreSummary, type braintrust_SerializedBraintrustState as SerializedBraintrustState, type braintrust_SetCurrentArg as SetCurrentArg, type braintrust_Span as Span, braintrust_SpanImpl as SpanImpl, type braintrust_StartSpanArgs as StartSpanArgs, type braintrust_WithTransactionId as WithTransactionId, braintrust_X_CACHED_HEADER as X_CACHED_HEADER, braintrust__exportsForTestingOnly as _exportsForTestingOnly, braintrust__internalGetGlobalState as _internalGetGlobalState, braintrust__internalSetInitialState as _internalSetInitialState, braintrust_braintrustStreamChunkSchema as braintrustStreamChunkSchema, braintrust_createFinalValuePassThroughStream as createFinalValuePassThroughStream, braintrust_currentExperiment as currentExperiment, braintrust_currentLogger as currentLogger, braintrust_currentSpan as currentSpan, braintrust_devNullWritableStream as devNullWritableStream, braintrust_flush as flush, braintrust_getSpanParentObject as getSpanParentObject, braintrust_init as init, braintrust_initDataset as initDataset, braintrust_initExperiment as initExperiment, braintrust_initLogger as initLogger, braintrust_invoke as invoke, braintrust_loadPrompt as loadPrompt, braintrust_log as log, braintrust_logError as logError, braintrust_login as login, braintrust_loginToState as loginToState, braintrust_newId as newId, braintrust_parseCachedHeader as parseCachedHeader, braintrust_permalink as permalink, braintrust_renderMessage as renderMessage, braintrust_setFetch as setFetch, braintrust_spanComponentsToObjectId as spanComponentsToObjectId, braintrust_startSpan as startSpan, braintrust_summarize as summarize, braintrust_traceable as traceable, braintrust_traced as traced, braintrust_updateSpan as updateSpan, braintrust_withCurrent as withCurrent, braintrust_withDataset as withDataset, braintrust_withExperiment as withExperiment, braintrust_withLogger as withLogger, braintrust_wrapOpenAI as wrapOpenAI, braintrust_wrapOpenAIv4 as wrapOpenAIv4, braintrust_wrapTraced as wrapTraced };
|
|
1694
|
+
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_devNullWritableStream as devNullWritableStream, braintrust_flush as flush, braintrust_getSpanParentObject as getSpanParentObject, braintrust_init as init, braintrust_initDataset as initDataset, braintrust_initExperiment as initExperiment, braintrust_initLogger as initLogger, braintrust_invoke as invoke, braintrust_loadPrompt as loadPrompt, braintrust_log as log, braintrust_logError as logError, braintrust_login as login, braintrust_loginToState as loginToState, braintrust_newId as newId, braintrust_parseCachedHeader as parseCachedHeader, braintrust_permalink as permalink, braintrust_renderMessage as renderMessage, braintrust_setFetch as setFetch, braintrust_spanComponentsToObjectId as spanComponentsToObjectId, braintrust_startSpan as startSpan, braintrust_summarize as summarize, braintrust_traceable as traceable, braintrust_traced as traced, braintrust_updateSpan as updateSpan, braintrust_withCurrent as withCurrent, braintrust_withDataset as withDataset, braintrust_withExperiment as withExperiment, braintrust_withLogger as withLogger, braintrust_wrapOpenAI as wrapOpenAI, braintrust_wrapOpenAIv4 as wrapOpenAIv4, braintrust_wrapTraced as wrapTraced };
|
|
1656
1695
|
}
|
|
1657
1696
|
|
|
1658
|
-
export { type AnyDataset, Attachment, type AttachmentParams, type BackgroundLoggerOpts, type BaseMetadata, BraintrustState, BraintrustStream, type BraintrustStreamChunk, type ChatPrompt, type CompiledPrompt, type CompiledPromptParams, type CompletionPrompt, type DataSummary, Dataset, type DatasetSummary, type DefaultMetadataType, type DefaultPromptArgs, type EndSpanArgs, type EvalCase, Experiment, type ExperimentSummary, type Exportable, FailedHTTPResponse, type FullInitOptions, type FullLoginOptions, type InitOptions, type InvokeFunctionArgs, type InvokeReturn, LEGACY_CACHED_HEADER, type LogOptions, Logger, type LoginOptions, type MetricSummary, NOOP_SPAN, NoopSpan, type ObjectMetadata, type PromiseUnless, Prompt, type PromptRowWithId, ReadonlyExperiment, type ScoreSummary, type SerializedBraintrustState, type SetCurrentArg, type Span, SpanImpl, type StartSpanArgs, type WithTransactionId, X_CACHED_HEADER, _exportsForTestingOnly, _internalGetGlobalState, _internalSetInitialState, braintrustStreamChunkSchema, createFinalValuePassThroughStream, currentExperiment, currentLogger, currentSpan, braintrust as default, devNullWritableStream, flush, getSpanParentObject, init, initDataset, initExperiment, initLogger, invoke, loadPrompt, log, logError, login, loginToState, newId, parseCachedHeader, permalink, renderMessage, setFetch, spanComponentsToObjectId, startSpan, summarize, traceable, traced, updateSpan, withCurrent, withDataset, withExperiment, withLogger, wrapOpenAI, wrapOpenAIv4, wrapTraced };
|
|
1697
|
+
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, devNullWritableStream, flush, getSpanParentObject, init, initDataset, initExperiment, initLogger, invoke, loadPrompt, log, logError, login, loginToState, newId, parseCachedHeader, permalink, renderMessage, setFetch, spanComponentsToObjectId, startSpan, summarize, traceable, traced, updateSpan, withCurrent, withDataset, withExperiment, withLogger, wrapOpenAI, wrapOpenAIv4, wrapTraced };
|
package/dist/browser.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LogFeedbackFullArgs, ExperimentEvent, BackgroundLogEvent, ExperimentLogFullArgs, ExperimentLogPartialArgs, IdField, SpanType, SpanComponentsV3, DEFAULT_IS_LEGACY_DATASET, TRANSACTION_ID_FIELD, TransactionId, SpanObjectTypeV3, DatasetRecord } from '@braintrust/core';
|
|
2
|
-
import { GitMetadataSettings, AttachmentReference, RepoInfo, PromptData, OpenAIMessage, Tools, AnyModelParam, Message, Prompt as Prompt$1, PromptSessionEvent, StreamingMode } from '@braintrust/core/typespecs';
|
|
2
|
+
import { GitMetadataSettings, AttachmentReference, AttachmentStatus, RepoInfo, PromptData, OpenAIMessage, Tools, AnyModelParam, Message, Prompt as Prompt$1, PromptSessionEvent, StreamingMode } from '@braintrust/core/typespecs';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
5
5
|
interface IsoAsyncLocalStorage<T> {
|
|
@@ -16,6 +16,8 @@ declare class LazyValue<T> {
|
|
|
16
16
|
get hasComputed(): boolean;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
/// <reference lib="dom" />
|
|
20
|
+
|
|
19
21
|
type SetCurrentArg = {
|
|
20
22
|
setCurrent?: boolean;
|
|
21
23
|
};
|
|
@@ -312,17 +314,19 @@ declare class Attachment {
|
|
|
312
314
|
/**
|
|
313
315
|
* Construct an attachment.
|
|
314
316
|
*
|
|
315
|
-
* @param
|
|
317
|
+
* @param param A parameter object with:
|
|
318
|
+
*
|
|
319
|
+
* `data`: A string representing the path of the file on disk, or a
|
|
316
320
|
* `Blob`/`ArrayBuffer` with the file's contents. The caller is responsible
|
|
317
321
|
* for ensuring the file/blob/buffer is not modified until upload is complete.
|
|
318
322
|
*
|
|
319
|
-
*
|
|
323
|
+
* `filename`: The desired name of the file in Braintrust after uploading.
|
|
320
324
|
* This parameter is for visualization purposes only and has no effect on
|
|
321
325
|
* attachment storage.
|
|
322
326
|
*
|
|
323
|
-
*
|
|
327
|
+
* `contentType`: The MIME type of the file.
|
|
324
328
|
*
|
|
325
|
-
*
|
|
329
|
+
* `state`: (Optional) For internal use.
|
|
326
330
|
*/
|
|
327
331
|
constructor({ data, filename, contentType, state }: AttachmentParams);
|
|
328
332
|
/**
|
|
@@ -350,6 +354,39 @@ declare class Attachment {
|
|
|
350
354
|
private initUploader;
|
|
351
355
|
private initData;
|
|
352
356
|
}
|
|
357
|
+
/**
|
|
358
|
+
* A readonly alternative to `Attachment`, which can be used for fetching
|
|
359
|
+
* already-uploaded Attachments.
|
|
360
|
+
*/
|
|
361
|
+
declare class ReadonlyAttachment {
|
|
362
|
+
/**
|
|
363
|
+
* Attachment metadata.
|
|
364
|
+
*/
|
|
365
|
+
readonly reference: AttachmentReference;
|
|
366
|
+
private readonly _data;
|
|
367
|
+
private readonly state?;
|
|
368
|
+
/**
|
|
369
|
+
* Construct a ReadonlyAttachment.
|
|
370
|
+
*
|
|
371
|
+
* @param reference The `AttachmentReference` that should be read by the
|
|
372
|
+
* `ReadonlyAttachment` object.
|
|
373
|
+
* @param state (Optional) For internal use.
|
|
374
|
+
* @returns The new `ReadonlyAttachment` object.
|
|
375
|
+
*/
|
|
376
|
+
constructor(reference: AttachmentReference, state?: BraintrustState);
|
|
377
|
+
/**
|
|
378
|
+
* The attachment contents. This is a lazy value that will read the attachment
|
|
379
|
+
* contents from the object store on first access.
|
|
380
|
+
*/
|
|
381
|
+
data(): Promise<Blob>;
|
|
382
|
+
/**
|
|
383
|
+
* Fetch the attachment upload status. This will re-fetch the status each time
|
|
384
|
+
* in case it changes over time.
|
|
385
|
+
*/
|
|
386
|
+
status(): Promise<AttachmentStatus>;
|
|
387
|
+
private initDownloader;
|
|
388
|
+
private fetchMetadata;
|
|
389
|
+
}
|
|
353
390
|
/**
|
|
354
391
|
* Update a span using the output of `span.export()`. It is important that you only resume updating
|
|
355
392
|
* to a span once the original span has been fully written and flushed, since otherwise updates to
|
|
@@ -1601,6 +1638,8 @@ type braintrust_PromiseUnless<B, R> = PromiseUnless<B, R>;
|
|
|
1601
1638
|
type braintrust_Prompt<HasId extends boolean = true, HasVersion extends boolean = true> = Prompt<HasId, HasVersion>;
|
|
1602
1639
|
declare const braintrust_Prompt: typeof Prompt;
|
|
1603
1640
|
type braintrust_PromptRowWithId<HasId extends boolean = true, HasVersion extends boolean = true> = PromptRowWithId<HasId, HasVersion>;
|
|
1641
|
+
type braintrust_ReadonlyAttachment = ReadonlyAttachment;
|
|
1642
|
+
declare const braintrust_ReadonlyAttachment: typeof ReadonlyAttachment;
|
|
1604
1643
|
type braintrust_ReadonlyExperiment = ReadonlyExperiment;
|
|
1605
1644
|
declare const braintrust_ReadonlyExperiment: typeof ReadonlyExperiment;
|
|
1606
1645
|
type braintrust_ScoreSummary = ScoreSummary;
|
|
@@ -1652,7 +1691,7 @@ declare const braintrust_wrapOpenAI: typeof wrapOpenAI;
|
|
|
1652
1691
|
declare const braintrust_wrapOpenAIv4: typeof wrapOpenAIv4;
|
|
1653
1692
|
declare const braintrust_wrapTraced: typeof wrapTraced;
|
|
1654
1693
|
declare namespace braintrust {
|
|
1655
|
-
export { type braintrust_AnyDataset as AnyDataset, braintrust_Attachment as Attachment, type braintrust_AttachmentParams as AttachmentParams, type braintrust_BackgroundLoggerOpts as BackgroundLoggerOpts, type braintrust_BaseMetadata as BaseMetadata, braintrust_BraintrustState as BraintrustState, braintrust_BraintrustStream as BraintrustStream, type braintrust_BraintrustStreamChunk as BraintrustStreamChunk, type braintrust_ChatPrompt as ChatPrompt, type braintrust_CompiledPrompt as CompiledPrompt, type braintrust_CompiledPromptParams as CompiledPromptParams, type braintrust_CompletionPrompt as CompletionPrompt, type braintrust_DataSummary as DataSummary, braintrust_Dataset as Dataset, type braintrust_DatasetSummary as DatasetSummary, type braintrust_DefaultMetadataType as DefaultMetadataType, type braintrust_DefaultPromptArgs as DefaultPromptArgs, type braintrust_EndSpanArgs as EndSpanArgs, type braintrust_EvalCase as EvalCase, braintrust_Experiment as Experiment, type braintrust_ExperimentSummary as ExperimentSummary, type braintrust_Exportable as Exportable, braintrust_FailedHTTPResponse as FailedHTTPResponse, type braintrust_FullInitOptions as FullInitOptions, type braintrust_FullLoginOptions as FullLoginOptions, type braintrust_InitOptions as InitOptions, type braintrust_InvokeFunctionArgs as InvokeFunctionArgs, type braintrust_InvokeReturn as InvokeReturn, braintrust_LEGACY_CACHED_HEADER as LEGACY_CACHED_HEADER, type braintrust_LogOptions as LogOptions, braintrust_Logger as Logger, type braintrust_LoginOptions as LoginOptions, type braintrust_MetricSummary as MetricSummary, braintrust_NOOP_SPAN as NOOP_SPAN, braintrust_NoopSpan as NoopSpan, type braintrust_ObjectMetadata as ObjectMetadata, type braintrust_PromiseUnless as PromiseUnless, braintrust_Prompt as Prompt, type braintrust_PromptRowWithId as PromptRowWithId, braintrust_ReadonlyExperiment as ReadonlyExperiment, type braintrust_ScoreSummary as ScoreSummary, type braintrust_SerializedBraintrustState as SerializedBraintrustState, type braintrust_SetCurrentArg as SetCurrentArg, type braintrust_Span as Span, braintrust_SpanImpl as SpanImpl, type braintrust_StartSpanArgs as StartSpanArgs, type braintrust_WithTransactionId as WithTransactionId, braintrust_X_CACHED_HEADER as X_CACHED_HEADER, braintrust__exportsForTestingOnly as _exportsForTestingOnly, braintrust__internalGetGlobalState as _internalGetGlobalState, braintrust__internalSetInitialState as _internalSetInitialState, braintrust_braintrustStreamChunkSchema as braintrustStreamChunkSchema, braintrust_createFinalValuePassThroughStream as createFinalValuePassThroughStream, braintrust_currentExperiment as currentExperiment, braintrust_currentLogger as currentLogger, braintrust_currentSpan as currentSpan, braintrust_devNullWritableStream as devNullWritableStream, braintrust_flush as flush, braintrust_getSpanParentObject as getSpanParentObject, braintrust_init as init, braintrust_initDataset as initDataset, braintrust_initExperiment as initExperiment, braintrust_initLogger as initLogger, braintrust_invoke as invoke, braintrust_loadPrompt as loadPrompt, braintrust_log as log, braintrust_logError as logError, braintrust_login as login, braintrust_loginToState as loginToState, braintrust_newId as newId, braintrust_parseCachedHeader as parseCachedHeader, braintrust_permalink as permalink, braintrust_renderMessage as renderMessage, braintrust_setFetch as setFetch, braintrust_spanComponentsToObjectId as spanComponentsToObjectId, braintrust_startSpan as startSpan, braintrust_summarize as summarize, braintrust_traceable as traceable, braintrust_traced as traced, braintrust_updateSpan as updateSpan, braintrust_withCurrent as withCurrent, braintrust_withDataset as withDataset, braintrust_withExperiment as withExperiment, braintrust_withLogger as withLogger, braintrust_wrapOpenAI as wrapOpenAI, braintrust_wrapOpenAIv4 as wrapOpenAIv4, braintrust_wrapTraced as wrapTraced };
|
|
1694
|
+
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_devNullWritableStream as devNullWritableStream, braintrust_flush as flush, braintrust_getSpanParentObject as getSpanParentObject, braintrust_init as init, braintrust_initDataset as initDataset, braintrust_initExperiment as initExperiment, braintrust_initLogger as initLogger, braintrust_invoke as invoke, braintrust_loadPrompt as loadPrompt, braintrust_log as log, braintrust_logError as logError, braintrust_login as login, braintrust_loginToState as loginToState, braintrust_newId as newId, braintrust_parseCachedHeader as parseCachedHeader, braintrust_permalink as permalink, braintrust_renderMessage as renderMessage, braintrust_setFetch as setFetch, braintrust_spanComponentsToObjectId as spanComponentsToObjectId, braintrust_startSpan as startSpan, braintrust_summarize as summarize, braintrust_traceable as traceable, braintrust_traced as traced, braintrust_updateSpan as updateSpan, braintrust_withCurrent as withCurrent, braintrust_withDataset as withDataset, braintrust_withExperiment as withExperiment, braintrust_withLogger as withLogger, braintrust_wrapOpenAI as wrapOpenAI, braintrust_wrapOpenAIv4 as wrapOpenAIv4, braintrust_wrapTraced as wrapTraced };
|
|
1656
1695
|
}
|
|
1657
1696
|
|
|
1658
|
-
export { type AnyDataset, Attachment, type AttachmentParams, type BackgroundLoggerOpts, type BaseMetadata, BraintrustState, BraintrustStream, type BraintrustStreamChunk, type ChatPrompt, type CompiledPrompt, type CompiledPromptParams, type CompletionPrompt, type DataSummary, Dataset, type DatasetSummary, type DefaultMetadataType, type DefaultPromptArgs, type EndSpanArgs, type EvalCase, Experiment, type ExperimentSummary, type Exportable, FailedHTTPResponse, type FullInitOptions, type FullLoginOptions, type InitOptions, type InvokeFunctionArgs, type InvokeReturn, LEGACY_CACHED_HEADER, type LogOptions, Logger, type LoginOptions, type MetricSummary, NOOP_SPAN, NoopSpan, type ObjectMetadata, type PromiseUnless, Prompt, type PromptRowWithId, ReadonlyExperiment, type ScoreSummary, type SerializedBraintrustState, type SetCurrentArg, type Span, SpanImpl, type StartSpanArgs, type WithTransactionId, X_CACHED_HEADER, _exportsForTestingOnly, _internalGetGlobalState, _internalSetInitialState, braintrustStreamChunkSchema, createFinalValuePassThroughStream, currentExperiment, currentLogger, currentSpan, braintrust as default, devNullWritableStream, flush, getSpanParentObject, init, initDataset, initExperiment, initLogger, invoke, loadPrompt, log, logError, login, loginToState, newId, parseCachedHeader, permalink, renderMessage, setFetch, spanComponentsToObjectId, startSpan, summarize, traceable, traced, updateSpan, withCurrent, withDataset, withExperiment, withLogger, wrapOpenAI, wrapOpenAIv4, wrapTraced };
|
|
1697
|
+
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, devNullWritableStream, flush, getSpanParentObject, init, initDataset, initExperiment, initLogger, invoke, loadPrompt, log, logError, login, loginToState, newId, parseCachedHeader, permalink, renderMessage, setFetch, spanComponentsToObjectId, startSpan, summarize, traceable, traced, updateSpan, withCurrent, withDataset, withExperiment, withLogger, wrapOpenAI, wrapOpenAIv4, wrapTraced };
|
package/dist/browser.js
CHANGED
|
@@ -41,6 +41,7 @@ __export(browser_exports, {
|
|
|
41
41
|
NOOP_SPAN: () => NOOP_SPAN,
|
|
42
42
|
NoopSpan: () => NoopSpan,
|
|
43
43
|
Prompt: () => Prompt,
|
|
44
|
+
ReadonlyAttachment: () => ReadonlyAttachment,
|
|
44
45
|
ReadonlyExperiment: () => ReadonlyExperiment,
|
|
45
46
|
SpanImpl: () => SpanImpl,
|
|
46
47
|
X_CACHED_HEADER: () => X_CACHED_HEADER,
|
|
@@ -801,17 +802,19 @@ var Attachment = class {
|
|
|
801
802
|
/**
|
|
802
803
|
* Construct an attachment.
|
|
803
804
|
*
|
|
804
|
-
* @param
|
|
805
|
+
* @param param A parameter object with:
|
|
806
|
+
*
|
|
807
|
+
* `data`: A string representing the path of the file on disk, or a
|
|
805
808
|
* `Blob`/`ArrayBuffer` with the file's contents. The caller is responsible
|
|
806
809
|
* for ensuring the file/blob/buffer is not modified until upload is complete.
|
|
807
810
|
*
|
|
808
|
-
*
|
|
811
|
+
* `filename`: The desired name of the file in Braintrust after uploading.
|
|
809
812
|
* This parameter is for visualization purposes only and has no effect on
|
|
810
813
|
* attachment storage.
|
|
811
814
|
*
|
|
812
|
-
*
|
|
815
|
+
* `contentType`: The MIME type of the file.
|
|
813
816
|
*
|
|
814
|
-
*
|
|
817
|
+
* `state`: (Optional) For internal use.
|
|
815
818
|
*/
|
|
816
819
|
constructor({ data, filename, contentType, state }) {
|
|
817
820
|
this.reference = {
|
|
@@ -955,6 +958,77 @@ with a Blob/ArrayBuffer, or run the program on Node.js.`
|
|
|
955
958
|
}
|
|
956
959
|
}
|
|
957
960
|
};
|
|
961
|
+
var attachmentMetadataSchema = import_zod2.z.object({
|
|
962
|
+
downloadUrl: import_zod2.z.string(),
|
|
963
|
+
status: import_typespecs2.attachmentStatusSchema
|
|
964
|
+
});
|
|
965
|
+
var ReadonlyAttachment = class {
|
|
966
|
+
/**
|
|
967
|
+
* Attachment metadata.
|
|
968
|
+
*/
|
|
969
|
+
reference;
|
|
970
|
+
_data;
|
|
971
|
+
state;
|
|
972
|
+
/**
|
|
973
|
+
* Construct a ReadonlyAttachment.
|
|
974
|
+
*
|
|
975
|
+
* @param reference The `AttachmentReference` that should be read by the
|
|
976
|
+
* `ReadonlyAttachment` object.
|
|
977
|
+
* @param state (Optional) For internal use.
|
|
978
|
+
* @returns The new `ReadonlyAttachment` object.
|
|
979
|
+
*/
|
|
980
|
+
constructor(reference, state) {
|
|
981
|
+
this.reference = reference;
|
|
982
|
+
this.state = state;
|
|
983
|
+
this._data = this.initDownloader();
|
|
984
|
+
}
|
|
985
|
+
/**
|
|
986
|
+
* The attachment contents. This is a lazy value that will read the attachment
|
|
987
|
+
* contents from the object store on first access.
|
|
988
|
+
*/
|
|
989
|
+
async data() {
|
|
990
|
+
return this._data.get();
|
|
991
|
+
}
|
|
992
|
+
/**
|
|
993
|
+
* Fetch the attachment upload status. This will re-fetch the status each time
|
|
994
|
+
* in case it changes over time.
|
|
995
|
+
*/
|
|
996
|
+
async status() {
|
|
997
|
+
return (await this.fetchMetadata()).status;
|
|
998
|
+
}
|
|
999
|
+
initDownloader() {
|
|
1000
|
+
const download = async () => {
|
|
1001
|
+
const { downloadUrl, status } = await this.fetchMetadata();
|
|
1002
|
+
if (status.upload_status !== "done") {
|
|
1003
|
+
throw new Error(
|
|
1004
|
+
`Expected attachment status "done", got "${status.upload_status}"`
|
|
1005
|
+
);
|
|
1006
|
+
}
|
|
1007
|
+
const objResponse = await fetch(downloadUrl);
|
|
1008
|
+
if (objResponse.status !== 200) {
|
|
1009
|
+
const error = await objResponse.text();
|
|
1010
|
+
throw new Error(`Couldn't download attachment: ${error}`);
|
|
1011
|
+
}
|
|
1012
|
+
return await objResponse.blob();
|
|
1013
|
+
};
|
|
1014
|
+
return new LazyValue(download);
|
|
1015
|
+
}
|
|
1016
|
+
async fetchMetadata() {
|
|
1017
|
+
const state = this.state ?? _globalState;
|
|
1018
|
+
await state.login({});
|
|
1019
|
+
const resp = await state.apiConn().get("/attachment", {
|
|
1020
|
+
key: this.reference.key,
|
|
1021
|
+
filename: this.reference.filename,
|
|
1022
|
+
content_type: this.reference.content_type,
|
|
1023
|
+
org_id: state.orgId || ""
|
|
1024
|
+
});
|
|
1025
|
+
if (!resp.ok) {
|
|
1026
|
+
const errorStr = JSON.stringify(resp);
|
|
1027
|
+
throw new Error(`Invalid response from API server: ${errorStr}`);
|
|
1028
|
+
}
|
|
1029
|
+
return attachmentMetadataSchema.parse(await resp.json());
|
|
1030
|
+
}
|
|
1031
|
+
};
|
|
958
1032
|
function logFeedbackImpl(state, parentObjectType, parentObjectId, {
|
|
959
1033
|
id,
|
|
960
1034
|
expected,
|
|
@@ -2496,6 +2570,20 @@ function extractAttachments(event, attachments) {
|
|
|
2496
2570
|
extractAttachments(value, attachments);
|
|
2497
2571
|
}
|
|
2498
2572
|
}
|
|
2573
|
+
function enrichAttachments(event) {
|
|
2574
|
+
for (const [key, value] of Object.entries(event)) {
|
|
2575
|
+
const parsedValue = import_typespecs2.attachmentReferenceSchema.safeParse(value);
|
|
2576
|
+
if (parsedValue.success) {
|
|
2577
|
+
event[key] = new ReadonlyAttachment(parsedValue.data);
|
|
2578
|
+
continue;
|
|
2579
|
+
}
|
|
2580
|
+
if (!(value instanceof Object)) {
|
|
2581
|
+
continue;
|
|
2582
|
+
}
|
|
2583
|
+
enrichAttachments(value);
|
|
2584
|
+
}
|
|
2585
|
+
return event;
|
|
2586
|
+
}
|
|
2499
2587
|
function validateAndSanitizeExperimentLogFullArgs(event, hasDataset) {
|
|
2500
2588
|
if ("input" in event && !isEmpty(event.input) && "inputs" in event && !isEmpty(event.inputs) || !("input" in event) && !("inputs" in event)) {
|
|
2501
2589
|
throw new Error(
|
|
@@ -2583,7 +2671,7 @@ var Experiment = class extends ObjectFetcher {
|
|
|
2583
2671
|
// For type identification.
|
|
2584
2672
|
kind = "experiment";
|
|
2585
2673
|
constructor(state, lazyMetadata, dataset) {
|
|
2586
|
-
super("experiment", void 0);
|
|
2674
|
+
super("experiment", void 0, enrichAttachments);
|
|
2587
2675
|
this.lazyMetadata = lazyMetadata;
|
|
2588
2676
|
this.dataset = dataset;
|
|
2589
2677
|
this.lastStartTime = getCurrentUnixTimestamp();
|
|
@@ -2826,7 +2914,7 @@ var Experiment = class extends ObjectFetcher {
|
|
|
2826
2914
|
};
|
|
2827
2915
|
var ReadonlyExperiment = class extends ObjectFetcher {
|
|
2828
2916
|
constructor(state, lazyMetadata) {
|
|
2829
|
-
super("experiment", void 0);
|
|
2917
|
+
super("experiment", void 0, enrichAttachments);
|
|
2830
2918
|
this.state = state;
|
|
2831
2919
|
this.lazyMetadata = lazyMetadata;
|
|
2832
2920
|
}
|
|
@@ -3103,7 +3191,7 @@ var Dataset = class extends ObjectFetcher {
|
|
|
3103
3191
|
super(
|
|
3104
3192
|
"dataset",
|
|
3105
3193
|
pinnedVersion,
|
|
3106
|
-
(r) => (0, import_core.ensureDatasetRecord)(r, isLegacyDataset)
|
|
3194
|
+
(r) => (0, import_core.ensureDatasetRecord)(enrichAttachments(r), isLegacyDataset)
|
|
3107
3195
|
);
|
|
3108
3196
|
this.state = state;
|
|
3109
3197
|
this.lazyMetadata = lazyMetadata;
|
|
@@ -3505,6 +3593,7 @@ __export(exports_browser_exports, {
|
|
|
3505
3593
|
NOOP_SPAN: () => NOOP_SPAN,
|
|
3506
3594
|
NoopSpan: () => NoopSpan,
|
|
3507
3595
|
Prompt: () => Prompt,
|
|
3596
|
+
ReadonlyAttachment: () => ReadonlyAttachment,
|
|
3508
3597
|
ReadonlyExperiment: () => ReadonlyExperiment,
|
|
3509
3598
|
SpanImpl: () => SpanImpl,
|
|
3510
3599
|
X_CACHED_HEADER: () => X_CACHED_HEADER,
|
|
@@ -4012,6 +4101,7 @@ var browser_default = exports_browser_exports;
|
|
|
4012
4101
|
NOOP_SPAN,
|
|
4013
4102
|
NoopSpan,
|
|
4014
4103
|
Prompt,
|
|
4104
|
+
ReadonlyAttachment,
|
|
4015
4105
|
ReadonlyExperiment,
|
|
4016
4106
|
SpanImpl,
|
|
4017
4107
|
X_CACHED_HEADER,
|
package/dist/browser.mjs
CHANGED
|
@@ -56,7 +56,9 @@ import {
|
|
|
56
56
|
promptSchema,
|
|
57
57
|
toolsSchema,
|
|
58
58
|
gitMetadataSettingsSchema,
|
|
59
|
-
BRAINTRUST_ATTACHMENT
|
|
59
|
+
BRAINTRUST_ATTACHMENT,
|
|
60
|
+
attachmentStatusSchema,
|
|
61
|
+
attachmentReferenceSchema
|
|
60
62
|
} from "@braintrust/core/typespecs";
|
|
61
63
|
|
|
62
64
|
// src/util.ts
|
|
@@ -750,17 +752,19 @@ var Attachment = class {
|
|
|
750
752
|
/**
|
|
751
753
|
* Construct an attachment.
|
|
752
754
|
*
|
|
753
|
-
* @param
|
|
755
|
+
* @param param A parameter object with:
|
|
756
|
+
*
|
|
757
|
+
* `data`: A string representing the path of the file on disk, or a
|
|
754
758
|
* `Blob`/`ArrayBuffer` with the file's contents. The caller is responsible
|
|
755
759
|
* for ensuring the file/blob/buffer is not modified until upload is complete.
|
|
756
760
|
*
|
|
757
|
-
*
|
|
761
|
+
* `filename`: The desired name of the file in Braintrust after uploading.
|
|
758
762
|
* This parameter is for visualization purposes only and has no effect on
|
|
759
763
|
* attachment storage.
|
|
760
764
|
*
|
|
761
|
-
*
|
|
765
|
+
* `contentType`: The MIME type of the file.
|
|
762
766
|
*
|
|
763
|
-
*
|
|
767
|
+
* `state`: (Optional) For internal use.
|
|
764
768
|
*/
|
|
765
769
|
constructor({ data, filename, contentType, state }) {
|
|
766
770
|
this.reference = {
|
|
@@ -904,6 +908,77 @@ with a Blob/ArrayBuffer, or run the program on Node.js.`
|
|
|
904
908
|
}
|
|
905
909
|
}
|
|
906
910
|
};
|
|
911
|
+
var attachmentMetadataSchema = z2.object({
|
|
912
|
+
downloadUrl: z2.string(),
|
|
913
|
+
status: attachmentStatusSchema
|
|
914
|
+
});
|
|
915
|
+
var ReadonlyAttachment = class {
|
|
916
|
+
/**
|
|
917
|
+
* Attachment metadata.
|
|
918
|
+
*/
|
|
919
|
+
reference;
|
|
920
|
+
_data;
|
|
921
|
+
state;
|
|
922
|
+
/**
|
|
923
|
+
* Construct a ReadonlyAttachment.
|
|
924
|
+
*
|
|
925
|
+
* @param reference The `AttachmentReference` that should be read by the
|
|
926
|
+
* `ReadonlyAttachment` object.
|
|
927
|
+
* @param state (Optional) For internal use.
|
|
928
|
+
* @returns The new `ReadonlyAttachment` object.
|
|
929
|
+
*/
|
|
930
|
+
constructor(reference, state) {
|
|
931
|
+
this.reference = reference;
|
|
932
|
+
this.state = state;
|
|
933
|
+
this._data = this.initDownloader();
|
|
934
|
+
}
|
|
935
|
+
/**
|
|
936
|
+
* The attachment contents. This is a lazy value that will read the attachment
|
|
937
|
+
* contents from the object store on first access.
|
|
938
|
+
*/
|
|
939
|
+
async data() {
|
|
940
|
+
return this._data.get();
|
|
941
|
+
}
|
|
942
|
+
/**
|
|
943
|
+
* Fetch the attachment upload status. This will re-fetch the status each time
|
|
944
|
+
* in case it changes over time.
|
|
945
|
+
*/
|
|
946
|
+
async status() {
|
|
947
|
+
return (await this.fetchMetadata()).status;
|
|
948
|
+
}
|
|
949
|
+
initDownloader() {
|
|
950
|
+
const download = async () => {
|
|
951
|
+
const { downloadUrl, status } = await this.fetchMetadata();
|
|
952
|
+
if (status.upload_status !== "done") {
|
|
953
|
+
throw new Error(
|
|
954
|
+
`Expected attachment status "done", got "${status.upload_status}"`
|
|
955
|
+
);
|
|
956
|
+
}
|
|
957
|
+
const objResponse = await fetch(downloadUrl);
|
|
958
|
+
if (objResponse.status !== 200) {
|
|
959
|
+
const error = await objResponse.text();
|
|
960
|
+
throw new Error(`Couldn't download attachment: ${error}`);
|
|
961
|
+
}
|
|
962
|
+
return await objResponse.blob();
|
|
963
|
+
};
|
|
964
|
+
return new LazyValue(download);
|
|
965
|
+
}
|
|
966
|
+
async fetchMetadata() {
|
|
967
|
+
const state = this.state ?? _globalState;
|
|
968
|
+
await state.login({});
|
|
969
|
+
const resp = await state.apiConn().get("/attachment", {
|
|
970
|
+
key: this.reference.key,
|
|
971
|
+
filename: this.reference.filename,
|
|
972
|
+
content_type: this.reference.content_type,
|
|
973
|
+
org_id: state.orgId || ""
|
|
974
|
+
});
|
|
975
|
+
if (!resp.ok) {
|
|
976
|
+
const errorStr = JSON.stringify(resp);
|
|
977
|
+
throw new Error(`Invalid response from API server: ${errorStr}`);
|
|
978
|
+
}
|
|
979
|
+
return attachmentMetadataSchema.parse(await resp.json());
|
|
980
|
+
}
|
|
981
|
+
};
|
|
907
982
|
function logFeedbackImpl(state, parentObjectType, parentObjectId, {
|
|
908
983
|
id,
|
|
909
984
|
expected,
|
|
@@ -2445,6 +2520,20 @@ function extractAttachments(event, attachments) {
|
|
|
2445
2520
|
extractAttachments(value, attachments);
|
|
2446
2521
|
}
|
|
2447
2522
|
}
|
|
2523
|
+
function enrichAttachments(event) {
|
|
2524
|
+
for (const [key, value] of Object.entries(event)) {
|
|
2525
|
+
const parsedValue = attachmentReferenceSchema.safeParse(value);
|
|
2526
|
+
if (parsedValue.success) {
|
|
2527
|
+
event[key] = new ReadonlyAttachment(parsedValue.data);
|
|
2528
|
+
continue;
|
|
2529
|
+
}
|
|
2530
|
+
if (!(value instanceof Object)) {
|
|
2531
|
+
continue;
|
|
2532
|
+
}
|
|
2533
|
+
enrichAttachments(value);
|
|
2534
|
+
}
|
|
2535
|
+
return event;
|
|
2536
|
+
}
|
|
2448
2537
|
function validateAndSanitizeExperimentLogFullArgs(event, hasDataset) {
|
|
2449
2538
|
if ("input" in event && !isEmpty(event.input) && "inputs" in event && !isEmpty(event.inputs) || !("input" in event) && !("inputs" in event)) {
|
|
2450
2539
|
throw new Error(
|
|
@@ -2532,7 +2621,7 @@ var Experiment = class extends ObjectFetcher {
|
|
|
2532
2621
|
// For type identification.
|
|
2533
2622
|
kind = "experiment";
|
|
2534
2623
|
constructor(state, lazyMetadata, dataset) {
|
|
2535
|
-
super("experiment", void 0);
|
|
2624
|
+
super("experiment", void 0, enrichAttachments);
|
|
2536
2625
|
this.lazyMetadata = lazyMetadata;
|
|
2537
2626
|
this.dataset = dataset;
|
|
2538
2627
|
this.lastStartTime = getCurrentUnixTimestamp();
|
|
@@ -2775,7 +2864,7 @@ var Experiment = class extends ObjectFetcher {
|
|
|
2775
2864
|
};
|
|
2776
2865
|
var ReadonlyExperiment = class extends ObjectFetcher {
|
|
2777
2866
|
constructor(state, lazyMetadata) {
|
|
2778
|
-
super("experiment", void 0);
|
|
2867
|
+
super("experiment", void 0, enrichAttachments);
|
|
2779
2868
|
this.state = state;
|
|
2780
2869
|
this.lazyMetadata = lazyMetadata;
|
|
2781
2870
|
}
|
|
@@ -3052,7 +3141,7 @@ var Dataset = class extends ObjectFetcher {
|
|
|
3052
3141
|
super(
|
|
3053
3142
|
"dataset",
|
|
3054
3143
|
pinnedVersion,
|
|
3055
|
-
(r) => ensureDatasetRecord(r, isLegacyDataset)
|
|
3144
|
+
(r) => ensureDatasetRecord(enrichAttachments(r), isLegacyDataset)
|
|
3056
3145
|
);
|
|
3057
3146
|
this.state = state;
|
|
3058
3147
|
this.lazyMetadata = lazyMetadata;
|
|
@@ -3454,6 +3543,7 @@ __export(exports_browser_exports, {
|
|
|
3454
3543
|
NOOP_SPAN: () => NOOP_SPAN,
|
|
3455
3544
|
NoopSpan: () => NoopSpan,
|
|
3456
3545
|
Prompt: () => Prompt,
|
|
3546
|
+
ReadonlyAttachment: () => ReadonlyAttachment,
|
|
3457
3547
|
ReadonlyExperiment: () => ReadonlyExperiment,
|
|
3458
3548
|
SpanImpl: () => SpanImpl,
|
|
3459
3549
|
X_CACHED_HEADER: () => X_CACHED_HEADER,
|
|
@@ -3962,6 +4052,7 @@ export {
|
|
|
3962
4052
|
NOOP_SPAN,
|
|
3963
4053
|
NoopSpan,
|
|
3964
4054
|
Prompt,
|
|
4055
|
+
ReadonlyAttachment,
|
|
3965
4056
|
ReadonlyExperiment,
|
|
3966
4057
|
SpanImpl,
|
|
3967
4058
|
X_CACHED_HEADER,
|