Files
cfw-autumn/shared/models/featureModels/featureModels.ts
Charlie Lamb 8822664df9 feat: AI credit system with model-based token pricing
Adds a new FeatureType.AiCreditSystem that enables model-based token
pricing with per-model markup configuration. Includes the @useautumn/ai-sdk
package for Vercel AI SDK integration with automatic token tracking.

Co-authored-by: TheUntraceable <73362400+TheUntraceable@users.noreply.github.com>
2026-05-19 19:05:37 +01:00

49 lines
1.2 KiB
TypeScript

import { ModelMarkupsSchema } from "@models/featureModels/featureConfig/creditConfig";
import { z } from "zod/v4";
import { AppEnv } from "../genModels/genEnums";
import { FeatureType } from "./featureEnums";
export const FeatureSchema = z.object({
internal_id: z.string(),
org_id: z.string(),
created_at: z.number(),
env: z.nativeEnum(AppEnv),
id: z.string().nonempty("Features must have an ID"),
name: z.string().nonempty("Features must have a name"),
type: z.nativeEnum(FeatureType, {
message: "Features must have a type",
}),
config: z.any(),
display: z
.object({
singular: z.string().optional(),
plural: z.string().optional(),
})
.nullish(),
archived: z.boolean(),
event_names: z.array(z.string()).default([]),
model_markups: ModelMarkupsSchema.nullish(),
});
export const CreateFeatureSchema = FeatureSchema.pick({
id: true,
name: true,
type: true,
config: true,
display: true,
event_names: true,
model_markups: true,
});
export const MinFeatureSchema = z.object({
internal_id: z.string(),
id: z.string(),
name: z.string(),
type: z.nativeEnum(FeatureType),
config: z.any(),
});
export type Feature = z.infer<typeof FeatureSchema>;
export type CreateFeature = z.infer<typeof CreateFeatureSchema>;