ai-chatbot/lib/agents/secondary-type-config.ts
Your Name ec988be30a
Some checks failed
Lint / build (20) (push) Has been cancelled
Playwright Tests / test (push) Has been cancelled
Update agent workflow and video task handling
2026-03-13 11:21:42 +08:00

48 lines
1.3 KiB
TypeScript

import type { AgentPresetType } from "@/types/agent";
export const AGENT_SECONDARY_TYPE_CONFIG_KEY = "agent_secondary_type_config";
export type AgentSecondaryTypeConfig = Record<AgentPresetType, string[]>;
export const defaultAgentSecondaryTypeConfig: AgentSecondaryTypeConfig = {
image: [],
video: [],
text: [],
};
export function normalizeAgentSecondaryTypeConfig(value: unknown): AgentSecondaryTypeConfig {
const raw =
value && typeof value === "object" && !Array.isArray(value)
? (value as Record<string, unknown>)
: {};
const normalizeList = (input: unknown) => {
if (!Array.isArray(input)) return [] as string[];
return Array.from(
new Set(
input
.map((item) => String(item || "").trim())
.filter(Boolean)
.slice(0, 200)
)
);
};
return {
image: normalizeList(raw.image),
video: normalizeList(raw.video),
text: normalizeList(raw.text),
};
}
export function isValidSecondaryTypeForPresetType(params: {
presetType: AgentPresetType;
secondaryType?: string | null;
config: AgentSecondaryTypeConfig;
}) {
const normalized = String(params.secondaryType || "").trim();
if (!normalized) return true;
const allowed = params.config[params.presetType] || [];
return allowed.includes(normalized);
}