import "server-only"; import type { DiscountableImageGenConfigLike } from "@/lib/ai/image-model-pricing"; import { getImageCreditCostFromConfig, getImageModelCreditDiscountLabel, } from "@/lib/ai/image-model-pricing"; import { getEnabledAiModelsWithProvider } from "@/lib/db/queries"; export type StyleProModelEntry = Awaited< ReturnType >[number]; export type PublicStyleProModelOption = { id: string; modelId: string; displayName: string; avatarUrl: string | null; providerName: string; providerType: string; isDefault: boolean; unitCost: number; creditDiscountLabel: string | null; }; export function isStyleProImageModel(entry: StyleProModelEntry) { return Boolean(entry.model.supportsImageGen); } export async function getStyleProImageModelEntries(options?: { includeHidden?: boolean; }) { const models = await getEnabledAiModelsWithProvider( false, options?.includeHidden === true ); return models.filter(isStyleProImageModel); } export function findStyleProImageModelByRef( entries: StyleProModelEntry[], modelRef?: string | null ) { const normalized = String(modelRef || "").trim(); if (!normalized) return null; return ( entries.find( ({ model }) => model.id === normalized || model.modelId === normalized ) || null ); } export function toPublicStyleProModelOption( entry: StyleProModelEntry ): PublicStyleProModelOption { const imageGenConfig = (entry.model.imageGenConfig || null) as DiscountableImageGenConfigLike | null; return { id: entry.model.id, modelId: entry.model.modelId, displayName: entry.model.displayName, avatarUrl: entry.model.avatarUrl || null, providerName: entry.provider.name, providerType: entry.provider.type, isDefault: entry.model.isDefault, unitCost: getImageCreditCostFromConfig(imageGenConfig), creditDiscountLabel: getImageModelCreditDiscountLabel(imageGenConfig), }; }