diff --git a/webui/src/pages/Chat.tsx b/webui/src/pages/Chat.tsx index f9a6b20..526cdd0 100644 --- a/webui/src/pages/Chat.tsx +++ b/webui/src/pages/Chat.tsx @@ -24,15 +24,24 @@ const Chat: React.FC = () => { const j = await r.json(); const arr = Array.isArray(j.messages) ? j.messages : []; const mapped: ChatItem[] = arr.map((m: any) => { - const role = (m.role === 'assistant' || m.role === 'user') ? m.role : 'assistant'; + const baseRole = String(m.role || 'assistant'); + let role: ChatItem['role'] = 'assistant'; + if (baseRole === 'user') role = 'user'; + else if (baseRole === 'tool') role = 'tool'; + else if (baseRole === 'system') role = 'system'; + let text = m.content || ''; - if (m.role === 'tool') { - text = `[tool output]\n${text}`; - } + let label = role === 'user' ? 'User' : role === 'tool' ? 'Exec' : role === 'system' ? 'System' : 'Agent'; + if (Array.isArray(m.tool_calls) && m.tool_calls.length > 0) { + role = 'exec'; + label = 'Exec'; text = `${text}\n[tool calls: ${m.tool_calls.map((x: any) => x?.function?.name || x?.name).filter(Boolean).join(', ')}]`; } - return { role, text }; + if (baseRole === 'tool') { + text = `[tool output]\n${text}`; + } + return { role, text, label }; }); setChat(mapped); } catch (e) { @@ -58,7 +67,7 @@ const Chat: React.FC = () => { } const userText = msg + (media ? `\n[Attached File: ${f?.name}]` : ''); - setChat((prev) => [...prev, { role: 'user', text: userText }]); + setChat((prev) => [...prev, { role: 'user', text: userText, label: 'User' }]); const currentMsg = msg; setMsg(''); @@ -78,7 +87,7 @@ const Chat: React.FC = () => { const decoder = new TextDecoder(); let assistantText = ''; - setChat((prev) => [...prev, { role: 'assistant', text: '' }]); + setChat((prev) => [...prev, { role: 'assistant', text: '', label: 'Agent' }]); while (true) { const { value, done } = await reader.read(); @@ -87,7 +96,7 @@ const Chat: React.FC = () => { assistantText += chunk; setChat((prev) => { const next = [...prev]; - next[next.length - 1] = { role: 'assistant', text: assistantText }; + next[next.length - 1] = { role: 'assistant', text: assistantText, label: 'Agent' }; return next; }); } @@ -95,7 +104,7 @@ const Chat: React.FC = () => { // refresh full persisted history (includes tool/internal traces) loadHistory(); } catch (e) { - setChat((prev) => [...prev, { role: 'assistant', text: 'Error: Failed to get response from server.' }]); + setChat((prev) => [...prev, { role: 'system', text: 'Error: Failed to get response from server.', label: 'System' }]); } } @@ -120,22 +129,43 @@ const Chat: React.FC = () => {
{t('startConversation')}
) : ( - chat.map((m, i) => ( -{m.text}
-{m.text}
+