diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index 7e69b4512..c0386447c 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -1391,19 +1391,28 @@ } }; + let processingQueueChats = new Set(); + const processNextInQueue = async (targetChatId: string) => { + if (processingQueueChats.has(targetChatId)) return; + const queue = $chatRequestQueues[targetChatId]; if (!queue || queue.length === 0) return; - const combinedPrompt = queue.map((m) => m.prompt).join('\n\n'); - const combinedFiles = queue.flatMap((m) => m.files); + processingQueueChats.add(targetChatId); + try { + const combinedPrompt = queue.map((m) => m.prompt).join('\n\n'); + const combinedFiles = queue.flatMap((m) => m.files); - chatRequestQueues.update((q) => { - const { [targetChatId]: _, ...rest } = q; - return rest; - }); + chatRequestQueues.update((q) => { + const { [targetChatId]: _, ...rest } = q; + return rest; + }); - await submitPrompt(combinedPrompt, combinedFiles); + await submitPrompt(combinedPrompt, combinedFiles); + } finally { + processingQueueChats.delete(targetChatId); + } }; const chatCompletedHandler = async (_chatId, modelId, responseMessageId, messages) => {