mirror of
https://github.com/fosrl/pangolin.git
synced 2026-09-08 20:16:50 +02:00
add basic crud for ai budgets
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
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"]
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user