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 {
10 getCurrentChatId,10 getCurrentChatId,
11 getRequestHeaders,11 getRequestHeaders,
12 getUserAvatar,12 getUserAvatar,
13 online_status,
13 saveSettingsDebounced,14 saveSettingsDebounced,
14 substituteParams,15 substituteParams,
15 substituteParamsExtended,16 substituteParamsExtended,
@@ -40,6 +41,7 @@ import {
40 resetScrollHeight,41 resetScrollHeight,
41 saveBase64AsFile,42 saveBase64AsFile,
42 stringFormat,43 stringFormat,
44 waitUntilCondition,
43} from '../../utils.js';45} from '../../utils.js';
44import { getMessageTimeStamp, humanizedDateTime } from '../../RossAscends-mods.js';46import { getMessageTimeStamp, humanizedDateTime } from '../../RossAscends-mods.js';
45import { SECRET_KEYS, secret_state } from '../../secrets.js';47import { SECRET_KEYS, secret_state } from '../../secrets.js';
@@ -3723,12 +3725,15 @@ async function withConnectionProfile(targetProfileId, callback) {
37233725
3724 const switchToProfile = async (profileId) => {3726 const switchToProfile = async (profileId) => {
3725 const loaded = new Promise(resolve => eventSource.once(event_types.CONNECTION_PROFILE_LOADED, resolve));3727 const loaded = new Promise(resolve => eventSource.once(event_types.CONNECTION_PROFILE_LOADED, resolve));
3726 const timeout = new Promise(resolve => setTimeout(resolve, 10000));
3727 const index = Array.from(select.options).findIndex(o => o.value === profileId);3728 const index = Array.from(select.options).findIndex(o => o.value === profileId);
3728 select.selectedIndex = index >= 0 ? index : 0;3729 select.selectedIndex = index >= 0 ? index : 0;
3729 select.dispatchEvent(new Event('change'));3730 select.dispatchEvent(new Event('change'));
3730 // Don't hang the image generation if the event never fires.3731 // Wait for the profile's commands to finish applying (don't hang forever if the event never fires).
3731 await Promise.race([loaded, timeout]);3732 await Promise.race([loaded, delay(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 });
3732 };3737 };
37333738
3734 await switchToProfile(targetProfileId);3739 await switchToProfile(targetProfileId);