重构部分会话消息处理逻辑,优化会话消息渲染

This commit is contained in:
xintaofei
2026-03-10 23:24:27 +08:00
parent a048a4cae2
commit 380f430d5a
15 changed files with 92 additions and 568 deletions

View File

@@ -1,50 +0,0 @@
"use client"
import { memo, useMemo } from "react"
import { useTranslations } from "next-intl"
import type { LiveMessage } from "@/contexts/acp-connections-context"
import { ContentPartsRenderer } from "@/components/message/content-parts-renderer"
import { adaptLiveMessageFromAcp } from "@/lib/adapters/ai-elements-adapter"
import { Message, MessageContent } from "@/components/ai-elements/message"
interface LiveMessageBlockProps {
message: LiveMessage
isStreaming?: boolean
}
export const LiveMessageBlock = memo(function LiveMessageBlock({
message,
isStreaming = true,
}: LiveMessageBlockProps) {
const t = useTranslations("Folder.chat.liveMessageBlock")
const sharedT = useTranslations("Folder.chat.shared")
const hasContent = message.content.length > 0
const adapted = useMemo(
() =>
adaptLiveMessageFromAcp(message, {
isLiveStreaming: isStreaming,
toolCallFailedText: sharedT("toolCallFailed"),
planUpdatedText: sharedT("planUpdated"),
}),
[message, isStreaming, sharedT]
)
return (
<Message from="assistant">
<MessageContent>
{hasContent ? (
<ContentPartsRenderer parts={adapted.content} role="assistant" />
) : (
<div
className="flex items-center gap-1.5 text-muted-foreground py-1"
aria-label={t("assistantThinkingAria")}
>
<span className="h-2 w-2 rounded-full bg-primary animate-bounce [animation-delay:-0.3s]" />
<span className="h-2 w-2 rounded-full bg-primary animate-bounce [animation-delay:-0.15s]" />
<span className="h-2 w-2 rounded-full bg-primary animate-bounce" />
</div>
)}
</MessageContent>
</Message>
)
})