From ba19940828e10f171fa5300441aab94b074802de Mon Sep 17 00:00:00 2001 From: ciaranbor <81697641+ciaranbor@users.noreply.github.com> Date: Fri, 23 Jan 2026 16:33:01 +0000 Subject: [PATCH] Fix regenerate for image models (#1263) ## Motivation The 'regenerate' button was hardcoded to chat completion. Clicking 'regenerate' for image request would result in an error after the model is loaded ## Changes Store request type and dispatch to appropriate request upon regeneration ## Why It Works We make sure to repeat the same request type as was performed originally ## Test Plan ### Manual Testing Checked 'regenerate' works for chat completion, image generation, image editing --- dashboard/src/lib/stores/app.svelte.ts | 47 ++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/dashboard/src/lib/stores/app.svelte.ts b/dashboard/src/lib/stores/app.svelte.ts index ebfe0cb8..1b1a3847 100644 --- a/dashboard/src/lib/stores/app.svelte.ts +++ b/dashboard/src/lib/stores/app.svelte.ts @@ -216,6 +216,8 @@ export interface Message { attachments?: MessageAttachment[]; ttftMs?: number; // Time to first token in ms (for assistant messages) tps?: number; // Tokens per second (for assistant messages) + requestType?: "chat" | "image-generation" | "image-editing"; + sourceImageDataUrl?: string; // For image editing regeneration } export interface Conversation { @@ -1270,10 +1272,46 @@ class AppStore { if (lastUserIndex === -1) return; - // Remove any messages after the user message - this.messages = this.messages.slice(0, lastUserIndex + 1); + const lastUserMessage = this.messages[lastUserIndex]; + const requestType = lastUserMessage.requestType || "chat"; + const prompt = lastUserMessage.content; - // Resend the message to get a new response + // Remove messages after user message (including the user message for image requests + // since generateImage/editImage will re-add it) + this.messages = this.messages.slice(0, lastUserIndex); + + switch (requestType) { + case "image-generation": + await this.generateImage(prompt); + break; + case "image-editing": + if (lastUserMessage.sourceImageDataUrl) { + await this.editImage(prompt, lastUserMessage.sourceImageDataUrl); + } else { + // Can't regenerate edit without source image - restore user message and show error + this.messages.push(lastUserMessage); + const errorMessage = this.addMessage("assistant", ""); + const idx = this.messages.findIndex((m) => m.id === errorMessage.id); + if (idx !== -1) { + this.messages[idx].content = + "Error: Cannot regenerate image edit - source image not found"; + } + this.updateActiveConversation(); + } + break; + case "chat": + default: + // Restore the user message for chat regeneration + this.messages.push(lastUserMessage); + await this.regenerateChatCompletion(); + break; + } + } + + /** + * Helper method to regenerate a chat completion response + */ + private async regenerateChatCompletion(): Promise { this.isLoading = true; this.currentResponse = ""; @@ -1788,6 +1826,7 @@ class AppStore { role: "user", content: prompt, timestamp: Date.now(), + requestType: "image-generation", }; this.messages.push(userMessage); @@ -1998,6 +2037,8 @@ class AppStore { role: "user", content: prompt, timestamp: Date.now(), + requestType: "image-editing", + sourceImageDataUrl: imageDataUrl, }; this.messages.push(userMessage);