diff --git a/src/components/Shakespeare/ChatPane.tsx b/src/components/Shakespeare/ChatPane.tsx index 387eb5e2..f2cebe81 100644 --- a/src/components/Shakespeare/ChatPane.tsx +++ b/src/components/Shakespeare/ChatPane.tsx @@ -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(({ } }), [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) && ( + + )} + {/* "Calling ..." if streaming tool call is in progress */} + {(streamingToolCall?.type === 'function') ? ( +
+
+ + + {t('calling')} {streamingToolCall.function?.name || 'tool'}... + +
+
+ ) : ( + <> + {/* Show loading skeleton if AI appears stuck generating tools */} + {isStuck && ( +
+
+
+ +
+
+
+ )} + + )} + + ) + } + + const lastMessage = messages[messages.length - 1] as AIMessage | undefined; + const lastToolCall = lastMessage?.role === 'assistant' ? lastMessage?.tool_calls?.[0] : undefined; + + // "Running ..." if last tool call is still executing + if (lastToolCall?.type === 'function') { + return ( +
+
+ + + {t('running')} {lastToolCall.function.name}... + +
+
+ ); + } + + // Fallback skeleton if AI is loading + if (isLoading) { + return ( +
+
+
+ +
+
+
+ ); + } + }; + return (
@@ -634,47 +708,8 @@ export const ChatPane = forwardRef(({ /> ); })} - {streamingMessage && ( - streamingMessage.content || streamingMessage.reasoning_content ? ( - <> - - {/* Show loading skeleton if AI appears stuck generating tools */} - {isStuck && ( -
-
-
- -
-
-
- )} - - ) : ( - !(streamingMessage?.tool_calls?.[0]?.type === 'function') && ( -
-
-
- -
-
-
- ) - ) - )} - {streamingMessage?.tool_calls?.[0]?.type === 'function' && ( -
-
- - - {t('running')} {streamingMessage.tool_calls?.[0]?.function?.name || 'tool'}... - -
-
- )} + + {renderStreamingMessage()} {/* Error Alert (Console or AI) - Don't show while assistant is loading */} {displayError && !isLoading && ( diff --git a/src/hooks/useAIChat.ts b/src/hooks/useAIChat.ts index 5a2d3ac5..74ac1435 100644 --- a/src/hooks/useAIChat.ts +++ b/src/hooks/useAIChat.ts @@ -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]); diff --git a/src/locales/en.json b/src/locales/en.json index 0d1a85c6..18c84244 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -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", diff --git a/src/locales/ha.json b/src/locales/ha.json index 5ab28476..fb568196 100644 --- a/src/locales/ha.json +++ b/src/locales/ha.json @@ -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", diff --git a/src/locales/ig.json b/src/locales/ig.json index de1b3bd3..f436ec94 100644 --- a/src/locales/ig.json +++ b/src/locales/ig.json @@ -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", diff --git a/src/locales/pt.json b/src/locales/pt.json index 01aa8395..acebd59e 100644 --- a/src/locales/pt.json +++ b/src/locales/pt.json @@ -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", diff --git a/src/locales/yo.json b/src/locales/yo.json index 2bdd9e7e..4484c1e2 100644 --- a/src/locales/yo.json +++ b/src/locales/yo.json @@ -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", diff --git a/src/locales/zh.json b/src/locales/zh.json index a6d4d390..365c3110 100644 --- a/src/locales/zh.json +++ b/src/locales/zh.json @@ -126,6 +126,7 @@ "selectModelFirst": "请先选择一个模型开始聊天...", "sendMessage": "发送消息", "stopGeneration": "停止生成", + "calling": "调用中", "running": "运行中", "chat": "聊天", "preview": "预览",