mirror of
https://github.com/fosrl/pangolin.git
synced 2026-08-11 23:18:24 +02:00
47 lines
1.1 KiB
TypeScript
47 lines
1.1 KiB
TypeScript
import { z } from "zod";
|
|
|
|
export const aiBudgetUnitSchema = z.enum(["usd", "tokens"]);
|
|
|
|
export const aiBudgetPeriodSchema = z.enum([
|
|
"monthly",
|
|
"yearly",
|
|
"lifetime",
|
|
"daily",
|
|
"hourly",
|
|
"weekly"
|
|
]);
|
|
|
|
export const aiBudgetEnforcementSchema = z.enum(["hard", "soft"]);
|
|
|
|
export function refineBudgetScopeFields(
|
|
data: {
|
|
providerId?: number | null;
|
|
modelId?: number | null;
|
|
resourceId?: number | null;
|
|
siteResourceId?: number | null;
|
|
roleId?: number | null;
|
|
},
|
|
ctx: z.RefinementCtx
|
|
) {
|
|
const scopeFields = [
|
|
data.providerId,
|
|
data.modelId,
|
|
data.resourceId,
|
|
data.siteResourceId,
|
|
data.roleId
|
|
];
|
|
|
|
const setCount = scopeFields.filter(
|
|
(value) => value !== null && value !== undefined
|
|
).length;
|
|
|
|
if (setCount > 1) {
|
|
ctx.addIssue({
|
|
code: "custom",
|
|
message:
|
|
"Only one of providerId, modelId, resourceId, siteResourceId, or roleId may be set on a budget",
|
|
path: ["providerId"]
|
|
});
|
|
}
|
|
}
|