braintrust 0.0.157 → 0.0.158

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
- import { GitMetadataSettings, LogFeedbackFullArgs, ExperimentEvent, BackgroundLogEvent, ExperimentLogFullArgs, ExperimentLogPartialArgs, IdField, SpanType, RepoInfo, DEFAULT_IS_LEGACY_DATASET, TRANSACTION_ID_FIELD, TransactionId, SpanObjectTypeV2, DatasetRecord } from '@braintrust/core';
2
- import { PromptData, OpenAIMessage, Tools, AnyModelParam, Prompt as Prompt$1, PromptSessionEvent } from '@braintrust/core/typespecs';
1
+ import { GitMetadataSettings, LogFeedbackFullArgs, ExperimentEvent, BackgroundLogEvent, ExperimentLogFullArgs, ExperimentLogPartialArgs, IdField, SpanType, RepoInfo, DEFAULT_IS_LEGACY_DATASET, TRANSACTION_ID_FIELD, TransactionId, SpanObjectTypeV3, DatasetRecord } from '@braintrust/core';
2
+ import { PromptData, OpenAIMessage, Tools, AnyModelParam, Message, Prompt as Prompt$1, PromptSessionEvent } from '@braintrust/core/typespecs';
3
3
  import { z } from 'zod';
4
4
 
5
5
  interface IsoAsyncLocalStorage<T> {
@@ -16,8 +16,6 @@ declare class LazyValue<T> {
16
16
  get hasComputed(): boolean;
17
17
  }
18
18
 
19
- /// <reference lib="dom" />
20
-
21
19
  type SetCurrentArg = {
22
20
  setCurrent?: boolean;
23
21
  };
@@ -29,6 +27,7 @@ type StartSpanArgs = {
29
27
  startTime?: number;
30
28
  parent?: string;
31
29
  event?: StartSpanEventArgs;
30
+ propagatedEvent?: StartSpanEventArgs;
32
31
  };
33
32
  type EndSpanArgs = {
34
33
  endTime?: number;
@@ -685,6 +684,10 @@ declare function flush(options?: OptionalStateArg): Promise<void>;
685
684
  * @param fetch The fetch implementation to use.
686
685
  */
687
686
  declare function setFetch(fetch: typeof globalThis.fetch): void;
687
+ /**
688
+ * Runs the provided callback with the span as the current span.
689
+ */
690
+ declare function withCurrent<R>(span: Span, callback: (span: Span) => R, state?: BraintrustState): R;
688
691
  type WithTransactionId<R> = R & {
689
692
  [TRANSACTION_ID_FIELD]: TransactionId;
690
693
  };
@@ -844,6 +847,7 @@ declare class SpanImpl implements Span {
844
847
  private state;
845
848
  private isMerge;
846
849
  private loggedEndTime;
850
+ private propagatedEvent;
847
851
  private parentObjectType;
848
852
  private parentObjectId;
849
853
  private parentComputeObjectMetadataArgs;
@@ -854,7 +858,7 @@ declare class SpanImpl implements Span {
854
858
  kind: "span";
855
859
  constructor(args: {
856
860
  state: BraintrustState;
857
- parentObjectType: SpanObjectTypeV2;
861
+ parentObjectType: SpanObjectTypeV3;
858
862
  parentObjectId: LazyValue<string>;
859
863
  parentComputeObjectMetadataArgs: Record<string, any> | undefined;
860
864
  parentSpanIds: ParentSpanIds | undefined;
@@ -887,6 +891,8 @@ declare class Dataset<IsLegacyDataset extends boolean = typeof DEFAULT_IS_LEGACY
887
891
  get name(): Promise<string>;
888
892
  get project(): Promise<ObjectMetadata>;
889
893
  protected getState(): Promise<BraintrustState>;
894
+ private validateEvent;
895
+ private createArgs;
890
896
  /**
891
897
  * Insert a single record to the dataset. The record will be batched and uploaded behind the scenes. If you pass in an `id`,
892
898
  * and a record with that `id` already exists, it will be overwritten (upsert).
@@ -911,6 +917,26 @@ declare class Dataset<IsLegacyDataset extends boolean = typeof DEFAULT_IS_LEGACY
911
917
  readonly id?: string;
912
918
  readonly output?: unknown;
913
919
  }): string;
920
+ /**
921
+ * Update fields of a single record in the dataset. The updated fields will be batched and uploaded behind the scenes.
922
+ * You must pass in an `id` of the record to update. Only the fields provided will be updated; other fields will remain unchanged.
923
+ *
924
+ * @param event The fields to update in the record.
925
+ * @param event.id The unique identifier of the record to update.
926
+ * @param event.input (Optional) The new input value for the record (an arbitrary, JSON serializable object).
927
+ * @param event.expected (Optional) The new expected output value for the record (an arbitrary, JSON serializable object).
928
+ * @param event.tags (Optional) A list of strings to update the tags of the record.
929
+ * @param event.metadata (Optional) A dictionary to update the metadata of the record. The values in `metadata` can be any
930
+ * JSON-serializable type, but its keys must be strings.
931
+ * @returns The `id` of the updated record.
932
+ */
933
+ update({ input, expected, metadata, tags, id, }: {
934
+ readonly id: string;
935
+ readonly input?: unknown;
936
+ readonly expected?: unknown;
937
+ readonly tags?: string[];
938
+ readonly metadata?: Record<string, unknown>;
939
+ }): string;
914
940
  delete(id: string): string;
915
941
  /**
916
942
  * Summarize the dataset, including high level metrics about its size and other metadata.
@@ -955,10 +981,13 @@ type CompiledPrompt<Flavor extends "chat" | "completion"> = CompiledPromptParams
955
981
  };
956
982
  } & (Flavor extends "chat" ? ChatPrompt : Flavor extends "completion" ? CompletionPrompt : {});
957
983
  type DefaultPromptArgs = Partial<CompiledPromptParams & AnyModelParam & ChatPrompt & CompletionPrompt>;
984
+ declare function renderMessage<T extends Message>(render: (template: string) => string, message: T): T;
958
985
  declare class Prompt {
959
986
  private metadata;
960
987
  private defaults;
961
988
  private noTrace;
989
+ private parsedPromptData;
990
+ private hasParsedPromptData;
962
991
  constructor(metadata: Omit<Prompt$1, "log_id"> | PromptSessionEvent, defaults: DefaultPromptArgs, noTrace: boolean);
963
992
  get id(): string;
964
993
  get projectId(): string;
@@ -978,6 +1007,7 @@ declare class Prompt {
978
1007
  flavor?: Flavor;
979
1008
  }): CompiledPrompt<Flavor>;
980
1009
  private runBuild;
1010
+ private getParsedPromptData;
981
1011
  }
982
1012
  type AnyDataset = Dataset<boolean>;
983
1013
  /**
@@ -1251,4 +1281,4 @@ declare const LEGACY_CACHED_HEADER = "x-cached";
1251
1281
  declare const X_CACHED_HEADER = "x-bt-cached";
1252
1282
  declare function parseCachedHeader(value: string | null | undefined): number | undefined;
1253
1283
 
1254
- export { type AnyDataset, type BackgroundLoggerOpts, type BaseMetadata, BraintrustState, BraintrustStream, type BraintrustStreamChunk, type ChatPrompt, type CompiledPrompt, type CompiledPromptParams, type CompletionPrompt, type DataSummary, Dataset, type DatasetSummary, type DefaultMetadataType, type DefaultPromptArgs, type EndSpanArgs, type EvalCase, Experiment, type ExperimentSummary, type Exportable, 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, ReadonlyExperiment, type ScoreSummary, type SerializedBraintrustState, type SetCurrentArg, type Span, SpanImpl, type StartSpanArgs, type WithTransactionId, X_CACHED_HEADER, _internalGetGlobalState, _internalSetInitialState, braintrustStreamChunkSchema, createFinalValuePassThroughStream, currentExperiment, currentLogger, currentSpan, devNullWritableStream, flush, getSpanParentObject, init, initDataset, initExperiment, initLogger, invoke, loadPrompt, log, logError, login, loginToState, newId, parseCachedHeader, setFetch, startSpan, summarize, traceable, traced, updateSpan, withDataset, withExperiment, withLogger, wrapOpenAI, wrapOpenAIv4, wrapTraced };
1284
+ export { type AnyDataset, type BackgroundLoggerOpts, type BaseMetadata, BraintrustState, BraintrustStream, type BraintrustStreamChunk, type ChatPrompt, type CompiledPrompt, type CompiledPromptParams, type CompletionPrompt, type DataSummary, Dataset, type DatasetSummary, type DefaultMetadataType, type DefaultPromptArgs, type EndSpanArgs, type EvalCase, Experiment, type ExperimentSummary, type Exportable, 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, ReadonlyExperiment, type ScoreSummary, type SerializedBraintrustState, type SetCurrentArg, type Span, SpanImpl, type StartSpanArgs, type WithTransactionId, X_CACHED_HEADER, _internalGetGlobalState, _internalSetInitialState, braintrustStreamChunkSchema, createFinalValuePassThroughStream, currentExperiment, currentLogger, currentSpan, devNullWritableStream, flush, getSpanParentObject, init, initDataset, initExperiment, initLogger, invoke, loadPrompt, log, logError, login, loginToState, newId, parseCachedHeader, renderMessage, setFetch, startSpan, summarize, traceable, traced, updateSpan, withCurrent, withDataset, withExperiment, withLogger, wrapOpenAI, wrapOpenAIv4, wrapTraced };
package/dist/browser.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { GitMetadataSettings, LogFeedbackFullArgs, ExperimentEvent, BackgroundLogEvent, ExperimentLogFullArgs, ExperimentLogPartialArgs, IdField, SpanType, RepoInfo, DEFAULT_IS_LEGACY_DATASET, TRANSACTION_ID_FIELD, TransactionId, SpanObjectTypeV2, DatasetRecord } from '@braintrust/core';
2
- import { PromptData, OpenAIMessage, Tools, AnyModelParam, Prompt as Prompt$1, PromptSessionEvent } from '@braintrust/core/typespecs';
1
+ import { GitMetadataSettings, LogFeedbackFullArgs, ExperimentEvent, BackgroundLogEvent, ExperimentLogFullArgs, ExperimentLogPartialArgs, IdField, SpanType, RepoInfo, DEFAULT_IS_LEGACY_DATASET, TRANSACTION_ID_FIELD, TransactionId, SpanObjectTypeV3, DatasetRecord } from '@braintrust/core';
2
+ import { PromptData, OpenAIMessage, Tools, AnyModelParam, Message, Prompt as Prompt$1, PromptSessionEvent } from '@braintrust/core/typespecs';
3
3
  import { z } from 'zod';
4
4
 
5
5
  interface IsoAsyncLocalStorage<T> {
@@ -16,8 +16,6 @@ declare class LazyValue<T> {
16
16
  get hasComputed(): boolean;
17
17
  }
18
18
 
19
- /// <reference lib="dom" />
20
-
21
19
  type SetCurrentArg = {
22
20
  setCurrent?: boolean;
23
21
  };
@@ -29,6 +27,7 @@ type StartSpanArgs = {
29
27
  startTime?: number;
30
28
  parent?: string;
31
29
  event?: StartSpanEventArgs;
30
+ propagatedEvent?: StartSpanEventArgs;
32
31
  };
33
32
  type EndSpanArgs = {
34
33
  endTime?: number;
@@ -685,6 +684,10 @@ declare function flush(options?: OptionalStateArg): Promise<void>;
685
684
  * @param fetch The fetch implementation to use.
686
685
  */
687
686
  declare function setFetch(fetch: typeof globalThis.fetch): void;
687
+ /**
688
+ * Runs the provided callback with the span as the current span.
689
+ */
690
+ declare function withCurrent<R>(span: Span, callback: (span: Span) => R, state?: BraintrustState): R;
688
691
  type WithTransactionId<R> = R & {
689
692
  [TRANSACTION_ID_FIELD]: TransactionId;
690
693
  };
@@ -844,6 +847,7 @@ declare class SpanImpl implements Span {
844
847
  private state;
845
848
  private isMerge;
846
849
  private loggedEndTime;
850
+ private propagatedEvent;
847
851
  private parentObjectType;
848
852
  private parentObjectId;
849
853
  private parentComputeObjectMetadataArgs;
@@ -854,7 +858,7 @@ declare class SpanImpl implements Span {
854
858
  kind: "span";
855
859
  constructor(args: {
856
860
  state: BraintrustState;
857
- parentObjectType: SpanObjectTypeV2;
861
+ parentObjectType: SpanObjectTypeV3;
858
862
  parentObjectId: LazyValue<string>;
859
863
  parentComputeObjectMetadataArgs: Record<string, any> | undefined;
860
864
  parentSpanIds: ParentSpanIds | undefined;
@@ -887,6 +891,8 @@ declare class Dataset<IsLegacyDataset extends boolean = typeof DEFAULT_IS_LEGACY
887
891
  get name(): Promise<string>;
888
892
  get project(): Promise<ObjectMetadata>;
889
893
  protected getState(): Promise<BraintrustState>;
894
+ private validateEvent;
895
+ private createArgs;
890
896
  /**
891
897
  * Insert a single record to the dataset. The record will be batched and uploaded behind the scenes. If you pass in an `id`,
892
898
  * and a record with that `id` already exists, it will be overwritten (upsert).
@@ -911,6 +917,26 @@ declare class Dataset<IsLegacyDataset extends boolean = typeof DEFAULT_IS_LEGACY
911
917
  readonly id?: string;
912
918
  readonly output?: unknown;
913
919
  }): string;
920
+ /**
921
+ * Update fields of a single record in the dataset. The updated fields will be batched and uploaded behind the scenes.
922
+ * You must pass in an `id` of the record to update. Only the fields provided will be updated; other fields will remain unchanged.
923
+ *
924
+ * @param event The fields to update in the record.
925
+ * @param event.id The unique identifier of the record to update.
926
+ * @param event.input (Optional) The new input value for the record (an arbitrary, JSON serializable object).
927
+ * @param event.expected (Optional) The new expected output value for the record (an arbitrary, JSON serializable object).
928
+ * @param event.tags (Optional) A list of strings to update the tags of the record.
929
+ * @param event.metadata (Optional) A dictionary to update the metadata of the record. The values in `metadata` can be any
930
+ * JSON-serializable type, but its keys must be strings.
931
+ * @returns The `id` of the updated record.
932
+ */
933
+ update({ input, expected, metadata, tags, id, }: {
934
+ readonly id: string;
935
+ readonly input?: unknown;
936
+ readonly expected?: unknown;
937
+ readonly tags?: string[];
938
+ readonly metadata?: Record<string, unknown>;
939
+ }): string;
914
940
  delete(id: string): string;
915
941
  /**
916
942
  * Summarize the dataset, including high level metrics about its size and other metadata.
@@ -955,10 +981,13 @@ type CompiledPrompt<Flavor extends "chat" | "completion"> = CompiledPromptParams
955
981
  };
956
982
  } & (Flavor extends "chat" ? ChatPrompt : Flavor extends "completion" ? CompletionPrompt : {});
957
983
  type DefaultPromptArgs = Partial<CompiledPromptParams & AnyModelParam & ChatPrompt & CompletionPrompt>;
984
+ declare function renderMessage<T extends Message>(render: (template: string) => string, message: T): T;
958
985
  declare class Prompt {
959
986
  private metadata;
960
987
  private defaults;
961
988
  private noTrace;
989
+ private parsedPromptData;
990
+ private hasParsedPromptData;
962
991
  constructor(metadata: Omit<Prompt$1, "log_id"> | PromptSessionEvent, defaults: DefaultPromptArgs, noTrace: boolean);
963
992
  get id(): string;
964
993
  get projectId(): string;
@@ -978,6 +1007,7 @@ declare class Prompt {
978
1007
  flavor?: Flavor;
979
1008
  }): CompiledPrompt<Flavor>;
980
1009
  private runBuild;
1010
+ private getParsedPromptData;
981
1011
  }
982
1012
  type AnyDataset = Dataset<boolean>;
983
1013
  /**
@@ -1251,4 +1281,4 @@ declare const LEGACY_CACHED_HEADER = "x-cached";
1251
1281
  declare const X_CACHED_HEADER = "x-bt-cached";
1252
1282
  declare function parseCachedHeader(value: string | null | undefined): number | undefined;
1253
1283
 
1254
- export { type AnyDataset, type BackgroundLoggerOpts, type BaseMetadata, BraintrustState, BraintrustStream, type BraintrustStreamChunk, type ChatPrompt, type CompiledPrompt, type CompiledPromptParams, type CompletionPrompt, type DataSummary, Dataset, type DatasetSummary, type DefaultMetadataType, type DefaultPromptArgs, type EndSpanArgs, type EvalCase, Experiment, type ExperimentSummary, type Exportable, 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, ReadonlyExperiment, type ScoreSummary, type SerializedBraintrustState, type SetCurrentArg, type Span, SpanImpl, type StartSpanArgs, type WithTransactionId, X_CACHED_HEADER, _internalGetGlobalState, _internalSetInitialState, braintrustStreamChunkSchema, createFinalValuePassThroughStream, currentExperiment, currentLogger, currentSpan, devNullWritableStream, flush, getSpanParentObject, init, initDataset, initExperiment, initLogger, invoke, loadPrompt, log, logError, login, loginToState, newId, parseCachedHeader, setFetch, startSpan, summarize, traceable, traced, updateSpan, withDataset, withExperiment, withLogger, wrapOpenAI, wrapOpenAIv4, wrapTraced };
1284
+ export { type AnyDataset, type BackgroundLoggerOpts, type BaseMetadata, BraintrustState, BraintrustStream, type BraintrustStreamChunk, type ChatPrompt, type CompiledPrompt, type CompiledPromptParams, type CompletionPrompt, type DataSummary, Dataset, type DatasetSummary, type DefaultMetadataType, type DefaultPromptArgs, type EndSpanArgs, type EvalCase, Experiment, type ExperimentSummary, type Exportable, 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, ReadonlyExperiment, type ScoreSummary, type SerializedBraintrustState, type SetCurrentArg, type Span, SpanImpl, type StartSpanArgs, type WithTransactionId, X_CACHED_HEADER, _internalGetGlobalState, _internalSetInitialState, braintrustStreamChunkSchema, createFinalValuePassThroughStream, currentExperiment, currentLogger, currentSpan, devNullWritableStream, flush, getSpanParentObject, init, initDataset, initExperiment, initLogger, invoke, loadPrompt, log, logError, login, loginToState, newId, parseCachedHeader, renderMessage, setFetch, startSpan, summarize, traceable, traced, updateSpan, withCurrent, withDataset, withExperiment, withLogger, wrapOpenAI, wrapOpenAIv4, wrapTraced };