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>
26 lines
711 B
TypeScript
26 lines
711 B
TypeScript
import type { CreditSchemaItem } from "../../models/featureModels/featureConfig/creditConfig.js";
|
|
import { FeatureType } from "../../models/featureModels/featureEnums.js";
|
|
import type { Feature } from "../../models/featureModels/featureModels.js";
|
|
|
|
export const creditSystemContainsFeature = ({
|
|
creditSystem,
|
|
meteredFeatureId,
|
|
}: {
|
|
creditSystem: Feature;
|
|
meteredFeatureId: string;
|
|
}) => {
|
|
if (creditSystem.type !== FeatureType.CreditSystem) {
|
|
return false;
|
|
}
|
|
const schema: CreditSchemaItem[] | undefined = creditSystem.config?.schema;
|
|
if (!schema) return false;
|
|
|
|
for (const schemaItem of schema) {
|
|
if (schemaItem.metered_feature_id === meteredFeatureId) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
};
|