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/index.mjs
CHANGED
|
@@ -481,15 +481,15 @@ function mergeTwoObjects(one, two, level = 0, objects) {
|
|
|
481
481
|
for (let i = 0, j = two.length; i < j; i++) {
|
|
482
482
|
result.push(takeValue(two[i]));
|
|
483
483
|
}
|
|
484
|
-
} else if (
|
|
484
|
+
} else if (isObject3(two)) {
|
|
485
485
|
const keys = Object.keys(two);
|
|
486
486
|
for (let i = 0, j = keys.length; i < j; i++) {
|
|
487
487
|
const key = keys[i];
|
|
488
488
|
result[key] = takeValue(two[key]);
|
|
489
489
|
}
|
|
490
490
|
}
|
|
491
|
-
} else if (
|
|
492
|
-
if (
|
|
491
|
+
} else if (isObject3(one)) {
|
|
492
|
+
if (isObject3(two)) {
|
|
493
493
|
if (!shouldMerge(one, two)) {
|
|
494
494
|
return two;
|
|
495
495
|
}
|
|
@@ -510,7 +510,7 @@ function mergeTwoObjects(one, two, level = 0, objects) {
|
|
|
510
510
|
if (wasObjectReferenced(one, key, objects) || wasObjectReferenced(two, key, objects)) {
|
|
511
511
|
delete result[key];
|
|
512
512
|
} else {
|
|
513
|
-
if (
|
|
513
|
+
if (isObject3(obj1) && isObject3(obj2)) {
|
|
514
514
|
const arr1 = objects.get(obj1) || [];
|
|
515
515
|
const arr2 = objects.get(obj2) || [];
|
|
516
516
|
arr1.push({ obj: one, key });
|
|
@@ -544,7 +544,7 @@ function isArray2(value) {
|
|
|
544
544
|
function isFunction(value) {
|
|
545
545
|
return typeof value === "function";
|
|
546
546
|
}
|
|
547
|
-
function
|
|
547
|
+
function isObject3(value) {
|
|
548
548
|
return !isPrimitive(value) && !isArray2(value) && !isFunction(value) && typeof value === "object";
|
|
549
549
|
}
|
|
550
550
|
function isPrimitive(value) {
|
|
@@ -3198,6 +3198,7 @@ import { AsyncLocalStorage } from "node:async_hooks";
|
|
|
3198
3198
|
import * as path from "node:path";
|
|
3199
3199
|
import * as fs from "node:fs/promises";
|
|
3200
3200
|
import * as os from "node:os";
|
|
3201
|
+
import * as fsSync from "node:fs";
|
|
3201
3202
|
import * as crypto from "node:crypto";
|
|
3202
3203
|
|
|
3203
3204
|
// src/isomorph.ts
|
|
@@ -3519,64 +3520,1264 @@ import {
|
|
|
3519
3520
|
isArray,
|
|
3520
3521
|
isObject
|
|
3521
3522
|
} from "@braintrust/core";
|
|
3522
|
-
import {
|
|
3523
|
-
attachmentReferenceSchema,
|
|
3524
|
-
responseFormatJsonSchemaSchema,
|
|
3525
|
-
attachmentStatusSchema,
|
|
3526
|
-
BRAINTRUST_ATTACHMENT,
|
|
3527
|
-
BRAINTRUST_PARAMS,
|
|
3528
|
-
gitMetadataSettingsSchema,
|
|
3529
|
-
promptDataSchema,
|
|
3530
|
-
promptSchema,
|
|
3531
|
-
toolsSchema,
|
|
3532
|
-
EXTERNAL_ATTACHMENT
|
|
3533
|
-
} from "@braintrust/core/typespecs";
|
|
3534
|
-
import { waitUntil } from "@vercel/functions";
|
|
3535
|
-
import Mustache2 from "mustache";
|
|
3536
|
-
import { z as z2, ZodError } from "zod";
|
|
3537
3523
|
|
|
3538
|
-
// src/
|
|
3539
|
-
import {
|
|
3540
|
-
callEventSchema,
|
|
3541
|
-
sseConsoleEventDataSchema,
|
|
3542
|
-
sseProgressEventDataSchema
|
|
3543
|
-
} from "@braintrust/core/typespecs";
|
|
3544
|
-
import {
|
|
3545
|
-
createParser
|
|
3546
|
-
} from "eventsource-parser";
|
|
3524
|
+
// src/generated_types.ts
|
|
3547
3525
|
import { z } from "zod";
|
|
3548
|
-
var
|
|
3526
|
+
var AclObjectType = z.union([
|
|
3527
|
+
z.enum([
|
|
3528
|
+
"organization",
|
|
3529
|
+
"project",
|
|
3530
|
+
"experiment",
|
|
3531
|
+
"dataset",
|
|
3532
|
+
"prompt",
|
|
3533
|
+
"prompt_session",
|
|
3534
|
+
"group",
|
|
3535
|
+
"role",
|
|
3536
|
+
"org_member",
|
|
3537
|
+
"project_log",
|
|
3538
|
+
"org_project"
|
|
3539
|
+
]),
|
|
3540
|
+
z.null()
|
|
3541
|
+
]);
|
|
3542
|
+
var Permission = z.enum([
|
|
3543
|
+
"create",
|
|
3544
|
+
"read",
|
|
3545
|
+
"update",
|
|
3546
|
+
"delete",
|
|
3547
|
+
"create_acls",
|
|
3548
|
+
"read_acls",
|
|
3549
|
+
"update_acls",
|
|
3550
|
+
"delete_acls"
|
|
3551
|
+
]);
|
|
3552
|
+
var Acl = z.object({
|
|
3553
|
+
id: z.string().uuid(),
|
|
3554
|
+
object_type: AclObjectType.and(z.string()),
|
|
3555
|
+
object_id: z.string().uuid(),
|
|
3556
|
+
user_id: z.union([z.string(), z.null()]).optional(),
|
|
3557
|
+
group_id: z.union([z.string(), z.null()]).optional(),
|
|
3558
|
+
permission: Permission.and(z.union([z.string(), z.null()])).optional(),
|
|
3559
|
+
restrict_object_type: AclObjectType.and(z.unknown()).optional(),
|
|
3560
|
+
role_id: z.union([z.string(), z.null()]).optional(),
|
|
3561
|
+
_object_org_id: z.string().uuid(),
|
|
3562
|
+
created: z.union([z.string(), z.null()]).optional()
|
|
3563
|
+
});
|
|
3564
|
+
var AISecret = z.object({
|
|
3565
|
+
id: z.string().uuid(),
|
|
3566
|
+
created: z.union([z.string(), z.null()]).optional(),
|
|
3567
|
+
updated_at: z.union([z.string(), z.null()]).optional(),
|
|
3568
|
+
org_id: z.string().uuid(),
|
|
3569
|
+
name: z.string(),
|
|
3570
|
+
type: z.union([z.string(), z.null()]).optional(),
|
|
3571
|
+
metadata: z.union([z.object({}).partial().passthrough(), z.null()]).optional(),
|
|
3572
|
+
preview_secret: z.union([z.string(), z.null()]).optional()
|
|
3573
|
+
});
|
|
3574
|
+
var ResponseFormatJsonSchema = z.object({
|
|
3575
|
+
name: z.string(),
|
|
3576
|
+
description: z.string().optional(),
|
|
3577
|
+
schema: z.union([z.object({}).partial().passthrough(), z.string()]).optional(),
|
|
3578
|
+
strict: z.union([z.boolean(), z.null()]).optional()
|
|
3579
|
+
});
|
|
3580
|
+
var ResponseFormat = z.union([
|
|
3581
|
+
z.object({ type: z.literal("json_object") }),
|
|
3582
|
+
z.object({
|
|
3583
|
+
type: z.literal("json_schema"),
|
|
3584
|
+
json_schema: ResponseFormatJsonSchema
|
|
3585
|
+
}),
|
|
3586
|
+
z.object({ type: z.literal("text") }),
|
|
3587
|
+
z.null()
|
|
3588
|
+
]);
|
|
3589
|
+
var AnyModelParams = z.object({
|
|
3590
|
+
temperature: z.number().optional(),
|
|
3591
|
+
top_p: z.number().optional(),
|
|
3592
|
+
max_tokens: z.number(),
|
|
3593
|
+
max_completion_tokens: z.number().optional(),
|
|
3594
|
+
frequency_penalty: z.number().optional(),
|
|
3595
|
+
presence_penalty: z.number().optional(),
|
|
3596
|
+
response_format: ResponseFormat.optional(),
|
|
3597
|
+
tool_choice: z.union([
|
|
3598
|
+
z.literal("auto"),
|
|
3599
|
+
z.literal("none"),
|
|
3600
|
+
z.literal("required"),
|
|
3601
|
+
z.object({
|
|
3602
|
+
type: z.literal("function"),
|
|
3603
|
+
function: z.object({ name: z.string() })
|
|
3604
|
+
})
|
|
3605
|
+
]).optional(),
|
|
3606
|
+
function_call: z.union([
|
|
3607
|
+
z.literal("auto"),
|
|
3608
|
+
z.literal("none"),
|
|
3609
|
+
z.object({ name: z.string() })
|
|
3610
|
+
]).optional(),
|
|
3611
|
+
n: z.number().optional(),
|
|
3612
|
+
stop: z.array(z.string()).optional(),
|
|
3613
|
+
reasoning_effort: z.enum(["minimal", "low", "medium", "high"]).optional(),
|
|
3614
|
+
verbosity: z.enum(["low", "medium", "high"]).optional(),
|
|
3615
|
+
top_k: z.number().optional(),
|
|
3616
|
+
stop_sequences: z.array(z.string()).optional(),
|
|
3617
|
+
max_tokens_to_sample: z.number().optional(),
|
|
3618
|
+
maxOutputTokens: z.number().optional(),
|
|
3619
|
+
topP: z.number().optional(),
|
|
3620
|
+
topK: z.number().optional(),
|
|
3621
|
+
use_cache: z.boolean().optional()
|
|
3622
|
+
});
|
|
3623
|
+
var ApiKey = z.object({
|
|
3624
|
+
id: z.string().uuid(),
|
|
3625
|
+
created: z.union([z.string(), z.null()]).optional(),
|
|
3626
|
+
name: z.string(),
|
|
3627
|
+
preview_name: z.string(),
|
|
3628
|
+
user_id: z.union([z.string(), z.null()]).optional(),
|
|
3629
|
+
user_email: z.union([z.string(), z.null()]).optional(),
|
|
3630
|
+
user_given_name: z.union([z.string(), z.null()]).optional(),
|
|
3631
|
+
user_family_name: z.union([z.string(), z.null()]).optional(),
|
|
3632
|
+
org_id: z.union([z.string(), z.null()]).optional()
|
|
3633
|
+
});
|
|
3634
|
+
var BraintrustAttachmentReference = z.object({
|
|
3635
|
+
type: z.literal("braintrust_attachment"),
|
|
3636
|
+
filename: z.string().min(1),
|
|
3637
|
+
content_type: z.string().min(1),
|
|
3638
|
+
key: z.string().min(1)
|
|
3639
|
+
});
|
|
3640
|
+
var ExternalAttachmentReference = z.object({
|
|
3641
|
+
type: z.literal("external_attachment"),
|
|
3642
|
+
filename: z.string().min(1),
|
|
3643
|
+
content_type: z.string().min(1),
|
|
3644
|
+
url: z.string().min(1)
|
|
3645
|
+
});
|
|
3646
|
+
var AttachmentReference = z.discriminatedUnion("type", [
|
|
3647
|
+
BraintrustAttachmentReference,
|
|
3648
|
+
ExternalAttachmentReference
|
|
3649
|
+
]);
|
|
3650
|
+
var UploadStatus = z.enum(["uploading", "done", "error"]);
|
|
3651
|
+
var AttachmentStatus = z.object({
|
|
3652
|
+
upload_status: UploadStatus,
|
|
3653
|
+
error_message: z.string().optional()
|
|
3654
|
+
});
|
|
3655
|
+
var BraintrustModelParams = z.object({ use_cache: z.boolean() }).partial();
|
|
3656
|
+
var CallEvent = z.union([
|
|
3657
|
+
z.object({
|
|
3658
|
+
id: z.string().optional(),
|
|
3659
|
+
data: z.string(),
|
|
3660
|
+
event: z.literal("text_delta")
|
|
3661
|
+
}),
|
|
3662
|
+
z.object({
|
|
3663
|
+
id: z.string().optional(),
|
|
3664
|
+
data: z.string(),
|
|
3665
|
+
event: z.literal("reasoning_delta")
|
|
3666
|
+
}),
|
|
3667
|
+
z.object({
|
|
3668
|
+
id: z.string().optional(),
|
|
3669
|
+
data: z.string(),
|
|
3670
|
+
event: z.literal("json_delta")
|
|
3671
|
+
}),
|
|
3672
|
+
z.object({
|
|
3673
|
+
id: z.string().optional(),
|
|
3674
|
+
data: z.string(),
|
|
3675
|
+
event: z.literal("progress")
|
|
3676
|
+
}),
|
|
3677
|
+
z.object({
|
|
3678
|
+
id: z.string().optional(),
|
|
3679
|
+
data: z.string(),
|
|
3680
|
+
event: z.literal("error")
|
|
3681
|
+
}),
|
|
3682
|
+
z.object({
|
|
3683
|
+
id: z.string().optional(),
|
|
3684
|
+
data: z.string(),
|
|
3685
|
+
event: z.literal("console")
|
|
3686
|
+
}),
|
|
3687
|
+
z.object({
|
|
3688
|
+
id: z.string().optional(),
|
|
3689
|
+
event: z.literal("start"),
|
|
3690
|
+
data: z.literal("")
|
|
3691
|
+
}),
|
|
3692
|
+
z.object({
|
|
3693
|
+
id: z.string().optional(),
|
|
3694
|
+
event: z.literal("done"),
|
|
3695
|
+
data: z.literal("")
|
|
3696
|
+
})
|
|
3697
|
+
]);
|
|
3698
|
+
var ChatCompletionContentPartTextWithTitle = z.object({
|
|
3699
|
+
text: z.string().default(""),
|
|
3700
|
+
type: z.literal("text"),
|
|
3701
|
+
cache_control: z.object({ type: z.literal("ephemeral") }).optional()
|
|
3702
|
+
});
|
|
3703
|
+
var ChatCompletionContentPartImageWithTitle = z.object({
|
|
3704
|
+
image_url: z.object({
|
|
3705
|
+
url: z.string(),
|
|
3706
|
+
detail: z.union([z.literal("auto"), z.literal("low"), z.literal("high")]).optional()
|
|
3707
|
+
}),
|
|
3708
|
+
type: z.literal("image_url")
|
|
3709
|
+
});
|
|
3710
|
+
var ChatCompletionContentPart = z.union([
|
|
3711
|
+
ChatCompletionContentPartTextWithTitle,
|
|
3712
|
+
ChatCompletionContentPartImageWithTitle
|
|
3713
|
+
]);
|
|
3714
|
+
var ChatCompletionContentPartText = z.object({
|
|
3715
|
+
text: z.string().default(""),
|
|
3716
|
+
type: z.literal("text"),
|
|
3717
|
+
cache_control: z.object({ type: z.literal("ephemeral") }).optional()
|
|
3718
|
+
});
|
|
3719
|
+
var ChatCompletionMessageToolCall = z.object({
|
|
3720
|
+
id: z.string(),
|
|
3721
|
+
function: z.object({ arguments: z.string(), name: z.string() }),
|
|
3722
|
+
type: z.literal("function")
|
|
3723
|
+
});
|
|
3724
|
+
var ChatCompletionMessageReasoning = z.object({ id: z.string(), content: z.string() }).partial();
|
|
3725
|
+
var ChatCompletionMessageParam = z.union([
|
|
3726
|
+
z.object({
|
|
3727
|
+
content: z.union([z.string(), z.array(ChatCompletionContentPartText)]),
|
|
3728
|
+
role: z.literal("system"),
|
|
3729
|
+
name: z.string().optional()
|
|
3730
|
+
}),
|
|
3731
|
+
z.object({
|
|
3732
|
+
content: z.union([z.string(), z.array(ChatCompletionContentPart)]),
|
|
3733
|
+
role: z.literal("user"),
|
|
3734
|
+
name: z.string().optional()
|
|
3735
|
+
}),
|
|
3736
|
+
z.object({
|
|
3737
|
+
role: z.literal("assistant"),
|
|
3738
|
+
content: z.union([z.string(), z.array(ChatCompletionContentPartText), z.null()]).optional(),
|
|
3739
|
+
function_call: z.object({ arguments: z.string(), name: z.string() }).optional(),
|
|
3740
|
+
name: z.string().optional(),
|
|
3741
|
+
tool_calls: z.array(ChatCompletionMessageToolCall).optional(),
|
|
3742
|
+
reasoning: z.array(ChatCompletionMessageReasoning).optional()
|
|
3743
|
+
}),
|
|
3744
|
+
z.object({
|
|
3745
|
+
content: z.union([z.string(), z.array(ChatCompletionContentPartText)]),
|
|
3746
|
+
role: z.literal("tool"),
|
|
3747
|
+
tool_call_id: z.string().default("")
|
|
3748
|
+
}),
|
|
3749
|
+
z.object({
|
|
3750
|
+
content: z.union([z.string(), z.null()]),
|
|
3751
|
+
name: z.string(),
|
|
3752
|
+
role: z.literal("function")
|
|
3753
|
+
}),
|
|
3754
|
+
z.object({
|
|
3755
|
+
content: z.union([z.string(), z.array(ChatCompletionContentPartText)]),
|
|
3756
|
+
role: z.literal("developer"),
|
|
3757
|
+
name: z.string().optional()
|
|
3758
|
+
}),
|
|
3759
|
+
z.object({
|
|
3760
|
+
role: z.literal("model"),
|
|
3761
|
+
content: z.union([z.string(), z.null()]).optional()
|
|
3762
|
+
})
|
|
3763
|
+
]);
|
|
3764
|
+
var ChatCompletionOpenAIMessageParam = z.union([
|
|
3765
|
+
z.object({
|
|
3766
|
+
content: z.union([z.string(), z.array(ChatCompletionContentPartText)]),
|
|
3767
|
+
role: z.literal("system"),
|
|
3768
|
+
name: z.string().optional()
|
|
3769
|
+
}),
|
|
3770
|
+
z.object({
|
|
3771
|
+
content: z.union([z.string(), z.array(ChatCompletionContentPart)]),
|
|
3772
|
+
role: z.literal("user"),
|
|
3773
|
+
name: z.string().optional()
|
|
3774
|
+
}),
|
|
3775
|
+
z.object({
|
|
3776
|
+
role: z.literal("assistant"),
|
|
3777
|
+
content: z.union([z.string(), z.array(ChatCompletionContentPartText), z.null()]).optional(),
|
|
3778
|
+
function_call: z.object({ arguments: z.string(), name: z.string() }).optional(),
|
|
3779
|
+
name: z.string().optional(),
|
|
3780
|
+
tool_calls: z.array(ChatCompletionMessageToolCall).optional(),
|
|
3781
|
+
reasoning: z.array(ChatCompletionMessageReasoning).optional()
|
|
3782
|
+
}),
|
|
3783
|
+
z.object({
|
|
3784
|
+
content: z.union([z.string(), z.array(ChatCompletionContentPartText)]),
|
|
3785
|
+
role: z.literal("tool"),
|
|
3786
|
+
tool_call_id: z.string().default("")
|
|
3787
|
+
}),
|
|
3788
|
+
z.object({
|
|
3789
|
+
content: z.union([z.string(), z.null()]),
|
|
3790
|
+
name: z.string(),
|
|
3791
|
+
role: z.literal("function")
|
|
3792
|
+
}),
|
|
3793
|
+
z.object({
|
|
3794
|
+
content: z.union([z.string(), z.array(ChatCompletionContentPartText)]),
|
|
3795
|
+
role: z.literal("developer"),
|
|
3796
|
+
name: z.string().optional()
|
|
3797
|
+
})
|
|
3798
|
+
]);
|
|
3799
|
+
var ChatCompletionTool = z.object({
|
|
3800
|
+
function: z.object({
|
|
3801
|
+
name: z.string(),
|
|
3802
|
+
description: z.string().optional(),
|
|
3803
|
+
parameters: z.object({}).partial().passthrough().optional()
|
|
3804
|
+
}),
|
|
3805
|
+
type: z.literal("function")
|
|
3806
|
+
});
|
|
3807
|
+
var CodeBundle = z.object({
|
|
3808
|
+
runtime_context: z.object({
|
|
3809
|
+
runtime: z.enum(["node", "python"]),
|
|
3810
|
+
version: z.string()
|
|
3811
|
+
}),
|
|
3812
|
+
location: z.union([
|
|
3813
|
+
z.object({
|
|
3814
|
+
type: z.literal("experiment"),
|
|
3815
|
+
eval_name: z.string(),
|
|
3816
|
+
position: z.union([
|
|
3817
|
+
z.object({ type: z.literal("task") }),
|
|
3818
|
+
z.object({ type: z.literal("scorer"), index: z.number().int().gte(0) })
|
|
3819
|
+
])
|
|
3820
|
+
}),
|
|
3821
|
+
z.object({ type: z.literal("function"), index: z.number().int().gte(0) })
|
|
3822
|
+
]),
|
|
3823
|
+
bundle_id: z.string(),
|
|
3824
|
+
preview: z.union([z.string(), z.null()]).optional()
|
|
3825
|
+
});
|
|
3826
|
+
var Dataset = z.object({
|
|
3827
|
+
id: z.string().uuid(),
|
|
3828
|
+
project_id: z.string().uuid(),
|
|
3829
|
+
name: z.string(),
|
|
3830
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
3831
|
+
created: z.union([z.string(), z.null()]).optional(),
|
|
3832
|
+
deleted_at: z.union([z.string(), z.null()]).optional(),
|
|
3833
|
+
user_id: z.union([z.string(), z.null()]).optional(),
|
|
3834
|
+
metadata: z.union([z.object({}).partial().passthrough(), z.null()]).optional()
|
|
3835
|
+
});
|
|
3836
|
+
var ObjectReference = z.union([
|
|
3837
|
+
z.object({
|
|
3838
|
+
object_type: z.enum([
|
|
3839
|
+
"project_logs",
|
|
3840
|
+
"experiment",
|
|
3841
|
+
"dataset",
|
|
3842
|
+
"prompt",
|
|
3843
|
+
"function",
|
|
3844
|
+
"prompt_session"
|
|
3845
|
+
]),
|
|
3846
|
+
object_id: z.string().uuid(),
|
|
3847
|
+
id: z.string(),
|
|
3848
|
+
_xact_id: z.union([z.string(), z.null()]).optional(),
|
|
3849
|
+
created: z.union([z.string(), z.null()]).optional()
|
|
3850
|
+
}),
|
|
3851
|
+
z.null()
|
|
3852
|
+
]);
|
|
3853
|
+
var DatasetEvent = z.object({
|
|
3854
|
+
id: z.string(),
|
|
3855
|
+
_xact_id: z.string(),
|
|
3856
|
+
created: z.string().datetime({ offset: true }),
|
|
3857
|
+
_pagination_key: z.union([z.string(), z.null()]).optional(),
|
|
3858
|
+
project_id: z.string().uuid(),
|
|
3859
|
+
dataset_id: z.string().uuid(),
|
|
3860
|
+
input: z.unknown().optional(),
|
|
3861
|
+
expected: z.unknown().optional(),
|
|
3862
|
+
metadata: z.union([
|
|
3863
|
+
z.object({ model: z.union([z.string(), z.null()]) }).partial().passthrough(),
|
|
3864
|
+
z.null()
|
|
3865
|
+
]).optional(),
|
|
3866
|
+
tags: z.union([z.array(z.string()), z.null()]).optional(),
|
|
3867
|
+
span_id: z.string(),
|
|
3868
|
+
root_span_id: z.string(),
|
|
3869
|
+
is_root: z.union([z.boolean(), z.null()]).optional(),
|
|
3870
|
+
origin: ObjectReference.optional()
|
|
3871
|
+
});
|
|
3872
|
+
var EnvVar = z.object({
|
|
3873
|
+
id: z.string().uuid(),
|
|
3874
|
+
object_type: z.enum(["organization", "project", "function"]),
|
|
3875
|
+
object_id: z.string().uuid(),
|
|
3876
|
+
name: z.string(),
|
|
3877
|
+
created: z.union([z.string(), z.null()]).optional(),
|
|
3878
|
+
used: z.union([z.string(), z.null()]).optional()
|
|
3879
|
+
});
|
|
3880
|
+
var RepoInfo = z.union([
|
|
3881
|
+
z.object({
|
|
3882
|
+
commit: z.union([z.string(), z.null()]),
|
|
3883
|
+
branch: z.union([z.string(), z.null()]),
|
|
3884
|
+
tag: z.union([z.string(), z.null()]),
|
|
3885
|
+
dirty: z.union([z.boolean(), z.null()]),
|
|
3886
|
+
author_name: z.union([z.string(), z.null()]),
|
|
3887
|
+
author_email: z.union([z.string(), z.null()]),
|
|
3888
|
+
commit_message: z.union([z.string(), z.null()]),
|
|
3889
|
+
commit_time: z.union([z.string(), z.null()]),
|
|
3890
|
+
git_diff: z.union([z.string(), z.null()])
|
|
3891
|
+
}).partial(),
|
|
3892
|
+
z.null()
|
|
3893
|
+
]);
|
|
3894
|
+
var Experiment = z.object({
|
|
3895
|
+
id: z.string().uuid(),
|
|
3896
|
+
project_id: z.string().uuid(),
|
|
3897
|
+
name: z.string(),
|
|
3898
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
3899
|
+
created: z.union([z.string(), z.null()]).optional(),
|
|
3900
|
+
repo_info: RepoInfo.optional(),
|
|
3901
|
+
commit: z.union([z.string(), z.null()]).optional(),
|
|
3902
|
+
base_exp_id: z.union([z.string(), z.null()]).optional(),
|
|
3903
|
+
deleted_at: z.union([z.string(), z.null()]).optional(),
|
|
3904
|
+
dataset_id: z.union([z.string(), z.null()]).optional(),
|
|
3905
|
+
dataset_version: z.union([z.string(), z.null()]).optional(),
|
|
3906
|
+
public: z.boolean(),
|
|
3907
|
+
user_id: z.union([z.string(), z.null()]).optional(),
|
|
3908
|
+
metadata: z.union([z.object({}).partial().passthrough(), z.null()]).optional(),
|
|
3909
|
+
tags: z.union([z.array(z.string()), z.null()]).optional()
|
|
3910
|
+
});
|
|
3911
|
+
var SpanType = z.union([
|
|
3912
|
+
z.enum(["llm", "score", "function", "eval", "task", "tool"]),
|
|
3913
|
+
z.null()
|
|
3914
|
+
]);
|
|
3915
|
+
var SpanAttributes = z.union([
|
|
3916
|
+
z.object({ name: z.union([z.string(), z.null()]), type: SpanType }).partial().passthrough(),
|
|
3917
|
+
z.null()
|
|
3918
|
+
]);
|
|
3919
|
+
var ExperimentEvent = z.object({
|
|
3920
|
+
id: z.string(),
|
|
3921
|
+
_xact_id: z.string(),
|
|
3922
|
+
created: z.string().datetime({ offset: true }),
|
|
3923
|
+
_pagination_key: z.union([z.string(), z.null()]).optional(),
|
|
3924
|
+
project_id: z.string().uuid(),
|
|
3925
|
+
experiment_id: z.string().uuid(),
|
|
3926
|
+
input: z.unknown().optional(),
|
|
3927
|
+
output: z.unknown().optional(),
|
|
3928
|
+
expected: z.unknown().optional(),
|
|
3929
|
+
error: z.unknown().optional(),
|
|
3930
|
+
scores: z.union([z.record(z.union([z.number(), z.null()])), z.null()]).optional(),
|
|
3931
|
+
metadata: z.union([
|
|
3932
|
+
z.object({ model: z.union([z.string(), z.null()]) }).partial().passthrough(),
|
|
3933
|
+
z.null()
|
|
3934
|
+
]).optional(),
|
|
3935
|
+
tags: z.union([z.array(z.string()), z.null()]).optional(),
|
|
3936
|
+
metrics: z.union([z.record(z.number()), z.null()]).optional(),
|
|
3937
|
+
context: z.union([
|
|
3938
|
+
z.object({
|
|
3939
|
+
caller_functionname: z.union([z.string(), z.null()]),
|
|
3940
|
+
caller_filename: z.union([z.string(), z.null()]),
|
|
3941
|
+
caller_lineno: z.union([z.number(), z.null()])
|
|
3942
|
+
}).partial().passthrough(),
|
|
3943
|
+
z.null()
|
|
3944
|
+
]).optional(),
|
|
3945
|
+
span_id: z.string(),
|
|
3946
|
+
span_parents: z.union([z.array(z.string()), z.null()]).optional(),
|
|
3947
|
+
root_span_id: z.string(),
|
|
3948
|
+
span_attributes: SpanAttributes.optional(),
|
|
3949
|
+
is_root: z.union([z.boolean(), z.null()]).optional(),
|
|
3950
|
+
origin: ObjectReference.optional()
|
|
3951
|
+
});
|
|
3952
|
+
var ExtendedSavedFunctionId = z.union([
|
|
3953
|
+
z.object({ type: z.literal("function"), id: z.string() }),
|
|
3954
|
+
z.object({ type: z.literal("global"), name: z.string() }),
|
|
3955
|
+
z.object({
|
|
3956
|
+
type: z.literal("slug"),
|
|
3957
|
+
project_id: z.string(),
|
|
3958
|
+
slug: z.string()
|
|
3959
|
+
})
|
|
3960
|
+
]);
|
|
3961
|
+
var PromptBlockDataNullish = z.union([
|
|
3962
|
+
z.object({ type: z.literal("completion"), content: z.string() }),
|
|
3963
|
+
z.object({
|
|
3964
|
+
type: z.literal("chat"),
|
|
3965
|
+
messages: z.array(ChatCompletionMessageParam),
|
|
3966
|
+
tools: z.string().optional()
|
|
3967
|
+
}),
|
|
3968
|
+
z.null()
|
|
3969
|
+
]);
|
|
3970
|
+
var ModelParams = z.union([
|
|
3971
|
+
z.object({
|
|
3972
|
+
use_cache: z.boolean(),
|
|
3973
|
+
temperature: z.number(),
|
|
3974
|
+
top_p: z.number(),
|
|
3975
|
+
max_tokens: z.number(),
|
|
3976
|
+
max_completion_tokens: z.number(),
|
|
3977
|
+
frequency_penalty: z.number(),
|
|
3978
|
+
presence_penalty: z.number(),
|
|
3979
|
+
response_format: ResponseFormat,
|
|
3980
|
+
tool_choice: z.union([
|
|
3981
|
+
z.literal("auto"),
|
|
3982
|
+
z.literal("none"),
|
|
3983
|
+
z.literal("required"),
|
|
3984
|
+
z.object({
|
|
3985
|
+
type: z.literal("function"),
|
|
3986
|
+
function: z.object({ name: z.string() })
|
|
3987
|
+
})
|
|
3988
|
+
]),
|
|
3989
|
+
function_call: z.union([
|
|
3990
|
+
z.literal("auto"),
|
|
3991
|
+
z.literal("none"),
|
|
3992
|
+
z.object({ name: z.string() })
|
|
3993
|
+
]),
|
|
3994
|
+
n: z.number(),
|
|
3995
|
+
stop: z.array(z.string()),
|
|
3996
|
+
reasoning_effort: z.enum(["minimal", "low", "medium", "high"]),
|
|
3997
|
+
verbosity: z.enum(["low", "medium", "high"])
|
|
3998
|
+
}).partial().passthrough(),
|
|
3999
|
+
z.object({
|
|
4000
|
+
use_cache: z.boolean().optional(),
|
|
4001
|
+
max_tokens: z.number(),
|
|
4002
|
+
temperature: z.number(),
|
|
4003
|
+
top_p: z.number().optional(),
|
|
4004
|
+
top_k: z.number().optional(),
|
|
4005
|
+
stop_sequences: z.array(z.string()).optional(),
|
|
4006
|
+
max_tokens_to_sample: z.number().optional()
|
|
4007
|
+
}).passthrough(),
|
|
4008
|
+
z.object({
|
|
4009
|
+
use_cache: z.boolean(),
|
|
4010
|
+
temperature: z.number(),
|
|
4011
|
+
maxOutputTokens: z.number(),
|
|
4012
|
+
topP: z.number(),
|
|
4013
|
+
topK: z.number()
|
|
4014
|
+
}).partial().passthrough(),
|
|
4015
|
+
z.object({
|
|
4016
|
+
use_cache: z.boolean(),
|
|
4017
|
+
temperature: z.number(),
|
|
4018
|
+
topK: z.number()
|
|
4019
|
+
}).partial().passthrough(),
|
|
4020
|
+
z.object({ use_cache: z.boolean() }).partial().passthrough()
|
|
4021
|
+
]);
|
|
4022
|
+
var PromptOptionsNullish = z.union([
|
|
4023
|
+
z.object({ model: z.string(), params: ModelParams, position: z.string() }).partial(),
|
|
4024
|
+
z.null()
|
|
4025
|
+
]);
|
|
4026
|
+
var PromptParserNullish = z.union([
|
|
4027
|
+
z.object({
|
|
4028
|
+
type: z.literal("llm_classifier"),
|
|
4029
|
+
use_cot: z.boolean(),
|
|
4030
|
+
choice_scores: z.record(z.number().gte(0).lte(1))
|
|
4031
|
+
}),
|
|
4032
|
+
z.null()
|
|
4033
|
+
]);
|
|
4034
|
+
var SavedFunctionId = z.union([
|
|
4035
|
+
z.object({ type: z.literal("function"), id: z.string() }),
|
|
4036
|
+
z.object({ type: z.literal("global"), name: z.string() })
|
|
4037
|
+
]);
|
|
4038
|
+
var PromptDataNullish = z.union([
|
|
4039
|
+
z.object({
|
|
4040
|
+
prompt: PromptBlockDataNullish,
|
|
4041
|
+
options: PromptOptionsNullish,
|
|
4042
|
+
parser: PromptParserNullish,
|
|
4043
|
+
tool_functions: z.union([z.array(SavedFunctionId), z.null()]),
|
|
4044
|
+
origin: z.union([
|
|
4045
|
+
z.object({
|
|
4046
|
+
prompt_id: z.string(),
|
|
4047
|
+
project_id: z.string(),
|
|
4048
|
+
prompt_version: z.string()
|
|
4049
|
+
}).partial(),
|
|
4050
|
+
z.null()
|
|
4051
|
+
])
|
|
4052
|
+
}).partial(),
|
|
4053
|
+
z.null()
|
|
4054
|
+
]);
|
|
4055
|
+
var FunctionTypeEnumNullish = z.union([
|
|
4056
|
+
z.enum(["llm", "scorer", "task", "tool"]),
|
|
4057
|
+
z.null()
|
|
4058
|
+
]);
|
|
4059
|
+
var FunctionIdRef = z.object({}).partial().passthrough();
|
|
4060
|
+
var PromptBlockData = z.union([
|
|
4061
|
+
z.object({ type: z.literal("completion"), content: z.string() }),
|
|
3549
4062
|
z.object({
|
|
3550
|
-
type: z.literal("
|
|
3551
|
-
|
|
4063
|
+
type: z.literal("chat"),
|
|
4064
|
+
messages: z.array(ChatCompletionMessageParam),
|
|
4065
|
+
tools: z.string().optional()
|
|
4066
|
+
})
|
|
4067
|
+
]);
|
|
4068
|
+
var GraphNode = z.union([
|
|
4069
|
+
z.object({
|
|
4070
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
4071
|
+
position: z.union([z.object({ x: z.number(), y: z.number() }), z.null()]).optional(),
|
|
4072
|
+
type: z.literal("function"),
|
|
4073
|
+
function: FunctionIdRef
|
|
3552
4074
|
}),
|
|
3553
4075
|
z.object({
|
|
3554
|
-
|
|
3555
|
-
|
|
4076
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
4077
|
+
position: z.union([z.object({ x: z.number(), y: z.number() }), z.null()]).optional(),
|
|
4078
|
+
type: z.literal("input")
|
|
3556
4079
|
}),
|
|
3557
4080
|
z.object({
|
|
3558
|
-
|
|
3559
|
-
|
|
4081
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
4082
|
+
position: z.union([z.object({ x: z.number(), y: z.number() }), z.null()]).optional(),
|
|
4083
|
+
type: z.literal("output")
|
|
3560
4084
|
}),
|
|
3561
4085
|
z.object({
|
|
3562
|
-
|
|
3563
|
-
|
|
4086
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
4087
|
+
position: z.union([z.object({ x: z.number(), y: z.number() }), z.null()]).optional(),
|
|
4088
|
+
type: z.literal("literal"),
|
|
4089
|
+
value: z.unknown().optional()
|
|
3564
4090
|
}),
|
|
3565
4091
|
z.object({
|
|
3566
|
-
|
|
3567
|
-
|
|
4092
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
4093
|
+
position: z.union([z.object({ x: z.number(), y: z.number() }), z.null()]).optional(),
|
|
4094
|
+
type: z.literal("btql"),
|
|
4095
|
+
expr: z.string()
|
|
3568
4096
|
}),
|
|
3569
4097
|
z.object({
|
|
3570
|
-
|
|
3571
|
-
|
|
4098
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
4099
|
+
position: z.union([z.object({ x: z.number(), y: z.number() }), z.null()]).optional(),
|
|
4100
|
+
type: z.literal("gate"),
|
|
4101
|
+
condition: z.union([z.string(), z.null()]).optional()
|
|
3572
4102
|
}),
|
|
3573
4103
|
z.object({
|
|
3574
|
-
|
|
3575
|
-
|
|
4104
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
4105
|
+
position: z.union([z.object({ x: z.number(), y: z.number() }), z.null()]).optional(),
|
|
4106
|
+
type: z.literal("aggregator")
|
|
3576
4107
|
}),
|
|
3577
4108
|
z.object({
|
|
3578
|
-
|
|
3579
|
-
|
|
4109
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
4110
|
+
position: z.union([z.object({ x: z.number(), y: z.number() }), z.null()]).optional(),
|
|
4111
|
+
type: z.literal("prompt_template"),
|
|
4112
|
+
prompt: PromptBlockData
|
|
4113
|
+
})
|
|
4114
|
+
]);
|
|
4115
|
+
var GraphEdge = z.object({
|
|
4116
|
+
source: z.object({ node: z.string().max(1024), variable: z.string() }),
|
|
4117
|
+
target: z.object({ node: z.string().max(1024), variable: z.string() }),
|
|
4118
|
+
purpose: z.enum(["control", "data", "messages"])
|
|
4119
|
+
});
|
|
4120
|
+
var GraphData = z.object({
|
|
4121
|
+
type: z.literal("graph"),
|
|
4122
|
+
nodes: z.record(GraphNode),
|
|
4123
|
+
edges: z.record(GraphEdge)
|
|
4124
|
+
});
|
|
4125
|
+
var FunctionData = z.union([
|
|
4126
|
+
z.object({ type: z.literal("prompt") }),
|
|
4127
|
+
z.object({
|
|
4128
|
+
type: z.literal("code"),
|
|
4129
|
+
data: z.union([
|
|
4130
|
+
z.object({ type: z.literal("bundle") }).and(CodeBundle),
|
|
4131
|
+
z.object({
|
|
4132
|
+
type: z.literal("inline"),
|
|
4133
|
+
runtime_context: z.object({
|
|
4134
|
+
runtime: z.enum(["node", "python"]),
|
|
4135
|
+
version: z.string()
|
|
4136
|
+
}),
|
|
4137
|
+
code: z.string()
|
|
4138
|
+
})
|
|
4139
|
+
])
|
|
4140
|
+
}),
|
|
4141
|
+
GraphData,
|
|
4142
|
+
z.object({
|
|
4143
|
+
type: z.literal("remote_eval"),
|
|
4144
|
+
endpoint: z.string(),
|
|
4145
|
+
eval_name: z.string(),
|
|
4146
|
+
parameters: z.object({}).partial().passthrough()
|
|
4147
|
+
}),
|
|
4148
|
+
z.object({ type: z.literal("global"), name: z.string() })
|
|
4149
|
+
]);
|
|
4150
|
+
var Function2 = z.object({
|
|
4151
|
+
id: z.string().uuid(),
|
|
4152
|
+
_xact_id: z.string(),
|
|
4153
|
+
project_id: z.string().uuid(),
|
|
4154
|
+
log_id: z.literal("p"),
|
|
4155
|
+
org_id: z.string().uuid(),
|
|
4156
|
+
name: z.string(),
|
|
4157
|
+
slug: z.string(),
|
|
4158
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
4159
|
+
created: z.union([z.string(), z.null()]).optional(),
|
|
4160
|
+
prompt_data: PromptDataNullish.optional(),
|
|
4161
|
+
tags: z.union([z.array(z.string()), z.null()]).optional(),
|
|
4162
|
+
metadata: z.union([z.object({}).partial().passthrough(), z.null()]).optional(),
|
|
4163
|
+
function_type: FunctionTypeEnumNullish.optional(),
|
|
4164
|
+
function_data: FunctionData,
|
|
4165
|
+
origin: z.union([
|
|
4166
|
+
z.object({
|
|
4167
|
+
object_type: AclObjectType.and(z.string()),
|
|
4168
|
+
object_id: z.string().uuid(),
|
|
4169
|
+
internal: z.union([z.boolean(), z.null()]).optional()
|
|
4170
|
+
}),
|
|
4171
|
+
z.null()
|
|
4172
|
+
]).optional(),
|
|
4173
|
+
function_schema: z.union([
|
|
4174
|
+
z.object({ parameters: z.unknown(), returns: z.unknown() }).partial(),
|
|
4175
|
+
z.null()
|
|
4176
|
+
]).optional()
|
|
4177
|
+
});
|
|
4178
|
+
var FunctionFormat = z.enum(["llm", "code", "global", "graph"]);
|
|
4179
|
+
var PromptData = z.object({
|
|
4180
|
+
prompt: PromptBlockDataNullish,
|
|
4181
|
+
options: PromptOptionsNullish,
|
|
4182
|
+
parser: PromptParserNullish,
|
|
4183
|
+
tool_functions: z.union([z.array(SavedFunctionId), z.null()]),
|
|
4184
|
+
origin: z.union([
|
|
4185
|
+
z.object({
|
|
4186
|
+
prompt_id: z.string(),
|
|
4187
|
+
project_id: z.string(),
|
|
4188
|
+
prompt_version: z.string()
|
|
4189
|
+
}).partial(),
|
|
4190
|
+
z.null()
|
|
4191
|
+
])
|
|
4192
|
+
}).partial();
|
|
4193
|
+
var FunctionTypeEnum = z.enum(["llm", "scorer", "task", "tool"]);
|
|
4194
|
+
var FunctionId = z.union([
|
|
4195
|
+
z.object({ function_id: z.string(), version: z.string().optional() }),
|
|
4196
|
+
z.object({
|
|
4197
|
+
project_name: z.string(),
|
|
4198
|
+
slug: z.string(),
|
|
4199
|
+
version: z.string().optional()
|
|
4200
|
+
}),
|
|
4201
|
+
z.object({ global_function: z.string() }),
|
|
4202
|
+
z.object({
|
|
4203
|
+
prompt_session_id: z.string(),
|
|
4204
|
+
prompt_session_function_id: z.string(),
|
|
4205
|
+
version: z.string().optional()
|
|
4206
|
+
}),
|
|
4207
|
+
z.object({
|
|
4208
|
+
inline_context: z.object({
|
|
4209
|
+
runtime: z.enum(["node", "python"]),
|
|
4210
|
+
version: z.string()
|
|
4211
|
+
}),
|
|
4212
|
+
code: z.string(),
|
|
4213
|
+
name: z.union([z.string(), z.null()]).optional()
|
|
4214
|
+
}),
|
|
4215
|
+
z.object({
|
|
4216
|
+
inline_prompt: PromptData.optional(),
|
|
4217
|
+
inline_function: z.object({}).partial().passthrough(),
|
|
4218
|
+
function_type: FunctionTypeEnum.optional(),
|
|
4219
|
+
name: z.union([z.string(), z.null()]).optional()
|
|
4220
|
+
}),
|
|
4221
|
+
z.object({
|
|
4222
|
+
inline_prompt: PromptData,
|
|
4223
|
+
function_type: FunctionTypeEnum.optional(),
|
|
4224
|
+
name: z.union([z.string(), z.null()]).optional()
|
|
4225
|
+
})
|
|
4226
|
+
]);
|
|
4227
|
+
var FunctionObjectType = z.enum([
|
|
4228
|
+
"prompt",
|
|
4229
|
+
"tool",
|
|
4230
|
+
"scorer",
|
|
4231
|
+
"task",
|
|
4232
|
+
"agent"
|
|
4233
|
+
]);
|
|
4234
|
+
var FunctionOutputType = z.enum(["completion", "score", "any"]);
|
|
4235
|
+
var GitMetadataSettings = z.object({
|
|
4236
|
+
collect: z.enum(["all", "none", "some"]),
|
|
4237
|
+
fields: z.array(
|
|
4238
|
+
z.enum([
|
|
4239
|
+
"commit",
|
|
4240
|
+
"branch",
|
|
4241
|
+
"tag",
|
|
4242
|
+
"dirty",
|
|
4243
|
+
"author_name",
|
|
4244
|
+
"author_email",
|
|
4245
|
+
"commit_message",
|
|
4246
|
+
"commit_time",
|
|
4247
|
+
"git_diff"
|
|
4248
|
+
])
|
|
4249
|
+
).optional()
|
|
4250
|
+
});
|
|
4251
|
+
var Group = z.object({
|
|
4252
|
+
id: z.string().uuid(),
|
|
4253
|
+
org_id: z.string().uuid(),
|
|
4254
|
+
user_id: z.union([z.string(), z.null()]).optional(),
|
|
4255
|
+
created: z.union([z.string(), z.null()]).optional(),
|
|
4256
|
+
name: z.string(),
|
|
4257
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
4258
|
+
deleted_at: z.union([z.string(), z.null()]).optional(),
|
|
4259
|
+
member_users: z.union([z.array(z.string().uuid()), z.null()]).optional(),
|
|
4260
|
+
member_groups: z.union([z.array(z.string().uuid()), z.null()]).optional()
|
|
4261
|
+
});
|
|
4262
|
+
var IfExists = z.enum(["error", "ignore", "replace"]);
|
|
4263
|
+
var InvokeParent = z.union([
|
|
4264
|
+
z.object({
|
|
4265
|
+
object_type: z.enum(["project_logs", "experiment", "playground_logs"]),
|
|
4266
|
+
object_id: z.string(),
|
|
4267
|
+
row_ids: z.union([
|
|
4268
|
+
z.object({
|
|
4269
|
+
id: z.string(),
|
|
4270
|
+
span_id: z.string(),
|
|
4271
|
+
root_span_id: z.string()
|
|
4272
|
+
}),
|
|
4273
|
+
z.null()
|
|
4274
|
+
]).optional(),
|
|
4275
|
+
propagated_event: z.union([z.object({}).partial().passthrough(), z.null()]).optional()
|
|
4276
|
+
}),
|
|
4277
|
+
z.string()
|
|
4278
|
+
]);
|
|
4279
|
+
var StreamingMode = z.union([z.enum(["auto", "parallel"]), z.null()]);
|
|
4280
|
+
var InvokeFunction = FunctionId.and(
|
|
4281
|
+
z.object({
|
|
4282
|
+
input: z.unknown(),
|
|
4283
|
+
expected: z.unknown(),
|
|
4284
|
+
metadata: z.union([z.object({}).partial().passthrough(), z.null()]),
|
|
4285
|
+
tags: z.union([z.array(z.string()), z.null()]),
|
|
4286
|
+
messages: z.array(ChatCompletionMessageParam),
|
|
4287
|
+
parent: InvokeParent,
|
|
4288
|
+
stream: z.union([z.boolean(), z.null()]),
|
|
4289
|
+
mode: StreamingMode,
|
|
4290
|
+
strict: z.union([z.boolean(), z.null()])
|
|
4291
|
+
}).partial()
|
|
4292
|
+
);
|
|
4293
|
+
var MessageRole = z.enum([
|
|
4294
|
+
"system",
|
|
4295
|
+
"user",
|
|
4296
|
+
"assistant",
|
|
4297
|
+
"function",
|
|
4298
|
+
"tool",
|
|
4299
|
+
"model",
|
|
4300
|
+
"developer"
|
|
4301
|
+
]);
|
|
4302
|
+
var OnlineScoreConfig = z.union([
|
|
4303
|
+
z.object({
|
|
4304
|
+
sampling_rate: z.number().gte(0).lte(1),
|
|
4305
|
+
scorers: z.array(SavedFunctionId),
|
|
4306
|
+
btql_filter: z.union([z.string(), z.null()]).optional(),
|
|
4307
|
+
apply_to_root_span: z.union([z.boolean(), z.null()]).optional(),
|
|
4308
|
+
apply_to_span_names: z.union([z.array(z.string()), z.null()]).optional(),
|
|
4309
|
+
skip_logging: z.union([z.boolean(), z.null()]).optional()
|
|
4310
|
+
}),
|
|
4311
|
+
z.null()
|
|
4312
|
+
]);
|
|
4313
|
+
var Organization = z.object({
|
|
4314
|
+
id: z.string().uuid(),
|
|
4315
|
+
name: z.string(),
|
|
4316
|
+
api_url: z.union([z.string(), z.null()]).optional(),
|
|
4317
|
+
is_universal_api: z.union([z.boolean(), z.null()]).optional(),
|
|
4318
|
+
proxy_url: z.union([z.string(), z.null()]).optional(),
|
|
4319
|
+
realtime_url: z.union([z.string(), z.null()]).optional(),
|
|
4320
|
+
created: z.union([z.string(), z.null()]).optional()
|
|
4321
|
+
});
|
|
4322
|
+
var ProjectSettings = z.union([
|
|
4323
|
+
z.object({
|
|
4324
|
+
comparison_key: z.union([z.string(), z.null()]),
|
|
4325
|
+
baseline_experiment_id: z.union([z.string(), z.null()]),
|
|
4326
|
+
spanFieldOrder: z.union([
|
|
4327
|
+
z.array(
|
|
4328
|
+
z.object({
|
|
4329
|
+
object_type: z.string(),
|
|
4330
|
+
column_id: z.string(),
|
|
4331
|
+
position: z.string(),
|
|
4332
|
+
layout: z.union([z.literal("full"), z.literal("two_column"), z.null()]).optional()
|
|
4333
|
+
})
|
|
4334
|
+
),
|
|
4335
|
+
z.null()
|
|
4336
|
+
]),
|
|
4337
|
+
remote_eval_sources: z.union([
|
|
4338
|
+
z.array(
|
|
4339
|
+
z.object({
|
|
4340
|
+
url: z.string(),
|
|
4341
|
+
name: z.string(),
|
|
4342
|
+
description: z.union([z.string(), z.null()]).optional()
|
|
4343
|
+
})
|
|
4344
|
+
),
|
|
4345
|
+
z.null()
|
|
4346
|
+
])
|
|
4347
|
+
}).partial(),
|
|
4348
|
+
z.null()
|
|
4349
|
+
]);
|
|
4350
|
+
var Project = z.object({
|
|
4351
|
+
id: z.string().uuid(),
|
|
4352
|
+
org_id: z.string().uuid(),
|
|
4353
|
+
name: z.string(),
|
|
4354
|
+
created: z.union([z.string(), z.null()]).optional(),
|
|
4355
|
+
deleted_at: z.union([z.string(), z.null()]).optional(),
|
|
4356
|
+
user_id: z.union([z.string(), z.null()]).optional(),
|
|
4357
|
+
settings: ProjectSettings.optional()
|
|
4358
|
+
});
|
|
4359
|
+
var RetentionObjectType = z.enum([
|
|
4360
|
+
"project_logs",
|
|
4361
|
+
"experiment",
|
|
4362
|
+
"dataset"
|
|
4363
|
+
]);
|
|
4364
|
+
var ProjectAutomation = z.object({
|
|
4365
|
+
id: z.string().uuid(),
|
|
4366
|
+
project_id: z.string().uuid(),
|
|
4367
|
+
user_id: z.union([z.string(), z.null()]).optional(),
|
|
4368
|
+
created: z.union([z.string(), z.null()]).optional(),
|
|
4369
|
+
name: z.string(),
|
|
4370
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
4371
|
+
config: z.union([
|
|
4372
|
+
z.object({
|
|
4373
|
+
event_type: z.literal("logs"),
|
|
4374
|
+
btql_filter: z.string(),
|
|
4375
|
+
interval_seconds: z.number().gte(1).lte(2592e3),
|
|
4376
|
+
action: z.object({ type: z.literal("webhook"), url: z.string() })
|
|
4377
|
+
}),
|
|
4378
|
+
z.object({
|
|
4379
|
+
event_type: z.literal("btql_export"),
|
|
4380
|
+
export_definition: z.union([
|
|
4381
|
+
z.object({ type: z.literal("log_traces") }),
|
|
4382
|
+
z.object({ type: z.literal("log_spans") }),
|
|
4383
|
+
z.object({ type: z.literal("btql_query"), btql_query: z.string() })
|
|
4384
|
+
]),
|
|
4385
|
+
export_path: z.string(),
|
|
4386
|
+
format: z.enum(["jsonl", "parquet"]),
|
|
4387
|
+
interval_seconds: z.number().gte(1).lte(2592e3),
|
|
4388
|
+
credentials: z.object({
|
|
4389
|
+
type: z.literal("aws_iam"),
|
|
4390
|
+
role_arn: z.string(),
|
|
4391
|
+
external_id: z.string()
|
|
4392
|
+
}),
|
|
4393
|
+
batch_size: z.union([z.number(), z.null()]).optional()
|
|
4394
|
+
}),
|
|
4395
|
+
z.object({
|
|
4396
|
+
event_type: z.literal("retention"),
|
|
4397
|
+
object_type: RetentionObjectType,
|
|
4398
|
+
retention_days: z.number().gte(0)
|
|
4399
|
+
})
|
|
4400
|
+
])
|
|
4401
|
+
});
|
|
4402
|
+
var ProjectLogsEvent = z.object({
|
|
4403
|
+
id: z.string(),
|
|
4404
|
+
_xact_id: z.string(),
|
|
4405
|
+
_pagination_key: z.union([z.string(), z.null()]).optional(),
|
|
4406
|
+
created: z.string().datetime({ offset: true }),
|
|
4407
|
+
org_id: z.string().uuid(),
|
|
4408
|
+
project_id: z.string().uuid(),
|
|
4409
|
+
log_id: z.literal("g"),
|
|
4410
|
+
input: z.unknown().optional(),
|
|
4411
|
+
output: z.unknown().optional(),
|
|
4412
|
+
expected: z.unknown().optional(),
|
|
4413
|
+
error: z.unknown().optional(),
|
|
4414
|
+
scores: z.union([z.record(z.union([z.number(), z.null()])), z.null()]).optional(),
|
|
4415
|
+
metadata: z.union([
|
|
4416
|
+
z.object({ model: z.union([z.string(), z.null()]) }).partial().passthrough(),
|
|
4417
|
+
z.null()
|
|
4418
|
+
]).optional(),
|
|
4419
|
+
tags: z.union([z.array(z.string()), z.null()]).optional(),
|
|
4420
|
+
metrics: z.union([z.record(z.number()), z.null()]).optional(),
|
|
4421
|
+
context: z.union([
|
|
4422
|
+
z.object({
|
|
4423
|
+
caller_functionname: z.union([z.string(), z.null()]),
|
|
4424
|
+
caller_filename: z.union([z.string(), z.null()]),
|
|
4425
|
+
caller_lineno: z.union([z.number(), z.null()])
|
|
4426
|
+
}).partial().passthrough(),
|
|
4427
|
+
z.null()
|
|
4428
|
+
]).optional(),
|
|
4429
|
+
span_id: z.string(),
|
|
4430
|
+
span_parents: z.union([z.array(z.string()), z.null()]).optional(),
|
|
4431
|
+
root_span_id: z.string(),
|
|
4432
|
+
is_root: z.union([z.boolean(), z.null()]).optional(),
|
|
4433
|
+
span_attributes: SpanAttributes.optional(),
|
|
4434
|
+
origin: ObjectReference.optional()
|
|
4435
|
+
});
|
|
4436
|
+
var ProjectScoreType = z.enum([
|
|
4437
|
+
"slider",
|
|
4438
|
+
"categorical",
|
|
4439
|
+
"weighted",
|
|
4440
|
+
"minimum",
|
|
4441
|
+
"maximum",
|
|
4442
|
+
"online",
|
|
4443
|
+
"free-form"
|
|
4444
|
+
]);
|
|
4445
|
+
var ProjectScoreCategory = z.object({
|
|
4446
|
+
name: z.string(),
|
|
4447
|
+
value: z.number()
|
|
4448
|
+
});
|
|
4449
|
+
var ProjectScoreCategories = z.union([
|
|
4450
|
+
z.array(ProjectScoreCategory),
|
|
4451
|
+
z.record(z.number()),
|
|
4452
|
+
z.array(z.string()),
|
|
4453
|
+
z.null()
|
|
4454
|
+
]);
|
|
4455
|
+
var ProjectScoreConfig = z.union([
|
|
4456
|
+
z.object({
|
|
4457
|
+
multi_select: z.union([z.boolean(), z.null()]),
|
|
4458
|
+
destination: z.union([z.string(), z.null()]),
|
|
4459
|
+
online: OnlineScoreConfig
|
|
4460
|
+
}).partial(),
|
|
4461
|
+
z.null()
|
|
4462
|
+
]);
|
|
4463
|
+
var ProjectScore = z.object({
|
|
4464
|
+
id: z.string().uuid(),
|
|
4465
|
+
project_id: z.string().uuid(),
|
|
4466
|
+
user_id: z.string().uuid(),
|
|
4467
|
+
created: z.union([z.string(), z.null()]).optional(),
|
|
4468
|
+
name: z.string(),
|
|
4469
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
4470
|
+
score_type: ProjectScoreType,
|
|
4471
|
+
categories: ProjectScoreCategories.optional(),
|
|
4472
|
+
config: ProjectScoreConfig.optional(),
|
|
4473
|
+
position: z.union([z.string(), z.null()]).optional()
|
|
4474
|
+
});
|
|
4475
|
+
var ProjectTag = z.object({
|
|
4476
|
+
id: z.string().uuid(),
|
|
4477
|
+
project_id: z.string().uuid(),
|
|
4478
|
+
user_id: z.string().uuid(),
|
|
4479
|
+
created: z.union([z.string(), z.null()]).optional(),
|
|
4480
|
+
name: z.string(),
|
|
4481
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
4482
|
+
color: z.union([z.string(), z.null()]).optional(),
|
|
4483
|
+
position: z.union([z.string(), z.null()]).optional()
|
|
4484
|
+
});
|
|
4485
|
+
var Prompt = z.object({
|
|
4486
|
+
id: z.string().uuid(),
|
|
4487
|
+
_xact_id: z.string(),
|
|
4488
|
+
project_id: z.string().uuid(),
|
|
4489
|
+
log_id: z.literal("p"),
|
|
4490
|
+
org_id: z.string().uuid(),
|
|
4491
|
+
name: z.string(),
|
|
4492
|
+
slug: z.string(),
|
|
4493
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
4494
|
+
created: z.union([z.string(), z.null()]).optional(),
|
|
4495
|
+
prompt_data: PromptDataNullish.optional(),
|
|
4496
|
+
tags: z.union([z.array(z.string()), z.null()]).optional(),
|
|
4497
|
+
metadata: z.union([z.object({}).partial().passthrough(), z.null()]).optional(),
|
|
4498
|
+
function_type: FunctionTypeEnumNullish.optional()
|
|
4499
|
+
});
|
|
4500
|
+
var PromptOptions = z.object({ model: z.string(), params: ModelParams, position: z.string() }).partial();
|
|
4501
|
+
var PromptSessionEvent = z.object({
|
|
4502
|
+
id: z.string(),
|
|
4503
|
+
_xact_id: z.string(),
|
|
4504
|
+
created: z.string().datetime({ offset: true }),
|
|
4505
|
+
_pagination_key: z.union([z.string(), z.null()]).optional(),
|
|
4506
|
+
project_id: z.string().uuid(),
|
|
4507
|
+
prompt_session_id: z.string().uuid(),
|
|
4508
|
+
prompt_session_data: z.unknown().optional(),
|
|
4509
|
+
prompt_data: z.unknown().optional(),
|
|
4510
|
+
function_data: z.unknown().optional(),
|
|
4511
|
+
function_type: FunctionTypeEnumNullish.optional(),
|
|
4512
|
+
object_data: z.unknown().optional(),
|
|
4513
|
+
completion: z.unknown().optional(),
|
|
4514
|
+
tags: z.union([z.array(z.string()), z.null()]).optional()
|
|
4515
|
+
});
|
|
4516
|
+
var Role = z.object({
|
|
4517
|
+
id: z.string().uuid(),
|
|
4518
|
+
org_id: z.union([z.string(), z.null()]).optional(),
|
|
4519
|
+
user_id: z.union([z.string(), z.null()]).optional(),
|
|
4520
|
+
created: z.union([z.string(), z.null()]).optional(),
|
|
4521
|
+
name: z.string(),
|
|
4522
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
4523
|
+
deleted_at: z.union([z.string(), z.null()]).optional(),
|
|
4524
|
+
member_permissions: z.union([
|
|
4525
|
+
z.array(
|
|
4526
|
+
z.object({
|
|
4527
|
+
permission: Permission,
|
|
4528
|
+
restrict_object_type: AclObjectType.optional()
|
|
4529
|
+
})
|
|
4530
|
+
),
|
|
4531
|
+
z.null()
|
|
4532
|
+
]).optional(),
|
|
4533
|
+
member_roles: z.union([z.array(z.string().uuid()), z.null()]).optional()
|
|
4534
|
+
});
|
|
4535
|
+
var RunEval = z.object({
|
|
4536
|
+
project_id: z.string(),
|
|
4537
|
+
data: z.union([
|
|
4538
|
+
z.object({
|
|
4539
|
+
dataset_id: z.string(),
|
|
4540
|
+
_internal_btql: z.union([z.object({}).partial().passthrough(), z.null()]).optional()
|
|
4541
|
+
}),
|
|
4542
|
+
z.object({
|
|
4543
|
+
project_name: z.string(),
|
|
4544
|
+
dataset_name: z.string(),
|
|
4545
|
+
_internal_btql: z.union([z.object({}).partial().passthrough(), z.null()]).optional()
|
|
4546
|
+
}),
|
|
4547
|
+
z.object({ data: z.array(z.unknown()) })
|
|
4548
|
+
]),
|
|
4549
|
+
task: FunctionId.and(z.unknown()),
|
|
4550
|
+
scores: z.array(FunctionId),
|
|
4551
|
+
experiment_name: z.string().optional(),
|
|
4552
|
+
metadata: z.object({}).partial().passthrough().optional(),
|
|
4553
|
+
parent: InvokeParent.and(z.unknown()).optional(),
|
|
4554
|
+
stream: z.boolean().optional(),
|
|
4555
|
+
trial_count: z.union([z.number(), z.null()]).optional(),
|
|
4556
|
+
is_public: z.union([z.boolean(), z.null()]).optional(),
|
|
4557
|
+
timeout: z.union([z.number(), z.null()]).optional(),
|
|
4558
|
+
max_concurrency: z.union([z.number(), z.null()]).optional().default(10),
|
|
4559
|
+
base_experiment_name: z.union([z.string(), z.null()]).optional(),
|
|
4560
|
+
base_experiment_id: z.union([z.string(), z.null()]).optional(),
|
|
4561
|
+
git_metadata_settings: GitMetadataSettings.and(
|
|
4562
|
+
z.union([z.object({}).partial(), z.null()])
|
|
4563
|
+
).optional(),
|
|
4564
|
+
repo_info: RepoInfo.and(z.unknown()).optional(),
|
|
4565
|
+
strict: z.union([z.boolean(), z.null()]).optional(),
|
|
4566
|
+
stop_token: z.union([z.string(), z.null()]).optional(),
|
|
4567
|
+
extra_messages: z.string().optional(),
|
|
4568
|
+
tags: z.array(z.string()).optional()
|
|
4569
|
+
});
|
|
4570
|
+
var ServiceToken = z.object({
|
|
4571
|
+
id: z.string().uuid(),
|
|
4572
|
+
created: z.union([z.string(), z.null()]).optional(),
|
|
4573
|
+
name: z.string(),
|
|
4574
|
+
preview_name: z.string(),
|
|
4575
|
+
user_id: z.union([z.string(), z.null()]).optional(),
|
|
4576
|
+
user_email: z.union([z.string(), z.null()]).optional(),
|
|
4577
|
+
user_given_name: z.union([z.string(), z.null()]).optional(),
|
|
4578
|
+
user_family_name: z.union([z.string(), z.null()]).optional(),
|
|
4579
|
+
org_id: z.union([z.string(), z.null()]).optional()
|
|
4580
|
+
});
|
|
4581
|
+
var SpanIFrame = z.object({
|
|
4582
|
+
id: z.string().uuid(),
|
|
4583
|
+
project_id: z.string().uuid(),
|
|
4584
|
+
user_id: z.union([z.string(), z.null()]).optional(),
|
|
4585
|
+
created: z.union([z.string(), z.null()]).optional(),
|
|
4586
|
+
deleted_at: z.union([z.string(), z.null()]).optional(),
|
|
4587
|
+
name: z.string(),
|
|
4588
|
+
description: z.union([z.string(), z.null()]).optional(),
|
|
4589
|
+
url: z.string(),
|
|
4590
|
+
post_message: z.union([z.boolean(), z.null()]).optional()
|
|
4591
|
+
});
|
|
4592
|
+
var SSEConsoleEventData = z.object({
|
|
4593
|
+
stream: z.enum(["stderr", "stdout"]),
|
|
4594
|
+
message: z.string()
|
|
4595
|
+
});
|
|
4596
|
+
var SSEProgressEventData = z.object({
|
|
4597
|
+
id: z.string(),
|
|
4598
|
+
object_type: FunctionObjectType,
|
|
4599
|
+
origin: ObjectReference.and(z.unknown()).optional(),
|
|
4600
|
+
format: FunctionFormat,
|
|
4601
|
+
output_type: FunctionOutputType,
|
|
4602
|
+
name: z.string(),
|
|
4603
|
+
event: z.enum([
|
|
4604
|
+
"reasoning_delta",
|
|
4605
|
+
"text_delta",
|
|
4606
|
+
"json_delta",
|
|
4607
|
+
"error",
|
|
4608
|
+
"console",
|
|
4609
|
+
"start",
|
|
4610
|
+
"done",
|
|
4611
|
+
"progress"
|
|
4612
|
+
]),
|
|
4613
|
+
data: z.string()
|
|
4614
|
+
});
|
|
4615
|
+
var ToolFunctionDefinition = z.object({
|
|
4616
|
+
type: z.literal("function"),
|
|
4617
|
+
function: z.object({
|
|
4618
|
+
name: z.string(),
|
|
4619
|
+
description: z.string().optional(),
|
|
4620
|
+
parameters: z.object({}).partial().passthrough().optional(),
|
|
4621
|
+
strict: z.union([z.boolean(), z.null()]).optional()
|
|
4622
|
+
})
|
|
4623
|
+
});
|
|
4624
|
+
var User = z.object({
|
|
4625
|
+
id: z.string().uuid(),
|
|
4626
|
+
given_name: z.union([z.string(), z.null()]).optional(),
|
|
4627
|
+
family_name: z.union([z.string(), z.null()]).optional(),
|
|
4628
|
+
email: z.union([z.string(), z.null()]).optional(),
|
|
4629
|
+
avatar_url: z.union([z.string(), z.null()]).optional(),
|
|
4630
|
+
created: z.union([z.string(), z.null()]).optional()
|
|
4631
|
+
});
|
|
4632
|
+
var ViewDataSearch = z.union([
|
|
4633
|
+
z.object({
|
|
4634
|
+
filter: z.union([z.array(z.unknown()), z.null()]),
|
|
4635
|
+
tag: z.union([z.array(z.unknown()), z.null()]),
|
|
4636
|
+
match: z.union([z.array(z.unknown()), z.null()]),
|
|
4637
|
+
sort: z.union([z.array(z.unknown()), z.null()])
|
|
4638
|
+
}).partial(),
|
|
4639
|
+
z.null()
|
|
4640
|
+
]);
|
|
4641
|
+
var ViewData = z.union([
|
|
4642
|
+
z.object({ search: ViewDataSearch }).partial(),
|
|
4643
|
+
z.null()
|
|
4644
|
+
]);
|
|
4645
|
+
var ViewOptions = z.union([
|
|
4646
|
+
z.object({
|
|
4647
|
+
viewType: z.literal("monitor"),
|
|
4648
|
+
options: z.object({
|
|
4649
|
+
spanType: z.union([z.enum(["range", "frame"]), z.null()]),
|
|
4650
|
+
rangeValue: z.union([z.string(), z.null()]),
|
|
4651
|
+
frameStart: z.union([z.string(), z.null()]),
|
|
4652
|
+
frameEnd: z.union([z.string(), z.null()]),
|
|
4653
|
+
tzUTC: z.union([z.boolean(), z.null()]),
|
|
4654
|
+
chartVisibility: z.union([z.record(z.boolean()), z.null()]),
|
|
4655
|
+
projectId: z.union([z.string(), z.null()]),
|
|
4656
|
+
type: z.union([z.enum(["project", "experiment"]), z.null()]),
|
|
4657
|
+
groupBy: z.union([z.string(), z.null()])
|
|
4658
|
+
}).partial()
|
|
4659
|
+
}),
|
|
4660
|
+
z.object({
|
|
4661
|
+
columnVisibility: z.union([z.record(z.boolean()), z.null()]),
|
|
4662
|
+
columnOrder: z.union([z.array(z.string()), z.null()]),
|
|
4663
|
+
columnSizing: z.union([z.record(z.number()), z.null()]),
|
|
4664
|
+
grouping: z.union([z.string(), z.null()]),
|
|
4665
|
+
rowHeight: z.union([z.string(), z.null()]),
|
|
4666
|
+
tallGroupRows: z.union([z.boolean(), z.null()]),
|
|
4667
|
+
layout: z.union([z.string(), z.null()]),
|
|
4668
|
+
chartHeight: z.union([z.number(), z.null()]),
|
|
4669
|
+
excludedMeasures: z.union([
|
|
4670
|
+
z.array(
|
|
4671
|
+
z.object({
|
|
4672
|
+
type: z.enum(["none", "score", "metric", "metadata"]),
|
|
4673
|
+
value: z.string()
|
|
4674
|
+
})
|
|
4675
|
+
),
|
|
4676
|
+
z.null()
|
|
4677
|
+
]),
|
|
4678
|
+
yMetric: z.union([
|
|
4679
|
+
z.object({
|
|
4680
|
+
type: z.enum(["none", "score", "metric", "metadata"]),
|
|
4681
|
+
value: z.string()
|
|
4682
|
+
}),
|
|
4683
|
+
z.null()
|
|
4684
|
+
]),
|
|
4685
|
+
xAxis: z.union([
|
|
4686
|
+
z.object({
|
|
4687
|
+
type: z.enum(["none", "score", "metric", "metadata"]),
|
|
4688
|
+
value: z.string()
|
|
4689
|
+
}),
|
|
4690
|
+
z.null()
|
|
4691
|
+
]),
|
|
4692
|
+
symbolGrouping: z.union([
|
|
4693
|
+
z.object({
|
|
4694
|
+
type: z.enum(["none", "score", "metric", "metadata"]),
|
|
4695
|
+
value: z.string()
|
|
4696
|
+
}),
|
|
4697
|
+
z.null()
|
|
4698
|
+
]),
|
|
4699
|
+
xAxisAggregation: z.union([z.string(), z.null()]),
|
|
4700
|
+
chartAnnotations: z.union([
|
|
4701
|
+
z.array(z.object({ id: z.string(), text: z.string() })),
|
|
4702
|
+
z.null()
|
|
4703
|
+
]),
|
|
4704
|
+
timeRangeFilter: z.union([
|
|
4705
|
+
z.string(),
|
|
4706
|
+
z.object({ from: z.string(), to: z.string() }),
|
|
4707
|
+
z.null()
|
|
4708
|
+
])
|
|
4709
|
+
}).partial(),
|
|
4710
|
+
z.null()
|
|
4711
|
+
]);
|
|
4712
|
+
var View = z.object({
|
|
4713
|
+
id: z.string().uuid(),
|
|
4714
|
+
object_type: AclObjectType.and(z.string()),
|
|
4715
|
+
object_id: z.string().uuid(),
|
|
4716
|
+
view_type: z.enum([
|
|
4717
|
+
"projects",
|
|
4718
|
+
"experiments",
|
|
4719
|
+
"experiment",
|
|
4720
|
+
"playgrounds",
|
|
4721
|
+
"playground",
|
|
4722
|
+
"datasets",
|
|
4723
|
+
"dataset",
|
|
4724
|
+
"prompts",
|
|
4725
|
+
"tools",
|
|
4726
|
+
"scorers",
|
|
4727
|
+
"logs",
|
|
4728
|
+
"agents",
|
|
4729
|
+
"monitor"
|
|
4730
|
+
]),
|
|
4731
|
+
name: z.string(),
|
|
4732
|
+
created: z.union([z.string(), z.null()]).optional(),
|
|
4733
|
+
view_data: ViewData.optional(),
|
|
4734
|
+
options: ViewOptions.optional(),
|
|
4735
|
+
user_id: z.union([z.string(), z.null()]).optional(),
|
|
4736
|
+
deleted_at: z.union([z.string(), z.null()]).optional()
|
|
4737
|
+
});
|
|
4738
|
+
|
|
4739
|
+
// src/logger.ts
|
|
4740
|
+
import { waitUntil } from "@vercel/functions";
|
|
4741
|
+
import Mustache2 from "mustache";
|
|
4742
|
+
import { z as z3, ZodError } from "zod";
|
|
4743
|
+
|
|
4744
|
+
// src/functions/stream.ts
|
|
4745
|
+
import {
|
|
4746
|
+
createParser
|
|
4747
|
+
} from "eventsource-parser";
|
|
4748
|
+
import { z as z2 } from "zod";
|
|
4749
|
+
var braintrustStreamChunkSchema = z2.union([
|
|
4750
|
+
z2.object({
|
|
4751
|
+
type: z2.literal("text_delta"),
|
|
4752
|
+
data: z2.string()
|
|
4753
|
+
}),
|
|
4754
|
+
z2.object({
|
|
4755
|
+
type: z2.literal("reasoning_delta"),
|
|
4756
|
+
data: z2.string()
|
|
4757
|
+
}),
|
|
4758
|
+
z2.object({
|
|
4759
|
+
type: z2.literal("json_delta"),
|
|
4760
|
+
data: z2.string()
|
|
4761
|
+
}),
|
|
4762
|
+
z2.object({
|
|
4763
|
+
type: z2.literal("error"),
|
|
4764
|
+
data: z2.string()
|
|
4765
|
+
}),
|
|
4766
|
+
z2.object({
|
|
4767
|
+
type: z2.literal("console"),
|
|
4768
|
+
data: SSEConsoleEventData
|
|
4769
|
+
}),
|
|
4770
|
+
z2.object({
|
|
4771
|
+
type: z2.literal("progress"),
|
|
4772
|
+
data: SSEProgressEventData
|
|
4773
|
+
}),
|
|
4774
|
+
z2.object({
|
|
4775
|
+
type: z2.literal("start"),
|
|
4776
|
+
data: z2.string()
|
|
4777
|
+
}),
|
|
4778
|
+
z2.object({
|
|
4779
|
+
type: z2.literal("done"),
|
|
4780
|
+
data: z2.string()
|
|
3580
4781
|
})
|
|
3581
4782
|
]);
|
|
3582
4783
|
var BraintrustStream = class _BraintrustStream {
|
|
@@ -3684,12 +4885,12 @@ var BraintrustStream = class _BraintrustStream {
|
|
|
3684
4885
|
case "progress":
|
|
3685
4886
|
return {
|
|
3686
4887
|
type: "progress",
|
|
3687
|
-
data:
|
|
4888
|
+
data: SSEProgressEventData.parse(JSON.parse(event.data))
|
|
3688
4889
|
};
|
|
3689
4890
|
case "console":
|
|
3690
4891
|
return {
|
|
3691
4892
|
type: "console",
|
|
3692
|
-
data:
|
|
4893
|
+
data: SSEConsoleEventData.parse(JSON.parse(event.data))
|
|
3693
4894
|
};
|
|
3694
4895
|
case "start":
|
|
3695
4896
|
return {
|
|
@@ -3765,7 +4966,7 @@ function btStreamParser() {
|
|
|
3765
4966
|
if (event.type === "reconnect-interval") {
|
|
3766
4967
|
return;
|
|
3767
4968
|
}
|
|
3768
|
-
const parsed =
|
|
4969
|
+
const parsed = CallEvent.safeParse(event);
|
|
3769
4970
|
if (!parsed.success) {
|
|
3770
4971
|
throw new Error(`Failed to parse event: ${parsed.error}`);
|
|
3771
4972
|
}
|
|
@@ -4196,6 +5397,44 @@ function getMustacheVars(prompt) {
|
|
|
4196
5397
|
}
|
|
4197
5398
|
|
|
4198
5399
|
// src/logger.ts
|
|
5400
|
+
import { prettifyXact } from "@braintrust/core";
|
|
5401
|
+
var BRAINTRUST_ATTACHMENT = BraintrustAttachmentReference.shape.type.value;
|
|
5402
|
+
var EXTERNAL_ATTACHMENT = ExternalAttachmentReference.shape.type.value;
|
|
5403
|
+
var BRAINTRUST_PARAMS = Object.keys(BraintrustModelParams.shape);
|
|
5404
|
+
var REDACTION_FIELDS = [
|
|
5405
|
+
"input",
|
|
5406
|
+
"output",
|
|
5407
|
+
"expected",
|
|
5408
|
+
"metadata",
|
|
5409
|
+
"context",
|
|
5410
|
+
"scores",
|
|
5411
|
+
"metrics"
|
|
5412
|
+
];
|
|
5413
|
+
var MaskingError = class {
|
|
5414
|
+
constructor(fieldName, errorType) {
|
|
5415
|
+
this.fieldName = fieldName;
|
|
5416
|
+
this.errorType = errorType;
|
|
5417
|
+
}
|
|
5418
|
+
get errorMsg() {
|
|
5419
|
+
return `ERROR: Failed to mask field '${this.fieldName}' - ${this.errorType}`;
|
|
5420
|
+
}
|
|
5421
|
+
};
|
|
5422
|
+
function applyMaskingToField(maskingFunction, data, fieldName) {
|
|
5423
|
+
try {
|
|
5424
|
+
return maskingFunction(data);
|
|
5425
|
+
} catch (error2) {
|
|
5426
|
+
const errorType = error2 instanceof Error ? error2.constructor.name : "Error";
|
|
5427
|
+
if (fieldName === "scores" || fieldName === "metrics") {
|
|
5428
|
+
return new MaskingError(fieldName, errorType);
|
|
5429
|
+
}
|
|
5430
|
+
if (fieldName === "metadata") {
|
|
5431
|
+
return {
|
|
5432
|
+
error: `ERROR: Failed to mask field '${fieldName}' - ${errorType}`
|
|
5433
|
+
};
|
|
5434
|
+
}
|
|
5435
|
+
return `ERROR: Failed to mask field '${fieldName}' - ${errorType}`;
|
|
5436
|
+
}
|
|
5437
|
+
}
|
|
4199
5438
|
var NoopSpan = class {
|
|
4200
5439
|
id;
|
|
4201
5440
|
spanId;
|
|
@@ -4246,15 +5485,15 @@ var NoopSpan = class {
|
|
|
4246
5485
|
};
|
|
4247
5486
|
var NOOP_SPAN = new NoopSpan();
|
|
4248
5487
|
var NOOP_SPAN_PERMALINK = "https://braintrust.dev/noop-span";
|
|
4249
|
-
var loginSchema =
|
|
4250
|
-
appUrl:
|
|
4251
|
-
appPublicUrl:
|
|
4252
|
-
orgName:
|
|
4253
|
-
apiUrl:
|
|
4254
|
-
proxyUrl:
|
|
4255
|
-
loginToken:
|
|
4256
|
-
orgId:
|
|
4257
|
-
gitMetadataSettings:
|
|
5488
|
+
var loginSchema = z3.strictObject({
|
|
5489
|
+
appUrl: z3.string(),
|
|
5490
|
+
appPublicUrl: z3.string(),
|
|
5491
|
+
orgName: z3.string(),
|
|
5492
|
+
apiUrl: z3.string(),
|
|
5493
|
+
proxyUrl: z3.string(),
|
|
5494
|
+
loginToken: z3.string(),
|
|
5495
|
+
orgId: z3.string().nullish(),
|
|
5496
|
+
gitMetadataSettings: GitMetadataSettings.nullish()
|
|
4258
5497
|
});
|
|
4259
5498
|
var stateNonce = 0;
|
|
4260
5499
|
var BraintrustState = class _BraintrustState {
|
|
@@ -4396,6 +5635,9 @@ var BraintrustState = class _BraintrustState {
|
|
|
4396
5635
|
this._apiConn?.setFetch(fetch2);
|
|
4397
5636
|
this._appConn?.setFetch(fetch2);
|
|
4398
5637
|
}
|
|
5638
|
+
setMaskingFunction(maskingFunction) {
|
|
5639
|
+
this.bgLogger().setMaskingFunction(maskingFunction);
|
|
5640
|
+
}
|
|
4399
5641
|
async login(loginParams) {
|
|
4400
5642
|
if (this.apiUrl && !loginParams.forceLogin) {
|
|
4401
5643
|
return;
|
|
@@ -4474,6 +5716,18 @@ function useTestBackgroundLogger() {
|
|
|
4474
5716
|
function clearTestBackgroundLogger() {
|
|
4475
5717
|
_internalGetGlobalState()?.setOverrideBgLogger(null);
|
|
4476
5718
|
}
|
|
5719
|
+
function initTestExperiment(experimentName, projectName) {
|
|
5720
|
+
setInitialTestState();
|
|
5721
|
+
const state = _internalGetGlobalState();
|
|
5722
|
+
const project = projectName ?? experimentName;
|
|
5723
|
+
const lazyMetadata = new LazyValue(
|
|
5724
|
+
async () => ({
|
|
5725
|
+
project: { id: project, name: project, fullInfo: {} },
|
|
5726
|
+
experiment: { id: experimentName, name: experimentName, fullInfo: {} }
|
|
5727
|
+
})
|
|
5728
|
+
);
|
|
5729
|
+
return new Experiment2(state, lazyMetadata);
|
|
5730
|
+
}
|
|
4477
5731
|
function _internalSetInitialState() {
|
|
4478
5732
|
if (_globalState) {
|
|
4479
5733
|
console.warn(
|
|
@@ -4715,9 +5969,9 @@ var Attachment = class extends BaseAttachment {
|
|
|
4715
5969
|
let signedUrl;
|
|
4716
5970
|
let headers;
|
|
4717
5971
|
try {
|
|
4718
|
-
({ signedUrl, headers } =
|
|
4719
|
-
signedUrl:
|
|
4720
|
-
headers:
|
|
5972
|
+
({ signedUrl, headers } = z3.object({
|
|
5973
|
+
signedUrl: z3.string().url(),
|
|
5974
|
+
headers: z3.record(z3.string())
|
|
4721
5975
|
}).parse(await metadataResponse.json()));
|
|
4722
5976
|
} catch (error2) {
|
|
4723
5977
|
if (error2 instanceof ZodError) {
|
|
@@ -4777,6 +6031,7 @@ var Attachment = class extends BaseAttachment {
|
|
|
4777
6031
|
}
|
|
4778
6032
|
initData(data) {
|
|
4779
6033
|
if (typeof data === "string") {
|
|
6034
|
+
this.ensureFileReadable(data);
|
|
4780
6035
|
const readFile2 = isomorph_default.readFile;
|
|
4781
6036
|
if (!readFile2) {
|
|
4782
6037
|
throw new Error(
|
|
@@ -4789,6 +6044,20 @@ with a Blob/ArrayBuffer, or run the program on Node.js.`
|
|
|
4789
6044
|
return new LazyValue(async () => new Blob([data]));
|
|
4790
6045
|
}
|
|
4791
6046
|
}
|
|
6047
|
+
ensureFileReadable(data) {
|
|
6048
|
+
const statSync2 = isomorph_default.statSync;
|
|
6049
|
+
if (!statSync2) {
|
|
6050
|
+
throw new Error(
|
|
6051
|
+
`This platform does not support reading the filesystem. Construct the Attachment
|
|
6052
|
+
with a Blob/ArrayBuffer, or run the program on Node.js.`
|
|
6053
|
+
);
|
|
6054
|
+
}
|
|
6055
|
+
try {
|
|
6056
|
+
statSync2(data);
|
|
6057
|
+
} catch (e) {
|
|
6058
|
+
console.warn(`Failed to read file: ${e}`);
|
|
6059
|
+
}
|
|
6060
|
+
}
|
|
4792
6061
|
};
|
|
4793
6062
|
var ExternalAttachment = class extends BaseAttachment {
|
|
4794
6063
|
/**
|
|
@@ -4857,9 +6126,9 @@ var ExternalAttachment = class extends BaseAttachment {
|
|
|
4857
6126
|
});
|
|
4858
6127
|
}
|
|
4859
6128
|
};
|
|
4860
|
-
var attachmentMetadataSchema =
|
|
4861
|
-
downloadUrl:
|
|
4862
|
-
status:
|
|
6129
|
+
var attachmentMetadataSchema = z3.object({
|
|
6130
|
+
downloadUrl: z3.string(),
|
|
6131
|
+
status: AttachmentStatus
|
|
4863
6132
|
});
|
|
4864
6133
|
var ReadonlyAttachment = class {
|
|
4865
6134
|
/**
|
|
@@ -5398,9 +6667,13 @@ function now() {
|
|
|
5398
6667
|
}
|
|
5399
6668
|
var TestBackgroundLogger = class {
|
|
5400
6669
|
items = [];
|
|
6670
|
+
maskingFunction = null;
|
|
5401
6671
|
log(items) {
|
|
5402
6672
|
this.items.push(items);
|
|
5403
6673
|
}
|
|
6674
|
+
setMaskingFunction(maskingFunction) {
|
|
6675
|
+
this.maskingFunction = maskingFunction;
|
|
6676
|
+
}
|
|
5404
6677
|
async flush() {
|
|
5405
6678
|
return Promise.resolve();
|
|
5406
6679
|
}
|
|
@@ -5414,7 +6687,34 @@ var TestBackgroundLogger = class {
|
|
|
5414
6687
|
}
|
|
5415
6688
|
}
|
|
5416
6689
|
const batch = mergeRowBatch(events);
|
|
5417
|
-
|
|
6690
|
+
let flatBatch = batch.flat();
|
|
6691
|
+
if (this.maskingFunction) {
|
|
6692
|
+
flatBatch = flatBatch.map((item) => {
|
|
6693
|
+
const maskedItem = { ...item };
|
|
6694
|
+
for (const field of REDACTION_FIELDS) {
|
|
6695
|
+
if (item[field] !== void 0) {
|
|
6696
|
+
const maskedValue = applyMaskingToField(
|
|
6697
|
+
this.maskingFunction,
|
|
6698
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
6699
|
+
item[field],
|
|
6700
|
+
field
|
|
6701
|
+
);
|
|
6702
|
+
if (maskedValue instanceof MaskingError) {
|
|
6703
|
+
delete maskedItem[field];
|
|
6704
|
+
if (maskedItem.error) {
|
|
6705
|
+
maskedItem.error = `${maskedItem.error}; ${maskedValue.errorMsg}`;
|
|
6706
|
+
} else {
|
|
6707
|
+
maskedItem.error = maskedValue.errorMsg;
|
|
6708
|
+
}
|
|
6709
|
+
} else {
|
|
6710
|
+
maskedItem[field] = maskedValue;
|
|
6711
|
+
}
|
|
6712
|
+
}
|
|
6713
|
+
}
|
|
6714
|
+
return maskedItem;
|
|
6715
|
+
});
|
|
6716
|
+
}
|
|
6717
|
+
return flatBatch;
|
|
5418
6718
|
}
|
|
5419
6719
|
};
|
|
5420
6720
|
var BACKGROUND_LOGGER_BASE_SLEEP_TIME_S = 1;
|
|
@@ -5425,6 +6725,7 @@ var HTTPBackgroundLogger = class _HTTPBackgroundLogger {
|
|
|
5425
6725
|
activeFlushResolved = true;
|
|
5426
6726
|
activeFlushError = void 0;
|
|
5427
6727
|
onFlushError;
|
|
6728
|
+
maskingFunction = null;
|
|
5428
6729
|
syncFlush = false;
|
|
5429
6730
|
// 6 MB for the AWS lambda gateway (from our own testing).
|
|
5430
6731
|
maxRequestSize = 6 * 1024 * 1024;
|
|
@@ -5492,6 +6793,9 @@ var HTTPBackgroundLogger = class _HTTPBackgroundLogger {
|
|
|
5492
6793
|
}
|
|
5493
6794
|
this.onFlushError = opts.onFlushError;
|
|
5494
6795
|
}
|
|
6796
|
+
setMaskingFunction(maskingFunction) {
|
|
6797
|
+
this.maskingFunction = maskingFunction;
|
|
6798
|
+
}
|
|
5495
6799
|
log(items) {
|
|
5496
6800
|
if (this._disabled) {
|
|
5497
6801
|
return;
|
|
@@ -5588,7 +6892,36 @@ var HTTPBackgroundLogger = class _HTTPBackgroundLogger {
|
|
|
5588
6892
|
const items = await Promise.all(wrappedItems.map((x) => x.get()));
|
|
5589
6893
|
const attachments = [];
|
|
5590
6894
|
items.forEach((item) => extractAttachments(item, attachments));
|
|
5591
|
-
|
|
6895
|
+
let mergedItems = mergeRowBatch(items);
|
|
6896
|
+
if (this.maskingFunction) {
|
|
6897
|
+
mergedItems = mergedItems.map(
|
|
6898
|
+
(batch) => batch.map((item) => {
|
|
6899
|
+
const maskedItem = { ...item };
|
|
6900
|
+
for (const field of REDACTION_FIELDS) {
|
|
6901
|
+
if (item[field] !== void 0) {
|
|
6902
|
+
const maskedValue = applyMaskingToField(
|
|
6903
|
+
this.maskingFunction,
|
|
6904
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
6905
|
+
item[field],
|
|
6906
|
+
field
|
|
6907
|
+
);
|
|
6908
|
+
if (maskedValue instanceof MaskingError) {
|
|
6909
|
+
delete maskedItem[field];
|
|
6910
|
+
if (maskedItem.error) {
|
|
6911
|
+
maskedItem.error = `${maskedItem.error}; ${maskedValue.errorMsg}`;
|
|
6912
|
+
} else {
|
|
6913
|
+
maskedItem.error = maskedValue.errorMsg;
|
|
6914
|
+
}
|
|
6915
|
+
} else {
|
|
6916
|
+
maskedItem[field] = maskedValue;
|
|
6917
|
+
}
|
|
6918
|
+
}
|
|
6919
|
+
}
|
|
6920
|
+
return maskedItem;
|
|
6921
|
+
})
|
|
6922
|
+
);
|
|
6923
|
+
}
|
|
6924
|
+
return [mergedItems, attachments];
|
|
5592
6925
|
} catch (e) {
|
|
5593
6926
|
let errmsg = "Encountered error when constructing records to flush";
|
|
5594
6927
|
const isRetrying = i + 1 < this.numTries;
|
|
@@ -5936,7 +7269,7 @@ function init(projectOrOptions, optionalOptions) {
|
|
|
5936
7269
|
};
|
|
5937
7270
|
}
|
|
5938
7271
|
);
|
|
5939
|
-
const ret = new
|
|
7272
|
+
const ret = new Experiment2(state, lazyMetadata, dataset);
|
|
5940
7273
|
if (options.setCurrent ?? true) {
|
|
5941
7274
|
state.currentExperiment = ret;
|
|
5942
7275
|
}
|
|
@@ -6033,7 +7366,7 @@ function initDataset(projectOrOptions, optionalOptions) {
|
|
|
6033
7366
|
};
|
|
6034
7367
|
}
|
|
6035
7368
|
);
|
|
6036
|
-
return new
|
|
7369
|
+
return new Dataset2(
|
|
6037
7370
|
stateArg ?? _globalState,
|
|
6038
7371
|
lazyMetadata,
|
|
6039
7372
|
version,
|
|
@@ -6229,8 +7562,8 @@ async function loadPrompt({
|
|
|
6229
7562
|
);
|
|
6230
7563
|
}
|
|
6231
7564
|
}
|
|
6232
|
-
const metadata =
|
|
6233
|
-
const prompt = new
|
|
7565
|
+
const metadata = Prompt.parse(response["objects"][0]);
|
|
7566
|
+
const prompt = new Prompt2(metadata, defaults || {}, noTrace);
|
|
6234
7567
|
try {
|
|
6235
7568
|
if (id) {
|
|
6236
7569
|
await state.promptCache.set({ id }, prompt);
|
|
@@ -6245,6 +7578,9 @@ async function loadPrompt({
|
|
|
6245
7578
|
}
|
|
6246
7579
|
return prompt;
|
|
6247
7580
|
}
|
|
7581
|
+
function setMaskingFunction(maskingFunction) {
|
|
7582
|
+
_globalState.setMaskingFunction(maskingFunction);
|
|
7583
|
+
}
|
|
6248
7584
|
async function login(options = {}) {
|
|
6249
7585
|
const { forceLogin = false } = options || {};
|
|
6250
7586
|
if (_globalState.loggedIn && !forceLogin) {
|
|
@@ -6769,13 +8105,13 @@ function validateAndSanitizeExperimentLogPartialArgs(event) {
|
|
|
6769
8105
|
function deepCopyEvent(event) {
|
|
6770
8106
|
const attachments = [];
|
|
6771
8107
|
const IDENTIFIER = "_bt_internal_saved_attachment";
|
|
6772
|
-
const savedAttachmentSchema =
|
|
8108
|
+
const savedAttachmentSchema = z3.strictObject({ [IDENTIFIER]: z3.number() });
|
|
6773
8109
|
const serialized = JSON.stringify(event, (_k, v) => {
|
|
6774
8110
|
if (v instanceof SpanImpl || v instanceof NoopSpan) {
|
|
6775
8111
|
return `<span>`;
|
|
6776
|
-
} else if (v instanceof
|
|
8112
|
+
} else if (v instanceof Experiment2) {
|
|
6777
8113
|
return `<experiment>`;
|
|
6778
|
-
} else if (v instanceof
|
|
8114
|
+
} else if (v instanceof Dataset2) {
|
|
6779
8115
|
return `<dataset>`;
|
|
6780
8116
|
} else if (v instanceof Logger) {
|
|
6781
8117
|
return `<logger>`;
|
|
@@ -6827,7 +8163,7 @@ function extractAttachments(event, attachments) {
|
|
|
6827
8163
|
}
|
|
6828
8164
|
function enrichAttachments(event, state) {
|
|
6829
8165
|
for (const [key, value] of Object.entries(event)) {
|
|
6830
|
-
const parsedValue =
|
|
8166
|
+
const parsedValue = AttachmentReference.safeParse(value);
|
|
6831
8167
|
if (parsedValue.success) {
|
|
6832
8168
|
event[key] = new ReadonlyAttachment(parsedValue.data, state);
|
|
6833
8169
|
continue;
|
|
@@ -6970,7 +8306,7 @@ var ObjectFetcher = class {
|
|
|
6970
8306
|
}
|
|
6971
8307
|
}
|
|
6972
8308
|
};
|
|
6973
|
-
var
|
|
8309
|
+
var Experiment2 = class extends ObjectFetcher {
|
|
6974
8310
|
lazyMetadata;
|
|
6975
8311
|
dataset;
|
|
6976
8312
|
lastStartTime;
|
|
@@ -7576,7 +8912,7 @@ function splitLoggingData({
|
|
|
7576
8912
|
}
|
|
7577
8913
|
return [serializableInternalData, lazyInternalData];
|
|
7578
8914
|
}
|
|
7579
|
-
var
|
|
8915
|
+
var Dataset2 = class extends ObjectFetcher {
|
|
7580
8916
|
constructor(state, lazyMetadata, pinnedVersion, legacy, _internal_btql) {
|
|
7581
8917
|
const isLegacyDataset = legacy ?? DEFAULT_IS_LEGACY_DATASET;
|
|
7582
8918
|
if (isLegacyDataset) {
|
|
@@ -7774,8 +9110,8 @@ var Dataset = class extends ObjectFetcher {
|
|
|
7774
9110
|
)}`;
|
|
7775
9111
|
let dataSummary;
|
|
7776
9112
|
if (summarizeData) {
|
|
7777
|
-
const rawDataSummary =
|
|
7778
|
-
total_records:
|
|
9113
|
+
const rawDataSummary = z3.object({
|
|
9114
|
+
total_records: z3.number()
|
|
7779
9115
|
}).parse(
|
|
7780
9116
|
await state.apiConn().get_json(
|
|
7781
9117
|
"dataset-summary",
|
|
@@ -7898,11 +9234,11 @@ function renderTemplatedObject(obj, args, options) {
|
|
|
7898
9234
|
return obj;
|
|
7899
9235
|
}
|
|
7900
9236
|
function renderPromptParams(params, args, options) {
|
|
7901
|
-
const schemaParsed =
|
|
7902
|
-
response_format:
|
|
7903
|
-
type:
|
|
7904
|
-
json_schema:
|
|
7905
|
-
schema:
|
|
9237
|
+
const schemaParsed = z3.object({
|
|
9238
|
+
response_format: z3.object({
|
|
9239
|
+
type: z3.literal("json_schema"),
|
|
9240
|
+
json_schema: ResponseFormatJsonSchema.omit({ schema: true }).extend({
|
|
9241
|
+
schema: z3.unknown()
|
|
7906
9242
|
})
|
|
7907
9243
|
})
|
|
7908
9244
|
}).safeParse(params);
|
|
@@ -7923,7 +9259,7 @@ function renderPromptParams(params, args, options) {
|
|
|
7923
9259
|
}
|
|
7924
9260
|
return params;
|
|
7925
9261
|
}
|
|
7926
|
-
var
|
|
9262
|
+
var Prompt2 = class _Prompt {
|
|
7927
9263
|
constructor(metadata, defaults, noTrace) {
|
|
7928
9264
|
this.metadata = metadata;
|
|
7929
9265
|
this.defaults = defaults;
|
|
@@ -8020,7 +9356,7 @@ var Prompt = class _Prompt {
|
|
|
8020
9356
|
if (!prompt) {
|
|
8021
9357
|
throw new Error("Empty prompt");
|
|
8022
9358
|
}
|
|
8023
|
-
const dictArgParsed =
|
|
9359
|
+
const dictArgParsed = z3.record(z3.unknown()).safeParse(buildArgs);
|
|
8024
9360
|
const variables = {
|
|
8025
9361
|
input: buildArgs,
|
|
8026
9362
|
...dictArgParsed.success ? dictArgParsed.data : {}
|
|
@@ -8041,7 +9377,7 @@ var Prompt = class _Prompt {
|
|
|
8041
9377
|
...spanInfo,
|
|
8042
9378
|
messages: renderedPrompt.messages,
|
|
8043
9379
|
...renderedPrompt.tools ? {
|
|
8044
|
-
tools:
|
|
9380
|
+
tools: ChatCompletionTool.array().parse(JSON.parse(renderedPrompt.tools))
|
|
8045
9381
|
} : void 0
|
|
8046
9382
|
};
|
|
8047
9383
|
} else if (flavor === "completion") {
|
|
@@ -8075,7 +9411,7 @@ var Prompt = class _Prompt {
|
|
|
8075
9411
|
return JSON.stringify(v);
|
|
8076
9412
|
}
|
|
8077
9413
|
};
|
|
8078
|
-
const dictArgParsed =
|
|
9414
|
+
const dictArgParsed = z3.record(z3.unknown()).safeParse(buildArgs);
|
|
8079
9415
|
const variables = {
|
|
8080
9416
|
input: buildArgs,
|
|
8081
9417
|
...dictArgParsed.success ? dictArgParsed.data : {}
|
|
@@ -8128,7 +9464,7 @@ var Prompt = class _Prompt {
|
|
|
8128
9464
|
}
|
|
8129
9465
|
getParsedPromptData() {
|
|
8130
9466
|
if (!this.hasParsedPromptData) {
|
|
8131
|
-
this.parsedPromptData =
|
|
9467
|
+
this.parsedPromptData = PromptData.parse(this.metadata.prompt_data);
|
|
8132
9468
|
this.hasParsedPromptData = true;
|
|
8133
9469
|
}
|
|
8134
9470
|
return this.parsedPromptData;
|
|
@@ -8165,6 +9501,57 @@ function simulateLogoutForTests() {
|
|
|
8165
9501
|
_globalState.appUrl = "https://www.braintrust.dev";
|
|
8166
9502
|
return _globalState;
|
|
8167
9503
|
}
|
|
9504
|
+
async function getPromptVersions(projectId, promptId) {
|
|
9505
|
+
const state = _internalGetGlobalState();
|
|
9506
|
+
if (!state) {
|
|
9507
|
+
throw new Error("Must log in first");
|
|
9508
|
+
}
|
|
9509
|
+
await state.login({});
|
|
9510
|
+
const query = {
|
|
9511
|
+
from: {
|
|
9512
|
+
op: "function",
|
|
9513
|
+
name: {
|
|
9514
|
+
op: "ident",
|
|
9515
|
+
name: ["project_prompts"]
|
|
9516
|
+
},
|
|
9517
|
+
args: [
|
|
9518
|
+
{
|
|
9519
|
+
op: "literal",
|
|
9520
|
+
value: projectId
|
|
9521
|
+
}
|
|
9522
|
+
]
|
|
9523
|
+
},
|
|
9524
|
+
select: [
|
|
9525
|
+
{
|
|
9526
|
+
op: "star"
|
|
9527
|
+
}
|
|
9528
|
+
],
|
|
9529
|
+
filter: {
|
|
9530
|
+
op: "eq",
|
|
9531
|
+
left: { op: "ident", name: ["id"] },
|
|
9532
|
+
right: { op: "literal", value: promptId }
|
|
9533
|
+
}
|
|
9534
|
+
};
|
|
9535
|
+
const response = await state.apiConn().post(
|
|
9536
|
+
"btql",
|
|
9537
|
+
{
|
|
9538
|
+
query,
|
|
9539
|
+
audit_log: true,
|
|
9540
|
+
use_columnstore: false,
|
|
9541
|
+
brainstore_realtime: true
|
|
9542
|
+
},
|
|
9543
|
+
{ headers: { "Accept-Encoding": "gzip" } }
|
|
9544
|
+
);
|
|
9545
|
+
if (!response.ok) {
|
|
9546
|
+
throw new Error(
|
|
9547
|
+
`API request failed: ${response.status} ${response.statusText}`
|
|
9548
|
+
);
|
|
9549
|
+
}
|
|
9550
|
+
const result = await response.json();
|
|
9551
|
+
return result.data?.filter(
|
|
9552
|
+
(entry) => ["upsert", "merge"].includes(entry.audit_data?.action)
|
|
9553
|
+
).map((entry) => prettifyXact(entry._xact_id)) || [];
|
|
9554
|
+
}
|
|
8168
9555
|
var _exportsForTestingOnly = {
|
|
8169
9556
|
extractAttachments,
|
|
8170
9557
|
deepCopyEvent,
|
|
@@ -8173,6 +9560,7 @@ var _exportsForTestingOnly = {
|
|
|
8173
9560
|
simulateLoginForTests,
|
|
8174
9561
|
simulateLogoutForTests,
|
|
8175
9562
|
setInitialTestState,
|
|
9563
|
+
initTestExperiment,
|
|
8176
9564
|
isGeneratorFunction,
|
|
8177
9565
|
isAsyncGeneratorFunction
|
|
8178
9566
|
};
|
|
@@ -8196,6 +9584,7 @@ function configureNode() {
|
|
|
8196
9584
|
isomorph_default.readFile = fs.readFile;
|
|
8197
9585
|
isomorph_default.readdir = fs.readdir;
|
|
8198
9586
|
isomorph_default.stat = fs.stat;
|
|
9587
|
+
isomorph_default.statSync = fsSync.statSync;
|
|
8199
9588
|
isomorph_default.utimes = fs.utimes;
|
|
8200
9589
|
isomorph_default.unlink = fs.unlink;
|
|
8201
9590
|
isomorph_default.homedir = os.homedir;
|
|
@@ -8219,11 +9608,11 @@ __export(exports_node_exports, {
|
|
|
8219
9608
|
BraintrustStream: () => BraintrustStream,
|
|
8220
9609
|
CodeFunction: () => CodeFunction,
|
|
8221
9610
|
CodePrompt: () => CodePrompt,
|
|
8222
|
-
Dataset: () =>
|
|
9611
|
+
Dataset: () => Dataset2,
|
|
8223
9612
|
ERR_PERMALINK: () => ERR_PERMALINK,
|
|
8224
9613
|
Eval: () => Eval,
|
|
8225
9614
|
EvalResultWithSummary: () => EvalResultWithSummary,
|
|
8226
|
-
Experiment: () =>
|
|
9615
|
+
Experiment: () => Experiment2,
|
|
8227
9616
|
ExternalAttachment: () => ExternalAttachment,
|
|
8228
9617
|
FailedHTTPResponse: () => FailedHTTPResponse,
|
|
8229
9618
|
INTERNAL_BTQL_LIMIT: () => INTERNAL_BTQL_LIMIT,
|
|
@@ -8233,9 +9622,9 @@ __export(exports_node_exports, {
|
|
|
8233
9622
|
NOOP_SPAN: () => NOOP_SPAN,
|
|
8234
9623
|
NOOP_SPAN_PERMALINK: () => NOOP_SPAN_PERMALINK,
|
|
8235
9624
|
NoopSpan: () => NoopSpan,
|
|
8236
|
-
Project: () =>
|
|
9625
|
+
Project: () => Project2,
|
|
8237
9626
|
ProjectNameIdMap: () => ProjectNameIdMap,
|
|
8238
|
-
Prompt: () =>
|
|
9627
|
+
Prompt: () => Prompt2,
|
|
8239
9628
|
PromptBuilder: () => PromptBuilder,
|
|
8240
9629
|
ReadonlyAttachment: () => ReadonlyAttachment,
|
|
8241
9630
|
ReadonlyExperiment: () => ReadonlyExperiment,
|
|
@@ -8258,6 +9647,7 @@ __export(exports_node_exports, {
|
|
|
8258
9647
|
deserializePlainStringAsJSON: () => deserializePlainStringAsJSON,
|
|
8259
9648
|
devNullWritableStream: () => devNullWritableStream,
|
|
8260
9649
|
flush: () => flush,
|
|
9650
|
+
getPromptVersions: () => getPromptVersions,
|
|
8261
9651
|
getSpanParentObject: () => getSpanParentObject,
|
|
8262
9652
|
graph: () => graph_framework_exports,
|
|
8263
9653
|
init: () => init,
|
|
@@ -8284,10 +9674,11 @@ __export(exports_node_exports, {
|
|
|
8284
9674
|
reportFailures: () => reportFailures,
|
|
8285
9675
|
runEvaluator: () => runEvaluator,
|
|
8286
9676
|
setFetch: () => setFetch,
|
|
9677
|
+
setMaskingFunction: () => setMaskingFunction,
|
|
8287
9678
|
spanComponentsToObjectId: () => spanComponentsToObjectId,
|
|
8288
9679
|
startSpan: () => startSpan,
|
|
8289
9680
|
summarize: () => summarize,
|
|
8290
|
-
toolFunctionDefinitionSchema: () =>
|
|
9681
|
+
toolFunctionDefinitionSchema: () => ToolFunctionDefinition,
|
|
8291
9682
|
traceable: () => traceable,
|
|
8292
9683
|
traced: () => traced,
|
|
8293
9684
|
updateSpan: () => updateSpan,
|
|
@@ -8304,9 +9695,6 @@ __export(exports_node_exports, {
|
|
|
8304
9695
|
});
|
|
8305
9696
|
|
|
8306
9697
|
// src/functions/invoke.ts
|
|
8307
|
-
import {
|
|
8308
|
-
functionIdSchema
|
|
8309
|
-
} from "@braintrust/core/typespecs";
|
|
8310
9698
|
async function invoke(args) {
|
|
8311
9699
|
const {
|
|
8312
9700
|
orgName,
|
|
@@ -8335,7 +9723,7 @@ async function invoke(args) {
|
|
|
8335
9723
|
fetch: fetch2
|
|
8336
9724
|
});
|
|
8337
9725
|
const parent = parentArg ? typeof parentArg === "string" ? parentArg : await parentArg.export() : await getSpanParentObject().export();
|
|
8338
|
-
const functionId =
|
|
9726
|
+
const functionId = FunctionId.safeParse({
|
|
8339
9727
|
function_id: functionIdArgs.function_id,
|
|
8340
9728
|
project_name: functionIdArgs.projectName,
|
|
8341
9729
|
slug: functionIdArgs.slug,
|
|
@@ -9476,26 +10864,20 @@ var BarProgressReporter = class {
|
|
|
9476
10864
|
};
|
|
9477
10865
|
|
|
9478
10866
|
// src/eval-parameters.ts
|
|
9479
|
-
import { z as
|
|
10867
|
+
import { z as z5 } from "zod";
|
|
9480
10868
|
|
|
9481
10869
|
// src/framework2.ts
|
|
9482
10870
|
import path2 from "path";
|
|
9483
10871
|
import slugifyLib from "slugify";
|
|
9484
|
-
import { z as
|
|
9485
|
-
import {
|
|
9486
|
-
toolFunctionDefinitionSchema,
|
|
9487
|
-
chatCompletionMessageParamSchema,
|
|
9488
|
-
modelParamsSchema,
|
|
9489
|
-
projectSchema
|
|
9490
|
-
} from "@braintrust/core/typespecs";
|
|
10872
|
+
import { z as z4 } from "zod";
|
|
9491
10873
|
import { loadPrettyXact } from "@braintrust/core";
|
|
9492
10874
|
var ProjectBuilder = class {
|
|
9493
10875
|
create(opts) {
|
|
9494
|
-
return new
|
|
10876
|
+
return new Project2(opts);
|
|
9495
10877
|
}
|
|
9496
10878
|
};
|
|
9497
10879
|
var projects = new ProjectBuilder();
|
|
9498
|
-
var
|
|
10880
|
+
var Project2 = class {
|
|
9499
10881
|
name;
|
|
9500
10882
|
id;
|
|
9501
10883
|
tools;
|
|
@@ -9722,23 +11104,23 @@ var CodePrompt = class {
|
|
|
9722
11104
|
};
|
|
9723
11105
|
}
|
|
9724
11106
|
};
|
|
9725
|
-
var promptContentsSchema =
|
|
9726
|
-
|
|
9727
|
-
prompt:
|
|
11107
|
+
var promptContentsSchema = z4.union([
|
|
11108
|
+
z4.object({
|
|
11109
|
+
prompt: z4.string()
|
|
9728
11110
|
}),
|
|
9729
|
-
|
|
9730
|
-
messages:
|
|
11111
|
+
z4.object({
|
|
11112
|
+
messages: z4.array(ChatCompletionMessageParam)
|
|
9731
11113
|
})
|
|
9732
11114
|
]);
|
|
9733
11115
|
var promptDefinitionSchema = promptContentsSchema.and(
|
|
9734
|
-
|
|
9735
|
-
model:
|
|
9736
|
-
params:
|
|
11116
|
+
z4.object({
|
|
11117
|
+
model: z4.string(),
|
|
11118
|
+
params: ModelParams.optional()
|
|
9737
11119
|
})
|
|
9738
11120
|
);
|
|
9739
11121
|
var promptDefinitionWithToolsSchema = promptDefinitionSchema.and(
|
|
9740
|
-
|
|
9741
|
-
tools:
|
|
11122
|
+
z4.object({
|
|
11123
|
+
tools: z4.array(ToolFunctionDefinition).optional()
|
|
9742
11124
|
})
|
|
9743
11125
|
);
|
|
9744
11126
|
var PromptBuilder = class {
|
|
@@ -9767,7 +11149,7 @@ var PromptBuilder = class {
|
|
|
9767
11149
|
prompt_data: promptData,
|
|
9768
11150
|
...this.project.id !== void 0 ? { project_id: this.project.id } : {}
|
|
9769
11151
|
};
|
|
9770
|
-
const prompt = new
|
|
11152
|
+
const prompt = new Prompt2(
|
|
9771
11153
|
promptRow,
|
|
9772
11154
|
{},
|
|
9773
11155
|
// It doesn't make sense to specify defaults here.
|
|
@@ -9806,8 +11188,8 @@ var ProjectNameIdMap = class {
|
|
|
9806
11188
|
const response = await _internalGetGlobalState().appConn().post_json("api/project/register", {
|
|
9807
11189
|
project_name: projectName
|
|
9808
11190
|
});
|
|
9809
|
-
const result =
|
|
9810
|
-
project:
|
|
11191
|
+
const result = z4.object({
|
|
11192
|
+
project: Project
|
|
9811
11193
|
}).parse(response);
|
|
9812
11194
|
const projectId = result.project.id;
|
|
9813
11195
|
this.nameToId[projectName] = projectId;
|
|
@@ -9820,7 +11202,7 @@ var ProjectNameIdMap = class {
|
|
|
9820
11202
|
const response = await _internalGetGlobalState().appConn().post_json("api/project/get", {
|
|
9821
11203
|
id: projectId
|
|
9822
11204
|
});
|
|
9823
|
-
const result =
|
|
11205
|
+
const result = z4.array(Project).nonempty().parse(response);
|
|
9824
11206
|
const projectName = result[0].name;
|
|
9825
11207
|
this.idToName[projectId] = projectName;
|
|
9826
11208
|
this.nameToId[projectName] = projectId;
|
|
@@ -9836,16 +11218,15 @@ var ProjectNameIdMap = class {
|
|
|
9836
11218
|
};
|
|
9837
11219
|
|
|
9838
11220
|
// src/eval-parameters.ts
|
|
9839
|
-
|
|
9840
|
-
|
|
9841
|
-
|
|
9842
|
-
|
|
9843
|
-
|
|
9844
|
-
type: z4.literal("prompt"),
|
|
11221
|
+
var evalParametersSchema = z5.record(
|
|
11222
|
+
z5.string(),
|
|
11223
|
+
z5.union([
|
|
11224
|
+
z5.object({
|
|
11225
|
+
type: z5.literal("prompt"),
|
|
9845
11226
|
default: promptDefinitionWithToolsSchema.optional(),
|
|
9846
|
-
description:
|
|
11227
|
+
description: z5.string().optional()
|
|
9847
11228
|
}),
|
|
9848
|
-
|
|
11229
|
+
z5.instanceof(z5.ZodType)
|
|
9849
11230
|
// For Zod schemas
|
|
9850
11231
|
])
|
|
9851
11232
|
);
|
|
@@ -9855,14 +11236,14 @@ function validateParameters(parameters, parameterSchema) {
|
|
|
9855
11236
|
const value = parameters[name];
|
|
9856
11237
|
try {
|
|
9857
11238
|
if ("type" in schema && schema.type === "prompt") {
|
|
9858
|
-
const promptData = value ?
|
|
11239
|
+
const promptData = value ? PromptData.parse(value) : schema.default ? promptDefinitionToPromptData(
|
|
9859
11240
|
schema.default,
|
|
9860
11241
|
schema.default.tools
|
|
9861
11242
|
) : void 0;
|
|
9862
11243
|
if (!promptData) {
|
|
9863
11244
|
throw new Error(`Parameter '${name}' is required`);
|
|
9864
11245
|
}
|
|
9865
|
-
return [name,
|
|
11246
|
+
return [name, Prompt2.fromPromptData(name, promptData)];
|
|
9866
11247
|
} else {
|
|
9867
11248
|
const schemaCasted = schema;
|
|
9868
11249
|
return [name, schemaCasted.parse(value)];
|
|
@@ -9982,7 +11363,7 @@ async function Eval(name, evaluator, reporterOrOpts) {
|
|
|
9982
11363
|
baseExperimentId: evaluator.baseExperimentId,
|
|
9983
11364
|
gitMetadataSettings: evaluator.gitMetadataSettings,
|
|
9984
11365
|
repoInfo: evaluator.repoInfo,
|
|
9985
|
-
dataset:
|
|
11366
|
+
dataset: Dataset2.isDataset(data) ? data : void 0
|
|
9986
11367
|
});
|
|
9987
11368
|
if (experiment && options.onStart) {
|
|
9988
11369
|
const summary = await experiment.summarize({ summarizeScores: false });
|
|
@@ -10143,7 +11524,7 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
10143
11524
|
datum,
|
|
10144
11525
|
trialIndex
|
|
10145
11526
|
}) => {
|
|
10146
|
-
const eventDataset = experiment ? experiment.dataset :
|
|
11527
|
+
const eventDataset = experiment ? experiment.dataset : Dataset2.isDataset(evaluator.data) ? evaluator.data : void 0;
|
|
10147
11528
|
const baseEvent = {
|
|
10148
11529
|
name: "eval",
|
|
10149
11530
|
spanAttributes: {
|
|
@@ -10170,6 +11551,7 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
10170
11551
|
const expected = "expected" in datum ? datum.expected : void 0;
|
|
10171
11552
|
let output = void 0;
|
|
10172
11553
|
let error2 = void 0;
|
|
11554
|
+
let tags = [...datum.tags ?? []];
|
|
10173
11555
|
const scores = {};
|
|
10174
11556
|
const scorerNames = evaluator.scores.map(scorerName);
|
|
10175
11557
|
let unhandledScores = scorerNames;
|
|
@@ -10177,7 +11559,7 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
10177
11559
|
const meta = (o) => metadata = { ...metadata, ...o };
|
|
10178
11560
|
await rootSpan.traced(
|
|
10179
11561
|
async (span) => {
|
|
10180
|
-
const
|
|
11562
|
+
const hooksForTask = {
|
|
10181
11563
|
meta,
|
|
10182
11564
|
metadata,
|
|
10183
11565
|
expected,
|
|
@@ -10192,13 +11574,16 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
10192
11574
|
object_type: "task"
|
|
10193
11575
|
});
|
|
10194
11576
|
},
|
|
10195
|
-
trialIndex
|
|
10196
|
-
|
|
11577
|
+
trialIndex,
|
|
11578
|
+
tags
|
|
11579
|
+
};
|
|
11580
|
+
const outputResult = evaluator.task(datum.input, hooksForTask);
|
|
10197
11581
|
if (outputResult instanceof Promise) {
|
|
10198
11582
|
output = await outputResult;
|
|
10199
11583
|
} else {
|
|
10200
11584
|
output = outputResult;
|
|
10201
11585
|
}
|
|
11586
|
+
tags = hooksForTask.tags ?? [];
|
|
10202
11587
|
span.log({ output });
|
|
10203
11588
|
},
|
|
10204
11589
|
{
|
|
@@ -10207,7 +11592,11 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
10207
11592
|
event: { input: datum.input }
|
|
10208
11593
|
}
|
|
10209
11594
|
);
|
|
10210
|
-
|
|
11595
|
+
if (tags.length) {
|
|
11596
|
+
rootSpan.log({ output, metadata, expected, tags });
|
|
11597
|
+
} else {
|
|
11598
|
+
rootSpan.log({ output, metadata, expected });
|
|
11599
|
+
}
|
|
10211
11600
|
const scoringArgs = {
|
|
10212
11601
|
input: datum.input,
|
|
10213
11602
|
expected: "expected" in datum ? datum.expected : void 0,
|
|
@@ -10319,7 +11708,7 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
10319
11708
|
input: datum.input,
|
|
10320
11709
|
..."expected" in datum ? { expected: datum.expected } : {},
|
|
10321
11710
|
output,
|
|
10322
|
-
tags:
|
|
11711
|
+
tags: tags.length ? tags : void 0,
|
|
10323
11712
|
metadata,
|
|
10324
11713
|
scores: {
|
|
10325
11714
|
...evaluator.errorScoreHandler && unhandledScores ? evaluator.errorScoreHandler({
|
|
@@ -10561,7 +11950,7 @@ var GraphBuilder = class {
|
|
|
10561
11950
|
};
|
|
10562
11951
|
}
|
|
10563
11952
|
resolveNode(node) {
|
|
10564
|
-
if (node instanceof
|
|
11953
|
+
if (node instanceof Prompt2) {
|
|
10565
11954
|
const cached = this.nodeLikeNodes.get(node);
|
|
10566
11955
|
if (cached) {
|
|
10567
11956
|
return [cached, []];
|
|
@@ -10773,6 +12162,7 @@ import { SpanTypeAttribute as SpanTypeAttribute3 } from "@braintrust/core";
|
|
|
10773
12162
|
import { mergeDicts as mergeDicts3 } from "@braintrust/core";
|
|
10774
12163
|
|
|
10775
12164
|
// src/wrappers/oai_responses.ts
|
|
12165
|
+
import { isObject as isObject2 } from "@braintrust/core";
|
|
10776
12166
|
function responsesProxy(openai) {
|
|
10777
12167
|
if (!openai.responses) {
|
|
10778
12168
|
return openai;
|
|
@@ -10962,11 +12352,11 @@ function parseMetricsFromUsage(usage) {
|
|
|
10962
12352
|
const metricName = TOKEN_NAME_MAP[oai_name] || oai_name;
|
|
10963
12353
|
metrics[metricName] = value;
|
|
10964
12354
|
} else if (oai_name.endsWith("_tokens_details")) {
|
|
10965
|
-
|
|
10966
|
-
const prefix = TOKEN_PREFIX_MAP[rawPrefix] || rawPrefix;
|
|
10967
|
-
if (typeof value !== "object") {
|
|
12355
|
+
if (!isObject2(value)) {
|
|
10968
12356
|
continue;
|
|
10969
12357
|
}
|
|
12358
|
+
const rawPrefix = oai_name.slice(0, -"_tokens_details".length);
|
|
12359
|
+
const prefix = TOKEN_PREFIX_MAP[rawPrefix] || rawPrefix;
|
|
10970
12360
|
for (const [key, n] of Object.entries(value)) {
|
|
10971
12361
|
if (typeof n !== "number") {
|
|
10972
12362
|
continue;
|
|
@@ -11450,6 +12840,28 @@ var WrapperStream = class {
|
|
|
11450
12840
|
|
|
11451
12841
|
// src/wrappers/ai-sdk-v2.ts
|
|
11452
12842
|
import { SpanTypeAttribute as SpanTypeAttribute4 } from "@braintrust/core";
|
|
12843
|
+
|
|
12844
|
+
// src/wrappers/anthropic-tokens-util.ts
|
|
12845
|
+
function finalizeAnthropicTokens(metrics) {
|
|
12846
|
+
const prompt_tokens = (metrics.prompt_tokens || 0) + (metrics.prompt_cached_tokens || 0) + (metrics.prompt_cache_creation_tokens || 0);
|
|
12847
|
+
return {
|
|
12848
|
+
...metrics,
|
|
12849
|
+
prompt_tokens,
|
|
12850
|
+
tokens: prompt_tokens + (metrics.completion_tokens || 0)
|
|
12851
|
+
};
|
|
12852
|
+
}
|
|
12853
|
+
function extractAnthropicCacheTokens(cacheReadTokens = 0, cacheCreationTokens = 0) {
|
|
12854
|
+
const cacheTokens = {};
|
|
12855
|
+
if (cacheReadTokens > 0) {
|
|
12856
|
+
cacheTokens.prompt_cached_tokens = cacheReadTokens;
|
|
12857
|
+
}
|
|
12858
|
+
if (cacheCreationTokens > 0) {
|
|
12859
|
+
cacheTokens.prompt_cache_creation_tokens = cacheCreationTokens;
|
|
12860
|
+
}
|
|
12861
|
+
return cacheTokens;
|
|
12862
|
+
}
|
|
12863
|
+
|
|
12864
|
+
// src/wrappers/ai-sdk-v2.ts
|
|
11453
12865
|
function detectProviderFromResult(result) {
|
|
11454
12866
|
if (!result?.providerMetadata) {
|
|
11455
12867
|
return void 0;
|
|
@@ -11498,7 +12910,7 @@ function getNumberProperty(obj, key) {
|
|
|
11498
12910
|
const value = Reflect.get(obj, key);
|
|
11499
12911
|
return typeof value === "number" ? value : void 0;
|
|
11500
12912
|
}
|
|
11501
|
-
function normalizeUsageMetrics(usage) {
|
|
12913
|
+
function normalizeUsageMetrics(usage, provider, providerMetadata) {
|
|
11502
12914
|
const metrics = {};
|
|
11503
12915
|
const inputTokens = getNumberProperty(usage, "inputTokens");
|
|
11504
12916
|
if (inputTokens !== void 0) {
|
|
@@ -11520,6 +12932,22 @@ function normalizeUsageMetrics(usage) {
|
|
|
11520
12932
|
if (cachedInputTokens !== void 0) {
|
|
11521
12933
|
metrics.prompt_cached_tokens = cachedInputTokens;
|
|
11522
12934
|
}
|
|
12935
|
+
if (provider === "anthropic") {
|
|
12936
|
+
const anthropicMetadata = providerMetadata?.anthropic;
|
|
12937
|
+
if (anthropicMetadata) {
|
|
12938
|
+
const cacheReadTokens = getNumberProperty(anthropicMetadata.usage, "cache_read_input_tokens") || 0;
|
|
12939
|
+
const cacheCreationTokens = getNumberProperty(
|
|
12940
|
+
anthropicMetadata.usage,
|
|
12941
|
+
"cache_creation_input_tokens"
|
|
12942
|
+
) || 0;
|
|
12943
|
+
const cacheTokens = extractAnthropicCacheTokens(
|
|
12944
|
+
cacheReadTokens,
|
|
12945
|
+
cacheCreationTokens
|
|
12946
|
+
);
|
|
12947
|
+
Object.assign(metrics, cacheTokens);
|
|
12948
|
+
Object.assign(metrics, finalizeAnthropicTokens(metrics));
|
|
12949
|
+
}
|
|
12950
|
+
}
|
|
11523
12951
|
return metrics;
|
|
11524
12952
|
}
|
|
11525
12953
|
function BraintrustMiddleware(config = {}) {
|
|
@@ -11555,7 +12983,11 @@ function BraintrustMiddleware(config = {}) {
|
|
|
11555
12983
|
span.log({
|
|
11556
12984
|
output: result.content,
|
|
11557
12985
|
metadata,
|
|
11558
|
-
metrics: normalizeUsageMetrics(
|
|
12986
|
+
metrics: normalizeUsageMetrics(
|
|
12987
|
+
result.usage,
|
|
12988
|
+
provider,
|
|
12989
|
+
result.providerMetadata
|
|
12990
|
+
)
|
|
11559
12991
|
});
|
|
11560
12992
|
return result;
|
|
11561
12993
|
} catch (error2) {
|
|
@@ -11632,7 +13064,11 @@ function BraintrustMiddleware(config = {}) {
|
|
|
11632
13064
|
span.log({
|
|
11633
13065
|
output,
|
|
11634
13066
|
metadata,
|
|
11635
|
-
metrics: normalizeUsageMetrics(
|
|
13067
|
+
metrics: normalizeUsageMetrics(
|
|
13068
|
+
finalUsage,
|
|
13069
|
+
provider,
|
|
13070
|
+
providerMetadata
|
|
13071
|
+
)
|
|
11636
13072
|
});
|
|
11637
13073
|
span.end();
|
|
11638
13074
|
} catch (error2) {
|
|
@@ -12009,7 +13445,7 @@ function createProxy(create) {
|
|
|
12009
13445
|
const event = parseEventFromMessage(msgOrStream);
|
|
12010
13446
|
span.log({
|
|
12011
13447
|
...event,
|
|
12012
|
-
metrics: event.metrics ?
|
|
13448
|
+
metrics: event.metrics ? finalizeAnthropicTokens(event.metrics) : void 0
|
|
12013
13449
|
});
|
|
12014
13450
|
span.end();
|
|
12015
13451
|
return msgOrStream;
|
|
@@ -12093,7 +13529,7 @@ function streamNextProxy(stream, sspan) {
|
|
|
12093
13529
|
const output = deltas.join("");
|
|
12094
13530
|
span.log({
|
|
12095
13531
|
output,
|
|
12096
|
-
metrics:
|
|
13532
|
+
metrics: finalizeAnthropicTokens(totals),
|
|
12097
13533
|
metadata
|
|
12098
13534
|
});
|
|
12099
13535
|
span.end();
|
|
@@ -12167,15 +13603,6 @@ function parseMetricsFromUsage2(usage) {
|
|
|
12167
13603
|
saveIfExistsTo("cache_creation_input_tokens", "prompt_cache_creation_tokens");
|
|
12168
13604
|
return metrics;
|
|
12169
13605
|
}
|
|
12170
|
-
function finalizeMetrics(metrics) {
|
|
12171
|
-
const prompt_tokens = (metrics.prompt_tokens || 0) + (metrics.prompt_cached_tokens || 0) + (metrics.prompt_cache_creation_tokens || 0);
|
|
12172
|
-
return {
|
|
12173
|
-
...metrics,
|
|
12174
|
-
// Anthropic's `input_tokens` does not include cache creation or cached read tokens.
|
|
12175
|
-
prompt_tokens,
|
|
12176
|
-
tokens: prompt_tokens + (metrics.completion_tokens || 0)
|
|
12177
|
-
};
|
|
12178
|
-
}
|
|
12179
13606
|
function coalesceInput(messages, system) {
|
|
12180
13607
|
const input = (messages || []).slice();
|
|
12181
13608
|
if (system) {
|
|
@@ -12334,11 +13761,31 @@ var BraintrustSpanProcessor = class _BraintrustSpanProcessor {
|
|
|
12334
13761
|
"x-bt-parent": parent,
|
|
12335
13762
|
...options.headers
|
|
12336
13763
|
};
|
|
12337
|
-
|
|
13764
|
+
const baseExporter = new OTLPTraceExporter2({
|
|
12338
13765
|
url: new URL("otel/v1/traces", apiUrl).href,
|
|
12339
13766
|
headers
|
|
12340
13767
|
});
|
|
13768
|
+
exporter = new Proxy(baseExporter, {
|
|
13769
|
+
get(target, prop, receiver) {
|
|
13770
|
+
if (prop === "export") {
|
|
13771
|
+
return function(spans, resultCallback) {
|
|
13772
|
+
const fixedSpans = spans.map((span) => {
|
|
13773
|
+
if (!span.instrumentationScope && span.instrumentationLibrary) {
|
|
13774
|
+
span.instrumentationScope = span.instrumentationLibrary;
|
|
13775
|
+
}
|
|
13776
|
+
return span;
|
|
13777
|
+
});
|
|
13778
|
+
return Reflect.apply(target.export, target, [
|
|
13779
|
+
fixedSpans,
|
|
13780
|
+
resultCallback
|
|
13781
|
+
]);
|
|
13782
|
+
};
|
|
13783
|
+
}
|
|
13784
|
+
return Reflect.get(target, prop, receiver);
|
|
13785
|
+
}
|
|
13786
|
+
});
|
|
12341
13787
|
} catch (error2) {
|
|
13788
|
+
console.error(error2);
|
|
12342
13789
|
throw new Error(
|
|
12343
13790
|
"Failed to create OTLP exporter. Make sure @opentelemetry/exporter-trace-otlp-http is installed."
|
|
12344
13791
|
);
|
|
@@ -12416,50 +13863,44 @@ var BraintrustExporter = class _BraintrustExporter {
|
|
|
12416
13863
|
};
|
|
12417
13864
|
|
|
12418
13865
|
// dev/types.ts
|
|
12419
|
-
import {
|
|
12420
|
-
|
|
12421
|
-
|
|
12422
|
-
|
|
12423
|
-
|
|
12424
|
-
|
|
12425
|
-
|
|
12426
|
-
|
|
12427
|
-
|
|
12428
|
-
parameters: z5.record(z5.string(), z5.unknown()).nullish(),
|
|
12429
|
-
data: runEvalSchema.shape.data,
|
|
12430
|
-
scores: z5.array(
|
|
12431
|
-
z5.object({
|
|
12432
|
-
function_id: functionIdSchema2,
|
|
12433
|
-
name: z5.string()
|
|
13866
|
+
import { z as z6 } from "zod";
|
|
13867
|
+
var evalBodySchema = z6.object({
|
|
13868
|
+
name: z6.string(),
|
|
13869
|
+
parameters: z6.record(z6.string(), z6.unknown()).nullish(),
|
|
13870
|
+
data: RunEval.shape.data,
|
|
13871
|
+
scores: z6.array(
|
|
13872
|
+
z6.object({
|
|
13873
|
+
function_id: FunctionId,
|
|
13874
|
+
name: z6.string()
|
|
12434
13875
|
})
|
|
12435
13876
|
).nullish(),
|
|
12436
|
-
experiment_name:
|
|
12437
|
-
project_id:
|
|
12438
|
-
parent:
|
|
12439
|
-
stream:
|
|
13877
|
+
experiment_name: z6.string().nullish(),
|
|
13878
|
+
project_id: z6.string().nullish(),
|
|
13879
|
+
parent: InvokeParent.optional(),
|
|
13880
|
+
stream: z6.boolean().optional()
|
|
12440
13881
|
});
|
|
12441
|
-
var evalParametersSerializedSchema =
|
|
12442
|
-
|
|
12443
|
-
|
|
12444
|
-
|
|
12445
|
-
type:
|
|
12446
|
-
default:
|
|
12447
|
-
description:
|
|
13882
|
+
var evalParametersSerializedSchema = z6.record(
|
|
13883
|
+
z6.string(),
|
|
13884
|
+
z6.union([
|
|
13885
|
+
z6.object({
|
|
13886
|
+
type: z6.literal("prompt"),
|
|
13887
|
+
default: PromptData.optional(),
|
|
13888
|
+
description: z6.string().optional()
|
|
12448
13889
|
}),
|
|
12449
|
-
|
|
12450
|
-
type:
|
|
12451
|
-
schema:
|
|
13890
|
+
z6.object({
|
|
13891
|
+
type: z6.literal("data"),
|
|
13892
|
+
schema: z6.record(z6.unknown()),
|
|
12452
13893
|
// JSON Schema
|
|
12453
|
-
default:
|
|
12454
|
-
description:
|
|
13894
|
+
default: z6.unknown().optional(),
|
|
13895
|
+
description: z6.string().optional()
|
|
12455
13896
|
})
|
|
12456
13897
|
])
|
|
12457
13898
|
);
|
|
12458
|
-
var evaluatorDefinitionSchema =
|
|
13899
|
+
var evaluatorDefinitionSchema = z6.object({
|
|
12459
13900
|
parameters: evalParametersSerializedSchema.optional()
|
|
12460
13901
|
});
|
|
12461
|
-
var evaluatorDefinitionsSchema =
|
|
12462
|
-
|
|
13902
|
+
var evaluatorDefinitionsSchema = z6.record(
|
|
13903
|
+
z6.string(),
|
|
12463
13904
|
evaluatorDefinitionSchema
|
|
12464
13905
|
);
|
|
12465
13906
|
|
|
@@ -12478,11 +13919,11 @@ export {
|
|
|
12478
13919
|
BraintrustStream,
|
|
12479
13920
|
CodeFunction,
|
|
12480
13921
|
CodePrompt,
|
|
12481
|
-
Dataset,
|
|
13922
|
+
Dataset2 as Dataset,
|
|
12482
13923
|
ERR_PERMALINK,
|
|
12483
13924
|
Eval,
|
|
12484
13925
|
EvalResultWithSummary,
|
|
12485
|
-
Experiment,
|
|
13926
|
+
Experiment2 as Experiment,
|
|
12486
13927
|
ExternalAttachment,
|
|
12487
13928
|
FailedHTTPResponse,
|
|
12488
13929
|
INTERNAL_BTQL_LIMIT,
|
|
@@ -12492,9 +13933,9 @@ export {
|
|
|
12492
13933
|
NOOP_SPAN,
|
|
12493
13934
|
NOOP_SPAN_PERMALINK,
|
|
12494
13935
|
NoopSpan,
|
|
12495
|
-
Project,
|
|
13936
|
+
Project2 as Project,
|
|
12496
13937
|
ProjectNameIdMap,
|
|
12497
|
-
Prompt,
|
|
13938
|
+
Prompt2 as Prompt,
|
|
12498
13939
|
PromptBuilder,
|
|
12499
13940
|
ReadonlyAttachment,
|
|
12500
13941
|
ReadonlyExperiment,
|
|
@@ -12520,6 +13961,7 @@ export {
|
|
|
12520
13961
|
evaluatorDefinitionSchema,
|
|
12521
13962
|
evaluatorDefinitionsSchema,
|
|
12522
13963
|
flush,
|
|
13964
|
+
getPromptVersions,
|
|
12523
13965
|
getSpanParentObject,
|
|
12524
13966
|
graph_framework_exports as graph,
|
|
12525
13967
|
init,
|
|
@@ -12546,10 +13988,11 @@ export {
|
|
|
12546
13988
|
reportFailures,
|
|
12547
13989
|
runEvaluator,
|
|
12548
13990
|
setFetch,
|
|
13991
|
+
setMaskingFunction,
|
|
12549
13992
|
spanComponentsToObjectId,
|
|
12550
13993
|
startSpan,
|
|
12551
13994
|
summarize,
|
|
12552
|
-
toolFunctionDefinitionSchema,
|
|
13995
|
+
ToolFunctionDefinition as toolFunctionDefinitionSchema,
|
|
12553
13996
|
traceable,
|
|
12554
13997
|
traced,
|
|
12555
13998
|
updateSpan,
|