132 lines
4.7 KiB
TypeScript
132 lines
4.7 KiB
TypeScript
import { CheckCircle2, ChevronRight, FileText, Search, PenLine, ClipboardEdit, Star } from 'lucide-react';
|
|
|
|
import type { AIWritingSessionSummary, CompletedInterventionRecord } from '../../api/ai-writing-sessions';
|
|
import { AIWritingTimeline } from './AIWritingTimeline';
|
|
|
|
const PAUSE_LABELS: Record<string, string> = {
|
|
material_confirm: '素材确认',
|
|
outline_confirm: '大纲确认',
|
|
draft_confirm: '草稿确认',
|
|
review_confirm: '编辑意见处理',
|
|
};
|
|
|
|
const ACTION_LABELS: Record<string, string> = {
|
|
approve: '已批准',
|
|
re_search: '重新搜索',
|
|
re_outline: '重新规划',
|
|
finalize: '直接定稿',
|
|
to_editor: '提交审核',
|
|
user_revise: '手动修改',
|
|
accept_review: '接受意见',
|
|
force_finalize: '强制定稿',
|
|
};
|
|
|
|
const PAUSE_ICONS: Record<string, React.ElementType> = {
|
|
material_confirm: Search,
|
|
outline_confirm: PenLine,
|
|
draft_confirm: FileText,
|
|
review_confirm: ClipboardEdit,
|
|
};
|
|
|
|
function InterventionTimelineItem({ record, isLast }: { record: CompletedInterventionRecord; isLast: boolean }) {
|
|
const Icon = PAUSE_ICONS[record.pausePoint] ?? CheckCircle2;
|
|
const ts = record.timestamp
|
|
? new Date(record.timestamp).toLocaleString('zh-CN', { month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' })
|
|
: '';
|
|
|
|
return (
|
|
<div className="flex gap-3">
|
|
<div className="flex flex-col items-center">
|
|
<div className="w-6 h-6 rounded-full bg-primary/10 flex items-center justify-center shrink-0">
|
|
<Icon className="w-3 h-3 text-primary" />
|
|
</div>
|
|
{!isLast && <div className="w-px flex-1 bg-border/60 mt-1" />}
|
|
</div>
|
|
<div className="pb-4 min-w-0 flex-1">
|
|
<div className="flex items-center gap-2">
|
|
<span className="text-xs font-medium">
|
|
{PAUSE_LABELS[record.pausePoint] ?? record.pausePoint}
|
|
</span>
|
|
<ChevronRight className="w-3 h-3 text-muted-foreground" />
|
|
<span className="text-xs text-primary font-medium">
|
|
{ACTION_LABELS[record.action] ?? record.action}
|
|
</span>
|
|
</div>
|
|
{ts && <p className="text-[10px] text-muted-foreground mt-0.5">{ts}</p>}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
interface AIWritingHistoryViewProps {
|
|
session: AIWritingSessionSummary;
|
|
}
|
|
|
|
export function AIWritingHistoryView({ session }: AIWritingHistoryViewProps) {
|
|
const interventions = session.completed_interventions ?? [];
|
|
const transcript = session.transcript;
|
|
// 有完整时间线快照时,复用实时对话的 AIWritingTimeline 渲染,保证回显与实时一致
|
|
const hasTranscript = !!transcript && (transcript.progressEvents?.length ?? 0) > 0;
|
|
const createdAt = session.created_at
|
|
? new Date(session.created_at).toLocaleString('zh-CN', {
|
|
year: 'numeric', month: 'short', day: 'numeric',
|
|
hour: '2-digit', minute: '2-digit',
|
|
})
|
|
: '';
|
|
|
|
return (
|
|
<div className="flex-1 overflow-y-auto">
|
|
{/* 元信息 */}
|
|
<div className="px-4 pt-3">
|
|
<div className="rounded-lg border bg-muted/30 px-3 py-2.5 space-y-1">
|
|
<p className="text-xs font-semibold truncate">{session.draft_title ?? session.title}</p>
|
|
{session.user_intent && (
|
|
<p className="text-[11px] text-muted-foreground leading-relaxed line-clamp-2">
|
|
{session.user_intent}
|
|
</p>
|
|
)}
|
|
{createdAt && (
|
|
<p className="text-[10px] text-muted-foreground">{createdAt}</p>
|
|
)}
|
|
</div>
|
|
</div>
|
|
|
|
{hasTranscript ? (
|
|
/* 完整对话时间线回显 */
|
|
<AIWritingTimeline
|
|
events={transcript!.progressEvents}
|
|
completedInterventions={transcript!.completedInterventions ?? []}
|
|
currentPause={null}
|
|
/>
|
|
) : (
|
|
/* 旧会话无时间线快照时,回退到精简阶段列表 */
|
|
<div className="px-4 py-3 space-y-4">
|
|
{interventions.length > 0 ? (
|
|
<div>
|
|
<p className="text-[11px] font-medium text-muted-foreground mb-2">写作阶段</p>
|
|
<div>
|
|
{interventions.map((rec, i) => (
|
|
<InterventionTimelineItem
|
|
key={i}
|
|
record={rec}
|
|
isLast={i === interventions.length - 1}
|
|
/>
|
|
))}
|
|
</div>
|
|
</div>
|
|
) : (
|
|
<div className="text-center py-4 text-xs text-muted-foreground">无阶段记录</div>
|
|
)}
|
|
|
|
{session.status === 'done' && (
|
|
<div className="flex items-center gap-2 text-xs text-green-600 dark:text-green-400">
|
|
<Star className="w-3.5 h-3.5" />
|
|
<span>写作完成</span>
|
|
</div>
|
|
)}
|
|
</div>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|