braintrust 0.0.141-dev1 → 0.0.141
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 +144 -23
- package/dist/browser.d.ts +144 -23
- package/dist/browser.js +181 -110
- package/dist/browser.mjs +182 -111
- package/dist/cli.js +221 -161
- package/dist/index.d.mts +144 -23
- package/dist/index.d.ts +144 -23
- package/dist/index.js +182 -111
- package/dist/index.mjs +183 -112
- package/package.json +12 -10
- package/.turbo/turbo-build.log +0 -42
- package/.turbo/turbo-watch.log +0 -1843
- package/LICENSE +0 -201
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { GitMetadataSettings, LogFeedbackFullArgs, BackgroundLogEvent, ExperimentEvent, ExperimentLogFullArgs, ExperimentLogPartialArgs, IdField, SpanType, RepoInfo, DEFAULT_IS_LEGACY_DATASET, TRANSACTION_ID_FIELD, TransactionId, SpanObjectTypeV2, DatasetRecord, Score } from '@braintrust/core';
|
|
2
2
|
export { CommentEvent, DatasetRecord, ExperimentLogFullArgs, ExperimentLogPartialArgs, IdField, InputField, InputsField, LogCommentFullArgs, LogFeedbackFullArgs, OtherExperimentLogFields, ParentExperimentIds, ParentProjectLogIds } from '@braintrust/core';
|
|
3
|
-
import { PromptData, OpenAIMessage, Tools, AnyModelParam, Prompt as Prompt$1, PromptSessionEvent
|
|
3
|
+
import { PromptData, OpenAIMessage, Tools, AnyModelParam, Prompt as Prompt$1, PromptSessionEvent } from '@braintrust/core/typespecs';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
|
|
6
6
|
interface IsoAsyncLocalStorage<T> {
|
|
@@ -138,7 +138,7 @@ declare const loginSchema: z.ZodObject<{
|
|
|
138
138
|
appUrl: z.ZodString;
|
|
139
139
|
appPublicUrl: z.ZodString;
|
|
140
140
|
orgName: z.ZodString;
|
|
141
|
-
|
|
141
|
+
apiUrl: z.ZodString;
|
|
142
142
|
proxyUrl: z.ZodString;
|
|
143
143
|
loginToken: z.ZodString;
|
|
144
144
|
orgId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
@@ -156,7 +156,7 @@ declare const loginSchema: z.ZodObject<{
|
|
|
156
156
|
appUrl: string;
|
|
157
157
|
appPublicUrl: string;
|
|
158
158
|
orgName: string;
|
|
159
|
-
|
|
159
|
+
apiUrl: string;
|
|
160
160
|
proxyUrl: string;
|
|
161
161
|
loginToken: string;
|
|
162
162
|
orgId?: string | null | undefined;
|
|
@@ -168,7 +168,7 @@ declare const loginSchema: z.ZodObject<{
|
|
|
168
168
|
appUrl: string;
|
|
169
169
|
appPublicUrl: string;
|
|
170
170
|
orgName: string;
|
|
171
|
-
|
|
171
|
+
apiUrl: string;
|
|
172
172
|
proxyUrl: string;
|
|
173
173
|
loginToken: string;
|
|
174
174
|
orgId?: string | null | undefined;
|
|
@@ -190,13 +190,13 @@ declare class BraintrustState {
|
|
|
190
190
|
loginToken: string | null;
|
|
191
191
|
orgId: string | null;
|
|
192
192
|
orgName: string | null;
|
|
193
|
-
|
|
193
|
+
apiUrl: string | null;
|
|
194
194
|
proxyUrl: string | null;
|
|
195
195
|
loggedIn: boolean;
|
|
196
196
|
gitMetadataSettings?: GitMetadataSettings;
|
|
197
197
|
fetch: typeof globalThis.fetch;
|
|
198
|
+
private _appConn;
|
|
198
199
|
private _apiConn;
|
|
199
|
-
private _logConn;
|
|
200
200
|
private _proxyConn;
|
|
201
201
|
constructor(loginParams: LoginOptions);
|
|
202
202
|
resetLoginInfo(): void;
|
|
@@ -207,11 +207,11 @@ declare class BraintrustState {
|
|
|
207
207
|
login(loginParams: LoginOptions & {
|
|
208
208
|
forceLogin?: boolean;
|
|
209
209
|
}): Promise<void>;
|
|
210
|
+
appConn(): HTTPConnection;
|
|
210
211
|
apiConn(): HTTPConnection;
|
|
211
|
-
logConn(): HTTPConnection;
|
|
212
212
|
proxyConn(): HTTPConnection;
|
|
213
213
|
bgLogger(): BackgroundLogger;
|
|
214
|
-
|
|
214
|
+
loginReplaceApiConn(apiConn: HTTPConnection): void;
|
|
215
215
|
}
|
|
216
216
|
declare function _internalSetInitialState(): void;
|
|
217
217
|
declare const _internalGetGlobalState: () => BraintrustState;
|
|
@@ -272,7 +272,6 @@ declare class Logger<IsAsyncFlush extends boolean> implements Exportable {
|
|
|
272
272
|
get project(): Promise<ObjectMetadata>;
|
|
273
273
|
get id(): Promise<string>;
|
|
274
274
|
private parentObjectType;
|
|
275
|
-
private triggerWaitUntilFlush;
|
|
276
275
|
/**
|
|
277
276
|
* Log a single event. The event will be batched and uploaded behind the scenes if `logOptions.asyncFlush` is true.
|
|
278
277
|
*
|
|
@@ -326,7 +325,7 @@ declare class Logger<IsAsyncFlush extends boolean> implements Exportable {
|
|
|
326
325
|
get asyncFlush(): IsAsyncFlush | undefined;
|
|
327
326
|
}
|
|
328
327
|
declare class BackgroundLogger {
|
|
329
|
-
private
|
|
328
|
+
private apiConn;
|
|
330
329
|
private items;
|
|
331
330
|
private activeFlush;
|
|
332
331
|
private activeFlushResolved;
|
|
@@ -340,7 +339,7 @@ declare class BackgroundLogger {
|
|
|
340
339
|
failedPublishPayloadsDir: string | undefined;
|
|
341
340
|
allPublishPayloadsDir: string | undefined;
|
|
342
341
|
private queueDropLoggingState;
|
|
343
|
-
constructor(
|
|
342
|
+
constructor(apiConn: LazyValue<HTTPConnection>);
|
|
344
343
|
log(items: LazyValue<BackgroundLogEvent>[]): void;
|
|
345
344
|
flush(): Promise<void>;
|
|
346
345
|
private flushOnce;
|
|
@@ -351,7 +350,7 @@ declare class BackgroundLogger {
|
|
|
351
350
|
private static writePayloadToDir;
|
|
352
351
|
private triggerActiveFlush;
|
|
353
352
|
private logFailedPayloadsDir;
|
|
354
|
-
|
|
353
|
+
internalReplaceApiConn(apiConn: HTTPConnection): void;
|
|
355
354
|
}
|
|
356
355
|
type InitOpenOption<IsOpen extends boolean> = {
|
|
357
356
|
open?: IsOpen;
|
|
@@ -1025,33 +1024,155 @@ interface DatasetSummary {
|
|
|
1025
1024
|
dataSummary: DataSummary;
|
|
1026
1025
|
}
|
|
1027
1026
|
|
|
1028
|
-
|
|
1027
|
+
declare const braintrustStreamChunkSchema: z.ZodUnion<[z.ZodObject<{
|
|
1028
|
+
type: z.ZodLiteral<"text_delta">;
|
|
1029
|
+
data: z.ZodString;
|
|
1030
|
+
}, "strip", z.ZodTypeAny, {
|
|
1031
|
+
data: string;
|
|
1032
|
+
type: "text_delta";
|
|
1033
|
+
}, {
|
|
1034
|
+
data: string;
|
|
1029
1035
|
type: "text_delta";
|
|
1036
|
+
}>, z.ZodObject<{
|
|
1037
|
+
type: z.ZodLiteral<"json_delta">;
|
|
1038
|
+
data: z.ZodString;
|
|
1039
|
+
}, "strip", z.ZodTypeAny, {
|
|
1030
1040
|
data: string;
|
|
1031
|
-
} | {
|
|
1032
1041
|
type: "json_delta";
|
|
1042
|
+
}, {
|
|
1033
1043
|
data: string;
|
|
1034
|
-
|
|
1044
|
+
type: "json_delta";
|
|
1045
|
+
}>]>;
|
|
1046
|
+
/**
|
|
1047
|
+
* A chunk of data from a Braintrust stream. Each chunk type matches
|
|
1048
|
+
* an SSE event type.
|
|
1049
|
+
*/
|
|
1050
|
+
type BraintrustStreamChunk = z.infer<typeof braintrustStreamChunkSchema>;
|
|
1051
|
+
/**
|
|
1052
|
+
* A Braintrust stream. This is a wrapper around a ReadableStream of `BraintrustStreamChunk`,
|
|
1053
|
+
* with some utility methods to make them easy to log and convert into various formats.
|
|
1054
|
+
*/
|
|
1035
1055
|
declare class BraintrustStream {
|
|
1036
1056
|
private stream;
|
|
1057
|
+
private memoizedFinalValue;
|
|
1037
1058
|
constructor(baseStream: ReadableStream<Uint8Array>);
|
|
1038
1059
|
constructor(stream: ReadableStream<string>);
|
|
1039
1060
|
constructor(stream: ReadableStream<BraintrustStreamChunk>);
|
|
1061
|
+
/**
|
|
1062
|
+
* Copy the stream. This returns a new stream that shares the same underlying
|
|
1063
|
+
* stream (via `tee`). Since streams are consumed in Javascript, use `copy()` if you
|
|
1064
|
+
* need to use the stream multiple times.
|
|
1065
|
+
*
|
|
1066
|
+
* @returns A new stream that you can independently consume.
|
|
1067
|
+
*/
|
|
1040
1068
|
copy(): BraintrustStream;
|
|
1069
|
+
/**
|
|
1070
|
+
* Get the underlying ReadableStream.
|
|
1071
|
+
*
|
|
1072
|
+
* @returns The underlying ReadableStream<BraintrustStreamChunk>.
|
|
1073
|
+
*/
|
|
1041
1074
|
toReadableStream(): ReadableStream<BraintrustStreamChunk>;
|
|
1075
|
+
/**
|
|
1076
|
+
* Get the final value of the stream. The final value is the concatenation of all
|
|
1077
|
+
* the chunks in the stream, deserialized into a string or JSON object, depending on
|
|
1078
|
+
* the value's type.
|
|
1079
|
+
*
|
|
1080
|
+
* This function returns a promise that resolves when the stream is closed, and
|
|
1081
|
+
* contains the final value. Multiple calls to `finalValue()` will return the same
|
|
1082
|
+
* promise, so it is safe to call this multiple times.
|
|
1083
|
+
*
|
|
1084
|
+
* This function consumes the stream, so if you need to use the stream multiple
|
|
1085
|
+
* times, you should call `copy()` first.
|
|
1086
|
+
*
|
|
1087
|
+
* @returns A promise that resolves with the final value of the stream or `undefined` if the stream is empty.
|
|
1088
|
+
*/
|
|
1089
|
+
finalValue(): Promise<unknown>;
|
|
1042
1090
|
}
|
|
1091
|
+
/**
|
|
1092
|
+
* Create a stream that passes through the final value of the stream. This is
|
|
1093
|
+
* used to implement `BraintrustStream.finalValue()`.
|
|
1094
|
+
*
|
|
1095
|
+
* @param onFinal A function to call with the final value of the stream.
|
|
1096
|
+
* @returns A new stream that passes through the final value of the stream.
|
|
1097
|
+
*/
|
|
1043
1098
|
declare function createFinalValuePassThroughStream<T extends BraintrustStreamChunk | string | Uint8Array>(onFinal: (result: unknown) => void): TransformStream<T, BraintrustStreamChunk>;
|
|
1044
1099
|
declare function devNullWritableStream(): WritableStream;
|
|
1045
1100
|
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1101
|
+
/**
|
|
1102
|
+
* Arguments for the `invoke` function.
|
|
1103
|
+
*/
|
|
1104
|
+
interface InvokeFunctionArgs<Input, Output, Stream extends boolean = false> {
|
|
1105
|
+
/**
|
|
1106
|
+
* The ID of the function to invoke.
|
|
1107
|
+
*/
|
|
1108
|
+
function_id?: string;
|
|
1109
|
+
/**
|
|
1110
|
+
* The name of the project containing the function to invoke.
|
|
1111
|
+
*/
|
|
1112
|
+
project_name?: string;
|
|
1113
|
+
/**
|
|
1114
|
+
* The slug of the function to invoke.
|
|
1115
|
+
*/
|
|
1116
|
+
slug?: string;
|
|
1117
|
+
/**
|
|
1118
|
+
* The name of the global function to invoke.
|
|
1119
|
+
*/
|
|
1120
|
+
global_function?: string;
|
|
1121
|
+
/**
|
|
1122
|
+
* The ID of the prompt session to invoke the function from.
|
|
1123
|
+
*/
|
|
1124
|
+
prompt_session_id?: string;
|
|
1125
|
+
/**
|
|
1126
|
+
* The ID of the function in the prompt session to invoke.
|
|
1127
|
+
*/
|
|
1128
|
+
prompt_session_function_id?: string;
|
|
1129
|
+
/**
|
|
1130
|
+
* The version of the function to invoke.
|
|
1131
|
+
*/
|
|
1132
|
+
version?: string;
|
|
1133
|
+
/**
|
|
1134
|
+
* The input to the function. This will be logged as the `input` field in the span.
|
|
1135
|
+
*/
|
|
1136
|
+
input: Input;
|
|
1137
|
+
/**
|
|
1138
|
+
* The parent of the function. This can be an existing span, logger, or experiment, or
|
|
1139
|
+
* the output of `.export()` if you are distributed tracing. If unspecified, will use
|
|
1140
|
+
* the same semantics as `traced()` to determine the parent and no-op if not in a tracing
|
|
1141
|
+
* context.
|
|
1142
|
+
*/
|
|
1049
1143
|
parent?: Exportable | string;
|
|
1050
|
-
|
|
1144
|
+
/**
|
|
1145
|
+
* Whether to stream the function's output. If true, the function will return a
|
|
1146
|
+
* `BraintrustStream`, otherwise it will return the output of the function as a JSON
|
|
1147
|
+
* object.
|
|
1148
|
+
*/
|
|
1051
1149
|
stream?: Stream;
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1150
|
+
/**
|
|
1151
|
+
* A Zod schema to validate the output of the function and return a typed value. This
|
|
1152
|
+
* is only used if `stream` is false.
|
|
1153
|
+
*/
|
|
1154
|
+
schema?: Stream extends true ? never : z.ZodSchema<Output>;
|
|
1155
|
+
/**
|
|
1156
|
+
* (Advanced) This parameter allows you to pass in a custom login state. This is useful
|
|
1157
|
+
* for multi-tenant environments where you are running functions from different Braintrust
|
|
1158
|
+
* organizations.
|
|
1159
|
+
*/
|
|
1160
|
+
state?: BraintrustState;
|
|
1161
|
+
}
|
|
1162
|
+
/**
|
|
1163
|
+
* The return type of the `invoke` function. Conditionally returns a `BraintrustStream`
|
|
1164
|
+
* if `stream` is true, otherwise returns the output of the function using the Zod schema's
|
|
1165
|
+
* type if present.
|
|
1166
|
+
*/
|
|
1167
|
+
type InvokeReturn<Stream extends boolean, Output> = Stream extends true ? BraintrustStream : Output;
|
|
1168
|
+
/**
|
|
1169
|
+
* Invoke a Braintrust function, returning a `BraintrustStream` or the value as a plain
|
|
1170
|
+
* Javascript object.
|
|
1171
|
+
*
|
|
1172
|
+
* @param args The arguments for the function (see {@link InvokeFunctionArgs} for more details).
|
|
1173
|
+
* @returns The output of the function.
|
|
1174
|
+
*/
|
|
1175
|
+
declare function invoke<Input, Output, Stream extends boolean = false>(args: InvokeFunctionArgs<Input, Output, Stream> & FullLoginOptions): Promise<InvokeReturn<Stream, Output>>;
|
|
1055
1176
|
|
|
1056
1177
|
type BaseExperiment<Input, Expected, Metadata extends BaseMetadata = DefaultMetadataType> = {
|
|
1057
1178
|
_type: "BaseExperiment";
|
|
@@ -1247,4 +1368,4 @@ declare function parseCachedHeader(value: string | null | undefined): number | u
|
|
|
1247
1368
|
*/
|
|
1248
1369
|
declare function wrapAISDKModel<T extends object>(model: T): T;
|
|
1249
1370
|
|
|
1250
|
-
export { type AnyDataset, BaseExperiment, 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, Eval, type EvalCase, type EvalScorerArgs, type EvalTask, type Evaluator, Experiment, type ExperimentSummary, type Exportable, type FullInitOptions, type FullLoginOptions, type InitOptions, type InvokeFunctionArgs, type InvokeReturn, LEGACY_CACHED_HEADER, LazyValue, type LogOptions, Logger, type LoginOptions, type MetricSummary, NOOP_SPAN, NoopSpan, type ObjectMetadata, type PromiseUnless, Prompt, ReadonlyExperiment, Reporter, type ReporterBody, type ScoreSummary, type SerializedBraintrustState, type SetCurrentArg, type Span, SpanImpl, type StartSpanArgs, type WithTransactionId, X_CACHED_HEADER, _internalGetGlobalState, _internalSetInitialState, buildLocalSummary, createFinalValuePassThroughStream, currentExperiment, currentLogger, currentSpan, devNullWritableStream, flush, getSpanParentObject, init, initDataset, initExperiment, initLogger, invoke, loadPrompt, log, login, loginToState, newId, parseCachedHeader, reportFailures, setFetch, startSpan, summarize, traceable, traced, withDataset, withExperiment, withLogger, wrapAISDKModel, wrapOpenAI, wrapOpenAIv4, wrapTraced };
|
|
1371
|
+
export { type AnyDataset, BaseExperiment, 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, Eval, type EvalCase, type EvalScorerArgs, type EvalTask, type Evaluator, Experiment, type ExperimentSummary, type Exportable, type FullInitOptions, type FullLoginOptions, type InitOptions, type InvokeFunctionArgs, type InvokeReturn, LEGACY_CACHED_HEADER, LazyValue, type LogOptions, Logger, type LoginOptions, type MetricSummary, NOOP_SPAN, NoopSpan, type ObjectMetadata, type PromiseUnless, Prompt, ReadonlyExperiment, Reporter, type ReporterBody, type ScoreSummary, type SerializedBraintrustState, type SetCurrentArg, type Span, SpanImpl, type StartSpanArgs, type WithTransactionId, X_CACHED_HEADER, _internalGetGlobalState, _internalSetInitialState, braintrustStreamChunkSchema, buildLocalSummary, createFinalValuePassThroughStream, currentExperiment, currentLogger, currentSpan, devNullWritableStream, flush, getSpanParentObject, init, initDataset, initExperiment, initLogger, invoke, loadPrompt, log, login, loginToState, newId, parseCachedHeader, reportFailures, setFetch, startSpan, summarize, traceable, traced, withDataset, withExperiment, withLogger, wrapAISDKModel, wrapOpenAI, wrapOpenAIv4, wrapTraced };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { GitMetadataSettings, LogFeedbackFullArgs, BackgroundLogEvent, ExperimentEvent, ExperimentLogFullArgs, ExperimentLogPartialArgs, IdField, SpanType, RepoInfo, DEFAULT_IS_LEGACY_DATASET, TRANSACTION_ID_FIELD, TransactionId, SpanObjectTypeV2, DatasetRecord, Score } from '@braintrust/core';
|
|
2
2
|
export { CommentEvent, DatasetRecord, ExperimentLogFullArgs, ExperimentLogPartialArgs, IdField, InputField, InputsField, LogCommentFullArgs, LogFeedbackFullArgs, OtherExperimentLogFields, ParentExperimentIds, ParentProjectLogIds } from '@braintrust/core';
|
|
3
|
-
import { PromptData, OpenAIMessage, Tools, AnyModelParam, Prompt as Prompt$1, PromptSessionEvent
|
|
3
|
+
import { PromptData, OpenAIMessage, Tools, AnyModelParam, Prompt as Prompt$1, PromptSessionEvent } from '@braintrust/core/typespecs';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
|
|
6
6
|
interface IsoAsyncLocalStorage<T> {
|
|
@@ -138,7 +138,7 @@ declare const loginSchema: z.ZodObject<{
|
|
|
138
138
|
appUrl: z.ZodString;
|
|
139
139
|
appPublicUrl: z.ZodString;
|
|
140
140
|
orgName: z.ZodString;
|
|
141
|
-
|
|
141
|
+
apiUrl: z.ZodString;
|
|
142
142
|
proxyUrl: z.ZodString;
|
|
143
143
|
loginToken: z.ZodString;
|
|
144
144
|
orgId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
@@ -156,7 +156,7 @@ declare const loginSchema: z.ZodObject<{
|
|
|
156
156
|
appUrl: string;
|
|
157
157
|
appPublicUrl: string;
|
|
158
158
|
orgName: string;
|
|
159
|
-
|
|
159
|
+
apiUrl: string;
|
|
160
160
|
proxyUrl: string;
|
|
161
161
|
loginToken: string;
|
|
162
162
|
orgId?: string | null | undefined;
|
|
@@ -168,7 +168,7 @@ declare const loginSchema: z.ZodObject<{
|
|
|
168
168
|
appUrl: string;
|
|
169
169
|
appPublicUrl: string;
|
|
170
170
|
orgName: string;
|
|
171
|
-
|
|
171
|
+
apiUrl: string;
|
|
172
172
|
proxyUrl: string;
|
|
173
173
|
loginToken: string;
|
|
174
174
|
orgId?: string | null | undefined;
|
|
@@ -190,13 +190,13 @@ declare class BraintrustState {
|
|
|
190
190
|
loginToken: string | null;
|
|
191
191
|
orgId: string | null;
|
|
192
192
|
orgName: string | null;
|
|
193
|
-
|
|
193
|
+
apiUrl: string | null;
|
|
194
194
|
proxyUrl: string | null;
|
|
195
195
|
loggedIn: boolean;
|
|
196
196
|
gitMetadataSettings?: GitMetadataSettings;
|
|
197
197
|
fetch: typeof globalThis.fetch;
|
|
198
|
+
private _appConn;
|
|
198
199
|
private _apiConn;
|
|
199
|
-
private _logConn;
|
|
200
200
|
private _proxyConn;
|
|
201
201
|
constructor(loginParams: LoginOptions);
|
|
202
202
|
resetLoginInfo(): void;
|
|
@@ -207,11 +207,11 @@ declare class BraintrustState {
|
|
|
207
207
|
login(loginParams: LoginOptions & {
|
|
208
208
|
forceLogin?: boolean;
|
|
209
209
|
}): Promise<void>;
|
|
210
|
+
appConn(): HTTPConnection;
|
|
210
211
|
apiConn(): HTTPConnection;
|
|
211
|
-
logConn(): HTTPConnection;
|
|
212
212
|
proxyConn(): HTTPConnection;
|
|
213
213
|
bgLogger(): BackgroundLogger;
|
|
214
|
-
|
|
214
|
+
loginReplaceApiConn(apiConn: HTTPConnection): void;
|
|
215
215
|
}
|
|
216
216
|
declare function _internalSetInitialState(): void;
|
|
217
217
|
declare const _internalGetGlobalState: () => BraintrustState;
|
|
@@ -272,7 +272,6 @@ declare class Logger<IsAsyncFlush extends boolean> implements Exportable {
|
|
|
272
272
|
get project(): Promise<ObjectMetadata>;
|
|
273
273
|
get id(): Promise<string>;
|
|
274
274
|
private parentObjectType;
|
|
275
|
-
private triggerWaitUntilFlush;
|
|
276
275
|
/**
|
|
277
276
|
* Log a single event. The event will be batched and uploaded behind the scenes if `logOptions.asyncFlush` is true.
|
|
278
277
|
*
|
|
@@ -326,7 +325,7 @@ declare class Logger<IsAsyncFlush extends boolean> implements Exportable {
|
|
|
326
325
|
get asyncFlush(): IsAsyncFlush | undefined;
|
|
327
326
|
}
|
|
328
327
|
declare class BackgroundLogger {
|
|
329
|
-
private
|
|
328
|
+
private apiConn;
|
|
330
329
|
private items;
|
|
331
330
|
private activeFlush;
|
|
332
331
|
private activeFlushResolved;
|
|
@@ -340,7 +339,7 @@ declare class BackgroundLogger {
|
|
|
340
339
|
failedPublishPayloadsDir: string | undefined;
|
|
341
340
|
allPublishPayloadsDir: string | undefined;
|
|
342
341
|
private queueDropLoggingState;
|
|
343
|
-
constructor(
|
|
342
|
+
constructor(apiConn: LazyValue<HTTPConnection>);
|
|
344
343
|
log(items: LazyValue<BackgroundLogEvent>[]): void;
|
|
345
344
|
flush(): Promise<void>;
|
|
346
345
|
private flushOnce;
|
|
@@ -351,7 +350,7 @@ declare class BackgroundLogger {
|
|
|
351
350
|
private static writePayloadToDir;
|
|
352
351
|
private triggerActiveFlush;
|
|
353
352
|
private logFailedPayloadsDir;
|
|
354
|
-
|
|
353
|
+
internalReplaceApiConn(apiConn: HTTPConnection): void;
|
|
355
354
|
}
|
|
356
355
|
type InitOpenOption<IsOpen extends boolean> = {
|
|
357
356
|
open?: IsOpen;
|
|
@@ -1025,33 +1024,155 @@ interface DatasetSummary {
|
|
|
1025
1024
|
dataSummary: DataSummary;
|
|
1026
1025
|
}
|
|
1027
1026
|
|
|
1028
|
-
|
|
1027
|
+
declare const braintrustStreamChunkSchema: z.ZodUnion<[z.ZodObject<{
|
|
1028
|
+
type: z.ZodLiteral<"text_delta">;
|
|
1029
|
+
data: z.ZodString;
|
|
1030
|
+
}, "strip", z.ZodTypeAny, {
|
|
1031
|
+
data: string;
|
|
1032
|
+
type: "text_delta";
|
|
1033
|
+
}, {
|
|
1034
|
+
data: string;
|
|
1029
1035
|
type: "text_delta";
|
|
1036
|
+
}>, z.ZodObject<{
|
|
1037
|
+
type: z.ZodLiteral<"json_delta">;
|
|
1038
|
+
data: z.ZodString;
|
|
1039
|
+
}, "strip", z.ZodTypeAny, {
|
|
1030
1040
|
data: string;
|
|
1031
|
-
} | {
|
|
1032
1041
|
type: "json_delta";
|
|
1042
|
+
}, {
|
|
1033
1043
|
data: string;
|
|
1034
|
-
|
|
1044
|
+
type: "json_delta";
|
|
1045
|
+
}>]>;
|
|
1046
|
+
/**
|
|
1047
|
+
* A chunk of data from a Braintrust stream. Each chunk type matches
|
|
1048
|
+
* an SSE event type.
|
|
1049
|
+
*/
|
|
1050
|
+
type BraintrustStreamChunk = z.infer<typeof braintrustStreamChunkSchema>;
|
|
1051
|
+
/**
|
|
1052
|
+
* A Braintrust stream. This is a wrapper around a ReadableStream of `BraintrustStreamChunk`,
|
|
1053
|
+
* with some utility methods to make them easy to log and convert into various formats.
|
|
1054
|
+
*/
|
|
1035
1055
|
declare class BraintrustStream {
|
|
1036
1056
|
private stream;
|
|
1057
|
+
private memoizedFinalValue;
|
|
1037
1058
|
constructor(baseStream: ReadableStream<Uint8Array>);
|
|
1038
1059
|
constructor(stream: ReadableStream<string>);
|
|
1039
1060
|
constructor(stream: ReadableStream<BraintrustStreamChunk>);
|
|
1061
|
+
/**
|
|
1062
|
+
* Copy the stream. This returns a new stream that shares the same underlying
|
|
1063
|
+
* stream (via `tee`). Since streams are consumed in Javascript, use `copy()` if you
|
|
1064
|
+
* need to use the stream multiple times.
|
|
1065
|
+
*
|
|
1066
|
+
* @returns A new stream that you can independently consume.
|
|
1067
|
+
*/
|
|
1040
1068
|
copy(): BraintrustStream;
|
|
1069
|
+
/**
|
|
1070
|
+
* Get the underlying ReadableStream.
|
|
1071
|
+
*
|
|
1072
|
+
* @returns The underlying ReadableStream<BraintrustStreamChunk>.
|
|
1073
|
+
*/
|
|
1041
1074
|
toReadableStream(): ReadableStream<BraintrustStreamChunk>;
|
|
1075
|
+
/**
|
|
1076
|
+
* Get the final value of the stream. The final value is the concatenation of all
|
|
1077
|
+
* the chunks in the stream, deserialized into a string or JSON object, depending on
|
|
1078
|
+
* the value's type.
|
|
1079
|
+
*
|
|
1080
|
+
* This function returns a promise that resolves when the stream is closed, and
|
|
1081
|
+
* contains the final value. Multiple calls to `finalValue()` will return the same
|
|
1082
|
+
* promise, so it is safe to call this multiple times.
|
|
1083
|
+
*
|
|
1084
|
+
* This function consumes the stream, so if you need to use the stream multiple
|
|
1085
|
+
* times, you should call `copy()` first.
|
|
1086
|
+
*
|
|
1087
|
+
* @returns A promise that resolves with the final value of the stream or `undefined` if the stream is empty.
|
|
1088
|
+
*/
|
|
1089
|
+
finalValue(): Promise<unknown>;
|
|
1042
1090
|
}
|
|
1091
|
+
/**
|
|
1092
|
+
* Create a stream that passes through the final value of the stream. This is
|
|
1093
|
+
* used to implement `BraintrustStream.finalValue()`.
|
|
1094
|
+
*
|
|
1095
|
+
* @param onFinal A function to call with the final value of the stream.
|
|
1096
|
+
* @returns A new stream that passes through the final value of the stream.
|
|
1097
|
+
*/
|
|
1043
1098
|
declare function createFinalValuePassThroughStream<T extends BraintrustStreamChunk | string | Uint8Array>(onFinal: (result: unknown) => void): TransformStream<T, BraintrustStreamChunk>;
|
|
1044
1099
|
declare function devNullWritableStream(): WritableStream;
|
|
1045
1100
|
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1101
|
+
/**
|
|
1102
|
+
* Arguments for the `invoke` function.
|
|
1103
|
+
*/
|
|
1104
|
+
interface InvokeFunctionArgs<Input, Output, Stream extends boolean = false> {
|
|
1105
|
+
/**
|
|
1106
|
+
* The ID of the function to invoke.
|
|
1107
|
+
*/
|
|
1108
|
+
function_id?: string;
|
|
1109
|
+
/**
|
|
1110
|
+
* The name of the project containing the function to invoke.
|
|
1111
|
+
*/
|
|
1112
|
+
project_name?: string;
|
|
1113
|
+
/**
|
|
1114
|
+
* The slug of the function to invoke.
|
|
1115
|
+
*/
|
|
1116
|
+
slug?: string;
|
|
1117
|
+
/**
|
|
1118
|
+
* The name of the global function to invoke.
|
|
1119
|
+
*/
|
|
1120
|
+
global_function?: string;
|
|
1121
|
+
/**
|
|
1122
|
+
* The ID of the prompt session to invoke the function from.
|
|
1123
|
+
*/
|
|
1124
|
+
prompt_session_id?: string;
|
|
1125
|
+
/**
|
|
1126
|
+
* The ID of the function in the prompt session to invoke.
|
|
1127
|
+
*/
|
|
1128
|
+
prompt_session_function_id?: string;
|
|
1129
|
+
/**
|
|
1130
|
+
* The version of the function to invoke.
|
|
1131
|
+
*/
|
|
1132
|
+
version?: string;
|
|
1133
|
+
/**
|
|
1134
|
+
* The input to the function. This will be logged as the `input` field in the span.
|
|
1135
|
+
*/
|
|
1136
|
+
input: Input;
|
|
1137
|
+
/**
|
|
1138
|
+
* The parent of the function. This can be an existing span, logger, or experiment, or
|
|
1139
|
+
* the output of `.export()` if you are distributed tracing. If unspecified, will use
|
|
1140
|
+
* the same semantics as `traced()` to determine the parent and no-op if not in a tracing
|
|
1141
|
+
* context.
|
|
1142
|
+
*/
|
|
1049
1143
|
parent?: Exportable | string;
|
|
1050
|
-
|
|
1144
|
+
/**
|
|
1145
|
+
* Whether to stream the function's output. If true, the function will return a
|
|
1146
|
+
* `BraintrustStream`, otherwise it will return the output of the function as a JSON
|
|
1147
|
+
* object.
|
|
1148
|
+
*/
|
|
1051
1149
|
stream?: Stream;
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1150
|
+
/**
|
|
1151
|
+
* A Zod schema to validate the output of the function and return a typed value. This
|
|
1152
|
+
* is only used if `stream` is false.
|
|
1153
|
+
*/
|
|
1154
|
+
schema?: Stream extends true ? never : z.ZodSchema<Output>;
|
|
1155
|
+
/**
|
|
1156
|
+
* (Advanced) This parameter allows you to pass in a custom login state. This is useful
|
|
1157
|
+
* for multi-tenant environments where you are running functions from different Braintrust
|
|
1158
|
+
* organizations.
|
|
1159
|
+
*/
|
|
1160
|
+
state?: BraintrustState;
|
|
1161
|
+
}
|
|
1162
|
+
/**
|
|
1163
|
+
* The return type of the `invoke` function. Conditionally returns a `BraintrustStream`
|
|
1164
|
+
* if `stream` is true, otherwise returns the output of the function using the Zod schema's
|
|
1165
|
+
* type if present.
|
|
1166
|
+
*/
|
|
1167
|
+
type InvokeReturn<Stream extends boolean, Output> = Stream extends true ? BraintrustStream : Output;
|
|
1168
|
+
/**
|
|
1169
|
+
* Invoke a Braintrust function, returning a `BraintrustStream` or the value as a plain
|
|
1170
|
+
* Javascript object.
|
|
1171
|
+
*
|
|
1172
|
+
* @param args The arguments for the function (see {@link InvokeFunctionArgs} for more details).
|
|
1173
|
+
* @returns The output of the function.
|
|
1174
|
+
*/
|
|
1175
|
+
declare function invoke<Input, Output, Stream extends boolean = false>(args: InvokeFunctionArgs<Input, Output, Stream> & FullLoginOptions): Promise<InvokeReturn<Stream, Output>>;
|
|
1055
1176
|
|
|
1056
1177
|
type BaseExperiment<Input, Expected, Metadata extends BaseMetadata = DefaultMetadataType> = {
|
|
1057
1178
|
_type: "BaseExperiment";
|
|
@@ -1247,4 +1368,4 @@ declare function parseCachedHeader(value: string | null | undefined): number | u
|
|
|
1247
1368
|
*/
|
|
1248
1369
|
declare function wrapAISDKModel<T extends object>(model: T): T;
|
|
1249
1370
|
|
|
1250
|
-
export { type AnyDataset, BaseExperiment, 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, Eval, type EvalCase, type EvalScorerArgs, type EvalTask, type Evaluator, Experiment, type ExperimentSummary, type Exportable, type FullInitOptions, type FullLoginOptions, type InitOptions, type InvokeFunctionArgs, type InvokeReturn, LEGACY_CACHED_HEADER, LazyValue, type LogOptions, Logger, type LoginOptions, type MetricSummary, NOOP_SPAN, NoopSpan, type ObjectMetadata, type PromiseUnless, Prompt, ReadonlyExperiment, Reporter, type ReporterBody, type ScoreSummary, type SerializedBraintrustState, type SetCurrentArg, type Span, SpanImpl, type StartSpanArgs, type WithTransactionId, X_CACHED_HEADER, _internalGetGlobalState, _internalSetInitialState, buildLocalSummary, createFinalValuePassThroughStream, currentExperiment, currentLogger, currentSpan, devNullWritableStream, flush, getSpanParentObject, init, initDataset, initExperiment, initLogger, invoke, loadPrompt, log, login, loginToState, newId, parseCachedHeader, reportFailures, setFetch, startSpan, summarize, traceable, traced, withDataset, withExperiment, withLogger, wrapAISDKModel, wrapOpenAI, wrapOpenAIv4, wrapTraced };
|
|
1371
|
+
export { type AnyDataset, BaseExperiment, 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, Eval, type EvalCase, type EvalScorerArgs, type EvalTask, type Evaluator, Experiment, type ExperimentSummary, type Exportable, type FullInitOptions, type FullLoginOptions, type InitOptions, type InvokeFunctionArgs, type InvokeReturn, LEGACY_CACHED_HEADER, LazyValue, type LogOptions, Logger, type LoginOptions, type MetricSummary, NOOP_SPAN, NoopSpan, type ObjectMetadata, type PromiseUnless, Prompt, ReadonlyExperiment, Reporter, type ReporterBody, type ScoreSummary, type SerializedBraintrustState, type SetCurrentArg, type Span, SpanImpl, type StartSpanArgs, type WithTransactionId, X_CACHED_HEADER, _internalGetGlobalState, _internalSetInitialState, braintrustStreamChunkSchema, buildLocalSummary, createFinalValuePassThroughStream, currentExperiment, currentLogger, currentSpan, devNullWritableStream, flush, getSpanParentObject, init, initDataset, initExperiment, initLogger, invoke, loadPrompt, log, login, loginToState, newId, parseCachedHeader, reportFailures, setFetch, startSpan, summarize, traceable, traced, withDataset, withExperiment, withLogger, wrapAISDKModel, wrapOpenAI, wrapOpenAIv4, wrapTraced };
|