Files
AIPortPilot/frontend/src/lib/api-v2.ts
T
selfrelease f4ddcab2ca test(frontend): UIUX E2E 测试 — 新增路由导航/创始人端/Admin端/工作台/移动端适配
新增 6 个 E2E 测试文件,覆盖 2-task-uiux.md 全部 50 项任务:
- uiux-navigation.spec.ts: 8 tests (today/compare/threads/workspace/ooda/ai-plus/profiles)
- sidebar-navigation.spec.ts: 6 tests (投资人 Sidebar 6 业务域)
- founder-uiux.spec.ts: 7 tests (创始人端 6 域导航)
- admin-uiux.spec.ts: 3 tests (Admin 6 管理域 + 商业秘密保护)
- workbench-uiux.spec.ts: 5 tests (Highlights/WorkMode/Tab/InsightRail)
- mobile-uiux.spec.ts: 5 tests (移动端抽屉导航 + 创始人底部导航)

同时修复全部 no-explicit-any 警告,替换为 TypeScript 接口定义。

测试结果: 41 E2E passed, 405 backend passed
2026-07-19 20:37:25 +08:00

534 lines
16 KiB
TypeScript

/** Phase 2-4 通用 API 调用封装。 */
import { apiFetch } from "@/lib/api";
// ============ Phase 2: 财务数据 ============
export async function listFinancialData(companyId: string) {
return apiFetch(`/financial?company_id=${companyId}`);
}
export async function createFinancialData(data: Record<string, unknown>) {
return apiFetch(`/financial`, {
method: "POST",
body: JSON.stringify(data),
});
}
export async function validateFinancial(companyId: string, year: number, month: number) {
return apiFetch(`/financial/validate?company_id=${companyId}&period_year=${year}&period_month=${month}`);
}
// ============ Phase 2: 投资协议 ============
export async function listAgreements(companyId?: string) {
const path = companyId ? `/agreements?company_id=${companyId}` : "/agreements";
return apiFetch(path);
}
export async function createAgreement(data: Record<string, unknown>) {
return apiFetch(`/agreements`, { method: "POST", body: JSON.stringify(data) });
}
export async function getAgreementAlerts(agreementId: string) {
return apiFetch(`/agreements/${agreementId}/alerts`);
}
// ============ Phase 2: 董事会 ============
export async function listBoardMeetings(companyId?: string) {
const path = companyId ? `/board?company_id=${companyId}` : "/board";
return apiFetch(path);
}
export async function createBoardMeeting(data: Record<string, unknown>) {
return apiFetch(`/board`, { method: "POST", body: JSON.stringify(data) });
}
export async function generateMeetingSummary(meetingId: string, materialsText: string) {
return apiFetch(`/board/${meetingId}/generate-summary`, {
method: "POST",
body: JSON.stringify({ materials_text: materialsText }),
});
}
export async function generateBoardQuestions(meetingId: string, materialsText: string) {
return apiFetch(`/board/${meetingId}/generate-questions`, {
method: "POST",
body: JSON.stringify({ materials_text: materialsText }),
});
}
// ============ Phase 2: 弱信号 ============
export async function listWeakSignals(companyId?: string, signalType?: string) {
const params = new URLSearchParams();
if (companyId) params.set("company_id", companyId);
if (signalType) params.set("signal_type", signalType);
return apiFetch(`/weak-signals${params.toString() ? `?${params}` : ""}`);
}
export async function correlateWeakSignals(signals: unknown[]) {
return apiFetch(`/weak-signals/correlate`, {
method: "POST",
body: JSON.stringify({ signals }),
});
}
// ============ Phase 2: 决策前哨 ============
export async function listDecisionSentinels(companyId?: string) {
const path = companyId ? `/decision-sentinels?company_id=${companyId}` : "/decision-sentinels";
return apiFetch(path);
}
export async function identifyDecisionPoints(companyContext: string) {
return apiFetch(`/decision-sentinels/identify`, {
method: "POST",
body: JSON.stringify({ company_context: companyContext }),
});
}
export async function analyzeSentinelScenarios(sentinelId: string, decision: Record<string, unknown>) {
return apiFetch(`/decision-sentinels/${sentinelId}/analyze`, {
method: "POST",
body: JSON.stringify({ decision }),
});
}
// ============ Phase 2: 重大事项 + 追问清单 ============
export async function listMajorEvents(companyId?: string) {
const path = companyId ? `/events?company_id=${companyId}` : "/events";
return apiFetch(path);
}
export async function detectMajorEvents(reportContent: string) {
return apiFetch(`/events/detect`, {
method: "POST",
body: JSON.stringify({ report_content: reportContent }),
});
}
export async function listInquiries(companyId?: string) {
const path = companyId ? `/inquiries?company_id=${companyId}` : "/inquiries";
return apiFetch(path);
}
export async function generateInquiryQuestions(reportContent: string, structuredData?: unknown) {
return apiFetch(`/inquiries/generate`, {
method: "POST",
body: JSON.stringify({ report_content: reportContent, structured_data: structuredData }),
});
}
// ============ Phase 2: 画像 ============
export async function listFirms() {
return apiFetch(`/profiles/firms`);
}
export async function listFunds(firmId?: string) {
const path = firmId ? `/profiles/funds?firm_id=${firmId}` : "/profiles/funds";
return apiFetch(path);
}
export async function listManagers(firmId?: string) {
const path = firmId ? `/profiles/managers?firm_id=${firmId}` : "/profiles/managers";
return apiFetch(path);
}
// ============ Phase 3: 协同 ============
export async function listSynergies(companyId?: string) {
const path = companyId ? `/synergies?company_id=${companyId}` : "/synergies";
return apiFetch(path);
}
export async function matchSynergies(companyAContext: string, portfolioContext: string) {
return apiFetch(`/synergies/match`, {
method: "POST",
body: JSON.stringify({ company_a_context: companyAContext, portfolio_context: portfolioContext }),
});
}
export async function authorizeSynergy(synergyId: string) {
return apiFetch(`/synergies/${synergyId}/authorize`, { method: "PUT" });
}
// ============ Phase 3: 创新 ============
export async function discoverInnovation(portfolioCapabilities: string) {
return apiFetch(`/innovation/discover`, {
method: "POST",
body: JSON.stringify({ portfolio_capabilities: portfolioCapabilities }),
});
}
// ============ Phase 3: 人才 ============
export async function listTalents() {
return apiFetch(`/talents`);
}
export async function predictTalentFlow(talentData: string) {
return apiFetch(`/talents/predict-flow`, {
method: "POST",
body: JSON.stringify({ talent_data: talentData }),
});
}
export async function recommendTalent(companyNeed: string, talentPool: string) {
return apiFetch(`/talents/recommend`, {
method: "POST",
body: JSON.stringify({ company_need: companyNeed, talent_pool: talentPool }),
});
}
// ============ Phase 3: OKR ============
export async function listOKRs(companyId?: string) {
const path = companyId ? `/okrs?company_id=${companyId}` : "/okrs";
return apiFetch(path);
}
export async function createOKR(data: Record<string, unknown>) {
return apiFetch(`/okrs`, { method: "POST", body: JSON.stringify(data) });
}
export async function trackOKR(okrId: string, keyResults: unknown[]) {
return apiFetch(`/okrs/${okrId}/track`, {
method: "POST",
body: JSON.stringify({ key_results: keyResults }),
});
}
// ============ Phase 3: 助推 ============
export async function listNudges(companyId?: string) {
const path = companyId ? `/nudges?company_id=${companyId}` : "/nudges";
return apiFetch(path);
}
export async function selectNudge(context: string) {
return apiFetch(`/nudges/select`, {
method: "POST",
body: JSON.stringify({ context }),
});
}
// ============ Phase 3: Peer Circles ============
export async function listPeerCircles() {
return apiFetch(`/peer-circles`);
}
export async function matchPeerCircle(foundersContext: string) {
return apiFetch(`/peer-circles/match`, {
method: "POST",
body: JSON.stringify({ founders_context: foundersContext }),
});
}
// ============ Phase 3: 产品诊断 ============
export async function listProductDiagnostics(companyId?: string) {
const path = companyId ? `/product-diagnostics?company_id=${companyId}` : "/product-diagnostics";
return apiFetch(path);
}
export async function diagnoseProduct(productInfo: string, competitorInfo: string) {
return apiFetch(`/product-diagnostics/diagnose`, {
method: "POST",
body: JSON.stringify({ product_info: productInfo, competitor_info: competitorInfo }),
});
}
// ============ Phase 3: 里程碑 ============
export async function listMilestones(companyId: string) {
return apiFetch(`/milestones?company_id=${companyId}`);
}
export async function suggestMilestoneSwitch(milestoneContext: string, envChanges: string) {
return apiFetch(`/milestones/suggest-switch`, {
method: "POST",
body: JSON.stringify({ milestone_context: milestoneContext, env_changes: envChanges }),
});
}
// ============ Phase 3: 高级分析 ============
export async function analyzeConstraints(companyData: string) {
return apiFetch(`/advanced-analysis/constraints`, {
method: "POST",
body: JSON.stringify({ company_data: companyData }),
});
}
export async function analyzeChasm(companyData: string) {
return apiFetch(`/advanced-analysis/chasm`, {
method: "POST",
body: JSON.stringify({ company_data: companyData }),
});
}
// ============ Phase 3: 任务 + 评论 ============
export async function listTasks(companyId?: string, status?: string) {
const params = new URLSearchParams();
if (companyId) params.set("company_id", companyId);
if (status) params.set("status", status);
return apiFetch(`/tasks${params.toString() ? `?${params}` : ""}`);
}
export async function createTask(data: Record<string, unknown>) {
return apiFetch(`/tasks`, { method: "POST", body: JSON.stringify(data) });
}
export async function updateTask(taskId: string, data: Record<string, unknown>) {
return apiFetch(`/tasks/${taskId}`, { method: "PUT", body: JSON.stringify(data) });
}
export async function listComments(targetType: string, targetId: string) {
return apiFetch(`/comments?target_type=${targetType}&target_id=${targetId}`);
}
export async function createComment(data: Record<string, unknown>) {
return apiFetch(`/comments`, { method: "POST", body: JSON.stringify(data) });
}
// ============ Phase 3: 客户成功 ============
export async function generateQBR(companyId: string, quarterData: string) {
return apiFetch(`/customer-success/qbr`, {
method: "POST",
body: JSON.stringify({ company_id: companyId, quarter_data: quarterData }),
});
}
export async function identifyExpansion(companyData: string) {
return apiFetch(`/customer-success/expansion`, {
method: "POST",
body: JSON.stringify({ company_data: companyData }),
});
}
export async function getChurnRisk() {
return apiFetch(`/customer-success/churn-risk`);
}
// ============ Phase 4: Alpha 归因 ============
export async function listInterventions(companyId?: string) {
const path = companyId ? `/alpha?company_id=${companyId}` : "/alpha";
return apiFetch(path);
}
export async function createIntervention(data: Record<string, unknown>) {
return apiFetch(`/alpha`, { method: "POST", body: JSON.stringify(data) });
}
export async function attributeAlpha(interventionId: string, intervention: unknown, metricChanges: unknown) {
return apiFetch(`/alpha/${interventionId}/attribute`, {
method: "POST",
body: JSON.stringify({ intervention, metric_changes: metricChanges }),
});
}
// ============ Phase 4: 退出预测 ============
export async function listExitPredictions(companyId?: string) {
const path = companyId ? `/exit-predictions?company_id=${companyId}` : "/exit-predictions";
return apiFetch(path);
}
export async function predictExit(companyData: string) {
return apiFetch(`/exit-predictions/predict`, {
method: "POST",
body: JSON.stringify({ company_data: companyData }),
});
}
// ============ Phase 4: 组合管理 ============
export async function rebalancePortfolio(companyReturns: unknown[]) {
return apiFetch(`/portfolio/rebalance`, {
method: "POST",
body: JSON.stringify({ company_returns: companyReturns }),
});
}
export async function runMonteCarlo(companyReturns: number[], iterations?: number) {
return apiFetch(`/portfolio/monte-carlo`, {
method: "POST",
body: JSON.stringify({ company_returns: companyReturns, iterations }),
});
}
// ============ Phase 4: 数字孪生 ============
export async function listDigitalTwins(companyId: string) {
return apiFetch(`/digital-twins?company_id=${companyId}`);
}
export async function buildDigitalTwin(companyData: string) {
return apiFetch(`/digital-twins/build`, {
method: "POST",
body: JSON.stringify({ company_data: companyData }),
});
}
export async function simulateTwin(modelParams: unknown, scenario: string) {
return apiFetch(`/digital-twins/simulate`, {
method: "POST",
body: JSON.stringify({ model_params: modelParams, scenario }),
});
}
// ============ Phase 4: 知识图谱 ============
export async function buildKnowledgeGraph(managementExperiences: string) {
return apiFetch(`/knowledge-graph/build`, {
method: "POST",
body: JSON.stringify({ management_experiences: managementExperiences }),
});
}
export async function matchBestStrategy(companyProfile: string, graph: unknown) {
return apiFetch(`/knowledge-graph/match-strategy`, {
method: "POST",
body: JSON.stringify({ new_company_profile: companyProfile, knowledge_graph: graph }),
});
}
// ============ Phase 4: AAR ============
export async function listAARs(companyId?: string) {
const path = companyId ? `/aars?company_id=${companyId}` : "/aars";
return apiFetch(path);
}
export async function generateAAR(triggerEvent: string, originalPlan: string, actualResult: string) {
return apiFetch(`/aars/generate`, {
method: "POST",
body: JSON.stringify({ trigger_event: triggerEvent, original_plan: originalPlan, actual_result: actualResult }),
});
}
// ============ Phase 4: Pre-mortem + Red Team ============
export async function listPreMortems(companyId?: string) {
const path = companyId ? `/pre-mortems?company_id=${companyId}` : "/pre-mortems";
return apiFetch(path);
}
export async function runPreMortem(decisionContext: string) {
return apiFetch(`/pre-mortems/run`, {
method: "POST",
body: JSON.stringify({ decision_context: decisionContext }),
});
}
export async function listRedTeams(companyId?: string) {
const path = companyId ? `/red-teams?company_id=${companyId}` : "/red-teams";
return apiFetch(path);
}
export async function runRedTeam(companyContext: string, perspective: string) {
return apiFetch(`/red-teams/run`, {
method: "POST",
body: JSON.stringify({ company_context: companyContext, perspective }),
});
}
// ============ Phase 4: Agent 执行 ============
export async function listAgentExecutions(page?: number) {
return apiFetch(`/agent-executions?page=${page ?? 1}`);
}
export async function orchestrateAgent(agentName: string, autonomyLevel: string, inputData: unknown) {
return apiFetch(`/agent-executions/orchestrate`, {
method: "POST",
body: JSON.stringify({ agent_name: agentName, autonomy_level: autonomyLevel, input_data: inputData }),
});
}
export async function reviewAgentExecution(executionId: string, reviewStatus: string) {
return apiFetch(`/agent-executions/${executionId}/review`, {
method: "PUT",
body: JSON.stringify({ review_status: reviewStatus }),
});
}
// ============ Phase 4: 知识库 ============
export async function searchKnowledge(query: string, topK?: number) {
return apiFetch(`/knowledge/search?q=${encodeURIComponent(query)}&top_k=${topK ?? 5}`);
}
// ============ Phase 4: 数据源 ============
export async function listDataSources(companyId?: string) {
const path = companyId ? `/data-sources?company_id=${companyId}` : "/data-sources";
return apiFetch(path);
}
export async function createDataSource(data: Record<string, unknown>) {
return apiFetch(`/data-sources`, { method: "POST", body: JSON.stringify(data) });
}
// ============ Phase 4: 行业研究 ============
export async function researchIndustry(industry: string, companies: string) {
return apiFetch(`/industry-research/research`, {
method: "POST",
body: JSON.stringify({ industry, companies }),
});
}
// ============ Phase 4: 基金 ============
export async function analyzeFundStrategy(fundsData: string) {
return apiFetch(`/funds/analyze-strategy`, {
method: "POST",
body: JSON.stringify({ funds_data: fundsData }),
});
}
export async function generateLPReport(fundData: string, portfolioSummary: string) {
return apiFetch(`/funds/lp-report`, {
method: "POST",
body: JSON.stringify({ fund_data: fundData, portfolio_summary: portfolioSummary }),
});
}
// ============ Admin ============
export async function adminOverview() {
return apiFetch(`/admin/overview`);
}
export async function listTenants() {
return apiFetch(`/admin/tenants`);
}
export async function listUsers() {
return apiFetch(`/admin/users`);
}
export async function listAuditLogs(page?: number) {
return apiFetch(`/admin/audit-logs?page=${page ?? 1}`);
}
// ============ Founder ============
export async function founderOverview() {
return apiFetch(`/founder/overview`);
}
export async function founderHealth() {
return apiFetch(`/founder/health`);
}