chore: 优化新建对话的逻辑

This commit is contained in:
Wenjie Zhang 2025-09-16 02:18:34 +08:00
parent d8e5612d19
commit 44c06f6935

View File

@ -534,9 +534,32 @@ const updateMessageInThread = (threadId, messageIndex, updatedMessage) => {
};
// ==================== CHAT ACTIONS ====================
//
const isFirstChatEmpty = () => {
if (threads.value.length === 0) return false;
const firstThread = threads.value[0];
const firstThreadMessages = threadMessages.value[firstThread.id] || [];
return firstThreadMessages.length === 0;
};
//
const switchToFirstChatIfEmpty = async () => {
if (threads.value.length > 0 && isFirstChatEmpty()) {
await selectChat(threads.value[0].id);
return true;
}
return false;
};
const createNewChat = async () => {
if (!AgentValidator.validateAgentId(currentAgentId.value, '创建对话') || isProcessing.value) return;
if (currentChatId.value && conversations.value.length === 0) return;
//
if (await switchToFirstChatIfEmpty()) return;
//
const currentThreadIndex = threads.value.findIndex(thread => thread.id === currentChatId.value);
if (currentChatId.value && conversations.value.length === 0 && currentThreadIndex === 0) return;
chatState.creatingNewChat = true;
try {