Fix streaming message rendering, add state for awaiting tool response

This commit is contained in:
Alex Gleason committed 2025-12-07 15:09:38 -06:00
1 parent 32892c8840
commit 799aaa5696
8 files changed
+83 -46

No files matched your search

+76 -41
View File
@@ -48,6 +48,7 @@ import { ChatInput } from '@/components/Shakespeare/ChatInput';
import { buildMessageContent } from '@/lib/buildMessageContent';
import { DotAI } from '@/lib/DotAI';
import { parseProviderModel } from '@/lib/parseProviderModel';
import { AIMessage } from '@/lib/SessionManager';
// Clean interfaces now handled by proper hooks
@@ -563,6 +564,79 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
}
}), [internalStartNewSession]);
/** Render streaming message, loading skeleton, or tool loading state */
const renderStreamingMessage = () => {
if (streamingMessage) {
const streamingToolCall = streamingMessage.tool_calls?.[0];
return (
<>
{/* Show streaming message if text is streaming */}
{(streamingMessage.content || streamingMessage.reasoning_content) && (
<AIMessageItem
key="streaming-message"
message={streamingMessage}
isCurrentlyLoading={isLoading}
/>
)}
{/* "Calling <tool>..." if streaming tool call is in progress */}
{(streamingToolCall?.type === 'function') ? (
<div key="tool-calls-loading" className="-mt-2">
<div className="flex items-center gap-2 px-2 py-1 text-xs text-muted-foreground">
<Loader2 className="h-3 w-3 animate-spin flex-shrink-0" />
<span className="font-medium">
{t('calling')} {streamingToolCall.function?.name || 'tool'}...
</span>
</div>
</div>
) : (
<>
{/* Show loading skeleton if AI appears stuck generating tools */}
{isStuck && (
<div key="stuck-loading-skeleton" className="flex">
<div className="flex-1 min-w-0">
<div className="text-sm space-y-2">
<Skeleton className="h-4 w-3/4" />
</div>
</div>
</div>
)}
</>
)}
</>
)
}
const lastMessage = messages[messages.length - 1] as AIMessage | undefined;
const lastToolCall = lastMessage?.role === 'assistant' ? lastMessage?.tool_calls?.[0] : undefined;
// "Running <tool>..." if last tool call is still executing
if (lastToolCall?.type === 'function') {
return (
<div key="tool-running-loading" className="-mt-2">
<div className="flex items-center gap-2 px-2 py-1 text-xs text-muted-foreground">
<Loader2 className="h-3 w-3 animate-spin flex-shrink-0" />
<span className="font-medium">
{t('running')} {lastToolCall.function.name}...
</span>
</div>
</div>
);
}
// Fallback skeleton if AI is loading
if (isLoading) {
return (
<div key="streaming-loading" className="flex">
<div className="flex-1 min-w-0">
<div className="text-sm space-y-2">
<Skeleton className="h-4 w-3/4" />
</div>
</div>
</div>
);
}
};
return (
<div className="h-full flex flex-col relative">
@@ -634,47 +708,8 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
/>
);
})}
{streamingMessage && (
streamingMessage.content || streamingMessage.reasoning_content ? (
<>
<AIMessageItem
key="streaming-message"
message={streamingMessage}
isCurrentlyLoading={isLoading}
/>
{/* Show loading skeleton if AI appears stuck generating tools */}
{isStuck && (
<div key="stuck-loading-skeleton" className="flex">
<div className="flex-1 min-w-0">
<div className="text-sm space-y-2">
<Skeleton className="h-4 w-3/4" />
</div>
</div>
</div>
)}
</>
) : (
!(streamingMessage?.tool_calls?.[0]?.type === 'function') && (
<div key="streaming-loading" className="flex">
<div className="flex-1 min-w-0">
<div className="text-sm space-y-2">
<Skeleton className="h-4 w-3/4" />
</div>
</div>
</div>
)
)
)}
{streamingMessage?.tool_calls?.[0]?.type === 'function' && (
<div key="tool-calls-loading" className="-mt-2">
<div className="flex items-center gap-2 px-2 py-1 text-xs text-muted-foreground">
<Loader2 className="h-3 w-3 animate-spin flex-shrink-0" />
<span className="font-medium">
{t('running')} {streamingMessage.tool_calls?.[0]?.function?.name || 'tool'}...
</span>
</div>
</div>
)}
{renderStreamingMessage()}
{/* Error Alert (Console or AI) - Don't show while assistant is loading */}
{displayError && !isLoading && (
+1 -5
View File
@@ -66,11 +66,7 @@ export function useAIChat({
setMessages(prev => [...prev, message]);
// Whenever an assistant message is added, it means streaming is done (until we get another streamingUpdate)
if (message.role === 'assistant') {
setStreamingMessage({
role: 'assistant',
content: '',
reasoning_content: '',
});
setStreamingMessage(undefined);
}
}
}, [projectId]);
+1
View File
@@ -131,6 +131,7 @@
"selectModelFirst": "Please select a model to start chatting...",
"sendMessage": "Send message",
"stopGeneration": "Stop generation",
"calling": "Calling",
"running": "Running",
"chat": "Chat",
"preview": "Preview",
+1
View File
@@ -124,6 +124,7 @@
"selectModelFirst": "Da fatan za a zaɓi samfuri don farawa hira...",
"sendMessage": "Aika saƙo",
"stopGeneration": "Tsayar da samarwa",
"calling": "Ana kira",
"running": "Ana gudana",
"chat": "Hira",
"preview": "Duba",
+1
View File
@@ -124,6 +124,7 @@
"selectModelFirst": "Biko họrọ ụdịdị iji malite ikwu okwu...",
"sendMessage": "Ziga ozi",
"stopGeneration": "Kwụsị mmepụta",
"calling": "Na-akpọ",
"running": "Na-agba ọsọ",
"chat": "Nkata",
"preview": "Nlele",
+1
View File
@@ -126,6 +126,7 @@
"selectModelFirst": "Selecione um modelo para começar a conversar...",
"sendMessage": "Enviar mensagem",
"stopGeneration": "Parar geração",
"calling": "Chamando",
"running": "Executando",
"chat": "Chat",
"preview": "Visualização",
+1
View File
@@ -124,6 +124,7 @@
"selectModelFirst": "Jọwọ yan awoṣe lati bẹrẹ ibaraẹnisọrọ...",
"sendMessage": "Fi ifiranṣẹ ranṣẹ",
"stopGeneration": "Duro ṣiṣẹda",
"calling": "N pe",
"running": "N ṣiṣẹ",
"chat": "Ibaraẹnisọrọ",
"preview": "Aṣaju wiwo",
+1
View File
@@ -126,6 +126,7 @@
"selectModelFirst": "请先选择一个模型开始聊天...",
"sendMessage": "发送消息",
"stopGeneration": "停止生成",
"calling": "调用中",
"running": "运行中",
"chat": "聊天",
"preview": "预览",