import { useEffect, useRef, useState } from "react";
import type { ChangeEvent, FormEvent } from "react";
import type { ReviewRunner } from "../state/useReviewRunner";
import type { Scenario } from "../mock/scenarios";
import type { ChatMsg, Todo } from "../state/types";
import { wan, yuan } from "../engine/format";
import { EvidenceTable } from "./EvidenceTable";
interface ChatCardViewProps {
msg: ChatMsg;
scenario: Scenario | null;
report: { fileName: string; html: string } | null;
onOpenReport: () => void;
}
function ChatCardView({ msg, scenario, report, onOpenReport }: ChatCardViewProps) {
if (msg.card.kind === "text") {
return
{msg.card.text}
;
}
if (!scenario) return null;
if (msg.card.kind === "summary") {
const s = scenario.summary;
return (
汇总结论
{s.overall}
({ label: r.agent, value: `${r.conclusion} · ${r.keyEvidence}` }))} />
{s.suggestions.length > 0 ? (
{s.suggestions.map((t, i) => (
- {t}
))}
) : null}
);
}
if (msg.card.kind === "order") {
const o = scenario.summary.order;
if (!o) return null;
return (
);
}
if (msg.card.kind === "suggest") {
const g = scenario.summary.creditGap;
return (
评审不通过 · 处理建议
信用达标 0 分
{g ? (
) : null}
);
}
if (msg.card.kind === "report") {
return (
需求评估报告已生成
网页
{msg.card.fileName}
);
}
return 临时授信流程已发起:授信审批 → 评级复跑 → 重新汇总。
;
}
function TodoCard({ todo, onResolve }: { todo: Todo; onResolve: (v: string | null) => void }) {
if (todo.kind === "followup") {
return (
待办 · 补全追问
等待响应
{todo.prompt}
{todo.options.map((o) => (
))}
);
}
if (todo.kind === "confirm") {
return (
待办 · 确认评审结论
评审通过
三个智能体结论齐备且依据透明,是否发起订单生成?
);
}
if (todo.kind === "next") {
return (
待办 · 下一步
评审收尾
本次评审已收尾并生成报告,接下来:
{todo.allowCreditRerun ? (
) : null}
);
}
return (
待办 · 异常处理
评级不通过
信用项不达标,是否发起客户临时授信?
);
}
export function RightPanel({ runner }: { runner: ReviewRunner }) {
const { demand, scenario, chat, todo, running } = runner;
const [text, setText] = useState("");
const chatRef = useRef(null);
const fileRef = useRef(null);
useEffect(() => {
chatRef.current?.scrollTo({ top: chatRef.current.scrollHeight });
}, [chat.length, todo]);
const submit = (e: FormEvent) => {
e.preventDefault();
runner.sendText(text);
setText("");
};
const onFile = (e: ChangeEvent) => {
const file = e.target.files?.[0];
e.target.value = "";
if (file) void runner.uploadFile(file);
};
const openReport = () => {
const r = runner.report;
if (!r) return;
const url = URL.createObjectURL(new Blob([r.html], { type: "text/html;charset=utf-8" }));
window.open(url, "_blank");
setTimeout(() => URL.revokeObjectURL(url), 60_000);
};
return (
);
}