fix: show Clawd processing hint
This commit is contained in:
parent
47f996d81a
commit
fb4915e657
@ -324,6 +324,12 @@ const CLAWD_TABLE_ACCEPT =
|
|||||||
const CLAWD_TABLE_ALLOWED_EXTENSIONS = new Set(["xlsx", "csv", "tsv"]);
|
const CLAWD_TABLE_ALLOWED_EXTENSIONS = new Set(["xlsx", "csv", "tsv"]);
|
||||||
const CLAWD_TABLE_MAX_FILES = 3;
|
const CLAWD_TABLE_MAX_FILES = 3;
|
||||||
const CLAWD_TABLE_MAX_BYTES = 10 * 1024 * 1024;
|
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) {
|
function getClawdTableFileExtension(fileName: string) {
|
||||||
return String(fileName || "")
|
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) {
|
function formatClawdTableFileSize(bytes: number) {
|
||||||
if (!Number.isFinite(bytes) || bytes <= 0) {
|
if (!Number.isFinite(bytes) || bytes <= 0) {
|
||||||
return "0KB";
|
return "0KB";
|
||||||
@ -986,7 +1015,7 @@ function CanvasTypewriterText({
|
|||||||
return <div className={className}>{displayText}</div>;
|
return <div className={className}>{displayText}</div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
function CanvasAssistantTypingPlaceholder() {
|
function CanvasAssistantTypingPlaceholder({ hint }: { hint?: string | null }) {
|
||||||
return (
|
return (
|
||||||
<div className="flex w-full justify-start">
|
<div className="flex w-full justify-start">
|
||||||
<style>{`
|
<style>{`
|
||||||
@ -1001,20 +1030,27 @@ function CanvasAssistantTypingPlaceholder() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
`}</style>
|
`}</style>
|
||||||
<div
|
<div className="flex max-w-[min(78%,680px)] flex-col items-start gap-2">
|
||||||
aria-label="Clawd 正在处理"
|
{hint ? (
|
||||||
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"
|
<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}
|
||||||
{[0, 1, 2].map((index) => (
|
</div>
|
||||||
<span
|
) : null}
|
||||||
key={index}
|
<div
|
||||||
className="h-1.5 w-1.5 rounded-full bg-current"
|
aria-label="Clawd 正在处理"
|
||||||
style={{
|
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"
|
||||||
animation: "clawdTypingDotBounce 0.9s ease-in-out infinite",
|
>
|
||||||
animationDelay: `${index * 140}ms`,
|
{[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>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@ -1363,6 +1399,7 @@ export function CanvasChatPanel({
|
|||||||
const [detailGenerationMode, setDetailGenerationMode] = useState<DetailGenerationMode>("classic");
|
const [detailGenerationMode, setDetailGenerationMode] = useState<DetailGenerationMode>("classic");
|
||||||
const [isDetailGenerating, setIsDetailGenerating] = useState(false);
|
const [isDetailGenerating, setIsDetailGenerating] = useState(false);
|
||||||
const [isClawdSubmitting, setIsClawdSubmitting] = useState(false);
|
const [isClawdSubmitting, setIsClawdSubmitting] = useState(false);
|
||||||
|
const [clawdProcessingHint, setClawdProcessingHint] = useState<string | null>(null);
|
||||||
const [detailSections, setDetailSections] = useState<Record<DetailSectionKey, boolean>>({
|
const [detailSections, setDetailSections] = useState<Record<DetailSectionKey, boolean>>({
|
||||||
required: true,
|
required: true,
|
||||||
strategy: false,
|
strategy: false,
|
||||||
@ -8884,6 +8921,13 @@ export function CanvasChatPanel({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const nextProcessingHint = shouldShowClawdProcessingHint(
|
||||||
|
textContent,
|
||||||
|
hasTableFiles,
|
||||||
|
hasImageAttachments
|
||||||
|
)
|
||||||
|
? CLAWD_PROCESSING_HINT
|
||||||
|
: null;
|
||||||
const userMessageId = generateUUID();
|
const userMessageId = generateUUID();
|
||||||
const latestMessageTimestamp = messages.reduce(
|
const latestMessageTimestamp = messages.reduce(
|
||||||
(latest, message) => Math.max(latest, getMessageTimestamp(message) ?? 0),
|
(latest, message) => Math.max(latest, getMessageTimestamp(message) ?? 0),
|
||||||
@ -8905,6 +8949,7 @@ export function CanvasChatPanel({
|
|||||||
signature: sendSignature,
|
signature: sendSignature,
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
});
|
});
|
||||||
|
setClawdProcessingHint(nextProcessingHint);
|
||||||
setIsClawdSubmitting(true);
|
setIsClawdSubmitting(true);
|
||||||
setMessages((previousMessages) =>
|
setMessages((previousMessages) =>
|
||||||
sortCanvasMessagesByCreatedAt([
|
sortCanvasMessagesByCreatedAt([
|
||||||
@ -8998,6 +9043,7 @@ export function CanvasChatPanel({
|
|||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
setIsClawdSubmitting(false);
|
setIsClawdSubmitting(false);
|
||||||
|
setClawdProcessingHint(null);
|
||||||
releaseSendGuard(activeChatId);
|
releaseSendGuard(activeChatId);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@ -11351,7 +11397,7 @@ export function CanvasChatPanel({
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
{isClawdMode && isClawdSubmitting ? (
|
{isClawdMode && isClawdSubmitting ? (
|
||||||
<CanvasAssistantTypingPlaceholder />
|
<CanvasAssistantTypingPlaceholder hint={clawdProcessingHint} />
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
{isLoading && !shouldRenderImageLoading && (
|
{isLoading && !shouldRenderImageLoading && (
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user