braintrust 0.2.4 → 0.2.6
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/dev/dist/index.d.mts +7279 -491
- package/dev/dist/index.d.ts +7279 -491
- package/dev/dist/index.js +1435 -112
- package/dev/dist/index.mjs +1490 -167
- package/dist/browser.d.mts +9210 -2104
- package/dist/browser.d.ts +9210 -2104
- package/dist/browser.js +1524 -104
- package/dist/browser.mjs +1547 -127
- package/dist/cli.js +1586 -236
- package/dist/index.d.mts +15905 -2447
- package/dist/index.d.ts +15905 -2447
- package/dist/index.js +1673 -193
- package/dist/index.mjs +1670 -190
- package/package.json +9 -6
package/dist/browser.mjs
CHANGED
|
@@ -109,64 +109,1302 @@ import {
|
|
|
109
109
|
isArray,
|
|
110
110
|
isObject
|
|
111
111
|
} from "@braintrust/core";
|
|
112
|
-
import {
|
|
113
|
-
attachmentReferenceSchema,
|
|
114
|
-
responseFormatJsonSchemaSchema,
|
|
115
|
-
attachmentStatusSchema,
|
|
116
|
-
BRAINTRUST_ATTACHMENT,
|
|
117
|
-
BRAINTRUST_PARAMS,
|
|
118
|
-
gitMetadataSettingsSchema,
|
|
119
|
-
promptDataSchema,
|
|
120
|
-
promptSchema,
|
|
121
|
-
toolsSchema,
|
|
122
|
-
EXTERNAL_ATTACHMENT
|
|
123
|
-
} from "@braintrust/core/typespecs";
|
|
124
|
-
import { waitUntil } from "@vercel/functions";
|
|
125
|
-
import Mustache2 from "mustache";
|
|
126
|
-
import { z as z2, ZodError } from "zod";
|
|
127
112
|
|
|
128
|
-
// src/
|
|
129
|
-
import {
|
|
130
|
-
callEventSchema,
|
|
131
|
-
sseConsoleEventDataSchema,
|
|
132
|
-
sseProgressEventDataSchema
|
|
133
|
-
} from "@braintrust/core/typespecs";
|
|
134
|
-
import {
|
|
135
|
-
createParser
|
|
136
|
-
} from "eventsource-parser";
|
|
113
|
+
// src/generated_types.ts
|
|
137
114
|
import { z } from "zod";
|
|
138
|
-
var
|
|
115
|
+
var AclObjectType = z.union([
|
|
116
|
+
z.enum([
|
|
117
|
+
"organization",
|
|
118
|
+
"project",
|
|
119
|
+
"experiment",
|
|
120
|
+
"dataset",
|
|
121
|
+
"prompt",
|
|
122
|
+
"prompt_session",
|
|
123
|
+
"group",
|
|
124
|
+
"role",
|
|
125
|
+
"org_member",
|
|
126
|
+
"project_log",
|
|
127
|
+
"org_project"
|
|
128
|
+
]),
|
|
129
|
+
z.null()
|
|
130
|
+
]);
|
|
131
|
+
var Permission = z.enum([
|
|
132
|
+
"create",
|
|
133
|
+
"read",
|
|
134
|
+
"update",
|
|
135
|
+
"delete",
|
|
136
|
+
"create_acls",
|
|
137
|
+
"read_acls",
|
|
138
|
+
"update_acls",
|
|
139
|
+
"delete_acls"
|
|
140
|
+
]);
|
|
141
|
+
var Acl = z.object({
|
|
142
|
+
id: z.string().uuid(),
|
|
143
|
+
object_type: AclObjectType.and(z.string()),
|
|
144
|
+
object_id: z.string().uuid(),
|
|
145
|
+
user_id: z.union([z.string(), z.null()]).optional(),
|
|
146
|
+
group_id: z.union([z.string(), z.null()]).optional(),
|
|
147
|
+
permission: Permission.and(z.union([z.string(), z.null()])).optional(),
|
|
148
|
+
restrict_object_type: AclObjectType.and(z.unknown()).optional(),
|
|
149
|
+
role_id: z.union([z.string(), z.null()]).optional(),
|
|
150
|
+
_object_org_id: z.string().uuid(),
|
|
151
|
+
created: z.union([z.string(), z.null()]).optional()
|
|
152
|
+
});
|
|
153
|
+
var AISecret = z.object({
|
|
154
|
+
id: z.string().uuid(),
|
|
155
|
+
created: z.union([z.string(), z.null()]).optional(),
|
|
156
|
+
updated_at: z.union([z.string(), z.null()]).optional(),
|
|
157
|
+
org_id: z.string().uuid(),
|
|
158
|
+
name: z.string(),
|
|
159
|
+
type: z.union([z.string(), z.null()]).optional(),
|
|
160
|
+
metadata: z.union([z.object({}).partial().passthrough(), z.null()]).optional(),
|
|
161
|
+
preview_secret: z.union([z.string(), z.null()]).optional()
|
|
162
|
+
});
|
|
163
|
+
var ResponseFormatJsonSchema = z.object({
|
|
164
|
+
name: z.string(),
|
|
165
|
+
description: z.string().optional(),
|
|
166
|
+
schema: z.union([z.object({}).partial().passthrough(), z.string()]).optional(),
|
|
167
|
+
strict: z.union([z.boolean(), z.null()]).optional()
|
|
168
|
+
});
|
|
169
|
+
var ResponseFormatNullish = z.union([
|
|
170
|
+
z.object({ type: z.literal("json_object") }),
|
|
171
|
+
z.object({
|
|
172
|
+
type: z.literal("json_schema"),
|
|
173
|
+
json_schema: ResponseFormatJsonSchema
|
|
174
|
+
}),
|
|
175
|
+
z.object({ type: z.literal("text") }),
|
|
176
|
+
z.null()
|
|
177
|
+
]);
|
|
178
|
+
var AnyModelParams = z.object({
|
|
179
|
+
temperature: z.number().optional(),
|
|
180
|
+
top_p: z.number().optional(),
|
|
181
|
+
max_tokens: z.number(),
|
|
182
|
+
max_completion_tokens: z.number().optional(),
|
|
183
|
+
frequency_penalty: z.number().optional(),
|
|
184
|
+
presence_penalty: z.number().optional(),
|
|
185
|
+
response_format: ResponseFormatNullish.optional(),
|
|
186
|
+
tool_choice: z.union([
|
|
187
|
+
z.literal("auto"),
|
|
188
|
+
z.literal("none"),
|
|
189
|
+
z.literal("required"),
|
|
190
|
+
z.object({
|
|
191
|
+
type: z.literal("function"),
|
|
192
|
+
function: z.object({ name: z.string() })
|
|
193
|
+
})
|
|
194
|
+
]).optional(),
|
|
195
|
+
function_call: z.union([
|
|
196
|
+
z.literal("auto"),
|
|
197
|
+
z.literal("none"),
|
|
198
|
+
z.object({ name: z.string() })
|
|
199
|
+
]).optional(),
|
|
200
|
+
n: z.number().optional(),
|
|
201
|
+
stop: z.array(z.string()).optional(),
|
|
202
|
+
reasoning_effort: z.enum(["minimal", "low", "medium", "high"]).optional(),
|
|
203
|
+
verbosity: z.enum(["low", "medium", "high"]).optional(),
|
|
204
|
+
top_k: z.number().optional(),
|
|
205
|
+
stop_sequences: z.array(z.string()).optional(),
|
|
206
|
+
max_tokens_to_sample: z.number().optional(),
|
|
207
|
+
maxOutputTokens: z.number().optional(),
|
|
208
|
+
topP: z.number().optional(),
|
|
209
|
+
topK: z.number().optional(),
|
|
210
|
+
use_cache: z.boolean().optional()
|
|
211
|
+
});
|
|
212
|
+
var ApiKey = z.object({
|
|
213
|
+
id: z.string().uuid(),
|
|
214
|
+
created: z.union([z.string(), z.null()]).optional(),
|
|
215
|
+
name: z.string(),
|
|
216
|
+
preview_name: z.string(),
|
|
217
|
+
user_id: z.union([z.string(), z.null()]).optional(),
|
|
218
|
+
user_email: z.union([z.string(), z.null()]).optional(),
|
|
219
|
+
user_given_name: z.union([z.string(), z.null()]).optional(),
|
|
220
|
+
user_family_name: z.union([z.string(), z.null()]).optional(),
|
|
221
|
+
org_id: z.union([z.string(), z.null()]).optional()
|
|
222
|
+
});
|
|
223
|
+
var AsyncScoringState = z.union([
|
|
224
|
+
z.object({
|
|
225
|
+
status: z.literal("enabled"),
|
|
226
|
+
token: z.string(),
|
|
227
|
+
function_ids: z.array(z.unknown()).min(1),
|
|
228
|
+
skip_logging: z.union([z.boolean(), z.null()]).optional()
|
|
229
|
+
}),
|
|
230
|
+
z.object({ status: z.literal("disabled") }),
|
|
231
|
+
z.null(),
|
|
232
|
+
z.null()
|
|
233
|
+
]);
|
|
234
|
+
var AsyncScoringControl = z.union([
|
|
235
|
+
z.object({ kind: z.literal("score_update"), token: z.string() }),
|
|
236
|
+
z.object({ kind: z.literal("state_override"), state: AsyncScoringState }),
|
|
237
|
+
z.object({ kind: z.literal("state_force_reselect") }),
|
|
238
|
+
z.object({ kind: z.literal("state_enabled_force_rescore") })
|
|
239
|
+
]);
|
|
240
|
+
var BraintrustAttachmentReference = z.object({
|
|
241
|
+
type: z.literal("braintrust_attachment"),
|
|
242
|
+
filename: z.string().min(1),
|
|
243
|
+
content_type: z.string().min(1),
|
|
244
|
+
key: z.string().min(1)
|
|
245
|
+
});
|
|
246
|
+
var ExternalAttachmentReference = z.object({
|
|
247
|
+
type: z.literal("external_attachment"),
|
|
248
|
+
filename: z.string().min(1),
|
|
249
|
+
content_type: z.string().min(1),
|
|
250
|
+
url: z.string().min(1)
|
|
251
|
+
});
|
|
252
|
+
var AttachmentReference = z.discriminatedUnion("type", [
|
|
253
|
+
BraintrustAttachmentReference,
|
|
254
|
+
ExternalAttachmentReference
|
|
255
|
+
]);
|
|
256
|
+
var UploadStatus = z.enum(["uploading", "done", "error"]);
|
|
257
|
+
var AttachmentStatus = z.object({
|
|
258
|
+
upload_status: UploadStatus,
|
|
259
|
+
error_message: z.string().optional()
|
|
260
|
+
});
|
|
261
|
+
var BraintrustModelParams = z.object({ use_cache: z.boolean() }).partial();
|
|
262
|
+
var CallEvent = z.union([
|
|
263
|
+
z.object({
|
|
264
|
+
id: z.string().optional(),
|
|
265
|
+
data: z.string(),
|
|
266
|
+
event: z.literal("text_delta")
|
|
267
|
+
}),
|
|
268
|
+
z.object({
|
|
269
|
+
id: z.string().optional(),
|
|
270
|
+
data: z.string(),
|
|
271
|
+
event: z.literal("reasoning_delta")
|
|
272
|
+
}),
|
|
273
|
+
z.object({
|
|
274
|
+
id: z.string().optional(),
|
|
275
|
+
data: z.string(),
|
|
276
|
+
event: z.literal("json_delta")
|
|
277
|
+
}),
|
|
278
|
+
z.object({
|
|
279
|
+
id: z.string().optional(),
|
|
280
|
+
data: z.string(),
|
|
281
|
+
event: z.literal("progress")
|
|
282
|
+
}),
|
|
283
|
+
z.object({
|
|
284
|
+
id: z.string().optional(),
|
|
285
|
+
data: z.string(),
|
|
286
|
+
event: z.literal("error")
|
|
287
|
+
}),
|
|
288
|
+
z.object({
|
|
289
|
+
id: z.string().optional(),
|
|
290
|
+
data: z.string(),
|
|
291
|
+
event: z.literal("console")
|
|
292
|
+
}),
|
|
293
|
+
z.object({
|
|
294
|
+
id: z.string().optional(),
|
|
295
|
+
event: z.literal("start"),
|
|
296
|
+
data: z.literal("")
|
|
297
|
+
}),
|
|
298
|
+
z.object({
|
|
299
|
+
id: z.string().optional(),
|
|
300
|
+
event: z.literal("done"),
|
|
301
|
+
data: z.literal("")
|
|
302
|
+
})
|
|
303
|
+
]);
|
|
304
|
+
var ChatCompletionContentPartTextWithTitle = z.object({
|
|
305
|
+
text: z.string().default(""),
|
|
306
|
+
type: z.literal("text"),
|
|
307
|
+
cache_control: z.object({ type: z.literal("ephemeral") }).optional()
|
|
308
|
+
});
|
|
309
|
+
var ChatCompletionContentPartImageWithTitle = z.object({
|
|
310
|
+
image_url: z.object({
|
|
311
|
+
url: z.string(),
|
|
312
|
+
detail: z.union([z.literal("auto"), z.literal("low"), z.literal("high")]).optional()
|
|
313
|
+
}),
|
|
314
|
+
type: z.literal("image_url")
|
|
315
|
+
});
|
|
316
|
+
var ChatCompletionContentPart = z.union([
|
|
317
|
+
ChatCompletionContentPartTextWithTitle,
|
|
318
|
+
ChatCompletionContentPartImageWithTitle
|
|
319
|
+
]);
|
|
320
|
+
var ChatCompletionContentPartText = z.object({
|
|
321
|
+
text: z.string().default(""),
|
|
322
|
+
type: z.literal("text"),
|
|
323
|
+
cache_control: z.object({ type: z.literal("ephemeral") }).optional()
|
|
324
|
+
});
|
|
325
|
+
var ChatCompletionMessageToolCall = z.object({
|
|
326
|
+
id: z.string(),
|
|
327
|
+
function: z.object({ arguments: z.string(), name: z.string() }),
|
|
328
|
+
type: z.literal("function")
|
|
329
|
+
});
|
|
330
|
+
var ChatCompletionMessageReasoning = z.object({ id: z.string(), content: z.string() }).partial();
|
|
331
|
+
var ChatCompletionMessageParam = z.union([
|
|
332
|
+
z.object({
|
|
333
|
+
content: z.union([z.string(), z.array(ChatCompletionContentPartText)]),
|
|
334
|
+
role: z.literal("system"),
|
|
335
|
+
name: z.string().optional()
|
|
336
|
+
}),
|
|
337
|
+
z.object({
|
|
338
|
+
content: z.union([z.string(), z.array(ChatCompletionContentPart)]),
|
|
339
|
+
role: z.literal("user"),
|
|
340
|
+
name: z.string().optional()
|
|
341
|
+
}),
|
|
342
|
+
z.object({
|
|
343
|
+
role: z.literal("assistant"),
|
|
344
|
+
content: z.union([z.string(), z.array(ChatCompletionContentPartText), z.null()]).optional(),
|
|
345
|
+
function_call: z.object({ arguments: z.string(), name: z.string() }).optional(),
|
|
346
|
+
name: z.string().optional(),
|
|
347
|
+
tool_calls: z.array(ChatCompletionMessageToolCall).optional(),
|
|
348
|
+
reasoning: z.array(ChatCompletionMessageReasoning).optional()
|
|
349
|
+
}),
|
|
350
|
+
z.object({
|
|
351
|
+
content: z.union([z.string(), z.array(ChatCompletionContentPartText)]),
|
|
352
|
+
role: z.literal("tool"),
|
|
353
|
+
tool_call_id: z.string().default("")
|
|
354
|
+
}),
|
|
355
|
+
z.object({
|
|
356
|
+
content: z.union([z.string(), z.null()]),
|
|
357
|
+
name: z.string(),
|
|
358
|
+
role: z.literal("function")
|
|
359
|
+
}),
|
|
360
|
+
z.object({
|
|
361
|
+
content: z.union([z.string(), z.array(ChatCompletionContentPartText)]),
|
|
362
|
+
role: z.literal("developer"),
|
|
363
|
+
name: z.string().optional()
|
|
364
|
+
}),
|
|
365
|
+
z.object({
|
|
366
|
+
role: z.literal("model"),
|
|
367
|
+
content: z.union([z.string(), z.null()]).optional()
|
|
368
|
+
})
|
|
369
|
+
]);
|
|
370
|
+
var ChatCompletionOpenAIMessageParam = z.union([
|
|
371
|
+
z.object({
|
|
372
|
+
content: z.union([z.string(), z.array(ChatCompletionContentPartText)]),
|
|
373
|
+
role: z.literal("system"),
|
|
374
|
+
name: z.string().optional()
|
|
375
|
+
}),
|
|
376
|
+
z.object({
|
|
377
|
+
content: z.union([z.string(), z.array(ChatCompletionContentPart)]),
|
|
378
|
+
role: z.literal("user"),
|
|
379
|
+
name: z.string().optional()
|
|
380
|
+
}),
|
|
381
|
+
z.object({
|
|
382
|
+
role: z.literal("assistant"),
|
|
383
|
+
content: z.union([z.string(), z.array(ChatCompletionContentPartText), z.null()]).optional(),
|
|
384
|
+
function_call: z.object({ arguments: z.string(), name: z.string() }).optional(),
|
|
385
|
+
name: z.string().optional(),
|
|
386
|
+
tool_calls: z.array(ChatCompletionMessageToolCall).optional(),
|
|
387
|
+
reasoning: z.array(ChatCompletionMessageReasoning).optional()
|
|
388
|
+
}),
|
|
389
|
+
z.object({
|
|
390
|
+
content: z.union([z.string(), z.array(ChatCompletionContentPartText)]),
|
|
391
|
+
role: z.literal("tool"),
|
|
392
|
+
tool_call_id: z.string().default("")
|
|
393
|
+
}),
|
|
394
|
+
z.object({
|
|
395
|
+
content: z.union([z.string(), z.null()]),
|
|
396
|
+
name: z.string(),
|
|
397
|
+
role: z.literal("function")
|
|
398
|
+
}),
|
|
399
|
+
z.object({
|
|
400
|
+
content: z.union([z.string(), z.array(ChatCompletionContentPartText)]),
|
|
401
|
+
role: z.literal("developer"),
|
|
402
|
+
name: z.string().optional()
|
|
403
|
+
})
|
|
404
|
+
]);
|
|
405
|
+
var ChatCompletionTool = z.object({
|
|
406
|
+
function: z.object({
|
|
407
|
+
name: z.string(),
|
|
408
|
+
description: z.string().optional(),
|
|
409
|
+
parameters: z.object({}).partial().passthrough().optional()
|
|
410
|
+
}),
|
|
411
|
+
type: z.literal("function")
|
|
412
|
+
});
|
|
413
|
+
var CodeBundle = z.object({
|
|
414
|
+
runtime_context: z.object({
|
|
415
|
+
runtime: z.enum(["node", "python"]),
|
|
416
|
+
version: z.string()
|
|
417
|
+
}),
|
|
418
|
+
location: z.union([
|
|
419
|
+
z.object({
|
|
420
|
+
type: z.literal("experiment"),
|
|
421
|
+
eval_name: z.string(),
|
|
422
|
+
position: z.union([
|
|
423
|
+
z.object({ type: z.literal("task") }),
|
|
424
|
+
z.object({ type: z.literal("scorer"), index: z.number().int().gte(0) })
|
|
425
|
+
])
|
|
426
|
+
}),
|
|
427
|
+
z.object({ type: z.literal("function"), index: z.number().int().gte(0) })
|
|
428
|
+
]),
|
|
429
|
+
bundle_id: z.string(),
|
|
430
|
+
preview: z.union([z.string(), z.null()]).optional()
|
|
431
|
+
});
|
|
432
|
+
var Dataset = z.object({
|
|
433
|
+
id: z.string().uuid(),
|
|
434
|
+
project_id: z.string().uuid(),
|
|
435
|
+
name: z.string(),
|
|
436
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
437
|
+
created: z.union([z.string(), z.null()]).optional(),
|
|
438
|
+
deleted_at: z.union([z.string(), z.null()]).optional(),
|
|
439
|
+
user_id: z.union([z.string(), z.null()]).optional(),
|
|
440
|
+
metadata: z.union([z.object({}).partial().passthrough(), z.null()]).optional()
|
|
441
|
+
});
|
|
442
|
+
var ObjectReferenceNullish = z.union([
|
|
443
|
+
z.object({
|
|
444
|
+
object_type: z.enum([
|
|
445
|
+
"project_logs",
|
|
446
|
+
"experiment",
|
|
447
|
+
"dataset",
|
|
448
|
+
"prompt",
|
|
449
|
+
"function",
|
|
450
|
+
"prompt_session"
|
|
451
|
+
]),
|
|
452
|
+
object_id: z.string().uuid(),
|
|
453
|
+
id: z.string(),
|
|
454
|
+
_xact_id: z.union([z.string(), z.null()]).optional(),
|
|
455
|
+
created: z.union([z.string(), z.null()]).optional()
|
|
456
|
+
}),
|
|
457
|
+
z.null()
|
|
458
|
+
]);
|
|
459
|
+
var DatasetEvent = z.object({
|
|
460
|
+
id: z.string(),
|
|
461
|
+
_xact_id: z.string(),
|
|
462
|
+
created: z.string().datetime({ offset: true }),
|
|
463
|
+
_pagination_key: z.union([z.string(), z.null()]).optional(),
|
|
464
|
+
project_id: z.string().uuid(),
|
|
465
|
+
dataset_id: z.string().uuid(),
|
|
466
|
+
input: z.unknown().optional(),
|
|
467
|
+
expected: z.unknown().optional(),
|
|
468
|
+
metadata: z.union([
|
|
469
|
+
z.object({ model: z.union([z.string(), z.null()]) }).partial().passthrough(),
|
|
470
|
+
z.null()
|
|
471
|
+
]).optional(),
|
|
472
|
+
tags: z.union([z.array(z.string()), z.null()]).optional(),
|
|
473
|
+
span_id: z.string(),
|
|
474
|
+
root_span_id: z.string(),
|
|
475
|
+
is_root: z.union([z.boolean(), z.null()]).optional(),
|
|
476
|
+
origin: ObjectReferenceNullish.optional()
|
|
477
|
+
});
|
|
478
|
+
var EnvVar = z.object({
|
|
479
|
+
id: z.string().uuid(),
|
|
480
|
+
object_type: z.enum(["organization", "project", "function"]),
|
|
481
|
+
object_id: z.string().uuid(),
|
|
482
|
+
name: z.string(),
|
|
483
|
+
created: z.union([z.string(), z.null()]).optional(),
|
|
484
|
+
used: z.union([z.string(), z.null()]).optional()
|
|
485
|
+
});
|
|
486
|
+
var RepoInfo = z.union([
|
|
487
|
+
z.object({
|
|
488
|
+
commit: z.union([z.string(), z.null()]),
|
|
489
|
+
branch: z.union([z.string(), z.null()]),
|
|
490
|
+
tag: z.union([z.string(), z.null()]),
|
|
491
|
+
dirty: z.union([z.boolean(), z.null()]),
|
|
492
|
+
author_name: z.union([z.string(), z.null()]),
|
|
493
|
+
author_email: z.union([z.string(), z.null()]),
|
|
494
|
+
commit_message: z.union([z.string(), z.null()]),
|
|
495
|
+
commit_time: z.union([z.string(), z.null()]),
|
|
496
|
+
git_diff: z.union([z.string(), z.null()])
|
|
497
|
+
}).partial(),
|
|
498
|
+
z.null()
|
|
499
|
+
]);
|
|
500
|
+
var Experiment = z.object({
|
|
501
|
+
id: z.string().uuid(),
|
|
502
|
+
project_id: z.string().uuid(),
|
|
503
|
+
name: z.string(),
|
|
504
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
505
|
+
created: z.union([z.string(), z.null()]).optional(),
|
|
506
|
+
repo_info: RepoInfo.optional(),
|
|
507
|
+
commit: z.union([z.string(), z.null()]).optional(),
|
|
508
|
+
base_exp_id: z.union([z.string(), z.null()]).optional(),
|
|
509
|
+
deleted_at: z.union([z.string(), z.null()]).optional(),
|
|
510
|
+
dataset_id: z.union([z.string(), z.null()]).optional(),
|
|
511
|
+
dataset_version: z.union([z.string(), z.null()]).optional(),
|
|
512
|
+
public: z.boolean(),
|
|
513
|
+
user_id: z.union([z.string(), z.null()]).optional(),
|
|
514
|
+
metadata: z.union([z.object({}).partial().passthrough(), z.null()]).optional(),
|
|
515
|
+
tags: z.union([z.array(z.string()), z.null()]).optional()
|
|
516
|
+
});
|
|
517
|
+
var SpanType = z.union([
|
|
518
|
+
z.enum(["llm", "score", "function", "eval", "task", "tool"]),
|
|
519
|
+
z.null()
|
|
520
|
+
]);
|
|
521
|
+
var SpanAttributes = z.union([
|
|
522
|
+
z.object({ name: z.union([z.string(), z.null()]), type: SpanType }).partial().passthrough(),
|
|
523
|
+
z.null()
|
|
524
|
+
]);
|
|
525
|
+
var ExperimentEvent = z.object({
|
|
526
|
+
id: z.string(),
|
|
527
|
+
_xact_id: z.string(),
|
|
528
|
+
created: z.string().datetime({ offset: true }),
|
|
529
|
+
_pagination_key: z.union([z.string(), z.null()]).optional(),
|
|
530
|
+
project_id: z.string().uuid(),
|
|
531
|
+
experiment_id: z.string().uuid(),
|
|
532
|
+
input: z.unknown().optional(),
|
|
533
|
+
output: z.unknown().optional(),
|
|
534
|
+
expected: z.unknown().optional(),
|
|
535
|
+
error: z.unknown().optional(),
|
|
536
|
+
scores: z.union([z.record(z.union([z.number(), z.null()])), z.null()]).optional(),
|
|
537
|
+
metadata: z.union([
|
|
538
|
+
z.object({ model: z.union([z.string(), z.null()]) }).partial().passthrough(),
|
|
539
|
+
z.null()
|
|
540
|
+
]).optional(),
|
|
541
|
+
tags: z.union([z.array(z.string()), z.null()]).optional(),
|
|
542
|
+
metrics: z.union([z.record(z.number()), z.null()]).optional(),
|
|
543
|
+
context: z.union([
|
|
544
|
+
z.object({
|
|
545
|
+
caller_functionname: z.union([z.string(), z.null()]),
|
|
546
|
+
caller_filename: z.union([z.string(), z.null()]),
|
|
547
|
+
caller_lineno: z.union([z.number(), z.null()])
|
|
548
|
+
}).partial().passthrough(),
|
|
549
|
+
z.null()
|
|
550
|
+
]).optional(),
|
|
551
|
+
span_id: z.string(),
|
|
552
|
+
span_parents: z.union([z.array(z.string()), z.null()]).optional(),
|
|
553
|
+
root_span_id: z.string(),
|
|
554
|
+
span_attributes: SpanAttributes.optional(),
|
|
555
|
+
is_root: z.union([z.boolean(), z.null()]).optional(),
|
|
556
|
+
origin: ObjectReferenceNullish.optional()
|
|
557
|
+
});
|
|
558
|
+
var ExtendedSavedFunctionId = z.union([
|
|
559
|
+
z.object({ type: z.literal("function"), id: z.string() }),
|
|
560
|
+
z.object({ type: z.literal("global"), name: z.string() }),
|
|
561
|
+
z.object({
|
|
562
|
+
type: z.literal("slug"),
|
|
563
|
+
project_id: z.string(),
|
|
564
|
+
slug: z.string()
|
|
565
|
+
})
|
|
566
|
+
]);
|
|
567
|
+
var PromptBlockDataNullish = z.union([
|
|
568
|
+
z.object({ type: z.literal("completion"), content: z.string() }),
|
|
569
|
+
z.object({
|
|
570
|
+
type: z.literal("chat"),
|
|
571
|
+
messages: z.array(ChatCompletionMessageParam),
|
|
572
|
+
tools: z.string().optional()
|
|
573
|
+
}),
|
|
574
|
+
z.null()
|
|
575
|
+
]);
|
|
576
|
+
var ModelParams = z.union([
|
|
577
|
+
z.object({
|
|
578
|
+
use_cache: z.boolean(),
|
|
579
|
+
temperature: z.number(),
|
|
580
|
+
top_p: z.number(),
|
|
581
|
+
max_tokens: z.number(),
|
|
582
|
+
max_completion_tokens: z.number(),
|
|
583
|
+
frequency_penalty: z.number(),
|
|
584
|
+
presence_penalty: z.number(),
|
|
585
|
+
response_format: ResponseFormatNullish,
|
|
586
|
+
tool_choice: z.union([
|
|
587
|
+
z.literal("auto"),
|
|
588
|
+
z.literal("none"),
|
|
589
|
+
z.literal("required"),
|
|
590
|
+
z.object({
|
|
591
|
+
type: z.literal("function"),
|
|
592
|
+
function: z.object({ name: z.string() })
|
|
593
|
+
})
|
|
594
|
+
]),
|
|
595
|
+
function_call: z.union([
|
|
596
|
+
z.literal("auto"),
|
|
597
|
+
z.literal("none"),
|
|
598
|
+
z.object({ name: z.string() })
|
|
599
|
+
]),
|
|
600
|
+
n: z.number(),
|
|
601
|
+
stop: z.array(z.string()),
|
|
602
|
+
reasoning_effort: z.enum(["minimal", "low", "medium", "high"]),
|
|
603
|
+
verbosity: z.enum(["low", "medium", "high"])
|
|
604
|
+
}).partial().passthrough(),
|
|
605
|
+
z.object({
|
|
606
|
+
use_cache: z.boolean().optional(),
|
|
607
|
+
max_tokens: z.number(),
|
|
608
|
+
temperature: z.number(),
|
|
609
|
+
top_p: z.number().optional(),
|
|
610
|
+
top_k: z.number().optional(),
|
|
611
|
+
stop_sequences: z.array(z.string()).optional(),
|
|
612
|
+
max_tokens_to_sample: z.number().optional()
|
|
613
|
+
}).passthrough(),
|
|
614
|
+
z.object({
|
|
615
|
+
use_cache: z.boolean(),
|
|
616
|
+
temperature: z.number(),
|
|
617
|
+
maxOutputTokens: z.number(),
|
|
618
|
+
topP: z.number(),
|
|
619
|
+
topK: z.number()
|
|
620
|
+
}).partial().passthrough(),
|
|
621
|
+
z.object({
|
|
622
|
+
use_cache: z.boolean(),
|
|
623
|
+
temperature: z.number(),
|
|
624
|
+
topK: z.number()
|
|
625
|
+
}).partial().passthrough(),
|
|
626
|
+
z.object({ use_cache: z.boolean() }).partial().passthrough()
|
|
627
|
+
]);
|
|
628
|
+
var PromptOptionsNullish = z.union([
|
|
629
|
+
z.object({ model: z.string(), params: ModelParams, position: z.string() }).partial(),
|
|
630
|
+
z.null()
|
|
631
|
+
]);
|
|
632
|
+
var PromptParserNullish = z.union([
|
|
633
|
+
z.object({
|
|
634
|
+
type: z.literal("llm_classifier"),
|
|
635
|
+
use_cot: z.boolean(),
|
|
636
|
+
choice_scores: z.record(z.number().gte(0).lte(1))
|
|
637
|
+
}),
|
|
638
|
+
z.null()
|
|
639
|
+
]);
|
|
640
|
+
var SavedFunctionId = z.union([
|
|
641
|
+
z.object({ type: z.literal("function"), id: z.string() }),
|
|
642
|
+
z.object({ type: z.literal("global"), name: z.string() })
|
|
643
|
+
]);
|
|
644
|
+
var PromptDataNullish = z.union([
|
|
645
|
+
z.object({
|
|
646
|
+
prompt: PromptBlockDataNullish,
|
|
647
|
+
options: PromptOptionsNullish,
|
|
648
|
+
parser: PromptParserNullish,
|
|
649
|
+
tool_functions: z.union([z.array(SavedFunctionId), z.null()]),
|
|
650
|
+
origin: z.union([
|
|
651
|
+
z.object({
|
|
652
|
+
prompt_id: z.string(),
|
|
653
|
+
project_id: z.string(),
|
|
654
|
+
prompt_version: z.string()
|
|
655
|
+
}).partial(),
|
|
656
|
+
z.null()
|
|
657
|
+
])
|
|
658
|
+
}).partial(),
|
|
659
|
+
z.null()
|
|
660
|
+
]);
|
|
661
|
+
var FunctionTypeEnumNullish = z.union([
|
|
662
|
+
z.enum(["llm", "scorer", "task", "tool"]),
|
|
663
|
+
z.null()
|
|
664
|
+
]);
|
|
665
|
+
var FunctionIdRef = z.object({}).partial().passthrough();
|
|
666
|
+
var PromptBlockData = z.union([
|
|
667
|
+
z.object({ type: z.literal("completion"), content: z.string() }),
|
|
668
|
+
z.object({
|
|
669
|
+
type: z.literal("chat"),
|
|
670
|
+
messages: z.array(ChatCompletionMessageParam),
|
|
671
|
+
tools: z.string().optional()
|
|
672
|
+
})
|
|
673
|
+
]);
|
|
674
|
+
var GraphNode = z.union([
|
|
675
|
+
z.object({
|
|
676
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
677
|
+
position: z.union([z.object({ x: z.number(), y: z.number() }), z.null()]).optional(),
|
|
678
|
+
type: z.literal("function"),
|
|
679
|
+
function: FunctionIdRef
|
|
680
|
+
}),
|
|
681
|
+
z.object({
|
|
682
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
683
|
+
position: z.union([z.object({ x: z.number(), y: z.number() }), z.null()]).optional(),
|
|
684
|
+
type: z.literal("input")
|
|
685
|
+
}),
|
|
686
|
+
z.object({
|
|
687
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
688
|
+
position: z.union([z.object({ x: z.number(), y: z.number() }), z.null()]).optional(),
|
|
689
|
+
type: z.literal("output")
|
|
690
|
+
}),
|
|
691
|
+
z.object({
|
|
692
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
693
|
+
position: z.union([z.object({ x: z.number(), y: z.number() }), z.null()]).optional(),
|
|
694
|
+
type: z.literal("literal"),
|
|
695
|
+
value: z.unknown().optional()
|
|
696
|
+
}),
|
|
697
|
+
z.object({
|
|
698
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
699
|
+
position: z.union([z.object({ x: z.number(), y: z.number() }), z.null()]).optional(),
|
|
700
|
+
type: z.literal("btql"),
|
|
701
|
+
expr: z.string()
|
|
702
|
+
}),
|
|
703
|
+
z.object({
|
|
704
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
705
|
+
position: z.union([z.object({ x: z.number(), y: z.number() }), z.null()]).optional(),
|
|
706
|
+
type: z.literal("gate"),
|
|
707
|
+
condition: z.union([z.string(), z.null()]).optional()
|
|
708
|
+
}),
|
|
709
|
+
z.object({
|
|
710
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
711
|
+
position: z.union([z.object({ x: z.number(), y: z.number() }), z.null()]).optional(),
|
|
712
|
+
type: z.literal("aggregator")
|
|
713
|
+
}),
|
|
714
|
+
z.object({
|
|
715
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
716
|
+
position: z.union([z.object({ x: z.number(), y: z.number() }), z.null()]).optional(),
|
|
717
|
+
type: z.literal("prompt_template"),
|
|
718
|
+
prompt: PromptBlockData
|
|
719
|
+
})
|
|
720
|
+
]);
|
|
721
|
+
var GraphEdge = z.object({
|
|
722
|
+
source: z.object({ node: z.string().max(1024), variable: z.string() }),
|
|
723
|
+
target: z.object({ node: z.string().max(1024), variable: z.string() }),
|
|
724
|
+
purpose: z.enum(["control", "data", "messages"])
|
|
725
|
+
});
|
|
726
|
+
var GraphData = z.object({
|
|
727
|
+
type: z.literal("graph"),
|
|
728
|
+
nodes: z.record(GraphNode),
|
|
729
|
+
edges: z.record(GraphEdge)
|
|
730
|
+
});
|
|
731
|
+
var FunctionData = z.union([
|
|
732
|
+
z.object({ type: z.literal("prompt") }),
|
|
733
|
+
z.object({
|
|
734
|
+
type: z.literal("code"),
|
|
735
|
+
data: z.union([
|
|
736
|
+
z.object({ type: z.literal("bundle") }).and(CodeBundle),
|
|
737
|
+
z.object({
|
|
738
|
+
type: z.literal("inline"),
|
|
739
|
+
runtime_context: z.object({
|
|
740
|
+
runtime: z.enum(["node", "python"]),
|
|
741
|
+
version: z.string()
|
|
742
|
+
}),
|
|
743
|
+
code: z.string()
|
|
744
|
+
})
|
|
745
|
+
])
|
|
746
|
+
}),
|
|
747
|
+
GraphData,
|
|
748
|
+
z.object({
|
|
749
|
+
type: z.literal("remote_eval"),
|
|
750
|
+
endpoint: z.string(),
|
|
751
|
+
eval_name: z.string(),
|
|
752
|
+
parameters: z.object({}).partial().passthrough()
|
|
753
|
+
}),
|
|
754
|
+
z.object({ type: z.literal("global"), name: z.string() })
|
|
755
|
+
]);
|
|
756
|
+
var Function = z.object({
|
|
757
|
+
id: z.string().uuid(),
|
|
758
|
+
_xact_id: z.string(),
|
|
759
|
+
project_id: z.string().uuid(),
|
|
760
|
+
log_id: z.literal("p"),
|
|
761
|
+
org_id: z.string().uuid(),
|
|
762
|
+
name: z.string(),
|
|
763
|
+
slug: z.string(),
|
|
764
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
765
|
+
created: z.union([z.string(), z.null()]).optional(),
|
|
766
|
+
prompt_data: PromptDataNullish.optional(),
|
|
767
|
+
tags: z.union([z.array(z.string()), z.null()]).optional(),
|
|
768
|
+
metadata: z.union([z.object({}).partial().passthrough(), z.null()]).optional(),
|
|
769
|
+
function_type: FunctionTypeEnumNullish.optional(),
|
|
770
|
+
function_data: FunctionData,
|
|
771
|
+
origin: z.union([
|
|
772
|
+
z.object({
|
|
773
|
+
object_type: AclObjectType.and(z.string()),
|
|
774
|
+
object_id: z.string().uuid(),
|
|
775
|
+
internal: z.union([z.boolean(), z.null()]).optional()
|
|
776
|
+
}),
|
|
777
|
+
z.null()
|
|
778
|
+
]).optional(),
|
|
779
|
+
function_schema: z.union([
|
|
780
|
+
z.object({ parameters: z.unknown(), returns: z.unknown() }).partial(),
|
|
781
|
+
z.null()
|
|
782
|
+
]).optional()
|
|
783
|
+
});
|
|
784
|
+
var FunctionFormat = z.enum(["llm", "code", "global", "graph"]);
|
|
785
|
+
var PromptData = z.object({
|
|
786
|
+
prompt: PromptBlockDataNullish,
|
|
787
|
+
options: PromptOptionsNullish,
|
|
788
|
+
parser: PromptParserNullish,
|
|
789
|
+
tool_functions: z.union([z.array(SavedFunctionId), z.null()]),
|
|
790
|
+
origin: z.union([
|
|
791
|
+
z.object({
|
|
792
|
+
prompt_id: z.string(),
|
|
793
|
+
project_id: z.string(),
|
|
794
|
+
prompt_version: z.string()
|
|
795
|
+
}).partial(),
|
|
796
|
+
z.null()
|
|
797
|
+
])
|
|
798
|
+
}).partial();
|
|
799
|
+
var FunctionTypeEnum = z.enum(["llm", "scorer", "task", "tool"]);
|
|
800
|
+
var FunctionId = z.union([
|
|
801
|
+
z.object({ function_id: z.string(), version: z.string().optional() }),
|
|
139
802
|
z.object({
|
|
140
|
-
|
|
141
|
-
|
|
803
|
+
project_name: z.string(),
|
|
804
|
+
slug: z.string(),
|
|
805
|
+
version: z.string().optional()
|
|
142
806
|
}),
|
|
807
|
+
z.object({ global_function: z.string() }),
|
|
143
808
|
z.object({
|
|
144
|
-
|
|
145
|
-
|
|
809
|
+
prompt_session_id: z.string(),
|
|
810
|
+
prompt_session_function_id: z.string(),
|
|
811
|
+
version: z.string().optional()
|
|
146
812
|
}),
|
|
147
813
|
z.object({
|
|
148
|
-
|
|
149
|
-
|
|
814
|
+
inline_context: z.object({
|
|
815
|
+
runtime: z.enum(["node", "python"]),
|
|
816
|
+
version: z.string()
|
|
817
|
+
}),
|
|
818
|
+
code: z.string(),
|
|
819
|
+
name: z.union([z.string(), z.null()]).optional()
|
|
150
820
|
}),
|
|
151
821
|
z.object({
|
|
152
|
-
|
|
153
|
-
|
|
822
|
+
inline_prompt: PromptData.optional(),
|
|
823
|
+
inline_function: z.object({}).partial().passthrough(),
|
|
824
|
+
function_type: FunctionTypeEnum.optional(),
|
|
825
|
+
name: z.union([z.string(), z.null()]).optional()
|
|
826
|
+
}),
|
|
827
|
+
z.object({
|
|
828
|
+
inline_prompt: PromptData,
|
|
829
|
+
function_type: FunctionTypeEnum.optional(),
|
|
830
|
+
name: z.union([z.string(), z.null()]).optional()
|
|
831
|
+
})
|
|
832
|
+
]);
|
|
833
|
+
var FunctionObjectType = z.enum([
|
|
834
|
+
"prompt",
|
|
835
|
+
"tool",
|
|
836
|
+
"scorer",
|
|
837
|
+
"task",
|
|
838
|
+
"agent"
|
|
839
|
+
]);
|
|
840
|
+
var FunctionOutputType = z.enum(["completion", "score", "any"]);
|
|
841
|
+
var GitMetadataSettings = z.object({
|
|
842
|
+
collect: z.enum(["all", "none", "some"]),
|
|
843
|
+
fields: z.array(
|
|
844
|
+
z.enum([
|
|
845
|
+
"commit",
|
|
846
|
+
"branch",
|
|
847
|
+
"tag",
|
|
848
|
+
"dirty",
|
|
849
|
+
"author_name",
|
|
850
|
+
"author_email",
|
|
851
|
+
"commit_message",
|
|
852
|
+
"commit_time",
|
|
853
|
+
"git_diff"
|
|
854
|
+
])
|
|
855
|
+
).optional()
|
|
856
|
+
});
|
|
857
|
+
var Group = z.object({
|
|
858
|
+
id: z.string().uuid(),
|
|
859
|
+
org_id: z.string().uuid(),
|
|
860
|
+
user_id: z.union([z.string(), z.null()]).optional(),
|
|
861
|
+
created: z.union([z.string(), z.null()]).optional(),
|
|
862
|
+
name: z.string(),
|
|
863
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
864
|
+
deleted_at: z.union([z.string(), z.null()]).optional(),
|
|
865
|
+
member_users: z.union([z.array(z.string().uuid()), z.null()]).optional(),
|
|
866
|
+
member_groups: z.union([z.array(z.string().uuid()), z.null()]).optional()
|
|
867
|
+
});
|
|
868
|
+
var IfExists = z.enum(["error", "ignore", "replace"]);
|
|
869
|
+
var InvokeParent = z.union([
|
|
870
|
+
z.object({
|
|
871
|
+
object_type: z.enum(["project_logs", "experiment", "playground_logs"]),
|
|
872
|
+
object_id: z.string(),
|
|
873
|
+
row_ids: z.union([
|
|
874
|
+
z.object({
|
|
875
|
+
id: z.string(),
|
|
876
|
+
span_id: z.string(),
|
|
877
|
+
root_span_id: z.string()
|
|
878
|
+
}),
|
|
879
|
+
z.null()
|
|
880
|
+
]).optional(),
|
|
881
|
+
propagated_event: z.union([z.object({}).partial().passthrough(), z.null()]).optional()
|
|
154
882
|
}),
|
|
883
|
+
z.string()
|
|
884
|
+
]);
|
|
885
|
+
var StreamingMode = z.union([z.enum(["auto", "parallel"]), z.null()]);
|
|
886
|
+
var InvokeFunction = FunctionId.and(
|
|
887
|
+
z.object({
|
|
888
|
+
input: z.unknown(),
|
|
889
|
+
expected: z.unknown(),
|
|
890
|
+
metadata: z.union([z.object({}).partial().passthrough(), z.null()]),
|
|
891
|
+
tags: z.union([z.array(z.string()), z.null()]),
|
|
892
|
+
messages: z.array(ChatCompletionMessageParam),
|
|
893
|
+
parent: InvokeParent,
|
|
894
|
+
stream: z.union([z.boolean(), z.null()]),
|
|
895
|
+
mode: StreamingMode,
|
|
896
|
+
strict: z.union([z.boolean(), z.null()])
|
|
897
|
+
}).partial()
|
|
898
|
+
);
|
|
899
|
+
var MessageRole = z.enum([
|
|
900
|
+
"system",
|
|
901
|
+
"user",
|
|
902
|
+
"assistant",
|
|
903
|
+
"function",
|
|
904
|
+
"tool",
|
|
905
|
+
"model",
|
|
906
|
+
"developer"
|
|
907
|
+
]);
|
|
908
|
+
var ObjectReference = z.object({
|
|
909
|
+
object_type: z.enum([
|
|
910
|
+
"project_logs",
|
|
911
|
+
"experiment",
|
|
912
|
+
"dataset",
|
|
913
|
+
"prompt",
|
|
914
|
+
"function",
|
|
915
|
+
"prompt_session"
|
|
916
|
+
]),
|
|
917
|
+
object_id: z.string().uuid(),
|
|
918
|
+
id: z.string(),
|
|
919
|
+
_xact_id: z.union([z.string(), z.null()]).optional(),
|
|
920
|
+
created: z.union([z.string(), z.null()]).optional()
|
|
921
|
+
});
|
|
922
|
+
var OnlineScoreConfig = z.union([
|
|
155
923
|
z.object({
|
|
156
|
-
|
|
157
|
-
|
|
924
|
+
sampling_rate: z.number().gte(0).lte(1),
|
|
925
|
+
scorers: z.array(SavedFunctionId),
|
|
926
|
+
btql_filter: z.union([z.string(), z.null()]).optional(),
|
|
927
|
+
apply_to_root_span: z.union([z.boolean(), z.null()]).optional(),
|
|
928
|
+
apply_to_span_names: z.union([z.array(z.string()), z.null()]).optional(),
|
|
929
|
+
skip_logging: z.union([z.boolean(), z.null()]).optional()
|
|
158
930
|
}),
|
|
931
|
+
z.null()
|
|
932
|
+
]);
|
|
933
|
+
var Organization = z.object({
|
|
934
|
+
id: z.string().uuid(),
|
|
935
|
+
name: z.string(),
|
|
936
|
+
api_url: z.union([z.string(), z.null()]).optional(),
|
|
937
|
+
is_universal_api: z.union([z.boolean(), z.null()]).optional(),
|
|
938
|
+
proxy_url: z.union([z.string(), z.null()]).optional(),
|
|
939
|
+
realtime_url: z.union([z.string(), z.null()]).optional(),
|
|
940
|
+
created: z.union([z.string(), z.null()]).optional()
|
|
941
|
+
});
|
|
942
|
+
var ProjectSettings = z.union([
|
|
943
|
+
z.object({
|
|
944
|
+
comparison_key: z.union([z.string(), z.null()]),
|
|
945
|
+
baseline_experiment_id: z.union([z.string(), z.null()]),
|
|
946
|
+
spanFieldOrder: z.union([
|
|
947
|
+
z.array(
|
|
948
|
+
z.object({
|
|
949
|
+
object_type: z.string(),
|
|
950
|
+
column_id: z.string(),
|
|
951
|
+
position: z.string(),
|
|
952
|
+
layout: z.union([z.literal("full"), z.literal("two_column"), z.null()]).optional()
|
|
953
|
+
})
|
|
954
|
+
),
|
|
955
|
+
z.null()
|
|
956
|
+
]),
|
|
957
|
+
remote_eval_sources: z.union([
|
|
958
|
+
z.array(
|
|
959
|
+
z.object({
|
|
960
|
+
url: z.string(),
|
|
961
|
+
name: z.string(),
|
|
962
|
+
description: z.union([z.string(), z.null()]).optional()
|
|
963
|
+
})
|
|
964
|
+
),
|
|
965
|
+
z.null()
|
|
966
|
+
])
|
|
967
|
+
}).partial(),
|
|
968
|
+
z.null()
|
|
969
|
+
]);
|
|
970
|
+
var Project = z.object({
|
|
971
|
+
id: z.string().uuid(),
|
|
972
|
+
org_id: z.string().uuid(),
|
|
973
|
+
name: z.string(),
|
|
974
|
+
created: z.union([z.string(), z.null()]).optional(),
|
|
975
|
+
deleted_at: z.union([z.string(), z.null()]).optional(),
|
|
976
|
+
user_id: z.union([z.string(), z.null()]).optional(),
|
|
977
|
+
settings: ProjectSettings.optional()
|
|
978
|
+
});
|
|
979
|
+
var RetentionObjectType = z.enum([
|
|
980
|
+
"project_logs",
|
|
981
|
+
"experiment",
|
|
982
|
+
"dataset"
|
|
983
|
+
]);
|
|
984
|
+
var ProjectAutomation = z.object({
|
|
985
|
+
id: z.string().uuid(),
|
|
986
|
+
project_id: z.string().uuid(),
|
|
987
|
+
user_id: z.union([z.string(), z.null()]).optional(),
|
|
988
|
+
created: z.union([z.string(), z.null()]).optional(),
|
|
989
|
+
name: z.string(),
|
|
990
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
991
|
+
config: z.union([
|
|
992
|
+
z.object({
|
|
993
|
+
event_type: z.literal("logs"),
|
|
994
|
+
btql_filter: z.string(),
|
|
995
|
+
interval_seconds: z.number().gte(1).lte(2592e3),
|
|
996
|
+
action: z.object({ type: z.literal("webhook"), url: z.string() })
|
|
997
|
+
}),
|
|
998
|
+
z.object({
|
|
999
|
+
event_type: z.literal("btql_export"),
|
|
1000
|
+
export_definition: z.union([
|
|
1001
|
+
z.object({ type: z.literal("log_traces") }),
|
|
1002
|
+
z.object({ type: z.literal("log_spans") }),
|
|
1003
|
+
z.object({ type: z.literal("btql_query"), btql_query: z.string() })
|
|
1004
|
+
]),
|
|
1005
|
+
export_path: z.string(),
|
|
1006
|
+
format: z.enum(["jsonl", "parquet"]),
|
|
1007
|
+
interval_seconds: z.number().gte(1).lte(2592e3),
|
|
1008
|
+
credentials: z.object({
|
|
1009
|
+
type: z.literal("aws_iam"),
|
|
1010
|
+
role_arn: z.string(),
|
|
1011
|
+
external_id: z.string()
|
|
1012
|
+
}),
|
|
1013
|
+
batch_size: z.union([z.number(), z.null()]).optional()
|
|
1014
|
+
}),
|
|
1015
|
+
z.object({
|
|
1016
|
+
event_type: z.literal("retention"),
|
|
1017
|
+
object_type: RetentionObjectType,
|
|
1018
|
+
retention_days: z.number().gte(0)
|
|
1019
|
+
})
|
|
1020
|
+
])
|
|
1021
|
+
});
|
|
1022
|
+
var ProjectLogsEvent = z.object({
|
|
1023
|
+
id: z.string(),
|
|
1024
|
+
_xact_id: z.string(),
|
|
1025
|
+
_pagination_key: z.union([z.string(), z.null()]).optional(),
|
|
1026
|
+
created: z.string().datetime({ offset: true }),
|
|
1027
|
+
org_id: z.string().uuid(),
|
|
1028
|
+
project_id: z.string().uuid(),
|
|
1029
|
+
log_id: z.literal("g"),
|
|
1030
|
+
input: z.unknown().optional(),
|
|
1031
|
+
output: z.unknown().optional(),
|
|
1032
|
+
expected: z.unknown().optional(),
|
|
1033
|
+
error: z.unknown().optional(),
|
|
1034
|
+
scores: z.union([z.record(z.union([z.number(), z.null()])), z.null()]).optional(),
|
|
1035
|
+
metadata: z.union([
|
|
1036
|
+
z.object({ model: z.union([z.string(), z.null()]) }).partial().passthrough(),
|
|
1037
|
+
z.null()
|
|
1038
|
+
]).optional(),
|
|
1039
|
+
tags: z.union([z.array(z.string()), z.null()]).optional(),
|
|
1040
|
+
metrics: z.union([z.record(z.number()), z.null()]).optional(),
|
|
1041
|
+
context: z.union([
|
|
1042
|
+
z.object({
|
|
1043
|
+
caller_functionname: z.union([z.string(), z.null()]),
|
|
1044
|
+
caller_filename: z.union([z.string(), z.null()]),
|
|
1045
|
+
caller_lineno: z.union([z.number(), z.null()])
|
|
1046
|
+
}).partial().passthrough(),
|
|
1047
|
+
z.null()
|
|
1048
|
+
]).optional(),
|
|
1049
|
+
span_id: z.string(),
|
|
1050
|
+
span_parents: z.union([z.array(z.string()), z.null()]).optional(),
|
|
1051
|
+
root_span_id: z.string(),
|
|
1052
|
+
is_root: z.union([z.boolean(), z.null()]).optional(),
|
|
1053
|
+
span_attributes: SpanAttributes.optional(),
|
|
1054
|
+
origin: ObjectReferenceNullish.optional()
|
|
1055
|
+
});
|
|
1056
|
+
var ProjectScoreType = z.enum([
|
|
1057
|
+
"slider",
|
|
1058
|
+
"categorical",
|
|
1059
|
+
"weighted",
|
|
1060
|
+
"minimum",
|
|
1061
|
+
"maximum",
|
|
1062
|
+
"online",
|
|
1063
|
+
"free-form"
|
|
1064
|
+
]);
|
|
1065
|
+
var ProjectScoreCategory = z.object({
|
|
1066
|
+
name: z.string(),
|
|
1067
|
+
value: z.number()
|
|
1068
|
+
});
|
|
1069
|
+
var ProjectScoreCategories = z.union([
|
|
1070
|
+
z.array(ProjectScoreCategory),
|
|
1071
|
+
z.record(z.number()),
|
|
1072
|
+
z.array(z.string()),
|
|
1073
|
+
z.null()
|
|
1074
|
+
]);
|
|
1075
|
+
var ProjectScoreConfig = z.union([
|
|
1076
|
+
z.object({
|
|
1077
|
+
multi_select: z.union([z.boolean(), z.null()]),
|
|
1078
|
+
destination: z.union([z.string(), z.null()]),
|
|
1079
|
+
online: OnlineScoreConfig
|
|
1080
|
+
}).partial(),
|
|
1081
|
+
z.null()
|
|
1082
|
+
]);
|
|
1083
|
+
var ProjectScore = z.object({
|
|
1084
|
+
id: z.string().uuid(),
|
|
1085
|
+
project_id: z.string().uuid(),
|
|
1086
|
+
user_id: z.string().uuid(),
|
|
1087
|
+
created: z.union([z.string(), z.null()]).optional(),
|
|
1088
|
+
name: z.string(),
|
|
1089
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
1090
|
+
score_type: ProjectScoreType,
|
|
1091
|
+
categories: ProjectScoreCategories.optional(),
|
|
1092
|
+
config: ProjectScoreConfig.optional(),
|
|
1093
|
+
position: z.union([z.string(), z.null()]).optional()
|
|
1094
|
+
});
|
|
1095
|
+
var ProjectTag = z.object({
|
|
1096
|
+
id: z.string().uuid(),
|
|
1097
|
+
project_id: z.string().uuid(),
|
|
1098
|
+
user_id: z.string().uuid(),
|
|
1099
|
+
created: z.union([z.string(), z.null()]).optional(),
|
|
1100
|
+
name: z.string(),
|
|
1101
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
1102
|
+
color: z.union([z.string(), z.null()]).optional(),
|
|
1103
|
+
position: z.union([z.string(), z.null()]).optional()
|
|
1104
|
+
});
|
|
1105
|
+
var Prompt = z.object({
|
|
1106
|
+
id: z.string().uuid(),
|
|
1107
|
+
_xact_id: z.string(),
|
|
1108
|
+
project_id: z.string().uuid(),
|
|
1109
|
+
log_id: z.literal("p"),
|
|
1110
|
+
org_id: z.string().uuid(),
|
|
1111
|
+
name: z.string(),
|
|
1112
|
+
slug: z.string(),
|
|
1113
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
1114
|
+
created: z.union([z.string(), z.null()]).optional(),
|
|
1115
|
+
prompt_data: PromptDataNullish.optional(),
|
|
1116
|
+
tags: z.union([z.array(z.string()), z.null()]).optional(),
|
|
1117
|
+
metadata: z.union([z.object({}).partial().passthrough(), z.null()]).optional(),
|
|
1118
|
+
function_type: FunctionTypeEnumNullish.optional()
|
|
1119
|
+
});
|
|
1120
|
+
var PromptOptions = z.object({ model: z.string(), params: ModelParams, position: z.string() }).partial();
|
|
1121
|
+
var PromptSessionEvent = z.object({
|
|
1122
|
+
id: z.string(),
|
|
1123
|
+
_xact_id: z.string(),
|
|
1124
|
+
created: z.string().datetime({ offset: true }),
|
|
1125
|
+
_pagination_key: z.union([z.string(), z.null()]).optional(),
|
|
1126
|
+
project_id: z.string().uuid(),
|
|
1127
|
+
prompt_session_id: z.string().uuid(),
|
|
1128
|
+
prompt_session_data: z.unknown().optional(),
|
|
1129
|
+
prompt_data: z.unknown().optional(),
|
|
1130
|
+
function_data: z.unknown().optional(),
|
|
1131
|
+
function_type: FunctionTypeEnumNullish.optional(),
|
|
1132
|
+
object_data: z.unknown().optional(),
|
|
1133
|
+
completion: z.unknown().optional(),
|
|
1134
|
+
tags: z.union([z.array(z.string()), z.null()]).optional()
|
|
1135
|
+
});
|
|
1136
|
+
var ResponseFormat = z.union([
|
|
1137
|
+
z.object({ type: z.literal("json_object") }),
|
|
159
1138
|
z.object({
|
|
160
|
-
type: z.literal("
|
|
161
|
-
|
|
1139
|
+
type: z.literal("json_schema"),
|
|
1140
|
+
json_schema: ResponseFormatJsonSchema
|
|
162
1141
|
}),
|
|
1142
|
+
z.object({ type: z.literal("text") })
|
|
1143
|
+
]);
|
|
1144
|
+
var Role = z.object({
|
|
1145
|
+
id: z.string().uuid(),
|
|
1146
|
+
org_id: z.union([z.string(), z.null()]).optional(),
|
|
1147
|
+
user_id: z.union([z.string(), z.null()]).optional(),
|
|
1148
|
+
created: z.union([z.string(), z.null()]).optional(),
|
|
1149
|
+
name: z.string(),
|
|
1150
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
1151
|
+
deleted_at: z.union([z.string(), z.null()]).optional(),
|
|
1152
|
+
member_permissions: z.union([
|
|
1153
|
+
z.array(
|
|
1154
|
+
z.object({
|
|
1155
|
+
permission: Permission,
|
|
1156
|
+
restrict_object_type: AclObjectType.optional()
|
|
1157
|
+
})
|
|
1158
|
+
),
|
|
1159
|
+
z.null()
|
|
1160
|
+
]).optional(),
|
|
1161
|
+
member_roles: z.union([z.array(z.string().uuid()), z.null()]).optional()
|
|
1162
|
+
});
|
|
1163
|
+
var RunEval = z.object({
|
|
1164
|
+
project_id: z.string(),
|
|
1165
|
+
data: z.union([
|
|
1166
|
+
z.object({
|
|
1167
|
+
dataset_id: z.string(),
|
|
1168
|
+
_internal_btql: z.union([z.object({}).partial().passthrough(), z.null()]).optional()
|
|
1169
|
+
}),
|
|
1170
|
+
z.object({
|
|
1171
|
+
project_name: z.string(),
|
|
1172
|
+
dataset_name: z.string(),
|
|
1173
|
+
_internal_btql: z.union([z.object({}).partial().passthrough(), z.null()]).optional()
|
|
1174
|
+
}),
|
|
1175
|
+
z.object({ data: z.array(z.unknown()) })
|
|
1176
|
+
]),
|
|
1177
|
+
task: FunctionId.and(z.unknown()),
|
|
1178
|
+
scores: z.array(FunctionId),
|
|
1179
|
+
experiment_name: z.string().optional(),
|
|
1180
|
+
metadata: z.object({}).partial().passthrough().optional(),
|
|
1181
|
+
parent: InvokeParent.and(z.unknown()).optional(),
|
|
1182
|
+
stream: z.boolean().optional(),
|
|
1183
|
+
trial_count: z.union([z.number(), z.null()]).optional(),
|
|
1184
|
+
is_public: z.union([z.boolean(), z.null()]).optional(),
|
|
1185
|
+
timeout: z.union([z.number(), z.null()]).optional(),
|
|
1186
|
+
max_concurrency: z.union([z.number(), z.null()]).optional().default(10),
|
|
1187
|
+
base_experiment_name: z.union([z.string(), z.null()]).optional(),
|
|
1188
|
+
base_experiment_id: z.union([z.string(), z.null()]).optional(),
|
|
1189
|
+
git_metadata_settings: GitMetadataSettings.and(
|
|
1190
|
+
z.union([z.object({}).partial(), z.null()])
|
|
1191
|
+
).optional(),
|
|
1192
|
+
repo_info: RepoInfo.and(z.unknown()).optional(),
|
|
1193
|
+
strict: z.union([z.boolean(), z.null()]).optional(),
|
|
1194
|
+
stop_token: z.union([z.string(), z.null()]).optional(),
|
|
1195
|
+
extra_messages: z.string().optional(),
|
|
1196
|
+
tags: z.array(z.string()).optional()
|
|
1197
|
+
});
|
|
1198
|
+
var ServiceToken = z.object({
|
|
1199
|
+
id: z.string().uuid(),
|
|
1200
|
+
created: z.union([z.string(), z.null()]).optional(),
|
|
1201
|
+
name: z.string(),
|
|
1202
|
+
preview_name: z.string(),
|
|
1203
|
+
service_account_id: z.union([z.string(), z.null()]).optional(),
|
|
1204
|
+
service_account_email: z.union([z.string(), z.null()]).optional(),
|
|
1205
|
+
service_account_name: z.union([z.string(), z.null()]).optional(),
|
|
1206
|
+
org_id: z.union([z.string(), z.null()]).optional()
|
|
1207
|
+
});
|
|
1208
|
+
var SpanIFrame = z.object({
|
|
1209
|
+
id: z.string().uuid(),
|
|
1210
|
+
project_id: z.string().uuid(),
|
|
1211
|
+
user_id: z.union([z.string(), z.null()]).optional(),
|
|
1212
|
+
created: z.union([z.string(), z.null()]).optional(),
|
|
1213
|
+
deleted_at: z.union([z.string(), z.null()]).optional(),
|
|
1214
|
+
name: z.string(),
|
|
1215
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
1216
|
+
url: z.string(),
|
|
1217
|
+
post_message: z.union([z.boolean(), z.null()]).optional()
|
|
1218
|
+
});
|
|
1219
|
+
var SSEConsoleEventData = z.object({
|
|
1220
|
+
stream: z.enum(["stderr", "stdout"]),
|
|
1221
|
+
message: z.string()
|
|
1222
|
+
});
|
|
1223
|
+
var SSEProgressEventData = z.object({
|
|
1224
|
+
id: z.string(),
|
|
1225
|
+
object_type: FunctionObjectType,
|
|
1226
|
+
origin: ObjectReferenceNullish.and(z.unknown()).optional(),
|
|
1227
|
+
format: FunctionFormat,
|
|
1228
|
+
output_type: FunctionOutputType,
|
|
1229
|
+
name: z.string(),
|
|
1230
|
+
event: z.enum([
|
|
1231
|
+
"reasoning_delta",
|
|
1232
|
+
"text_delta",
|
|
1233
|
+
"json_delta",
|
|
1234
|
+
"error",
|
|
1235
|
+
"console",
|
|
1236
|
+
"start",
|
|
1237
|
+
"done",
|
|
1238
|
+
"progress"
|
|
1239
|
+
]),
|
|
1240
|
+
data: z.string()
|
|
1241
|
+
});
|
|
1242
|
+
var ToolFunctionDefinition = z.object({
|
|
1243
|
+
type: z.literal("function"),
|
|
1244
|
+
function: z.object({
|
|
1245
|
+
name: z.string(),
|
|
1246
|
+
description: z.string().optional(),
|
|
1247
|
+
parameters: z.object({}).partial().passthrough().optional(),
|
|
1248
|
+
strict: z.union([z.boolean(), z.null()]).optional()
|
|
1249
|
+
})
|
|
1250
|
+
});
|
|
1251
|
+
var User = z.object({
|
|
1252
|
+
id: z.string().uuid(),
|
|
1253
|
+
given_name: z.union([z.string(), z.null()]).optional(),
|
|
1254
|
+
family_name: z.union([z.string(), z.null()]).optional(),
|
|
1255
|
+
email: z.union([z.string(), z.null()]).optional(),
|
|
1256
|
+
avatar_url: z.union([z.string(), z.null()]).optional(),
|
|
1257
|
+
created: z.union([z.string(), z.null()]).optional()
|
|
1258
|
+
});
|
|
1259
|
+
var ViewDataSearch = z.union([
|
|
163
1260
|
z.object({
|
|
164
|
-
|
|
165
|
-
|
|
1261
|
+
filter: z.union([z.array(z.unknown()), z.null()]),
|
|
1262
|
+
tag: z.union([z.array(z.unknown()), z.null()]),
|
|
1263
|
+
match: z.union([z.array(z.unknown()), z.null()]),
|
|
1264
|
+
sort: z.union([z.array(z.unknown()), z.null()])
|
|
1265
|
+
}).partial(),
|
|
1266
|
+
z.null()
|
|
1267
|
+
]);
|
|
1268
|
+
var ViewData = z.union([
|
|
1269
|
+
z.object({ search: ViewDataSearch }).partial(),
|
|
1270
|
+
z.null()
|
|
1271
|
+
]);
|
|
1272
|
+
var ViewOptions = z.union([
|
|
1273
|
+
z.object({
|
|
1274
|
+
viewType: z.literal("monitor"),
|
|
1275
|
+
options: z.object({
|
|
1276
|
+
spanType: z.union([z.enum(["range", "frame"]), z.null()]),
|
|
1277
|
+
rangeValue: z.union([z.string(), z.null()]),
|
|
1278
|
+
frameStart: z.union([z.string(), z.null()]),
|
|
1279
|
+
frameEnd: z.union([z.string(), z.null()]),
|
|
1280
|
+
tzUTC: z.union([z.boolean(), z.null()]),
|
|
1281
|
+
chartVisibility: z.union([z.record(z.boolean()), z.null()]),
|
|
1282
|
+
projectId: z.union([z.string(), z.null()]),
|
|
1283
|
+
type: z.union([z.enum(["project", "experiment"]), z.null()]),
|
|
1284
|
+
groupBy: z.union([z.string(), z.null()])
|
|
1285
|
+
}).partial()
|
|
166
1286
|
}),
|
|
167
1287
|
z.object({
|
|
168
|
-
|
|
169
|
-
|
|
1288
|
+
columnVisibility: z.union([z.record(z.boolean()), z.null()]),
|
|
1289
|
+
columnOrder: z.union([z.array(z.string()), z.null()]),
|
|
1290
|
+
columnSizing: z.union([z.record(z.number()), z.null()]),
|
|
1291
|
+
grouping: z.union([z.string(), z.null()]),
|
|
1292
|
+
rowHeight: z.union([z.string(), z.null()]),
|
|
1293
|
+
tallGroupRows: z.union([z.boolean(), z.null()]),
|
|
1294
|
+
layout: z.union([z.string(), z.null()]),
|
|
1295
|
+
chartHeight: z.union([z.number(), z.null()]),
|
|
1296
|
+
excludedMeasures: z.union([
|
|
1297
|
+
z.array(
|
|
1298
|
+
z.object({
|
|
1299
|
+
type: z.enum(["none", "score", "metric", "metadata"]),
|
|
1300
|
+
value: z.string()
|
|
1301
|
+
})
|
|
1302
|
+
),
|
|
1303
|
+
z.null()
|
|
1304
|
+
]),
|
|
1305
|
+
yMetric: z.union([
|
|
1306
|
+
z.object({
|
|
1307
|
+
type: z.enum(["none", "score", "metric", "metadata"]),
|
|
1308
|
+
value: z.string()
|
|
1309
|
+
}),
|
|
1310
|
+
z.null()
|
|
1311
|
+
]),
|
|
1312
|
+
xAxis: z.union([
|
|
1313
|
+
z.object({
|
|
1314
|
+
type: z.enum(["none", "score", "metric", "metadata"]),
|
|
1315
|
+
value: z.string()
|
|
1316
|
+
}),
|
|
1317
|
+
z.null()
|
|
1318
|
+
]),
|
|
1319
|
+
symbolGrouping: z.union([
|
|
1320
|
+
z.object({
|
|
1321
|
+
type: z.enum(["none", "score", "metric", "metadata"]),
|
|
1322
|
+
value: z.string()
|
|
1323
|
+
}),
|
|
1324
|
+
z.null()
|
|
1325
|
+
]),
|
|
1326
|
+
xAxisAggregation: z.union([z.string(), z.null()]),
|
|
1327
|
+
chartAnnotations: z.union([
|
|
1328
|
+
z.array(z.object({ id: z.string(), text: z.string() })),
|
|
1329
|
+
z.null()
|
|
1330
|
+
]),
|
|
1331
|
+
timeRangeFilter: z.union([
|
|
1332
|
+
z.string(),
|
|
1333
|
+
z.object({ from: z.string(), to: z.string() }),
|
|
1334
|
+
z.null()
|
|
1335
|
+
])
|
|
1336
|
+
}).partial(),
|
|
1337
|
+
z.null()
|
|
1338
|
+
]);
|
|
1339
|
+
var View = z.object({
|
|
1340
|
+
id: z.string().uuid(),
|
|
1341
|
+
object_type: AclObjectType.and(z.string()),
|
|
1342
|
+
object_id: z.string().uuid(),
|
|
1343
|
+
view_type: z.enum([
|
|
1344
|
+
"projects",
|
|
1345
|
+
"experiments",
|
|
1346
|
+
"experiment",
|
|
1347
|
+
"playgrounds",
|
|
1348
|
+
"playground",
|
|
1349
|
+
"datasets",
|
|
1350
|
+
"dataset",
|
|
1351
|
+
"prompts",
|
|
1352
|
+
"tools",
|
|
1353
|
+
"scorers",
|
|
1354
|
+
"logs",
|
|
1355
|
+
"agents",
|
|
1356
|
+
"monitor"
|
|
1357
|
+
]),
|
|
1358
|
+
name: z.string(),
|
|
1359
|
+
created: z.union([z.string(), z.null()]).optional(),
|
|
1360
|
+
view_data: ViewData.optional(),
|
|
1361
|
+
options: ViewOptions.optional(),
|
|
1362
|
+
user_id: z.union([z.string(), z.null()]).optional(),
|
|
1363
|
+
deleted_at: z.union([z.string(), z.null()]).optional()
|
|
1364
|
+
});
|
|
1365
|
+
|
|
1366
|
+
// src/logger.ts
|
|
1367
|
+
import { waitUntil } from "@vercel/functions";
|
|
1368
|
+
import Mustache2 from "mustache";
|
|
1369
|
+
import { z as z3, ZodError } from "zod";
|
|
1370
|
+
|
|
1371
|
+
// src/functions/stream.ts
|
|
1372
|
+
import {
|
|
1373
|
+
createParser
|
|
1374
|
+
} from "eventsource-parser";
|
|
1375
|
+
import { z as z2 } from "zod";
|
|
1376
|
+
var braintrustStreamChunkSchema = z2.union([
|
|
1377
|
+
z2.object({
|
|
1378
|
+
type: z2.literal("text_delta"),
|
|
1379
|
+
data: z2.string()
|
|
1380
|
+
}),
|
|
1381
|
+
z2.object({
|
|
1382
|
+
type: z2.literal("reasoning_delta"),
|
|
1383
|
+
data: z2.string()
|
|
1384
|
+
}),
|
|
1385
|
+
z2.object({
|
|
1386
|
+
type: z2.literal("json_delta"),
|
|
1387
|
+
data: z2.string()
|
|
1388
|
+
}),
|
|
1389
|
+
z2.object({
|
|
1390
|
+
type: z2.literal("error"),
|
|
1391
|
+
data: z2.string()
|
|
1392
|
+
}),
|
|
1393
|
+
z2.object({
|
|
1394
|
+
type: z2.literal("console"),
|
|
1395
|
+
data: SSEConsoleEventData
|
|
1396
|
+
}),
|
|
1397
|
+
z2.object({
|
|
1398
|
+
type: z2.literal("progress"),
|
|
1399
|
+
data: SSEProgressEventData
|
|
1400
|
+
}),
|
|
1401
|
+
z2.object({
|
|
1402
|
+
type: z2.literal("start"),
|
|
1403
|
+
data: z2.string()
|
|
1404
|
+
}),
|
|
1405
|
+
z2.object({
|
|
1406
|
+
type: z2.literal("done"),
|
|
1407
|
+
data: z2.string()
|
|
170
1408
|
})
|
|
171
1409
|
]);
|
|
172
1410
|
var BraintrustStream = class _BraintrustStream {
|
|
@@ -274,12 +1512,12 @@ var BraintrustStream = class _BraintrustStream {
|
|
|
274
1512
|
case "progress":
|
|
275
1513
|
return {
|
|
276
1514
|
type: "progress",
|
|
277
|
-
data:
|
|
1515
|
+
data: SSEProgressEventData.parse(JSON.parse(event.data))
|
|
278
1516
|
};
|
|
279
1517
|
case "console":
|
|
280
1518
|
return {
|
|
281
1519
|
type: "console",
|
|
282
|
-
data:
|
|
1520
|
+
data: SSEConsoleEventData.parse(JSON.parse(event.data))
|
|
283
1521
|
};
|
|
284
1522
|
case "start":
|
|
285
1523
|
return {
|
|
@@ -355,7 +1593,7 @@ function btStreamParser() {
|
|
|
355
1593
|
if (event.type === "reconnect-interval") {
|
|
356
1594
|
return;
|
|
357
1595
|
}
|
|
358
|
-
const parsed =
|
|
1596
|
+
const parsed = CallEvent.safeParse(event);
|
|
359
1597
|
if (!parsed.success) {
|
|
360
1598
|
throw new Error(`Failed to parse event: ${parsed.error}`);
|
|
361
1599
|
}
|
|
@@ -780,6 +2018,44 @@ function getMustacheVars(prompt) {
|
|
|
780
2018
|
}
|
|
781
2019
|
|
|
782
2020
|
// src/logger.ts
|
|
2021
|
+
import { prettifyXact } from "@braintrust/core";
|
|
2022
|
+
var BRAINTRUST_ATTACHMENT = BraintrustAttachmentReference.shape.type.value;
|
|
2023
|
+
var EXTERNAL_ATTACHMENT = ExternalAttachmentReference.shape.type.value;
|
|
2024
|
+
var BRAINTRUST_PARAMS = Object.keys(BraintrustModelParams.shape);
|
|
2025
|
+
var REDACTION_FIELDS = [
|
|
2026
|
+
"input",
|
|
2027
|
+
"output",
|
|
2028
|
+
"expected",
|
|
2029
|
+
"metadata",
|
|
2030
|
+
"context",
|
|
2031
|
+
"scores",
|
|
2032
|
+
"metrics"
|
|
2033
|
+
];
|
|
2034
|
+
var MaskingError = class {
|
|
2035
|
+
constructor(fieldName, errorType) {
|
|
2036
|
+
this.fieldName = fieldName;
|
|
2037
|
+
this.errorType = errorType;
|
|
2038
|
+
}
|
|
2039
|
+
get errorMsg() {
|
|
2040
|
+
return `ERROR: Failed to mask field '${this.fieldName}' - ${this.errorType}`;
|
|
2041
|
+
}
|
|
2042
|
+
};
|
|
2043
|
+
function applyMaskingToField(maskingFunction, data, fieldName) {
|
|
2044
|
+
try {
|
|
2045
|
+
return maskingFunction(data);
|
|
2046
|
+
} catch (error) {
|
|
2047
|
+
const errorType = error instanceof Error ? error.constructor.name : "Error";
|
|
2048
|
+
if (fieldName === "scores" || fieldName === "metrics") {
|
|
2049
|
+
return new MaskingError(fieldName, errorType);
|
|
2050
|
+
}
|
|
2051
|
+
if (fieldName === "metadata") {
|
|
2052
|
+
return {
|
|
2053
|
+
error: `ERROR: Failed to mask field '${fieldName}' - ${errorType}`
|
|
2054
|
+
};
|
|
2055
|
+
}
|
|
2056
|
+
return `ERROR: Failed to mask field '${fieldName}' - ${errorType}`;
|
|
2057
|
+
}
|
|
2058
|
+
}
|
|
783
2059
|
var NoopSpan = class {
|
|
784
2060
|
id;
|
|
785
2061
|
spanId;
|
|
@@ -830,15 +2106,15 @@ var NoopSpan = class {
|
|
|
830
2106
|
};
|
|
831
2107
|
var NOOP_SPAN = new NoopSpan();
|
|
832
2108
|
var NOOP_SPAN_PERMALINK = "https://braintrust.dev/noop-span";
|
|
833
|
-
var loginSchema =
|
|
834
|
-
appUrl:
|
|
835
|
-
appPublicUrl:
|
|
836
|
-
orgName:
|
|
837
|
-
apiUrl:
|
|
838
|
-
proxyUrl:
|
|
839
|
-
loginToken:
|
|
840
|
-
orgId:
|
|
841
|
-
gitMetadataSettings:
|
|
2109
|
+
var loginSchema = z3.strictObject({
|
|
2110
|
+
appUrl: z3.string(),
|
|
2111
|
+
appPublicUrl: z3.string(),
|
|
2112
|
+
orgName: z3.string(),
|
|
2113
|
+
apiUrl: z3.string(),
|
|
2114
|
+
proxyUrl: z3.string(),
|
|
2115
|
+
loginToken: z3.string(),
|
|
2116
|
+
orgId: z3.string().nullish(),
|
|
2117
|
+
gitMetadataSettings: GitMetadataSettings.nullish()
|
|
842
2118
|
});
|
|
843
2119
|
var stateNonce = 0;
|
|
844
2120
|
var BraintrustState = class _BraintrustState {
|
|
@@ -980,6 +2256,9 @@ var BraintrustState = class _BraintrustState {
|
|
|
980
2256
|
this._apiConn?.setFetch(fetch2);
|
|
981
2257
|
this._appConn?.setFetch(fetch2);
|
|
982
2258
|
}
|
|
2259
|
+
setMaskingFunction(maskingFunction) {
|
|
2260
|
+
this.bgLogger().setMaskingFunction(maskingFunction);
|
|
2261
|
+
}
|
|
983
2262
|
async login(loginParams) {
|
|
984
2263
|
if (this.apiUrl && !loginParams.forceLogin) {
|
|
985
2264
|
return;
|
|
@@ -1058,6 +2337,18 @@ function useTestBackgroundLogger() {
|
|
|
1058
2337
|
function clearTestBackgroundLogger() {
|
|
1059
2338
|
_internalGetGlobalState()?.setOverrideBgLogger(null);
|
|
1060
2339
|
}
|
|
2340
|
+
function initTestExperiment(experimentName, projectName) {
|
|
2341
|
+
setInitialTestState();
|
|
2342
|
+
const state = _internalGetGlobalState();
|
|
2343
|
+
const project = projectName ?? experimentName;
|
|
2344
|
+
const lazyMetadata = new LazyValue(
|
|
2345
|
+
async () => ({
|
|
2346
|
+
project: { id: project, name: project, fullInfo: {} },
|
|
2347
|
+
experiment: { id: experimentName, name: experimentName, fullInfo: {} }
|
|
2348
|
+
})
|
|
2349
|
+
);
|
|
2350
|
+
return new Experiment2(state, lazyMetadata);
|
|
2351
|
+
}
|
|
1061
2352
|
function _internalSetInitialState() {
|
|
1062
2353
|
if (_globalState) {
|
|
1063
2354
|
console.warn(
|
|
@@ -1299,9 +2590,9 @@ var Attachment = class extends BaseAttachment {
|
|
|
1299
2590
|
let signedUrl;
|
|
1300
2591
|
let headers;
|
|
1301
2592
|
try {
|
|
1302
|
-
({ signedUrl, headers } =
|
|
1303
|
-
signedUrl:
|
|
1304
|
-
headers:
|
|
2593
|
+
({ signedUrl, headers } = z3.object({
|
|
2594
|
+
signedUrl: z3.string().url(),
|
|
2595
|
+
headers: z3.record(z3.string())
|
|
1305
2596
|
}).parse(await metadataResponse.json()));
|
|
1306
2597
|
} catch (error) {
|
|
1307
2598
|
if (error instanceof ZodError) {
|
|
@@ -1361,6 +2652,7 @@ var Attachment = class extends BaseAttachment {
|
|
|
1361
2652
|
}
|
|
1362
2653
|
initData(data) {
|
|
1363
2654
|
if (typeof data === "string") {
|
|
2655
|
+
this.ensureFileReadable(data);
|
|
1364
2656
|
const readFile = isomorph_default.readFile;
|
|
1365
2657
|
if (!readFile) {
|
|
1366
2658
|
throw new Error(
|
|
@@ -1373,6 +2665,20 @@ with a Blob/ArrayBuffer, or run the program on Node.js.`
|
|
|
1373
2665
|
return new LazyValue(async () => new Blob([data]));
|
|
1374
2666
|
}
|
|
1375
2667
|
}
|
|
2668
|
+
ensureFileReadable(data) {
|
|
2669
|
+
const statSync = isomorph_default.statSync;
|
|
2670
|
+
if (!statSync) {
|
|
2671
|
+
throw new Error(
|
|
2672
|
+
`This platform does not support reading the filesystem. Construct the Attachment
|
|
2673
|
+
with a Blob/ArrayBuffer, or run the program on Node.js.`
|
|
2674
|
+
);
|
|
2675
|
+
}
|
|
2676
|
+
try {
|
|
2677
|
+
statSync(data);
|
|
2678
|
+
} catch (e) {
|
|
2679
|
+
console.warn(`Failed to read file: ${e}`);
|
|
2680
|
+
}
|
|
2681
|
+
}
|
|
1376
2682
|
};
|
|
1377
2683
|
var ExternalAttachment = class extends BaseAttachment {
|
|
1378
2684
|
/**
|
|
@@ -1441,9 +2747,9 @@ var ExternalAttachment = class extends BaseAttachment {
|
|
|
1441
2747
|
});
|
|
1442
2748
|
}
|
|
1443
2749
|
};
|
|
1444
|
-
var attachmentMetadataSchema =
|
|
1445
|
-
downloadUrl:
|
|
1446
|
-
status:
|
|
2750
|
+
var attachmentMetadataSchema = z3.object({
|
|
2751
|
+
downloadUrl: z3.string(),
|
|
2752
|
+
status: AttachmentStatus
|
|
1447
2753
|
});
|
|
1448
2754
|
var ReadonlyAttachment = class {
|
|
1449
2755
|
/**
|
|
@@ -1982,9 +3288,13 @@ function now() {
|
|
|
1982
3288
|
}
|
|
1983
3289
|
var TestBackgroundLogger = class {
|
|
1984
3290
|
items = [];
|
|
3291
|
+
maskingFunction = null;
|
|
1985
3292
|
log(items) {
|
|
1986
3293
|
this.items.push(items);
|
|
1987
3294
|
}
|
|
3295
|
+
setMaskingFunction(maskingFunction) {
|
|
3296
|
+
this.maskingFunction = maskingFunction;
|
|
3297
|
+
}
|
|
1988
3298
|
async flush() {
|
|
1989
3299
|
return Promise.resolve();
|
|
1990
3300
|
}
|
|
@@ -1998,7 +3308,34 @@ var TestBackgroundLogger = class {
|
|
|
1998
3308
|
}
|
|
1999
3309
|
}
|
|
2000
3310
|
const batch = mergeRowBatch(events);
|
|
2001
|
-
|
|
3311
|
+
let flatBatch = batch.flat();
|
|
3312
|
+
if (this.maskingFunction) {
|
|
3313
|
+
flatBatch = flatBatch.map((item) => {
|
|
3314
|
+
const maskedItem = { ...item };
|
|
3315
|
+
for (const field of REDACTION_FIELDS) {
|
|
3316
|
+
if (item[field] !== void 0) {
|
|
3317
|
+
const maskedValue = applyMaskingToField(
|
|
3318
|
+
this.maskingFunction,
|
|
3319
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3320
|
+
item[field],
|
|
3321
|
+
field
|
|
3322
|
+
);
|
|
3323
|
+
if (maskedValue instanceof MaskingError) {
|
|
3324
|
+
delete maskedItem[field];
|
|
3325
|
+
if (maskedItem.error) {
|
|
3326
|
+
maskedItem.error = `${maskedItem.error}; ${maskedValue.errorMsg}`;
|
|
3327
|
+
} else {
|
|
3328
|
+
maskedItem.error = maskedValue.errorMsg;
|
|
3329
|
+
}
|
|
3330
|
+
} else {
|
|
3331
|
+
maskedItem[field] = maskedValue;
|
|
3332
|
+
}
|
|
3333
|
+
}
|
|
3334
|
+
}
|
|
3335
|
+
return maskedItem;
|
|
3336
|
+
});
|
|
3337
|
+
}
|
|
3338
|
+
return flatBatch;
|
|
2002
3339
|
}
|
|
2003
3340
|
};
|
|
2004
3341
|
var BACKGROUND_LOGGER_BASE_SLEEP_TIME_S = 1;
|
|
@@ -2009,6 +3346,7 @@ var HTTPBackgroundLogger = class _HTTPBackgroundLogger {
|
|
|
2009
3346
|
activeFlushResolved = true;
|
|
2010
3347
|
activeFlushError = void 0;
|
|
2011
3348
|
onFlushError;
|
|
3349
|
+
maskingFunction = null;
|
|
2012
3350
|
syncFlush = false;
|
|
2013
3351
|
// 6 MB for the AWS lambda gateway (from our own testing).
|
|
2014
3352
|
maxRequestSize = 6 * 1024 * 1024;
|
|
@@ -2076,6 +3414,9 @@ var HTTPBackgroundLogger = class _HTTPBackgroundLogger {
|
|
|
2076
3414
|
}
|
|
2077
3415
|
this.onFlushError = opts.onFlushError;
|
|
2078
3416
|
}
|
|
3417
|
+
setMaskingFunction(maskingFunction) {
|
|
3418
|
+
this.maskingFunction = maskingFunction;
|
|
3419
|
+
}
|
|
2079
3420
|
log(items) {
|
|
2080
3421
|
if (this._disabled) {
|
|
2081
3422
|
return;
|
|
@@ -2172,7 +3513,36 @@ var HTTPBackgroundLogger = class _HTTPBackgroundLogger {
|
|
|
2172
3513
|
const items = await Promise.all(wrappedItems.map((x) => x.get()));
|
|
2173
3514
|
const attachments = [];
|
|
2174
3515
|
items.forEach((item) => extractAttachments(item, attachments));
|
|
2175
|
-
|
|
3516
|
+
let mergedItems = mergeRowBatch(items);
|
|
3517
|
+
if (this.maskingFunction) {
|
|
3518
|
+
mergedItems = mergedItems.map(
|
|
3519
|
+
(batch) => batch.map((item) => {
|
|
3520
|
+
const maskedItem = { ...item };
|
|
3521
|
+
for (const field of REDACTION_FIELDS) {
|
|
3522
|
+
if (item[field] !== void 0) {
|
|
3523
|
+
const maskedValue = applyMaskingToField(
|
|
3524
|
+
this.maskingFunction,
|
|
3525
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3526
|
+
item[field],
|
|
3527
|
+
field
|
|
3528
|
+
);
|
|
3529
|
+
if (maskedValue instanceof MaskingError) {
|
|
3530
|
+
delete maskedItem[field];
|
|
3531
|
+
if (maskedItem.error) {
|
|
3532
|
+
maskedItem.error = `${maskedItem.error}; ${maskedValue.errorMsg}`;
|
|
3533
|
+
} else {
|
|
3534
|
+
maskedItem.error = maskedValue.errorMsg;
|
|
3535
|
+
}
|
|
3536
|
+
} else {
|
|
3537
|
+
maskedItem[field] = maskedValue;
|
|
3538
|
+
}
|
|
3539
|
+
}
|
|
3540
|
+
}
|
|
3541
|
+
return maskedItem;
|
|
3542
|
+
})
|
|
3543
|
+
);
|
|
3544
|
+
}
|
|
3545
|
+
return [mergedItems, attachments];
|
|
2176
3546
|
} catch (e) {
|
|
2177
3547
|
let errmsg = "Encountered error when constructing records to flush";
|
|
2178
3548
|
const isRetrying = i + 1 < this.numTries;
|
|
@@ -2520,7 +3890,7 @@ function init(projectOrOptions, optionalOptions) {
|
|
|
2520
3890
|
};
|
|
2521
3891
|
}
|
|
2522
3892
|
);
|
|
2523
|
-
const ret = new
|
|
3893
|
+
const ret = new Experiment2(state, lazyMetadata, dataset);
|
|
2524
3894
|
if (options.setCurrent ?? true) {
|
|
2525
3895
|
state.currentExperiment = ret;
|
|
2526
3896
|
}
|
|
@@ -2617,7 +3987,7 @@ function initDataset(projectOrOptions, optionalOptions) {
|
|
|
2617
3987
|
};
|
|
2618
3988
|
}
|
|
2619
3989
|
);
|
|
2620
|
-
return new
|
|
3990
|
+
return new Dataset2(
|
|
2621
3991
|
stateArg ?? _globalState,
|
|
2622
3992
|
lazyMetadata,
|
|
2623
3993
|
version,
|
|
@@ -2813,8 +4183,8 @@ async function loadPrompt({
|
|
|
2813
4183
|
);
|
|
2814
4184
|
}
|
|
2815
4185
|
}
|
|
2816
|
-
const metadata =
|
|
2817
|
-
const prompt = new
|
|
4186
|
+
const metadata = Prompt.parse(response["objects"][0]);
|
|
4187
|
+
const prompt = new Prompt2(metadata, defaults || {}, noTrace);
|
|
2818
4188
|
try {
|
|
2819
4189
|
if (id) {
|
|
2820
4190
|
await state.promptCache.set({ id }, prompt);
|
|
@@ -2829,6 +4199,9 @@ async function loadPrompt({
|
|
|
2829
4199
|
}
|
|
2830
4200
|
return prompt;
|
|
2831
4201
|
}
|
|
4202
|
+
function setMaskingFunction(maskingFunction) {
|
|
4203
|
+
_globalState.setMaskingFunction(maskingFunction);
|
|
4204
|
+
}
|
|
2832
4205
|
async function login(options = {}) {
|
|
2833
4206
|
const { forceLogin = false } = options || {};
|
|
2834
4207
|
if (_globalState.loggedIn && !forceLogin) {
|
|
@@ -3353,13 +4726,13 @@ function validateAndSanitizeExperimentLogPartialArgs(event) {
|
|
|
3353
4726
|
function deepCopyEvent(event) {
|
|
3354
4727
|
const attachments = [];
|
|
3355
4728
|
const IDENTIFIER = "_bt_internal_saved_attachment";
|
|
3356
|
-
const savedAttachmentSchema =
|
|
4729
|
+
const savedAttachmentSchema = z3.strictObject({ [IDENTIFIER]: z3.number() });
|
|
3357
4730
|
const serialized = JSON.stringify(event, (_k, v) => {
|
|
3358
4731
|
if (v instanceof SpanImpl || v instanceof NoopSpan) {
|
|
3359
4732
|
return `<span>`;
|
|
3360
|
-
} else if (v instanceof
|
|
4733
|
+
} else if (v instanceof Experiment2) {
|
|
3361
4734
|
return `<experiment>`;
|
|
3362
|
-
} else if (v instanceof
|
|
4735
|
+
} else if (v instanceof Dataset2) {
|
|
3363
4736
|
return `<dataset>`;
|
|
3364
4737
|
} else if (v instanceof Logger) {
|
|
3365
4738
|
return `<logger>`;
|
|
@@ -3411,7 +4784,7 @@ function extractAttachments(event, attachments) {
|
|
|
3411
4784
|
}
|
|
3412
4785
|
function enrichAttachments(event, state) {
|
|
3413
4786
|
for (const [key, value] of Object.entries(event)) {
|
|
3414
|
-
const parsedValue =
|
|
4787
|
+
const parsedValue = AttachmentReference.safeParse(value);
|
|
3415
4788
|
if (parsedValue.success) {
|
|
3416
4789
|
event[key] = new ReadonlyAttachment(parsedValue.data, state);
|
|
3417
4790
|
continue;
|
|
@@ -3554,7 +4927,7 @@ var ObjectFetcher = class {
|
|
|
3554
4927
|
}
|
|
3555
4928
|
}
|
|
3556
4929
|
};
|
|
3557
|
-
var
|
|
4930
|
+
var Experiment2 = class extends ObjectFetcher {
|
|
3558
4931
|
lazyMetadata;
|
|
3559
4932
|
dataset;
|
|
3560
4933
|
lastStartTime;
|
|
@@ -4160,7 +5533,7 @@ function splitLoggingData({
|
|
|
4160
5533
|
}
|
|
4161
5534
|
return [serializableInternalData, lazyInternalData];
|
|
4162
5535
|
}
|
|
4163
|
-
var
|
|
5536
|
+
var Dataset2 = class extends ObjectFetcher {
|
|
4164
5537
|
constructor(state, lazyMetadata, pinnedVersion, legacy, _internal_btql) {
|
|
4165
5538
|
const isLegacyDataset = legacy ?? DEFAULT_IS_LEGACY_DATASET;
|
|
4166
5539
|
if (isLegacyDataset) {
|
|
@@ -4358,8 +5731,8 @@ var Dataset = class extends ObjectFetcher {
|
|
|
4358
5731
|
)}`;
|
|
4359
5732
|
let dataSummary;
|
|
4360
5733
|
if (summarizeData) {
|
|
4361
|
-
const rawDataSummary =
|
|
4362
|
-
total_records:
|
|
5734
|
+
const rawDataSummary = z3.object({
|
|
5735
|
+
total_records: z3.number()
|
|
4363
5736
|
}).parse(
|
|
4364
5737
|
await state.apiConn().get_json(
|
|
4365
5738
|
"dataset-summary",
|
|
@@ -4482,11 +5855,11 @@ function renderTemplatedObject(obj, args, options) {
|
|
|
4482
5855
|
return obj;
|
|
4483
5856
|
}
|
|
4484
5857
|
function renderPromptParams(params, args, options) {
|
|
4485
|
-
const schemaParsed =
|
|
4486
|
-
response_format:
|
|
4487
|
-
type:
|
|
4488
|
-
json_schema:
|
|
4489
|
-
schema:
|
|
5858
|
+
const schemaParsed = z3.object({
|
|
5859
|
+
response_format: z3.object({
|
|
5860
|
+
type: z3.literal("json_schema"),
|
|
5861
|
+
json_schema: ResponseFormatJsonSchema.omit({ schema: true }).extend({
|
|
5862
|
+
schema: z3.unknown()
|
|
4490
5863
|
})
|
|
4491
5864
|
})
|
|
4492
5865
|
}).safeParse(params);
|
|
@@ -4507,7 +5880,7 @@ function renderPromptParams(params, args, options) {
|
|
|
4507
5880
|
}
|
|
4508
5881
|
return params;
|
|
4509
5882
|
}
|
|
4510
|
-
var
|
|
5883
|
+
var Prompt2 = class _Prompt {
|
|
4511
5884
|
constructor(metadata, defaults, noTrace) {
|
|
4512
5885
|
this.metadata = metadata;
|
|
4513
5886
|
this.defaults = defaults;
|
|
@@ -4604,7 +5977,7 @@ var Prompt = class _Prompt {
|
|
|
4604
5977
|
if (!prompt) {
|
|
4605
5978
|
throw new Error("Empty prompt");
|
|
4606
5979
|
}
|
|
4607
|
-
const dictArgParsed =
|
|
5980
|
+
const dictArgParsed = z3.record(z3.unknown()).safeParse(buildArgs);
|
|
4608
5981
|
const variables = {
|
|
4609
5982
|
input: buildArgs,
|
|
4610
5983
|
...dictArgParsed.success ? dictArgParsed.data : {}
|
|
@@ -4625,7 +5998,7 @@ var Prompt = class _Prompt {
|
|
|
4625
5998
|
...spanInfo,
|
|
4626
5999
|
messages: renderedPrompt.messages,
|
|
4627
6000
|
...renderedPrompt.tools ? {
|
|
4628
|
-
tools:
|
|
6001
|
+
tools: ChatCompletionTool.array().parse(JSON.parse(renderedPrompt.tools))
|
|
4629
6002
|
} : void 0
|
|
4630
6003
|
};
|
|
4631
6004
|
} else if (flavor === "completion") {
|
|
@@ -4659,7 +6032,7 @@ var Prompt = class _Prompt {
|
|
|
4659
6032
|
return JSON.stringify(v);
|
|
4660
6033
|
}
|
|
4661
6034
|
};
|
|
4662
|
-
const dictArgParsed =
|
|
6035
|
+
const dictArgParsed = z3.record(z3.unknown()).safeParse(buildArgs);
|
|
4663
6036
|
const variables = {
|
|
4664
6037
|
input: buildArgs,
|
|
4665
6038
|
...dictArgParsed.success ? dictArgParsed.data : {}
|
|
@@ -4712,7 +6085,7 @@ var Prompt = class _Prompt {
|
|
|
4712
6085
|
}
|
|
4713
6086
|
getParsedPromptData() {
|
|
4714
6087
|
if (!this.hasParsedPromptData) {
|
|
4715
|
-
this.parsedPromptData =
|
|
6088
|
+
this.parsedPromptData = PromptData.parse(this.metadata.prompt_data);
|
|
4716
6089
|
this.hasParsedPromptData = true;
|
|
4717
6090
|
}
|
|
4718
6091
|
return this.parsedPromptData;
|
|
@@ -4749,6 +6122,57 @@ function simulateLogoutForTests() {
|
|
|
4749
6122
|
_globalState.appUrl = "https://www.braintrust.dev";
|
|
4750
6123
|
return _globalState;
|
|
4751
6124
|
}
|
|
6125
|
+
async function getPromptVersions(projectId, promptId) {
|
|
6126
|
+
const state = _internalGetGlobalState();
|
|
6127
|
+
if (!state) {
|
|
6128
|
+
throw new Error("Must log in first");
|
|
6129
|
+
}
|
|
6130
|
+
await state.login({});
|
|
6131
|
+
const query = {
|
|
6132
|
+
from: {
|
|
6133
|
+
op: "function",
|
|
6134
|
+
name: {
|
|
6135
|
+
op: "ident",
|
|
6136
|
+
name: ["project_prompts"]
|
|
6137
|
+
},
|
|
6138
|
+
args: [
|
|
6139
|
+
{
|
|
6140
|
+
op: "literal",
|
|
6141
|
+
value: projectId
|
|
6142
|
+
}
|
|
6143
|
+
]
|
|
6144
|
+
},
|
|
6145
|
+
select: [
|
|
6146
|
+
{
|
|
6147
|
+
op: "star"
|
|
6148
|
+
}
|
|
6149
|
+
],
|
|
6150
|
+
filter: {
|
|
6151
|
+
op: "eq",
|
|
6152
|
+
left: { op: "ident", name: ["id"] },
|
|
6153
|
+
right: { op: "literal", value: promptId }
|
|
6154
|
+
}
|
|
6155
|
+
};
|
|
6156
|
+
const response = await state.apiConn().post(
|
|
6157
|
+
"btql",
|
|
6158
|
+
{
|
|
6159
|
+
query,
|
|
6160
|
+
audit_log: true,
|
|
6161
|
+
use_columnstore: false,
|
|
6162
|
+
brainstore_realtime: true
|
|
6163
|
+
},
|
|
6164
|
+
{ headers: { "Accept-Encoding": "gzip" } }
|
|
6165
|
+
);
|
|
6166
|
+
if (!response.ok) {
|
|
6167
|
+
throw new Error(
|
|
6168
|
+
`API request failed: ${response.status} ${response.statusText}`
|
|
6169
|
+
);
|
|
6170
|
+
}
|
|
6171
|
+
const result = await response.json();
|
|
6172
|
+
return result.data?.filter(
|
|
6173
|
+
(entry) => ["upsert", "merge"].includes(entry.audit_data?.action)
|
|
6174
|
+
).map((entry) => prettifyXact(entry._xact_id)) || [];
|
|
6175
|
+
}
|
|
4752
6176
|
var _exportsForTestingOnly = {
|
|
4753
6177
|
extractAttachments,
|
|
4754
6178
|
deepCopyEvent,
|
|
@@ -4757,6 +6181,7 @@ var _exportsForTestingOnly = {
|
|
|
4757
6181
|
simulateLoginForTests,
|
|
4758
6182
|
simulateLogoutForTests,
|
|
4759
6183
|
setInitialTestState,
|
|
6184
|
+
initTestExperiment,
|
|
4760
6185
|
isGeneratorFunction,
|
|
4761
6186
|
isAsyncGeneratorFunction
|
|
4762
6187
|
};
|
|
@@ -4800,9 +6225,9 @@ __export(exports_browser_exports, {
|
|
|
4800
6225
|
BaseAttachment: () => BaseAttachment,
|
|
4801
6226
|
BraintrustState: () => BraintrustState,
|
|
4802
6227
|
BraintrustStream: () => BraintrustStream,
|
|
4803
|
-
Dataset: () =>
|
|
6228
|
+
Dataset: () => Dataset2,
|
|
4804
6229
|
ERR_PERMALINK: () => ERR_PERMALINK,
|
|
4805
|
-
Experiment: () =>
|
|
6230
|
+
Experiment: () => Experiment2,
|
|
4806
6231
|
ExternalAttachment: () => ExternalAttachment,
|
|
4807
6232
|
FailedHTTPResponse: () => FailedHTTPResponse,
|
|
4808
6233
|
INTERNAL_BTQL_LIMIT: () => INTERNAL_BTQL_LIMIT,
|
|
@@ -4812,7 +6237,7 @@ __export(exports_browser_exports, {
|
|
|
4812
6237
|
NOOP_SPAN: () => NOOP_SPAN,
|
|
4813
6238
|
NOOP_SPAN_PERMALINK: () => NOOP_SPAN_PERMALINK,
|
|
4814
6239
|
NoopSpan: () => NoopSpan,
|
|
4815
|
-
Prompt: () =>
|
|
6240
|
+
Prompt: () => Prompt2,
|
|
4816
6241
|
ReadonlyAttachment: () => ReadonlyAttachment,
|
|
4817
6242
|
ReadonlyExperiment: () => ReadonlyExperiment,
|
|
4818
6243
|
SpanImpl: () => SpanImpl,
|
|
@@ -4831,6 +6256,7 @@ __export(exports_browser_exports, {
|
|
|
4831
6256
|
evaluatorDefinitionSchema: () => evaluatorDefinitionSchema,
|
|
4832
6257
|
evaluatorDefinitionsSchema: () => evaluatorDefinitionsSchema,
|
|
4833
6258
|
flush: () => flush,
|
|
6259
|
+
getPromptVersions: () => getPromptVersions,
|
|
4834
6260
|
getSpanParentObject: () => getSpanParentObject,
|
|
4835
6261
|
init: () => init,
|
|
4836
6262
|
initDataset: () => initDataset,
|
|
@@ -4849,6 +6275,7 @@ __export(exports_browser_exports, {
|
|
|
4849
6275
|
renderMessage: () => renderMessage,
|
|
4850
6276
|
renderPromptParams: () => renderPromptParams,
|
|
4851
6277
|
setFetch: () => setFetch,
|
|
6278
|
+
setMaskingFunction: () => setMaskingFunction,
|
|
4852
6279
|
spanComponentsToObjectId: () => spanComponentsToObjectId,
|
|
4853
6280
|
startSpan: () => startSpan,
|
|
4854
6281
|
summarize: () => summarize,
|
|
@@ -4866,9 +6293,6 @@ __export(exports_browser_exports, {
|
|
|
4866
6293
|
});
|
|
4867
6294
|
|
|
4868
6295
|
// src/functions/invoke.ts
|
|
4869
|
-
import {
|
|
4870
|
-
functionIdSchema
|
|
4871
|
-
} from "@braintrust/core/typespecs";
|
|
4872
6296
|
async function invoke(args) {
|
|
4873
6297
|
const {
|
|
4874
6298
|
orgName,
|
|
@@ -4897,7 +6321,7 @@ async function invoke(args) {
|
|
|
4897
6321
|
fetch: fetch2
|
|
4898
6322
|
});
|
|
4899
6323
|
const parent = parentArg ? typeof parentArg === "string" ? parentArg : await parentArg.export() : await getSpanParentObject().export();
|
|
4900
|
-
const functionId =
|
|
6324
|
+
const functionId = FunctionId.safeParse({
|
|
4901
6325
|
function_id: functionIdArgs.function_id,
|
|
4902
6326
|
project_name: functionIdArgs.projectName,
|
|
4903
6327
|
slug: functionIdArgs.slug,
|
|
@@ -5638,50 +7062,44 @@ var WrapperStream = class {
|
|
|
5638
7062
|
};
|
|
5639
7063
|
|
|
5640
7064
|
// dev/types.ts
|
|
5641
|
-
import {
|
|
5642
|
-
|
|
5643
|
-
|
|
5644
|
-
|
|
5645
|
-
|
|
5646
|
-
|
|
5647
|
-
|
|
5648
|
-
|
|
5649
|
-
|
|
5650
|
-
parameters: z3.record(z3.string(), z3.unknown()).nullish(),
|
|
5651
|
-
data: runEvalSchema.shape.data,
|
|
5652
|
-
scores: z3.array(
|
|
5653
|
-
z3.object({
|
|
5654
|
-
function_id: functionIdSchema2,
|
|
5655
|
-
name: z3.string()
|
|
7065
|
+
import { z as z4 } from "zod";
|
|
7066
|
+
var evalBodySchema = z4.object({
|
|
7067
|
+
name: z4.string(),
|
|
7068
|
+
parameters: z4.record(z4.string(), z4.unknown()).nullish(),
|
|
7069
|
+
data: RunEval.shape.data,
|
|
7070
|
+
scores: z4.array(
|
|
7071
|
+
z4.object({
|
|
7072
|
+
function_id: FunctionId,
|
|
7073
|
+
name: z4.string()
|
|
5656
7074
|
})
|
|
5657
7075
|
).nullish(),
|
|
5658
|
-
experiment_name:
|
|
5659
|
-
project_id:
|
|
5660
|
-
parent:
|
|
5661
|
-
stream:
|
|
7076
|
+
experiment_name: z4.string().nullish(),
|
|
7077
|
+
project_id: z4.string().nullish(),
|
|
7078
|
+
parent: InvokeParent.optional(),
|
|
7079
|
+
stream: z4.boolean().optional()
|
|
5662
7080
|
});
|
|
5663
|
-
var evalParametersSerializedSchema =
|
|
5664
|
-
|
|
5665
|
-
|
|
5666
|
-
|
|
5667
|
-
type:
|
|
5668
|
-
default:
|
|
5669
|
-
description:
|
|
7081
|
+
var evalParametersSerializedSchema = z4.record(
|
|
7082
|
+
z4.string(),
|
|
7083
|
+
z4.union([
|
|
7084
|
+
z4.object({
|
|
7085
|
+
type: z4.literal("prompt"),
|
|
7086
|
+
default: PromptData.optional(),
|
|
7087
|
+
description: z4.string().optional()
|
|
5670
7088
|
}),
|
|
5671
|
-
|
|
5672
|
-
type:
|
|
5673
|
-
schema:
|
|
7089
|
+
z4.object({
|
|
7090
|
+
type: z4.literal("data"),
|
|
7091
|
+
schema: z4.record(z4.unknown()),
|
|
5674
7092
|
// JSON Schema
|
|
5675
|
-
default:
|
|
5676
|
-
description:
|
|
7093
|
+
default: z4.unknown().optional(),
|
|
7094
|
+
description: z4.string().optional()
|
|
5677
7095
|
})
|
|
5678
7096
|
])
|
|
5679
7097
|
);
|
|
5680
|
-
var evaluatorDefinitionSchema =
|
|
7098
|
+
var evaluatorDefinitionSchema = z4.object({
|
|
5681
7099
|
parameters: evalParametersSerializedSchema.optional()
|
|
5682
7100
|
});
|
|
5683
|
-
var evaluatorDefinitionsSchema =
|
|
5684
|
-
|
|
7101
|
+
var evaluatorDefinitionsSchema = z4.record(
|
|
7102
|
+
z4.string(),
|
|
5685
7103
|
evaluatorDefinitionSchema
|
|
5686
7104
|
);
|
|
5687
7105
|
|
|
@@ -5693,9 +7111,9 @@ export {
|
|
|
5693
7111
|
BaseAttachment,
|
|
5694
7112
|
BraintrustState,
|
|
5695
7113
|
BraintrustStream,
|
|
5696
|
-
Dataset,
|
|
7114
|
+
Dataset2 as Dataset,
|
|
5697
7115
|
ERR_PERMALINK,
|
|
5698
|
-
Experiment,
|
|
7116
|
+
Experiment2 as Experiment,
|
|
5699
7117
|
ExternalAttachment,
|
|
5700
7118
|
FailedHTTPResponse,
|
|
5701
7119
|
INTERNAL_BTQL_LIMIT,
|
|
@@ -5705,7 +7123,7 @@ export {
|
|
|
5705
7123
|
NOOP_SPAN,
|
|
5706
7124
|
NOOP_SPAN_PERMALINK,
|
|
5707
7125
|
NoopSpan,
|
|
5708
|
-
Prompt,
|
|
7126
|
+
Prompt2 as Prompt,
|
|
5709
7127
|
ReadonlyAttachment,
|
|
5710
7128
|
ReadonlyExperiment,
|
|
5711
7129
|
SpanImpl,
|
|
@@ -5725,6 +7143,7 @@ export {
|
|
|
5725
7143
|
evaluatorDefinitionSchema,
|
|
5726
7144
|
evaluatorDefinitionsSchema,
|
|
5727
7145
|
flush,
|
|
7146
|
+
getPromptVersions,
|
|
5728
7147
|
getSpanParentObject,
|
|
5729
7148
|
init,
|
|
5730
7149
|
initDataset,
|
|
@@ -5743,6 +7162,7 @@ export {
|
|
|
5743
7162
|
renderMessage,
|
|
5744
7163
|
renderPromptParams,
|
|
5745
7164
|
setFetch,
|
|
7165
|
+
setMaskingFunction,
|
|
5746
7166
|
spanComponentsToObjectId,
|
|
5747
7167
|
startSpan,
|
|
5748
7168
|
summarize,
|