Show persistent timestamps for operation and teacher messages

This commit is contained in:
鲨鱼辣椒
2026-09-29 18:02:54 +08:00
parent 3a175101c9
commit ead3407890
24 changed files with 355 additions and 9 deletions

View File

@@ -0,0 +1,18 @@
import { messageTimestamp } from '../../shared/message-timestamp';
export function formatMessageTimestamp(value: unknown, now = new Date()) {
const timestamp = messageTimestamp(value);
if (timestamp === undefined) return undefined;
const date = new Date(timestamp);
const pad = (part: number) => String(part).padStart(2, '0');
const time = `${pad(date.getHours())}:${pad(date.getMinutes())}`;
const sameYear = date.getFullYear() === now.getFullYear();
const today = sameYear && date.getMonth() === now.getMonth() && date.getDate() === now.getDate();
const day = `${date.getMonth() + 1}月${date.getDate()}日`;
return {
iso: date.toISOString(),
short: today ? time : `${sameYear ? '' : `${date.getFullYear()}年`}${day} ${time}`,
full: `${date.getFullYear()}年${day} ${time}:${pad(date.getSeconds())}`,
};
}

View File

@@ -1,5 +1,6 @@
import { OPEN_WORK_PROMPT } from '../../../shared/coding-work-preview';
import { CONTINUE_CODING_PROMPT, type CodingRecoveryAction } from '../../../shared/coding-recovery';
import { MessageTimestamp } from './MessageTimestamp';
import { CodingRecoveryCard } from './CodingRecoveryCard';
import {
memo,
@@ -539,6 +540,7 @@ const MessageNode = memo(function MessageNode({
</Button>
)}
</div>
<MessageTimestamp value={node.timestamp} pending={!user && node.status === 'streaming'} label={user ? '发送时间' : '回复完成时间'} className={cn('mt-1', user && 'text-right')} />
{!user && answerText && (
<Button
type="button"
@@ -1330,6 +1332,7 @@ const AssistantCommentary = memo(function AssistantCommentary({
{blocks.length === 0 && node.status === 'aborted' && <p className="text-muted-foreground">本次处理已中止。</p>}
</div>
</CompactProcessText>
<MessageTimestamp value={node.timestamp} pending={streaming} className="mt-1" />
</div>
);
});

View File

@@ -0,0 +1,15 @@
import { formatMessageTimestamp } from '@/lib/message-timestamp';
import { cn } from '@/lib/utils';
export function MessageTimestamp({ value, pending = false, label = '回复完成时间', className }: {
value?: number | string;
pending?: boolean;
label?: string;
className?: string;
}) {
const formatted = pending ? undefined : formatMessageTimestamp(value);
const style = cn('block text-[11px] leading-5 text-muted-foreground tabular-nums', className);
return formatted
? <time className={style} dateTime={formatted.iso} title={formatted.full} aria-label={`${label}:${formatted.full}`}>{formatted.short}</time>
: <span className={style} data-message-time={pending ? 'pending' : 'unknown'}>{pending ? '回复中…' : '时间未记录'}</span>;
}

View File

@@ -13,6 +13,7 @@ import type {
} from '../../../shared/coding-teacher';
import { TeacherAvatar } from './TeacherAvatar';
import { TeacherReply } from './TeacherReply';
import { MessageTimestamp } from './MessageTimestamp';
// Preserve loaded pages and the reading anchor while moving between contacts.
// Durable messages remain Main-owned; this is only the current window's view.
@@ -514,8 +515,8 @@ export function TeacherChatPanel({
{topic?.requests.map((request, index) => <div key={request.id} className="mb-7 space-y-4">
{continuous && request.projectId && (index === 0 || request.projectId !== topic.requests[index - 1].projectId) && <p className="text-center text-[10px] text-muted-foreground">{request.projectName || '之前的项目'}</p>}
{request.intent === 'check-in'
? <p className="text-[11px] text-muted-foreground">智能体来看看你的进展</p>
: <div className="flex justify-end"><p className="consultation-user max-w-[92%] whitespace-pre-wrap break-words rounded-2xl rounded-br-sm px-4 py-3 text-[13px] leading-7">{request.text}</p></div>}
? <div className="space-y-1"><p className="text-[11px] text-muted-foreground">智能体来看看你的进展</p><MessageTimestamp value={request.createdAt} label="主动检查时间" /></div>
: <div className="flex flex-col items-end gap-1"><p className="consultation-user max-w-[92%] whitespace-pre-wrap break-words rounded-2xl rounded-br-sm px-4 py-3 text-[13px] leading-7">{request.text}</p><MessageTimestamp value={request.createdAt} label="发送时间" className="text-right" /></div>}
{request.references.length > 0 && <details className="text-xs text-muted-foreground"><summary>本轮引用 {request.references.length} 项</summary>{request.references.map((ref, index) => <pre className="whitespace-pre-wrap" key={index}>{ref.text}</pre>)}</details>}
<div className="flex items-center gap-2 text-[11px] text-muted-foreground"><TeacherAvatar definition={definition} className="h-6 w-6 rounded-lg" />{definition?.name ?? label}</div>
{!!request.toolActivity?.length && <details className="text-xs text-muted-foreground">
@@ -528,6 +529,7 @@ export function TeacherChatPanel({
</li>)}
</ul>
</details>}
<div className="space-y-1.5">
{request.status === 'completed' && request.replyIncomplete ? <div className="space-y-3">
<p role="status" className="text-[13px] leading-7 text-muted-foreground">这次回复未能完整显示</p>
{request.intent !== 'check-in' && request.text.trim() && <button type="button" disabled={helpUnavailable || !retryScopeMatches(request)} onClick={() => void send({ text: request.text, intent: request.intent }, request)} className="consultation-retry">重新回答</button>}
@@ -537,13 +539,12 @@ export function TeacherChatPanel({
? <p role="status" className="flex items-center gap-2 text-[13px] leading-7 text-muted-foreground"><Loader2 className="h-3.5 w-3.5 animate-spin motion-reduce:animate-none" />我看看你最近做到了哪里…</p>
: request.status === 'completed' && <>
<TeacherReply text={request.response} />
<div className="consultation-follow-ups" aria-label="可以和智能体聊的问题">
{request.suggestedQuestions?.map((question, index) => <button key={`${request.id}:${index}`} type="button" disabled={helpUnavailable} onClick={() => void send({ text: question })} className="consultation-follow-up"><span className="min-w-0 flex-1">{question}</span><ChevronRight className="h-4 w-4 shrink-0 opacity-70" aria-hidden="true" /></button>)}
</div>
</>}
{['failed', 'cancelled', 'interrupted'].includes(request.status) && <button type="button" disabled={helpUnavailable} onClick={askForSuggestions} className="consultation-retry">帮我整体看🧠</button>}
</> : request.response ? <TeacherReply text={request.response} /> : <div className="text-[13px] leading-7">{['running', 'preparing'].includes(request.status) ? <span role="status" className="inline-flex items-center gap-2 text-muted-foreground"><Loader2 className="h-3.5 w-3.5 animate-spin motion-reduce:animate-none" />{label}正在想…</span> : ['cancelled', 'interrupted'].includes(request.status) ? '这次先停在这里。想继续时可以再说说。' : ''}</div>}
{request.intent !== 'suggestions' && request.status === 'completed' && !request.replyIncomplete && Boolean(request.suggestedQuestions?.length) && <div className="consultation-follow-ups" aria-label="接着聊">
<MessageTimestamp value={request.finishedAt} pending={['running', 'preparing'].includes(request.status)} />
</div>
{request.status === 'completed' && !request.replyIncomplete && Boolean(request.suggestedQuestions?.length) && <div className="consultation-follow-ups" aria-label={request.intent === 'suggestions' ? '可以和智能体聊的问题' : '接着聊'}>
{request.suggestedQuestions?.map((question, index) => <button type="button" key={`${request.id}:${index}`} disabled={helpUnavailable} onClick={() => void send({ text: question })} className="consultation-follow-up"><span className="min-w-0 flex-1">{question}</span><ChevronRight className="h-4 w-4 shrink-0 opacity-70" aria-hidden="true" /></button>)}
</div>}
{request.status === 'completed' && !request.replyIncomplete && request.replyParseError && <p role="status" className="text-xs text-muted-foreground">回答正文已保留,部分附加内容未能显示。</p>}

View File

@@ -227,6 +227,7 @@ function optimisticNode(
id: nodeId,
clientRequestId,
role: 'user',
timestamp: Date.now(),
status: 'optimistic',
blocks: [
...(draft.text ? [{