Chore: enable brace-style eslint check (#5159) * eslint: enable brace-style check * Fix jsdoc and color * fix: correct CSS color syntax in CreateZenSliders function
Signed| @@ -102,8 +102,8 @@ module.exports = { | ||
| 102 | 102 | // These rules should eventually be enabled. |
| 103 | 103 | 'no-async-promise-executor': 'off', |
| 104 | 104 | 'no-inner-declarations': 'off', |
| 105 | - 'brace-style': 'off', | |
| 106 | 105 | // Additional formatting rules based on codebase conventions |
| 106 | + 'brace-style': ['error', '1tbs', { allowSingleLine: true }], | |
| 107 | 107 | 'array-bracket-spacing': ['error', 'never'], |
| 108 | 108 | 'computed-property-spacing': ['error', 'never'], |
| 109 | 109 | 'block-spacing': ['error', 'always'], |
| @@ -89,8 +89,7 @@ async function installPlugin(pluginName) { | ||
| 89 | 89 | |
| 90 | 90 | await git().clone(pluginName, pluginPath, { '--depth': 1 }); |
| 91 | 91 | console.log(`Plugin ${color.green(pluginName)} installed to ${color.cyan(pluginPath)}`); |
| 92 | - } | |
| 92 | + } catch (error) { | |
| 93 | - catch (error) { | |
| 94 | 93 | console.error(color.red(`Failed to install plugin ${pluginName}`), error); |
| 95 | 94 | } |
| 96 | 95 | } |
| @@ -512,8 +512,7 @@ export function reloadMarkdownProcessor() { | ||
| 512 | 512 | export function getCurrentChatId() { |
| 513 | 513 | if (selected_group) { |
| 514 | 514 | return groups.find(x => x.id == selected_group)?.chat_id; |
| 515 | - } | |
| 515 | + } else if (this_chid !== undefined) { | |
| 516 | - else if (this_chid !== undefined) { | |
| 517 | 516 | return characters[this_chid]?.chat; |
| 518 | 517 | } |
| 519 | 518 | } |
| @@ -910,8 +909,7 @@ function getCharacterBlock(item, id) { | ||
| 910 | 909 | const description = item.data?.creator_notes || ''; |
| 911 | 910 | if (description) { |
| 912 | 911 | template.find('.ch_description').text(description); |
| 913 | 912 | } else { |
| 914 | - else { | |
| 915 | 913 | template.find('.ch_description').hide(); |
| 916 | 914 | } |
| 917 | 915 | |
| @@ -919,8 +917,7 @@ function getCharacterBlock(item, id) { | ||
| 919 | 917 | const auxFieldValue = (item.data && item.data[auxFieldName]) || ''; |
| 920 | 918 | if (auxFieldValue) { |
| 921 | 919 | template.find('.character_version').text(auxFieldValue); |
| 922 | 920 | } else { |
| 923 | - else { | |
| 924 | 921 | template.find('.character_version').hide(); |
| 925 | 922 | } |
| 926 | 923 | |
| @@ -1364,16 +1361,14 @@ export async function replaceCurrentChat() { | ||
| 1364 | 1361 | const chats = Object.values(await chatsResponse.json()); |
| 1365 | 1362 | chats.sort((a, b) => sortMoments(timestampToMoment(a.last_mes), timestampToMoment(b.last_mes))); |
| 1366 | 1363 | |
| 1367 | - // pick existing chat | |
| 1368 | 1364 | if (chats.length && typeof chats[0] === 'object') { |
| 1365 | + // pick existing chat | |
| 1369 | 1366 | characters[this_chid].chat = chats[0].file_name.replace('.jsonl', ''); |
| 1370 | 1367 | $('#selected_chat_pole').val(characters[this_chid].chat); |
| 1371 | 1368 | saveCharacterDebounced(); |
| 1372 | 1369 | await getChat(); |
| 1373 | 1370 | } else { |
| 1374 | - | |
| 1371 | + // start new chat | |
| 1375 | - // start new chat | |
| 1376 | - else { | |
| 1377 | 1372 | characters[this_chid].chat = `${name2} - ${humanizedDateTime()}`; |
| 1378 | 1373 | $('#selected_chat_pole').val(characters[this_chid].chat); |
| 1379 | 1374 | saveCharacterDebounced(); |
| @@ -1640,11 +1635,9 @@ export async function reloadCurrentChatUnsafe() { | ||
| 1640 | 1635 | |
| 1641 | 1636 | if (selected_group) { |
| 1642 | 1637 | await getGroupChat(selected_group, true); |
| 1643 | - } | |
| 1638 | + } else if (this_chid !== undefined) { | |
| 1644 | - else if (this_chid !== undefined) { | |
| 1645 | 1639 | await getChat(); |
| 1646 | 1640 | } else { |
| 1647 | - else { | |
| 1648 | 1641 | resetChatState(); |
| 1649 | 1642 | restoreNeutralChat(); |
| 1650 | 1643 | await getCharacters(); |
| @@ -1870,32 +1863,16 @@ export function messageFormatting(mes, ch_name, isSystem, isUser, messageId, san | ||
| 1870 | 1863 | /** |
| 1871 | 1864 | * Inserts or replaces an SVG icon adjacent to the provided message's timestamp. |
| 1872 | 1865 | * |
| 1873 | - * If the `extra.api` is "openai" and `extra.model` contains the substring "claude", | |
| 1874 | - * the function fetches the "claude.svg". Otherwise, it fetches the SVG named after | |
| 1875 | - * the value in `extra.api`. | |
| 1876 | - * | |
| 1877 | 1866 | * @param {JQuery<HTMLElement>} mes - The message element containing the timestamp where the icon should be inserted or replaced. |
| 1878 | 1867 | * @param {ChatMessageExtra} extra - Contains the API and model details. |
| 1879 | 1868 | */ |
| 1880 | 1869 | function insertSVGIcon(mes, extra) { |
| 1881 | 1870 | // Determine the SVG filename |
| 1882 | - let modelName; | |
| 1871 | + let modelName = extra?.api || ''; | |
| 1883 | 1872 | |
| 1884 | - // Claude on OpenRouter or Anthropic | |
| 1873 | + // If there's no API information, we can't determine which SVG to use | |
| 1885 | - if (extra.api === 'openai' && extra.model?.toLowerCase().includes('claude')) { | |
| 1874 | + if (!modelName) { | |
| 1886 | - modelName = 'claude'; | |
| 1875 | + return; | |
| 1887 | - } | |
| 1888 | - // OpenAI on OpenRouter | |
| 1889 | - else if (extra.api === 'openai' && extra.model?.toLowerCase().includes('openai')) { | |
| 1890 | - modelName = 'openai'; | |
| 1891 | - } | |
| 1892 | - // OpenRouter website model or other models | |
| 1893 | - else if (extra.api === 'openai' && (extra.model === null || extra.model?.toLowerCase().includes('/'))) { | |
| 1894 | - modelName = 'openrouter'; | |
| 1895 | - } | |
| 1896 | - // Everything else | |
| 1897 | - else { | |
| 1898 | - modelName = extra.api; | |
| 1899 | 1876 | } |
| 1900 | 1877 | |
| 1901 | 1878 | const insertOrReplaceSVG = (image, className, targetSelector, insertBefore) => { |
| @@ -3755,8 +3732,7 @@ class StreamingProcessor { | ||
| 3755 | 3732 | } |
| 3756 | 3733 | const seconds = (timestamps[timestamps.length - 1] - timestamps[0]) / 1000; |
| 3757 | 3734 | console.warn(`Stream stats: ${timestamps.length} tokens, ${seconds.toFixed(2)} seconds, rate: ${Number(timestamps.length / seconds).toFixed(2)} TPS`); |
| 3758 | - } | |
| 3735 | + } catch (err) { | |
| 3759 | - catch (err) { | |
| 3760 | 3736 | // in the case of a self-inflicted abort, we have already cleaned up |
| 3761 | 3737 | if (!this.isFinished) { |
| 3762 | 3738 | console.error(err); |
| @@ -4236,8 +4212,7 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro | ||
| 4236 | 4212 | textareaText = ''; |
| 4237 | 4213 | if (chat.length && lastMessage.is_user) { |
| 4238 | 4214 | //do nothing? why does this check exist? |
| 4239 | - } | |
| 4215 | + } else if (type !== 'quiet' && type !== 'swipe' && !isImpersonate && !dryRun && !depth && chat.length) { | |
| 4240 | - else if (type !== 'quiet' && type !== 'swipe' && !isImpersonate && !dryRun && !depth && chat.length) { | |
| 4241 | 4216 | deleteItemizedPromptForMessage(chat.length - 1); |
| 4242 | 4217 | chat.length = chat.length - 1; |
| 4243 | 4218 | await removeLastMessage(); |
| @@ -4282,12 +4257,10 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro | ||
| 4282 | 4257 | // If user message contains no text other than bias - send as a system message |
| 4283 | 4258 | if (messageBias && !removeMacros(textareaText)) { |
| 4284 | 4259 | sendSystemMessage(system_message_types.GENERIC, ' ', { bias: messageBias }); |
| 4285 | 4260 | } else { |
| 4286 | - else { | |
| 4287 | 4261 | await sendMessageAsUser(textareaText, messageBias); |
| 4288 | 4262 | } |
| 4289 | - } | |
| 4263 | + } else if (textareaText == '' && !automatic_trigger && !dryRun && [undefined, 'normal'].includes(type) && main_api == 'openai' && oai_settings.send_if_empty.trim().length > 0 && !depth) { | |
| 4290 | - else if (textareaText == '' && !automatic_trigger && !dryRun && [undefined, 'normal'].includes(type) && main_api == 'openai' && oai_settings.send_if_empty.trim().length > 0 && !depth) { | |
| 4291 | 4264 | // Use send_if_empty if set and the user message is empty. Only when sending messages normally |
| 4292 | 4265 | await sendMessageAsUser(oai_settings.send_if_empty.trim(), messageBias); |
| 4293 | 4266 | } |
| @@ -4406,8 +4379,7 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro | ||
| 4406 | 4379 | if (main_api == 'koboldhorde' && (horde_settings.auto_adjust_context_length || horde_settings.auto_adjust_response_length)) { |
| 4407 | 4380 | try { |
| 4408 | 4381 | adjustedParams = await adjustHordeGenerationParams(max_context, amount_gen); |
| 4409 | 4382 | } catch { |
| 4410 | - catch { | |
| 4411 | 4383 | unblockGeneration(type); |
| 4412 | 4384 | return Promise.resolve(); |
| 4413 | 4385 | } |
| @@ -4585,8 +4557,7 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro | ||
| 4585 | 4557 | // When continuing generation of previous output, last user message precedes the message to continue |
| 4586 | 4558 | if (isContinue) { |
| 4587 | 4559 | coreChat.splice(coreChat.length - 1, 0, { mes: jailbreak, is_user: true }); |
| 4588 | 4560 | } else { |
| 4589 | - else { | |
| 4590 | 4561 | // This operation will result in the injectedIndices indexes being off by one |
| 4591 | 4562 | coreChat.push({ mes: jailbreak, is_user: true }); |
| 4592 | 4563 | // Add +1 to the elements to correct for the new PHI/Jailbreak message. |
| @@ -5207,8 +5178,7 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro | ||
| 5207 | 5178 | |
| 5208 | 5179 | if (itemizedIndex !== -1) { |
| 5209 | 5180 | itemizedPrompts[itemizedIndex] = additionalPromptStuff; |
| 5210 | 5181 | } else { |
| 5211 | - else { | |
| 5212 | 5182 | itemizedPrompts.push(additionalPromptStuff); |
| 5213 | 5183 | } |
| 5214 | 5184 | |
| @@ -5350,17 +5320,14 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro | ||
| 5350 | 5320 | if (isImpersonate) { |
| 5351 | 5321 | $('#send_textarea').val(getMessage)[0].dispatchEvent(new Event('input', { bubbles: true })); |
| 5352 | 5322 | await eventSource.emit(event_types.IMPERSONATE_READY, getMessage); |
| 5353 | - } | |
| 5323 | + } else if (type == 'quiet') { | |
| 5354 | - else if (type == 'quiet') { | |
| 5355 | 5324 | unblockGeneration(type); |
| 5356 | 5325 | return getMessage; |
| 5357 | 5326 | } else { |
| 5358 | - else { | |
| 5359 | 5327 | // Without streaming we'll be having a full message on continuation. Treat it as a last chunk. |
| 5360 | 5328 | if (originalType !== 'continue') { |
| 5361 | 5329 | ({ type, getMessage } = await saveReply({ type, getMessage, title, swipes, reasoning, imageUrls, reasoningSignature })); |
| 5362 | 5330 | } else { |
| 5363 | - else { | |
| 5364 | 5331 | ({ type, getMessage } = await saveReply({ type: 'appendFinal', getMessage, title, swipes, reasoning, imageUrls, reasoningSignature })); |
| 5365 | 5332 | } |
| 5366 | 5333 | |
| @@ -5829,9 +5796,7 @@ function addChatsPreamble(mesSendString) { | ||
| 5829 | 5796 | function addChatsSeparator(mesSendString) { |
| 5830 | 5797 | if (power_user.context.chat_start) { |
| 5831 | 5798 | return substituteParams(power_user.context.chat_start + '\n') + mesSendString; |
| 5832 | 5799 | } else { |
| 5833 | - | |
| 5834 | - else { | |
| 5835 | 5800 | return mesSendString; |
| 5836 | 5801 | } |
| 5837 | 5802 | } |
| @@ -7055,16 +7020,13 @@ export async function renameCharacter(name = null, { silent = false, renameChats | ||
| 7055 | 7020 | } else { |
| 7056 | 7021 | toastr.success(t`Character renamed!`, t`Rename Character`); |
| 7057 | 7022 | } |
| 7058 | 7023 | } else { |
| 7059 | - else { | |
| 7060 | 7024 | throw new Error('Newly renamed character was lost?'); |
| 7061 | 7025 | } |
| 7062 | 7026 | } else { |
| 7063 | - else { | |
| 7064 | 7027 | throw new Error('Could not rename the character'); |
| 7065 | 7028 | } |
| 7066 | - } | |
| 7029 | + } catch (error) { | |
| 7067 | - catch (error) { | |
| 7068 | 7030 | // Reloading to prevent data corruption |
| 7069 | 7031 | if (!silent) await Popup.show.text(t`Rename Character`, t`Something went wrong. The page will be reloaded.`); |
| 7070 | 7032 | else toastr.error(t`Something went wrong. The page will be reloaded.`, t`Rename Character`); |
| @@ -7356,8 +7318,7 @@ export function buildAvatarList(block, entities, { templateId = 'inline_avatar_t | ||
| 7356 | 7318 | avatarTemplate.append(grpTemplate.children()); |
| 7357 | 7319 | avatarTemplate.attr({ 'data-grid': id, 'data-chid': null }); |
| 7358 | 7320 | avatarTemplate.attr('title', `[Group] ${entity.item.name}`); |
| 7359 | - } | |
| 7321 | + } else if (entity.type === 'persona') { | |
| 7360 | - else if (entity.type === 'persona') { | |
| 7361 | 7322 | avatarTemplate.attr({ 'data-pid': id, 'data-chid': null }); |
| 7362 | 7323 | avatarTemplate.find('img').attr('src', getThumbnailUrl('persona', entity.item.avatar)); |
| 7363 | 7324 | avatarTemplate.attr('title', `[Persona] ${entity.item.name}\nFile: ${entity.item.avatar}`); |
| @@ -8099,8 +8060,7 @@ async function messageEditCancel(messageId = this_edit_mes_id) { | ||
| 8099 | 8060 | await eventSource.emit(event_types.MESSAGE_UPDATED, messageId); |
| 8100 | 8061 | if (messageId == this_edit_mes_id) { |
| 8101 | 8062 | this_edit_mes_id = undefined; |
| 8102 | 8063 | } else { |
| 8103 | - else { | |
| 8104 | 8064 | console.warn(`The message editor was closed on message #${messageId} while #${this_edit_mes_id} is being edited.`); |
| 8105 | 8065 | } |
| 8106 | 8066 | |
| @@ -8134,8 +8094,7 @@ async function messageEditMove(sourceId, targetId) { | ||
| 8134 | 8094 | |
| 8135 | 8095 | if (sourceId <= targetId) { |
| 8136 | 8096 | sourceMessageDiv.insertAfter(targetMessageDiv); |
| 8137 | 8097 | } else { |
| 8138 | - else { | |
| 8139 | 8098 | sourceMessageDiv.insertBefore(targetMessageDiv); |
| 8140 | 8099 | } |
| 8141 | 8100 | |
| @@ -8951,11 +8910,13 @@ export function isMessageSwipeable(messageId, message = undefined) { | ||
| 8951 | 8910 | //User messages are not swipeable. |
| 8952 | 8911 | !message.is_user |
| 8953 | 8912 | ) |
| 8954 | 8913 | ) { |
| 8955 | 8914 | // The message is swipeable. |
| 8956 | 8915 | { return true; } |
| 8957 | - //The message is not swipeable. | |
| 8916 | + } else { | |
| 8958 | - else { return false; } | |
| 8917 | + // The message is not swipeable. | |
| 8918 | + return false; | |
| 8919 | + } | |
| 8959 | 8920 | } |
| 8960 | 8921 | |
| 8961 | 8922 | /** |
| @@ -9145,8 +9106,7 @@ export async function saveChatConditional() { | ||
| 9145 | 9106 | |
| 9146 | 9107 | if (selected_group) { |
| 9147 | 9108 | await saveGroupChat(selected_group, true); |
| 9148 | 9109 | } else { |
| 9149 | - else { | |
| 9150 | 9110 | await saveChat(); |
| 9151 | 9111 | } |
| 9152 | 9112 | |
| @@ -9252,8 +9212,7 @@ export function closeMessageEditor(what = 'all') { | ||
| 9252 | 9212 | export function setGenerationProgress(progress) { |
| 9253 | 9213 | if (!progress) { |
| 9254 | 9214 | $('#send_textarea').css({ 'background': '', 'transition': '' }); |
| 9255 | 9215 | } else { |
| 9256 | - else { | |
| 9257 | 9216 | $('#send_textarea').css({ |
| 9258 | 9217 | 'background': `linear-gradient(90deg, #008000d6 ${progress}%, transparent ${progress}%)`, |
| 9259 | 9218 | 'transition': '0.25s ease-in-out', |
| @@ -9767,8 +9726,7 @@ export async function swipe(event, direction, { source, repeated, message = chat | ||
| 9767 | 9726 | document.body.dataset.swiping = 'true'; |
| 9768 | 9727 | await generation; |
| 9769 | 9728 | } |
| 9770 | - } | |
| 9729 | + } catch (error) { | |
| 9771 | - catch (error) { | |
| 9772 | 9730 | console.warn(`Swipe failed, Swiping back. ${error}`); |
| 9773 | 9731 | } |
| 9774 | 9732 | |
| @@ -9804,8 +9762,7 @@ export async function swipe(event, direction, { source, repeated, message = chat | ||
| 9804 | 9762 | //Update the chat. |
| 9805 | 9763 | await loadFromSwipeId(mesId, chat[mesId].swipe_id); |
| 9806 | 9764 | await redisplayChat({ startIndex: mesId }); |
| 9807 | 9765 | } else { |
| 9808 | - else { | |
| 9809 | 9766 | await Popup.show.confirm( |
| 9810 | 9767 | t`ERROR: <code>syncSwipeToMes</code> has failed to revert the failed ${direction} swipe on message #${mesId}.`, |
| 9811 | 9768 | t`<p>After you click OK, the chat will be reloaded to prevent data corruption.</p>`, |
| @@ -10104,9 +10061,8 @@ export async function swipe(event, direction, { source, repeated, message = chat | ||
| 10104 | 10061 | } |
| 10105 | 10062 | await standardSwipe(newSwipeId); |
| 10106 | 10063 | return; |
| 10107 | - } | |
| 10064 | + } else if (direction === SWIPE_DIRECTION.RIGHT) { | |
| 10108 | 10065 | //If swiping right. |
| 10109 | - else if (direction === SWIPE_DIRECTION.RIGHT) { | |
| 10110 | 10066 | // make new slot in array |
| 10111 | 10067 | if (forceSwipeId == null) newSwipeId++; |
| 10112 | 10068 | |
| @@ -10133,18 +10089,16 @@ export async function swipe(event, direction, { source, repeated, message = chat | ||
| 10133 | 10089 | chat[mesId].swipe_id = originalSwipeId; |
| 10134 | 10090 | await endSwipe(); |
| 10135 | 10091 | return; |
| 10136 | - } | |
| 10092 | + } else if (overswipe == OVERSWIPE_BEHAVIOR.REGENERATE) { | |
| 10137 | 10093 | //Regenerate the message |
| 10138 | - else if (overswipe == OVERSWIPE_BEHAVIOR.REGENERATE) { | |
| 10139 | 10094 | clearMessageData(chat[mesId]); |
| 10140 | 10095 | let run_generate = true; |
| 10141 | 10096 | //Generate. |
| 10142 | 10097 | await animateSwipe(run_generate); |
| 10143 | 10098 | await endSwipe(); |
| 10144 | 10099 | return; |
| 10145 | - } | |
| 10100 | + } else if (overswipe == OVERSWIPE_BEHAVIOR.LOOP || overswipe == OVERSWIPE_BEHAVIOR.PRISTINE_GREETING) { | |
| 10146 | 10101 | // Loop to the first swipe. |
| 10147 | - else if (overswipe == OVERSWIPE_BEHAVIOR.LOOP || overswipe == OVERSWIPE_BEHAVIOR.PRISTINE_GREETING) { | |
| 10148 | 10102 | newSwipeId = 0; |
| 10149 | 10103 | } |
| 10150 | 10104 | } |
| @@ -10363,8 +10317,7 @@ export async function doNewChat({ deleteCurrentChat = false } = {}) { | ||
| 10363 | 10317 | if (selected_group) { |
| 10364 | 10318 | await createNewGroupChat(selected_group); |
| 10365 | 10319 | if (deleteCurrentChat) await deleteGroupChat(selected_group, chat_file_for_del, { jumpToNewChat: false }); // don't jump, new chat was already created and jumped to above |
| 10366 | 10320 | } else { |
| 10367 | - else { | |
| 10368 | 10321 | //RossAscends: added character name to new chat filenames and replaced Date.now() with humanizedDateTime; |
| 10369 | 10322 | chat_metadata = {}; |
| 10370 | 10323 | characters[this_chid].chat = `${name2} - ${humanizedDateTime()}`; |
| @@ -10427,8 +10380,7 @@ export async function renameGroupOrCharacterChat({ characterId, groupId, oldFile | ||
| 10427 | 10380 | |
| 10428 | 10381 | if (groupId) { |
| 10429 | 10382 | await renameGroupChat(groupId, oldFileName, newFileName); |
| 10430 | - } | |
| 10383 | + } else if (characterId !== undefined && String(characterId) === String(this_chid) && characters[characterId]?.chat === oldFileName) { | |
| 10431 | - else if (characterId !== undefined && String(characterId) === String(this_chid) && characters[characterId]?.chat === oldFileName) { | |
| 10432 | 10384 | characters[characterId].chat = newFileName; |
| 10433 | 10385 | $('#selected_chat_pole').val(characters[characterId].chat); |
| 10434 | 10386 | await createOrEditCharacter(); |
| @@ -11080,8 +11032,7 @@ jQuery(async function () { | ||
| 11080 | 11032 | if (popup_type == 'input') { |
| 11081 | 11033 | dialogueResolve($('#dialogue_popup_input').val()); |
| 11082 | 11034 | $('#dialogue_popup_input').val(''); |
| 11083 | 11035 | } else { |
| 11084 | - else { | |
| 11085 | 11036 | dialogueResolve(true); |
| 11086 | 11037 | } |
| 11087 | 11038 | |
| @@ -11316,9 +11267,7 @@ jQuery(async function () { | ||
| 11316 | 11267 | }); |
| 11317 | 11268 | } |
| 11318 | 11269 | } |
| 11319 | - } | |
| 11270 | + } else if (id == 'option_start_new_chat') { | |
| 11320 | - | |
| 11321 | - else if (id == 'option_start_new_chat') { | |
| 11322 | 11271 | if ((selected_group || this_chid !== undefined) && !is_send_press) { |
| 11323 | 11272 | let deleteCurrentChat = false; |
| 11324 | 11273 | const result = await Popup.show.confirm(t`Start new chat?`, await renderTemplateAsync('newChatConfirm'), { |
| @@ -11334,9 +11283,7 @@ jQuery(async function () { | ||
| 11334 | 11283 | const alreadyInTempChat = this_chid === undefined && name2 === neutralCharacterName; |
| 11335 | 11284 | await newAssistantChat({ temporary: alreadyInTempChat }); |
| 11336 | 11285 | } |
| 11337 | - } | |
| 11286 | + } else if (id == 'option_regenerate') { | |
| 11338 | - | |
| 11339 | - else if (id == 'option_regenerate') { | |
| 11340 | 11287 | //Attempting to regenerate a user message will instead generate a new message. |
| 11341 | 11288 | if (chat.length && chat.length - 1 === this_edit_mes_id && chat[this_edit_mes_id]?.is_user == false) { |
| 11342 | 11289 | toastr.warning(t`Finish the edit before starting a generation.`, t`You cannot regenerate the message you are editing.`); |
| @@ -11345,22 +11292,17 @@ jQuery(async function () { | ||
| 11345 | 11292 | if (is_send_press == false) { |
| 11346 | 11293 | if (selected_group) { |
| 11347 | 11294 | regenerateGroup(); |
| 11348 | 11295 | } else { |
| 11349 | - else { | |
| 11350 | 11296 | is_send_press = true; |
| 11351 | 11297 | Generate('regenerate', buildOrFillAdditionalArgs()); |
| 11352 | 11298 | } |
| 11353 | 11299 | } |
| 11354 | - } | |
| 11300 | + } else if (id == 'option_impersonate') { | |
| 11355 | - | |
| 11356 | - else if (id == 'option_impersonate') { | |
| 11357 | 11301 | if (is_send_press == false || fromSlashCommand) { |
| 11358 | 11302 | is_send_press = true; |
| 11359 | 11303 | Generate('impersonate', buildOrFillAdditionalArgs()); |
| 11360 | 11304 | } |
| 11361 | - } | |
| 11305 | + } else if (id == 'option_continue') { | |
| 11362 | - | |
| 11363 | - else if (id == 'option_continue') { | |
| 11364 | 11306 | if (swipeState == SWIPE_STATE.EDITING) { |
| 11365 | 11307 | toastr.warning(t`Confirm the edit to start a generation.`, t`You cannot send a message during a swipe-edit.`); |
| 11366 | 11308 | return; |
| @@ -11374,17 +11316,11 @@ jQuery(async function () { | ||
| 11374 | 11316 | is_send_press = true; |
| 11375 | 11317 | Generate('continue', buildOrFillAdditionalArgs()); |
| 11376 | 11318 | } |
| 11377 | - } | |
| 11319 | + } else if (id == 'option_delete_mes') { | |
| 11378 | - | |
| 11379 | - else if (id == 'option_delete_mes') { | |
| 11380 | 11320 | setTimeout(() => openMessageDelete(fromSlashCommand), animation_duration); |
| 11381 | - } | |
| 11321 | + } else if (id == 'option_close_chat') { | |
| 11382 | - | |
| 11383 | - else if (id == 'option_close_chat') { | |
| 11384 | 11322 | await closeCurrentChat(); |
| 11385 | - } | |
| 11323 | + } else if (id === 'option_settings') { | |
| 11386 | - | |
| 11387 | - else if (id === 'option_settings') { | |
| 11388 | 11324 | //var checkBox = document.getElementById("waifuMode"); |
| 11389 | 11325 | var topBar = document.getElementById('top-bar'); |
| 11390 | 11326 | var topSettingsHolder = document.getElementById('top-settings-holder'); |
| @@ -379,8 +379,7 @@ function RA_autoconnect(PrevApi) { | ||
| 379 | 379 | || (textgen_settings.type === textgen_types.FEATHERLESS && secret_state[SECRET_KEYS.FEATHERLESS]) |
| 380 | 380 | ) { |
| 381 | 381 | $('#api_button_textgenerationwebui').trigger('click'); |
| 382 | - } | |
| 382 | + } else if (isValidUrl(getTextGenServer())) { | |
| 383 | - else if (isValidUrl(getTextGenServer())) { | |
| 384 | 383 | $('#api_button_textgenerationwebui').trigger('click'); |
| 385 | 384 | } |
| 386 | 385 | break; |
| @@ -1053,8 +1052,7 @@ export function initRossMods() { | ||
| 1053 | 1052 | $('#send_textarea').trigger('focus'); |
| 1054 | 1053 | reasoningMesDone.trigger('click'); |
| 1055 | 1054 | return; |
| 1056 | - } | |
| 1055 | + } else if (is_send_press == false) { | |
| 1057 | - else if (is_send_press == false) { | |
| 1058 | 1056 | const skipConfirmKey = 'RegenerateWithCtrlEnter'; |
| 1059 | 1057 | const skipConfirm = accountStorage.getItem(skipConfirmKey) === 'true'; |
| 1060 | 1058 | function doRegenerate() { |
| @@ -231,11 +231,9 @@ function onExtensionFloatingCharaPromptInput() { | ||
| 231 | 231 | !existingCharaNote.useChara |
| 232 | 232 | ) { |
| 233 | 233 | extension_settings.note.chara.splice(existingCharaNoteIndex, 1); |
| 234 | - } | |
| 234 | + } else if (extension_settings.note.chara && existingCharaNote) { | |
| 235 | - else if (extension_settings.note.chara && existingCharaNote) { | |
| 236 | 235 | Object.assign(existingCharaNote, tempCharaNote); |
| 237 | - } | |
| 236 | + } else if (avatarName && tempPrompt.length > 0) { | |
| 238 | - else if (avatarName && tempPrompt.length > 0) { | |
| 239 | 237 | if (!extension_settings.note.chara) { |
| 240 | 238 | extension_settings.note.chara = []; |
| 241 | 239 | } |
| @@ -111,12 +111,10 @@ function getMainChatName() { | ||
| 111 | 111 | if (chat_metadata) { |
| 112 | 112 | if (chat_metadata.main_chat) { |
| 113 | 113 | return chat_metadata.main_chat; |
| 114 | - } | |
| 114 | + } else if (selected_group) { | |
| 115 | 115 | // groups didn't support bookmarks before chat metadata was introduced |
| 116 | - else if (selected_group) { | |
| 117 | 116 | return null; |
| 118 | - } | |
| 117 | + } else if (characters[this_chid].chat && characters[this_chid].chat.includes(bookmarkNameToken)) { | |
| 119 | - else if (characters[this_chid].chat && characters[this_chid].chat.includes(bookmarkNameToken)) { | |
| 120 | 118 | const tokenIndex = characters[this_chid].chat.lastIndexOf(bookmarkNameToken); |
| 121 | 119 | chat_metadata.main_chat = characters[this_chid].chat.substring(0, tokenIndex).trim(); |
| 122 | 120 | return chat_metadata.main_chat; |
| @@ -146,8 +144,7 @@ export function showBookmarksButtons() { | ||
| 146 | 144 | $('#option_back_to_main').hide(); |
| 147 | 145 | $('#option_new_bookmark').show(); |
| 148 | 146 | } |
| 149 | 147 | } catch { |
| 150 | - catch { | |
| 151 | 148 | $('#option_back_to_main').hide(); |
| 152 | 149 | $('#option_new_bookmark').hide(); |
| 153 | 150 | $('#option_convert_to_group').hide(); |
| @@ -832,11 +832,9 @@ async function openExternalMediaOverridesDialog() { | ||
| 832 | 832 | |
| 833 | 833 | if (power_user.external_media_allowed_overrides.includes(entityId)) { |
| 834 | 834 | template.find('#forbid_media_override_allowed').prop('checked', true); |
| 835 | - } | |
| 835 | + } else if (power_user.external_media_forbidden_overrides.includes(entityId)) { | |
| 836 | - else if (power_user.external_media_forbidden_overrides.includes(entityId)) { | |
| 837 | 836 | template.find('#forbid_media_override_forbidden').prop('checked', true); |
| 838 | 837 | } else { |
| 839 | - else { | |
| 840 | 838 | template.find('#forbid_media_override_global').prop('checked', true); |
| 841 | 839 | } |
| 842 | 840 | |
| @@ -1678,8 +1676,7 @@ async function runScraper(scraperId, target, callback) { | ||
| 1678 | 1676 | |
| 1679 | 1677 | toastr.success(t`Scraped ${files.length} files from ${scraperId} to ${target}.`, t`Data Bank`); |
| 1680 | 1678 | callback(); |
| 1681 | - } | |
| 1679 | + } catch (error) { | |
| 1682 | - catch (error) { | |
| 1683 | 1680 | console.error('Scraping failed', error); |
| 1684 | 1681 | toastr.error(t`Check browser console for details.`, t`Scraping failed`); |
| 1685 | 1682 | } |
| @@ -73,8 +73,7 @@ function applyDynamicFocusStyles(styleSheet, { fromExtension = false } = {}) { | ||
| 73 | 73 | const isHover = selector.includes(':hover'), isFocus = selector.includes(':focus'); |
| 74 | 74 | if (isHover && isFocus) { |
| 75 | 75 | // We currently do nothing here. Rules containing both hover and focus are very specific and should never be automatically touched |
| 76 | - } | |
| 76 | + } else if (isHover) { | |
| 77 | - else if (isHover) { | |
| 78 | 77 | const baseSelector = selector.replace(/:hover/g, PLACEHOLDER).trim(); |
| 79 | 78 | hoverRules.push({ baseSelector, rule, wrappers: [...wrappers] }); |
| 80 | 79 | } else if (isFocus) { |
| @@ -278,12 +278,10 @@ async function discoverExtensions() { | ||
| 278 | 278 | if (response.ok) { |
| 279 | 279 | const extensions = await response.json(); |
| 280 | 280 | return extensions; |
| 281 | 281 | } else { |
| 282 | - else { | |
| 283 | 282 | return []; |
| 284 | 283 | } |
| 285 | - } | |
| 284 | + } catch (err) { | |
| 286 | - catch (err) { | |
| 287 | 285 | console.error(err); |
| 288 | 286 | return []; |
| 289 | 287 | } |
| @@ -627,8 +625,7 @@ async function connectToApi(baseUrl) { | ||
| 627 | 625 | } |
| 628 | 626 | |
| 629 | 627 | updateStatus(getExtensionsResult.ok); |
| 630 | 628 | } catch { |
| 631 | - catch { | |
| 632 | 629 | updateStatus(false); |
| 633 | 630 | } |
| 634 | 631 | } |
| @@ -82,8 +82,7 @@ function getAuthorFromUrl(url) { | ||
| 82 | 82 | result.name = pathSegments[0]; |
| 83 | 83 | result.url = `${parsedUrl.protocol}//${parsedUrl.hostname}/${result.name}`; |
| 84 | 84 | } |
| 85 | - } | |
| 85 | + } catch (error) { | |
| 86 | - catch (error) { | |
| 87 | 86 | console.debug(DEBUG_PREFIX, 'Error parsing URL:', error); |
| 88 | 87 | } |
| 89 | 88 | |
| @@ -199,8 +198,7 @@ async function downloadAssetsList(url) { | ||
| 199 | 198 | label.removeClass('fa-trash'); |
| 200 | 199 | label.removeClass('redOverlayGlow'); |
| 201 | 200 | }); |
| 202 | 201 | } else { |
| 203 | - else { | |
| 204 | 202 | console.debug(DEBUG_PREFIX, 'not installed, unchecked'); |
| 205 | 203 | element.prop('checked', false); |
| 206 | 204 | element.on('click', assetInstall); |
| @@ -346,8 +344,7 @@ async function installAsset(url, assetType, filename) { | ||
| 346 | 344 | console.debug(DEBUG_PREFIX, 'Character downloaded.'); |
| 347 | 345 | } |
| 348 | 346 | } |
| 349 | - } | |
| 347 | + } catch (err) { | |
| 350 | - catch (err) { | |
| 351 | 348 | console.log(err); |
| 352 | 349 | return []; |
| 353 | 350 | } |
| @@ -373,8 +370,7 @@ async function deleteAsset(assetType, filename) { | ||
| 373 | 370 | if (result.ok) { |
| 374 | 371 | console.debug(DEBUG_PREFIX, 'Deletion success.'); |
| 375 | 372 | } |
| 376 | - } | |
| 373 | + } catch (err) { | |
| 377 | - catch (err) { | |
| 378 | 374 | console.log(err); |
| 379 | 375 | return []; |
| 380 | 376 | } |
| @@ -427,8 +423,7 @@ async function updateCurrentAssets() { | ||
| 427 | 423 | headers: getRequestHeaders({ omitContentType: true }), |
| 428 | 424 | }); |
| 429 | 425 | currentAssets = result.ok ? (await result.json()) : {}; |
| 430 | - } | |
| 426 | + } catch (err) { | |
| 431 | - catch (err) { | |
| 432 | 427 | console.log(err); |
| 433 | 428 | } |
| 434 | 429 | console.debug(DEBUG_PREFIX, 'Current assets found:', currentAssets); |
| @@ -490,8 +485,7 @@ jQuery(async () => { | ||
| 490 | 485 | connectButton.addClass('fa-plug-circle-exclamation'); |
| 491 | 486 | connectButton.removeClass('redOverlayGlow'); |
| 492 | 487 | } |
| 493 | 488 | } else { |
| 494 | - else { | |
| 495 | 489 | console.debug(DEBUG_PREFIX, 'Connection refused by user'); |
| 496 | 490 | } |
| 497 | 491 | }); |
| @@ -68,8 +68,7 @@ async function setImageIcon() { | ||
| 68 | 68 | const sendButton = $('#send_picture .extensionsMenuExtensionButton'); |
| 69 | 69 | sendButton.addClass('fa-image'); |
| 70 | 70 | sendButton.removeClass('fa-hourglass-half'); |
| 71 | - } | |
| 71 | + } catch (error) { | |
| 72 | - catch (error) { | |
| 73 | 72 | console.log(error); |
| 74 | 73 | } |
| 75 | 74 | } |
| @@ -82,8 +81,7 @@ async function setSpinnerIcon() { | ||
| 82 | 81 | const sendButton = $('#send_picture .extensionsMenuExtensionButton'); |
| 83 | 82 | sendButton.removeClass('fa-image'); |
| 84 | 83 | sendButton.addClass('fa-hourglass-half'); |
| 85 | - } | |
| 84 | + } catch (error) { | |
| 86 | - catch (error) { | |
| 87 | 85 | console.log(error); |
| 88 | 86 | } |
| 89 | 87 | } |
| @@ -376,14 +374,12 @@ async function getCaptionForFile(file, prompt, quiet) { | ||
| 376 | 374 | await sendCaptionedMessage(caption, imagePath, file.type); |
| 377 | 375 | } |
| 378 | 376 | return caption; |
| 379 | - } | |
| 377 | + } catch (error) { | |
| 380 | - catch (error) { | |
| 381 | 378 | const errorMessage = error.message || 'Unknown error'; |
| 382 | 379 | toastr.error(errorMessage, 'Failed to caption'); |
| 383 | 380 | console.error(error); |
| 384 | 381 | return ''; |
| 385 | 382 | } finally { |
| 386 | - finally { | |
| 387 | 383 | setImageIcon(); |
| 388 | 384 | } |
| 389 | 385 | } |
| @@ -363,8 +363,7 @@ export async function visualNovelUpdateLayers(container) { | ||
| 363 | 363 | if (power_user.reduced_motion) { |
| 364 | 364 | element.css('left', currentPosition + 'px'); |
| 365 | 365 | requestAnimationFrame(() => resolve()); |
| 366 | 366 | } else { |
| 367 | - else { | |
| 368 | 367 | element.animate({ left: currentPosition + 'px' }, 500, () => { |
| 369 | 368 | resolve(); |
| 370 | 369 | }); |
| @@ -525,8 +524,7 @@ async function moduleWorker({ newChat = false } = {}) { | ||
| 525 | 524 | } |
| 526 | 525 | |
| 527 | 526 | return; |
| 528 | 527 | } else { |
| 529 | - else { | |
| 530 | 528 | // force reload expressions list on connect to API |
| 531 | 529 | if (offlineMode.is(':visible')) { |
| 532 | 530 | expressionsList = null; |
| @@ -599,11 +597,9 @@ async function moduleWorker({ newChat = false } = {}) { | ||
| 599 | 597 | } |
| 600 | 598 | |
| 601 | 599 | await sendExpressionCall(spriteFolderName, expression, { force: force, vnMode: vnMode }); |
| 602 | - } | |
| 600 | + } catch (error) { | |
| 603 | - catch (error) { | |
| 604 | 601 | console.log(error); |
| 605 | 602 | } finally { |
| 606 | - finally { | |
| 607 | 603 | inApiCall = false; |
| 608 | 604 | lastCharacter = context.groupId || context.characterId; |
| 609 | 605 | lastMessage = currentLastMessage.mes; |
| @@ -631,8 +627,7 @@ function getFolderNameByMessage(message) { | ||
| 631 | 627 | |
| 632 | 628 | if (context.groupId) { |
| 633 | 629 | avatarPath = message.original_avatar || context.characters.find(x => message.force_avatar && message.force_avatar.includes(encodeURIComponent(x.avatar)))?.avatar; |
| 634 | - } | |
| 630 | + } else if (context.characterId !== undefined) { | |
| 635 | - else if (context.characterId !== undefined) { | |
| 636 | 631 | avatarPath = getCharaFilename(); |
| 637 | 632 | } |
| 638 | 633 | |
| @@ -1303,8 +1298,7 @@ async function getSpritesList(name) { | ||
| 1303 | 1298 | } |
| 1304 | 1299 | |
| 1305 | 1300 | return grouped; |
| 1306 | - } | |
| 1301 | + } catch (err) { | |
| 1307 | - catch (err) { | |
| 1308 | 1302 | console.log(err); |
| 1309 | 1303 | return []; |
| 1310 | 1304 | } |
| @@ -1476,9 +1470,8 @@ function chooseSpriteForExpression(spriteFolderName, expression, { prevExpressio | ||
| 1476 | 1470 | const searched = sprite.files.find(x => x.fileName === overrideSpriteFile); |
| 1477 | 1471 | if (searched) spriteFile = searched; |
| 1478 | 1472 | else toastr.warning(t`Couldn't find sprite file ${overrideSpriteFile} for expression ${expression}.`, t`Sprite Not Found`); |
| 1479 | - } | |
| 1473 | + } else if (extension_settings.expressions.allowMultiple && sprite.files.length > 1) { | |
| 1480 | 1474 | // Else calculate next expression, if multiple are allowed |
| 1481 | - else if (extension_settings.expressions.allowMultiple && sprite.files.length > 1) { | |
| 1482 | 1475 | let possibleFiles = sprite.files; |
| 1483 | 1476 | if (extension_settings.expressions.rerollIfSame) { |
| 1484 | 1477 | possibleFiles = possibleFiles.filter(x => !prevExpressionSrc || x.imageSrc !== prevExpressionSrc); |
| @@ -1593,8 +1586,7 @@ async function setExpression(spriteFolderName, expression, { force = false, over | ||
| 1593 | 1586 | } |
| 1594 | 1587 | |
| 1595 | 1588 | console.info('Expression set', { expression: spriteFile.expression, file: spriteFile.fileName }); |
| 1596 | 1589 | } else { |
| 1597 | - else { | |
| 1598 | 1590 | img.attr('data-sprite-folder-name', spriteFolderName); |
| 1599 | 1591 | |
| 1600 | 1592 | img.off('error'); |
| @@ -1844,19 +1836,16 @@ async function onClickExpressionUpload(event) { | ||
| 1844 | 1836 | const fileNameWithoutExtension = withoutExtension(file.name); |
| 1845 | 1837 | const validFileName = validateExpressionSpriteName(expression, fileNameWithoutExtension); |
| 1846 | 1838 | |
| 1847 | - // If there is no expression yet and it's a valid expression, we just take it | |
| 1848 | 1839 | if (!clickedFileName && validFileName) { |
| 1840 | + // If there is no expression yet and it's a valid expression, we just take it | |
| 1849 | 1841 | spriteName = fileNameWithoutExtension; |
| 1850 | - } | |
| 1842 | + } else if (clickedFileName === file.name) { | |
| 1851 | 1843 | // If the filename matches the one that was clicked, we just take it and replace it |
| 1852 | - else if (clickedFileName === file.name) { | |
| 1853 | 1844 | spriteName = fileNameWithoutExtension; |
| 1854 | - } | |
| 1845 | + } else if (!matchesExisting && validFileName) { | |
| 1855 | 1846 | // If it's a valid filename and there's no existing file with the same name, we just take it |
| 1856 | - else if (!matchesExisting && validFileName) { | |
| 1857 | 1847 | spriteName = fileNameWithoutExtension; |
| 1858 | 1848 | } else { |
| 1859 | - else { | |
| 1860 | 1849 | /** @type {import('../../popup.js').CustomPopupButton[]} */ |
| 1861 | 1850 | const customButtons = []; |
| 1862 | 1851 | if (clickedFileName) { |
| @@ -881,11 +881,9 @@ async function summarizeChatExtras(context) { | ||
| 881 | 881 | } |
| 882 | 882 | |
| 883 | 883 | setMemoryContext(summary, true); |
| 884 | - } | |
| 884 | + } catch (error) { | |
| 885 | - catch (error) { | |
| 886 | 885 | console.log(error); |
| 887 | 886 | } finally { |
| 888 | - finally { | |
| 889 | 887 | inApiCall = false; |
| 890 | 888 | } |
| 891 | 889 | } |
| @@ -398,8 +398,7 @@ export class QuickReply { | ||
| 398 | 398 | if (this.icon) { |
| 399 | 399 | icon.classList.add('fa-solid'); |
| 400 | 400 | icon.classList.add(this.icon); |
| 401 | 401 | } else { |
| 402 | - else { | |
| 403 | 402 | icon.textContent = '…'; |
| 404 | 403 | } |
| 405 | 404 | icon.addEventListener('click', async () => { |
| @@ -3021,8 +3021,7 @@ async function generatePicture(initiator, args, trigger, message, callback) { | ||
| 3021 | 3021 | const errorText = 'SD prompt text generation failed. ' + reason; |
| 3022 | 3022 | toastr.error(errorText, 'Image Generation'); |
| 3023 | 3023 | throw new Error(errorText); |
| 3024 | 3024 | } finally { |
| 3025 | - finally { | |
| 3026 | 3025 | $(stopButton).hide(); |
| 3027 | 3026 | restoreOriginalDimensions(dimensions); |
| 3028 | 3027 | eventSource.removeListener(CUSTOM_STOP_EVENT, stopListener); |
| @@ -497,8 +497,7 @@ class CoquiTtsProvider { | ||
| 497 | 497 | const language_label = JSON.stringify(model_settings.languages[i]).replaceAll('"', ''); |
| 498 | 498 | $('#coqui_api_model_settings_language').append(new Option(language_label, i)); |
| 499 | 499 | } |
| 500 | 500 | } else { |
| 501 | - else { | |
| 502 | 501 | $('#coqui_api_model_settings_language').hide(); |
| 503 | 502 | } |
| 504 | 503 | |
| @@ -516,8 +515,7 @@ class CoquiTtsProvider { | ||
| 516 | 515 | const speaker_label = JSON.stringify(model_settings.speakers[i]).replaceAll('"', ''); |
| 517 | 516 | $('#coqui_api_model_settings_speaker').append(new Option(speaker_label, i)); |
| 518 | 517 | } |
| 519 | 518 | } else { |
| 520 | - else { | |
| 521 | 519 | $('#coqui_api_model_settings_speaker').hide(); |
| 522 | 520 | } |
| 523 | 521 | |
| @@ -536,15 +534,13 @@ class CoquiTtsProvider { | ||
| 536 | 534 | if (model_state == 'installed') { |
| 537 | 535 | $('#coqui_api_model_install_status').text('Model already installed on extras server'); |
| 538 | 536 | $('#coqui_api_model_install_button').hide(); |
| 539 | 537 | } else { |
| 540 | - else { | |
| 541 | 538 | let action = 'download'; |
| 542 | 539 | if (model_state == 'corrupted') { |
| 543 | 540 | action = 'repare'; |
| 544 | 541 | //toastr.error("Click install button to reinstall the model "+$("#coqui_api_model_name").find(":selected").text(), DEBUG_PREFIX+" corrupted model install", { timeOut: 10000, extendedTimeOut: 20000, preventDuplicates: true }); |
| 545 | 542 | $('#coqui_api_model_install_status').text('Model found but incomplete try install again (maybe still downloading)'); // (remove and download again) |
| 546 | 543 | } else { |
| 547 | - else { | |
| 548 | 544 | toastr.info('Click download button to install the model ' + $('#coqui_api_model_name').find(':selected').text(), DEBUG_PREFIX + ' model not installed', { timeOut: 10000, extendedTimeOut: 20000, preventDuplicates: true }); |
| 549 | 545 | $('#coqui_api_model_install_status').text('Model not found on extras server'); |
| 550 | 546 | } |
| @@ -346,8 +346,7 @@ globalThis.tts_preview = function (id) { | ||
| 346 | 346 | |
| 347 | 347 | if (audio instanceof HTMLAudioElement && !$(audio).data('disabled')) { |
| 348 | 348 | audio.play(); |
| 349 | 349 | } else { |
| 350 | - else { | |
| 351 | 350 | ttsProvider.previewTtsVoice(id); |
| 352 | 351 | } |
| 353 | 352 | }; |
| @@ -1452,8 +1451,7 @@ async function initVoiceMapInternal(unrestricted) { | ||
| 1452 | 1451 | let voiceIdsFromProvider; |
| 1453 | 1452 | try { |
| 1454 | 1453 | voiceIdsFromProvider = await ttsProvider.fetchTtsVoiceObjects(); |
| 1455 | 1454 | } catch { |
| 1456 | - catch { | |
| 1457 | 1455 | toastr.error('TTS Provider failed to return voice ids.'); |
| 1458 | 1456 | } |
| 1459 | 1457 | |
| @@ -29,8 +29,7 @@ var speechUtteranceChunker = function (utt, settings, callback) { | ||
| 29 | 29 | callback(); |
| 30 | 30 | } |
| 31 | 31 | }); |
| 32 | 32 | } else { |
| 33 | - else { | |
| 34 | 33 | var chunkLength = (settings && settings.chunkLength) || 160; |
| 35 | 34 | var pattRegex = new RegExp('^[\\s\\S]{' + Math.floor(chunkLength / 2) + ',' + chunkLength + '}[.!?,]{1}|^[\\s\\S]{1,' + chunkLength + '}$|^[\\s\\S]{1,' + chunkLength + '} '); |
| 36 | 35 | var chunkArr = txt.match(pattRegex); |
| @@ -325,8 +325,7 @@ class VITSTtsProvider { | ||
| 325 | 325 | if (streaming) { |
| 326 | 326 | params.append('streaming', streaming); |
| 327 | 327 | // Streaming response only supports MP3 |
| 328 | 328 | } else { |
| 329 | - else { | |
| 330 | 329 | params.append('format', this.settings.format); |
| 331 | 330 | } |
| 332 | 331 | params.append('lang', lang ?? this.settings.lang); |
| @@ -337,8 +336,7 @@ class VITSTtsProvider { | ||
| 337 | 336 | |
| 338 | 337 | if (model_type == this.modelTypes.W2V2_VITS) { |
| 339 | 338 | params.append('emotion', this.settings.dim_emotion); |
| 340 | - } | |
| 339 | + } else if (model_type == this.modelTypes.BERT_VITS2) { | |
| 341 | - else if (model_type == this.modelTypes.BERT_VITS2) { | |
| 342 | 340 | params.append('sdp_ratio', this.settings.sdp_ratio); |
| 343 | 341 | params.append('emotion', this.settings.emotion); |
| 344 | 342 | if (this.settings.text_prompt) { |
| @@ -251,8 +251,7 @@ async function summarizeExtra(element) { | ||
| 251 | 251 | const data = await apiResult.json(); |
| 252 | 252 | element.text = data.summary; |
| 253 | 253 | } |
| 254 | - } | |
| 254 | + } catch (error) { | |
| 255 | - catch (error) { | |
| 256 | 255 | console.log(error); |
| 257 | 256 | return false; |
| 258 | 257 | } |
| @@ -938,8 +937,7 @@ function throwIfSourceInvalid() { | ||
| 938 | 937 | if (!settings.alt_endpoint_url) { |
| 939 | 938 | throw new Error('Vectors: API URL missing', { cause: 'api_url_missing' }); |
| 940 | 939 | } |
| 941 | 940 | } else { |
| 942 | - else { | |
| 943 | 941 | if (settings.source === 'ollama' && !textgenerationwebui_settings.server_urls[textgen_types.OLLAMA] || |
| 944 | 942 | settings.source === 'vllm' && !textgenerationwebui_settings.server_urls[textgen_types.VLLM] || |
| 945 | 943 | settings.source === 'koboldcpp' && !textgenerationwebui_settings.server_urls[textgen_types.KOBOLDCPP] || |
| @@ -328,8 +328,7 @@ export class FilterHelper { | ||
| 328 | 328 | // We can filter easily by checking if we have saved a score |
| 329 | 329 | const score = _this.getScore(FILTER_TYPES.SEARCH, `${entity.type}.${entity.id}`); |
| 330 | 330 | return score !== undefined; |
| 331 | 331 | } else { |
| 332 | - else { | |
| 333 | 332 | // Compare insensitive and without accents |
| 334 | 333 | return includesIgnoreCaseAndAccents(entity.item?.name, searchValue); |
| 335 | 334 | } |
| @@ -173,9 +173,8 @@ async function regenerateGroup() { | ||
| 173 | 173 | // for new generations after the update |
| 174 | 174 | if ((generationId && this_generationId) && generationId !== this_generationId) { |
| 175 | 175 | break; |
| 176 | - } | |
| 176 | + } else if (lastMes.is_user || lastMes.is_system) { | |
| 177 | 177 | // legacy for generations before the update |
| 178 | - else if (lastMes.is_user || lastMes.is_system) { | |
| 179 | 178 | break; |
| 180 | 179 | } |
| 181 | 180 | |
| @@ -392,8 +391,7 @@ export function findGroupMemberId(arg, full = false) { | ||
| 392 | 391 | console.log(`Targeting group member ${chid} (${arg}) from search result`, result[0]); |
| 393 | 392 | |
| 394 | 393 | return !full ? chid : { ...{ id: chid }, ...result[0].item }; |
| 395 | 394 | } else { |
| 396 | - else { | |
| 397 | 395 | const memberAvatar = group.members[index]; |
| 398 | 396 | |
| 399 | 397 | if (memberAvatar === undefined) { |
| @@ -744,8 +742,7 @@ export async function renameGroupMember(oldAvatar, newAvatar, newName) { | ||
| 744 | 742 | } |
| 745 | 743 | } |
| 746 | 744 | } |
| 747 | - } | |
| 745 | + } catch (error) { | |
| 748 | - catch (error) { | |
| 749 | 746 | console.log(`An error during renaming the character ${newName} in group: ${group.name}`); |
| 750 | 747 | console.error(error); |
| 751 | 748 | } |
| @@ -1011,28 +1008,22 @@ async function generateGroupWrapper(byAutoMode, type = null, params = {}) { | ||
| 1011 | 1008 | if (activatedMembers.length === 0) { |
| 1012 | 1009 | activatedMembers = activateListOrder(group.members.slice(0, 1)); |
| 1013 | 1010 | } |
| 1014 | - } | |
| 1011 | + } else if (type === 'swipe' || type === 'continue') { | |
| 1015 | - else if (type === 'swipe' || type === 'continue') { | |
| 1016 | 1012 | activatedMembers = activateSwipe(group.members, { allowSystem: false }); |
| 1017 | 1013 | |
| 1018 | 1014 | if (activatedMembers.length === 0) { |
| 1019 | 1015 | toastr.warning(t`Deleted group member swiped. To get a reply, add them back to the group.`); |
| 1020 | 1016 | throw new Error('Deleted group member swiped'); |
| 1021 | 1017 | } |
| 1022 | - } | |
| 1018 | + } else if (type === 'impersonate') { | |
| 1023 | - else if (type === 'impersonate') { | |
| 1024 | 1019 | activatedMembers = activateImpersonate(group.members); |
| 1025 | - } | |
| 1020 | + } else if (activationStrategy === group_activation_strategy.NATURAL) { | |
| 1026 | - else if (activationStrategy === group_activation_strategy.NATURAL) { | |
| 1027 | 1021 | activatedMembers = activateNaturalOrder(enabledMembers, activationText, lastMessage, group.allow_self_responses, isUserInput); |
| 1028 | - } | |
| 1022 | + } else if (activationStrategy === group_activation_strategy.LIST) { | |
| 1029 | - else if (activationStrategy === group_activation_strategy.LIST) { | |
| 1030 | 1023 | activatedMembers = activateListOrder(enabledMembers); |
| 1031 | - } | |
| 1024 | + } else if (activationStrategy === group_activation_strategy.POOLED) { | |
| 1032 | - else if (activationStrategy === group_activation_strategy.POOLED) { | |
| 1033 | 1025 | activatedMembers = activatePooledOrder(enabledMembers, lastMessage, isUserInput); |
| 1034 | - } | |
| 1026 | + } else if (activationStrategy === group_activation_strategy.MANUAL && !isUserInput) { | |
| 1035 | - else if (activationStrategy === group_activation_strategy.MANUAL && !isUserInput) { | |
| 1036 | 1027 | activatedMembers = shuffle(enabledMembers).slice(0, 1).map(x => characters.findIndex(y => y.avatar === x)).filter(x => x !== -1); |
| 1037 | 1028 | } |
| 1038 | 1029 | |
| @@ -1168,8 +1159,7 @@ function activateSwipe(members, { allowSystem = false } = {}) { | ||
| 1168 | 1159 | break; |
| 1169 | 1160 | } |
| 1170 | 1161 | } |
| 1171 | 1162 | } else { |
| 1172 | - else { | |
| 1173 | 1163 | activatedNames.push(lastMessage.original_avatar); |
| 1174 | 1164 | } |
| 1175 | 1165 | |
| @@ -1704,8 +1694,7 @@ function getGroupCharacterBlock(character) { | ||
| 1704 | 1694 | const auxFieldValue = (character.data && character.data[auxFieldName]) || ''; |
| 1705 | 1695 | if (auxFieldValue) { |
| 1706 | 1696 | template.find('.character_version').text(auxFieldValue); |
| 1707 | 1697 | } else { |
| 1708 | - else { | |
| 1709 | 1698 | template.find('.character_version').hide(); |
| 1710 | 1699 | } |
| 1711 | 1700 | |
| @@ -1875,8 +1864,7 @@ function select_group_chats(groupId, skipAnimation) { | ||
| 1875 | 1864 | if (group) { |
| 1876 | 1865 | $('#rm_group_automode_label').show(); |
| 1877 | 1866 | $('#rm_button_selected_ch').children('h2').text(groupName); |
| 1878 | 1867 | } else { |
| 1879 | - else { | |
| 1880 | 1868 | $('#rm_group_automode_label').hide(); |
| 1881 | 1869 | } |
| 1882 | 1870 | |
| @@ -126,8 +126,7 @@ export async function getStatusHorde() { | ||
| 126 | 126 | try { |
| 127 | 127 | const hordeStatus = await checkHordeStatus(); |
| 128 | 128 | setOnlineStatus(hordeStatus ? t`Connected` : 'no_connection'); |
| 129 | 129 | } catch { |
| 130 | - catch { | |
| 131 | 130 | setOnlineStatus('no_connection'); |
| 132 | 131 | } |
| 133 | 132 | |
| @@ -220,8 +220,7 @@ function tryParseStreamingError(response, decoded) { | ||
| 220 | 220 | toastr.error(data.error.message || response.statusText, 'KoboldAI API'); |
| 221 | 221 | throw new Error(data); |
| 222 | 222 | } |
| 223 | 223 | } catch { |
| 224 | - catch { | |
| 225 | 224 | // No JSON. Do nothing. |
| 226 | 225 | } |
| 227 | 226 | } |
| @@ -117,11 +117,8 @@ export function getLogitBiasListResult(biasPreset, tokenizerType, getBiasObject) | ||
| 117 | 117 | if (text.startsWith('{') && text.endsWith('}')) { |
| 118 | 118 | const tokens = getTextTokens(tokenizerType, text.slice(1, -1)); |
| 119 | 119 | result.push(getBiasObject(entry.value, tokens)); |
| 120 | - } | |
| 120 | + } else if (text.startsWith('[') && text.endsWith(']')) { | |
| 121 | - | |
| 121 | + // Raw token ids, JSON serialized | |
| 122 | - | |
| 123 | - // Raw token ids, JSON serialized | |
| 124 | - else if (text.startsWith('[') && text.endsWith(']')) { | |
| 125 | 122 | try { |
| 126 | 123 | const tokens = JSON.parse(text); |
| 127 | 124 | |
| @@ -133,11 +130,8 @@ export function getLogitBiasListResult(biasPreset, tokenizerType, getBiasObject) | ||
| 133 | 130 | } catch (err) { |
| 134 | 131 | console.log(`Failed to parse logit bias token list: ${text}`, err); |
| 135 | 132 | } |
| 136 | 133 | } else { |
| 137 | - | |
| 134 | + // Text with a leading space | |
| 138 | - | |
| 139 | - // Text with a leading space | |
| 140 | - else { | |
| 141 | 135 | const biasText = ` ${text}`; |
| 142 | 136 | const tokens = getTextTokens(tokenizerType, biasText); |
| 143 | 137 | result.push(getBiasObject(entry.value, tokens)); |
| @@ -1001,9 +1001,8 @@ class MacroCstWalker { | ||
| 1001 | 1001 | endOffset: element.endOffset ?? element.startOffset, |
| 1002 | 1002 | token: element, |
| 1003 | 1003 | }); |
| 1004 | - } | |
| 1004 | + } else if ('children' in element) { | |
| 1005 | 1005 | // Handle nested CstNode (macro or argument) |
| 1006 | - else if ('children' in element) { | |
| 1007 | 1006 | const nestedChildren = element.children || {}; |
| 1008 | 1007 | const nestedEnd = /** @type {IToken?} */ ((nestedChildren['Macro.End'] || [])[0]); |
| 1009 | 1008 | const nestedStart = /** @type {IToken?} */ ((nestedChildren['Macro.Start'] || [])[0]); |
| @@ -180,8 +180,7 @@ export function loadNovelPreset(preset) { | ||
| 180 | 180 | $('#amount_gen').val(preset.max_length).trigger('input'); |
| 181 | 181 | $('#max_context_unlocked').prop('checked', needsUnlock).trigger('change'); |
| 182 | 182 | $('#max_context').val(preset.max_context).trigger('input'); |
| 183 | 183 | } else { |
| 184 | - else { | |
| 185 | 184 | setGenerationParamsFromPreset(preset); |
| 186 | 185 | } |
| 187 | 186 | |
| @@ -459,10 +458,8 @@ function getBadWordIds(banned_tokens, tokenizerType) { | ||
| 459 | 458 | if (trimmed.startsWith('{') && trimmed.endsWith('}')) { |
| 460 | 459 | const tokens = getTextTokens(tokenizerType, trimmed.slice(1, -1)); |
| 461 | 460 | result.push(tokens); |
| 462 | - } | |
| 461 | + } else if (trimmed.startsWith('[') && trimmed.endsWith(']')) { | |
| 463 | - | |
| 462 | + // Raw token ids, JSON serialized | |
| 464 | - // Raw token ids, JSON serialized | |
| 465 | - else if (trimmed.startsWith('[') && trimmed.endsWith(']')) { | |
| 466 | 463 | try { |
| 467 | 464 | const tokens = JSON.parse(trimmed); |
| 468 | 465 | |
| @@ -474,10 +471,8 @@ function getBadWordIds(banned_tokens, tokenizerType) { | ||
| 474 | 471 | } catch (err) { |
| 475 | 472 | console.log(`Failed to parse bad word token list: ${trimmed}`, err); |
| 476 | 473 | } |
| 477 | 474 | } else { |
| 478 | - | |
| 475 | + // Apply permutations | |
| 479 | - // Apply permutations | |
| 480 | - else { | |
| 481 | 476 | const permutations = getBadWordPermutations(trimmed).map(t => getTextTokens(tokenizerType, t)); |
| 482 | 477 | result.push(...permutations); |
| 483 | 478 | } |
| @@ -738,8 +733,7 @@ function tryParseStreamingError(response, decoded) { | ||
| 738 | 733 | toastr.error(data.message || data.error?.message || response.statusText, 'NovelAI API'); |
| 739 | 734 | throw new Error(data); |
| 740 | 735 | } |
| 741 | 736 | } catch { |
| 742 | - catch { | |
| 743 | 737 | // No JSON. Do nothing. |
| 744 | 738 | } |
| 745 | 739 | } |
| @@ -495,8 +495,7 @@ async function validateReverseProxy() { | ||
| 495 | 495 | |
| 496 | 496 | try { |
| 497 | 497 | new URL(oai_settings.reverse_proxy); |
| 498 | - } | |
| 498 | + } catch (err) { | |
| 499 | - catch (err) { | |
| 500 | 499 | toastr.error(t`Entered reverse proxy address is not a valid URL`); |
| 501 | 500 | setOnlineStatus('no_connection'); |
| 502 | 501 | resultCheckStatus(); |
| @@ -1551,8 +1550,7 @@ export function tryParseStreamingError(response, decoded, { quiet = false } = {} | ||
| 1551 | 1550 | !quiet && toastr.error(data.detail?.error?.message || response.statusText, 'Chat Completion API'); |
| 1552 | 1551 | throw new Error(data); |
| 1553 | 1552 | } |
| 1554 | 1553 | } catch { |
| 1555 | - catch { | |
| 1556 | 1554 | // No JSON. Do nothing. |
| 1557 | 1555 | } |
| 1558 | 1556 | } |
| @@ -2868,8 +2866,7 @@ async function sendOpenAIRequest(type, messages, signal, { jsonSchema = null } = | ||
| 2868 | 2866 | yield { text, swipes: swipes, logprobs: parseChatCompletionLogprobs(parsed), toolCalls: toolCalls, state: state }; |
| 2869 | 2867 | } |
| 2870 | 2868 | }; |
| 2871 | 2869 | } else { |
| 2872 | - else { | |
| 2873 | 2870 | const data = await response.json(); |
| 2874 | 2871 | |
| 2875 | 2872 | checkQuotaError(data); |
| @@ -3081,8 +3078,7 @@ async function calculateLogitBias() { | ||
| 3081 | 3078 | }); |
| 3082 | 3079 | |
| 3083 | 3080 | result = await reply.json(); |
| 3084 | - } | |
| 3081 | + } catch (err) { | |
| 3085 | - catch (err) { | |
| 3086 | 3082 | result = {}; |
| 3087 | 3083 | console.error(err); |
| 3088 | 3084 | } |
| @@ -3602,13 +3598,11 @@ export class ChatCompletion { | ||
| 3602 | 3598 | if (lastMessage && shouldSquash(lastMessage)) { |
| 3603 | 3599 | lastMessage.content += '\n' + message.content; |
| 3604 | 3600 | lastMessage.tokens = await tokenHandler.countAsync({ role: lastMessage.role, content: lastMessage.content }); |
| 3605 | 3601 | } else { |
| 3606 | - else { | |
| 3607 | 3602 | squashedMessages.push(message); |
| 3608 | 3603 | lastMessage = message; |
| 3609 | 3604 | } |
| 3610 | 3605 | } else { |
| 3611 | - else { | |
| 3612 | 3606 | squashedMessages.push(message); |
| 3613 | 3607 | lastMessage = message; |
| 3614 | 3608 | } |
| @@ -4242,8 +4236,7 @@ async function saveOpenAIPreset(name, settings, triggerUi = true) { | ||
| 4242 | 4236 | Object.assign(openai_settings[value], presetBody); |
| 4243 | 4237 | $(`#settings_preset_openai option[value="${value}"]`).prop('selected', true); |
| 4244 | 4238 | if (triggerUi) $('#settings_preset_openai').trigger('change'); |
| 4245 | 4239 | } else { |
| 4246 | - else { | |
| 4247 | 4240 | openai_settings.push(presetBody); |
| 4248 | 4241 | openai_setting_names[data.name] = openai_settings.length - 1; |
| 4249 | 4242 | const option = document.createElement('option'); |
| @@ -4692,47 +4685,33 @@ function onSettingsPresetChange() { | ||
| 4692 | 4685 | function getMaxContextOpenAI(value) { |
| 4693 | 4686 | if (oai_settings.max_context_unlocked) { |
| 4694 | 4687 | return unlocked_max; |
| 4695 | - } | |
| 4688 | + } else if (value.startsWith('gpt-5')) { | |
| 4696 | - else if (value.startsWith('gpt-5')) { | |
| 4697 | 4689 | return max_400k; |
| 4698 | - } | |
| 4690 | + } else if (value.includes('gpt-4.1')) { | |
| 4699 | - else if (value.includes('gpt-4.1')) { | |
| 4700 | 4691 | return max_1mil; |
| 4701 | - } | |
| 4692 | + } else if (value.includes('gpt-audio')) { | |
| 4702 | - else if (value.includes('gpt-audio')) { | |
| 4703 | 4693 | return max_128k; |
| 4704 | - } | |
| 4694 | + } else if (value.startsWith('o1')) { | |
| 4705 | - else if (value.startsWith('o1')) { | |
| 4706 | 4695 | return max_128k; |
| 4707 | - } | |
| 4696 | + } else if (value.startsWith('o4') || value.startsWith('o3')) { | |
| 4708 | - else if (value.startsWith('o4') || value.startsWith('o3')) { | |
| 4709 | 4697 | return max_200k; |
| 4710 | - } | |
| 4698 | + } else if (value.includes('chatgpt-4o-latest') || value.includes('gpt-4-turbo') || value.includes('gpt-4o') || value.includes('gpt-4-1106') || value.includes('gpt-4-0125') || value.includes('gpt-4-vision')) { | |
| 4711 | - else if (value.includes('chatgpt-4o-latest') || value.includes('gpt-4-turbo') || value.includes('gpt-4o') || value.includes('gpt-4-1106') || value.includes('gpt-4-0125') || value.includes('gpt-4-vision')) { | |
| 4712 | 4699 | return max_128k; |
| 4713 | - } | |
| 4700 | + } else if (value.includes('gpt-3.5-turbo-1106')) { | |
| 4714 | - else if (value.includes('gpt-3.5-turbo-1106')) { | |
| 4715 | 4701 | return max_16k; |
| 4716 | - } | |
| 4702 | + } else if (['gpt-4', 'gpt-4-0314', 'gpt-4-0613'].includes(value)) { | |
| 4717 | - else if (['gpt-4', 'gpt-4-0314', 'gpt-4-0613'].includes(value)) { | |
| 4718 | 4703 | return max_8k; |
| 4719 | - } | |
| 4704 | + } else if (['gpt-4-32k', 'gpt-4-32k-0314', 'gpt-4-32k-0613'].includes(value)) { | |
| 4720 | - else if (['gpt-4-32k', 'gpt-4-32k-0314', 'gpt-4-32k-0613'].includes(value)) { | |
| 4721 | 4705 | return max_32k; |
| 4722 | - } | |
| 4706 | + } else if (value.includes('gpt-realtime')) { | |
| 4723 | - else if (value.includes('gpt-realtime')) { | |
| 4724 | 4707 | return max_32k; |
| 4725 | - } | |
| 4708 | + } else if (['gpt-3.5-turbo-16k', 'gpt-3.5-turbo-16k-0613'].includes(value)) { | |
| 4726 | - else if (['gpt-3.5-turbo-16k', 'gpt-3.5-turbo-16k-0613'].includes(value)) { | |
| 4727 | 4709 | return max_16k; |
| 4728 | - } | |
| 4710 | + } else if (value == 'code-davinci-002') { | |
| 4729 | - else if (value == 'code-davinci-002') { | |
| 4730 | 4711 | return max_8k; |
| 4731 | - } | |
| 4712 | + } else if (['text-curie-001', 'text-babbage-001', 'text-ada-001'].includes(value)) { | |
| 4732 | - else if (['text-curie-001', 'text-babbage-001', 'text-ada-001'].includes(value)) { | |
| 4733 | 4713 | return max_2k; |
| 4734 | 4714 | } else { |
| 4735 | - else { | |
| 4736 | 4715 | // default to gpt-3 (4095 tokens) |
| 4737 | 4716 | return max_4k; |
| 4738 | 4717 | } |
| @@ -5269,8 +5248,7 @@ async function onModelChange() { | ||
| 5269 | 5248 | if (value && (value.includes('claude') || value.includes('palm-2'))) { |
| 5270 | 5249 | oai_settings.temp_openai = Math.min(claude_max_temp, oai_settings.temp_openai); |
| 5271 | 5250 | $('#temp_openai').attr('max', claude_max_temp).val(oai_settings.temp_openai).trigger('input'); |
| 5272 | 5251 | } else { |
| 5273 | - else { | |
| 5274 | 5252 | oai_settings.temp_openai = Math.min(oai_max_temp, oai_settings.temp_openai); |
| 5275 | 5253 | $('#temp_openai').attr('max', oai_max_temp).val(oai_settings.temp_openai).trigger('input'); |
| 5276 | 5254 | } |
| @@ -5281,17 +5259,13 @@ async function onModelChange() { | ||
| 5281 | 5259 | if (oai_settings.chat_completion_source == chat_completion_sources.CLAUDE) { |
| 5282 | 5260 | if (oai_settings.max_context_unlocked) { |
| 5283 | 5261 | $('#openai_max_context').attr('max', unlocked_max); |
| 5284 | - } | |
| 5262 | + } else if (value.startsWith('claude-sonnet-4-5') || value.startsWith('claude-opus-4-6')) { | |
| 5285 | - else if (value.startsWith('claude-sonnet-4-5') || value.startsWith('claude-opus-4-6')) { | |
| 5286 | 5263 | $('#openai_max_context').attr('max', max_1mil); |
| 5287 | - } | |
| 5264 | + } else if (value == 'claude-2.1' || value.startsWith('claude-3') || value.startsWith('claude-opus') || value.startsWith('claude-haiku') || value.startsWith('claude-sonnet')) { | |
| 5288 | - else if (value == 'claude-2.1' || value.startsWith('claude-3') || value.startsWith('claude-opus') || value.startsWith('claude-haiku') || value.startsWith('claude-sonnet')) { | |
| 5289 | 5265 | $('#openai_max_context').attr('max', max_200k); |
| 5290 | - } | |
| 5266 | + } else if (value.endsWith('100k') || value.startsWith('claude-2') || value === 'claude-instant-1.2') { | |
| 5291 | - else if (value.endsWith('100k') || value.startsWith('claude-2') || value === 'claude-instant-1.2') { | |
| 5292 | 5267 | $('#openai_max_context').attr('max', claude_100k_max); |
| 5293 | 5268 | } else { |
| 5294 | - else { | |
| 5295 | 5269 | $('#openai_max_context').attr('max', claude_max); |
| 5296 | 5270 | } |
| 5297 | 5271 | |
| @@ -5327,23 +5301,17 @@ async function onModelChange() { | ||
| 5327 | 5301 | if (oai_settings.chat_completion_source === chat_completion_sources.COHERE) { |
| 5328 | 5302 | if (oai_settings.max_context_unlocked) { |
| 5329 | 5303 | $('#openai_max_context').attr('max', unlocked_max); |
| 5330 | - } | |
| 5304 | + } else if (['command-light-nightly', 'command-light', 'command'].includes(oai_settings.cohere_model)) { | |
| 5331 | - else if (['command-light-nightly', 'command-light', 'command'].includes(oai_settings.cohere_model)) { | |
| 5332 | 5305 | $('#openai_max_context').attr('max', max_4k); |
| 5333 | - } | |
| 5306 | + } else if (oai_settings.cohere_model.includes('command-r') || ['c4ai-aya-23', 'c4ai-aya-expanse-32b', 'command-nightly', 'command-a-vision-07-2025'].includes(oai_settings.cohere_model)) { | |
| 5334 | - else if (oai_settings.cohere_model.includes('command-r') || ['c4ai-aya-23', 'c4ai-aya-expanse-32b', 'command-nightly', 'command-a-vision-07-2025'].includes(oai_settings.cohere_model)) { | |
| 5335 | 5307 | $('#openai_max_context').attr('max', max_128k); |
| 5336 | - } | |
| 5308 | + } else if (['command-a-03-2025'].includes(oai_settings.cohere_model)) { | |
| 5337 | - else if (['command-a-03-2025'].includes(oai_settings.cohere_model)) { | |
| 5338 | 5309 | $('#openai_max_context').attr('max', max_256k); |
| 5339 | - } | |
| 5310 | + } else if (['c4ai-aya-23-8b', 'c4ai-aya-expanse-8b'].includes(oai_settings.cohere_model)) { | |
| 5340 | - else if (['c4ai-aya-23-8b', 'c4ai-aya-expanse-8b'].includes(oai_settings.cohere_model)) { | |
| 5341 | 5311 | $('#openai_max_context').attr('max', max_8k); |
| 5342 | - } | |
| 5312 | + } else if (['c4ai-aya-vision-8b', 'c4ai-aya-vision-32b'].includes(oai_settings.cohere_model)) { | |
| 5343 | - else if (['c4ai-aya-vision-8b', 'c4ai-aya-vision-32b'].includes(oai_settings.cohere_model)) { | |
| 5344 | 5313 | $('#openai_max_context').attr('max', max_16k); |
| 5345 | 5314 | } else { |
| 5346 | - else { | |
| 5347 | 5315 | $('#openai_max_context').attr('max', max_4k); |
| 5348 | 5316 | } |
| 5349 | 5317 | oai_settings.openai_max_context = Math.min(Number($('#openai_max_context').attr('max')), oai_settings.openai_max_context); |
| @@ -5354,19 +5322,15 @@ async function onModelChange() { | ||
| 5354 | 5322 | if (oai_settings.chat_completion_source === chat_completion_sources.PERPLEXITY) { |
| 5355 | 5323 | if (oai_settings.max_context_unlocked) { |
| 5356 | 5324 | $('#openai_max_context').attr('max', unlocked_max); |
| 5357 | - } | |
| 5325 | + } else if (['sonar', 'sonar-reasoning', 'sonar-reasoning-pro', 'r1-1776'].includes(oai_settings.perplexity_model)) { | |
| 5358 | - else if (['sonar', 'sonar-reasoning', 'sonar-reasoning-pro', 'r1-1776'].includes(oai_settings.perplexity_model)) { | |
| 5359 | 5326 | $('#openai_max_context').attr('max', 127000); |
| 5360 | - } | |
| 5327 | + } else if (['sonar-pro'].includes(oai_settings.perplexity_model)) { | |
| 5361 | - else if (['sonar-pro'].includes(oai_settings.perplexity_model)) { | |
| 5362 | 5328 | $('#openai_max_context').attr('max', 200000); |
| 5363 | - } | |
| 5329 | + } else if (oai_settings.perplexity_model.includes('llama-3.1')) { | |
| 5364 | - else if (oai_settings.perplexity_model.includes('llama-3.1')) { | |
| 5365 | 5330 | const isOnline = oai_settings.perplexity_model.includes('online'); |
| 5366 | 5331 | const contextSize = isOnline ? 128 * 1024 - 4000 : 128 * 1024; |
| 5367 | 5332 | $('#openai_max_context').attr('max', contextSize); |
| 5368 | 5333 | } else { |
| 5369 | - else { | |
| 5370 | 5334 | $('#openai_max_context').attr('max', max_128k); |
| 5371 | 5335 | } |
| 5372 | 5336 | oai_settings.openai_max_context = Math.min(Number($('#openai_max_context').attr('max')), oai_settings.openai_max_context); |
| @@ -5660,81 +5624,57 @@ async function onConnectButtonClick(e) { | ||
| 5660 | 5624 | function toggleChatCompletionForms() { |
| 5661 | 5625 | if (oai_settings.chat_completion_source == chat_completion_sources.CLAUDE) { |
| 5662 | 5626 | $('#model_claude_select').trigger('change'); |
| 5663 | - } | |
| 5627 | + } else if (oai_settings.chat_completion_source == chat_completion_sources.OPENAI) { | |
| 5664 | - else if (oai_settings.chat_completion_source == chat_completion_sources.OPENAI) { | |
| 5665 | 5628 | if (oai_settings.show_external_models && (!Array.isArray(model_list) || model_list.length == 0)) { |
| 5666 | 5629 | // Wait until the models list is loaded so that we could show a proper saved model |
| 5667 | 5630 | } else { |
| 5668 | - else { | |
| 5669 | 5631 | $('#model_openai_select').trigger('change'); |
| 5670 | 5632 | } |
| 5671 | - } | |
| 5633 | + } else if (oai_settings.chat_completion_source == chat_completion_sources.MAKERSUITE) { | |
| 5672 | - else if (oai_settings.chat_completion_source == chat_completion_sources.MAKERSUITE) { | |
| 5673 | 5634 | $('#model_google_select').trigger('change'); |
| 5674 | - } | |
| 5635 | + } else if (oai_settings.chat_completion_source == chat_completion_sources.VERTEXAI) { | |
| 5675 | - else if (oai_settings.chat_completion_source == chat_completion_sources.VERTEXAI) { | |
| 5676 | 5636 | $('#model_vertexai_select').trigger('change'); |
| 5677 | 5637 | // Update UI based on authentication mode |
| 5678 | 5638 | onVertexAIAuthModeChange.call($('#vertexai_auth_mode')[0]); |
| 5679 | - } | |
| 5639 | + } else if (oai_settings.chat_completion_source == chat_completion_sources.OPENROUTER) { | |
| 5680 | - else if (oai_settings.chat_completion_source == chat_completion_sources.OPENROUTER) { | |
| 5681 | 5640 | $('#model_openrouter_select').trigger('change'); |
| 5682 | - } | |
| 5641 | + } else if (oai_settings.chat_completion_source == chat_completion_sources.AI21) { | |
| 5683 | - else if (oai_settings.chat_completion_source == chat_completion_sources.AI21) { | |
| 5684 | 5642 | $('#model_ai21_select').trigger('change'); |
| 5685 | - } | |
| 5643 | + } else if (oai_settings.chat_completion_source == chat_completion_sources.MISTRALAI) { | |
| 5686 | - else if (oai_settings.chat_completion_source == chat_completion_sources.MISTRALAI) { | |
| 5687 | 5644 | $('#model_mistralai_select').trigger('change'); |
| 5688 | - } | |
| 5645 | + } else if (oai_settings.chat_completion_source == chat_completion_sources.COHERE) { | |
| 5689 | - else if (oai_settings.chat_completion_source == chat_completion_sources.COHERE) { | |
| 5690 | 5646 | $('#model_cohere_select').trigger('change'); |
| 5691 | - } | |
| 5647 | + } else if (oai_settings.chat_completion_source == chat_completion_sources.PERPLEXITY) { | |
| 5692 | - else if (oai_settings.chat_completion_source == chat_completion_sources.PERPLEXITY) { | |
| 5693 | 5648 | $('#model_perplexity_select').trigger('change'); |
| 5694 | - } | |
| 5649 | + } else if (oai_settings.chat_completion_source == chat_completion_sources.GROQ) { | |
| 5695 | - else if (oai_settings.chat_completion_source == chat_completion_sources.GROQ) { | |
| 5696 | 5650 | $('#model_groq_select').trigger('change'); |
| 5697 | - } | |
| 5651 | + } else if (oai_settings.chat_completion_source == chat_completion_sources.CHUTES) { | |
| 5698 | - else if (oai_settings.chat_completion_source == chat_completion_sources.CHUTES) { | |
| 5699 | 5652 | $('#model_chutes_select').trigger('change'); |
| 5700 | - } | |
| 5653 | + } else if (oai_settings.chat_completion_source == chat_completion_sources.SILICONFLOW) { | |
| 5701 | - else if (oai_settings.chat_completion_source == chat_completion_sources.SILICONFLOW) { | |
| 5702 | 5654 | $('#model_siliconflow_select').trigger('change'); |
| 5703 | - } | |
| 5655 | + } else if (oai_settings.chat_completion_source == chat_completion_sources.ELECTRONHUB) { | |
| 5704 | - else if (oai_settings.chat_completion_source == chat_completion_sources.ELECTRONHUB) { | |
| 5705 | 5656 | $('#model_electronhub_select').trigger('change'); |
| 5706 | - } | |
| 5657 | + } else if (oai_settings.chat_completion_source == chat_completion_sources.NANOGPT) { | |
| 5707 | - else if (oai_settings.chat_completion_source == chat_completion_sources.NANOGPT) { | |
| 5708 | 5658 | $('#model_nanogpt_select').trigger('change'); |
| 5709 | - } | |
| 5659 | + } else if (oai_settings.chat_completion_source == chat_completion_sources.CUSTOM) { | |
| 5710 | - else if (oai_settings.chat_completion_source == chat_completion_sources.CUSTOM) { | |
| 5711 | 5660 | $('#model_custom_select').trigger('change'); |
| 5712 | - } | |
| 5661 | + } else if (oai_settings.chat_completion_source == chat_completion_sources.DEEPSEEK) { | |
| 5713 | - else if (oai_settings.chat_completion_source == chat_completion_sources.DEEPSEEK) { | |
| 5714 | 5662 | $('#model_deepseek_select').trigger('change'); |
| 5715 | - } | |
| 5663 | + } else if (oai_settings.chat_completion_source == chat_completion_sources.AIMLAPI) { | |
| 5716 | - else if (oai_settings.chat_completion_source == chat_completion_sources.AIMLAPI) { | |
| 5717 | 5664 | $('#model_aimlapi_select').trigger('change'); |
| 5718 | - } | |
| 5665 | + } else if (oai_settings.chat_completion_source == chat_completion_sources.XAI) { | |
| 5719 | - else if (oai_settings.chat_completion_source == chat_completion_sources.XAI) { | |
| 5720 | 5666 | $('#model_xai_select').trigger('change'); |
| 5721 | - } | |
| 5667 | + } else if (oai_settings.chat_completion_source == chat_completion_sources.POLLINATIONS) { | |
| 5722 | - else if (oai_settings.chat_completion_source == chat_completion_sources.POLLINATIONS) { | |
| 5723 | 5668 | $('#model_pollinations_select').trigger('change'); |
| 5724 | - } | |
| 5669 | + } else if (oai_settings.chat_completion_source == chat_completion_sources.MOONSHOT) { | |
| 5725 | - else if (oai_settings.chat_completion_source == chat_completion_sources.MOONSHOT) { | |
| 5726 | 5670 | $('#model_moonshot_select').trigger('change'); |
| 5727 | - } | |
| 5671 | + } else if (oai_settings.chat_completion_source == chat_completion_sources.FIREWORKS) { | |
| 5728 | - else if (oai_settings.chat_completion_source == chat_completion_sources.FIREWORKS) { | |
| 5729 | 5672 | $('#model_fireworks_select').trigger('change'); |
| 5730 | - } | |
| 5673 | + } else if (oai_settings.chat_completion_source == chat_completion_sources.COMETAPI) { | |
| 5731 | - else if (oai_settings.chat_completion_source == chat_completion_sources.COMETAPI) { | |
| 5732 | 5674 | $('#model_cometapi_select').trigger('change'); |
| 5733 | - } | |
| 5675 | + } else if (oai_settings.chat_completion_source == chat_completion_sources.AZURE_OPENAI) { | |
| 5734 | - else if (oai_settings.chat_completion_source == chat_completion_sources.AZURE_OPENAI) { | |
| 5735 | 5676 | $('#azure_openai_model').trigger('change'); |
| 5736 | - } | |
| 5677 | + } else if (oai_settings.chat_completion_source == chat_completion_sources.ZAI) { | |
| 5737 | - else if (oai_settings.chat_completion_source == chat_completion_sources.ZAI) { | |
| 5738 | 5678 | $('#model_zai_select').trigger('change'); |
| 5739 | 5679 | } |
| 5740 | 5680 | |
| @@ -5757,8 +5697,7 @@ async function testApiConnection() { | ||
| 5757 | 5697 | const reply = await sendOpenAIRequest('quiet', [{ 'role': 'user', 'content': 'Hi' }], new AbortController().signal); |
| 5758 | 5698 | console.log(reply); |
| 5759 | 5699 | toastr.success(t`API connection successful!`); |
| 5760 | - } | |
| 5700 | + } catch (err) { | |
| 5761 | - catch (err) { | |
| 5762 | 5701 | toastr.error(t`Could not get a reply from API. Check your connection settings / API key and try again.`); |
| 5763 | 5702 | } |
| 5764 | 5703 | } |
| @@ -1552,9 +1552,8 @@ async function loadPersonaForCurrentChat({ doRender = false } = {}) { | ||
| 1552 | 1552 | } |
| 1553 | 1553 | toastr.success(message, t`Persona Auto Selected`, { escapeHtml: false }); |
| 1554 | 1554 | } |
| 1555 | - } | |
| 1555 | + } else if (chatPersona && power_user.persona_auto_lock && !chat_metadata.persona) { | |
| 1556 | 1556 | // Even if it's the same persona, we still might need to auto-lock to chat if that's enabled |
| 1557 | - else if (chatPersona && power_user.persona_auto_lock && !chat_metadata.persona) { | |
| 1558 | 1557 | await lockPersona('chat'); |
| 1559 | 1558 | } |
| 1560 | 1559 | |
| @@ -810,9 +810,8 @@ async function CreateZenSliders(elmnt) { | ||
| 810 | 810 | handle.text(handleText) |
| 811 | 811 | .css('margin-left', `${leftMargin}px`); |
| 812 | 812 | //console.log(`${newSlider.attr('id')} initial value:${handleText}, stepNum:${stepNumber}, numSteps:${numSteps}, left-margin:${leftMargin}`) |
| 813 | - } | |
| 813 | + } else if (newSlider.attr('id') == 'rep_pen_range_textgenerationwebui_zenslider') { | |
| 814 | 814 | //handling creation of rep_pen_range for ooba |
| 815 | - else if (newSlider.attr('id') == 'rep_pen_range_textgenerationwebui_zenslider') { | |
| 816 | 815 | if ($('#rep_pen_range_textgenerationwebui_zensliders').length !== 0) { |
| 817 | 816 | $('#rep_pen_range_textgenerationwebui_zensliders').remove(); |
| 818 | 817 | } |
| @@ -821,22 +820,19 @@ async function CreateZenSliders(elmnt) { | ||
| 821 | 820 | leftMargin = ((stepNumber) / numSteps) * 50 * -1; |
| 822 | 821 | if (sliderValue === offVal) { |
| 823 | 822 | handleText = 'Off'; |
| 824 | 823 | handle.css('color', 'rgba(128,128,128,0.5)'); |
| 825 | - } | |
| 824 | + } else if (sliderValue === allVal) { handleText = 'All'; } else { handle.css('color', ''); } | |
| 826 | - else if (sliderValue === allVal) { handleText = 'All'; } | |
| 827 | - else { handle.css('color', ''); } | |
| 828 | 825 | handle.text(handleText) |
| 829 | 826 | .css('margin-left', `${leftMargin}px`); |
| 830 | 827 | //console.log(sliderValue, handleText, offVal, allVal) |
| 831 | 828 | //console.log(`${newSlider.attr('id')} sliderValue = ${sliderValue}, handleText:${handleText}, stepNum:${stepNumber}, numSteps:${numSteps}, left-margin:${leftMargin}`) |
| 832 | 829 | originalSlider.val(steps[sliderValue]); |
| 833 | 830 | } else { |
| 834 | 831 | //create all other sliders |
| 835 | - else { | |
| 836 | 832 | var numVal = Number(sliderValue).toFixed(decimals); |
| 837 | 833 | offVal = Number(offVal).toFixed(decimals); |
| 838 | 834 | if (numVal === offVal) { |
| 839 | 835 | handle.text('Off').css('color', 'rgba(128,128,128,0.5)'); |
| 840 | 836 | } else { |
| 841 | 837 | handle.text(numVal).css('color', ''); |
| 842 | 838 | } |
| @@ -928,29 +924,24 @@ async function CreateZenSliders(elmnt) { | ||
| 928 | 924 | width: ${newSlider.width()} |
| 929 | 925 | percent of max: ${percentOfMax} |
| 930 | 926 | left: ${leftPos}`) */ |
| 931 | - //special handling for response length slider, pulls text aliases for step values from an array | |
| 932 | 927 | if (newSlider.attr('id') == 'amount_gen_zenslider') { |
| 928 | + //special handling for response length slider, pulls text aliases for step values from an array | |
| 933 | 929 | handleText = steps[stepNumber]; |
| 934 | 930 | handle.text(handleText); |
| 935 | 931 | newSlider.val(stepNumber); |
| 936 | 932 | numVal = steps[stepNumber]; |
| 937 | - } | |
| 933 | + } else if (newSlider.attr('id') == 'rep_pen_range_textgenerationwebui_zenslider') { | |
| 938 | 934 | //special handling for TextCompletion rep pen range slider, pulls text aliases for step values from an array |
| 939 | - else if (newSlider.attr('id') == 'rep_pen_range_textgenerationwebui_zenslider') { | |
| 940 | 935 | handleText = steps[stepNumber]; |
| 941 | 936 | handle.text(handleText); |
| 942 | 937 | newSlider.val(stepNumber); |
| 943 | 938 | if (numVal === offVal) { handle.text('Off').css('color', 'rgba(128,128,128,0.5)'); } else if (numVal === allVal) { handle.text('All'); } else { handle.css('color', ''); } |
| 944 | - else if (numVal === allVal) { handle.text('All'); } | |
| 945 | - else { handle.css('color', ''); } | |
| 946 | 939 | numVal = steps[stepNumber]; |
| 947 | 940 | } else { |
| 948 | 941 | //everything else uses the flat slider value |
| 949 | 942 | //also note: the above sliders are not custom inputtable due to the array aliasing |
| 950 | - else { | |
| 951 | 943 | //show 'off' if disabled value is set |
| 952 | 944 | if (numVal === offVal) { handle.text('Off').css('color', 'rgba(128,128,128,0.5)'); } else { handle.text(ui.value.toFixed(decimals)).css('color', ''); } |
| 953 | - else { handle.text(ui.value.toFixed(decimals)).css('color', ''); } | |
| 954 | 945 | newSlider.val(handleText); |
| 955 | 946 | } |
| 956 | 947 | //for manually typed-in values we must adjust left position because JQUI doesn't do it for us |
| @@ -991,8 +982,7 @@ function switchSpoilerMode() { | ||
| 991 | 982 | $('#firstMessageWrapper').hide(); |
| 992 | 983 | $('#spoiler_free_desc').addClass('flex1'); |
| 993 | 984 | $('#creators_note_desc_hidden').show(); |
| 994 | 985 | } else { |
| 995 | - else { | |
| 996 | 986 | $('#descriptionWrapper').show(); |
| 997 | 987 | $('#firstMessageWrapper').show(); |
| 998 | 988 | $('#spoiler_free_desc').removeClass('flex1'); |
| @@ -2524,8 +2514,7 @@ async function saveTheme(name = undefined, theme = undefined) { | ||
| 2524 | 2514 | option.value = name; |
| 2525 | 2515 | option.innerText = name; |
| 2526 | 2516 | $('#themes').append(option); |
| 2527 | 2517 | } else { |
| 2528 | - else { | |
| 2529 | 2518 | themes[themeIndex] = theme; |
| 2530 | 2519 | $(`#themes option[value="${name}"]`).prop('selected', true); |
| 2531 | 2520 | } |
| @@ -2632,8 +2621,7 @@ async function saveMovingUI() { | ||
| 2632 | 2621 | option.value = name; |
| 2633 | 2622 | option.innerText = name; |
| 2634 | 2623 | $('#movingUIPresets').append(option); |
| 2635 | 2624 | } else { |
| 2636 | - else { | |
| 2637 | 2625 | movingUIPresets[movingUIPresetIndex] = movingUIPreset; |
| 2638 | 2626 | $(`#movingUIPresets option[value="${name}"]`).prop('selected', true); |
| 2639 | 2627 | } |
| @@ -608,15 +608,13 @@ class PresetManager { | ||
| 608 | 608 | presets[preset_names.indexOf(name)] = preset; |
| 609 | 609 | $(this.select).find(`option[value="${name}"]`).prop('selected', true); |
| 610 | 610 | $(this.select).val(name).trigger('change'); |
| 611 | 611 | } else { |
| 612 | - else { | |
| 613 | 612 | const value = preset_names[name]; |
| 614 | 613 | presets[value] = preset; |
| 615 | 614 | $(this.select).find(`option[value="${value}"]`).prop('selected', true); |
| 616 | 615 | $(this.select).val(value).trigger('change'); |
| 617 | 616 | } |
| 618 | 617 | } else { |
| 619 | - else { | |
| 620 | 618 | presets.push(preset); |
| 621 | 619 | const value = presets.length - 1; |
| 622 | 620 | |
| @@ -246,9 +246,7 @@ async function listSamplers(main_api, arrayOnly = false) { | ||
| 246 | 246 | |
| 247 | 247 | if (prioritizeManualSamplerSelect) { |
| 248 | 248 | finalState = isManuallyActivated; |
| 249 | - } | |
| 249 | + } else if (!isInDefaultState) { | |
| 250 | - | |
| 251 | - else if (!isInDefaultState) { | |
| 252 | 250 | finalState = displayModified === SELECT_SAMPLER.SHOWN; |
| 253 | 251 | customColor = finalState ? forcedOnColoring : forcedOffColoring; |
| 254 | 252 | } |
| @@ -3026,8 +3026,7 @@ export function initDefaultSlashCommands() { | ||
| 3026 | 3026 | try { |
| 3027 | 3027 | const text = await navigator.clipboard.readText(); |
| 3028 | 3028 | return text; |
| 3029 | - } | |
| 3029 | + } catch (error) { | |
| 3030 | - catch (error) { | |
| 3031 | 3030 | console.error('Error reading clipboard:', error); |
| 3032 | 3031 | toastr.warning(t`Failed to read clipboard text. Have you granted the permission?`); |
| 3033 | 3032 | return ''; |
| @@ -4432,8 +4431,7 @@ async function sendUserMessageCallback(args, text) { | ||
| 4432 | 4431 | const name = args.name || ''; |
| 4433 | 4432 | const avatar = findPersonaByName(name) || user_avatar; |
| 4434 | 4433 | message = await sendMessageAsUser(text, bias, insertAt, compact, name, avatar); |
| 4435 | 4434 | } else { |
| 4436 | - else { | |
| 4437 | 4435 | message = await sendMessageAsUser(text, bias, insertAt, compact); |
| 4438 | 4436 | } |
| 4439 | 4437 | |
| @@ -4640,12 +4638,10 @@ export function getNameAndAvatarForMessage(character, name = null) { | ||
| 4640 | 4638 | let force_avatar, original_avatar; |
| 4641 | 4639 | if (character?.avatar === currentChar?.avatar || isNeutralCharacter) { |
| 4642 | 4640 | // If the targeted character is the currently selected one in a solo chat, we don't need to force any avatars |
| 4643 | - } | |
| 4641 | + } else if (character && character.avatar !== 'none') { | |
| 4644 | - else if (character && character.avatar !== 'none') { | |
| 4645 | 4642 | force_avatar = getThumbnailUrl('avatar', character.avatar); |
| 4646 | 4643 | original_avatar = character.avatar; |
| 4647 | 4644 | } else { |
| 4648 | - else { | |
| 4649 | 4645 | force_avatar = default_avatar; |
| 4650 | 4646 | original_avatar = default_avatar; |
| 4651 | 4647 | } |
| @@ -111,8 +111,8 @@ function getDelay(s) { | ||
| 111 | 111 | * @returns {AsyncGenerator<{data: object, chunk: string, reasoning?: boolean}>} The parsed data and the chunk to be sent. |
| 112 | 112 | */ |
| 113 | 113 | async function* parseStreamData(json) { |
| 114 | - // Cohere | |
| 115 | 114 | if (typeof json.delta === 'object' && typeof json.delta.message === 'object' && ['tool-plan-delta', 'content-delta'].includes(json.type)) { |
| 115 | + // Cohere | |
| 116 | 116 | const text = json?.delta?.message?.content?.text ?? ''; |
| 117 | 117 | for (let i = 0; i < text.length; i++) { |
| 118 | 118 | const str = json.delta.message.content.text[i]; |
| @@ -122,9 +122,8 @@ async function* parseStreamData(json) { | ||
| 122 | 122 | }; |
| 123 | 123 | } |
| 124 | 124 | return; |
| 125 | - } | |
| 125 | + } else if (typeof json.delta === 'object' && typeof json.delta.text === 'string') { | |
| 126 | 126 | // Claude |
| 127 | - else if (typeof json.delta === 'object' && typeof json.delta.text === 'string') { | |
| 128 | 127 | if (json.delta.text.length > 0) { |
| 129 | 128 | for (let i = 0; i < json.delta.text.length; i++) { |
| 130 | 129 | const str = json.delta.text[i]; |
| @@ -135,8 +134,8 @@ async function* parseStreamData(json) { | ||
| 135 | 134 | } |
| 136 | 135 | } |
| 137 | 136 | return; |
| 138 | - } | |
| 137 | + } else if (typeof json.delta === 'object' && typeof json.delta.thinking === 'string') { | |
| 139 | - else if (typeof json.delta === 'object' && typeof json.delta.thinking === 'string') { | |
| 138 | + // Claude (reasoning content) | |
| 140 | 139 | if (json.delta.thinking.length > 0) { |
| 141 | 140 | for (let i = 0; i < json.delta.thinking.length; i++) { |
| 142 | 141 | const str = json.delta.thinking[i]; |
| @@ -148,9 +147,8 @@ async function* parseStreamData(json) { | ||
| 148 | 147 | } |
| 149 | 148 | } |
| 150 | 149 | return; |
| 151 | - } | |
| 150 | + } else if (Array.isArray(json.candidates)) { | |
| 152 | - // MakerSuite | |
| 151 | + // Google VertexAI / AI Studio | |
| 153 | - else if (Array.isArray(json.candidates)) { | |
| 154 | 152 | for (let i = 0; i < json.candidates.length; i++) { |
| 155 | 153 | const isNotPrimary = json.candidates?.[0]?.index > 0; |
| 156 | 154 | const hasToolCalls = json?.candidates?.[0]?.content?.parts?.some(p => p?.functionCall); |
| @@ -187,9 +185,8 @@ async function* parseStreamData(json) { | ||
| 187 | 185 | } |
| 188 | 186 | } |
| 189 | 187 | return; |
| 190 | - } | |
| 188 | + } else if (typeof json.token === 'string' && json.token.length > 0) { | |
| 191 | 189 | // NovelAI / KoboldCpp Classic |
| 192 | - else if (typeof json.token === 'string' && json.token.length > 0) { | |
| 193 | 190 | for (let i = 0; i < json.token.length; i++) { |
| 194 | 191 | const str = json.token[i]; |
| 195 | 192 | yield { |
| @@ -198,9 +195,8 @@ async function* parseStreamData(json) { | ||
| 198 | 195 | }; |
| 199 | 196 | } |
| 200 | 197 | return; |
| 201 | - } | |
| 198 | + } else if (typeof json.content === 'string' && json.content.length > 0 && json.object !== 'chat.completion.chunk') { | |
| 202 | 199 | // llama.cpp? |
| 203 | - else if (typeof json.content === 'string' && json.content.length > 0 && json.object !== 'chat.completion.chunk') { | |
| 204 | 200 | const isNotPrimary = json?.index > 0; |
| 205 | 201 | if (isNotPrimary) { |
| 206 | 202 | throw new Error('Not a primary swipe', { cause: NOT_PRIMARY }); |
| @@ -213,9 +209,8 @@ async function* parseStreamData(json) { | ||
| 213 | 209 | }; |
| 214 | 210 | } |
| 215 | 211 | return; |
| 216 | - } | |
| 212 | + } else if (Array.isArray(json.choices)) { | |
| 217 | 213 | // OpenAI-likes and friends |
| 218 | - else if (Array.isArray(json.choices)) { | |
| 219 | 214 | const isNotPrimary = json?.choices?.[0]?.index > 0; |
| 220 | 215 | if (isNotPrimary || json.choices.length === 0) { |
| 221 | 216 | throw new Error('Not a primary swipe', { cause: NOT_PRIMARY }); |
| @@ -233,8 +228,7 @@ async function* parseStreamData(json) { | ||
| 233 | 228 | }; |
| 234 | 229 | } |
| 235 | 230 | return; |
| 236 | - } | |
| 231 | + } else if (typeof json.choices[0].thinking === 'string' && json.choices[0].thinking.length > 0) { | |
| 237 | - else if (typeof json.choices[0].thinking === 'string' && json.choices[0].thinking.length > 0) { | |
| 238 | 232 | for (let j = 0; j < json.choices[0].thinking.length; j++) { |
| 239 | 233 | const str = json.choices[0].thinking[j]; |
| 240 | 234 | const choiceClone = structuredClone(json.choices[0]); |
| @@ -247,8 +241,7 @@ async function* parseStreamData(json) { | ||
| 247 | 241 | }; |
| 248 | 242 | } |
| 249 | 243 | return; |
| 250 | - } | |
| 244 | + } else if (typeof json.choices[0].delta === 'object') { | |
| 251 | - else if (typeof json.choices[0].delta === 'object') { | |
| 252 | 245 | if (typeof json.choices[0].delta.text === 'string' && json.choices[0].delta.text.length > 0) { |
| 253 | 246 | for (let j = 0; j < json.choices[0].delta.text.length; j++) { |
| 254 | 247 | const str = json.choices[0].delta.text[j]; |
| @@ -261,8 +254,7 @@ async function* parseStreamData(json) { | ||
| 261 | 254 | }; |
| 262 | 255 | } |
| 263 | 256 | return; |
| 264 | - } | |
| 257 | + } else if (typeof json.choices[0].delta.reasoning_content === 'string' && json.choices[0].delta.reasoning_content.length > 0) { | |
| 265 | - else if (typeof json.choices[0].delta.reasoning_content === 'string' && json.choices[0].delta.reasoning_content.length > 0) { | |
| 266 | 258 | for (let j = 0; j < json.choices[0].delta.reasoning_content.length; j++) { |
| 267 | 259 | const str = json.choices[0].delta.reasoning_content[j]; |
| 268 | 260 | const isLastSymbol = j === json.choices[0].delta.reasoning_content.length - 1; |
| @@ -277,8 +269,7 @@ async function* parseStreamData(json) { | ||
| 277 | 269 | }; |
| 278 | 270 | } |
| 279 | 271 | return; |
| 280 | - } | |
| 272 | + } else if (typeof json.choices[0].delta.reasoning === 'string' && json.choices[0].delta.reasoning.length > 0) { | |
| 281 | - else if (typeof json.choices[0].delta.reasoning === 'string' && json.choices[0].delta.reasoning.length > 0) { | |
| 282 | 273 | for (let j = 0; j < json.choices[0].delta.reasoning.length; j++) { |
| 283 | 274 | const str = json.choices[0].delta.reasoning[j]; |
| 284 | 275 | const isLastSymbol = j === json.choices[0].delta.reasoning.length - 1; |
| @@ -293,8 +284,7 @@ async function* parseStreamData(json) { | ||
| 293 | 284 | }; |
| 294 | 285 | } |
| 295 | 286 | return; |
| 296 | - } | |
| 287 | + } else if (typeof json.choices[0].delta.content === 'string' && json.choices[0].delta.content.length > 0) { | |
| 297 | - else if (typeof json.choices[0].delta.content === 'string' && json.choices[0].delta.content.length > 0) { | |
| 298 | 288 | for (let j = 0; j < json.choices[0].delta.content.length; j++) { |
| 299 | 289 | const str = json.choices[0].delta.content[j]; |
| 300 | 290 | const choiceClone = structuredClone(json.choices[0]); |
| @@ -306,8 +296,7 @@ async function* parseStreamData(json) { | ||
| 306 | 296 | }; |
| 307 | 297 | } |
| 308 | 298 | return; |
| 309 | - } | |
| 299 | + } else if (Array.isArray(json.choices[0].delta.content) && json.choices[0].delta.content.length > 0) { | |
| 310 | - else if (Array.isArray(json.choices[0].delta.content) && json.choices[0].delta.content.length > 0) { | |
| 311 | 300 | if (Array.isArray(json.choices[0].delta.content[0].thinking) && json.choices[0].delta.content[0].thinking.length > 0) { |
| 312 | 301 | if (typeof json.choices[0].delta.content[0].thinking[0].text === 'string' && json.choices[0].delta.content[0].thinking[0].text.length > 0) { |
| 313 | 302 | for (let j = 0; j < json.choices[0].delta.content[0].thinking[0].text.length; j++) { |
| @@ -325,8 +314,7 @@ async function* parseStreamData(json) { | ||
| 325 | 314 | } |
| 326 | 315 | } |
| 327 | 316 | } |
| 328 | - } | |
| 317 | + } else if (typeof json.choices[0].message === 'object') { | |
| 329 | - else if (typeof json.choices[0].message === 'object') { | |
| 330 | 318 | if (typeof json.choices[0].message.content === 'string' && json.choices[0].message.content.length > 0) { |
| 331 | 319 | for (let j = 0; j < json.choices[0].message.content.length; j++) { |
| 332 | 320 | const str = json.choices[0].message.content[j]; |
| @@ -209,8 +209,7 @@ async function recreateStats() { | ||
| 209 | 209 | if (!response.ok) { |
| 210 | 210 | toastr.error('Stats could not be loaded. Try reloading the page.'); |
| 211 | 211 | throw new Error('Error getting stats'); |
| 212 | 212 | } else { |
| 213 | - else { | |
| 214 | 213 | toastr.success('Stats file recreated successfully!'); |
| 215 | 214 | } |
| 216 | 215 | } |
| @@ -858,8 +858,7 @@ function addTagToMap(tagId, characterId = null) { | ||
| 858 | 858 | if (!Array.isArray(tag_map[key])) { |
| 859 | 859 | tag_map[key] = [tagId]; |
| 860 | 860 | return true; |
| 861 | 861 | } else { |
| 862 | - else { | |
| 863 | 862 | if (tag_map[key].includes(tagId)) |
| 864 | 863 | return false; |
| 865 | 864 | |
| @@ -885,8 +884,7 @@ function removeTagFromMap(tagId, characterId = null) { | ||
| 885 | 884 | if (!Array.isArray(tag_map[key])) { |
| 886 | 885 | tag_map[key] = []; |
| 887 | 886 | return false; |
| 888 | 887 | } else { |
| 889 | - else { | |
| 890 | 888 | const indexOf = tag_map[key].indexOf(tagId); |
| 891 | 889 | tag_map[key].splice(indexOf, 1); |
| 892 | 890 | return indexOf !== -1; |
| @@ -541,14 +541,11 @@ export async function loadFeatherlessModels(data) { | ||
| 541 | 541 | |
| 542 | 542 | if (selectedCategory === 'All') { |
| 543 | 543 | return matchesSearch && matchesClass; |
| 544 | - } | |
| 544 | + } else if (selectedCategory === 'Top') { | |
| 545 | - else if (selectedCategory === 'Top') { | |
| 546 | 545 | return matchesSearch && matchesClass && matchesTop; |
| 547 | - } | |
| 546 | + } else if (selectedCategory === 'New') { | |
| 548 | - else if (selectedCategory === 'New') { | |
| 549 | 547 | return matchesSearch && matchesClass && matchesNew; |
| 550 | 548 | } else { |
| 551 | - else { | |
| 552 | 549 | return matchesSearch && matchesClass; |
| 553 | 550 | } |
| 554 | 551 | }); |
| @@ -1040,12 +1040,10 @@ export function initTextGenSettings() { | ||
| 1040 | 1040 | if (isCheckbox) { |
| 1041 | 1041 | const value = $(this).prop('checked'); |
| 1042 | 1042 | textgenerationwebui_settings[id] = value; |
| 1043 | - } | |
| 1043 | + } else if (isText) { | |
| 1044 | - else if (isText) { | |
| 1045 | 1044 | const value = $(this).val(); |
| 1046 | 1045 | textgenerationwebui_settings[id] = value; |
| 1047 | 1046 | } else { |
| 1048 | - else { | |
| 1049 | 1047 | const value = Number($(this).val()); |
| 1050 | 1048 | $(`#${id}_counter_textgenerationwebui`).val(value); |
| 1051 | 1049 | textgenerationwebui_settings[id] = value; |
| @@ -1254,11 +1252,9 @@ function setSettingByName(setting, value, trigger) { | ||
| 1254 | 1252 | if ('send_banned_tokens' === setting) { |
| 1255 | 1253 | $(`#${setting}_textgenerationwebui`).trigger('change'); |
| 1256 | 1254 | } |
| 1257 | - } | |
| 1255 | + } else if (isText) { | |
| 1258 | - else if (isText) { | |
| 1259 | 1256 | $(`#${setting}_textgenerationwebui`).val(value); |
| 1260 | 1257 | } else { |
| 1261 | - else { | |
| 1262 | 1258 | const val = parseFloat(value); |
| 1263 | 1259 | $(`#${setting}_textgenerationwebui`).val(val); |
| 1264 | 1260 | $(`#${setting}_counter_textgenerationwebui`).val(val); |
| @@ -603,47 +603,34 @@ export function getTokenizerModel() { | ||
| 603 | 603 | |
| 604 | 604 | if (model?.architecture?.tokenizer === 'Llama2') { |
| 605 | 605 | return llamaTokenizer; |
| 606 | - } | |
| 606 | + } else if (model?.architecture?.tokenizer === 'Llama3') { | |
| 607 | - else if (model?.architecture?.tokenizer === 'Llama3') { | |
| 608 | 607 | return llama3Tokenizer; |
| 609 | - } | |
| 608 | + } else if (model?.architecture?.tokenizer === 'Mistral') { | |
| 610 | - else if (model?.architecture?.tokenizer === 'Mistral') { | |
| 611 | 609 | return mistralTokenizer; |
| 612 | - } | |
| 610 | + } else if (model?.architecture?.tokenizer === 'Yi') { | |
| 613 | - else if (model?.architecture?.tokenizer === 'Yi') { | |
| 614 | 611 | return yiTokenizer; |
| 615 | - } | |
| 612 | + } else if (model?.architecture?.tokenizer === 'Gemini') { | |
| 616 | - else if (model?.architecture?.tokenizer === 'Gemini') { | |
| 617 | 613 | return gemmaTokenizer; |
| 618 | - } | |
| 614 | + } else if (model?.architecture?.tokenizer === 'Qwen') { | |
| 619 | - else if (model?.architecture?.tokenizer === 'Qwen') { | |
| 620 | 615 | return qwen2Tokenizer; |
| 621 | - } | |
| 616 | + } else if (model?.architecture?.tokenizer === 'Cohere') { | |
| 622 | - else if (model?.architecture?.tokenizer === 'Cohere') { | |
| 623 | 617 | if (model?.id && model?.id.includes('command-a')) { |
| 624 | 618 | return commandATokenizer; |
| 625 | 619 | } |
| 626 | 620 | return commandRTokenizer; |
| 627 | - } | |
| 621 | + } else if (oai_settings.openrouter_model.includes('gpt-4o')) { | |
| 628 | - else if (oai_settings.openrouter_model.includes('gpt-4o')) { | |
| 629 | 622 | return gpt4oTokenizer; |
| 630 | - } | |
| 623 | + } else if (oai_settings.openrouter_model.includes('gpt-4')) { | |
| 631 | - else if (oai_settings.openrouter_model.includes('gpt-4')) { | |
| 632 | 624 | return gpt4Tokenizer; |
| 633 | - } | |
| 625 | + } else if (oai_settings.openrouter_model.includes('gpt-3.5-turbo')) { | |
| 634 | - else if (oai_settings.openrouter_model.includes('gpt-3.5-turbo')) { | |
| 635 | 626 | return turboTokenizer; |
| 636 | - } | |
| 627 | + } else if (oai_settings.openrouter_model.includes('claude')) { | |
| 637 | - else if (oai_settings.openrouter_model.includes('claude')) { | |
| 638 | 628 | return claudeTokenizer; |
| 639 | - } | |
| 629 | + } else if (oai_settings.openrouter_model.includes('GPT-NeoXT')) { | |
| 640 | - else if (oai_settings.openrouter_model.includes('GPT-NeoXT')) { | |
| 641 | 630 | return gpt2Tokenizer; |
| 642 | - } | |
| 631 | + } else if (oai_settings.openrouter_model.includes('jamba')) { | |
| 643 | - else if (oai_settings.openrouter_model.includes('jamba')) { | |
| 644 | 632 | return jambaTokenizer; |
| 645 | - } | |
| 633 | + } else if (oai_settings.openrouter_model.includes('deepseek')) { | |
| 646 | - else if (oai_settings.openrouter_model.includes('deepseek')) { | |
| 647 | 634 | return deepseekTokenizer; |
| 648 | 635 | } |
| 649 | 636 | } |
| @@ -651,50 +638,35 @@ export function getTokenizerModel() { | ||
| 651 | 638 | if (oai_settings.chat_completion_source == chat_completion_sources.ELECTRONHUB && oai_settings.electronhub_model) { |
| 652 | 639 | if (oai_settings.electronhub_model.includes('gpt-4o') || oai_settings.electronhub_model.includes('gpt-5')) { |
| 653 | 640 | return gpt4oTokenizer; |
| 654 | - } | |
| 641 | + } else if (oai_settings.electronhub_model.includes('gpt-4.1') || oai_settings.electronhub_model.includes('gpt-4.5')) { | |
| 655 | - else if (oai_settings.electronhub_model.includes('gpt-4.1') || oai_settings.electronhub_model.includes('gpt-4.5')) { | |
| 656 | 642 | return gpt4oTokenizer; |
| 657 | - } | |
| 643 | + } else if (oai_settings.electronhub_model.includes('gpt-4')) { | |
| 658 | - else if (oai_settings.electronhub_model.includes('gpt-4')) { | |
| 659 | 644 | return gpt4Tokenizer; |
| 660 | - } | |
| 645 | + } else if (oai_settings.electronhub_model.includes('gpt-3.5-turbo')) { | |
| 661 | - else if (oai_settings.electronhub_model.includes('gpt-3.5-turbo')) { | |
| 662 | 646 | return turboTokenizer; |
| 663 | - } | |
| 647 | + } else if (oai_settings.electronhub_model.includes('claude')) { | |
| 664 | - else if (oai_settings.electronhub_model.includes('claude')) { | |
| 665 | 648 | return claudeTokenizer; |
| 666 | - } | |
| 649 | + } else if (oai_settings.electronhub_model.includes('jamba')) { | |
| 667 | - else if (oai_settings.electronhub_model.includes('jamba')) { | |
| 668 | 650 | return jambaTokenizer; |
| 669 | - } | |
| 651 | + } else if (oai_settings.electronhub_model.includes('deepseek') || oai_settings.electronhub_model.includes('sonar-reasoning') || oai_settings.electronhub_model.includes('r1')) { | |
| 670 | - else if (oai_settings.electronhub_model.includes('deepseek') || oai_settings.electronhub_model.includes('sonar-reasoning') || oai_settings.electronhub_model.includes('r1')) { | |
| 671 | 652 | return deepseekTokenizer; |
| 672 | - } | |
| 653 | + } else if (oai_settings.electronhub_model.includes('qwen')) { | |
| 673 | - else if (oai_settings.electronhub_model.includes('qwen')) { | |
| 674 | 654 | return qwen2Tokenizer; |
| 675 | - } | |
| 655 | + } else if (oai_settings.electronhub_model.includes('gemma')) { | |
| 676 | - else if (oai_settings.electronhub_model.includes('gemma')) { | |
| 677 | 656 | return gemmaTokenizer; |
| 678 | - } | |
| 657 | + } else if (oai_settings.electronhub_model.includes('mistral')) { | |
| 679 | - else if (oai_settings.electronhub_model.includes('mistral')) { | |
| 680 | 658 | return mistralTokenizer; |
| 681 | - } | |
| 659 | + } else if (oai_settings.electronhub_model.includes('yi')) { | |
| 682 | - else if (oai_settings.electronhub_model.includes('yi')) { | |
| 683 | 660 | return yiTokenizer; |
| 684 | - } | |
| 661 | + } else if (oai_settings.electronhub_model.includes('llama3') || oai_settings.electronhub_model.includes('llama-3') || oai_settings.electronhub_model.startsWith('l3')) { | |
| 685 | - else if (oai_settings.electronhub_model.includes('llama3') || oai_settings.electronhub_model.includes('llama-3') || oai_settings.electronhub_model.startsWith('l3')) { | |
| 686 | 662 | return llama3Tokenizer; |
| 687 | - } | |
| 663 | + } else if (oai_settings.electronhub_model.includes('llama')) { | |
| 688 | - else if (oai_settings.electronhub_model.includes('llama')) { | |
| 689 | 664 | return llamaTokenizer; |
| 690 | - } | |
| 665 | + } else if (oai_settings.electronhub_model.includes('command-a')) { | |
| 691 | - else if (oai_settings.electronhub_model.includes('command-a')) { | |
| 692 | 666 | return commandATokenizer; |
| 693 | - } | |
| 667 | + } else if (oai_settings.electronhub_model.includes('command-r')) { | |
| 694 | - else if (oai_settings.electronhub_model.includes('command-r')) { | |
| 695 | 668 | return commandRTokenizer; |
| 696 | - } | |
| 669 | + } else if (oai_settings.electronhub_model.includes('nemo')) { | |
| 697 | - else if (oai_settings.electronhub_model.includes('nemo')) { | |
| 698 | 670 | return nemoTokenizer; |
| 699 | 671 | } |
| 700 | 672 | } |
| @@ -814,9 +786,7 @@ export function countTokensOpenAI(messages, full = false) { | ||
| 814 | 786 | |
| 815 | 787 | if (typeof cachedCount === 'number') { |
| 816 | 788 | token_count += cachedCount; |
| 817 | 789 | } else { |
| 818 | - | |
| 819 | - else { | |
| 820 | 790 | jQuery.ajax({ |
| 821 | 791 | async: false, |
| 822 | 792 | type: 'POST', // |
| @@ -866,9 +836,7 @@ export async function countTokensOpenAIAsync(messages, full = false) { | ||
| 866 | 836 | |
| 867 | 837 | if (typeof cachedCount === 'number') { |
| 868 | 838 | token_count += cachedCount; |
| 869 | 839 | } else { |
| 870 | - | |
| 871 | - else { | |
| 872 | 840 | const data = await jQuery.ajax({ |
| 873 | 841 | async: true, |
| 874 | 842 | type: 'POST', // |
| @@ -898,8 +866,7 @@ function getTokenCacheObject() { | ||
| 898 | 866 | try { |
| 899 | 867 | if (selected_group) { |
| 900 | 868 | chatId = groups.find(x => x.id == selected_group)?.chat_id; |
| 901 | - } | |
| 869 | + } else if (this_chid !== undefined) { | |
| 902 | - else if (this_chid !== undefined) { | |
| 903 | 870 | chatId = characters[this_chid].chat; |
| 904 | 871 | } |
| 905 | 872 | } catch { |
| @@ -327,8 +327,7 @@ async function changePassword(handle, callback) { | ||
| 327 | 327 | |
| 328 | 328 | toastr.success('Password changed successfully', 'Password Changed'); |
| 329 | 329 | callback(); |
| 330 | - } | |
| 330 | + } catch (error) { | |
| 331 | - catch (error) { | |
| 332 | 331 | console.error('Error changing password:', error); |
| 333 | 332 | } |
| 334 | 333 | } |
| @@ -36,8 +36,7 @@ export class SimpleMutex { | ||
| 36 | 36 | try { |
| 37 | 37 | this.isBusy = true; |
| 38 | 38 | await this.callback(...args); |
| 39 | 39 | } finally { |
| 40 | - finally { | |
| 41 | 40 | this.isBusy = false; |
| 42 | 41 | } |
| 43 | 42 | } |
| @@ -388,8 +388,7 @@ async function timesCallback(args, value) { | ||
| 388 | 388 | command.breakController = new SlashCommandBreakController(); |
| 389 | 389 | command.scope.setMacro('timesIndex', i); |
| 390 | 390 | result = await command.execute(); |
| 391 | 391 | } else { |
| 392 | - else { | |
| 393 | 392 | result = await executeSubCommands(command.replace(/\{\{timesIndex\}\}/g, i.toString()), args._scope, args._parserFlags, args._abortController); |
| 394 | 393 | } |
| 395 | 394 | if (result.isAborted) break; |
| @@ -716,8 +716,7 @@ export async function openPermanentAssistantChat({ tryCreate = true, created = f | ||
| 716 | 716 | console.log(`Character not found for avatar ID: ${avatar}. Creating new assistant.`); |
| 717 | 717 | await createPermanentAssistant(); |
| 718 | 718 | return openPermanentAssistantChat({ tryCreate: false, created: true }); |
| 719 | - } | |
| 719 | + } catch (error) { | |
| 720 | - catch (error) { | |
| 721 | 720 | console.error('Error creating permanent assistant:', error); |
| 722 | 721 | toastr.error(t`Failed to create ${neutralCharacterName}. See console for details.`); |
| 723 | 722 | return; |
| @@ -351,8 +351,7 @@ class WorldInfoBuffer { | ||
| 351 | 351 | |
| 352 | 352 | if (keyWords.length > 1) { |
| 353 | 353 | return haystack.includes(transformedString); |
| 354 | 354 | } else { |
| 355 | - else { | |
| 356 | 355 | // Use custom boundaries to include punctuation and other non-alphanumeric characters |
| 357 | 356 | const regex = new RegExp(`(?:^|\\W)(${escapeRegex(transformedString)})(?:$|\\W)`); |
| 358 | 357 | if (regex.test(haystack)) { |
| @@ -1141,8 +1140,7 @@ function registerWorldInfoSlashCommands() { | ||
| 1141 | 1140 | // Also assign the book now - additional if requested, otherwise as primary |
| 1142 | 1141 | if (type === 'additional') { |
| 1143 | 1142 | await charUpdateAddAuxWorld(character.avatar, newName); |
| 1144 | 1143 | } else { |
| 1145 | - else { | |
| 1146 | 1144 | await charUpdatePrimaryWorld(newName); |
| 1147 | 1145 | } |
| 1148 | 1146 | // Refresh UI, if needed |
| @@ -2169,8 +2167,7 @@ export function sortWorldInfoEntries(data, { customSort = null } = {}) { | ||
| 2169 | 2167 | const bScore = worldInfoFilter.getScore(FILTER_TYPES.WORLD_INFO_SEARCH, b.uid); |
| 2170 | 2168 | return aScore - bScore; |
| 2171 | 2169 | }; |
| 2172 | - } | |
| 2170 | + } else if (sortRule === 'custom') { | |
| 2173 | - else if (sortRule === 'custom') { | |
| 2174 | 2171 | // First by display index |
| 2175 | 2172 | primarySort = (a, b) => { |
| 2176 | 2173 | const aValue = a.displayIndex; |
| @@ -4434,8 +4431,7 @@ export async function getSortedEntries() { | ||
| 4434 | 4431 | |
| 4435 | 4432 | // Need to deep clone the entries to avoid modifying the cached data |
| 4436 | 4433 | return structuredClone(entries); |
| 4437 | - } | |
| 4434 | + } catch (e) { | |
| 4438 | - catch (e) { | |
| 4439 | 4435 | console.error(e); |
| 4440 | 4436 | return []; |
| 4441 | 4437 | } |
| @@ -4481,8 +4477,7 @@ function parseDecorators(content) { | ||
| 4481 | 4477 | if (isKnownDecorator(splited[i])) { |
| 4482 | 4478 | decorators.push(splited[i].startsWith('@@@') ? splited[i].substring(1) : splited[i]); |
| 4483 | 4479 | fallbacked = false; |
| 4484 | 4480 | } else { |
| 4485 | - else { | |
| 4486 | 4481 | fallbacked = true; |
| 4487 | 4482 | } |
| 4488 | 4483 | } else { |
| @@ -5506,8 +5501,7 @@ export function checkEmbeddedWorld(chid) { | ||
| 5506 | 5501 | } |
| 5507 | 5502 | }; |
| 5508 | 5503 | callGenericPopup(html, POPUP_TYPE.CONFIRM, '', { okButton: 'Yes' }).then(checkResult); |
| 5509 | 5504 | } else { |
| 5510 | - else { | |
| 5511 | 5505 | toastr.info( |
| 5512 | 5506 | 'To import and use it, select "Import Card Lore" in the "More..." dropdown menu on the character panel.', |
| 5513 | 5507 | `${characters[chid].name} has an embedded World/Lorebook`, |
| @@ -6121,8 +6115,7 @@ export function initWorldInfo() { | ||
| 6121 | 6115 | } else if (hasEmbed && !event.shiftKey) { |
| 6122 | 6116 | await importEmbeddedWorldInfo(); |
| 6123 | 6117 | saveCharacterDebounced(); |
| 6124 | 6118 | } else { |
| 6125 | - else { | |
| 6126 | 6119 | openSetWorldMenu(); |
| 6127 | 6120 | } |
| 6128 | 6121 | }); |
| @@ -173,8 +173,7 @@ router.post('/get', async (request, response) => { | ||
| 173 | 173 | } |
| 174 | 174 | } |
| 175 | 175 | } |
| 176 | - } | |
| 176 | + } catch (err) { | |
| 177 | - catch (err) { | |
| 178 | 177 | console.error(err); |
| 179 | 178 | } |
| 180 | 179 | return response.send(output); |
| @@ -255,8 +254,7 @@ router.post('/download', async (request, response) => { | ||
| 255 | 254 | fs.copyFileSync(temp_path, file_path); |
| 256 | 255 | fs.unlinkSync(temp_path); |
| 257 | 256 | response.sendStatus(200); |
| 258 | - } | |
| 257 | + } catch (error) { | |
| 259 | - catch (error) { | |
| 260 | 258 | console.error(error); |
| 261 | 259 | response.sendStatus(500); |
| 262 | 260 | } |
| @@ -299,15 +297,13 @@ router.post('/delete', async (request, response) => { | ||
| 299 | 297 | if (err) throw err; |
| 300 | 298 | }); |
| 301 | 299 | console.info('Asset deleted.'); |
| 302 | 300 | } else { |
| 303 | - else { | |
| 304 | 301 | console.error('Asset not found.'); |
| 305 | 302 | response.sendStatus(400); |
| 306 | 303 | } |
| 307 | 304 | // Move into asset place |
| 308 | 305 | response.sendStatus(200); |
| 309 | - } | |
| 306 | + } catch (error) { | |
| 310 | - catch (error) { | |
| 311 | 307 | console.error(error); |
| 312 | 308 | response.sendStatus(500); |
| 313 | 309 | } |
| @@ -372,8 +368,7 @@ router.post('/character', async (request, response) => { | ||
| 372 | 368 | output.push(`/characters/${name}/${category}/${i}`); |
| 373 | 369 | } |
| 374 | 370 | return response.send(output); |
| 375 | - } | |
| 371 | + } catch (err) { | |
| 376 | - catch (err) { | |
| 377 | 372 | console.error(err); |
| 378 | 373 | return response.sendStatus(500); |
| 379 | 374 | } |
| @@ -1425,8 +1425,7 @@ async function sendElectronHubRequest(request, response) { | ||
| 1425 | 1425 | console.debug('Electron Hub response:', generateResponseJson); |
| 1426 | 1426 | return response.send(generateResponseJson); |
| 1427 | 1427 | } |
| 1428 | - } | |
| 1428 | + } catch (error) { | |
| 1429 | - catch (error) { | |
| 1430 | 1429 | console.error('Error communicating with Electron Hub: ', error); |
| 1431 | 1430 | if (!response.headersSent) { |
| 1432 | 1431 | response.send({ error: true }); |
| @@ -1527,8 +1526,7 @@ async function sendChutesRequest(request, response) { | ||
| 1527 | 1526 | console.debug('Chutes response:', generateResponseJson); |
| 1528 | 1527 | return response.send(generateResponseJson); |
| 1529 | 1528 | } |
| 1530 | - } | |
| 1529 | + } catch (error) { | |
| 1531 | - catch (error) { | |
| 1532 | 1530 | console.error('Error communicating with Chutes: ', error); |
| 1533 | 1531 | if (!response.headersSent) { |
| 1534 | 1532 | response.send({ error: true }); |
| @@ -1910,8 +1908,7 @@ router.post('/status', async function (request, statusResponse) { | ||
| 1910 | 1908 | console.warn('Chat Completion endpoint did not return a list of models.'); |
| 1911 | 1909 | } |
| 1912 | 1910 | } |
| 1913 | 1911 | } else { |
| 1914 | - else { | |
| 1915 | 1912 | console.error('Chat Completion status check failed. Either Access Token is incorrect or API endpoint is down.'); |
| 1916 | 1913 | statusResponse.send({ error: true, data: { data: [] } }); |
| 1917 | 1914 | } |
| @@ -405,8 +405,7 @@ router.post('/generate', async function (request, response) { | ||
| 405 | 405 | const completionsStream = await fetch(url, args); |
| 406 | 406 | // Pipe remote SSE stream to Express response |
| 407 | 407 | forwardFetchResponse(completionsStream, response); |
| 408 | 408 | } else { |
| 409 | - else { | |
| 410 | 409 | const completionsReply = await fetch(url, args); |
| 411 | 410 | |
| 412 | 411 | if (completionsReply.ok) { |
| @@ -45,8 +45,7 @@ router.post('/chat/delete', async (request, response) => { | ||
| 45 | 45 | |
| 46 | 46 | await fsPromises.unlink(filePath); |
| 47 | 47 | return response.sendStatus(200); |
| 48 | - } | |
| 48 | + } catch (error) { | |
| 49 | - catch (error) { | |
| 50 | 49 | console.error(error); |
| 51 | 50 | return response.sendStatus(500); |
| 52 | 51 | } |
| @@ -67,8 +66,7 @@ router.post('/chat/download', async (request, response) => { | ||
| 67 | 66 | } |
| 68 | 67 | |
| 69 | 68 | return response.download(filePath); |
| 70 | - } | |
| 69 | + } catch (error) { | |
| 71 | - catch (error) { | |
| 72 | 70 | console.error(error); |
| 73 | 71 | return response.sendStatus(500); |
| 74 | 72 | } |
| @@ -326,9 +326,8 @@ async function tryReadImage(imgPath, crop) { | ||
| 326 | 326 | try { |
| 327 | 327 | const rawImg = await Jimp.read(imgPath); |
| 328 | 328 | return await applyAvatarCropResize(rawImg, crop); |
| 329 | - } | |
| 329 | + } catch (error) { | |
| 330 | 330 | // If it's an unsupported type of image (APNG) - just read the file as buffer |
| 331 | - catch (error) { | |
| 332 | 331 | console.error(`Failed to read image: ${imgPath}`, error); |
| 333 | 332 | return fs.readFileSync(imgPath); |
| 334 | 333 | } |
| @@ -423,8 +422,7 @@ const processCharacter = async (item, directories, { shallow }) => { | ||
| 423 | 422 | character.date_last_chat = dateLastChat; |
| 424 | 423 | character.data_size = calculateDataSize(jsonObject?.data); |
| 425 | 424 | return shallow ? toShallow(character) : character; |
| 426 | - } | |
| 425 | + } catch (err) { | |
| 427 | - catch (err) { | |
| 428 | 426 | console.error(`Could not process character: ${item}`); |
| 429 | 427 | |
| 430 | 428 | if (err instanceof SyntaxError) { |
| @@ -1081,8 +1079,7 @@ router.post('/rename', validateAvatarUrlMiddleware, async function (request, res | ||
| 1081 | 1079 | |
| 1082 | 1080 | // Return new avatar name to ST |
| 1083 | 1081 | return response.send({ avatar: newAvatarName }); |
| 1084 | - } | |
| 1082 | + } catch (err) { | |
| 1085 | - catch (err) { | |
| 1086 | 1083 | console.error(err); |
| 1087 | 1084 | return response.sendStatus(500); |
| 1088 | 1085 | } |
| @@ -1495,8 +1492,7 @@ router.post('/duplicate', validateAvatarUrlMiddleware, async function (request, | ||
| 1495 | 1492 | fs.copyFileSync(filename, newFilename); |
| 1496 | 1493 | console.info(`${filename} was copied to ${newFilename}`); |
| 1497 | 1494 | response.send({ path: path.parse(newFilename).base }); |
| 1498 | - } | |
| 1495 | + } catch (error) { | |
| 1499 | - catch (error) { | |
| 1500 | 1496 | console.error(error); |
| 1501 | 1497 | return response.send({ error: true }); |
| 1502 | 1498 | } |
| @@ -1532,8 +1528,7 @@ router.post('/export', validateAvatarUrlMiddleware, async function (request, res | ||
| 1532 | 1528 | const jsonObject = getCharaCardV2(JSON.parse(json), request.user.directories); |
| 1533 | 1529 | unsetPrivateFields(jsonObject); |
| 1534 | 1530 | return response.type('json').send(JSON.stringify(jsonObject, null, 4)); |
| 1535 | 1531 | } catch { |
| 1536 | - catch { | |
| 1537 | 1532 | return response.sendStatus(400); |
| 1538 | 1533 | } |
| 1539 | 1534 | } |
| @@ -837,8 +837,7 @@ router.post('/group/save', async function (request, response) { | ||
| 837 | 837 | if (Array.isArray(chatData)) { |
| 838 | 838 | await trySaveChat(chatData, chatFilePath, request.body.force, handle, String(id), request.user.directories.backups); |
| 839 | 839 | return response.send({ ok: true }); |
| 840 | 840 | } else { |
| 841 | - else { | |
| 842 | 841 | return response.status(400).send({ error: 'The request\'s body.chat is not an array.' }); |
| 843 | 842 | } |
| 844 | 843 | } catch (error) { |
| @@ -941,12 +941,10 @@ router.post('/importURL', async (request, response) => { | ||
| 941 | 941 | if (chubParsed?.type === 'character') { |
| 942 | 942 | console.info('Downloading chub character:', chubParsed.id); |
| 943 | 943 | result = await downloadChubCharacter(chubParsed.id); |
| 944 | - } | |
| 944 | + } else if (chubParsed?.type === 'lorebook') { | |
| 945 | - else if (chubParsed?.type === 'lorebook') { | |
| 946 | 945 | console.info('Downloading chub lorebook:', chubParsed.id); |
| 947 | 946 | result = await downloadChubLorebook(chubParsed.id); |
| 948 | 947 | } else { |
| 949 | - else { | |
| 950 | 948 | return response.sendStatus(404); |
| 951 | 949 | } |
| 952 | 950 | } else if (isRisu) { |
| @@ -1020,12 +1018,10 @@ router.post('/importUUID', async (request, response) => { | ||
| 1020 | 1018 | if (uuidType === 'character') { |
| 1021 | 1019 | console.info('Downloading chub character:', uuid); |
| 1022 | 1020 | result = await downloadChubCharacter(uuid); |
| 1023 | - } | |
| 1021 | + } else if (uuidType === 'lorebook') { | |
| 1024 | - else if (uuidType === 'lorebook') { | |
| 1025 | 1022 | console.info('Downloading chub lorebook:', uuid); |
| 1026 | 1023 | result = await downloadChubLorebook(uuid); |
| 1027 | 1024 | } else { |
| 1028 | - else { | |
| 1029 | 1025 | return response.sendStatus(404); |
| 1030 | 1026 | } |
| 1031 | 1027 | } |
| @@ -145,8 +145,7 @@ router.post('/all', (request, response) => { | ||
| 145 | 145 | group.date_last_chat = date_last_chat; |
| 146 | 146 | group.chat_size = chat_size; |
| 147 | 147 | groups.push(group); |
| 148 | - } | |
| 148 | + } catch (error) { | |
| 149 | - catch (error) { | |
| 150 | 149 | console.error(error); |
| 151 | 150 | } |
| 152 | 151 | }); |
| @@ -113,8 +113,7 @@ router.post('/text-models', async (request, response) => { | ||
| 113 | 113 | try { |
| 114 | 114 | const metadata = await getHordeTextModelMetadata(); |
| 115 | 115 | data = await mergeModelsAndMetadata(data, metadata); |
| 116 | - } | |
| 116 | + } catch (error) { | |
| 117 | - catch (error) { | |
| 118 | 117 | console.error('Failed to fetch metadata:', error); |
| 119 | 118 | } |
| 120 | 119 | |
| @@ -154,8 +154,7 @@ router.post('/status', async function (req, res) { | ||
| 154 | 154 | } else if (response.status == 401) { |
| 155 | 155 | console.error('NovelAI Access Token is incorrect.'); |
| 156 | 156 | return res.send({ error: true }); |
| 157 | 157 | } else { |
| 158 | - else { | |
| 159 | 158 | console.warn('NovelAI returned an error:', response.statusText); |
| 160 | 159 | return res.send({ error: true }); |
| 161 | 160 | } |
| @@ -281,8 +280,7 @@ router.post('/generate', async function (req, res) { | ||
| 281 | 280 | try { |
| 282 | 281 | const data = JSON.parse(text); |
| 283 | 282 | message = data.message; |
| 284 | 283 | } catch { |
| 285 | - catch { | |
| 286 | 284 | // ignore |
| 287 | 285 | } |
| 288 | 286 | |
| @@ -476,8 +474,7 @@ router.post('/generate-voice', async (request, response) => { | ||
| 476 | 474 | const buffer = Buffer.concat(chunks.map(chunk => new Uint8Array(chunk))); |
| 477 | 475 | response.setHeader('Content-Type', 'audio/mpeg'); |
| 478 | 476 | return response.send(buffer); |
| 479 | - } | |
| 477 | + } catch (error) { | |
| 480 | - catch (error) { | |
| 481 | 478 | console.error(error); |
| 482 | 479 | return response.sendStatus(500); |
| 483 | 480 | } |
| @@ -262,8 +262,7 @@ router.post('/caption-image', async (request, response) => { | ||
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | return response.json({ caption }); |
| 265 | - } | |
| 265 | + } catch (error) { | |
| 266 | - catch (error) { | |
| 267 | 266 | console.error(error); |
| 268 | 267 | response.status(500).send('Internal server error'); |
| 269 | 268 | } |
| @@ -58,8 +58,7 @@ function readAndParseFromDirectory(directoryPath, fileExtension = '.json') { | ||
| 58 | 58 | try { |
| 59 | 59 | const file = fs.readFileSync(path.join(directoryPath, item), 'utf-8'); |
| 60 | 60 | parsedFiles.push(fileExtension == '.json' ? JSON.parse(file) : file); |
| 61 | 61 | } catch { |
| 62 | - catch { | |
| 63 | 62 | // skip |
| 64 | 63 | } |
| 65 | 64 | }); |
| @@ -143,8 +143,7 @@ router.get('/get', function (request, response) { | ||
| 143 | 143 | }; |
| 144 | 144 | }); |
| 145 | 145 | } |
| 146 | - } | |
| 146 | + } catch (err) { | |
| 147 | - catch (err) { | |
| 148 | 147 | console.error(err); |
| 149 | 148 | } |
| 150 | 149 | return response.send(sprites); |
| @@ -1316,8 +1316,7 @@ chutes.post('/models', async (request, response) => { | ||
| 1316 | 1316 | const chutesData = /** @type {{items: Array<{name: string}>}} */ (data); |
| 1317 | 1317 | const models = chutesData.items.map(x => ({ value: x.name, text: x.name })).sort((a, b) => a?.text?.localeCompare(b?.text)); |
| 1318 | 1318 | return response.send(models); |
| 1319 | - } | |
| 1319 | + } catch (error) { | |
| 1320 | - catch (error) { | |
| 1321 | 1320 | console.error(error); |
| 1322 | 1321 | return response.sendStatus(500); |
| 1323 | 1322 | } |
| @@ -1363,8 +1362,7 @@ chutes.post('/generate', async (request, response) => { | ||
| 1363 | 1362 | const base64 = Buffer.from(buffer).toString('base64'); |
| 1364 | 1363 | |
| 1365 | 1364 | return response.send({ image: base64 }); |
| 1366 | - } | |
| 1365 | + } catch (error) { | |
| 1367 | - catch (error) { | |
| 1368 | 1366 | console.error(error); |
| 1369 | 1367 | return response.sendStatus(500); |
| 1370 | 1368 | } |
| @@ -1405,8 +1403,7 @@ nanogpt.post('/models', async (request, response) => { | ||
| 1405 | 1403 | |
| 1406 | 1404 | const models = Object.values(imageModels).map(x => ({ value: x.model, text: x.name })); |
| 1407 | 1405 | return response.send(models); |
| 1408 | - } | |
| 1406 | + } catch (error) { | |
| 1409 | - catch (error) { | |
| 1410 | 1407 | console.error(error); |
| 1411 | 1408 | return response.sendStatus(500); |
| 1412 | 1409 | } |
| @@ -1447,8 +1444,7 @@ nanogpt.post('/generate', async (request, response) => { | ||
| 1447 | 1444 | } |
| 1448 | 1445 | |
| 1449 | 1446 | return response.send({ image }); |
| 1450 | - } | |
| 1447 | + } catch (error) { | |
| 1451 | - catch (error) { | |
| 1452 | 1448 | console.error(error); |
| 1453 | 1449 | return response.sendStatus(500); |
| 1454 | 1450 | } |
| @@ -939,8 +939,7 @@ export function mergeMessages(messages, names, { strict = false, placeholders = | ||
| 939 | 939 | if (mergedMessages.length && placeholders) { |
| 940 | 940 | if (mergedMessages[0].role === 'system' && (mergedMessages.length === 1 || mergedMessages[1].role !== 'user')) { |
| 941 | 941 | mergedMessages.splice(1, 0, { role: 'user', content: PROMPT_PLACEHOLDER }); |
| 942 | - } | |
| 942 | + } else if (mergedMessages[0].role !== 'system' && mergedMessages[0].role !== 'user') { | |
| 943 | - else if (mergedMessages[0].role !== 'system' && mergedMessages[0].role !== 'user') { | |
| 944 | 943 | mergedMessages.unshift({ role: 'user', content: PROMPT_PLACEHOLDER }); |
| 945 | 944 | } |
| 946 | 945 | } |
| @@ -964,11 +963,9 @@ export function convertTextCompletionPrompt(messages) { | ||
| 964 | 963 | messages.forEach(m => { |
| 965 | 964 | if (m.role === 'system' && m.name === undefined) { |
| 966 | 965 | messageStrings.push('System: ' + m.content); |
| 967 | - } | |
| 966 | + } else if (m.role === 'system' && m.name !== undefined) { | |
| 968 | - else if (m.role === 'system' && m.name !== undefined) { | |
| 969 | 967 | messageStrings.push(m.name + ': ' + m.content); |
| 970 | 968 | } else { |
| 971 | - else { | |
| 972 | 969 | messageStrings.push(m.role + ': ' + m.content); |
| 973 | 970 | } |
| 974 | 971 | }); |
| @@ -680,8 +680,7 @@ export async function getUserAvatar(handle) { | ||
| 680 | 680 | const mimeType = mime.lookup(avatarPath); |
| 681 | 681 | const base64Content = fs.readFileSync(avatarPath, 'base64'); |
| 682 | 682 | return `data:${mimeType};base64,${base64Content}`; |
| 683 | 683 | } catch { |
| 684 | - catch { | |
| 685 | 684 | // Ignore errors |
| 686 | 685 | return PUBLIC_USER_AVATAR; |
| 687 | 686 | } |
| @@ -157,8 +157,7 @@ export async function getVersion() { | ||
| 157 | 157 | const remoteLatest = await git.revparse([trackingBranch]); |
| 158 | 158 | isLatest = localLatest === remoteLatest; |
| 159 | 159 | } |
| 160 | 160 | } catch { |
| 161 | - catch { | |
| 162 | 161 | // suppress exception |
| 163 | 162 | } |
| 164 | 163 | |
| @@ -821,8 +820,7 @@ export function mergeObjectWithYaml(obj, yamlString) { | ||
| 821 | 820 | Object.assign(obj, item); |
| 822 | 821 | } |
| 823 | 822 | } |
| 824 | - } | |
| 823 | + } else if (parsedObject && typeof parsedObject === 'object') { | |
| 825 | - else if (parsedObject && typeof parsedObject === 'object') { | |
| 826 | 824 | Object.assign(obj, parsedObject); |
| 827 | 825 | } |
| 828 | 826 | } catch { |
| @@ -1307,8 +1305,7 @@ export function safeReadFileSync(filePath, options = { encoding: 'utf-8' }) { | ||
| 1307 | 1305 | export function setWindowTitle(title) { |
| 1308 | 1306 | if (process.platform === 'win32') { |
| 1309 | 1307 | process.title = title; |
| 1310 | 1308 | } else { |
| 1311 | - else { | |
| 1312 | 1309 | process.stdout.write(`\x1b]2;${title}\x1b\x5c`); |
| 1313 | 1310 | } |
| 1314 | 1311 | } |
| @@ -34,8 +34,7 @@ async function getExtrasVectorImpl(text, apiUrl, apiKey) { | ||
| 34 | 34 | try { |
| 35 | 35 | url = new URL(apiUrl); |
| 36 | 36 | url.pathname = '/api/embeddings/compute'; |
| 37 | - } | |
| 37 | + } catch (error) { | |
| 38 | - catch (error) { | |
| 39 | 38 | console.error('Failed to set up Extras API call:', error); |
| 40 | 39 | console.debug('Extras API URL given was:', apiUrl); |
| 41 | 40 | throw error; |