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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
import { useState } from "react";
import type { ConversationMessage as ConversationMessageType } from "../../lib/api";
interface ConversationMessageProps {
message: ConversationMessageType;
}
// Get role styling
function getRoleStyle(role: string) {
switch (role.toLowerCase()) {
case "user":
return { label: "User", color: "text-[#9bc3ff]", bg: "bg-[rgba(155,195,255,0.1)]" };
case "assistant":
return { label: "Assistant", color: "text-emerald-400", bg: "bg-[rgba(52,211,153,0.1)]" };
case "system":
return { label: "System", color: "text-yellow-400", bg: "bg-[rgba(250,204,21,0.1)]" };
case "tool":
return { label: "Tool", color: "text-purple-400", bg: "bg-[rgba(192,132,252,0.1)]" };
default:
return { label: role, color: "text-[#7788aa]", bg: "bg-[rgba(119,136,170,0.1)]" };
}
}
// Format JSON for display
function formatJson(data: unknown): string {
try {
return JSON.stringify(data, null, 2);
} catch {
return String(data);
}
}
export function ConversationMessage({ message }: ConversationMessageProps) {
const [showToolDetails, setShowToolDetails] = useState(false);
const { label, color, bg } = getRoleStyle(message.role);
const hasToolInfo = message.toolName || message.toolCalls?.length;
return (
<div className={`p-3 ${bg} border-l-2 border-transparent hover:border-[rgba(117,170,252,0.3)]`}>
{/* Header */}
<div className="flex items-center justify-between mb-2">
<div className="flex items-center gap-2">
<span className={`font-mono text-[10px] uppercase ${color}`}>{label}</span>
{message.toolName && (
<span className="font-mono text-[9px] text-purple-400 px-1.5 py-0.5 border border-[rgba(192,132,252,0.3)]">
{message.toolName}
</span>
)}
</div>
<div className="flex items-center gap-3">
{message.tokenCount && (
<span className="font-mono text-[9px] text-[#556677]">
{message.tokenCount.toLocaleString()} tokens
</span>
)}
{message.costUsd !== undefined && message.costUsd > 0 && (
<span className="font-mono text-[9px] text-[#556677]">
${message.costUsd.toFixed(4)}
</span>
)}
<span className="font-mono text-[9px] text-[#556677]">
{new Date(message.timestamp).toLocaleTimeString()}
</span>
</div>
</div>
{/* Content */}
<div className="font-mono text-xs text-[#dbe7ff] whitespace-pre-wrap break-words">
{message.content}
</div>
{/* Tool calls */}
{hasToolInfo && (
<div className="mt-2">
<button
onClick={() => setShowToolDetails(!showToolDetails)}
className="font-mono text-[9px] text-purple-400 hover:text-purple-300 uppercase flex items-center gap-1"
>
<svg
className={`w-3 h-3 transition-transform ${showToolDetails ? "rotate-90" : ""}`}
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
>
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 5l7 7-7 7" />
</svg>
{message.toolCalls?.length
? `${message.toolCalls.length} tool call${message.toolCalls.length > 1 ? "s" : ""}`
: "Tool details"}
</button>
{showToolDetails && (
<div className="mt-2 space-y-2">
{/* Tool input */}
{message.toolInput && (
<div className="p-2 bg-[rgba(0,0,0,0.3)] border border-[rgba(192,132,252,0.2)]">
<div className="font-mono text-[9px] text-purple-400 uppercase mb-1">Input</div>
<pre className="font-mono text-[10px] text-[#9bc3ff] overflow-x-auto">
{formatJson(message.toolInput)}
</pre>
</div>
)}
{/* Tool result */}
{message.toolResult && (
<div
className={`p-2 border ${
message.isError
? "bg-[rgba(239,68,68,0.1)] border-[rgba(239,68,68,0.3)]"
: "bg-[rgba(0,0,0,0.3)] border-[rgba(192,132,252,0.2)]"
}`}
>
<div
className={`font-mono text-[9px] uppercase mb-1 ${
message.isError ? "text-red-400" : "text-purple-400"
}`}
>
{message.isError ? "Error" : "Result"}
</div>
<pre className="font-mono text-[10px] text-[#9bc3ff] overflow-x-auto max-h-48 overflow-y-auto">
{message.toolResult}
</pre>
</div>
)}
{/* Multiple tool calls */}
{message.toolCalls?.map((call, i) => (
<div
key={call.id || i}
className="p-2 bg-[rgba(0,0,0,0.3)] border border-[rgba(192,132,252,0.2)]"
>
<div className="font-mono text-[9px] text-purple-400 uppercase mb-1">
{call.name}
</div>
<pre className="font-mono text-[10px] text-[#9bc3ff] overflow-x-auto">
{formatJson(call.input)}
</pre>
</div>
))}
</div>
)}
</div>
)}
</div>
);
}
|