fix: show Clawd processing hint

This commit is contained in:
134 2026-06-24 00:50:45 +08:00
parent 47f996d81a
commit fb4915e657

View File

@ -324,6 +324,12 @@ const CLAWD_TABLE_ACCEPT =
const CLAWD_TABLE_ALLOWED_EXTENSIONS = new Set(["xlsx", "csv", "tsv"]);
const CLAWD_TABLE_MAX_FILES = 3;
const CLAWD_TABLE_MAX_BYTES = 10 * 1024 * 1024;
const CLAWD_PROCESSING_HINT =
"已收到,这个任务稍微繁重一些,处理时间可能会长一点,请耐心等候。";
const CLAWD_SIMPLE_PROMPT_PATTERNS = [
/^(hi|hello|hey|你好|您好|哈喽|嗨|在吗|早上好|下午好|晚上好)[\s!.。!??~~]*$/i,
/^(你是谁|你叫什么|你叫什么名字|你能做什么|你可以做什么|有什么功能|介绍一下自己|帮我介绍一下你)[\s!.。!??~~]*$/,
];
function getClawdTableFileExtension(fileName: string) {
return String(fileName || "")
@ -339,6 +345,29 @@ function isClawdTableFile(file: File) {
);
}
function shouldShowClawdProcessingHint(
message: string,
hasTableFiles: boolean,
hasImageAttachments: boolean
) {
if (hasTableFiles || hasImageAttachments) {
return true;
}
const normalizedMessage = String(message || "")
.replace(/\u200b/g, " ")
.replace(/\s+/g, " ")
.trim();
if (!normalizedMessage) {
return false;
}
return !CLAWD_SIMPLE_PROMPT_PATTERNS.some((pattern) =>
pattern.test(normalizedMessage)
);
}
function formatClawdTableFileSize(bytes: number) {
if (!Number.isFinite(bytes) || bytes <= 0) {
return "0KB";
@ -986,7 +1015,7 @@ function CanvasTypewriterText({
return <div className={className}>{displayText}</div>;
}
function CanvasAssistantTypingPlaceholder() {
function CanvasAssistantTypingPlaceholder({ hint }: { hint?: string | null }) {
return (
<div className="flex w-full justify-start">
<style>{`
@ -1001,20 +1030,27 @@ function CanvasAssistantTypingPlaceholder() {
}
}
`}</style>
<div
aria-label="Clawd 正在处理"
className="inline-flex h-7 items-center gap-1 rounded-[14px] bg-[#f4f5f7] px-3 text-[#9aa3b2] dark:bg-white/8 dark:text-zinc-400"
>
{[0, 1, 2].map((index) => (
<span
key={index}
className="h-1.5 w-1.5 rounded-full bg-current"
style={{
animation: "clawdTypingDotBounce 0.9s ease-in-out infinite",
animationDelay: `${index * 140}ms`,
}}
/>
))}
<div className="flex max-w-[min(78%,680px)] flex-col items-start gap-2">
{hint ? (
<div className="rounded-[18px] bg-[#f4f5f7] px-4 py-3 text-[15px] leading-6 text-[#2f343d] shadow-sm dark:bg-white/8 dark:text-zinc-200">
{hint}
</div>
) : null}
<div
aria-label="Clawd 正在处理"
className="inline-flex h-7 items-center gap-1 rounded-[14px] bg-[#f4f5f7] px-3 text-[#9aa3b2] dark:bg-white/8 dark:text-zinc-400"
>
{[0, 1, 2].map((index) => (
<span
key={index}
className="h-1.5 w-1.5 rounded-full bg-current"
style={{
animation: "clawdTypingDotBounce 0.9s ease-in-out infinite",
animationDelay: `${index * 140}ms`,
}}
/>
))}
</div>
</div>
</div>
);
@ -1363,6 +1399,7 @@ export function CanvasChatPanel({
const [detailGenerationMode, setDetailGenerationMode] = useState<DetailGenerationMode>("classic");
const [isDetailGenerating, setIsDetailGenerating] = useState(false);
const [isClawdSubmitting, setIsClawdSubmitting] = useState(false);
const [clawdProcessingHint, setClawdProcessingHint] = useState<string | null>(null);
const [detailSections, setDetailSections] = useState<Record<DetailSectionKey, boolean>>({
required: true,
strategy: false,
@ -8884,6 +8921,13 @@ export function CanvasChatPanel({
return;
}
const nextProcessingHint = shouldShowClawdProcessingHint(
textContent,
hasTableFiles,
hasImageAttachments
)
? CLAWD_PROCESSING_HINT
: null;
const userMessageId = generateUUID();
const latestMessageTimestamp = messages.reduce(
(latest, message) => Math.max(latest, getMessageTimestamp(message) ?? 0),
@ -8905,6 +8949,7 @@ export function CanvasChatPanel({
signature: sendSignature,
timestamp: Date.now(),
});
setClawdProcessingHint(nextProcessingHint);
setIsClawdSubmitting(true);
setMessages((previousMessages) =>
sortCanvasMessagesByCreatedAt([
@ -8998,6 +9043,7 @@ export function CanvasChatPanel({
}
} finally {
setIsClawdSubmitting(false);
setClawdProcessingHint(null);
releaseSendGuard(activeChatId);
}
return;
@ -11351,7 +11397,7 @@ export function CanvasChatPanel({
)}
{isClawdMode && isClawdSubmitting ? (
<CanvasAssistantTypingPlaceholder />
<CanvasAssistantTypingPlaceholder hint={clawdProcessingHint} />
) : null}
{isLoading && !shouldRenderImageLoading && (