48 lines
1.3 KiB
TypeScript
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);
|
|
}
|