ai-chatbot/lib/ai/detail-agent-model-config.ts
Your Name 3101f5966d
Some checks failed
Lint / build (20) (push) Has been cancelled
Playwright Tests / test (push) Has been cancelled
feat: enhance canvas agent UI customization
2026-04-23 13:25:05 +08:00

59 lines
1.9 KiB
TypeScript

export const DETAIL_AGENT_LOCAL_MOONSHOT_SETTING_KEY =
"canvas_detail_agent_moonshot_config";
// Stable option id: keep the historical value so existing site settings remain valid.
export const DETAIL_AGENT_LOCAL_MOONSHOT_OPTION_ID =
"__moonshot_kimi_k25_local__";
export const DETAIL_AGENT_LOCAL_MOONSHOT_BASE_URL =
"https://api.moonshot.cn/v1";
export const DETAIL_AGENT_LOCAL_MOONSHOT_MODEL_ID = "kimi-k2.6";
export const DETAIL_AGENT_LOCAL_MOONSHOT_DISPLAY_NAME = "官方 Kimi K2.6";
export type DetailAgentLocalMoonshotConfig = {
enabled: boolean;
providerName: string;
baseUrl: string;
apiKey: string;
modelId: string;
displayName: string;
};
export function isDetailAgentLocalMoonshotOption(value: unknown) {
return String(value || "").trim() === DETAIL_AGENT_LOCAL_MOONSHOT_OPTION_ID;
}
function normalizeMoonshotModelId(value: unknown) {
const modelId = String(value || "").trim();
if (!modelId || modelId === "kimi-k2.5") {
return DETAIL_AGENT_LOCAL_MOONSHOT_MODEL_ID;
}
return modelId;
}
function normalizeMoonshotDisplayName(value: unknown) {
const displayName = String(value || "").trim();
if (!displayName || displayName === "官方 Kimi K2.5") {
return DETAIL_AGENT_LOCAL_MOONSHOT_DISPLAY_NAME;
}
return displayName;
}
export function normalizeDetailAgentLocalMoonshotConfig(
value: unknown,
): DetailAgentLocalMoonshotConfig {
const raw =
value && typeof value === "object" && !Array.isArray(value)
? (value as Record<string, unknown>)
: {};
return {
enabled: raw.enabled !== false,
providerName:
String(raw.providerName || "").trim() || "Moonshot AI (Official)",
baseUrl:
String(raw.baseUrl || "").trim() || DETAIL_AGENT_LOCAL_MOONSHOT_BASE_URL,
apiKey: String(raw.apiKey || "").trim(),
modelId: normalizeMoonshotModelId(raw.modelId),
displayName: normalizeMoonshotDisplayName(raw.displayName),
};
}