Improve chat title generation or smth
CI / check (22) (push) Failing after 4m50s
CI / check (24) (push) Failing after 4m51s

This commit is contained in:
2026-10-13 23:40:29 +02:00
parent 42e71fb502
commit b8b06a8a33
4 changed files with 81 additions and 12 deletions
+15 -6
View File
@@ -2,7 +2,6 @@
import * as defaultApi from "./api.js";
import {updateReasoning, finishReasoning} from "./reasoning.js";
import {createStreamRenderer} from "./streamRenderer.js";
import {titleFromFirstMessage} from "./chatTitle.js";
export function createComposerController({
state, elements, attachmentComposer, webSearchButton, reasoningToggle, webSearchToggle,
@@ -101,12 +100,9 @@ export function createComposerController({
}
const currentChat = getChatById(chatId);
if (currentChat && !currentChat.assistant_persona_id && currentChat.title === "New chat") {
const title = titleFromFirstMessage(message);
const renamed = await api.put(`/chats/${chatId}`, {title}, {signal});
const renamed = await api.put(`/chats/${chatId}`, {title: currentChat.title}, {signal});
signal.throwIfAborted();
if (renamed.error) throw new Error(renamed.error);
currentChat.title = title;
updateWorkspaceCopy(); renderChatList();
}
signal.throwIfAborted();
if (visible()) {
@@ -149,11 +145,24 @@ export function createComposerController({
: searchState === "no_relevant_results" ? "No sufficiently relevant results. Generating response..."
: sourceCount === 0 ? "No web results found. Generating response..." : "Generating response...";
},
onDone: ({reply, sources}) => { completedReply = reply; completedSources = sources; }
onDone: ({reply, sources, chatTitle}) => {
completedReply = reply; completedSources = sources;
if (chatTitle && currentChat) {
currentChat.title = chatTitle;
updateWorkspaceCopy(); renderChatList();
}
}
}, {signal});
rendering.flush();
rendering.dispose();
const updatedChat = getChatById(chatId);
if (api === defaultApi && currentChat && !currentChat.assistant_persona_id && currentChat.title === "New chat") {
const titled = await api.post(`/chats/${chatId}/title`, {message, model}, {signal});
if (!signal.aborted && titled.title) {
currentChat.title = titled.title;
updateWorkspaceCopy(); renderChatList();
}
}
if (updatedChat && completedReply !== null) {
updatedChat.last_message_preview = completedReply.slice(0, 180);
updatedChat.updated_at = new Date().toISOString();