Stable Diffusion: never re-run reference image selection on swipe The reference image is selected once, together with the image prompt. Swipes reuse the prompt, so they now also always reuse the selection: if no stored selection exists (e.g. after a page reload), a swipe falls back to the first library image instead of asking the LLM again.

6d112755c32328608e0aa05943d069b69f5221e1

permissionBRICK <40219477+permissionBRICK@users.noreply.github.com>

1 files changed, +18 -0Ignore whitespace
public/scripts/extensions/stable-diffusion/index.js+18 -0
@@ -1145,6 +1145,13 @@ const REFERENCE_IMAGE_PLACEHOLDER = /"%reference[-_]image%"/i;
1145let pendingReferenceImage = null;1145let pendingReferenceImage = null;
11461146
1147/**1147/**
1148 * Whether the current generation may run an LLM reference-image selection.
1149 * Swipes reuse the prompt, so they must also reuse the reference selection
1150 * instead of asking the LLM again.
1151 */
1152let referenceSelectionAllowed = true;
1153
1154/**
1148 * Returns library entries that have an uploaded image.1155 * Returns library entries that have an uploaded image.
1149 * @returns {{tag: string, description: string, path: string}[]} Valid reference images.1156 * @returns {{tag: string, description: string, path: string}[]} Valid reference images.
1150 */1157 */
@@ -1414,6 +1421,13 @@ async function resolveReferenceImageForGeneration(prompt) {
1414 pendingReferenceImage = images[0];1421 pendingReferenceImage = images[0];
1415 return pendingReferenceImage;1422 return pendingReferenceImage;
1416 }1423 }
1424 if (!referenceSelectionAllowed) {
1425 // Swipe without a stored selection (e.g. after a page reload): don't ask
1426 // the LLM again, just fall back to the first library image.
1427 console.log('SD: swipe regeneration - reusing the reference image without a new LLM selection');
1428 pendingReferenceImage = images[0];
1429 return pendingReferenceImage;
1430 }
1417 try {1431 try {
1418 pendingReferenceImage = await selectReferenceImageWithLlm(prompt, images) ?? images[0];1432 pendingReferenceImage = await selectReferenceImageWithLlm(prompt, images) ?? images[0];
1419 } catch (error) {1433 } catch (error) {
@@ -4241,6 +4255,10 @@ async function sendGenerationRequest(generationType, prompt, additionalNegativeP
4241 const isCharChat = this_chid !== undefined && !selected_group;4255 const isCharChat = this_chid !== undefined && !selected_group;
4242 const ignoreNoCharForSwipe = initiator === initiators.swipe && isCharChat;4256 const ignoreNoCharForSwipe = initiator === initiators.swipe && isCharChat;
42434257
4258 // Swipes reuse the existing prompt, so the reference-image selection must be
4259 // reused as well - never re-run the LLM selection for a swipe.
4260 referenceSelectionAllowed = initiator !== initiators.swipe;
4261
4244 const skipCharPrefix = !ignoreNoCharForSwipe && noCharPrefix.includes(generationType);4262 const skipCharPrefix = !ignoreNoCharForSwipe && noCharPrefix.includes(generationType);
42454263
4246 /**4264 /**