修复会话实时状态显示

This commit is contained in:
xintaofei
2026-03-10 14:10:04 +08:00
parent 13667729b9
commit aa1ff9a6df
3 changed files with 25 additions and 11 deletions

View File

@@ -932,7 +932,12 @@ export function WelcomeInputPanel({
overscan={10} overscan={10}
/> />
</MessageThread> </MessageThread>
{showLive && <LiveTurnStats message={conn.liveMessage!} />} {showLive && connStatus === "prompting" && (
<LiveTurnStats
message={conn.liveMessage!}
isStreaming={connStatus === "prompting"}
/>
)}
<AgentPlanOverlay <AgentPlanOverlay
message={conn.liveMessage} message={conn.liveMessage}
entries={historicalPlanEntries} entries={historicalPlanEntries}

View File

@@ -12,6 +12,7 @@ import { FilePenLine, Timer, Wrench } from "lucide-react"
interface LiveTurnStatsProps { interface LiveTurnStatsProps {
message: LiveMessage message: LiveMessage
isStreaming?: boolean
} }
interface LineChangeStats { interface LineChangeStats {
@@ -257,7 +258,10 @@ function extractLiveEditStats(message: LiveMessage): LiveEditStats {
return { files: files.size, additions, deletions } return { files: files.size, additions, deletions }
} }
export function LiveTurnStats({ message }: LiveTurnStatsProps) { export function LiveTurnStats({
message,
isStreaming = true,
}: LiveTurnStatsProps) {
const locale = useLocale() const locale = useLocale()
const t = useTranslations("Folder.chat.liveTurnStats") const t = useTranslations("Folder.chat.liveTurnStats")
const [elapsed, setElapsed] = useState(() => Date.now() - message.startedAt) const [elapsed, setElapsed] = useState(() => Date.now() - message.startedAt)
@@ -280,21 +284,23 @@ export function LiveTurnStats({ message }: LiveTurnStatsProps) {
// Count tool calls from live content // Count tool calls from live content
let toolCallCount = 0 let toolCallCount = 0
let isThinking = false let hasThinkingBlock = false
for (const block of message.content) { for (const block of message.content) {
if (block.type === "tool_call") { if (block.type === "tool_call") {
toolCallCount++ toolCallCount++
} else if (block.type === "thinking") { } else if (block.type === "thinking") {
isThinking = true hasThinkingBlock = true
} }
} }
// If the last block is thinking, mark as currently thinking // Only active streams should show thinking/streaming state.
const lastBlock = message.content[message.content.length - 1] const lastBlock = message.content[message.content.length - 1]
if (lastBlock?.type === "thinking") { const isThinking =
isThinking = true isStreaming &&
} hasThinkingBlock &&
message.content.length <= 1 &&
lastBlock?.type === "thinking"
const elapsedLabel = const elapsedLabel =
elapsed >= 60_000 elapsed >= 60_000
@@ -304,7 +310,7 @@ export function LiveTurnStats({ message }: LiveTurnStatsProps) {
return ( return (
<div className="flex h-8 shrink-0 items-center justify-center gap-3 px-4 text-xs leading-none text-muted-foreground"> <div className="flex h-8 shrink-0 items-center justify-center gap-3 px-4 text-xs leading-none text-muted-foreground">
<span className="inline-block h-1.5 w-1.5 rounded-full bg-primary animate-pulse shrink-0" /> <span className="inline-block h-1.5 w-1.5 rounded-full bg-primary animate-pulse shrink-0" />
{isThinking && message.content.length <= 1 ? ( {isThinking ? (
<span>{t("thinking")}</span> <span>{t("thinking")}</span>
) : ( ) : (
<span>{t("streaming")}</span> <span>{t("streaming")}</span>

View File

@@ -402,8 +402,11 @@ export function MessageListView({
overscan={10} overscan={10}
/> />
</MessageThread> </MessageThread>
{showLiveMessage && liveMessage && ( {showLiveMessage && liveMessage && connStatus === "prompting" && (
<LiveTurnStats message={liveMessage} /> <LiveTurnStats
message={liveMessage}
isStreaming={connStatus === "prompting"}
/>
)} )}
<AgentPlanOverlay <AgentPlanOverlay
key={agentPlanOverlayKey} key={agentPlanOverlayKey}