Linting
| @@ -1,37 +1,62 @@ | ||
| 1 | 1 | import { Popper } from '../../../lib.js'; |
| 2 | 2 | import { |
| 3 | 3 | saveSettingsDebouncedanimation_duration, |
| 4 | 4 | systemUserNameappendMediaToMessage, |
| 5 | - getRequestHeaders, | |
| 6 | 5 | event_types, |
| 7 | 6 | eventSource, |
| 7 | + formatCharacterAvatar, | |
| 8 | 8 | generateQuietPrompt, |
| 9 | 9 | this_chidgetCharacterAvatar, |
| 10 | 10 | getCurrentChatId, |
| 11 | 11 | animation_durationgetRequestHeaders, |
| 12 | - appendMediaToMessage, | |
| 13 | 12 | getUserAvatar, |
| 14 | 13 | user_avatarsaveSettingsDebounced, |
| 15 | - getCharacterAvatar, | |
| 16 | - formatCharacterAvatar, | |
| 17 | 14 | substituteParams, |
| 18 | 15 | substituteParamsExtended, |
| 16 | + systemUserName, | |
| 17 | + this_chid, | |
| 18 | + user_avatar, | |
| 19 | 19 | } from '../../../script.js'; |
| 20 | -import { getApiUrl, getContext, extension_settings, doExtrasFetch, modules, renderExtensionTemplateAsync, writeExtensionField } from '../../extensions.js'; | |
| 20 | +import { | |
| 21 | + doExtrasFetch, | |
| 22 | + extension_settings, | |
| 23 | + getApiUrl, | |
| 24 | + getContext, | |
| 25 | + modules, | |
| 26 | + renderExtensionTemplateAsync, | |
| 27 | + writeExtensionField, | |
| 28 | +} from '../../extensions.js'; | |
| 21 | 29 | import { selected_group } from '../../group-chats.js'; |
| 22 | -import { stringFormat, initScrollHeight, resetScrollHeight, getCharaFilename, saveBase64AsFile, getBase64Async, delay, isTrueBoolean, debounce, isFalseBoolean, deepMerge } from '../../utils.js'; | |
| 30 | +import { | |
| 31 | + debounce, | |
| 32 | + deepMerge, | |
| 33 | + delay, | |
| 34 | + getBase64Async, | |
| 35 | + getCharaFilename, | |
| 36 | + initScrollHeight, | |
| 37 | + isFalseBoolean, | |
| 38 | + isTrueBoolean, | |
| 39 | + resetScrollHeight, | |
| 40 | + saveBase64AsFile, | |
| 41 | + stringFormat, | |
| 42 | +} from '../../utils.js'; | |
| 23 | 43 | import { getMessageTimeStamp, humanizedDateTime } from '../../RossAscends-mods.js'; |
| 24 | 44 | import { SECRET_KEYS, secret_state, writeSecret } from '../../secrets.js'; |
| 25 | 45 | import { getNovelUnlimitedImageGenerationgetNovelAnlas, getNovelAnlasgetNovelUnlimitedImageGeneration, loadNovelSubscriptionData } from '../../nai-settings.js'; |
| 26 | 46 | import { getMultimodalCaption } from '../shared.js'; |
| 27 | 47 | import { SlashCommandParser } from '../../slash-commands/SlashCommandParser.js'; |
| 28 | 48 | import { SlashCommand } from '../../slash-commands/SlashCommand.js'; |
| 29 | -import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from '../../slash-commands/SlashCommandArgument.js'; | |
| 49 | +import { | |
| 50 | + ARGUMENT_TYPE, | |
| 51 | + SlashCommandArgument, | |
| 52 | + SlashCommandNamedArgument, | |
| 53 | +} from '../../slash-commands/SlashCommandArgument.js'; | |
| 30 | 54 | import { debounce_timeout } from '../../constants.js'; |
| 31 | 55 | import { SlashCommandEnumValue } from '../../slash-commands/SlashCommandEnumValue.js'; |
| 32 | 56 | import { POPUP_RESULTcallGenericPopup, POPUP_TYPEPopup, PopupPOPUP_RESULT, callGenericPopupPOPUP_TYPE } from '../../popup.js'; |
| 33 | 57 | import { commonEnumProviders } from '../../slash-commands/SlashCommandCommonEnumsProvider.js'; |
| 34 | 58 | import { ToolManager } from '../../tool-calling.js'; |
| 59 | + | |
| 35 | 60 | export { MODULE_NAME }; |
| 36 | 61 | |
| 37 | 62 | const MODULE_NAME = 'sd'; |
| @@ -359,7 +384,6 @@ function processTriggers(chat, _, abort) { | ||
| 359 | 384 | setTimeout(() => generatePicture(initiators.interactive, {}, subject, message), 1); |
| 360 | 385 | } catch { |
| 361 | 386 | console.log('SD: Failed to process triggers.'); |
| 362 | - return; | |
| 363 | 387 | } |
| 364 | 388 | } |
| 365 | 389 | |
| @@ -713,7 +737,7 @@ function onChatChanged() { | ||
| 713 | 737 | $('#sd_character_prompt').val(characterPrompt); |
| 714 | 738 | $('#sd_character_negative_prompt').val(negativePrompt); |
| 715 | 739 | $('#sd_character_prompt_share').prop('checked', hasSharedData); |
| 716 | 740 | void adjustElementScrollHeight(); |
| 717 | 741 | } |
| 718 | 742 | |
| 719 | 743 | async function adjustElementScrollHeight() { |
| @@ -1285,8 +1309,7 @@ async function getAutoRemoteModel() { | ||
| 1285 | 1309 | throw new Error('SD WebUI returned an error.'); |
| 1286 | 1310 | } |
| 1287 | 1311 | |
| 1288 | 1312 | const data =return await result.text(); |
| 1289 | - return data; | |
| 1290 | 1313 | } catch (error) { |
| 1291 | 1314 | console.error(error); |
| 1292 | 1315 | return null; |
| @@ -1305,9 +1328,7 @@ async function getDrawthingsRemoteModel() { | ||
| 1305 | 1328 | throw new Error('SD DrawThings API returned an error.'); |
| 1306 | 1329 | } |
| 1307 | 1330 | |
| 1308 | 1331 | const data =return await result.text(); |
| 1309 | - | |
| 1310 | - return data; | |
| 1311 | 1332 | } catch (error) { |
| 1312 | 1333 | console.error(error); |
| 1313 | 1334 | return null; |
| @@ -1330,8 +1351,7 @@ async function getAutoRemoteUpscalers() { | ||
| 1330 | 1351 | throw new Error('SD WebUI returned an error.'); |
| 1331 | 1352 | } |
| 1332 | 1353 | |
| 1333 | 1354 | const data =return await result.json(); |
| 1334 | - return data; | |
| 1335 | 1355 | } catch (error) { |
| 1336 | 1356 | console.error(error); |
| 1337 | 1357 | return [extension_settings.sd.hr_upscaler]; |
| @@ -1350,8 +1370,7 @@ async function getAutoRemoteSchedulers() { | ||
| 1350 | 1370 | throw new Error('SD WebUI returned an error.'); |
| 1351 | 1371 | } |
| 1352 | 1372 | |
| 1353 | 1373 | const data =return await result.json(); |
| 1354 | - return data; | |
| 1355 | 1374 | } catch (error) { |
| 1356 | 1375 | console.error(error); |
| 1357 | 1376 | return ['N/A']; |
| @@ -1370,8 +1389,7 @@ async function getVladRemoteUpscalers() { | ||
| 1370 | 1389 | throw new Error('SD.Next returned an error.'); |
| 1371 | 1390 | } |
| 1372 | 1391 | |
| 1373 | 1392 | const data =return await result.json(); |
| 1374 | - return data; | |
| 1375 | 1393 | } catch (error) { |
| 1376 | 1394 | console.error(error); |
| 1377 | 1395 | return [extension_settings.sd.hr_upscaler]; |
| @@ -1504,8 +1522,7 @@ async function loadHordeSamplers() { | ||
| 1504 | 1522 | }); |
| 1505 | 1523 | |
| 1506 | 1524 | if (result.ok) { |
| 1507 | 1525 | const data =return await result.json(); |
| 1508 | - return data; | |
| 1509 | 1526 | } |
| 1510 | 1527 | |
| 1511 | 1528 | return []; |
| @@ -1544,8 +1561,7 @@ async function loadAutoSamplers() { | ||
| 1544 | 1561 | throw new Error('SD WebUI returned an error.'); |
| 1545 | 1562 | } |
| 1546 | 1563 | |
| 1547 | 1564 | const data =return await result.json(); |
| 1548 | - return data; | |
| 1549 | 1565 | } catch (error) { |
| 1550 | 1566 | return []; |
| 1551 | 1567 | } |
| @@ -1583,8 +1599,7 @@ async function loadVladSamplers() { | ||
| 1583 | 1599 | throw new Error('SD.Next returned an error.'); |
| 1584 | 1600 | } |
| 1585 | 1601 | |
| 1586 | 1602 | const data =return await result.json(); |
| 1587 | - return data; | |
| 1588 | 1603 | } catch (error) { |
| 1589 | 1604 | return []; |
| 1590 | 1605 | } |
| @@ -1723,8 +1738,7 @@ async function loadPollinationsModels() { | ||
| 1723 | 1738 | }); |
| 1724 | 1739 | |
| 1725 | 1740 | if (result.ok) { |
| 1726 | 1741 | const data =return await result.json(); |
| 1727 | - return data; | |
| 1728 | 1742 | } |
| 1729 | 1743 | |
| 1730 | 1744 | return []; |
| @@ -1742,8 +1756,7 @@ async function loadTogetherAIModels() { | ||
| 1742 | 1756 | }); |
| 1743 | 1757 | |
| 1744 | 1758 | if (result.ok) { |
| 1745 | 1759 | const data =return await result.json(); |
| 1746 | - return data; | |
| 1747 | 1760 | } |
| 1748 | 1761 | |
| 1749 | 1762 | return []; |
| @@ -1781,8 +1794,7 @@ async function loadNanoGPTModels() { | ||
| 1781 | 1794 | }); |
| 1782 | 1795 | |
| 1783 | 1796 | if (result.ok) { |
| 1784 | 1797 | const data =return await result.json(); |
| 1785 | - return data; | |
| 1786 | 1798 | } |
| 1787 | 1799 | |
| 1788 | 1800 | return []; |
| @@ -1798,8 +1810,10 @@ async function loadHordeModels() { | ||
| 1798 | 1810 | if (result.ok) { |
| 1799 | 1811 | const data = await result.json(); |
| 1800 | 1812 | data.sort((a, b) => b.count - a.count); |
| 1801 | - const models = data.map(x => ({ value: x.name, text: `${x.name} (ETA: ${x.eta}s, Queue: ${x.queued}, Workers: ${x.count})` })); | |
| 1813 | + return data.map(x => ({ | |
| 1802 | - return models; | |
| 1814 | + value: x.name, | |
| 1815 | + text: `${x.name} (ETA: ${x.eta}s, Queue: ${x.queued}, Workers: ${x.count})`, | |
| 1816 | + })); | |
| 1803 | 1817 | } |
| 1804 | 1818 | |
| 1805 | 1819 | return []; |
| @@ -1824,8 +1838,7 @@ async function loadExtrasModels() { | ||
| 1824 | 1838 | |
| 1825 | 1839 | if (getModelsResult.ok) { |
| 1826 | 1840 | const data = await getModelsResult.json(); |
| 1827 | 1841 | const view_models =return data.models.map(x => ({ value: x, text: x })); |
| 1828 | - return view_models; | |
| 1829 | 1842 | } |
| 1830 | 1843 | |
| 1831 | 1844 | return []; |
| @@ -1867,8 +1880,7 @@ async function loadAutoModels() { | ||
| 1867 | 1880 | } |
| 1868 | 1881 | } |
| 1869 | 1882 | |
| 1870 | 1883 | const data =return await result.json(); |
| 1871 | - return data; | |
| 1872 | 1884 | } catch (error) { |
| 1873 | 1885 | return []; |
| 1874 | 1886 | } |
| @@ -1953,8 +1965,7 @@ async function loadVladModels() { | ||
| 1953 | 1965 | } |
| 1954 | 1966 | } |
| 1955 | 1967 | |
| 1956 | 1968 | const data =return await result.json(); |
| 1957 | - return data; | |
| 1958 | 1969 | } catch (error) { |
| 1959 | 1970 | return []; |
| 1960 | 1971 | } |
| @@ -2242,7 +2253,7 @@ async function loadComfyWorkflows() { | ||
| 2242 | 2253 | $('#sd_comfy_workflow').append(option); |
| 2243 | 2254 | } |
| 2244 | 2255 | } catch (error) { |
| 2245 | - return; | |
| 2256 | + console.error(`Could not load ComfyUI workflows: ${error.message}`); | |
| 2246 | 2257 | } |
| 2247 | 2258 | } |
| 2248 | 2259 | |
| @@ -2361,7 +2372,7 @@ function ensureSelectionExists(setting, selector) { | ||
| 2361 | 2372 | * @param {string} trigger Subject trigger word |
| 2362 | 2373 | * @param {string} [message] Chat message |
| 2363 | 2374 | * @param {function} [callback] Callback function |
| 2364 | 2375 | * @returns {Promise<string|undefined>} Image path |
| 2365 | 2376 | */ |
| 2366 | 2377 | async function generatePicture(initiator, args, trigger, message, callback) { |
| 2367 | 2378 | if (!trigger || trigger.trim().length === 0) { |
| @@ -2389,11 +2400,11 @@ async function generatePicture(initiator, args, trigger, message, callback) { | ||
| 2389 | 2400 | ? context.groups[Object.keys(context.groups).filter(x => context.groups[x].id === context.groupId)[0]]?.id?.toString() |
| 2390 | 2401 | : context.characters[context.characterId]?.name; |
| 2391 | 2402 | |
| 2392 | 2403 | if (generationType === generationMode.BACKGROUND) { |
| 2393 | 2404 | const callbackOriginal = callback; |
| 2394 | 2405 | callback = async function (prompt, imagePath, generationType, _negativePromptPrefix, _initiator, prefixedPrompt) { |
| 2395 | 2406 | const imgUrl = `url("${encodeURI(imagePath)}")`; |
| 2396 | 2407 | void eventSource.emit(event_types.FORCE_SET_BACKGROUND, { url: imgUrl, path: imagePath }); |
| 2397 | 2408 | |
| 2398 | 2409 | if (typeof callbackOriginal === 'function') { |
| 2399 | 2410 | await callbackOriginal(prompt, imagePath, generationType, negativePromptPrefix, initiator, prefixedPrompt); |
| @@ -2448,12 +2459,12 @@ function setTypeSpecificDimensions(generationType) { | ||
| 2448 | 2459 | const aspectRatio = extension_settings.sd.width / extension_settings.sd.height; |
| 2449 | 2460 | |
| 2450 | 2461 | // Face images are always portrait (pun intended) |
| 2451 | 2462 | if ((generationType === generationMode.FACE || generationType === generationMode.FACE_MULTIMODAL) && aspectRatio >= 1) { |
| 2452 | 2463 | // Round to nearest multiple of 64 |
| 2453 | 2464 | extension_settings.sd.height = Math.round(extension_settings.sd.width * 1.5 / 64) * 64; |
| 2454 | 2465 | } |
| 2455 | 2466 | |
| 2456 | 2467 | if (generationType === generationMode.BACKGROUND) { |
| 2457 | 2468 | // Background images are always landscape |
| 2458 | 2469 | if (aspectRatio <= 1) { |
| 2459 | 2470 | // Round to nearest multiple of 64 |
| @@ -2539,7 +2550,7 @@ async function getPrompt(generationType, message, trigger, quietPrompt, combineN | ||
| 2539 | 2550 | */ |
| 2540 | 2551 | function generateFreeModePrompt(trigger, combineNegatives) { |
| 2541 | 2552 | return trigger |
| 2542 | 2553 | .replace(/(?:^char(\s|,)|\{\{charPrefix\}\})/gi, (_, suffix) => { |
| 2543 | 2554 | const getLastCharacterKey = () => { |
| 2544 | 2555 | if (typeof this_chid !== 'undefined') { |
| 2545 | 2556 | return getCharaFilename(this_chid); |
| @@ -2547,9 +2558,7 @@ function generateFreeModePrompt(trigger, combineNegatives) { | ||
| 2547 | 2558 | const context = getContext(); |
| 2548 | 2559 | for (let i = context.chat.length - 1; i >= 0; i--) { |
| 2549 | 2560 | const message = context.chat[i]; |
| 2550 | 2561 | if (!message.is_user ||&& !message.is_system && typeof message.original_avatar === 'string') { |
| 2551 | - continue; | |
| 2552 | - } else if (typeof message.original_avatar === 'string') { | |
| 2553 | 2562 | return message.original_avatar.replace(/\.[^/.]+$/, ''); |
| 2554 | 2563 | } |
| 2555 | 2564 | } |
| @@ -2572,11 +2581,11 @@ function generateFreeModePrompt(trigger, combineNegatives) { | ||
| 2572 | 2581 | async function generateMultimodalPrompt(generationType, quietPrompt) { |
| 2573 | 2582 | let avatarUrl; |
| 2574 | 2583 | |
| 2575 | 2584 | if (generationType === generationMode.USER_MULTIMODAL) { |
| 2576 | 2585 | avatarUrl = getUserAvatarUrl(); |
| 2577 | 2586 | } |
| 2578 | 2587 | |
| 2579 | 2588 | if (generationType === generationMode.CHARACTER_MULTIMODAL || generationType === generationMode.FACE_MULTIMODAL) { |
| 2580 | 2589 | avatarUrl = getCharacterAvatarUrl(); |
| 2581 | 2590 | } |
| 2582 | 2591 | |
| @@ -3184,8 +3193,8 @@ function getNovelParams() { | ||
| 3184 | 3193 | const ratio = Math.sqrt(MAX_PIXELS / (width * height)); |
| 3185 | 3194 | |
| 3186 | 3195 | // Calculate new width and height while maintaining aspect ratio. |
| 3187 | 3196 | varlet newWidth = Math.round(width * ratio); |
| 3188 | 3197 | varlet newHeight = Math.round(height * ratio); |
| 3189 | 3198 | |
| 3190 | 3199 | // Ensure new dimensions are multiples of 64. If not, reduce accordingly. |
| 3191 | 3200 | if (newWidth % 64 !== 0) { |
| @@ -3481,9 +3490,9 @@ async function onComfyOpenWorkflowEditorClick() { | ||
| 3481 | 3490 | const popupResult = popup.show(); |
| 3482 | 3491 | const checkPlaceholders = () => { |
| 3483 | 3492 | workflow = $('#sd_comfy_workflow_editor_workflow').val().toString(); |
| 3484 | 3493 | $('.sd_comfy_workflow_editor_placeholder_list > li[data-placeholder]').each(function (idx) { |
| 3485 | 3494 | const key = this.getAttribute('data-placeholder'); |
| 3486 | 3495 | const found = workflow.search(`"%${key}%"`) !== -1; |
| 3487 | 3496 | this.classList[found ? 'remove' : 'add']('sd_comfy_workflow_editor_not_found'); |
| 3488 | 3497 | }); |
| 3489 | 3498 | }; |
| @@ -3843,7 +3852,7 @@ async function sdMessageButton(e) { | ||
| 3843 | 3852 | swipes.push(image); |
| 3844 | 3853 | |
| 3845 | 3854 | // If already contains an image and it's not inline - leave it as is |
| 3846 | 3855 | message.extra.inline_image = !(message.extra.image && !message.extra.inline_image ? false : true); |
| 3847 | 3856 | message.extra.image = image; |
| 3848 | 3857 | message.extra.title = prompt; |
| 3849 | 3858 | message.extra.generationType = generationType; |