Files
cfw-autumn/shared/models/featureModels/featureConfig/creditConfig.ts
2026-06-10 15:46:14 +01:00

48 lines
1.5 KiB
TypeScript

import { z } from "zod/v4";
import { FeatureUsageType } from "../featureEnums";
export const CreditSchemaItemSchema = z.object({
metered_feature_id: z.string(),
feature_amount: z.number().optional(),
credit_amount: z.number(),
});
const MarkupEntrySchema = z.object({
markup: z.number().min(-100), // percentage markup, e.g. 20 for 20%, -100 for free
});
export const ProviderMarkupsSchema = z
.record(
z.string(), // Provider key from the model name, e.g. "openrouter" in "openrouter/anthropic/claude"
MarkupEntrySchema,
)
.nullish();
export const CreditSystemConfigSchema = z.object({
schema: z.array(
z.object({
metered_feature_id: z.string(),
credit_amount: z.number(),
}),
),
usage_type: z.nativeEnum(FeatureUsageType),
default_markup: z.number().min(-100).optional(),
provider_markups: ProviderMarkupsSchema,
});
export const ModelMarkupsSchema = z
.record(
z.string(), // Represents the model name in "provider/model" format, e.g. "anthropic/claude-2"
MarkupEntrySchema.extend({
markup: z.number().min(-100).optional(), // Omit to inherit provider/global markup
input_cost: z.number().min(0).optional(), // $/M tokens, required for custom/ models
output_cost: z.number().min(0).optional(), // $/M tokens, required for custom/ models
}),
)
.nullish();
export type CreditSystemConfig = z.infer<typeof CreditSystemConfigSchema>;
export type CreditSchemaItem = z.infer<typeof CreditSchemaItemSchema>;
export type ModelMarkups = z.infer<typeof ModelMarkupsSchema>;
export type ProviderMarkups = z.infer<typeof ProviderMarkupsSchema>;