fix: hide internal image failure messages
This commit is contained in:
parent
fdff0c2865
commit
ffed16d802
@ -194,6 +194,15 @@ function stripModelBadgeLines(text: string): string {
|
|||||||
.trim();
|
.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isInternalImageGenerationFailureText(text: string): boolean {
|
||||||
|
const normalized = stripModelBadgeLines(filterAgentRoutingNoise(filterVideoContent(text))).trim();
|
||||||
|
if (!normalized) return false;
|
||||||
|
if (extractImageUrlsFromText(normalized).length > 0) return false;
|
||||||
|
return /^(?:生成图片失败|图片生成失败)[,,::\s]*(?:未找到图片数据|未解析到图片|模型未返回生成图片|图片数据不可用)?$/i.test(
|
||||||
|
normalized
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function appendImageDoneSummary(text: string): string {
|
function appendImageDoneSummary(text: string): string {
|
||||||
if (!text) return text;
|
if (!text) return text;
|
||||||
const normalized = String(text || "").trim();
|
const normalized = String(text || "").trim();
|
||||||
@ -375,9 +384,23 @@ const PurePreviewMessage = ({
|
|||||||
const attachmentsFromMessage = message.parts.filter(
|
const attachmentsFromMessage = message.parts.filter(
|
||||||
(part) => part.type === "file"
|
(part) => part.type === "file"
|
||||||
);
|
);
|
||||||
|
const hasVisibleTextPart = message.parts.some(
|
||||||
|
(part) =>
|
||||||
|
part.type === "text" &&
|
||||||
|
part.text?.trim() &&
|
||||||
|
!(message.role === "assistant" && isInternalImageGenerationFailureText(part.text))
|
||||||
|
);
|
||||||
|
|
||||||
useDataStream();
|
useDataStream();
|
||||||
|
|
||||||
|
if (
|
||||||
|
message.role === "assistant" &&
|
||||||
|
!hasVisibleTextPart &&
|
||||||
|
attachmentsFromMessage.length === 0
|
||||||
|
) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className="group/message fade-in w-full animate-in duration-200"
|
className="group/message fade-in w-full animate-in duration-200"
|
||||||
@ -390,7 +413,7 @@ const PurePreviewMessage = ({
|
|||||||
"justify-start": message.role === "assistant",
|
"justify-start": message.role === "assistant",
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
{message.role === "assistant" && message.parts.some((part) => part.type === "text" && part.text && part.text.trim().length > 0) && (
|
{message.role === "assistant" && hasVisibleTextPart && (
|
||||||
<div className="-mt-1 flex size-8 shrink-0 items-center justify-center rounded-full bg-background ring-1 ring-border">
|
<div className="-mt-1 flex size-8 shrink-0 items-center justify-center rounded-full bg-background ring-1 ring-border">
|
||||||
<SparklesIcon size={14} />
|
<SparklesIcon size={14} />
|
||||||
</div>
|
</div>
|
||||||
@ -398,14 +421,9 @@ const PurePreviewMessage = ({
|
|||||||
|
|
||||||
<div
|
<div
|
||||||
className={cn("flex min-w-0 flex-col", {
|
className={cn("flex min-w-0 flex-col", {
|
||||||
"gap-2 md:gap-4": message.parts?.some(
|
"gap-2 md:gap-4": hasVisibleTextPart,
|
||||||
(p) => p.type === "text" && p.text?.trim()
|
|
||||||
),
|
|
||||||
"w-full":
|
"w-full":
|
||||||
(message.role === "assistant" &&
|
(message.role === "assistant" && hasVisibleTextPart) ||
|
||||||
message.parts?.some(
|
|
||||||
(p) => p.type === "text" && p.text?.trim()
|
|
||||||
)) ||
|
|
||||||
mode === "edit",
|
mode === "edit",
|
||||||
"max-w-[calc(100%-2.5rem)] sm:max-w-[min(fit-content,80%)]":
|
"max-w-[calc(100%-2.5rem)] sm:max-w-[min(fit-content,80%)]":
|
||||||
message.role === "user" && mode !== "edit",
|
message.role === "user" && mode !== "edit",
|
||||||
@ -445,6 +463,13 @@ const PurePreviewMessage = ({
|
|||||||
|
|
||||||
if (type === "text") {
|
if (type === "text") {
|
||||||
if (mode === "view") {
|
if (mode === "view") {
|
||||||
|
if (
|
||||||
|
message.role === "assistant" &&
|
||||||
|
isInternalImageGenerationFailureText(part.text)
|
||||||
|
) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// 检查是否是图片处理的加载消息
|
// 检查是否是图片处理的加载消息
|
||||||
if (part.text === "正在变清晰..." || part.text === "正在抠图..." || part.text === "正在图像拓展..." || part.text === "正在去水印...") {
|
if (part.text === "正在变清晰..." || part.text === "正在抠图..." || part.text === "正在图像拓展..." || part.text === "正在去水印...") {
|
||||||
let type: "enhance" | "rmbg" | "extend" | "watermark";
|
let type: "enhance" | "rmbg" | "extend" | "watermark";
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user