"use client"; /** * 临床情景对话对练:输入情景标识发起会话 → 逐轮对话 → 结束生成三维评估报告。 */ import { useState } from "react"; import { Send, Stethoscope } from "lucide-react"; import { CredibilityBadge, RawDetails, ScoreBar, StatTile, } from "@/components/display"; import { ErrorBanner, Loading, PageHeading } from "@/components/feedback"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { UsageGuide } from "@/components/usage-guide"; import { ApiError } from "@/lib/api"; import { clinicalApi } from "@/lib/services"; import type { DialogueReport } from "@/lib/types"; import { cn } from "@/lib/utils"; /* eslint-disable @typescript-eslint/no-explicit-any */ interface ChatTurn { role: "student" | "system"; text: string; } export default function ClinicalPage() { const [scenarioId, setScenarioId] = useState(""); const [session, setSession] = useState(null); const [turns, setTurns] = useState([]); const [input, setInput] = useState(""); const [report, setReport] = useState(null); const [busy, setBusy] = useState(false); const [error, setError] = useState(null); async function run(fn: () => Promise, after?: (v: T) => void) { setError(null); setBusy(true); try { after?.(await fn()); } catch (err) { setError(err instanceof ApiError ? err.message : "操作失败"); } finally { setBusy(false); } } function extractSystemReply(v: any): string { return ( v?.systemResponse ?? v?.reply ?? v?.message ?? v?.turn?.systemResponse ?? JSON.stringify(v) ); } function sendTurn() { if (!input || busy || !session) return; const text = input; setTurns((t) => [...t, { role: "student", text }]); setInput(""); run( () => clinicalApi.sendTurn(session.id, { studentInput: text }), (v: any) => setTurns((t) => [...t, { role: "system", text: extractSystemReply(v) }]), ); } return (
} title="临床模拟" description="模拟真实问诊、查体与医患沟通情景,与 AI 患者交互后获得多维评估反馈。" /> 发起对练
setScenarioId(e.target.value)} placeholder="如:胸痛分诊" />
{error && (
)}
{session && !report && ( 对话
{turns.length === 0 && (

输入你的第一句话开始对话。

)} {turns.map((t, i) => (
{t.text}
))}
{busy && }
setInput(e.target.value)} placeholder="输入对话内容…" onKeyDown={(e) => { if (e.key === "Enter" && !e.shiftKey) { e.preventDefault(); sendTurn(); } }} />
)} {report && ( 三维评估报告
共 {report.turnCount} 轮对话
{report.dimensions?.map((d) => (
= 60 ? "success" : "warning"} /> {d.comment && (

{d.comment}

)}
))}
)}
); }