Stable Diffusion: wait for API reconnect after switching to the image-prompt profile

8a47b3fdc48dc9404d14df231a7bfc71cd61f4a0

permissionBRICK <permissionBRICK@gmail.com>

1 files changed, +8 -3Ignore whitespace
public/scripts/extensions/stable-diffusion/index.js+8 -3
@@ -10,6 +10,7 @@ import {
1010 getCurrentChatId,
1111 getRequestHeaders,
1212 getUserAvatar,
13+ online_status,
1314 saveSettingsDebounced,
1415 substituteParams,
1516 substituteParamsExtended,
@@ -40,6 +41,7 @@ import {
4041 resetScrollHeight,
4142 saveBase64AsFile,
4243 stringFormat,
44+ waitUntilCondition,
4345} from '../../utils.js';
4446import { getMessageTimeStamp, humanizedDateTime } from '../../RossAscends-mods.js';
4547import { SECRET_KEYS, secret_state } from '../../secrets.js';
@@ -3723,12 +3725,15 @@ async function withConnectionProfile(targetProfileId, callback) {
37233725
37243726 const switchToProfile = async (profileId) => {
37253727 const loaded = new Promise(resolve => eventSource.once(event_types.CONNECTION_PROFILE_LOADED, resolve));
3726- const timeout = new Promise(resolve => setTimeout(resolve, 10000));
37273728 const index = Array.from(select.options).findIndex(o => o.value === profileId);
37283729 select.selectedIndex = index >= 0 ? index : 0;
37293730 select.dispatchEvent(new Event('change'));
37303731 // Don'tWait hangfor the imageprofile's generationcommands to finish applying (don't hang forever if the event never fires).
37313732 await Promise.race([loaded, timeoutdelay(10000)]);
3733+ // Applying a profile reconnects the API, which is asynchronous. Generating before the
3734+ // connection is re-established fails instantly, so wait for it to come back up
3735+ // (mirrors the built-in /profile command). rejectOnTimeout:false -> proceed anyway after the timeout.
3736+ await waitUntilCondition(() => online_status !== 'no_connection', 10000, 100, { rejectOnTimeout: false });
37323737 };
37333738
37343739 await switchToProfile(targetProfileId);