()
| 94 | const { updateChat, insertChatMessage } = useChatStore(); |
| 95 | |
| 96 | const handleSaveMessage = async () => { |
| 97 | await insertChatMessage({ |
| 98 | content: input, |
| 99 | createdAt: new Date(), |
| 100 | role: "user", |
| 101 | chatId: chat.id, |
| 102 | }); |
| 103 | |
| 104 | // If this is the first user message and the chat title is "New Chat", generate a title |
| 105 | if (messages.length === 0 && chat.title === "New Chat") { |
| 106 | try { |
| 107 | const generatedTitle = generateChatTitle(input); |
| 108 | await updateChat(chat.id, { |
| 109 | title: generatedTitle, |
| 110 | updatedAt: new Date(), |
| 111 | }); |
| 112 | } catch (error) { |
| 113 | console.error("Failed to generate chat title:", error); |
| 114 | } |
| 115 | } |
| 116 | }; |
| 117 | |
| 118 | const handleSubmitWithSave = async () => { |
| 119 | if (input.trim()) { |
no test coverage detected