1+ import {
2+ logPreviewLabel ,
3+ type TaskLogEntry ,
4+ type TaskLogs ,
5+ } from "@repo/shared" ;
6+ import { formatDistanceToNowStrict } from "date-fns" ;
7+
18import { LogViewer , LogViewerPlaceholder } from "./LogViewer" ;
29
3- import type { TaskLogEntry , TaskLogs } from "@repo/shared " ;
10+ import type { ReactNode } from "react " ;
411
512interface AgentChatHistoryProps {
613 taskLogs : TaskLogs ;
@@ -26,14 +33,39 @@ function LogEntry({
2633 ) ;
2734}
2835
36+ function chatHistoryHeader ( taskLogs : TaskLogs ) : ReactNode {
37+ if ( taskLogs . status !== "ok" || taskLogs . snapshot !== true ) {
38+ return "Chat history" ;
39+ }
40+ const label = logPreviewLabel ( taskLogs . logs . length ) ;
41+ if ( taskLogs . snapshotAt === undefined ) {
42+ return label ;
43+ }
44+ const relativeTime = formatDistanceToNowStrict (
45+ new Date ( taskLogs . snapshotAt ) ,
46+ { addSuffix : true } ,
47+ ) ;
48+ return (
49+ < >
50+ { label } { " " }
51+ < span className = "snapshot-info" >
52+ < span className = "codicon codicon-info" />
53+ < span className = "snapshot-info-tooltip" >
54+ Snapshot taken { relativeTime }
55+ </ span >
56+ </ span >
57+ </ >
58+ ) ;
59+ }
60+
2961export function AgentChatHistory ( {
3062 taskLogs,
3163 isThinking,
3264} : AgentChatHistoryProps ) {
3365 const logs = taskLogs . status === "ok" ? taskLogs . logs : [ ] ;
3466
3567 return (
36- < LogViewer header = "Chat History" >
68+ < LogViewer header = { chatHistoryHeader ( taskLogs ) } >
3769 { logs . length === 0 ? (
3870 < LogViewerPlaceholder error = { taskLogs . status === "error" } >
3971 { getEmptyMessage ( taskLogs . status ) }
0 commit comments