import type { AgentWorkflowShowcaseConfig } from "@/types/agent"; export const AGENT_WORKFLOW_SHOWCASE_CONFIG_KEY = "agent_workflow_showcase_config"; export const defaultAgentWorkflowShowcaseConfig: AgentWorkflowShowcaseConfig = { enabled: true, title: "三倍速出片,电影级质感", subtitle: "第一步:风格选择 第二步:生图模式", actionText: "我要创作", videoUrl: "", posterUrl: "", overlayText: "让每一步选择,都能直达高质感成片", footerText: "用户作品", }; function sanitizeText(value: unknown, maxLength: number) { return String(value || "").trim().slice(0, maxLength); } export function normalizeAgentWorkflowShowcaseConfig( value: unknown ): AgentWorkflowShowcaseConfig { if (!value || typeof value !== "object" || Array.isArray(value)) { return defaultAgentWorkflowShowcaseConfig; } const raw = value as Record; return { enabled: typeof raw.enabled === "boolean" ? raw.enabled : defaultAgentWorkflowShowcaseConfig.enabled, title: sanitizeText(raw.title, 200) || defaultAgentWorkflowShowcaseConfig.title, subtitle: sanitizeText(raw.subtitle, 300) || defaultAgentWorkflowShowcaseConfig.subtitle, actionText: sanitizeText(raw.actionText, 48) || defaultAgentWorkflowShowcaseConfig.actionText, videoUrl: sanitizeText(raw.videoUrl, 2000), posterUrl: sanitizeText(raw.posterUrl, 2000) || null, overlayText: sanitizeText(raw.overlayText, 200) || defaultAgentWorkflowShowcaseConfig.overlayText, footerText: sanitizeText(raw.footerText, 64) || defaultAgentWorkflowShowcaseConfig.footerText, }; }