This commit is contained in:
Timothy Jaeryang Baek committed 2026-03-15 18:49:49 -05:00
1 parent 14d876c259
commit 486c004cbb
1 file changed
+23 -17
+23 -17
View File
@@ -1340,18 +1340,6 @@
} }
taskIds = null; taskIds = null;
// Process message queue - combine all queued messages and submit at once
if (messageQueue.length > 0) {
const combinedPrompt = messageQueue.map((m) => m.prompt).join('\n\n');
const combinedFiles = messageQueue.flatMap((m) => m.files);
messageQueue = [];
// Set the files and submit
files = combinedFiles;
await tick();
await submitPrompt(combinedPrompt);
}
}; };
const chatActionHandler = async (_chatId, actionId, modelId, responseMessageId, event = null) => { const chatActionHandler = async (_chatId, actionId, modelId, responseMessageId, event = null) => {
@@ -1693,12 +1681,26 @@
scrollToBottom(); scrollToBottom();
} }
await chatCompletedHandler( // Fire-and-forget: run chatCompletedHandler for background work
// (outlet filters, chat save, title gen, follow-ups, tags)
// without blocking the user from sending new messages.
chatCompletedHandler(
chatId, chatId,
message.model, message.model,
message.id, message.id,
createMessagesList(history, message.id) createMessagesList(history, message.id)
); );
// Process message queue immediately after main response finishes
if (messageQueue.length > 0) {
const combinedPrompt = messageQueue.map((m) => m.prompt).join('\n\n');
const combinedFiles = messageQueue.flatMap((m) => m.files);
messageQueue = [];
files = combinedFiles;
await tick();
await submitPrompt(combinedPrompt);
}
} }
console.log(data); console.log(data);
@@ -1755,8 +1757,12 @@
return; return;
} }
// Check if there are pending tasks (more reliable than lastMessage.done) // Check if the assistant is still generating the main response
if (taskIds !== null && taskIds.length > 0) { // (don't block on background tasks like title gen, follow-ups, tags)
const lastMessage = history.currentId ? history.messages[history.currentId] : null;
const isGenerating = lastMessage && lastMessage.role === 'assistant' && !lastMessage.done;
if (isGenerating) {
if ($settings?.enableMessageQueue ?? true) { if ($settings?.enableMessageQueue ?? true) {
// Queue the message // Queue the message
const _files = structuredClone(files); const _files = structuredClone(files);
@@ -1781,9 +1787,9 @@
} }
if (history?.currentId) { if (history?.currentId) {
const lastMessage = history.messages[history.currentId]; const currentMessage = history.messages[history.currentId];
if (lastMessage.error && !lastMessage.content) { if (currentMessage.error && !currentMessage.content) {
// Error in response // Error in response
toast.error($i18n.t(`Oops! There was an error in the previous response.`)); toast.error($i18n.t(`Oops! There was an error in the previous response.`));
return; return;