fix(design): preserve command outcome certainty
This commit is contained in:
@@ -3,6 +3,7 @@ import { Loader2, MessageSquareText, Send, Sparkles } from 'lucide-react';
|
||||
import { toast } from 'sonner';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
import { ImageWorkspaceApiError } from '@/lib/image-workspace';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { useImageWorkspaceStore } from '@/stores/image-workspace';
|
||||
import type { DesignWorkspace } from '../../../shared/image-workspace';
|
||||
@@ -14,6 +15,32 @@ const STARTER_MESSAGES = [
|
||||
'做一张社团活动海报',
|
||||
];
|
||||
|
||||
function chatFailureMessage(error: unknown): string {
|
||||
if (error instanceof ImageWorkspaceApiError) {
|
||||
if (error.commandOutcome === 'unknown') {
|
||||
return error.status === 401 || error.status === 403
|
||||
? '登录已过期,这条消息的结果还没确认;重新登录后请继续原操作'
|
||||
: '暂时没能确认这条消息的处理结果,内容还在输入框里';
|
||||
}
|
||||
const messages: Record<string, string> = {
|
||||
design_reasoner_invalid: 'AI 没有整理好这次想法,请再试一次',
|
||||
design_reasoner_unavailable: 'AI 现在有点忙,暂时没能整理这次想法,请稍后再试',
|
||||
design_agent_run_failed: 'AI 这次没有整理好,内容还在输入框里,请再试一次',
|
||||
design_agent_run_cancelled: '这次整理已停止,内容还在输入框里',
|
||||
design_revision_conflict: '设计内容刚刚更新了,请再发送一次',
|
||||
design_direction_revision_conflict: '设计内容刚刚更新了,请再发送一次',
|
||||
auth_required: '请先登录,再继续创作',
|
||||
auth_expired: '登录已过期,请重新登录后继续创作',
|
||||
};
|
||||
const message = messages[error.code.toLowerCase()];
|
||||
if (message) return message;
|
||||
if (error.commandOutcome === 'definitive_failure') {
|
||||
return 'AI 这次没有完成设计整理,内容还在输入框里,请再试一次';
|
||||
}
|
||||
}
|
||||
return '暂时没能确认这条消息的处理结果,内容还在输入框里';
|
||||
}
|
||||
|
||||
export function DesignConversationPane({ workspace }: { workspace: DesignWorkspace }) {
|
||||
const chatDraft = useImageWorkspaceStore((state) => state.chatDraft);
|
||||
const setChatDraft = useImageWorkspaceStore((state) => state.setChatDraft);
|
||||
@@ -43,8 +70,8 @@ export function DesignConversationPane({ workspace }: { workspace: DesignWorkspa
|
||||
|
||||
const submit = () => {
|
||||
if (!chatDraft.trim() || submittingChat) return;
|
||||
void sendChat().catch(() => {
|
||||
toast.error('消息没有发出去,请再试一次');
|
||||
void sendChat().catch((error) => {
|
||||
toast.error(chatFailureMessage(error));
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user