diff --git a/src/components/chat/ChatMain.vue b/src/components/chat/ChatMain.vue index a8d0248..3c2bfba 100644 --- a/src/components/chat/ChatMain.vue +++ b/src/components/chat/ChatMain.vue @@ -181,6 +181,7 @@ async function handleSend( deepThinking?: boolean; systemPrompt?: string; skipUserMessage?: boolean; + conversationTitle?: string; }, ) { // 检查认证状态 @@ -221,7 +222,13 @@ async function handleSend( // 如果没有当前对话,创建新对话 if (!currentConversation.value) { - await chatStore.createConversation(); + await chatStore.createConversation(options?.conversationTitle || text); + } else if (currentConversation.value.title === "新对话") { + // 如果当前对话是"新对话",用传入的标题或用户输入重命名 + chatStore.renameConversation( + currentConversation.value.id, + options?.conversationTitle || text + ); } // 获取系统提示词(优先使用传入的,否则使用会话设置) @@ -488,7 +495,11 @@ function handleRegenerate(messageId: string) { } function handleSuggestion(suggestion: Suggestion) { - handleSend(suggestion.text, [], { systemPrompt: suggestion.systemPrompt, skipUserMessage: true }); + handleSend(suggestion.text, [], { + systemPrompt: suggestion.systemPrompt, + skipUserMessage: true, + conversationTitle: suggestion.text, + }); } function focusInput() { diff --git a/src/stores/chat.ts b/src/stores/chat.ts index 06efcf5..766fbae 100644 --- a/src/stores/chat.ts +++ b/src/stores/chat.ts @@ -79,10 +79,10 @@ export const useChatStore = defineStore("chat", () => { } // 创建对话 - async function createConversation(): Promise { + async function createConversation(title?: string): Promise { const newConversation: Conversation = { id: generateId(), - title: "新对话", + title: title || "新对话", messages: [], createdAt: Date.now(), updatedAt: Date.now(),