braintrust 0.2.3 → 0.2.5
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 +7261 -471
- package/dev/dist/index.d.ts +7261 -471
- package/dev/dist/index.js +1396 -111
- package/dev/dist/index.mjs +1451 -166
- package/dist/browser.d.mts +9148 -2040
- package/dist/browser.d.ts +9148 -2040
- package/dist/browser.js +1490 -107
- package/dist/browser.mjs +1513 -130
- package/dist/cli.js +1490 -177
- package/dist/index.d.mts +15826 -2367
- package/dist/index.d.ts +15826 -2367
- package/dist/index.js +1642 -199
- package/dist/index.mjs +1639 -196
- package/package.json +6 -2
package/dist/browser.mjs
CHANGED
|
@@ -109,64 +109,1264 @@ 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 ResponseFormat = 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: ResponseFormat.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 BraintrustAttachmentReference = z.object({
|
|
224
|
+
type: z.literal("braintrust_attachment"),
|
|
225
|
+
filename: z.string().min(1),
|
|
226
|
+
content_type: z.string().min(1),
|
|
227
|
+
key: z.string().min(1)
|
|
228
|
+
});
|
|
229
|
+
var ExternalAttachmentReference = z.object({
|
|
230
|
+
type: z.literal("external_attachment"),
|
|
231
|
+
filename: z.string().min(1),
|
|
232
|
+
content_type: z.string().min(1),
|
|
233
|
+
url: z.string().min(1)
|
|
234
|
+
});
|
|
235
|
+
var AttachmentReference = z.discriminatedUnion("type", [
|
|
236
|
+
BraintrustAttachmentReference,
|
|
237
|
+
ExternalAttachmentReference
|
|
238
|
+
]);
|
|
239
|
+
var UploadStatus = z.enum(["uploading", "done", "error"]);
|
|
240
|
+
var AttachmentStatus = z.object({
|
|
241
|
+
upload_status: UploadStatus,
|
|
242
|
+
error_message: z.string().optional()
|
|
243
|
+
});
|
|
244
|
+
var BraintrustModelParams = z.object({ use_cache: z.boolean() }).partial();
|
|
245
|
+
var CallEvent = z.union([
|
|
246
|
+
z.object({
|
|
247
|
+
id: z.string().optional(),
|
|
248
|
+
data: z.string(),
|
|
249
|
+
event: z.literal("text_delta")
|
|
250
|
+
}),
|
|
251
|
+
z.object({
|
|
252
|
+
id: z.string().optional(),
|
|
253
|
+
data: z.string(),
|
|
254
|
+
event: z.literal("reasoning_delta")
|
|
255
|
+
}),
|
|
256
|
+
z.object({
|
|
257
|
+
id: z.string().optional(),
|
|
258
|
+
data: z.string(),
|
|
259
|
+
event: z.literal("json_delta")
|
|
260
|
+
}),
|
|
261
|
+
z.object({
|
|
262
|
+
id: z.string().optional(),
|
|
263
|
+
data: z.string(),
|
|
264
|
+
event: z.literal("progress")
|
|
265
|
+
}),
|
|
266
|
+
z.object({
|
|
267
|
+
id: z.string().optional(),
|
|
268
|
+
data: z.string(),
|
|
269
|
+
event: z.literal("error")
|
|
270
|
+
}),
|
|
271
|
+
z.object({
|
|
272
|
+
id: z.string().optional(),
|
|
273
|
+
data: z.string(),
|
|
274
|
+
event: z.literal("console")
|
|
275
|
+
}),
|
|
276
|
+
z.object({
|
|
277
|
+
id: z.string().optional(),
|
|
278
|
+
event: z.literal("start"),
|
|
279
|
+
data: z.literal("")
|
|
280
|
+
}),
|
|
281
|
+
z.object({
|
|
282
|
+
id: z.string().optional(),
|
|
283
|
+
event: z.literal("done"),
|
|
284
|
+
data: z.literal("")
|
|
285
|
+
})
|
|
286
|
+
]);
|
|
287
|
+
var ChatCompletionContentPartTextWithTitle = z.object({
|
|
288
|
+
text: z.string().default(""),
|
|
289
|
+
type: z.literal("text"),
|
|
290
|
+
cache_control: z.object({ type: z.literal("ephemeral") }).optional()
|
|
291
|
+
});
|
|
292
|
+
var ChatCompletionContentPartImageWithTitle = z.object({
|
|
293
|
+
image_url: z.object({
|
|
294
|
+
url: z.string(),
|
|
295
|
+
detail: z.union([z.literal("auto"), z.literal("low"), z.literal("high")]).optional()
|
|
296
|
+
}),
|
|
297
|
+
type: z.literal("image_url")
|
|
298
|
+
});
|
|
299
|
+
var ChatCompletionContentPart = z.union([
|
|
300
|
+
ChatCompletionContentPartTextWithTitle,
|
|
301
|
+
ChatCompletionContentPartImageWithTitle
|
|
302
|
+
]);
|
|
303
|
+
var ChatCompletionContentPartText = z.object({
|
|
304
|
+
text: z.string().default(""),
|
|
305
|
+
type: z.literal("text"),
|
|
306
|
+
cache_control: z.object({ type: z.literal("ephemeral") }).optional()
|
|
307
|
+
});
|
|
308
|
+
var ChatCompletionMessageToolCall = z.object({
|
|
309
|
+
id: z.string(),
|
|
310
|
+
function: z.object({ arguments: z.string(), name: z.string() }),
|
|
311
|
+
type: z.literal("function")
|
|
312
|
+
});
|
|
313
|
+
var ChatCompletionMessageReasoning = z.object({ id: z.string(), content: z.string() }).partial();
|
|
314
|
+
var ChatCompletionMessageParam = z.union([
|
|
315
|
+
z.object({
|
|
316
|
+
content: z.union([z.string(), z.array(ChatCompletionContentPartText)]),
|
|
317
|
+
role: z.literal("system"),
|
|
318
|
+
name: z.string().optional()
|
|
319
|
+
}),
|
|
320
|
+
z.object({
|
|
321
|
+
content: z.union([z.string(), z.array(ChatCompletionContentPart)]),
|
|
322
|
+
role: z.literal("user"),
|
|
323
|
+
name: z.string().optional()
|
|
324
|
+
}),
|
|
325
|
+
z.object({
|
|
326
|
+
role: z.literal("assistant"),
|
|
327
|
+
content: z.union([z.string(), z.array(ChatCompletionContentPartText), z.null()]).optional(),
|
|
328
|
+
function_call: z.object({ arguments: z.string(), name: z.string() }).optional(),
|
|
329
|
+
name: z.string().optional(),
|
|
330
|
+
tool_calls: z.array(ChatCompletionMessageToolCall).optional(),
|
|
331
|
+
reasoning: z.array(ChatCompletionMessageReasoning).optional()
|
|
332
|
+
}),
|
|
333
|
+
z.object({
|
|
334
|
+
content: z.union([z.string(), z.array(ChatCompletionContentPartText)]),
|
|
335
|
+
role: z.literal("tool"),
|
|
336
|
+
tool_call_id: z.string().default("")
|
|
337
|
+
}),
|
|
338
|
+
z.object({
|
|
339
|
+
content: z.union([z.string(), z.null()]),
|
|
340
|
+
name: z.string(),
|
|
341
|
+
role: z.literal("function")
|
|
342
|
+
}),
|
|
343
|
+
z.object({
|
|
344
|
+
content: z.union([z.string(), z.array(ChatCompletionContentPartText)]),
|
|
345
|
+
role: z.literal("developer"),
|
|
346
|
+
name: z.string().optional()
|
|
347
|
+
}),
|
|
348
|
+
z.object({
|
|
349
|
+
role: z.literal("model"),
|
|
350
|
+
content: z.union([z.string(), z.null()]).optional()
|
|
351
|
+
})
|
|
352
|
+
]);
|
|
353
|
+
var ChatCompletionOpenAIMessageParam = z.union([
|
|
354
|
+
z.object({
|
|
355
|
+
content: z.union([z.string(), z.array(ChatCompletionContentPartText)]),
|
|
356
|
+
role: z.literal("system"),
|
|
357
|
+
name: z.string().optional()
|
|
358
|
+
}),
|
|
359
|
+
z.object({
|
|
360
|
+
content: z.union([z.string(), z.array(ChatCompletionContentPart)]),
|
|
361
|
+
role: z.literal("user"),
|
|
362
|
+
name: z.string().optional()
|
|
363
|
+
}),
|
|
364
|
+
z.object({
|
|
365
|
+
role: z.literal("assistant"),
|
|
366
|
+
content: z.union([z.string(), z.array(ChatCompletionContentPartText), z.null()]).optional(),
|
|
367
|
+
function_call: z.object({ arguments: z.string(), name: z.string() }).optional(),
|
|
368
|
+
name: z.string().optional(),
|
|
369
|
+
tool_calls: z.array(ChatCompletionMessageToolCall).optional(),
|
|
370
|
+
reasoning: z.array(ChatCompletionMessageReasoning).optional()
|
|
371
|
+
}),
|
|
372
|
+
z.object({
|
|
373
|
+
content: z.union([z.string(), z.array(ChatCompletionContentPartText)]),
|
|
374
|
+
role: z.literal("tool"),
|
|
375
|
+
tool_call_id: z.string().default("")
|
|
376
|
+
}),
|
|
377
|
+
z.object({
|
|
378
|
+
content: z.union([z.string(), z.null()]),
|
|
379
|
+
name: z.string(),
|
|
380
|
+
role: z.literal("function")
|
|
381
|
+
}),
|
|
382
|
+
z.object({
|
|
383
|
+
content: z.union([z.string(), z.array(ChatCompletionContentPartText)]),
|
|
384
|
+
role: z.literal("developer"),
|
|
385
|
+
name: z.string().optional()
|
|
386
|
+
})
|
|
387
|
+
]);
|
|
388
|
+
var ChatCompletionTool = z.object({
|
|
389
|
+
function: z.object({
|
|
390
|
+
name: z.string(),
|
|
391
|
+
description: z.string().optional(),
|
|
392
|
+
parameters: z.object({}).partial().passthrough().optional()
|
|
393
|
+
}),
|
|
394
|
+
type: z.literal("function")
|
|
395
|
+
});
|
|
396
|
+
var CodeBundle = z.object({
|
|
397
|
+
runtime_context: z.object({
|
|
398
|
+
runtime: z.enum(["node", "python"]),
|
|
399
|
+
version: z.string()
|
|
400
|
+
}),
|
|
401
|
+
location: z.union([
|
|
402
|
+
z.object({
|
|
403
|
+
type: z.literal("experiment"),
|
|
404
|
+
eval_name: z.string(),
|
|
405
|
+
position: z.union([
|
|
406
|
+
z.object({ type: z.literal("task") }),
|
|
407
|
+
z.object({ type: z.literal("scorer"), index: z.number().int().gte(0) })
|
|
408
|
+
])
|
|
409
|
+
}),
|
|
410
|
+
z.object({ type: z.literal("function"), index: z.number().int().gte(0) })
|
|
411
|
+
]),
|
|
412
|
+
bundle_id: z.string(),
|
|
413
|
+
preview: z.union([z.string(), z.null()]).optional()
|
|
414
|
+
});
|
|
415
|
+
var Dataset = z.object({
|
|
416
|
+
id: z.string().uuid(),
|
|
417
|
+
project_id: z.string().uuid(),
|
|
418
|
+
name: z.string(),
|
|
419
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
420
|
+
created: z.union([z.string(), z.null()]).optional(),
|
|
421
|
+
deleted_at: z.union([z.string(), z.null()]).optional(),
|
|
422
|
+
user_id: z.union([z.string(), z.null()]).optional(),
|
|
423
|
+
metadata: z.union([z.object({}).partial().passthrough(), z.null()]).optional()
|
|
424
|
+
});
|
|
425
|
+
var ObjectReference = z.union([
|
|
426
|
+
z.object({
|
|
427
|
+
object_type: z.enum([
|
|
428
|
+
"project_logs",
|
|
429
|
+
"experiment",
|
|
430
|
+
"dataset",
|
|
431
|
+
"prompt",
|
|
432
|
+
"function",
|
|
433
|
+
"prompt_session"
|
|
434
|
+
]),
|
|
435
|
+
object_id: z.string().uuid(),
|
|
436
|
+
id: z.string(),
|
|
437
|
+
_xact_id: z.union([z.string(), z.null()]).optional(),
|
|
438
|
+
created: z.union([z.string(), z.null()]).optional()
|
|
439
|
+
}),
|
|
440
|
+
z.null()
|
|
441
|
+
]);
|
|
442
|
+
var DatasetEvent = z.object({
|
|
443
|
+
id: z.string(),
|
|
444
|
+
_xact_id: z.string(),
|
|
445
|
+
created: z.string().datetime({ offset: true }),
|
|
446
|
+
_pagination_key: z.union([z.string(), z.null()]).optional(),
|
|
447
|
+
project_id: z.string().uuid(),
|
|
448
|
+
dataset_id: z.string().uuid(),
|
|
449
|
+
input: z.unknown().optional(),
|
|
450
|
+
expected: z.unknown().optional(),
|
|
451
|
+
metadata: z.union([
|
|
452
|
+
z.object({ model: z.union([z.string(), z.null()]) }).partial().passthrough(),
|
|
453
|
+
z.null()
|
|
454
|
+
]).optional(),
|
|
455
|
+
tags: z.union([z.array(z.string()), z.null()]).optional(),
|
|
456
|
+
span_id: z.string(),
|
|
457
|
+
root_span_id: z.string(),
|
|
458
|
+
is_root: z.union([z.boolean(), z.null()]).optional(),
|
|
459
|
+
origin: ObjectReference.optional()
|
|
460
|
+
});
|
|
461
|
+
var EnvVar = z.object({
|
|
462
|
+
id: z.string().uuid(),
|
|
463
|
+
object_type: z.enum(["organization", "project", "function"]),
|
|
464
|
+
object_id: z.string().uuid(),
|
|
465
|
+
name: z.string(),
|
|
466
|
+
created: z.union([z.string(), z.null()]).optional(),
|
|
467
|
+
used: z.union([z.string(), z.null()]).optional()
|
|
468
|
+
});
|
|
469
|
+
var RepoInfo = z.union([
|
|
470
|
+
z.object({
|
|
471
|
+
commit: z.union([z.string(), z.null()]),
|
|
472
|
+
branch: z.union([z.string(), z.null()]),
|
|
473
|
+
tag: z.union([z.string(), z.null()]),
|
|
474
|
+
dirty: z.union([z.boolean(), z.null()]),
|
|
475
|
+
author_name: z.union([z.string(), z.null()]),
|
|
476
|
+
author_email: z.union([z.string(), z.null()]),
|
|
477
|
+
commit_message: z.union([z.string(), z.null()]),
|
|
478
|
+
commit_time: z.union([z.string(), z.null()]),
|
|
479
|
+
git_diff: z.union([z.string(), z.null()])
|
|
480
|
+
}).partial(),
|
|
481
|
+
z.null()
|
|
482
|
+
]);
|
|
483
|
+
var Experiment = z.object({
|
|
484
|
+
id: z.string().uuid(),
|
|
485
|
+
project_id: z.string().uuid(),
|
|
486
|
+
name: z.string(),
|
|
487
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
488
|
+
created: z.union([z.string(), z.null()]).optional(),
|
|
489
|
+
repo_info: RepoInfo.optional(),
|
|
490
|
+
commit: z.union([z.string(), z.null()]).optional(),
|
|
491
|
+
base_exp_id: z.union([z.string(), z.null()]).optional(),
|
|
492
|
+
deleted_at: z.union([z.string(), z.null()]).optional(),
|
|
493
|
+
dataset_id: z.union([z.string(), z.null()]).optional(),
|
|
494
|
+
dataset_version: z.union([z.string(), z.null()]).optional(),
|
|
495
|
+
public: z.boolean(),
|
|
496
|
+
user_id: z.union([z.string(), z.null()]).optional(),
|
|
497
|
+
metadata: z.union([z.object({}).partial().passthrough(), z.null()]).optional(),
|
|
498
|
+
tags: z.union([z.array(z.string()), z.null()]).optional()
|
|
499
|
+
});
|
|
500
|
+
var SpanType = z.union([
|
|
501
|
+
z.enum(["llm", "score", "function", "eval", "task", "tool"]),
|
|
502
|
+
z.null()
|
|
503
|
+
]);
|
|
504
|
+
var SpanAttributes = z.union([
|
|
505
|
+
z.object({ name: z.union([z.string(), z.null()]), type: SpanType }).partial().passthrough(),
|
|
506
|
+
z.null()
|
|
507
|
+
]);
|
|
508
|
+
var ExperimentEvent = z.object({
|
|
509
|
+
id: z.string(),
|
|
510
|
+
_xact_id: z.string(),
|
|
511
|
+
created: z.string().datetime({ offset: true }),
|
|
512
|
+
_pagination_key: z.union([z.string(), z.null()]).optional(),
|
|
513
|
+
project_id: z.string().uuid(),
|
|
514
|
+
experiment_id: z.string().uuid(),
|
|
515
|
+
input: z.unknown().optional(),
|
|
516
|
+
output: z.unknown().optional(),
|
|
517
|
+
expected: z.unknown().optional(),
|
|
518
|
+
error: z.unknown().optional(),
|
|
519
|
+
scores: z.union([z.record(z.union([z.number(), z.null()])), z.null()]).optional(),
|
|
520
|
+
metadata: z.union([
|
|
521
|
+
z.object({ model: z.union([z.string(), z.null()]) }).partial().passthrough(),
|
|
522
|
+
z.null()
|
|
523
|
+
]).optional(),
|
|
524
|
+
tags: z.union([z.array(z.string()), z.null()]).optional(),
|
|
525
|
+
metrics: z.union([z.record(z.number()), z.null()]).optional(),
|
|
526
|
+
context: z.union([
|
|
527
|
+
z.object({
|
|
528
|
+
caller_functionname: z.union([z.string(), z.null()]),
|
|
529
|
+
caller_filename: z.union([z.string(), z.null()]),
|
|
530
|
+
caller_lineno: z.union([z.number(), z.null()])
|
|
531
|
+
}).partial().passthrough(),
|
|
532
|
+
z.null()
|
|
533
|
+
]).optional(),
|
|
534
|
+
span_id: z.string(),
|
|
535
|
+
span_parents: z.union([z.array(z.string()), z.null()]).optional(),
|
|
536
|
+
root_span_id: z.string(),
|
|
537
|
+
span_attributes: SpanAttributes.optional(),
|
|
538
|
+
is_root: z.union([z.boolean(), z.null()]).optional(),
|
|
539
|
+
origin: ObjectReference.optional()
|
|
540
|
+
});
|
|
541
|
+
var ExtendedSavedFunctionId = z.union([
|
|
542
|
+
z.object({ type: z.literal("function"), id: z.string() }),
|
|
543
|
+
z.object({ type: z.literal("global"), name: z.string() }),
|
|
544
|
+
z.object({
|
|
545
|
+
type: z.literal("slug"),
|
|
546
|
+
project_id: z.string(),
|
|
547
|
+
slug: z.string()
|
|
548
|
+
})
|
|
549
|
+
]);
|
|
550
|
+
var PromptBlockDataNullish = z.union([
|
|
551
|
+
z.object({ type: z.literal("completion"), content: z.string() }),
|
|
552
|
+
z.object({
|
|
553
|
+
type: z.literal("chat"),
|
|
554
|
+
messages: z.array(ChatCompletionMessageParam),
|
|
555
|
+
tools: z.string().optional()
|
|
556
|
+
}),
|
|
557
|
+
z.null()
|
|
558
|
+
]);
|
|
559
|
+
var ModelParams = z.union([
|
|
560
|
+
z.object({
|
|
561
|
+
use_cache: z.boolean(),
|
|
562
|
+
temperature: z.number(),
|
|
563
|
+
top_p: z.number(),
|
|
564
|
+
max_tokens: z.number(),
|
|
565
|
+
max_completion_tokens: z.number(),
|
|
566
|
+
frequency_penalty: z.number(),
|
|
567
|
+
presence_penalty: z.number(),
|
|
568
|
+
response_format: ResponseFormat,
|
|
569
|
+
tool_choice: z.union([
|
|
570
|
+
z.literal("auto"),
|
|
571
|
+
z.literal("none"),
|
|
572
|
+
z.literal("required"),
|
|
573
|
+
z.object({
|
|
574
|
+
type: z.literal("function"),
|
|
575
|
+
function: z.object({ name: z.string() })
|
|
576
|
+
})
|
|
577
|
+
]),
|
|
578
|
+
function_call: z.union([
|
|
579
|
+
z.literal("auto"),
|
|
580
|
+
z.literal("none"),
|
|
581
|
+
z.object({ name: z.string() })
|
|
582
|
+
]),
|
|
583
|
+
n: z.number(),
|
|
584
|
+
stop: z.array(z.string()),
|
|
585
|
+
reasoning_effort: z.enum(["minimal", "low", "medium", "high"]),
|
|
586
|
+
verbosity: z.enum(["low", "medium", "high"])
|
|
587
|
+
}).partial().passthrough(),
|
|
588
|
+
z.object({
|
|
589
|
+
use_cache: z.boolean().optional(),
|
|
590
|
+
max_tokens: z.number(),
|
|
591
|
+
temperature: z.number(),
|
|
592
|
+
top_p: z.number().optional(),
|
|
593
|
+
top_k: z.number().optional(),
|
|
594
|
+
stop_sequences: z.array(z.string()).optional(),
|
|
595
|
+
max_tokens_to_sample: z.number().optional()
|
|
596
|
+
}).passthrough(),
|
|
597
|
+
z.object({
|
|
598
|
+
use_cache: z.boolean(),
|
|
599
|
+
temperature: z.number(),
|
|
600
|
+
maxOutputTokens: z.number(),
|
|
601
|
+
topP: z.number(),
|
|
602
|
+
topK: z.number()
|
|
603
|
+
}).partial().passthrough(),
|
|
604
|
+
z.object({
|
|
605
|
+
use_cache: z.boolean(),
|
|
606
|
+
temperature: z.number(),
|
|
607
|
+
topK: z.number()
|
|
608
|
+
}).partial().passthrough(),
|
|
609
|
+
z.object({ use_cache: z.boolean() }).partial().passthrough()
|
|
610
|
+
]);
|
|
611
|
+
var PromptOptionsNullish = z.union([
|
|
612
|
+
z.object({ model: z.string(), params: ModelParams, position: z.string() }).partial(),
|
|
613
|
+
z.null()
|
|
614
|
+
]);
|
|
615
|
+
var PromptParserNullish = z.union([
|
|
616
|
+
z.object({
|
|
617
|
+
type: z.literal("llm_classifier"),
|
|
618
|
+
use_cot: z.boolean(),
|
|
619
|
+
choice_scores: z.record(z.number().gte(0).lte(1))
|
|
620
|
+
}),
|
|
621
|
+
z.null()
|
|
622
|
+
]);
|
|
623
|
+
var SavedFunctionId = z.union([
|
|
624
|
+
z.object({ type: z.literal("function"), id: z.string() }),
|
|
625
|
+
z.object({ type: z.literal("global"), name: z.string() })
|
|
626
|
+
]);
|
|
627
|
+
var PromptDataNullish = z.union([
|
|
628
|
+
z.object({
|
|
629
|
+
prompt: PromptBlockDataNullish,
|
|
630
|
+
options: PromptOptionsNullish,
|
|
631
|
+
parser: PromptParserNullish,
|
|
632
|
+
tool_functions: z.union([z.array(SavedFunctionId), z.null()]),
|
|
633
|
+
origin: z.union([
|
|
634
|
+
z.object({
|
|
635
|
+
prompt_id: z.string(),
|
|
636
|
+
project_id: z.string(),
|
|
637
|
+
prompt_version: z.string()
|
|
638
|
+
}).partial(),
|
|
639
|
+
z.null()
|
|
640
|
+
])
|
|
641
|
+
}).partial(),
|
|
642
|
+
z.null()
|
|
643
|
+
]);
|
|
644
|
+
var FunctionTypeEnumNullish = z.union([
|
|
645
|
+
z.enum(["llm", "scorer", "task", "tool"]),
|
|
646
|
+
z.null()
|
|
647
|
+
]);
|
|
648
|
+
var FunctionIdRef = z.object({}).partial().passthrough();
|
|
649
|
+
var PromptBlockData = z.union([
|
|
650
|
+
z.object({ type: z.literal("completion"), content: z.string() }),
|
|
651
|
+
z.object({
|
|
652
|
+
type: z.literal("chat"),
|
|
653
|
+
messages: z.array(ChatCompletionMessageParam),
|
|
654
|
+
tools: z.string().optional()
|
|
655
|
+
})
|
|
656
|
+
]);
|
|
657
|
+
var GraphNode = z.union([
|
|
658
|
+
z.object({
|
|
659
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
660
|
+
position: z.union([z.object({ x: z.number(), y: z.number() }), z.null()]).optional(),
|
|
661
|
+
type: z.literal("function"),
|
|
662
|
+
function: FunctionIdRef
|
|
663
|
+
}),
|
|
664
|
+
z.object({
|
|
665
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
666
|
+
position: z.union([z.object({ x: z.number(), y: z.number() }), z.null()]).optional(),
|
|
667
|
+
type: z.literal("input")
|
|
668
|
+
}),
|
|
669
|
+
z.object({
|
|
670
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
671
|
+
position: z.union([z.object({ x: z.number(), y: z.number() }), z.null()]).optional(),
|
|
672
|
+
type: z.literal("output")
|
|
673
|
+
}),
|
|
674
|
+
z.object({
|
|
675
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
676
|
+
position: z.union([z.object({ x: z.number(), y: z.number() }), z.null()]).optional(),
|
|
677
|
+
type: z.literal("literal"),
|
|
678
|
+
value: z.unknown().optional()
|
|
679
|
+
}),
|
|
680
|
+
z.object({
|
|
681
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
682
|
+
position: z.union([z.object({ x: z.number(), y: z.number() }), z.null()]).optional(),
|
|
683
|
+
type: z.literal("btql"),
|
|
684
|
+
expr: z.string()
|
|
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("gate"),
|
|
690
|
+
condition: z.union([z.string(), z.null()]).optional()
|
|
691
|
+
}),
|
|
692
|
+
z.object({
|
|
693
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
694
|
+
position: z.union([z.object({ x: z.number(), y: z.number() }), z.null()]).optional(),
|
|
695
|
+
type: z.literal("aggregator")
|
|
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("prompt_template"),
|
|
701
|
+
prompt: PromptBlockData
|
|
702
|
+
})
|
|
703
|
+
]);
|
|
704
|
+
var GraphEdge = z.object({
|
|
705
|
+
source: z.object({ node: z.string().max(1024), variable: z.string() }),
|
|
706
|
+
target: z.object({ node: z.string().max(1024), variable: z.string() }),
|
|
707
|
+
purpose: z.enum(["control", "data", "messages"])
|
|
708
|
+
});
|
|
709
|
+
var GraphData = z.object({
|
|
710
|
+
type: z.literal("graph"),
|
|
711
|
+
nodes: z.record(GraphNode),
|
|
712
|
+
edges: z.record(GraphEdge)
|
|
713
|
+
});
|
|
714
|
+
var FunctionData = z.union([
|
|
715
|
+
z.object({ type: z.literal("prompt") }),
|
|
716
|
+
z.object({
|
|
717
|
+
type: z.literal("code"),
|
|
718
|
+
data: z.union([
|
|
719
|
+
z.object({ type: z.literal("bundle") }).and(CodeBundle),
|
|
720
|
+
z.object({
|
|
721
|
+
type: z.literal("inline"),
|
|
722
|
+
runtime_context: z.object({
|
|
723
|
+
runtime: z.enum(["node", "python"]),
|
|
724
|
+
version: z.string()
|
|
725
|
+
}),
|
|
726
|
+
code: z.string()
|
|
727
|
+
})
|
|
728
|
+
])
|
|
729
|
+
}),
|
|
730
|
+
GraphData,
|
|
731
|
+
z.object({
|
|
732
|
+
type: z.literal("remote_eval"),
|
|
733
|
+
endpoint: z.string(),
|
|
734
|
+
eval_name: z.string(),
|
|
735
|
+
parameters: z.object({}).partial().passthrough()
|
|
736
|
+
}),
|
|
737
|
+
z.object({ type: z.literal("global"), name: z.string() })
|
|
738
|
+
]);
|
|
739
|
+
var Function = z.object({
|
|
740
|
+
id: z.string().uuid(),
|
|
741
|
+
_xact_id: z.string(),
|
|
742
|
+
project_id: z.string().uuid(),
|
|
743
|
+
log_id: z.literal("p"),
|
|
744
|
+
org_id: z.string().uuid(),
|
|
745
|
+
name: z.string(),
|
|
746
|
+
slug: z.string(),
|
|
747
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
748
|
+
created: z.union([z.string(), z.null()]).optional(),
|
|
749
|
+
prompt_data: PromptDataNullish.optional(),
|
|
750
|
+
tags: z.union([z.array(z.string()), z.null()]).optional(),
|
|
751
|
+
metadata: z.union([z.object({}).partial().passthrough(), z.null()]).optional(),
|
|
752
|
+
function_type: FunctionTypeEnumNullish.optional(),
|
|
753
|
+
function_data: FunctionData,
|
|
754
|
+
origin: z.union([
|
|
755
|
+
z.object({
|
|
756
|
+
object_type: AclObjectType.and(z.string()),
|
|
757
|
+
object_id: z.string().uuid(),
|
|
758
|
+
internal: z.union([z.boolean(), z.null()]).optional()
|
|
759
|
+
}),
|
|
760
|
+
z.null()
|
|
761
|
+
]).optional(),
|
|
762
|
+
function_schema: z.union([
|
|
763
|
+
z.object({ parameters: z.unknown(), returns: z.unknown() }).partial(),
|
|
764
|
+
z.null()
|
|
765
|
+
]).optional()
|
|
766
|
+
});
|
|
767
|
+
var FunctionFormat = z.enum(["llm", "code", "global", "graph"]);
|
|
768
|
+
var PromptData = z.object({
|
|
769
|
+
prompt: PromptBlockDataNullish,
|
|
770
|
+
options: PromptOptionsNullish,
|
|
771
|
+
parser: PromptParserNullish,
|
|
772
|
+
tool_functions: z.union([z.array(SavedFunctionId), z.null()]),
|
|
773
|
+
origin: z.union([
|
|
774
|
+
z.object({
|
|
775
|
+
prompt_id: z.string(),
|
|
776
|
+
project_id: z.string(),
|
|
777
|
+
prompt_version: z.string()
|
|
778
|
+
}).partial(),
|
|
779
|
+
z.null()
|
|
780
|
+
])
|
|
781
|
+
}).partial();
|
|
782
|
+
var FunctionTypeEnum = z.enum(["llm", "scorer", "task", "tool"]);
|
|
783
|
+
var FunctionId = z.union([
|
|
784
|
+
z.object({ function_id: z.string(), version: z.string().optional() }),
|
|
139
785
|
z.object({
|
|
140
|
-
|
|
141
|
-
|
|
786
|
+
project_name: z.string(),
|
|
787
|
+
slug: z.string(),
|
|
788
|
+
version: z.string().optional()
|
|
142
789
|
}),
|
|
790
|
+
z.object({ global_function: z.string() }),
|
|
143
791
|
z.object({
|
|
144
|
-
|
|
145
|
-
|
|
792
|
+
prompt_session_id: z.string(),
|
|
793
|
+
prompt_session_function_id: z.string(),
|
|
794
|
+
version: z.string().optional()
|
|
146
795
|
}),
|
|
147
796
|
z.object({
|
|
148
|
-
|
|
149
|
-
|
|
797
|
+
inline_context: z.object({
|
|
798
|
+
runtime: z.enum(["node", "python"]),
|
|
799
|
+
version: z.string()
|
|
800
|
+
}),
|
|
801
|
+
code: z.string(),
|
|
802
|
+
name: z.union([z.string(), z.null()]).optional()
|
|
150
803
|
}),
|
|
151
804
|
z.object({
|
|
152
|
-
|
|
153
|
-
|
|
805
|
+
inline_prompt: PromptData.optional(),
|
|
806
|
+
inline_function: z.object({}).partial().passthrough(),
|
|
807
|
+
function_type: FunctionTypeEnum.optional(),
|
|
808
|
+
name: z.union([z.string(), z.null()]).optional()
|
|
154
809
|
}),
|
|
155
810
|
z.object({
|
|
156
|
-
|
|
157
|
-
|
|
811
|
+
inline_prompt: PromptData,
|
|
812
|
+
function_type: FunctionTypeEnum.optional(),
|
|
813
|
+
name: z.union([z.string(), z.null()]).optional()
|
|
814
|
+
})
|
|
815
|
+
]);
|
|
816
|
+
var FunctionObjectType = z.enum([
|
|
817
|
+
"prompt",
|
|
818
|
+
"tool",
|
|
819
|
+
"scorer",
|
|
820
|
+
"task",
|
|
821
|
+
"agent"
|
|
822
|
+
]);
|
|
823
|
+
var FunctionOutputType = z.enum(["completion", "score", "any"]);
|
|
824
|
+
var GitMetadataSettings = z.object({
|
|
825
|
+
collect: z.enum(["all", "none", "some"]),
|
|
826
|
+
fields: z.array(
|
|
827
|
+
z.enum([
|
|
828
|
+
"commit",
|
|
829
|
+
"branch",
|
|
830
|
+
"tag",
|
|
831
|
+
"dirty",
|
|
832
|
+
"author_name",
|
|
833
|
+
"author_email",
|
|
834
|
+
"commit_message",
|
|
835
|
+
"commit_time",
|
|
836
|
+
"git_diff"
|
|
837
|
+
])
|
|
838
|
+
).optional()
|
|
839
|
+
});
|
|
840
|
+
var Group = z.object({
|
|
841
|
+
id: z.string().uuid(),
|
|
842
|
+
org_id: z.string().uuid(),
|
|
843
|
+
user_id: z.union([z.string(), z.null()]).optional(),
|
|
844
|
+
created: z.union([z.string(), z.null()]).optional(),
|
|
845
|
+
name: z.string(),
|
|
846
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
847
|
+
deleted_at: z.union([z.string(), z.null()]).optional(),
|
|
848
|
+
member_users: z.union([z.array(z.string().uuid()), z.null()]).optional(),
|
|
849
|
+
member_groups: z.union([z.array(z.string().uuid()), z.null()]).optional()
|
|
850
|
+
});
|
|
851
|
+
var IfExists = z.enum(["error", "ignore", "replace"]);
|
|
852
|
+
var InvokeParent = z.union([
|
|
853
|
+
z.object({
|
|
854
|
+
object_type: z.enum(["project_logs", "experiment", "playground_logs"]),
|
|
855
|
+
object_id: z.string(),
|
|
856
|
+
row_ids: z.union([
|
|
857
|
+
z.object({
|
|
858
|
+
id: z.string(),
|
|
859
|
+
span_id: z.string(),
|
|
860
|
+
root_span_id: z.string()
|
|
861
|
+
}),
|
|
862
|
+
z.null()
|
|
863
|
+
]).optional(),
|
|
864
|
+
propagated_event: z.union([z.object({}).partial().passthrough(), z.null()]).optional()
|
|
158
865
|
}),
|
|
866
|
+
z.string()
|
|
867
|
+
]);
|
|
868
|
+
var StreamingMode = z.union([z.enum(["auto", "parallel"]), z.null()]);
|
|
869
|
+
var InvokeFunction = FunctionId.and(
|
|
870
|
+
z.object({
|
|
871
|
+
input: z.unknown(),
|
|
872
|
+
expected: z.unknown(),
|
|
873
|
+
metadata: z.union([z.object({}).partial().passthrough(), z.null()]),
|
|
874
|
+
tags: z.union([z.array(z.string()), z.null()]),
|
|
875
|
+
messages: z.array(ChatCompletionMessageParam),
|
|
876
|
+
parent: InvokeParent,
|
|
877
|
+
stream: z.union([z.boolean(), z.null()]),
|
|
878
|
+
mode: StreamingMode,
|
|
879
|
+
strict: z.union([z.boolean(), z.null()])
|
|
880
|
+
}).partial()
|
|
881
|
+
);
|
|
882
|
+
var MessageRole = z.enum([
|
|
883
|
+
"system",
|
|
884
|
+
"user",
|
|
885
|
+
"assistant",
|
|
886
|
+
"function",
|
|
887
|
+
"tool",
|
|
888
|
+
"model",
|
|
889
|
+
"developer"
|
|
890
|
+
]);
|
|
891
|
+
var OnlineScoreConfig = z.union([
|
|
159
892
|
z.object({
|
|
160
|
-
|
|
161
|
-
|
|
893
|
+
sampling_rate: z.number().gte(0).lte(1),
|
|
894
|
+
scorers: z.array(SavedFunctionId),
|
|
895
|
+
btql_filter: z.union([z.string(), z.null()]).optional(),
|
|
896
|
+
apply_to_root_span: z.union([z.boolean(), z.null()]).optional(),
|
|
897
|
+
apply_to_span_names: z.union([z.array(z.string()), z.null()]).optional(),
|
|
898
|
+
skip_logging: z.union([z.boolean(), z.null()]).optional()
|
|
162
899
|
}),
|
|
900
|
+
z.null()
|
|
901
|
+
]);
|
|
902
|
+
var Organization = z.object({
|
|
903
|
+
id: z.string().uuid(),
|
|
904
|
+
name: z.string(),
|
|
905
|
+
api_url: z.union([z.string(), z.null()]).optional(),
|
|
906
|
+
is_universal_api: z.union([z.boolean(), z.null()]).optional(),
|
|
907
|
+
proxy_url: z.union([z.string(), z.null()]).optional(),
|
|
908
|
+
realtime_url: z.union([z.string(), z.null()]).optional(),
|
|
909
|
+
created: z.union([z.string(), z.null()]).optional()
|
|
910
|
+
});
|
|
911
|
+
var ProjectSettings = z.union([
|
|
912
|
+
z.object({
|
|
913
|
+
comparison_key: z.union([z.string(), z.null()]),
|
|
914
|
+
baseline_experiment_id: z.union([z.string(), z.null()]),
|
|
915
|
+
spanFieldOrder: z.union([
|
|
916
|
+
z.array(
|
|
917
|
+
z.object({
|
|
918
|
+
object_type: z.string(),
|
|
919
|
+
column_id: z.string(),
|
|
920
|
+
position: z.string(),
|
|
921
|
+
layout: z.union([z.literal("full"), z.literal("two_column"), z.null()]).optional()
|
|
922
|
+
})
|
|
923
|
+
),
|
|
924
|
+
z.null()
|
|
925
|
+
]),
|
|
926
|
+
remote_eval_sources: z.union([
|
|
927
|
+
z.array(
|
|
928
|
+
z.object({
|
|
929
|
+
url: z.string(),
|
|
930
|
+
name: z.string(),
|
|
931
|
+
description: z.union([z.string(), z.null()]).optional()
|
|
932
|
+
})
|
|
933
|
+
),
|
|
934
|
+
z.null()
|
|
935
|
+
])
|
|
936
|
+
}).partial(),
|
|
937
|
+
z.null()
|
|
938
|
+
]);
|
|
939
|
+
var Project = z.object({
|
|
940
|
+
id: z.string().uuid(),
|
|
941
|
+
org_id: z.string().uuid(),
|
|
942
|
+
name: z.string(),
|
|
943
|
+
created: z.union([z.string(), z.null()]).optional(),
|
|
944
|
+
deleted_at: z.union([z.string(), z.null()]).optional(),
|
|
945
|
+
user_id: z.union([z.string(), z.null()]).optional(),
|
|
946
|
+
settings: ProjectSettings.optional()
|
|
947
|
+
});
|
|
948
|
+
var RetentionObjectType = z.enum([
|
|
949
|
+
"project_logs",
|
|
950
|
+
"experiment",
|
|
951
|
+
"dataset"
|
|
952
|
+
]);
|
|
953
|
+
var ProjectAutomation = z.object({
|
|
954
|
+
id: z.string().uuid(),
|
|
955
|
+
project_id: z.string().uuid(),
|
|
956
|
+
user_id: z.union([z.string(), z.null()]).optional(),
|
|
957
|
+
created: z.union([z.string(), z.null()]).optional(),
|
|
958
|
+
name: z.string(),
|
|
959
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
960
|
+
config: z.union([
|
|
961
|
+
z.object({
|
|
962
|
+
event_type: z.literal("logs"),
|
|
963
|
+
btql_filter: z.string(),
|
|
964
|
+
interval_seconds: z.number().gte(1).lte(2592e3),
|
|
965
|
+
action: z.object({ type: z.literal("webhook"), url: z.string() })
|
|
966
|
+
}),
|
|
967
|
+
z.object({
|
|
968
|
+
event_type: z.literal("btql_export"),
|
|
969
|
+
export_definition: z.union([
|
|
970
|
+
z.object({ type: z.literal("log_traces") }),
|
|
971
|
+
z.object({ type: z.literal("log_spans") }),
|
|
972
|
+
z.object({ type: z.literal("btql_query"), btql_query: z.string() })
|
|
973
|
+
]),
|
|
974
|
+
export_path: z.string(),
|
|
975
|
+
format: z.enum(["jsonl", "parquet"]),
|
|
976
|
+
interval_seconds: z.number().gte(1).lte(2592e3),
|
|
977
|
+
credentials: z.object({
|
|
978
|
+
type: z.literal("aws_iam"),
|
|
979
|
+
role_arn: z.string(),
|
|
980
|
+
external_id: z.string()
|
|
981
|
+
}),
|
|
982
|
+
batch_size: z.union([z.number(), z.null()]).optional()
|
|
983
|
+
}),
|
|
984
|
+
z.object({
|
|
985
|
+
event_type: z.literal("retention"),
|
|
986
|
+
object_type: RetentionObjectType,
|
|
987
|
+
retention_days: z.number().gte(0)
|
|
988
|
+
})
|
|
989
|
+
])
|
|
990
|
+
});
|
|
991
|
+
var ProjectLogsEvent = z.object({
|
|
992
|
+
id: z.string(),
|
|
993
|
+
_xact_id: z.string(),
|
|
994
|
+
_pagination_key: z.union([z.string(), z.null()]).optional(),
|
|
995
|
+
created: z.string().datetime({ offset: true }),
|
|
996
|
+
org_id: z.string().uuid(),
|
|
997
|
+
project_id: z.string().uuid(),
|
|
998
|
+
log_id: z.literal("g"),
|
|
999
|
+
input: z.unknown().optional(),
|
|
1000
|
+
output: z.unknown().optional(),
|
|
1001
|
+
expected: z.unknown().optional(),
|
|
1002
|
+
error: z.unknown().optional(),
|
|
1003
|
+
scores: z.union([z.record(z.union([z.number(), z.null()])), z.null()]).optional(),
|
|
1004
|
+
metadata: z.union([
|
|
1005
|
+
z.object({ model: z.union([z.string(), z.null()]) }).partial().passthrough(),
|
|
1006
|
+
z.null()
|
|
1007
|
+
]).optional(),
|
|
1008
|
+
tags: z.union([z.array(z.string()), z.null()]).optional(),
|
|
1009
|
+
metrics: z.union([z.record(z.number()), z.null()]).optional(),
|
|
1010
|
+
context: z.union([
|
|
1011
|
+
z.object({
|
|
1012
|
+
caller_functionname: z.union([z.string(), z.null()]),
|
|
1013
|
+
caller_filename: z.union([z.string(), z.null()]),
|
|
1014
|
+
caller_lineno: z.union([z.number(), z.null()])
|
|
1015
|
+
}).partial().passthrough(),
|
|
1016
|
+
z.null()
|
|
1017
|
+
]).optional(),
|
|
1018
|
+
span_id: z.string(),
|
|
1019
|
+
span_parents: z.union([z.array(z.string()), z.null()]).optional(),
|
|
1020
|
+
root_span_id: z.string(),
|
|
1021
|
+
is_root: z.union([z.boolean(), z.null()]).optional(),
|
|
1022
|
+
span_attributes: SpanAttributes.optional(),
|
|
1023
|
+
origin: ObjectReference.optional()
|
|
1024
|
+
});
|
|
1025
|
+
var ProjectScoreType = z.enum([
|
|
1026
|
+
"slider",
|
|
1027
|
+
"categorical",
|
|
1028
|
+
"weighted",
|
|
1029
|
+
"minimum",
|
|
1030
|
+
"maximum",
|
|
1031
|
+
"online",
|
|
1032
|
+
"free-form"
|
|
1033
|
+
]);
|
|
1034
|
+
var ProjectScoreCategory = z.object({
|
|
1035
|
+
name: z.string(),
|
|
1036
|
+
value: z.number()
|
|
1037
|
+
});
|
|
1038
|
+
var ProjectScoreCategories = z.union([
|
|
1039
|
+
z.array(ProjectScoreCategory),
|
|
1040
|
+
z.record(z.number()),
|
|
1041
|
+
z.array(z.string()),
|
|
1042
|
+
z.null()
|
|
1043
|
+
]);
|
|
1044
|
+
var ProjectScoreConfig = z.union([
|
|
163
1045
|
z.object({
|
|
164
|
-
|
|
165
|
-
|
|
1046
|
+
multi_select: z.union([z.boolean(), z.null()]),
|
|
1047
|
+
destination: z.union([z.string(), z.null()]),
|
|
1048
|
+
online: OnlineScoreConfig
|
|
1049
|
+
}).partial(),
|
|
1050
|
+
z.null()
|
|
1051
|
+
]);
|
|
1052
|
+
var ProjectScore = z.object({
|
|
1053
|
+
id: z.string().uuid(),
|
|
1054
|
+
project_id: z.string().uuid(),
|
|
1055
|
+
user_id: z.string().uuid(),
|
|
1056
|
+
created: z.union([z.string(), z.null()]).optional(),
|
|
1057
|
+
name: z.string(),
|
|
1058
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
1059
|
+
score_type: ProjectScoreType,
|
|
1060
|
+
categories: ProjectScoreCategories.optional(),
|
|
1061
|
+
config: ProjectScoreConfig.optional(),
|
|
1062
|
+
position: z.union([z.string(), z.null()]).optional()
|
|
1063
|
+
});
|
|
1064
|
+
var ProjectTag = z.object({
|
|
1065
|
+
id: z.string().uuid(),
|
|
1066
|
+
project_id: z.string().uuid(),
|
|
1067
|
+
user_id: z.string().uuid(),
|
|
1068
|
+
created: z.union([z.string(), z.null()]).optional(),
|
|
1069
|
+
name: z.string(),
|
|
1070
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
1071
|
+
color: z.union([z.string(), z.null()]).optional(),
|
|
1072
|
+
position: z.union([z.string(), z.null()]).optional()
|
|
1073
|
+
});
|
|
1074
|
+
var Prompt = z.object({
|
|
1075
|
+
id: z.string().uuid(),
|
|
1076
|
+
_xact_id: z.string(),
|
|
1077
|
+
project_id: z.string().uuid(),
|
|
1078
|
+
log_id: z.literal("p"),
|
|
1079
|
+
org_id: z.string().uuid(),
|
|
1080
|
+
name: z.string(),
|
|
1081
|
+
slug: z.string(),
|
|
1082
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
1083
|
+
created: z.union([z.string(), z.null()]).optional(),
|
|
1084
|
+
prompt_data: PromptDataNullish.optional(),
|
|
1085
|
+
tags: z.union([z.array(z.string()), z.null()]).optional(),
|
|
1086
|
+
metadata: z.union([z.object({}).partial().passthrough(), z.null()]).optional(),
|
|
1087
|
+
function_type: FunctionTypeEnumNullish.optional()
|
|
1088
|
+
});
|
|
1089
|
+
var PromptOptions = z.object({ model: z.string(), params: ModelParams, position: z.string() }).partial();
|
|
1090
|
+
var PromptSessionEvent = z.object({
|
|
1091
|
+
id: z.string(),
|
|
1092
|
+
_xact_id: z.string(),
|
|
1093
|
+
created: z.string().datetime({ offset: true }),
|
|
1094
|
+
_pagination_key: z.union([z.string(), z.null()]).optional(),
|
|
1095
|
+
project_id: z.string().uuid(),
|
|
1096
|
+
prompt_session_id: z.string().uuid(),
|
|
1097
|
+
prompt_session_data: z.unknown().optional(),
|
|
1098
|
+
prompt_data: z.unknown().optional(),
|
|
1099
|
+
function_data: z.unknown().optional(),
|
|
1100
|
+
function_type: FunctionTypeEnumNullish.optional(),
|
|
1101
|
+
object_data: z.unknown().optional(),
|
|
1102
|
+
completion: z.unknown().optional(),
|
|
1103
|
+
tags: z.union([z.array(z.string()), z.null()]).optional()
|
|
1104
|
+
});
|
|
1105
|
+
var Role = z.object({
|
|
1106
|
+
id: z.string().uuid(),
|
|
1107
|
+
org_id: z.union([z.string(), z.null()]).optional(),
|
|
1108
|
+
user_id: z.union([z.string(), z.null()]).optional(),
|
|
1109
|
+
created: z.union([z.string(), z.null()]).optional(),
|
|
1110
|
+
name: z.string(),
|
|
1111
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
1112
|
+
deleted_at: z.union([z.string(), z.null()]).optional(),
|
|
1113
|
+
member_permissions: z.union([
|
|
1114
|
+
z.array(
|
|
1115
|
+
z.object({
|
|
1116
|
+
permission: Permission,
|
|
1117
|
+
restrict_object_type: AclObjectType.optional()
|
|
1118
|
+
})
|
|
1119
|
+
),
|
|
1120
|
+
z.null()
|
|
1121
|
+
]).optional(),
|
|
1122
|
+
member_roles: z.union([z.array(z.string().uuid()), z.null()]).optional()
|
|
1123
|
+
});
|
|
1124
|
+
var RunEval = z.object({
|
|
1125
|
+
project_id: z.string(),
|
|
1126
|
+
data: z.union([
|
|
1127
|
+
z.object({
|
|
1128
|
+
dataset_id: z.string(),
|
|
1129
|
+
_internal_btql: z.union([z.object({}).partial().passthrough(), z.null()]).optional()
|
|
1130
|
+
}),
|
|
1131
|
+
z.object({
|
|
1132
|
+
project_name: z.string(),
|
|
1133
|
+
dataset_name: z.string(),
|
|
1134
|
+
_internal_btql: z.union([z.object({}).partial().passthrough(), z.null()]).optional()
|
|
1135
|
+
}),
|
|
1136
|
+
z.object({ data: z.array(z.unknown()) })
|
|
1137
|
+
]),
|
|
1138
|
+
task: FunctionId.and(z.unknown()),
|
|
1139
|
+
scores: z.array(FunctionId),
|
|
1140
|
+
experiment_name: z.string().optional(),
|
|
1141
|
+
metadata: z.object({}).partial().passthrough().optional(),
|
|
1142
|
+
parent: InvokeParent.and(z.unknown()).optional(),
|
|
1143
|
+
stream: z.boolean().optional(),
|
|
1144
|
+
trial_count: z.union([z.number(), z.null()]).optional(),
|
|
1145
|
+
is_public: z.union([z.boolean(), z.null()]).optional(),
|
|
1146
|
+
timeout: z.union([z.number(), z.null()]).optional(),
|
|
1147
|
+
max_concurrency: z.union([z.number(), z.null()]).optional().default(10),
|
|
1148
|
+
base_experiment_name: z.union([z.string(), z.null()]).optional(),
|
|
1149
|
+
base_experiment_id: z.union([z.string(), z.null()]).optional(),
|
|
1150
|
+
git_metadata_settings: GitMetadataSettings.and(
|
|
1151
|
+
z.union([z.object({}).partial(), z.null()])
|
|
1152
|
+
).optional(),
|
|
1153
|
+
repo_info: RepoInfo.and(z.unknown()).optional(),
|
|
1154
|
+
strict: z.union([z.boolean(), z.null()]).optional(),
|
|
1155
|
+
stop_token: z.union([z.string(), z.null()]).optional(),
|
|
1156
|
+
extra_messages: z.string().optional(),
|
|
1157
|
+
tags: z.array(z.string()).optional()
|
|
1158
|
+
});
|
|
1159
|
+
var ServiceToken = z.object({
|
|
1160
|
+
id: z.string().uuid(),
|
|
1161
|
+
created: z.union([z.string(), z.null()]).optional(),
|
|
1162
|
+
name: z.string(),
|
|
1163
|
+
preview_name: z.string(),
|
|
1164
|
+
user_id: z.union([z.string(), z.null()]).optional(),
|
|
1165
|
+
user_email: z.union([z.string(), z.null()]).optional(),
|
|
1166
|
+
user_given_name: z.union([z.string(), z.null()]).optional(),
|
|
1167
|
+
user_family_name: z.union([z.string(), z.null()]).optional(),
|
|
1168
|
+
org_id: z.union([z.string(), z.null()]).optional()
|
|
1169
|
+
});
|
|
1170
|
+
var SpanIFrame = z.object({
|
|
1171
|
+
id: z.string().uuid(),
|
|
1172
|
+
project_id: z.string().uuid(),
|
|
1173
|
+
user_id: z.union([z.string(), z.null()]).optional(),
|
|
1174
|
+
created: z.union([z.string(), z.null()]).optional(),
|
|
1175
|
+
deleted_at: z.union([z.string(), z.null()]).optional(),
|
|
1176
|
+
name: z.string(),
|
|
1177
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
1178
|
+
url: z.string(),
|
|
1179
|
+
post_message: z.union([z.boolean(), z.null()]).optional()
|
|
1180
|
+
});
|
|
1181
|
+
var SSEConsoleEventData = z.object({
|
|
1182
|
+
stream: z.enum(["stderr", "stdout"]),
|
|
1183
|
+
message: z.string()
|
|
1184
|
+
});
|
|
1185
|
+
var SSEProgressEventData = z.object({
|
|
1186
|
+
id: z.string(),
|
|
1187
|
+
object_type: FunctionObjectType,
|
|
1188
|
+
origin: ObjectReference.and(z.unknown()).optional(),
|
|
1189
|
+
format: FunctionFormat,
|
|
1190
|
+
output_type: FunctionOutputType,
|
|
1191
|
+
name: z.string(),
|
|
1192
|
+
event: z.enum([
|
|
1193
|
+
"reasoning_delta",
|
|
1194
|
+
"text_delta",
|
|
1195
|
+
"json_delta",
|
|
1196
|
+
"error",
|
|
1197
|
+
"console",
|
|
1198
|
+
"start",
|
|
1199
|
+
"done",
|
|
1200
|
+
"progress"
|
|
1201
|
+
]),
|
|
1202
|
+
data: z.string()
|
|
1203
|
+
});
|
|
1204
|
+
var ToolFunctionDefinition = z.object({
|
|
1205
|
+
type: z.literal("function"),
|
|
1206
|
+
function: z.object({
|
|
1207
|
+
name: z.string(),
|
|
1208
|
+
description: z.string().optional(),
|
|
1209
|
+
parameters: z.object({}).partial().passthrough().optional(),
|
|
1210
|
+
strict: z.union([z.boolean(), z.null()]).optional()
|
|
1211
|
+
})
|
|
1212
|
+
});
|
|
1213
|
+
var User = z.object({
|
|
1214
|
+
id: z.string().uuid(),
|
|
1215
|
+
given_name: z.union([z.string(), z.null()]).optional(),
|
|
1216
|
+
family_name: z.union([z.string(), z.null()]).optional(),
|
|
1217
|
+
email: z.union([z.string(), z.null()]).optional(),
|
|
1218
|
+
avatar_url: z.union([z.string(), z.null()]).optional(),
|
|
1219
|
+
created: z.union([z.string(), z.null()]).optional()
|
|
1220
|
+
});
|
|
1221
|
+
var ViewDataSearch = z.union([
|
|
1222
|
+
z.object({
|
|
1223
|
+
filter: z.union([z.array(z.unknown()), z.null()]),
|
|
1224
|
+
tag: z.union([z.array(z.unknown()), z.null()]),
|
|
1225
|
+
match: z.union([z.array(z.unknown()), z.null()]),
|
|
1226
|
+
sort: z.union([z.array(z.unknown()), z.null()])
|
|
1227
|
+
}).partial(),
|
|
1228
|
+
z.null()
|
|
1229
|
+
]);
|
|
1230
|
+
var ViewData = z.union([
|
|
1231
|
+
z.object({ search: ViewDataSearch }).partial(),
|
|
1232
|
+
z.null()
|
|
1233
|
+
]);
|
|
1234
|
+
var ViewOptions = z.union([
|
|
1235
|
+
z.object({
|
|
1236
|
+
viewType: z.literal("monitor"),
|
|
1237
|
+
options: z.object({
|
|
1238
|
+
spanType: z.union([z.enum(["range", "frame"]), z.null()]),
|
|
1239
|
+
rangeValue: z.union([z.string(), z.null()]),
|
|
1240
|
+
frameStart: z.union([z.string(), z.null()]),
|
|
1241
|
+
frameEnd: z.union([z.string(), z.null()]),
|
|
1242
|
+
tzUTC: z.union([z.boolean(), z.null()]),
|
|
1243
|
+
chartVisibility: z.union([z.record(z.boolean()), z.null()]),
|
|
1244
|
+
projectId: z.union([z.string(), z.null()]),
|
|
1245
|
+
type: z.union([z.enum(["project", "experiment"]), z.null()]),
|
|
1246
|
+
groupBy: z.union([z.string(), z.null()])
|
|
1247
|
+
}).partial()
|
|
166
1248
|
}),
|
|
167
1249
|
z.object({
|
|
168
|
-
|
|
169
|
-
|
|
1250
|
+
columnVisibility: z.union([z.record(z.boolean()), z.null()]),
|
|
1251
|
+
columnOrder: z.union([z.array(z.string()), z.null()]),
|
|
1252
|
+
columnSizing: z.union([z.record(z.number()), z.null()]),
|
|
1253
|
+
grouping: z.union([z.string(), z.null()]),
|
|
1254
|
+
rowHeight: z.union([z.string(), z.null()]),
|
|
1255
|
+
tallGroupRows: z.union([z.boolean(), z.null()]),
|
|
1256
|
+
layout: z.union([z.string(), z.null()]),
|
|
1257
|
+
chartHeight: z.union([z.number(), z.null()]),
|
|
1258
|
+
excludedMeasures: z.union([
|
|
1259
|
+
z.array(
|
|
1260
|
+
z.object({
|
|
1261
|
+
type: z.enum(["none", "score", "metric", "metadata"]),
|
|
1262
|
+
value: z.string()
|
|
1263
|
+
})
|
|
1264
|
+
),
|
|
1265
|
+
z.null()
|
|
1266
|
+
]),
|
|
1267
|
+
yMetric: z.union([
|
|
1268
|
+
z.object({
|
|
1269
|
+
type: z.enum(["none", "score", "metric", "metadata"]),
|
|
1270
|
+
value: z.string()
|
|
1271
|
+
}),
|
|
1272
|
+
z.null()
|
|
1273
|
+
]),
|
|
1274
|
+
xAxis: z.union([
|
|
1275
|
+
z.object({
|
|
1276
|
+
type: z.enum(["none", "score", "metric", "metadata"]),
|
|
1277
|
+
value: z.string()
|
|
1278
|
+
}),
|
|
1279
|
+
z.null()
|
|
1280
|
+
]),
|
|
1281
|
+
symbolGrouping: z.union([
|
|
1282
|
+
z.object({
|
|
1283
|
+
type: z.enum(["none", "score", "metric", "metadata"]),
|
|
1284
|
+
value: z.string()
|
|
1285
|
+
}),
|
|
1286
|
+
z.null()
|
|
1287
|
+
]),
|
|
1288
|
+
xAxisAggregation: z.union([z.string(), z.null()]),
|
|
1289
|
+
chartAnnotations: z.union([
|
|
1290
|
+
z.array(z.object({ id: z.string(), text: z.string() })),
|
|
1291
|
+
z.null()
|
|
1292
|
+
]),
|
|
1293
|
+
timeRangeFilter: z.union([
|
|
1294
|
+
z.string(),
|
|
1295
|
+
z.object({ from: z.string(), to: z.string() }),
|
|
1296
|
+
z.null()
|
|
1297
|
+
])
|
|
1298
|
+
}).partial(),
|
|
1299
|
+
z.null()
|
|
1300
|
+
]);
|
|
1301
|
+
var View = z.object({
|
|
1302
|
+
id: z.string().uuid(),
|
|
1303
|
+
object_type: AclObjectType.and(z.string()),
|
|
1304
|
+
object_id: z.string().uuid(),
|
|
1305
|
+
view_type: z.enum([
|
|
1306
|
+
"projects",
|
|
1307
|
+
"experiments",
|
|
1308
|
+
"experiment",
|
|
1309
|
+
"playgrounds",
|
|
1310
|
+
"playground",
|
|
1311
|
+
"datasets",
|
|
1312
|
+
"dataset",
|
|
1313
|
+
"prompts",
|
|
1314
|
+
"tools",
|
|
1315
|
+
"scorers",
|
|
1316
|
+
"logs",
|
|
1317
|
+
"agents",
|
|
1318
|
+
"monitor"
|
|
1319
|
+
]),
|
|
1320
|
+
name: z.string(),
|
|
1321
|
+
created: z.union([z.string(), z.null()]).optional(),
|
|
1322
|
+
view_data: ViewData.optional(),
|
|
1323
|
+
options: ViewOptions.optional(),
|
|
1324
|
+
user_id: z.union([z.string(), z.null()]).optional(),
|
|
1325
|
+
deleted_at: z.union([z.string(), z.null()]).optional()
|
|
1326
|
+
});
|
|
1327
|
+
|
|
1328
|
+
// src/logger.ts
|
|
1329
|
+
import { waitUntil } from "@vercel/functions";
|
|
1330
|
+
import Mustache2 from "mustache";
|
|
1331
|
+
import { z as z3, ZodError } from "zod";
|
|
1332
|
+
|
|
1333
|
+
// src/functions/stream.ts
|
|
1334
|
+
import {
|
|
1335
|
+
createParser
|
|
1336
|
+
} from "eventsource-parser";
|
|
1337
|
+
import { z as z2 } from "zod";
|
|
1338
|
+
var braintrustStreamChunkSchema = z2.union([
|
|
1339
|
+
z2.object({
|
|
1340
|
+
type: z2.literal("text_delta"),
|
|
1341
|
+
data: z2.string()
|
|
1342
|
+
}),
|
|
1343
|
+
z2.object({
|
|
1344
|
+
type: z2.literal("reasoning_delta"),
|
|
1345
|
+
data: z2.string()
|
|
1346
|
+
}),
|
|
1347
|
+
z2.object({
|
|
1348
|
+
type: z2.literal("json_delta"),
|
|
1349
|
+
data: z2.string()
|
|
1350
|
+
}),
|
|
1351
|
+
z2.object({
|
|
1352
|
+
type: z2.literal("error"),
|
|
1353
|
+
data: z2.string()
|
|
1354
|
+
}),
|
|
1355
|
+
z2.object({
|
|
1356
|
+
type: z2.literal("console"),
|
|
1357
|
+
data: SSEConsoleEventData
|
|
1358
|
+
}),
|
|
1359
|
+
z2.object({
|
|
1360
|
+
type: z2.literal("progress"),
|
|
1361
|
+
data: SSEProgressEventData
|
|
1362
|
+
}),
|
|
1363
|
+
z2.object({
|
|
1364
|
+
type: z2.literal("start"),
|
|
1365
|
+
data: z2.string()
|
|
1366
|
+
}),
|
|
1367
|
+
z2.object({
|
|
1368
|
+
type: z2.literal("done"),
|
|
1369
|
+
data: z2.string()
|
|
170
1370
|
})
|
|
171
1371
|
]);
|
|
172
1372
|
var BraintrustStream = class _BraintrustStream {
|
|
@@ -274,12 +1474,12 @@ var BraintrustStream = class _BraintrustStream {
|
|
|
274
1474
|
case "progress":
|
|
275
1475
|
return {
|
|
276
1476
|
type: "progress",
|
|
277
|
-
data:
|
|
1477
|
+
data: SSEProgressEventData.parse(JSON.parse(event.data))
|
|
278
1478
|
};
|
|
279
1479
|
case "console":
|
|
280
1480
|
return {
|
|
281
1481
|
type: "console",
|
|
282
|
-
data:
|
|
1482
|
+
data: SSEConsoleEventData.parse(JSON.parse(event.data))
|
|
283
1483
|
};
|
|
284
1484
|
case "start":
|
|
285
1485
|
return {
|
|
@@ -355,7 +1555,7 @@ function btStreamParser() {
|
|
|
355
1555
|
if (event.type === "reconnect-interval") {
|
|
356
1556
|
return;
|
|
357
1557
|
}
|
|
358
|
-
const parsed =
|
|
1558
|
+
const parsed = CallEvent.safeParse(event);
|
|
359
1559
|
if (!parsed.success) {
|
|
360
1560
|
throw new Error(`Failed to parse event: ${parsed.error}`);
|
|
361
1561
|
}
|
|
@@ -780,6 +1980,44 @@ function getMustacheVars(prompt) {
|
|
|
780
1980
|
}
|
|
781
1981
|
|
|
782
1982
|
// src/logger.ts
|
|
1983
|
+
import { prettifyXact } from "@braintrust/core";
|
|
1984
|
+
var BRAINTRUST_ATTACHMENT = BraintrustAttachmentReference.shape.type.value;
|
|
1985
|
+
var EXTERNAL_ATTACHMENT = ExternalAttachmentReference.shape.type.value;
|
|
1986
|
+
var BRAINTRUST_PARAMS = Object.keys(BraintrustModelParams.shape);
|
|
1987
|
+
var REDACTION_FIELDS = [
|
|
1988
|
+
"input",
|
|
1989
|
+
"output",
|
|
1990
|
+
"expected",
|
|
1991
|
+
"metadata",
|
|
1992
|
+
"context",
|
|
1993
|
+
"scores",
|
|
1994
|
+
"metrics"
|
|
1995
|
+
];
|
|
1996
|
+
var MaskingError = class {
|
|
1997
|
+
constructor(fieldName, errorType) {
|
|
1998
|
+
this.fieldName = fieldName;
|
|
1999
|
+
this.errorType = errorType;
|
|
2000
|
+
}
|
|
2001
|
+
get errorMsg() {
|
|
2002
|
+
return `ERROR: Failed to mask field '${this.fieldName}' - ${this.errorType}`;
|
|
2003
|
+
}
|
|
2004
|
+
};
|
|
2005
|
+
function applyMaskingToField(maskingFunction, data, fieldName) {
|
|
2006
|
+
try {
|
|
2007
|
+
return maskingFunction(data);
|
|
2008
|
+
} catch (error) {
|
|
2009
|
+
const errorType = error instanceof Error ? error.constructor.name : "Error";
|
|
2010
|
+
if (fieldName === "scores" || fieldName === "metrics") {
|
|
2011
|
+
return new MaskingError(fieldName, errorType);
|
|
2012
|
+
}
|
|
2013
|
+
if (fieldName === "metadata") {
|
|
2014
|
+
return {
|
|
2015
|
+
error: `ERROR: Failed to mask field '${fieldName}' - ${errorType}`
|
|
2016
|
+
};
|
|
2017
|
+
}
|
|
2018
|
+
return `ERROR: Failed to mask field '${fieldName}' - ${errorType}`;
|
|
2019
|
+
}
|
|
2020
|
+
}
|
|
783
2021
|
var NoopSpan = class {
|
|
784
2022
|
id;
|
|
785
2023
|
spanId;
|
|
@@ -830,15 +2068,15 @@ var NoopSpan = class {
|
|
|
830
2068
|
};
|
|
831
2069
|
var NOOP_SPAN = new NoopSpan();
|
|
832
2070
|
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:
|
|
2071
|
+
var loginSchema = z3.strictObject({
|
|
2072
|
+
appUrl: z3.string(),
|
|
2073
|
+
appPublicUrl: z3.string(),
|
|
2074
|
+
orgName: z3.string(),
|
|
2075
|
+
apiUrl: z3.string(),
|
|
2076
|
+
proxyUrl: z3.string(),
|
|
2077
|
+
loginToken: z3.string(),
|
|
2078
|
+
orgId: z3.string().nullish(),
|
|
2079
|
+
gitMetadataSettings: GitMetadataSettings.nullish()
|
|
842
2080
|
});
|
|
843
2081
|
var stateNonce = 0;
|
|
844
2082
|
var BraintrustState = class _BraintrustState {
|
|
@@ -980,6 +2218,9 @@ var BraintrustState = class _BraintrustState {
|
|
|
980
2218
|
this._apiConn?.setFetch(fetch2);
|
|
981
2219
|
this._appConn?.setFetch(fetch2);
|
|
982
2220
|
}
|
|
2221
|
+
setMaskingFunction(maskingFunction) {
|
|
2222
|
+
this.bgLogger().setMaskingFunction(maskingFunction);
|
|
2223
|
+
}
|
|
983
2224
|
async login(loginParams) {
|
|
984
2225
|
if (this.apiUrl && !loginParams.forceLogin) {
|
|
985
2226
|
return;
|
|
@@ -1058,6 +2299,18 @@ function useTestBackgroundLogger() {
|
|
|
1058
2299
|
function clearTestBackgroundLogger() {
|
|
1059
2300
|
_internalGetGlobalState()?.setOverrideBgLogger(null);
|
|
1060
2301
|
}
|
|
2302
|
+
function initTestExperiment(experimentName, projectName) {
|
|
2303
|
+
setInitialTestState();
|
|
2304
|
+
const state = _internalGetGlobalState();
|
|
2305
|
+
const project = projectName ?? experimentName;
|
|
2306
|
+
const lazyMetadata = new LazyValue(
|
|
2307
|
+
async () => ({
|
|
2308
|
+
project: { id: project, name: project, fullInfo: {} },
|
|
2309
|
+
experiment: { id: experimentName, name: experimentName, fullInfo: {} }
|
|
2310
|
+
})
|
|
2311
|
+
);
|
|
2312
|
+
return new Experiment2(state, lazyMetadata);
|
|
2313
|
+
}
|
|
1061
2314
|
function _internalSetInitialState() {
|
|
1062
2315
|
if (_globalState) {
|
|
1063
2316
|
console.warn(
|
|
@@ -1299,9 +2552,9 @@ var Attachment = class extends BaseAttachment {
|
|
|
1299
2552
|
let signedUrl;
|
|
1300
2553
|
let headers;
|
|
1301
2554
|
try {
|
|
1302
|
-
({ signedUrl, headers } =
|
|
1303
|
-
signedUrl:
|
|
1304
|
-
headers:
|
|
2555
|
+
({ signedUrl, headers } = z3.object({
|
|
2556
|
+
signedUrl: z3.string().url(),
|
|
2557
|
+
headers: z3.record(z3.string())
|
|
1305
2558
|
}).parse(await metadataResponse.json()));
|
|
1306
2559
|
} catch (error) {
|
|
1307
2560
|
if (error instanceof ZodError) {
|
|
@@ -1361,6 +2614,7 @@ var Attachment = class extends BaseAttachment {
|
|
|
1361
2614
|
}
|
|
1362
2615
|
initData(data) {
|
|
1363
2616
|
if (typeof data === "string") {
|
|
2617
|
+
this.ensureFileReadable(data);
|
|
1364
2618
|
const readFile = isomorph_default.readFile;
|
|
1365
2619
|
if (!readFile) {
|
|
1366
2620
|
throw new Error(
|
|
@@ -1373,6 +2627,20 @@ with a Blob/ArrayBuffer, or run the program on Node.js.`
|
|
|
1373
2627
|
return new LazyValue(async () => new Blob([data]));
|
|
1374
2628
|
}
|
|
1375
2629
|
}
|
|
2630
|
+
ensureFileReadable(data) {
|
|
2631
|
+
const statSync = isomorph_default.statSync;
|
|
2632
|
+
if (!statSync) {
|
|
2633
|
+
throw new Error(
|
|
2634
|
+
`This platform does not support reading the filesystem. Construct the Attachment
|
|
2635
|
+
with a Blob/ArrayBuffer, or run the program on Node.js.`
|
|
2636
|
+
);
|
|
2637
|
+
}
|
|
2638
|
+
try {
|
|
2639
|
+
statSync(data);
|
|
2640
|
+
} catch (e) {
|
|
2641
|
+
console.warn(`Failed to read file: ${e}`);
|
|
2642
|
+
}
|
|
2643
|
+
}
|
|
1376
2644
|
};
|
|
1377
2645
|
var ExternalAttachment = class extends BaseAttachment {
|
|
1378
2646
|
/**
|
|
@@ -1441,9 +2709,9 @@ var ExternalAttachment = class extends BaseAttachment {
|
|
|
1441
2709
|
});
|
|
1442
2710
|
}
|
|
1443
2711
|
};
|
|
1444
|
-
var attachmentMetadataSchema =
|
|
1445
|
-
downloadUrl:
|
|
1446
|
-
status:
|
|
2712
|
+
var attachmentMetadataSchema = z3.object({
|
|
2713
|
+
downloadUrl: z3.string(),
|
|
2714
|
+
status: AttachmentStatus
|
|
1447
2715
|
});
|
|
1448
2716
|
var ReadonlyAttachment = class {
|
|
1449
2717
|
/**
|
|
@@ -1982,9 +3250,13 @@ function now() {
|
|
|
1982
3250
|
}
|
|
1983
3251
|
var TestBackgroundLogger = class {
|
|
1984
3252
|
items = [];
|
|
3253
|
+
maskingFunction = null;
|
|
1985
3254
|
log(items) {
|
|
1986
3255
|
this.items.push(items);
|
|
1987
3256
|
}
|
|
3257
|
+
setMaskingFunction(maskingFunction) {
|
|
3258
|
+
this.maskingFunction = maskingFunction;
|
|
3259
|
+
}
|
|
1988
3260
|
async flush() {
|
|
1989
3261
|
return Promise.resolve();
|
|
1990
3262
|
}
|
|
@@ -1998,7 +3270,34 @@ var TestBackgroundLogger = class {
|
|
|
1998
3270
|
}
|
|
1999
3271
|
}
|
|
2000
3272
|
const batch = mergeRowBatch(events);
|
|
2001
|
-
|
|
3273
|
+
let flatBatch = batch.flat();
|
|
3274
|
+
if (this.maskingFunction) {
|
|
3275
|
+
flatBatch = flatBatch.map((item) => {
|
|
3276
|
+
const maskedItem = { ...item };
|
|
3277
|
+
for (const field of REDACTION_FIELDS) {
|
|
3278
|
+
if (item[field] !== void 0) {
|
|
3279
|
+
const maskedValue = applyMaskingToField(
|
|
3280
|
+
this.maskingFunction,
|
|
3281
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3282
|
+
item[field],
|
|
3283
|
+
field
|
|
3284
|
+
);
|
|
3285
|
+
if (maskedValue instanceof MaskingError) {
|
|
3286
|
+
delete maskedItem[field];
|
|
3287
|
+
if (maskedItem.error) {
|
|
3288
|
+
maskedItem.error = `${maskedItem.error}; ${maskedValue.errorMsg}`;
|
|
3289
|
+
} else {
|
|
3290
|
+
maskedItem.error = maskedValue.errorMsg;
|
|
3291
|
+
}
|
|
3292
|
+
} else {
|
|
3293
|
+
maskedItem[field] = maskedValue;
|
|
3294
|
+
}
|
|
3295
|
+
}
|
|
3296
|
+
}
|
|
3297
|
+
return maskedItem;
|
|
3298
|
+
});
|
|
3299
|
+
}
|
|
3300
|
+
return flatBatch;
|
|
2002
3301
|
}
|
|
2003
3302
|
};
|
|
2004
3303
|
var BACKGROUND_LOGGER_BASE_SLEEP_TIME_S = 1;
|
|
@@ -2009,6 +3308,7 @@ var HTTPBackgroundLogger = class _HTTPBackgroundLogger {
|
|
|
2009
3308
|
activeFlushResolved = true;
|
|
2010
3309
|
activeFlushError = void 0;
|
|
2011
3310
|
onFlushError;
|
|
3311
|
+
maskingFunction = null;
|
|
2012
3312
|
syncFlush = false;
|
|
2013
3313
|
// 6 MB for the AWS lambda gateway (from our own testing).
|
|
2014
3314
|
maxRequestSize = 6 * 1024 * 1024;
|
|
@@ -2076,6 +3376,9 @@ var HTTPBackgroundLogger = class _HTTPBackgroundLogger {
|
|
|
2076
3376
|
}
|
|
2077
3377
|
this.onFlushError = opts.onFlushError;
|
|
2078
3378
|
}
|
|
3379
|
+
setMaskingFunction(maskingFunction) {
|
|
3380
|
+
this.maskingFunction = maskingFunction;
|
|
3381
|
+
}
|
|
2079
3382
|
log(items) {
|
|
2080
3383
|
if (this._disabled) {
|
|
2081
3384
|
return;
|
|
@@ -2172,7 +3475,36 @@ var HTTPBackgroundLogger = class _HTTPBackgroundLogger {
|
|
|
2172
3475
|
const items = await Promise.all(wrappedItems.map((x) => x.get()));
|
|
2173
3476
|
const attachments = [];
|
|
2174
3477
|
items.forEach((item) => extractAttachments(item, attachments));
|
|
2175
|
-
|
|
3478
|
+
let mergedItems = mergeRowBatch(items);
|
|
3479
|
+
if (this.maskingFunction) {
|
|
3480
|
+
mergedItems = mergedItems.map(
|
|
3481
|
+
(batch) => batch.map((item) => {
|
|
3482
|
+
const maskedItem = { ...item };
|
|
3483
|
+
for (const field of REDACTION_FIELDS) {
|
|
3484
|
+
if (item[field] !== void 0) {
|
|
3485
|
+
const maskedValue = applyMaskingToField(
|
|
3486
|
+
this.maskingFunction,
|
|
3487
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3488
|
+
item[field],
|
|
3489
|
+
field
|
|
3490
|
+
);
|
|
3491
|
+
if (maskedValue instanceof MaskingError) {
|
|
3492
|
+
delete maskedItem[field];
|
|
3493
|
+
if (maskedItem.error) {
|
|
3494
|
+
maskedItem.error = `${maskedItem.error}; ${maskedValue.errorMsg}`;
|
|
3495
|
+
} else {
|
|
3496
|
+
maskedItem.error = maskedValue.errorMsg;
|
|
3497
|
+
}
|
|
3498
|
+
} else {
|
|
3499
|
+
maskedItem[field] = maskedValue;
|
|
3500
|
+
}
|
|
3501
|
+
}
|
|
3502
|
+
}
|
|
3503
|
+
return maskedItem;
|
|
3504
|
+
})
|
|
3505
|
+
);
|
|
3506
|
+
}
|
|
3507
|
+
return [mergedItems, attachments];
|
|
2176
3508
|
} catch (e) {
|
|
2177
3509
|
let errmsg = "Encountered error when constructing records to flush";
|
|
2178
3510
|
const isRetrying = i + 1 < this.numTries;
|
|
@@ -2520,7 +3852,7 @@ function init(projectOrOptions, optionalOptions) {
|
|
|
2520
3852
|
};
|
|
2521
3853
|
}
|
|
2522
3854
|
);
|
|
2523
|
-
const ret = new
|
|
3855
|
+
const ret = new Experiment2(state, lazyMetadata, dataset);
|
|
2524
3856
|
if (options.setCurrent ?? true) {
|
|
2525
3857
|
state.currentExperiment = ret;
|
|
2526
3858
|
}
|
|
@@ -2617,7 +3949,7 @@ function initDataset(projectOrOptions, optionalOptions) {
|
|
|
2617
3949
|
};
|
|
2618
3950
|
}
|
|
2619
3951
|
);
|
|
2620
|
-
return new
|
|
3952
|
+
return new Dataset2(
|
|
2621
3953
|
stateArg ?? _globalState,
|
|
2622
3954
|
lazyMetadata,
|
|
2623
3955
|
version,
|
|
@@ -2813,8 +4145,8 @@ async function loadPrompt({
|
|
|
2813
4145
|
);
|
|
2814
4146
|
}
|
|
2815
4147
|
}
|
|
2816
|
-
const metadata =
|
|
2817
|
-
const prompt = new
|
|
4148
|
+
const metadata = Prompt.parse(response["objects"][0]);
|
|
4149
|
+
const prompt = new Prompt2(metadata, defaults || {}, noTrace);
|
|
2818
4150
|
try {
|
|
2819
4151
|
if (id) {
|
|
2820
4152
|
await state.promptCache.set({ id }, prompt);
|
|
@@ -2829,6 +4161,9 @@ async function loadPrompt({
|
|
|
2829
4161
|
}
|
|
2830
4162
|
return prompt;
|
|
2831
4163
|
}
|
|
4164
|
+
function setMaskingFunction(maskingFunction) {
|
|
4165
|
+
_globalState.setMaskingFunction(maskingFunction);
|
|
4166
|
+
}
|
|
2832
4167
|
async function login(options = {}) {
|
|
2833
4168
|
const { forceLogin = false } = options || {};
|
|
2834
4169
|
if (_globalState.loggedIn && !forceLogin) {
|
|
@@ -3353,13 +4688,13 @@ function validateAndSanitizeExperimentLogPartialArgs(event) {
|
|
|
3353
4688
|
function deepCopyEvent(event) {
|
|
3354
4689
|
const attachments = [];
|
|
3355
4690
|
const IDENTIFIER = "_bt_internal_saved_attachment";
|
|
3356
|
-
const savedAttachmentSchema =
|
|
4691
|
+
const savedAttachmentSchema = z3.strictObject({ [IDENTIFIER]: z3.number() });
|
|
3357
4692
|
const serialized = JSON.stringify(event, (_k, v) => {
|
|
3358
4693
|
if (v instanceof SpanImpl || v instanceof NoopSpan) {
|
|
3359
4694
|
return `<span>`;
|
|
3360
|
-
} else if (v instanceof
|
|
4695
|
+
} else if (v instanceof Experiment2) {
|
|
3361
4696
|
return `<experiment>`;
|
|
3362
|
-
} else if (v instanceof
|
|
4697
|
+
} else if (v instanceof Dataset2) {
|
|
3363
4698
|
return `<dataset>`;
|
|
3364
4699
|
} else if (v instanceof Logger) {
|
|
3365
4700
|
return `<logger>`;
|
|
@@ -3411,7 +4746,7 @@ function extractAttachments(event, attachments) {
|
|
|
3411
4746
|
}
|
|
3412
4747
|
function enrichAttachments(event, state) {
|
|
3413
4748
|
for (const [key, value] of Object.entries(event)) {
|
|
3414
|
-
const parsedValue =
|
|
4749
|
+
const parsedValue = AttachmentReference.safeParse(value);
|
|
3415
4750
|
if (parsedValue.success) {
|
|
3416
4751
|
event[key] = new ReadonlyAttachment(parsedValue.data, state);
|
|
3417
4752
|
continue;
|
|
@@ -3554,7 +4889,7 @@ var ObjectFetcher = class {
|
|
|
3554
4889
|
}
|
|
3555
4890
|
}
|
|
3556
4891
|
};
|
|
3557
|
-
var
|
|
4892
|
+
var Experiment2 = class extends ObjectFetcher {
|
|
3558
4893
|
lazyMetadata;
|
|
3559
4894
|
dataset;
|
|
3560
4895
|
lastStartTime;
|
|
@@ -4160,7 +5495,7 @@ function splitLoggingData({
|
|
|
4160
5495
|
}
|
|
4161
5496
|
return [serializableInternalData, lazyInternalData];
|
|
4162
5497
|
}
|
|
4163
|
-
var
|
|
5498
|
+
var Dataset2 = class extends ObjectFetcher {
|
|
4164
5499
|
constructor(state, lazyMetadata, pinnedVersion, legacy, _internal_btql) {
|
|
4165
5500
|
const isLegacyDataset = legacy ?? DEFAULT_IS_LEGACY_DATASET;
|
|
4166
5501
|
if (isLegacyDataset) {
|
|
@@ -4358,8 +5693,8 @@ var Dataset = class extends ObjectFetcher {
|
|
|
4358
5693
|
)}`;
|
|
4359
5694
|
let dataSummary;
|
|
4360
5695
|
if (summarizeData) {
|
|
4361
|
-
const rawDataSummary =
|
|
4362
|
-
total_records:
|
|
5696
|
+
const rawDataSummary = z3.object({
|
|
5697
|
+
total_records: z3.number()
|
|
4363
5698
|
}).parse(
|
|
4364
5699
|
await state.apiConn().get_json(
|
|
4365
5700
|
"dataset-summary",
|
|
@@ -4482,11 +5817,11 @@ function renderTemplatedObject(obj, args, options) {
|
|
|
4482
5817
|
return obj;
|
|
4483
5818
|
}
|
|
4484
5819
|
function renderPromptParams(params, args, options) {
|
|
4485
|
-
const schemaParsed =
|
|
4486
|
-
response_format:
|
|
4487
|
-
type:
|
|
4488
|
-
json_schema:
|
|
4489
|
-
schema:
|
|
5820
|
+
const schemaParsed = z3.object({
|
|
5821
|
+
response_format: z3.object({
|
|
5822
|
+
type: z3.literal("json_schema"),
|
|
5823
|
+
json_schema: ResponseFormatJsonSchema.omit({ schema: true }).extend({
|
|
5824
|
+
schema: z3.unknown()
|
|
4490
5825
|
})
|
|
4491
5826
|
})
|
|
4492
5827
|
}).safeParse(params);
|
|
@@ -4507,7 +5842,7 @@ function renderPromptParams(params, args, options) {
|
|
|
4507
5842
|
}
|
|
4508
5843
|
return params;
|
|
4509
5844
|
}
|
|
4510
|
-
var
|
|
5845
|
+
var Prompt2 = class _Prompt {
|
|
4511
5846
|
constructor(metadata, defaults, noTrace) {
|
|
4512
5847
|
this.metadata = metadata;
|
|
4513
5848
|
this.defaults = defaults;
|
|
@@ -4604,7 +5939,7 @@ var Prompt = class _Prompt {
|
|
|
4604
5939
|
if (!prompt) {
|
|
4605
5940
|
throw new Error("Empty prompt");
|
|
4606
5941
|
}
|
|
4607
|
-
const dictArgParsed =
|
|
5942
|
+
const dictArgParsed = z3.record(z3.unknown()).safeParse(buildArgs);
|
|
4608
5943
|
const variables = {
|
|
4609
5944
|
input: buildArgs,
|
|
4610
5945
|
...dictArgParsed.success ? dictArgParsed.data : {}
|
|
@@ -4625,7 +5960,7 @@ var Prompt = class _Prompt {
|
|
|
4625
5960
|
...spanInfo,
|
|
4626
5961
|
messages: renderedPrompt.messages,
|
|
4627
5962
|
...renderedPrompt.tools ? {
|
|
4628
|
-
tools:
|
|
5963
|
+
tools: ChatCompletionTool.array().parse(JSON.parse(renderedPrompt.tools))
|
|
4629
5964
|
} : void 0
|
|
4630
5965
|
};
|
|
4631
5966
|
} else if (flavor === "completion") {
|
|
@@ -4659,7 +5994,7 @@ var Prompt = class _Prompt {
|
|
|
4659
5994
|
return JSON.stringify(v);
|
|
4660
5995
|
}
|
|
4661
5996
|
};
|
|
4662
|
-
const dictArgParsed =
|
|
5997
|
+
const dictArgParsed = z3.record(z3.unknown()).safeParse(buildArgs);
|
|
4663
5998
|
const variables = {
|
|
4664
5999
|
input: buildArgs,
|
|
4665
6000
|
...dictArgParsed.success ? dictArgParsed.data : {}
|
|
@@ -4712,7 +6047,7 @@ var Prompt = class _Prompt {
|
|
|
4712
6047
|
}
|
|
4713
6048
|
getParsedPromptData() {
|
|
4714
6049
|
if (!this.hasParsedPromptData) {
|
|
4715
|
-
this.parsedPromptData =
|
|
6050
|
+
this.parsedPromptData = PromptData.parse(this.metadata.prompt_data);
|
|
4716
6051
|
this.hasParsedPromptData = true;
|
|
4717
6052
|
}
|
|
4718
6053
|
return this.parsedPromptData;
|
|
@@ -4749,6 +6084,57 @@ function simulateLogoutForTests() {
|
|
|
4749
6084
|
_globalState.appUrl = "https://www.braintrust.dev";
|
|
4750
6085
|
return _globalState;
|
|
4751
6086
|
}
|
|
6087
|
+
async function getPromptVersions(projectId, promptId) {
|
|
6088
|
+
const state = _internalGetGlobalState();
|
|
6089
|
+
if (!state) {
|
|
6090
|
+
throw new Error("Must log in first");
|
|
6091
|
+
}
|
|
6092
|
+
await state.login({});
|
|
6093
|
+
const query = {
|
|
6094
|
+
from: {
|
|
6095
|
+
op: "function",
|
|
6096
|
+
name: {
|
|
6097
|
+
op: "ident",
|
|
6098
|
+
name: ["project_prompts"]
|
|
6099
|
+
},
|
|
6100
|
+
args: [
|
|
6101
|
+
{
|
|
6102
|
+
op: "literal",
|
|
6103
|
+
value: projectId
|
|
6104
|
+
}
|
|
6105
|
+
]
|
|
6106
|
+
},
|
|
6107
|
+
select: [
|
|
6108
|
+
{
|
|
6109
|
+
op: "star"
|
|
6110
|
+
}
|
|
6111
|
+
],
|
|
6112
|
+
filter: {
|
|
6113
|
+
op: "eq",
|
|
6114
|
+
left: { op: "ident", name: ["id"] },
|
|
6115
|
+
right: { op: "literal", value: promptId }
|
|
6116
|
+
}
|
|
6117
|
+
};
|
|
6118
|
+
const response = await state.apiConn().post(
|
|
6119
|
+
"btql",
|
|
6120
|
+
{
|
|
6121
|
+
query,
|
|
6122
|
+
audit_log: true,
|
|
6123
|
+
use_columnstore: false,
|
|
6124
|
+
brainstore_realtime: true
|
|
6125
|
+
},
|
|
6126
|
+
{ headers: { "Accept-Encoding": "gzip" } }
|
|
6127
|
+
);
|
|
6128
|
+
if (!response.ok) {
|
|
6129
|
+
throw new Error(
|
|
6130
|
+
`API request failed: ${response.status} ${response.statusText}`
|
|
6131
|
+
);
|
|
6132
|
+
}
|
|
6133
|
+
const result = await response.json();
|
|
6134
|
+
return result.data?.filter(
|
|
6135
|
+
(entry) => ["upsert", "merge"].includes(entry.audit_data?.action)
|
|
6136
|
+
).map((entry) => prettifyXact(entry._xact_id)) || [];
|
|
6137
|
+
}
|
|
4752
6138
|
var _exportsForTestingOnly = {
|
|
4753
6139
|
extractAttachments,
|
|
4754
6140
|
deepCopyEvent,
|
|
@@ -4757,6 +6143,7 @@ var _exportsForTestingOnly = {
|
|
|
4757
6143
|
simulateLoginForTests,
|
|
4758
6144
|
simulateLogoutForTests,
|
|
4759
6145
|
setInitialTestState,
|
|
6146
|
+
initTestExperiment,
|
|
4760
6147
|
isGeneratorFunction,
|
|
4761
6148
|
isAsyncGeneratorFunction
|
|
4762
6149
|
};
|
|
@@ -4800,9 +6187,9 @@ __export(exports_browser_exports, {
|
|
|
4800
6187
|
BaseAttachment: () => BaseAttachment,
|
|
4801
6188
|
BraintrustState: () => BraintrustState,
|
|
4802
6189
|
BraintrustStream: () => BraintrustStream,
|
|
4803
|
-
Dataset: () =>
|
|
6190
|
+
Dataset: () => Dataset2,
|
|
4804
6191
|
ERR_PERMALINK: () => ERR_PERMALINK,
|
|
4805
|
-
Experiment: () =>
|
|
6192
|
+
Experiment: () => Experiment2,
|
|
4806
6193
|
ExternalAttachment: () => ExternalAttachment,
|
|
4807
6194
|
FailedHTTPResponse: () => FailedHTTPResponse,
|
|
4808
6195
|
INTERNAL_BTQL_LIMIT: () => INTERNAL_BTQL_LIMIT,
|
|
@@ -4812,7 +6199,7 @@ __export(exports_browser_exports, {
|
|
|
4812
6199
|
NOOP_SPAN: () => NOOP_SPAN,
|
|
4813
6200
|
NOOP_SPAN_PERMALINK: () => NOOP_SPAN_PERMALINK,
|
|
4814
6201
|
NoopSpan: () => NoopSpan,
|
|
4815
|
-
Prompt: () =>
|
|
6202
|
+
Prompt: () => Prompt2,
|
|
4816
6203
|
ReadonlyAttachment: () => ReadonlyAttachment,
|
|
4817
6204
|
ReadonlyExperiment: () => ReadonlyExperiment,
|
|
4818
6205
|
SpanImpl: () => SpanImpl,
|
|
@@ -4831,6 +6218,7 @@ __export(exports_browser_exports, {
|
|
|
4831
6218
|
evaluatorDefinitionSchema: () => evaluatorDefinitionSchema,
|
|
4832
6219
|
evaluatorDefinitionsSchema: () => evaluatorDefinitionsSchema,
|
|
4833
6220
|
flush: () => flush,
|
|
6221
|
+
getPromptVersions: () => getPromptVersions,
|
|
4834
6222
|
getSpanParentObject: () => getSpanParentObject,
|
|
4835
6223
|
init: () => init,
|
|
4836
6224
|
initDataset: () => initDataset,
|
|
@@ -4849,6 +6237,7 @@ __export(exports_browser_exports, {
|
|
|
4849
6237
|
renderMessage: () => renderMessage,
|
|
4850
6238
|
renderPromptParams: () => renderPromptParams,
|
|
4851
6239
|
setFetch: () => setFetch,
|
|
6240
|
+
setMaskingFunction: () => setMaskingFunction,
|
|
4852
6241
|
spanComponentsToObjectId: () => spanComponentsToObjectId,
|
|
4853
6242
|
startSpan: () => startSpan,
|
|
4854
6243
|
summarize: () => summarize,
|
|
@@ -4866,9 +6255,6 @@ __export(exports_browser_exports, {
|
|
|
4866
6255
|
});
|
|
4867
6256
|
|
|
4868
6257
|
// src/functions/invoke.ts
|
|
4869
|
-
import {
|
|
4870
|
-
functionIdSchema
|
|
4871
|
-
} from "@braintrust/core/typespecs";
|
|
4872
6258
|
async function invoke(args) {
|
|
4873
6259
|
const {
|
|
4874
6260
|
orgName,
|
|
@@ -4897,7 +6283,7 @@ async function invoke(args) {
|
|
|
4897
6283
|
fetch: fetch2
|
|
4898
6284
|
});
|
|
4899
6285
|
const parent = parentArg ? typeof parentArg === "string" ? parentArg : await parentArg.export() : await getSpanParentObject().export();
|
|
4900
|
-
const functionId =
|
|
6286
|
+
const functionId = FunctionId.safeParse({
|
|
4901
6287
|
function_id: functionIdArgs.function_id,
|
|
4902
6288
|
project_name: functionIdArgs.projectName,
|
|
4903
6289
|
slug: functionIdArgs.slug,
|
|
@@ -4961,6 +6347,7 @@ import { SpanTypeAttribute as SpanTypeAttribute2 } from "@braintrust/core";
|
|
|
4961
6347
|
import { mergeDicts as mergeDicts2 } from "@braintrust/core";
|
|
4962
6348
|
|
|
4963
6349
|
// src/wrappers/oai_responses.ts
|
|
6350
|
+
import { isObject as isObject2 } from "@braintrust/core";
|
|
4964
6351
|
function responsesProxy(openai) {
|
|
4965
6352
|
if (!openai.responses) {
|
|
4966
6353
|
return openai;
|
|
@@ -5150,11 +6537,11 @@ function parseMetricsFromUsage(usage) {
|
|
|
5150
6537
|
const metricName = TOKEN_NAME_MAP[oai_name] || oai_name;
|
|
5151
6538
|
metrics[metricName] = value;
|
|
5152
6539
|
} else if (oai_name.endsWith("_tokens_details")) {
|
|
5153
|
-
|
|
5154
|
-
const prefix = TOKEN_PREFIX_MAP[rawPrefix] || rawPrefix;
|
|
5155
|
-
if (typeof value !== "object") {
|
|
6540
|
+
if (!isObject2(value)) {
|
|
5156
6541
|
continue;
|
|
5157
6542
|
}
|
|
6543
|
+
const rawPrefix = oai_name.slice(0, -"_tokens_details".length);
|
|
6544
|
+
const prefix = TOKEN_PREFIX_MAP[rawPrefix] || rawPrefix;
|
|
5158
6545
|
for (const [key, n] of Object.entries(value)) {
|
|
5159
6546
|
if (typeof n !== "number") {
|
|
5160
6547
|
continue;
|
|
@@ -5637,50 +7024,44 @@ var WrapperStream = class {
|
|
|
5637
7024
|
};
|
|
5638
7025
|
|
|
5639
7026
|
// dev/types.ts
|
|
5640
|
-
import {
|
|
5641
|
-
|
|
5642
|
-
|
|
5643
|
-
|
|
5644
|
-
|
|
5645
|
-
|
|
5646
|
-
|
|
5647
|
-
|
|
5648
|
-
|
|
5649
|
-
parameters: z3.record(z3.string(), z3.unknown()).nullish(),
|
|
5650
|
-
data: runEvalSchema.shape.data,
|
|
5651
|
-
scores: z3.array(
|
|
5652
|
-
z3.object({
|
|
5653
|
-
function_id: functionIdSchema2,
|
|
5654
|
-
name: z3.string()
|
|
7027
|
+
import { z as z4 } from "zod";
|
|
7028
|
+
var evalBodySchema = z4.object({
|
|
7029
|
+
name: z4.string(),
|
|
7030
|
+
parameters: z4.record(z4.string(), z4.unknown()).nullish(),
|
|
7031
|
+
data: RunEval.shape.data,
|
|
7032
|
+
scores: z4.array(
|
|
7033
|
+
z4.object({
|
|
7034
|
+
function_id: FunctionId,
|
|
7035
|
+
name: z4.string()
|
|
5655
7036
|
})
|
|
5656
7037
|
).nullish(),
|
|
5657
|
-
experiment_name:
|
|
5658
|
-
project_id:
|
|
5659
|
-
parent:
|
|
5660
|
-
stream:
|
|
7038
|
+
experiment_name: z4.string().nullish(),
|
|
7039
|
+
project_id: z4.string().nullish(),
|
|
7040
|
+
parent: InvokeParent.optional(),
|
|
7041
|
+
stream: z4.boolean().optional()
|
|
5661
7042
|
});
|
|
5662
|
-
var evalParametersSerializedSchema =
|
|
5663
|
-
|
|
5664
|
-
|
|
5665
|
-
|
|
5666
|
-
type:
|
|
5667
|
-
default:
|
|
5668
|
-
description:
|
|
7043
|
+
var evalParametersSerializedSchema = z4.record(
|
|
7044
|
+
z4.string(),
|
|
7045
|
+
z4.union([
|
|
7046
|
+
z4.object({
|
|
7047
|
+
type: z4.literal("prompt"),
|
|
7048
|
+
default: PromptData.optional(),
|
|
7049
|
+
description: z4.string().optional()
|
|
5669
7050
|
}),
|
|
5670
|
-
|
|
5671
|
-
type:
|
|
5672
|
-
schema:
|
|
7051
|
+
z4.object({
|
|
7052
|
+
type: z4.literal("data"),
|
|
7053
|
+
schema: z4.record(z4.unknown()),
|
|
5673
7054
|
// JSON Schema
|
|
5674
|
-
default:
|
|
5675
|
-
description:
|
|
7055
|
+
default: z4.unknown().optional(),
|
|
7056
|
+
description: z4.string().optional()
|
|
5676
7057
|
})
|
|
5677
7058
|
])
|
|
5678
7059
|
);
|
|
5679
|
-
var evaluatorDefinitionSchema =
|
|
7060
|
+
var evaluatorDefinitionSchema = z4.object({
|
|
5680
7061
|
parameters: evalParametersSerializedSchema.optional()
|
|
5681
7062
|
});
|
|
5682
|
-
var evaluatorDefinitionsSchema =
|
|
5683
|
-
|
|
7063
|
+
var evaluatorDefinitionsSchema = z4.record(
|
|
7064
|
+
z4.string(),
|
|
5684
7065
|
evaluatorDefinitionSchema
|
|
5685
7066
|
);
|
|
5686
7067
|
|
|
@@ -5692,9 +7073,9 @@ export {
|
|
|
5692
7073
|
BaseAttachment,
|
|
5693
7074
|
BraintrustState,
|
|
5694
7075
|
BraintrustStream,
|
|
5695
|
-
Dataset,
|
|
7076
|
+
Dataset2 as Dataset,
|
|
5696
7077
|
ERR_PERMALINK,
|
|
5697
|
-
Experiment,
|
|
7078
|
+
Experiment2 as Experiment,
|
|
5698
7079
|
ExternalAttachment,
|
|
5699
7080
|
FailedHTTPResponse,
|
|
5700
7081
|
INTERNAL_BTQL_LIMIT,
|
|
@@ -5704,7 +7085,7 @@ export {
|
|
|
5704
7085
|
NOOP_SPAN,
|
|
5705
7086
|
NOOP_SPAN_PERMALINK,
|
|
5706
7087
|
NoopSpan,
|
|
5707
|
-
Prompt,
|
|
7088
|
+
Prompt2 as Prompt,
|
|
5708
7089
|
ReadonlyAttachment,
|
|
5709
7090
|
ReadonlyExperiment,
|
|
5710
7091
|
SpanImpl,
|
|
@@ -5724,6 +7105,7 @@ export {
|
|
|
5724
7105
|
evaluatorDefinitionSchema,
|
|
5725
7106
|
evaluatorDefinitionsSchema,
|
|
5726
7107
|
flush,
|
|
7108
|
+
getPromptVersions,
|
|
5727
7109
|
getSpanParentObject,
|
|
5728
7110
|
init,
|
|
5729
7111
|
initDataset,
|
|
@@ -5742,6 +7124,7 @@ export {
|
|
|
5742
7124
|
renderMessage,
|
|
5743
7125
|
renderPromptParams,
|
|
5744
7126
|
setFetch,
|
|
7127
|
+
setMaskingFunction,
|
|
5745
7128
|
spanComponentsToObjectId,
|
|
5746
7129
|
startSpan,
|
|
5747
7130
|
summarize,
|