mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 08:37:22 +00:00
Fix streaming message rendering, add state for awaiting tool response
This commit is contained in:
8 files changed
+83
-46
No files matched your search
@@ -48,6 +48,7 @@ import { ChatInput } from '@/components/Shakespeare/ChatInput';
|
|||||||
import { buildMessageContent } from '@/lib/buildMessageContent';
|
import { buildMessageContent } from '@/lib/buildMessageContent';
|
||||||
import { DotAI } from '@/lib/DotAI';
|
import { DotAI } from '@/lib/DotAI';
|
||||||
import { parseProviderModel } from '@/lib/parseProviderModel';
|
import { parseProviderModel } from '@/lib/parseProviderModel';
|
||||||
|
import { AIMessage } from '@/lib/SessionManager';
|
||||||
|
|
||||||
// Clean interfaces now handled by proper hooks
|
// Clean interfaces now handled by proper hooks
|
||||||
|
|
||||||
@@ -563,6 +564,79 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
|||||||
}
|
}
|
||||||
}), [internalStartNewSession]);
|
}), [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 (
|
return (
|
||||||
<div className="h-full flex flex-col relative">
|
<div className="h-full flex flex-col relative">
|
||||||
|
|
||||||
@@ -634,47 +708,8 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
|||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
{streamingMessage && (
|
|
||||||
streamingMessage.content || streamingMessage.reasoning_content ? (
|
{renderStreamingMessage()}
|
||||||
<>
|
|
||||||
<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>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Error Alert (Console or AI) - Don't show while assistant is loading */}
|
{/* Error Alert (Console or AI) - Don't show while assistant is loading */}
|
||||||
{displayError && !isLoading && (
|
{displayError && !isLoading && (
|
||||||
|
|||||||
@@ -66,11 +66,7 @@ export function useAIChat({
|
|||||||
setMessages(prev => [...prev, message]);
|
setMessages(prev => [...prev, message]);
|
||||||
// Whenever an assistant message is added, it means streaming is done (until we get another streamingUpdate)
|
// Whenever an assistant message is added, it means streaming is done (until we get another streamingUpdate)
|
||||||
if (message.role === 'assistant') {
|
if (message.role === 'assistant') {
|
||||||
setStreamingMessage({
|
setStreamingMessage(undefined);
|
||||||
role: 'assistant',
|
|
||||||
content: '',
|
|
||||||
reasoning_content: '',
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [projectId]);
|
}, [projectId]);
|
||||||
|
|||||||
@@ -131,6 +131,7 @@
|
|||||||
"selectModelFirst": "Please select a model to start chatting...",
|
"selectModelFirst": "Please select a model to start chatting...",
|
||||||
"sendMessage": "Send message",
|
"sendMessage": "Send message",
|
||||||
"stopGeneration": "Stop generation",
|
"stopGeneration": "Stop generation",
|
||||||
|
"calling": "Calling",
|
||||||
"running": "Running",
|
"running": "Running",
|
||||||
"chat": "Chat",
|
"chat": "Chat",
|
||||||
"preview": "Preview",
|
"preview": "Preview",
|
||||||
|
|||||||
@@ -124,6 +124,7 @@
|
|||||||
"selectModelFirst": "Da fatan za a zaɓi samfuri don farawa hira...",
|
"selectModelFirst": "Da fatan za a zaɓi samfuri don farawa hira...",
|
||||||
"sendMessage": "Aika saƙo",
|
"sendMessage": "Aika saƙo",
|
||||||
"stopGeneration": "Tsayar da samarwa",
|
"stopGeneration": "Tsayar da samarwa",
|
||||||
|
"calling": "Ana kira",
|
||||||
"running": "Ana gudana",
|
"running": "Ana gudana",
|
||||||
"chat": "Hira",
|
"chat": "Hira",
|
||||||
"preview": "Duba",
|
"preview": "Duba",
|
||||||
|
|||||||
@@ -124,6 +124,7 @@
|
|||||||
"selectModelFirst": "Biko họrọ ụdịdị iji malite ikwu okwu...",
|
"selectModelFirst": "Biko họrọ ụdịdị iji malite ikwu okwu...",
|
||||||
"sendMessage": "Ziga ozi",
|
"sendMessage": "Ziga ozi",
|
||||||
"stopGeneration": "Kwụsị mmepụta",
|
"stopGeneration": "Kwụsị mmepụta",
|
||||||
|
"calling": "Na-akpọ",
|
||||||
"running": "Na-agba ọsọ",
|
"running": "Na-agba ọsọ",
|
||||||
"chat": "Nkata",
|
"chat": "Nkata",
|
||||||
"preview": "Nlele",
|
"preview": "Nlele",
|
||||||
|
|||||||
@@ -126,6 +126,7 @@
|
|||||||
"selectModelFirst": "Selecione um modelo para começar a conversar...",
|
"selectModelFirst": "Selecione um modelo para começar a conversar...",
|
||||||
"sendMessage": "Enviar mensagem",
|
"sendMessage": "Enviar mensagem",
|
||||||
"stopGeneration": "Parar geração",
|
"stopGeneration": "Parar geração",
|
||||||
|
"calling": "Chamando",
|
||||||
"running": "Executando",
|
"running": "Executando",
|
||||||
"chat": "Chat",
|
"chat": "Chat",
|
||||||
"preview": "Visualização",
|
"preview": "Visualização",
|
||||||
|
|||||||
@@ -124,6 +124,7 @@
|
|||||||
"selectModelFirst": "Jọwọ yan awoṣe lati bẹrẹ ibaraẹnisọrọ...",
|
"selectModelFirst": "Jọwọ yan awoṣe lati bẹrẹ ibaraẹnisọrọ...",
|
||||||
"sendMessage": "Fi ifiranṣẹ ranṣẹ",
|
"sendMessage": "Fi ifiranṣẹ ranṣẹ",
|
||||||
"stopGeneration": "Duro ṣiṣẹda",
|
"stopGeneration": "Duro ṣiṣẹda",
|
||||||
|
"calling": "N pe",
|
||||||
"running": "N ṣiṣẹ",
|
"running": "N ṣiṣẹ",
|
||||||
"chat": "Ibaraẹnisọrọ",
|
"chat": "Ibaraẹnisọrọ",
|
||||||
"preview": "Aṣaju wiwo",
|
"preview": "Aṣaju wiwo",
|
||||||
|
|||||||
@@ -126,6 +126,7 @@
|
|||||||
"selectModelFirst": "请先选择一个模型开始聊天...",
|
"selectModelFirst": "请先选择一个模型开始聊天...",
|
||||||
"sendMessage": "发送消息",
|
"sendMessage": "发送消息",
|
||||||
"stopGeneration": "停止生成",
|
"stopGeneration": "停止生成",
|
||||||
|
"calling": "调用中",
|
||||||
"running": "运行中",
|
"running": "运行中",
|
||||||
"chat": "聊天",
|
"chat": "聊天",
|
||||||
"preview": "预览",
|
"preview": "预览",
|
||||||
|
|||||||
Reference in new issue
Block a user