ai-chatbot/lib/agents/workflow-goods-info-config.ts
Your Name 8e225e9ae1
Some checks failed
Lint / build (20) (push) Has been cancelled
Playwright Tests / test (push) Has been cancelled
feat: add sku goods info query support
2026-03-22 23:39:16 +08:00

45 lines
1.3 KiB
TypeScript

import type { AgentWorkflowGoodsInfoApiConfig } from "@/types/agent";
export const AGENT_WORKFLOW_GOODS_INFO_API_CONFIG_KEY =
"agent_workflow_goods_info_api_config";
export const defaultAgentWorkflowGoodsInfoApiConfig: AgentWorkflowGoodsInfoApiConfig = {
enabled: false,
baseUrl: "https://www.jiansun.vip:63211",
clientKey: "",
secret: "",
};
function sanitizeText(value: unknown, maxLength: number) {
return String(value || "").trim().slice(0, maxLength);
}
export function normalizeAgentWorkflowGoodsInfoApiConfig(
value: unknown
): AgentWorkflowGoodsInfoApiConfig {
if (!value || typeof value !== "object" || Array.isArray(value)) {
return defaultAgentWorkflowGoodsInfoApiConfig;
}
const raw = value as Partial<AgentWorkflowGoodsInfoApiConfig>;
return {
enabled: raw.enabled === true,
baseUrl:
sanitizeText(raw.baseUrl, 255) || defaultAgentWorkflowGoodsInfoApiConfig.baseUrl,
clientKey: sanitizeText(raw.clientKey, 255),
secret: sanitizeText(raw.secret, 255),
};
}
export function normalizeAgentWorkflowGoodsInfoApiConfigForPublic(
value: unknown
): AgentWorkflowGoodsInfoApiConfig {
const config = normalizeAgentWorkflowGoodsInfoApiConfig(value);
return {
...config,
clientKey: "",
secret: "",
};
}