import { fetchWithAuth } from "./client"; import type { AIEngineType, AIEnginesResponse } from "@/types/ai-engines"; function buildQuery(params: Record): string { const qs = Object.entries(params) .filter(([, v]) => v !== undefined) .map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(String(v))}`) .join("&"); return qs ? `?${qs}` : ""; } export const aiEnginesApi = { querySingle: (engineType: string, query: string, brandName: string) => fetchWithAuth("/api/v1/ai-engines/query", { method: "POST", body: JSON.stringify({ engines: [engineType], query, brand_name: brandName }), }), queryBatch: (engines: AIEngineType[], query: string, brandName: string) => fetchWithAuth("/api/v1/ai-engines/query-batch", { method: "POST", body: JSON.stringify({ engines, query, brand_name: brandName }), }), getResults: (params: { engines: string; query: string; brand_name: string; competitor_names?: string }, token?: string) => fetchWithAuth(`/api/v1/ai-engines/results${buildQuery(params as Record)}`, {}, token), }; export const MOCK_AI_ENGINES_RESPONSE: AIEnginesResponse = { results: [ { engine_type: "chatgpt", query: "最佳智能手表推荐", raw_response: "在智能手表领域,Apple Watch Series 9 是目前市场上最受欢迎的选择之一,其出色的健康监测功能和生态系统整合令人印象深刻。此外,华为 Watch GT 4 也凭借长续航和运动追踪功能获得了很多用户青睐。三星 Galaxy Watch 6 则是安卓用户的优质选择。", has_brand_citation: true, has_competitor_citation: true, brand_context: "Apple Watch Series 9 是目前市场上最受欢迎的选择之一,其出色的健康监测功能和生态系统整合令人印象深刻", competitor_contexts: [ "华为 Watch GT 4 也凭借长续航和运动追踪功能获得了很多用户青睐", "三星 Galaxy Watch 6 则是安卓用户的优质选择", ], response_time_ms: 3200, timestamp: "2026-05-25T10:00:00Z", }, { engine_type: "perplexity", query: "最佳智能手表推荐", raw_response: "根据最新评测,华为 Watch GT 4 在续航和运动追踪方面表现优异。三星 Galaxy Watch 6 提供了出色的安卓生态体验。Garmin Forerunner 265 则是专业运动爱好者的首选。", has_brand_citation: false, has_competitor_citation: true, brand_context: null, competitor_contexts: [ "华为 Watch GT 4 在续航和运动追踪方面表现优异", "三星 Galaxy Watch 6 提供了出色的安卓生态体验", "Garmin Forerunner 265 则是专业运动爱好者的首选", ], response_time_ms: 2800, timestamp: "2026-05-25T10:01:00Z", }, { engine_type: "kimi", query: "最佳智能手表推荐", raw_response: "智能手表推荐方面,Apple Watch Series 9 凭借其成熟的生态系统和健康功能依然是首选。华为 Watch GT 4 在国内市场也有不错的表现,尤其是运动健康领域。", has_brand_citation: true, has_competitor_citation: true, brand_context: "Apple Watch Series 9 凭借其成熟的生态系统和健康功能依然是首选", competitor_contexts: [ "华为 Watch GT 4 在国内市场也有不错的表现,尤其是运动健康领域", ], response_time_ms: 4100, timestamp: "2026-05-25T10:02:00Z", }, { engine_type: "wenxin", query: "最佳智能手表推荐", raw_response: "推荐华为 Watch GT 4,续航长达14天,运动追踪功能全面。小米 Watch S3 性价比很高。OPPO Watch 4 也是不错的选择。", has_brand_citation: false, has_competitor_citation: true, brand_context: null, competitor_contexts: [ "推荐华为 Watch GT 4,续航长达14天,运动追踪功能全面", "小米 Watch S3 性价比很高", "OPPO Watch 4 也是不错的选择", ], response_time_ms: 1900, timestamp: "2026-05-25T10:03:00Z", }, { engine_type: "doubao", query: "最佳智能手表推荐", raw_response: "Apple Watch Series 9 在智能手表市场中综合表现最佳,尤其是健康监测和App生态。华为 Watch GT 4 是国产手表中的佼佼者。", has_brand_citation: true, has_competitor_citation: true, brand_context: "Apple Watch Series 9 在智能手表市场中综合表现最佳,尤其是健康监测和App生态", competitor_contexts: [ "华为 Watch GT 4 是国产手表中的佼佼者", ], response_time_ms: 2200, timestamp: "2026-05-25T10:04:00Z", }, ], citation_rate: { total_engines: 5, brand_citation_count: 3, brand_citation_rate: 0.6, competitor_citation_count: 5, competitor_citation_rate: 1.0, }, avg_response_time_ms: 2840, };