mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-21 15:41:17 +00:00
- Reduce ACP stall detection from 15s to 3s for faster feedback - Add statusText field to ChatMessage for transient status display - Render status text with thinking-shimmer CSS animation - Clear statusText when real content arrives (onTextDelta) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
159 lines
6.1 KiB
TypeScript
159 lines
6.1 KiB
TypeScript
/**
|
|
* ChatMessageList - Renders the list of chat messages
|
|
*
|
|
* Claude-Code-style: user messages in bordered bubbles (right-aligned),
|
|
* assistant responses as plain text (left-aligned, no border/bg).
|
|
* No avatars. Thinking blocks are collapsible.
|
|
*/
|
|
|
|
import { AlertCircle } from 'lucide-react';
|
|
import React from 'react';
|
|
import { useI18n } from '../../application/i18n/I18nProvider';
|
|
import type { ChatMessage } from '../../infrastructure/ai/types';
|
|
import {
|
|
Conversation,
|
|
ConversationContent,
|
|
ConversationScrollButton,
|
|
} from '../ai-elements/conversation';
|
|
import { Message, MessageContent, MessageResponse } from '../ai-elements/message';
|
|
import { ToolCall } from '../ai-elements/tool-call';
|
|
import { InlineApprovalCard } from './InlineApprovalCard';
|
|
import ThinkingBlock from './ThinkingBlock';
|
|
|
|
interface ChatMessageListProps {
|
|
messages: ChatMessage[];
|
|
isStreaming?: boolean;
|
|
onApprove?: (messageId: string) => void;
|
|
onReject?: (messageId: string) => void;
|
|
}
|
|
|
|
const ChatMessageList: React.FC<ChatMessageListProps> = ({ messages, isStreaming, onApprove, onReject }) => {
|
|
const { t } = useI18n();
|
|
const visibleMessages = messages.filter(m => m.role !== 'system');
|
|
|
|
if (visibleMessages.length === 0 && !isStreaming) {
|
|
return (
|
|
<div className="flex-1 flex items-center justify-center px-6">
|
|
<p className="text-[13px] text-muted-foreground/40 text-center">
|
|
{t('ai.chat.emptyHint')}
|
|
</p>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
const lastAssistantMessage = visibleMessages.findLast(m => m.role === 'assistant');
|
|
|
|
return (
|
|
<Conversation className="flex-1">
|
|
<ConversationContent className="gap-1.5 px-4 py-2">
|
|
{visibleMessages.map((message) => {
|
|
if (message.role === 'tool') {
|
|
return message.toolResults?.map((tr) => (
|
|
<ToolCall
|
|
key={tr.toolCallId}
|
|
name={tr.toolCallId}
|
|
result={tr.content}
|
|
isError={tr.isError}
|
|
/>
|
|
));
|
|
}
|
|
|
|
const isUser = message.role === 'user';
|
|
const isLastAssistant = message === lastAssistantMessage;
|
|
const isThisStreaming = isStreaming && isLastAssistant;
|
|
|
|
return (
|
|
<Message key={message.id} from={message.role}>
|
|
<MessageContent>
|
|
{/* Thinking block */}
|
|
{!isUser && message.thinking && (
|
|
<ThinkingBlock
|
|
content={message.thinking}
|
|
isStreaming={!!isThisStreaming && !message.content}
|
|
durationMs={message.thinkingDurationMs}
|
|
/>
|
|
)}
|
|
|
|
{/* User images */}
|
|
{isUser && message.images && message.images.length > 0 && (
|
|
<div className="flex gap-1.5 flex-wrap mb-1">
|
|
{message.images.map((img, i) => (
|
|
<img
|
|
key={i}
|
|
src={`data:${img.mediaType};base64,${img.base64Data}`}
|
|
alt={img.filename || 'image'}
|
|
className="max-h-[120px] max-w-[200px] rounded-md object-contain border border-border/20"
|
|
/>
|
|
))}
|
|
</div>
|
|
)}
|
|
|
|
{message.content && (
|
|
isUser
|
|
? <div className="whitespace-pre-wrap break-words text-[13px]">{message.content}</div>
|
|
: <MessageResponse isAnimating={isThisStreaming}>
|
|
{message.content}
|
|
</MessageResponse>
|
|
)}
|
|
|
|
{/* Tool calls */}
|
|
{message.toolCalls?.map((tc) => (
|
|
<ToolCall
|
|
key={tc.id}
|
|
name={tc.name}
|
|
args={tc.arguments}
|
|
isLoading={isThisStreaming && message.executionStatus === 'running'}
|
|
/>
|
|
))}
|
|
|
|
{/* Inline approval card */}
|
|
{message.pendingApproval && (
|
|
<InlineApprovalCard
|
|
toolName={message.pendingApproval.toolName}
|
|
toolArgs={message.pendingApproval.toolArgs}
|
|
status={message.pendingApproval.status}
|
|
onApprove={() => onApprove?.(message.id)}
|
|
onReject={() => onReject?.(message.id)}
|
|
/>
|
|
)}
|
|
|
|
{/* Status text with shimmer */}
|
|
{message.statusText && (
|
|
<div className="py-1">
|
|
<span className="thinking-shimmer text-xs">{message.statusText}</span>
|
|
</div>
|
|
)}
|
|
|
|
{/* Error info */}
|
|
{message.errorInfo && (
|
|
<div className="flex items-start gap-2 px-3 py-2 rounded-md bg-destructive/10 border border-destructive/20 text-sm">
|
|
<AlertCircle className="h-4 w-4 text-destructive shrink-0 mt-0.5" />
|
|
<div className="flex-1 min-w-0">
|
|
<p className="text-destructive font-medium">{message.errorInfo.message}</p>
|
|
{message.errorInfo.retryable && (
|
|
<p className="text-muted-foreground text-xs mt-1">You can retry by sending your message again.</p>
|
|
)}
|
|
</div>
|
|
</div>
|
|
)}
|
|
</MessageContent>
|
|
</Message>
|
|
);
|
|
})}
|
|
|
|
{/* Streaming indicator — only when no content and no thinking yet */}
|
|
{isStreaming && !lastAssistantMessage?.content && !lastAssistantMessage?.thinking && (
|
|
<div className="flex items-center gap-1 py-2">
|
|
<span className="w-1.5 h-1.5 rounded-full bg-muted-foreground/30 animate-bounce [animation-delay:0ms]" />
|
|
<span className="w-1.5 h-1.5 rounded-full bg-muted-foreground/30 animate-bounce [animation-delay:150ms]" />
|
|
<span className="w-1.5 h-1.5 rounded-full bg-muted-foreground/30 animate-bounce [animation-delay:300ms]" />
|
|
</div>
|
|
)}
|
|
</ConversationContent>
|
|
<ConversationScrollButton />
|
|
</Conversation>
|
|
);
|
|
};
|
|
|
|
export default React.memo(ChatMessageList);
|