import { humanizedDateTime, favsToHotswap, getMessageTimeStamp, dragElement, isMobile, } from "./scripts/RossAscends-mods.js"; import { userStatsHandler, statMesProcess } from './scripts/stats.js'; import { encode } from "../scripts/gpt-2-3-tokenizer/mod.js"; import { GPT3BrowserTokenizer } from "../scripts/gpt-3-tokenizer/gpt3-tokenizer.js"; import { generateKoboldWithStreaming, kai_settings, loadKoboldSettings, formatKoboldUrl, getKoboldGenerationData, canUseKoboldStopSequence, canUseKoboldStreaming, } from "./scripts/kai-settings.js"; import { textgenerationwebui_settings, loadTextGenSettings, generateTextGenWithStreaming, getTextGenGenerationData, formatTextGenURL, } from "./scripts/textgen-settings.js"; import { world_info_budget, world_info_depth, world_info, getWorldInfoPrompt, setWorldInfoSettings, world_info_recursive, world_info_overflow_alert, world_info_case_sensitive, world_info_match_whole_words, world_names, world_info_character_strategy, importEmbeddedWorldInfo, checkEmbeddedWorld, setWorldInfoButtonClass, importWorldInfo, } from "./scripts/world-info.js"; import { groups, selected_group, saveGroupChat, getGroups, generateGroupWrapper, deleteGroup, is_group_generating, printGroups, resetSelectedGroup, select_group_chats, regenerateGroup, group_generation_id, getGroupChat, renameGroupMember, createNewGroupChat, getGroupPastChats, getGroupAvatar, openGroupChat, editGroup, deleteGroupChat, renameGroupChat, importGroupChat, } from "./scripts/group-chats.js"; import { collapseNewlines, loadPowerUserSettings, playMessageSound, sortCharactersList, fixMarkdown, power_user, pygmalion_options, tokenizers, formatInstructModeChat, formatInstructStoryString, formatInstructModePrompt, persona_description_positions, loadMovingUIState, getCustomStoppingStrings, fuzzySearchCharacters, MAX_CONTEXT_DEFAULT, } from "./scripts/power-user.js"; import { setOpenAIMessageExamples, setOpenAIMessages, prepareOpenAIMessages, sendOpenAIRequest, loadOpenAISettings, setOpenAIOnlineStatus, generateOpenAIPromptCache, oai_settings, is_get_status_openai, openai_messages_count, getTokenCountOpenAI, chat_completion_sources, getTokenizerModel, getChatCompletionModel, } from "./scripts/openai.js"; import { generateNovelWithStreaming, getNovelGenerationData, getNovelTier, loadNovelPreset, loadNovelSettings, nai_settings, } from "./scripts/nai-settings.js"; import { createNewBookmark, showBookmarksButtons } from "./scripts/bookmarks.js"; import { horde_settings, loadHordeSettings, generateHorde, checkHordeStatus, getHordeModels, adjustHordeGenerationParams, MIN_AMOUNT_GEN, } from "./scripts/horde.js"; import { debounce, delay, restoreCaretPosition, saveCaretPosition, end_trim_to_sentence, countOccurrences, isOdd, sortMoments, timestampToMoment, download, isDataURL, getCharaFilename, isDigitsOnly, } from "./scripts/utils.js"; import { extension_settings, getContext, loadExtensionSettings, runGenerationInterceptors, saveMetadataDebounced } from "./scripts/extensions.js"; import { executeSlashCommands, getSlashCommandsHelp, registerSlashCommand } from "./scripts/slash-commands.js"; import { tag_map, tags, loadTagsSettings, printTagFilters, getTagsList, appendTagToList, createTagMapFromList, renameTagKey, importTags, tag_filter_types, } from "./scripts/tags.js"; import { SECRET_KEYS, readSecretState, secret_state, writeSecret } from "./scripts/secrets.js"; import { EventEmitter } from './scripts/eventemitter.js'; import { context_settings, loadContextTemplatesFromSettings } from "./scripts/context-template.js"; import { markdownExclusionExt } from "./scripts/showdown-exclusion.js"; import { NOTE_MODULE_NAME, metadata_keys, setFloatingPrompt, shouldWIAddPrompt } from "./scripts/authors-note.js"; import { deviceInfo } from "./scripts/RossAscends-mods.js"; import { getRegexedString, regex_placement } from "./scripts/extensions/regex/engine.js"; //exporting functions and vars for mods export { Generate, getSettings, saveSettings, saveSettingsDebounced, printMessages, clearChat, getChat, getCharacters, callPopup, substituteParams, sendSystemMessage, addOneMessage, deleteLastMessage, resetChatState, select_rm_info, setCharacterId, setCharacterName, replaceCurrentChat, setOnlineStatus, checkOnlineStatus, setEditedMessageId, setSendButtonState, selectRightMenuWithAnimation, setRightTabSelectedClass, openCharacterChat, saveChat, messageFormatting, getExtensionPrompt, showSwipeButtons, hideSwipeButtons, changeMainAPI, setGenerationProgress, updateChatMetadata, scrollChatToBottom, getTokenCount, isStreamingEnabled, getThumbnailUrl, getStoppingStrings, getStatus, reloadMarkdownProcessor, getCurrentChatId, chat, this_chid, selected_button, menu_type, settings, characters, online_status, main_api, api_server, system_messages, nai_settings, token, name1, name2, is_send_press, api_server_textgenerationwebui, max_context, chat_metadata, streamingProcessor, default_avatar, system_message_types, talkativeness_default, default_ch_mes, extension_prompt_types, updateVisibleDivs, mesForShowdownParse, printCharacters, } // API OBJECT FOR EXTERNAL WIRING window["SillyTavern"] = {}; // Event source init export const event_types = { EXTRAS_CONNECTED: 'extras_connected', MESSAGE_SWIPED: 'message_swiped', MESSAGE_SENT: 'message_sent', MESSAGE_RECEIVED: 'message_received', MESSAGE_EDITED: 'message_edited', MESSAGE_DELETED: 'message_deleted', IMPERSONATE_READY: 'impersonate_ready', CHAT_CHANGED: 'chat_id_changed', GENERATION_STOPPED: 'generation_stopped', EXTENSIONS_FIRST_LOAD: 'extensions_first_load', SETTINGS_LOADED: 'settings_loaded', SETTINGS_UPDATED: 'settings_updated', GROUP_UPDATED: 'group_updated', MOVABLE_PANELS_RESET: 'movable_panels_reset', } export const eventSource = new EventEmitter(); const gpt3 = new GPT3BrowserTokenizer({ type: 'gpt3' }); hljs.addPlugin({ "before:highlightElement": ({ el }) => { el.textContent = el.innerText } }); // Markdown converter let mesForShowdownParse; //intended to be used as a context to compare showdown strings against let converter; reloadMarkdownProcessor(); // array for prompt token calculations console.debug('initializing Prompt Itemization Array on Startup'); let itemizedPrompts = []; /* let bg_menu_toggle = false; */ export const systemUserName = "SillyTavern System"; let default_user_name = "User"; let name1 = default_user_name; let name2 = "SillyTavern System"; let chat = []; let safetychat = [ { name: systemUserName, is_user: false, is_name: true, create_date: 0, mes: "You deleted a character/chat and arrived back here for safety reasons! Pick another character!", }, ]; let chat_create_date = 0; let firstRun = false; const default_ch_mes = "Hello"; let count_view_mes = 0; let mesStr = ""; let generatedPromtCache = ""; let generation_started = new Date(); let characters = []; let this_chid; let backgrounds = []; const default_avatar = "img/ai4.png"; export const system_avatar = "img/five.png"; export const comment_avatar = "img/quill.png"; export let CLIENT_VERSION = 'SillyTavern:UNKNOWN:Cohee#1207'; // For Horde header let is_colab = false; let is_checked_colab = false; let optionsPopper = Popper.createPopper(document.getElementById('options_button'), document.getElementById('options'), { placement: 'top-start' }); let exportPopper = Popper.createPopper(document.getElementById('export_button'), document.getElementById('export_format_popup'), { placement: 'left' }); let rawPromptPopper = Popper.createPopper(document.getElementById('dialogue_popup'), document.getElementById('rawPromptPopup'), { placement: 'right' }); let dialogueResolve = null; let chat_metadata = {}; let streamingProcessor = null; let crop_data = undefined; let is_delete_mode = false; let fav_ch_checked = false; let scrollLock = false; //initialize global var for future cropped blobs let currentCroppedAvatar = ''; const durationSaveEdit = 1000; const saveSettingsDebounced = debounce(() => saveSettings(), durationSaveEdit); export const saveCharacterDebounced = debounce(() => $("#create_button").trigger('click'), durationSaveEdit); const getStatusDebounced = debounce(() => getStatus(), 300_000); const saveChatDebounced = debounce(() => saveChatConditional(), durationSaveEdit); const system_message_types = { HELP: "help", WELCOME: "welcome", GROUP: "group", EMPTY: "empty", GENERIC: "generic", BOOKMARK_CREATED: "bookmark_created", BOOKMARK_BACK: "bookmark_back", NARRATOR: "narrator", COMMENT: "comment", SLASH_COMMANDS: "slash_commands", FORMATTING: "formatting", HOTKEYS: "hotkeys", MACROS: "macros", }; const extension_prompt_types = { AFTER_SCENARIO: 0, IN_CHAT: 1 }; const system_messages = { help: { name: systemUserName, force_avatar: system_avatar, is_user: false, is_system: true, is_name: true, mes: `Hello there! Please select the help topic you would like to learn more about:
Still got questions left? The Official SillyTavern Documentation Website has much more information!` }, slash_commands: { name: systemUserName, force_avatar: system_avatar, is_user: false, is_system: true, is_name: true, mes: '', }, hotkeys: { name: systemUserName, force_avatar: system_avatar, is_user: false, is_system: true, is_name: true, mes: `Hotkeys/Keybinds: ` }, formatting: { name: systemUserName, force_avatar: system_avatar, is_user: false, is_system: true, is_name: true, mes: `Text formatting commands: ` }, macros: { name: systemUserName, force_avatar: system_avatar, is_user: false, is_system: true, is_name: true, mes: `System-wide Replacement Macros: ` }, welcome: { name: systemUserName, force_avatar: system_avatar, is_user: false, is_system: true, is_name: true, mes: [ '

SillyTavern

', "Want to update?", '
', '

How to start chatting?

', '
    ', '
  1. Click and select a Chat API.
  2. ', '
  3. Click and pick a character
  4. ', '
', '
', '

Want more characters?

', 'Not controlled by SillyTavern team.', '', '
', '

Confused or lost?

', '', '
', '

Still have questions?

', '