File size: 1,439 Bytes
e77f678
 
 
a56db97
 
 
e77f678
 
 
 
 
 
 
 
a56db97
 
e77f678
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0bc8e38
 
e77f678
bbfa431
e77f678
 
 
 
 
 
bbfa431
e77f678
bbfa431
e77f678
 
 
b1d24de
e77f678
 
a56db97
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import UserMessage from './UserMessage';
import AssistantMessage from './AssistantMessage';
import type { Message } from '@/types/agent';

interface MessageBubbleProps {
  message: Message;
  /** True if this is the user message that starts the last turn. */
  isLastTurn?: boolean;
  /** Callback to undo (remove) the last turn. */
  onUndoTurn?: () => void;
  /** Whether the agent is currently processing. */
  isProcessing?: boolean;
  /** True when this message is actively receiving streaming chunks. */
  isStreaming?: boolean;
}

/**
 * Thin dispatcher — routes each message to the correct
 * specialised component based on its role / content.
 */
export default function MessageBubble({
  message,
  isLastTurn = false,
  onUndoTurn,
  isProcessing = false,
  isStreaming = false,
}: MessageBubbleProps) {
  // Legacy approval-only messages (from old localStorage data) — skip them.
  // Approvals are now rendered inline within ToolCallGroup.
  if (message.approval && !message.content && !message.segments?.length) {
    return null;
  }

  if (message.role === 'user') {
    return (
      <UserMessage
        message={message}
        isLastTurn={isLastTurn}
        onUndoTurn={onUndoTurn}
        isProcessing={isProcessing}
      />
    );
  }

  if (message.role === 'assistant') {
    return <AssistantMessage message={message} isStreaming={isStreaming} />;
  }

  // Fallback (tool messages, etc.)
  return null;
}