import * as React from "react"; import { Link, createFileRoute } from "@tanstack/react-router"; import { ArrowLeft, Clock, Loader2, AlertCircle, RefreshCw, Wrench, Zap, Calendar } from "lucide-react"; import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query"; import Markdown from "react-markdown"; import remarkGfm from "remark-gfm"; import { Mermaid } from "../components/Mermaid"; import { fetchAiLatestReport, triggerAiAnalysis, fetchAiReport } from "../lib/ai-analysis-api"; import { Button } from "../components/ui/button"; import { Card, CardContent } from "../components/ui/card"; import { toast } from "sonner"; export const Route = createFileRoute("/ai-analysis")({ component: AiAnalysisPage, }); function AiAnalysisPage() { const queryClient = useQueryClient(); const { data: report, isLoading, isError, refetch } = useQuery({ queryKey: ["ai-report-latest"], queryFn: fetchAiLatestReport, retry: false, }); const triggerMutation = useMutation({ mutationFn: triggerAiAnalysis, onSuccess: () => { toast.success("AI 分析已开始,请稍候..."); queryClient.invalidateQueries({ queryKey: ["ai-report-latest"] }); }, onError: (err: Error) => { toast.error(err.message || "触发失败"); }, }); return (
{/* Header */}

AI 收盘分析

{/* Content */} {isLoading ? (

加载中...

) : isError || !report ? (

暂无分析报告

点击"立即分析"生成今日报告

) : ( <> {/* Meta Info */}
{report.created_at} {report.model} {report.tokens_used?.toLocaleString()} tokens {report.toolsUsed && report.toolsUsed.length > 0 && ( {report.toolsUsed.length} 个工具 )}
{/* Report Content */} {children}
); }, code({ className, children, ...props }) { const match = /language-(\w+)/.exec(className || ""); if (match && match[1] === "mermaid") { return ; } return ( {children} ); }, }} > {report.content} {/* Disclaimer */}

本报告由 AI 生成,仅供参考,不构成投资建议

)}
); }