Merge branch 'staging' into whitelist-hosts
| @@ -4153,7 +4153,7 @@ | ||
| 4153 | 4153 | </div> |
| 4154 | 4154 | <div id="UI-language-block" class="flex-container alignItemsBaseline"> |
| 4155 | 4155 | <span data-i18n="UI Language">Language:</span> |
| 4156 | 4156 | <select id="ui_language_select" class="flex1 margin0 text_pole"> |
| 4157 | 4157 | <option value="" data-i18n="Default">Default</option> |
| 4158 | 4158 | <option value="en">English</option> |
| 4159 | 4159 | </select> |
| @@ -5388,17 +5388,17 @@ | ||
| 5388 | 5388 | </div> |
| 5389 | 5389 | </div> |
| 5390 | 5390 | <div id="GroupFavDelOkBack" class="flex-container flexGap5 spaceEvenly flex1"> |
| 5391 | 5391 | <div id="rm_button_back_from_group" class="heightFitContent margin0 menu_button fa-solid fa-fw fa-left-long"></div> |
| 5392 | 5392 | <div id="rm_group_scenario" class="heightFitContent margin0 menu_button fa-solid fa-fw fa-scroll" title="Set a group chat scenario" data-i18n="[title]Set a group chat scenario"></div> |
| 5393 | 5393 | <div id="group_favorite_button" class="heightFitContent margin0 menu_button fa-solid fa-fw fa-star" title="Add to Favorites" data-i18n="[title]Add to Favorites"></div> |
| 5394 | 5394 | <input id="rm_group_fav" type="hidden" /> |
| 5395 | 5395 | <div id="group_open_media_overrides" class="heightFitContent margin0 menu_button menu_button_icon open_media_overrides" title="Click to allow/forbid the use of external media for this group." data-i18n="[title]Click to allow/forbid the use of external media for this group."> |
| 5396 | 5396 | <i id="group_media_allowed_icon" class="fa-solid fa-fw fa-link"></i> |
| 5397 | 5397 | <i id="group_media_forbidden_icon" class="fa-solid fa-fw fa-link-slash"></i> |
| 5398 | 5398 | </div> |
| 5399 | 5399 | <div id="rm_group_submit" class="heightFitContent margin0 menu_button fa-solid fa-fw fa-check" title="Create" data-i18n="[title]Create"></div> |
| 5400 | 5400 | <div id="rm_group_restore_avatar" class="heightFitContent margin0 menu_button fa-solid fa-fw fa-images" title="Restore collage avatar" data-i18n="[title]Restore collage avatar"></div> |
| 5401 | 5401 | <div id="rm_group_delete" class="heightFitContent margin0 menu_button fa-solid fa-fw fa-trash-can" title="Delete" data-i18n="[title]Delete"></div> |
| 5402 | 5402 | <div class="flex1"> |
| 5403 | 5403 | <label class="checkbox_label whitespacenowrap"> |
| 5404 | 5404 | <input id="rm_group_allow_self_responses" type="checkbox" /> |
| @@ -553,6 +553,10 @@ let generatedPromptCache = ''; | ||
| 553 | 553 | let generation_started = new Date(); |
| 554 | 554 | /** @type {import('./scripts/char-data.js').v1CharData[]} */ |
| 555 | 555 | export let characters = []; |
| 556 | +/** | |
| 557 | + * Stringified index of a currently chosen entity in the characters array. | |
| 558 | + * @type {string|undefined} Yes, we hate it as much as you do. | |
| 559 | + */ | |
| 556 | 560 | export let this_chid; |
| 557 | 561 | let saveCharactersPage = 0; |
| 558 | 562 | export const default_avatar = 'img/ai4.png'; |
| @@ -1378,7 +1382,7 @@ export async function selectCharacterById(id) { | ||
| 1378 | 1382 | return; |
| 1379 | 1383 | } |
| 1380 | 1384 | |
| 1381 | 1385 | if (selected_group || String(this_chid) !== String(id)) { |
| 1382 | 1386 | //if clicked on a different character from what was currently selected |
| 1383 | 1387 | if (!is_send_press) { |
| 1384 | 1388 | await clearChat(); |
| @@ -1386,7 +1390,7 @@ export async function selectCharacterById(id) { | ||
| 1386 | 1390 | resetSelectedGroup(); |
| 1387 | 1391 | this_edit_mes_id = undefined; |
| 1388 | 1392 | selected_button = 'character_edit'; |
| 1389 | - this_chid = id; | |
| 1393 | + setCharacterId(id); | |
| 1390 | 1394 | chat.length = 0; |
| 1391 | 1395 | chat_metadata = {}; |
| 1392 | 1396 | await getChat(); |
| @@ -5309,7 +5313,7 @@ function addChatsSeparator(mesSendString) { | ||
| 5309 | 5313 | } |
| 5310 | 5314 | |
| 5311 | 5315 | async function duplicateCharacter() { |
| 5312 | 5316 | if (this_chid === undefined || !characters[this_chid]) { |
| 5313 | 5317 | toastr.warning(t`You must first select a character to duplicate!`); |
| 5314 | 5318 | return ''; |
| 5315 | 5319 | } |
| @@ -6210,7 +6214,7 @@ export function resetChatState() { | ||
| 6210 | 6214 | // replaces deleted charcter name with system user since it will be displayed next. |
| 6211 | 6215 | name2 = (this_chid === undefined && neutralCharacterName) ? neutralCharacterName : systemUserName; |
| 6212 | 6216 | //unsets expected chid before reloading (related to getCharacters/printCharacters from using old arrays) |
| 6213 | - this_chid = undefined; | |
| 6217 | + setCharacterId(undefined); | |
| 6214 | 6218 | // sets up system user to tell user about having deleted a character |
| 6215 | 6219 | chat.splice(0, chat.length, ...SAFETY_CHAT); |
| 6216 | 6220 | // resets chat metadata |
| @@ -6233,8 +6237,29 @@ export function setExternalAbortController(controller) { | ||
| 6233 | 6237 | abortController = controller; |
| 6234 | 6238 | } |
| 6235 | 6239 | |
| 6240 | +/** | |
| 6241 | + * Sets a character array index. | |
| 6242 | + * @param {number|string|undefined} value | |
| 6243 | + */ | |
| 6236 | 6244 | export function setCharacterId(value) { |
| 6237 | - this_chid = value; | |
| 6245 | + switch (typeof value) { | |
| 6246 | + case 'bigint': | |
| 6247 | + case 'number': | |
| 6248 | + this_chid = String(value); | |
| 6249 | + break; | |
| 6250 | + case 'string': | |
| 6251 | + this_chid = !isNaN(parseInt(value)) ? value : undefined; | |
| 6252 | + break; | |
| 6253 | + case 'object': | |
| 6254 | + this_chid = characters.indexOf(value) !== -1 ? String(characters.indexOf(value)) : undefined; | |
| 6255 | + break; | |
| 6256 | + case 'undefined': | |
| 6257 | + this_chid = undefined; | |
| 6258 | + break; | |
| 6259 | + default: | |
| 6260 | + console.error('Invalid character ID type:', value); | |
| 6261 | + break; | |
| 6262 | + } | |
| 6238 | 6263 | } |
| 6239 | 6264 | |
| 6240 | 6265 | export function setCharacterName(value) { |
| @@ -6350,13 +6375,13 @@ export async function renameCharacter(name = null, { silent = false, renameChats | ||
| 6350 | 6375 | |
| 6351 | 6376 | if (newChId !== -1) { |
| 6352 | 6377 | // Select the character after the renaming |
| 6353 | - this_chid = -1; | |
| 6378 | + setCharacterId(undefined); | |
| 6354 | 6379 | await selectCharacterById(newChId); |
| 6355 | 6380 | |
| 6356 | 6381 | // Async delay to update UI |
| 6357 | 6382 | await delay(1); |
| 6358 | 6383 | |
| 6359 | 6384 | if (this_chid === -1undefined) { |
| 6360 | 6385 | throw new Error('New character not selected'); |
| 6361 | 6386 | } |
| 6362 | 6387 | |
| @@ -7658,7 +7683,7 @@ export function select_rm_info(type, charId, previousCharId = null) { | ||
| 7658 | 7683 | if (previousCharId) { |
| 7659 | 7684 | const newId = characters.findIndex((x) => x.avatar == previousCharId); |
| 7660 | 7685 | if (newId >= 0) { |
| 7661 | - this_chid = newId; | |
| 7686 | + setCharacterId(newId); | |
| 7662 | 7687 | } |
| 7663 | 7688 | } |
| 7664 | 7689 | } |
| @@ -7678,6 +7703,7 @@ export function select_selected_character(chid) { | ||
| 7678 | 7703 | $('#create_button').attr('value', 'Save'); // what is the use case for this? |
| 7679 | 7704 | $('#dupe_button').show(); |
| 7680 | 7705 | $('#create_button_label').css('display', 'none'); |
| 7706 | + $('#char_connections_button').show(); | |
| 7681 | 7707 | |
| 7682 | 7708 | // Hide the chat scenario button if we're peeking the group member defs |
| 7683 | 7709 | $('#set_chat_scenario').toggle(!selected_group); |
| @@ -7762,6 +7788,7 @@ function select_rm_create() { | ||
| 7762 | 7788 | $('#create_button_label').css('display', ''); |
| 7763 | 7789 | $('#create_button').attr('value', 'Create'); |
| 7764 | 7790 | $('#dupe_button').hide(); |
| 7791 | + $('#char_connections_button').hide(); | |
| 7765 | 7792 | |
| 7766 | 7793 | //create text poles |
| 7767 | 7794 | $('#rm_button_back').css('display', ''); |
| @@ -7791,8 +7818,8 @@ function select_rm_create() { | ||
| 7791 | 7818 | $('#renameCharButton').css('display', 'none'); |
| 7792 | 7819 | $('#name_div').removeClass('displayNone'); |
| 7793 | 7820 | $('#name_div').addClass('displayBlock'); |
| 7794 | 7821 | $('.open_alternate_greetings').data('chid', undefined-1); |
| 7795 | 7822 | $('#set_character_world').data('chid', undefined-1); |
| 7796 | 7823 | setWorldInfoButtonClass(undefined, !!create_save.world); |
| 7797 | 7824 | updateFavButtonState(false); |
| 7798 | 7825 | checkEmbeddedWorld(); |
| @@ -7883,7 +7910,7 @@ function updateFavButtonState(state) { | ||
| 7883 | 7910 | } |
| 7884 | 7911 | |
| 7885 | 7912 | export async function setScenarioOverride() { |
| 7886 | 7913 | if (!selected_group && (this_chid === undefined || !characters[this_chid])) { |
| 7887 | 7914 | console.warn('setScenarioOverride() -- no selected group or character'); |
| 7888 | 7915 | return; |
| 7889 | 7916 | } |
| @@ -8248,7 +8275,7 @@ function updateAlternateGreetingsHintVisibility(root) { | ||
| 8248 | 8275 | function openCharacterWorldPopup() { |
| 8249 | 8276 | const chid = $('#set_character_world').data('chid'); |
| 8250 | 8277 | |
| 8251 | 8278 | if (menu_type != 'create' && chid === undefined) { |
| 8252 | 8279 | toastr.error('Does not have an Id for this character in world select menu.'); |
| 8253 | 8280 | return; |
| 8254 | 8281 | } |
| @@ -8380,7 +8407,7 @@ function openAlternateGreetings() { | ||
| 8380 | 8407 | return; |
| 8381 | 8408 | } else { |
| 8382 | 8409 | // If the character does not have alternate greetings, create an empty array |
| 8383 | 8410 | if (characters[chid] && !Array.isArray(characters[chid].data.alternate_greetings) == false) { |
| 8384 | 8411 | characters[chid].data.alternate_greetings = []; |
| 8385 | 8412 | } |
| 8386 | 8413 | } |
| @@ -8567,7 +8594,7 @@ async function createOrEditCharacter(e) { | ||
| 8567 | 8594 | |
| 8568 | 8595 | formData.delete('alternate_greetings'); |
| 8569 | 8596 | const chid = $('.open_alternate_greetings').data('chid'); |
| 8570 | 8597 | if (characters[chid] && Array.isArray(characters[chid]?.data?.alternate_greetings)) { |
| 8571 | 8598 | for (const value of characters[chid].data.alternate_greetings) { |
| 8572 | 8599 | formData.append('alternate_greetings', value); |
| 8573 | 8600 | } |
| @@ -10283,7 +10310,7 @@ jQuery(async function () { | ||
| 10283 | 10310 | $('#form_create').submit(createOrEditCharacter); |
| 10284 | 10311 | |
| 10285 | 10312 | $('#delete_button').on('click', async function () { |
| 10286 | 10313 | if (this_chid === undefined || !characters[this_chid]) { |
| 10287 | 10314 | toastr.warning('No character selected.'); |
| 10288 | 10315 | return; |
| 10289 | 10316 | } |
| @@ -395,7 +395,7 @@ class BulkEditOverlay { | ||
| 395 | 395 | |
| 396 | 396 | /** |
| 397 | 397 | * @typedef {object} LastSelected - An object noting the last selected character and its state. |
| 398 | 398 | * @property {stringnumber} [characterId] - The character id of the last selected character. |
| 399 | 399 | * @property {boolean} [select] - The selected state of the last selected character. <c>true</c> if it was selected, <c>false</c> if it was deselected. |
| 400 | 400 | */ |
| 401 | 401 | |
| @@ -675,7 +675,7 @@ class BulkEditOverlay { | ||
| 675 | 675 | const characterId = Number(currentCharacter.getAttribute('data-chid')); |
| 676 | 676 | const select = !this.selectedCharacters.includes(characterId); |
| 677 | 677 | |
| 678 | 678 | if (this.lastSelected.characterId >= 0 && this.lastSelected.select !== undefined) { |
| 679 | 679 | // Only if select state and the last select state match we execute the range select |
| 680 | 680 | if (select === this.lastSelected.select) { |
| 681 | 681 | this.toggleCharactersInRange(currentCharacter, select); |
| @@ -299,7 +299,7 @@ function loadSettings() { | ||
| 299 | 299 | $('#extension_floating_role').val(chat_metadata[metadata_keys.role]); |
| 300 | 300 | $(`input[name="extension_floating_position"][value="${chat_metadata[metadata_keys.position]}"]`).prop('checked', true); |
| 301 | 301 | |
| 302 | 302 | if (extension_settings.note.chara && getContext().characterId !== undefined) { |
| 303 | 303 | const charaNote = extension_settings.note.chara.find((e) => e.name === getCharaFilename()); |
| 304 | 304 | |
| 305 | 305 | $('#extension_floating_chara').val(charaNote ? charaNote.prompt : ''); |
| @@ -389,49 +389,49 @@ export function setFloatingPrompt() { | ||
| 389 | 389 | } |
| 390 | 390 | |
| 391 | 391 | function onANMenuItemClick() { |
| 392 | 392 | if (!selected_group ||&& this_chid === undefined) { |
| 393 | - //show AN if it's hidden | |
| 393 | + toastr.warning(t`Select a character before trying to use Author's Note`, '', { timeOut: 2000 }); | |
| 394 | - if ($('#floatingPrompt').css('display') !== 'flex') { | |
| 394 | + return; | |
| 395 | - $('#floatingPrompt').addClass('resizing'); | |
| 395 | + } | |
| 396 | - $('#floatingPrompt').css('display', 'flex'); | |
| 396 | + | |
| 397 | - $('#floatingPrompt').css('opacity', 0.0); | |
| 397 | + //show AN if it's hidden | |
| 398 | - $('#floatingPrompt').transition({ | |
| 398 | + if ($('#floatingPrompt').css('display') !== 'flex') { | |
| 399 | - opacity: 1.0, | |
| 399 | + $('#floatingPrompt').addClass('resizing'); | |
| 400 | - duration: animation_duration, | |
| 400 | + $('#floatingPrompt').css('display', 'flex'); | |
| 401 | - }, async function () { | |
| 401 | + $('#floatingPrompt').css('opacity', 0.0); | |
| 402 | - await delay(50); | |
| 402 | + $('#floatingPrompt').transition({ | |
| 403 | - $('#floatingPrompt').removeClass('resizing'); | |
| 403 | + opacity: 1.0, | |
| 404 | - }); | |
| 404 | + duration: animation_duration, | |
| 405 | - | |
| 405 | + }, async function () { | |
| 406 | - //auto-open the main AN inline drawer | |
| 406 | + await delay(50); | |
| 407 | 407 | if ($('#ANBlockTogglefloatingPrompt').removeClass('resizing'); |
| 408 | - .siblings('.inline-drawer-content') | |
| 408 | + }); | |
| 409 | - .css('display') !== 'block') { | |
| 410 | - $('#floatingPrompt').addClass('resizing'); | |
| 411 | - $('#ANBlockToggle').click(); | |
| 412 | - } | |
| 413 | - } else { | |
| 414 | - //hide AN if it's already displayed | |
| 415 | - $('#floatingPrompt').addClass('resizing'); | |
| 416 | - $('#floatingPrompt').transition({ | |
| 417 | - opacity: 0.0, | |
| 418 | - duration: animation_duration, | |
| 419 | - }, | |
| 420 | - async function () { | |
| 421 | - await delay(50); | |
| 422 | - $('#floatingPrompt').removeClass('resizing'); | |
| 423 | - }); | |
| 424 | - setTimeout(function () { | |
| 425 | - $('#floatingPrompt').hide(); | |
| 426 | - }, animation_duration); | |
| 427 | 409 | |
| 410 | + //auto-open the main AN inline drawer | |
| 411 | + if ($('#ANBlockToggle') | |
| 412 | + .siblings('.inline-drawer-content') | |
| 413 | + .css('display') !== 'block') { | |
| 414 | + $('#floatingPrompt').addClass('resizing'); | |
| 415 | + $('#ANBlockToggle').click(); | |
| 428 | 416 | } |
| 429 | - //duplicate options menu close handler from script.js | |
| 430 | - //because this listener takes priority | |
| 431 | - $('#options').stop().fadeOut(animation_duration); | |
| 432 | 417 | } else { |
| 433 | - toastr.warning(t`Select a character before trying to use Author's Note`, '', { timeOut: 2000 }); | |
| 418 | + //hide AN if it's already displayed | |
| 419 | + $('#floatingPrompt').addClass('resizing'); | |
| 420 | + $('#floatingPrompt').transition({ | |
| 421 | + opacity: 0.0, | |
| 422 | + duration: animation_duration, | |
| 423 | + }, async function () { | |
| 424 | + await delay(50); | |
| 425 | + $('#floatingPrompt').removeClass('resizing'); | |
| 426 | + }); | |
| 427 | + setTimeout(function () { | |
| 428 | + $('#floatingPrompt').hide(); | |
| 429 | + }, animation_duration); | |
| 434 | 430 | } |
| 431 | + | |
| 432 | + //duplicate options menu close handler from script.js | |
| 433 | + //because this listener takes priority | |
| 434 | + $('#options').stop().fadeOut(animation_duration); | |
| 435 | 435 | } |
| 436 | 436 | |
| 437 | 437 | async function onChatChanged() { |
| @@ -446,7 +446,7 @@ async function onChatChanged() { | ||
| 446 | 446 | $('#extension_floating_prompt_token_counter').text(tokenCounter1); |
| 447 | 447 | |
| 448 | 448 | let tokenCounter2; |
| 449 | 449 | if (extension_settings.note.chara && context.characterId !== undefined) { |
| 450 | 450 | const charaNote = extension_settings.note.chara.find((e) => e.name === getCharaFilename()); |
| 451 | 451 | |
| 452 | 452 | if (charaNote) { |
| @@ -40,7 +40,7 @@ function setCharCfg(tempValue, setting) { | ||
| 40 | 40 | name: avatarName, |
| 41 | 41 | }; |
| 42 | 42 | |
| 43 | 43 | switch (setting) { |
| 44 | 44 | case settingType.guidance_scale: |
| 45 | 45 | tempCharaCfg['guidance_scale'] = Number(tempValue); |
| 46 | 46 | break; |
| @@ -69,8 +69,7 @@ function setCharCfg(tempValue, setting) { | ||
| 69 | 69 | if (!existingCharaCfg.useChara && |
| 70 | 70 | (tempAssign.guidance_scale ?? 1.00) === 1.00 && |
| 71 | 71 | (tempAssign.negative_prompt?.length ?? 0) === 0 && |
| 72 | 72 | (tempAssign.positive_prompt?.length ?? 0) === 0) { |
| 73 | - { | |
| 74 | 73 | extension_settings.cfg.chara.splice(existingCharaCfgIndex, 1); |
| 75 | 74 | } |
| 76 | 75 | } else if (avatarName && tempValue.length > 0) { |
| @@ -92,7 +91,7 @@ function setCharCfg(tempValue, setting) { | ||
| 92 | 91 | } |
| 93 | 92 | |
| 94 | 93 | function setChatCfg(tempValue, setting) { |
| 95 | 94 | switch (setting) { |
| 96 | 95 | case settingType.guidance_scale: |
| 97 | 96 | chat_metadata[metadataKeys.guidance_scale] = tempValue; |
| 98 | 97 | break; |
| @@ -113,49 +112,49 @@ function setChatCfg(tempValue, setting) { | ||
| 113 | 112 | |
| 114 | 113 | // TODO: Only change CFG when character is selected |
| 115 | 114 | function onCfgMenuItemClick() { |
| 116 | 115 | if (!selected_group ||&& this_chid === undefined) { |
| 117 | - //show CFG config if it's hidden | |
| 116 | + toastr.warning('Select a character before trying to configure CFG', '', { timeOut: 2000 }); | |
| 118 | - if ($('#cfgConfig').css('display') !== 'flex') { | |
| 117 | + return; | |
| 119 | - $('#cfgConfig').addClass('resizing'); | |
| 118 | + } | |
| 120 | - $('#cfgConfig').css('display', 'flex'); | |
| 119 | + | |
| 121 | - $('#cfgConfig').css('opacity', 0.0); | |
| 120 | + //show CFG config if it's hidden | |
| 122 | - $('#cfgConfig').transition({ | |
| 121 | + if ($('#cfgConfig').css('display') !== 'flex') { | |
| 123 | - opacity: 1.0, | |
| 122 | + $('#cfgConfig').addClass('resizing'); | |
| 124 | - duration: animation_duration, | |
| 123 | + $('#cfgConfig').css('display', 'flex'); | |
| 125 | - }, async function () { | |
| 124 | + $('#cfgConfig').css('opacity', 0.0); | |
| 126 | - await delay(50); | |
| 125 | + $('#cfgConfig').transition({ | |
| 127 | - $('#cfgConfig').removeClass('resizing'); | |
| 126 | + opacity: 1.0, | |
| 128 | - }); | |
| 127 | + duration: animation_duration, | |
| 129 | - | |
| 128 | + }, async function () { | |
| 130 | - //auto-open the main AN inline drawer | |
| 129 | + await delay(50); | |
| 131 | 130 | if ($('#CFGBlockTogglecfgConfig').removeClass('resizing'); |
| 132 | - .siblings('.inline-drawer-content') | |
| 131 | + }); | |
| 133 | - .css('display') !== 'block') { | |
| 134 | - $('#floatingPrompt').addClass('resizing'); | |
| 135 | - $('#CFGBlockToggle').click(); | |
| 136 | - } | |
| 137 | - } else { | |
| 138 | - //hide AN if it's already displayed | |
| 139 | - $('#cfgConfig').addClass('resizing'); | |
| 140 | - $('#cfgConfig').transition({ | |
| 141 | - opacity: 0.0, | |
| 142 | - duration: animation_duration, | |
| 143 | - }, | |
| 144 | - async function () { | |
| 145 | - await delay(50); | |
| 146 | - $('#cfgConfig').removeClass('resizing'); | |
| 147 | - }); | |
| 148 | - setTimeout(function () { | |
| 149 | - $('#cfgConfig').hide(); | |
| 150 | - }, animation_duration); | |
| 151 | 132 | |
| 133 | + //auto-open the main AN inline drawer | |
| 134 | + if ($('#CFGBlockToggle') | |
| 135 | + .siblings('.inline-drawer-content') | |
| 136 | + .css('display') !== 'block') { | |
| 137 | + $('#floatingPrompt').addClass('resizing'); | |
| 138 | + $('#CFGBlockToggle').click(); | |
| 152 | 139 | } |
| 153 | - //duplicate options menu close handler from script.js | |
| 154 | - //because this listener takes priority | |
| 155 | - $('#options').stop().fadeOut(animation_duration); | |
| 156 | 140 | } else { |
| 157 | - toastr.warning('Select a character before trying to configure CFG', '', { timeOut: 2000 }); | |
| 141 | + //hide AN if it's already displayed | |
| 142 | + $('#cfgConfig').addClass('resizing'); | |
| 143 | + $('#cfgConfig').transition({ | |
| 144 | + opacity: 0.0, | |
| 145 | + duration: animation_duration, | |
| 146 | + }, async function () { | |
| 147 | + await delay(50); | |
| 148 | + $('#cfgConfig').removeClass('resizing'); | |
| 149 | + }); | |
| 150 | + setTimeout(function () { | |
| 151 | + $('#cfgConfig').hide(); | |
| 152 | + }, animation_duration); | |
| 153 | + | |
| 158 | 154 | } |
| 155 | + //duplicate options menu close handler from script.js | |
| 156 | + //because this listener takes priority | |
| 157 | + $('#options').stop().fadeOut(animation_duration); | |
| 159 | 158 | } |
| 160 | 159 | |
| 161 | 160 | async function onChatChanged() { |
| @@ -288,7 +287,7 @@ export function initCfg() { | ||
| 288 | 287 | setTimeout(function () { $('#cfgConfig').hide(); }, animation_duration); |
| 289 | 288 | }); |
| 290 | 289 | |
| 291 | 290 | $('#chat_cfg_guidance_scale').on('input', function () { |
| 292 | 291 | const numberValue = Number($(this).val()); |
| 293 | 292 | const success = setChatCfg(numberValue, settingType.guidance_scale); |
| 294 | 293 | if (success) { |
| @@ -296,15 +295,15 @@ export function initCfg() { | ||
| 296 | 295 | } |
| 297 | 296 | }); |
| 298 | 297 | |
| 299 | 298 | $('#chat_cfg_negative_prompt').on('input', function () { |
| 300 | 299 | setChatCfg($(this).val(), settingType.negative_prompt); |
| 301 | 300 | }); |
| 302 | 301 | |
| 303 | 302 | $('#chat_cfg_positive_prompt').on('input', function () { |
| 304 | 303 | setChatCfg($(this).val(), settingType.positive_prompt); |
| 305 | 304 | }); |
| 306 | 305 | |
| 307 | 306 | $('#chara_cfg_guidance_scale').on('input', function () { |
| 308 | 307 | const value = $(this).val(); |
| 309 | 308 | const success = setCharCfg(value, settingType.guidance_scale); |
| 310 | 309 | if (success) { |
| @@ -312,34 +311,34 @@ export function initCfg() { | ||
| 312 | 311 | } |
| 313 | 312 | }); |
| 314 | 313 | |
| 315 | 314 | $('#chara_cfg_negative_prompt').on('input', function () { |
| 316 | 315 | setCharCfg($(this).val(), settingType.negative_prompt); |
| 317 | 316 | }); |
| 318 | 317 | |
| 319 | 318 | $('#chara_cfg_positive_prompt').on('input', function () { |
| 320 | 319 | setCharCfg($(this).val(), settingType.positive_prompt); |
| 321 | 320 | }); |
| 322 | 321 | |
| 323 | 322 | $('#global_cfg_guidance_scale').on('input', function () { |
| 324 | 323 | extension_settings.cfg.global.guidance_scale = Number($(this).val()); |
| 325 | 324 | $('#global_cfg_guidance_scale_counter').val(extension_settings.cfg.global.guidance_scale.toFixed(2)); |
| 326 | 325 | saveSettingsDebounced(); |
| 327 | 326 | }); |
| 328 | 327 | |
| 329 | 328 | $('#global_cfg_negative_prompt').on('input', function () { |
| 330 | 329 | extension_settings.cfg.global.negative_prompt = $(this).val(); |
| 331 | 330 | saveSettingsDebounced(); |
| 332 | 331 | }); |
| 333 | 332 | |
| 334 | 333 | $('#global_cfg_positive_prompt').on('input', function () { |
| 335 | 334 | extension_settings.cfg.global.positive_prompt = $(this).val(); |
| 336 | 335 | saveSettingsDebounced(); |
| 337 | 336 | }); |
| 338 | 337 | |
| 339 | 338 | $('input[name="cfg_prompt_combine"]').on('input', function () { |
| 340 | 339 | const values = $('#cfgConfig').find('input[name="cfg_prompt_combine"]') |
| 341 | 340 | .filter(':checked') |
| 342 | 341 | .map(function () { return Number($(this).val()); }) |
| 343 | 342 | .get() |
| 344 | 343 | .filter((e) => !Number.isNaN(e)) || []; |
| 345 | 344 | |
| @@ -347,17 +346,17 @@ export function initCfg() { | ||
| 347 | 346 | saveMetadataDebounced(); |
| 348 | 347 | }); |
| 349 | 348 | |
| 350 | 349 | $('#cfg_prompt_insertion_depth').on('input', function () { |
| 351 | 350 | chat_metadata[metadataKeys.prompt_insertion_depth] = Number($(this).val()); |
| 352 | 351 | saveMetadataDebounced(); |
| 353 | 352 | }); |
| 354 | 353 | |
| 355 | 354 | $('#cfg_prompt_separator').on('input', function () { |
| 356 | 355 | chat_metadata[metadataKeys.prompt_separator] = $(this).val(); |
| 357 | 356 | saveMetadataDebounced(); |
| 358 | 357 | }); |
| 359 | 358 | |
| 360 | 359 | $('#groupchat_cfg_use_chara').on('input', function () { |
| 361 | 360 | const checked = !!$(this).prop('checked'); |
| 362 | 361 | chat_metadata[metadataKeys.groupchat_individual_chars] = checked; |
| 363 | 362 | |
| @@ -624,7 +624,7 @@ function getFolderNameByMessage(message) { | ||
| 624 | 624 | if (context.groupId) { |
| 625 | 625 | avatarPath = message.original_avatar || context.characters.find(x => message.force_avatar && message.force_avatar.includes(encodeURIComponent(x.avatar)))?.avatar; |
| 626 | 626 | } |
| 627 | 627 | else if (context.characterId !== undefined) { |
| 628 | 628 | avatarPath = getCharaFilename(); |
| 629 | 629 | } |
| 630 | 630 | |
| @@ -169,9 +169,9 @@ async function showCharGallery() { | ||
| 169 | 169 | |
| 170 | 170 | try { |
| 171 | 171 | let url = selected_group || this_chid; |
| 172 | 172 | if (!selected_group && this_chid !== undefined) { |
| 173 | 173 | const char = characters[this_chid]; |
| 174 | 174 | url = char.avatar.replace('.png', '')name; |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | const items = await getGalleryItems(url); |
| @@ -455,9 +455,9 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({ | ||
| 455 | 455 | async function listGalleryCommand(args) { |
| 456 | 456 | try { |
| 457 | 457 | let url = args.char ?? (args.group ? groups.find(it => it.name == args.group)?.id : null) ?? (selected_group || this_chid); |
| 458 | 458 | if (!args.char && !args.group && !selected_group && this_chid !== undefined) { |
| 459 | 459 | const char = characters[this_chid]; |
| 460 | 460 | url = char.avatar.replace('.png', '')name; |
| 461 | 461 | } |
| 462 | 462 | |
| 463 | 463 | const items = await getGalleryItems(url); |
| @@ -378,6 +378,23 @@ function getIndexOfLatestChatSummary(chat) { | ||
| 378 | 378 | return -1; |
| 379 | 379 | } |
| 380 | 380 | |
| 381 | +/** | |
| 382 | + * Check if something is changed during the summarization process. | |
| 383 | + * @param {{ groupId: any; chatId: any; characterId: any; }} context | |
| 384 | + * @returns {boolean} True if the context has changed and the summary should be discarded | |
| 385 | + */ | |
| 386 | +function isContextChanged(context) { | |
| 387 | + const newContext = getContext(); | |
| 388 | + if (newContext.groupId !== context.groupId | |
| 389 | + || newContext.chatId !== context.chatId | |
| 390 | + || (!newContext.groupId && (newContext.characterId !== context.characterId))) { | |
| 391 | + console.log('Context changed, summary discarded'); | |
| 392 | + return true; | |
| 393 | + } | |
| 394 | + | |
| 395 | + return false; | |
| 396 | +} | |
| 397 | + | |
| 381 | 398 | function onChatChanged() { |
| 382 | 399 | const context = getContext(); |
| 383 | 400 | const latestMemory = getLatestMemoryFromChat(context.chat); |
| @@ -626,7 +643,6 @@ async function summarizeChatWebLLM(context, force) { | ||
| 626 | 643 | try { |
| 627 | 644 | inApiCall = true; |
| 628 | 645 | const summary = await generateWebLlmChatPrompt(messages, params); |
| 629 | - const newContext = getContext(); | |
| 630 | 646 | |
| 631 | 647 | if (!summary) { |
| 632 | 648 | console.warn('Empty summary received'); |
| @@ -634,10 +650,7 @@ async function summarizeChatWebLLM(context, force) { | ||
| 634 | 650 | } |
| 635 | 651 | |
| 636 | 652 | // something changed during summarization request |
| 637 | - if (newContext.groupId !== context.groupId || | |
| 653 | + if (isContextChanged(context)) { | |
| 638 | - newContext.chatId !== context.chatId || | |
| 639 | - (!newContext.groupId && (newContext.characterId !== context.characterId))) { | |
| 640 | - console.log('Context changed, summary discarded'); | |
| 641 | 654 | return; |
| 642 | 655 | } |
| 643 | 656 | |
| @@ -701,13 +714,7 @@ async function summarizeChatMain(context, force, skipWIAN) { | ||
| 701 | 714 | return; |
| 702 | 715 | } |
| 703 | 716 | |
| 704 | - const newContext = getContext(); | |
| 717 | + if (isContextChanged(context)) { | |
| 705 | - | |
| 706 | - // something changed during summarization request | |
| 707 | - if (newContext.groupId !== context.groupId | |
| 708 | - || newContext.chatId !== context.chatId | |
| 709 | - || (!newContext.groupId && (newContext.characterId !== context.characterId))) { | |
| 710 | - console.log('Context changed, summary discarded'); | |
| 711 | 718 | return; |
| 712 | 719 | } |
| 713 | 720 | |
| @@ -833,18 +840,13 @@ async function summarizeChatExtras(context) { | ||
| 833 | 840 | try { |
| 834 | 841 | inApiCall = true; |
| 835 | 842 | const summary = await callExtrasSummarizeAPI(resultingString); |
| 836 | - const newContext = getContext(); | |
| 837 | 843 | |
| 838 | 844 | if (!summary) { |
| 839 | 845 | console.warn('Empty summary received'); |
| 840 | 846 | return; |
| 841 | 847 | } |
| 842 | 848 | |
| 843 | - // something changed during summarization request | |
| 849 | + if (isContextChanged(context)) { | |
| 844 | - if (newContext.groupId !== context.groupId | |
| 845 | - || newContext.chatId !== context.chatId | |
| 846 | - || (!newContext.groupId && (newContext.characterId !== context.characterId))) { | |
| 847 | - console.log('Context changed, summary discarded'); | |
| 848 | 850 | return; |
| 849 | 851 | } |
| 850 | 852 | |
| @@ -783,7 +783,7 @@ async function onCharacterNegativePromptInput() { | ||
| 783 | 783 | } |
| 784 | 784 | |
| 785 | 785 | function getCharacterPrefix() { |
| 786 | 786 | if (!this_chid === undefined || selected_group) { |
| 787 | 787 | return ''; |
| 788 | 788 | } |
| 789 | 789 | |
| @@ -797,7 +797,7 @@ function getCharacterPrefix() { | ||
| 797 | 797 | } |
| 798 | 798 | |
| 799 | 799 | function getCharacterNegativePrefix() { |
| 800 | 800 | if (!this_chid === undefined || selected_group) { |
| 801 | 801 | return ''; |
| 802 | 802 | } |
| 803 | 803 | |
| @@ -51,6 +51,8 @@ var speechUtteranceChunker = function (utt, settings, callback) { | ||
| 51 | 51 | } |
| 52 | 52 | newUtt.lang = utt.lang; |
| 53 | 53 | newUtt.voice = utt.voice; |
| 54 | + newUtt.rate = utt.rate; | |
| 55 | + newUtt.pitch = utt.pitch; | |
| 54 | 56 | newUtt.addEventListener('end', function () { |
| 55 | 57 | if (speechUtteranceChunker.cancel) { |
| 56 | 58 | speechUtteranceChunker.cancel = false; |
| @@ -406,6 +406,8 @@ jQuery(function () { | ||
| 406 | 406 | } else { |
| 407 | 407 | $('#adjustedHordeParams').text('Context: --, Response: --'); |
| 408 | 408 | } |
| 409 | + | |
| 410 | + saveSettingsDebounced(); | |
| 409 | 411 | }); |
| 410 | 412 | |
| 411 | 413 | $('#horde_auto_adjust_response_length').on('input', function () { |
| @@ -132,10 +132,14 @@ async function getLocaleData(language) { | ||
| 132 | 132 | return data; |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | +/** | |
| 136 | + * Gets a language object for the given language code. | |
| 137 | + * @param {string} language Language code | |
| 138 | + */ | |
| 135 | 139 | function findLang(language) { |
| 136 | 140 | varconst supportedLang = langs.find(x => x.lang === language); |
| 137 | 141 | |
| 138 | 142 | if (!supportedLang && language !== 'en') { |
| 139 | 143 | console.warn(`Unsupported language: ${language}`); |
| 140 | 144 | } |
| 141 | 145 | return supportedLang; |
| @@ -496,9 +496,13 @@ function getMessageHash(message) { | ||
| 496 | 496 | /** |
| 497 | 497 | * getActiveMessageLogprobData returns the logprobs data for the active chat |
| 498 | 498 | * message. |
| 499 | 499 | * @returns {MessageLogprobData || null} |
| 500 | 500 | */ |
| 501 | 501 | function getActiveMessageLogprobData() { |
| 502 | + if (chat.length === 0) { | |
| 503 | + return null; | |
| 504 | + } | |
| 505 | + | |
| 502 | 506 | const hash = getMessageHash(chat[chat.length - 1]); |
| 503 | 507 | return state.messageLogprobs.get(hash) || null; |
| 504 | 508 | } |
| @@ -45,6 +45,8 @@ import { | ||
| 45 | 45 | this_chid, |
| 46 | 46 | updateChatMetadata, |
| 47 | 47 | updateMessageBlock, |
| 48 | + printMessages, | |
| 49 | + clearChat, | |
| 48 | 50 | } from '../script.js'; |
| 49 | 51 | import { |
| 50 | 52 | extension_settings, |
| @@ -203,6 +205,8 @@ export function getContext() { | ||
| 203 | 205 | extractMessageFromData, |
| 204 | 206 | getPresetManager, |
| 205 | 207 | getChatCompletionModel, |
| 208 | + printMessages, | |
| 209 | + clearChat, | |
| 206 | 210 | }; |
| 207 | 211 | } |
| 208 | 212 | |
| @@ -410,7 +410,7 @@ function getInlineListSelector() { | ||
| 410 | 410 | return `.group_select[grid="${selected_group}"] .tags`; |
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | if (this_chid !== undefined && menu_type === 'character_edit') { |
| 414 | 414 | return `.character_select[chid="${this_chid}"] .tags`; |
| 415 | 415 | } |
| 416 | 416 | |
| @@ -4732,7 +4732,7 @@ export function setWorldInfoButtonClass(chid, forceValue = undefined) { | ||
| 4732 | 4732 | return; |
| 4733 | 4733 | } |
| 4734 | 4734 | |
| 4735 | 4735 | if (!chid === undefined) { |
| 4736 | 4736 | return; |
| 4737 | 4737 | } |
| 4738 | 4738 | |
| @@ -4749,7 +4749,7 @@ export function checkEmbeddedWorld(chid) { | ||
| 4749 | 4749 | } |
| 4750 | 4750 | |
| 4751 | 4751 | if (characters[chid]?.data?.character_book) { |
| 4752 | 4752 | $('#import_character_info').data('data-chid', chid).show(); |
| 4753 | 4753 | |
| 4754 | 4754 | // Only show the alert once per character |
| 4755 | 4755 | const checkKey = `AlertWI_${characters[chid].avatar}`; |
| @@ -4783,9 +4783,15 @@ export function checkEmbeddedWorld(chid) { | ||
| 4783 | 4783 | } |
| 4784 | 4784 | |
| 4785 | 4785 | export async function importEmbeddedWorldInfo(skipPopup = false) { |
| 4786 | 4786 | const chid = $('#import_character_info').data('data-chid'); |
| 4787 | 4787 | |
| 4788 | 4788 | if (chid === undefined || chid === -1) { |
| 4789 | + return; | |
| 4790 | + } | |
| 4791 | + | |
| 4792 | + const hasEmbed = checkEmbeddedWorld(chid); | |
| 4793 | + | |
| 4794 | + if (!hasEmbed) { | |
| 4789 | 4795 | return; |
| 4790 | 4796 | } |
| 4791 | 4797 | |
| @@ -5167,20 +5173,24 @@ jQuery(() => { | ||
| 5167 | 5173 | }); |
| 5168 | 5174 | |
| 5169 | 5175 | $('#world_button').on('click', async function (event) { |
| 5176 | + const openSetWorldMenu = () => $('#char-management-dropdown').val($('#set_character_world').val()).trigger('change'); | |
| 5170 | 5177 | const chid = $('#set_character_world').data('chid'); |
| 5171 | 5178 | |
| 5172 | 5179 | if (chid === -1) { |
| 5173 | - const worldName = characters[chid]?.data?.extensions?.world; | |
| 5180 | + openSetWorldMenu(); | |
| 5174 | - const hasEmbed = checkEmbeddedWorld(chid); | |
| 5181 | + return; | |
| 5175 | - if (worldName && world_names.includes(worldName) && !event.shiftKey) { | |
| 5182 | + } | |
| 5176 | - openWorldInfoEditor(worldName); | |
| 5183 | + | |
| 5177 | - } else if (hasEmbed && !event.shiftKey) { | |
| 5184 | + const worldName = characters[chid]?.data?.extensions?.world; | |
| 5178 | - await importEmbeddedWorldInfo(); | |
| 5185 | + const hasEmbed = checkEmbeddedWorld(chid); | |
| 5179 | - saveCharacterDebounced(); | |
| 5186 | + if (worldName && world_names.includes(worldName) && !event.shiftKey) { | |
| 5180 | - } | |
| 5187 | + openWorldInfoEditor(worldName); | |
| 5181 | - else { | |
| 5188 | + } else if (hasEmbed && !event.shiftKey) { | |
| 5182 | - $('#char-management-dropdown').val($('#set_character_world').val()).trigger('change'); | |
| 5189 | + await importEmbeddedWorldInfo(); | |
| 5183 | - } | |
| 5190 | + saveCharacterDebounced(); | |
| 5191 | + } | |
| 5192 | + else { | |
| 5193 | + openSetWorldMenu(); | |
| 5184 | 5194 | } |
| 5185 | 5195 | }); |
| 5186 | 5196 | |