Migrate built-in extensions to use manifest-based activate hooks (#5435) * Convert jQuery/IIFE wrappers to exported init() functions and register activate hooks in 8 extension manifests * Convert remaining extensions to exported init() with activate hooks and await initExtensions() - Convert jQuery/IIFE wrappers to exported init() functions in expressions, memory, quick-reply, regex, stable-diffusion, translate, tts, and vectors extensions - Register init functions as activate hooks in extension manifests - Properly await async initExtensions() in firstLoadInit() * Fix eslint --------- Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
Signed| @@ -741,7 +741,7 @@ async function firstLoadInit() { | |||
| 741 | initKoboldSettings(); | 741 | initKoboldSettings(); |
| 742 | initNovelAISettings(); | 742 | initNovelAISettings(); |
| 743 | initSystemPrompts(); | 743 | initSystemPrompts(); |
| 744 | initExtensions(); | 744 | await initExtensions(); |
| 745 | initExtensionSlashCommands(); | 745 | initExtensionSlashCommands(); |
| 746 | ToolManager.initToolSlashCommands(); | 746 | ToolManager.initToolSlashCommands(); |
| 747 | await initPresetManager(); | 747 | await initPresetManager(); |
| @@ -435,7 +435,7 @@ async function updateCurrentAssets() { | |||
| 435 | //#############################// | 435 | //#############################// |
| 436 | 436 | ||
| 437 | // This function is called when the extension is loaded | 437 | // This function is called when the extension is loaded |
| 438 | jQuery(async () => { | 438 | export async function init() { |
| 439 | // This is an example of loading HTML from a file | 439 | // This is an example of loading HTML from a file |
| 440 | const windowTemplate = await renderExtensionTemplateAsync(MODULE_NAME, 'window', {}); | 440 | const windowTemplate = await renderExtensionTemplateAsync(MODULE_NAME, 'window', {}); |
| 441 | const windowHtml = $(windowTemplate); | 441 | const windowHtml = $(windowTemplate); |
| @@ -496,4 +496,4 @@ jQuery(async () => { | |||
| 496 | eventSource.on(event_types.OPEN_CHARACTER_LIBRARY, async (forceDefault) => { | 496 | eventSource.on(event_types.OPEN_CHARACTER_LIBRARY, async (forceDefault) => { |
| 497 | openCharacterBrowser(forceDefault); | 497 | openCharacterBrowser(forceDefault); |
| 498 | }); | 498 | }); |
| 499 | }); | 499 | } |
| @@ -7,5 +7,8 @@ | |||
| 7 | "css": "style.css", | 7 | "css": "style.css", |
| 8 | "author": "Keij#6799", | 8 | "author": "Keij#6799", |
| 9 | "version": "0.1.0", | 9 | "version": "0.1.0", |
| 10 | "homePage": "https://github.com/SillyTavern/SillyTavern" | 10 | "homePage": "https://github.com/SillyTavern/SillyTavern", |
| 11 | "hooks": { | ||
| 12 | "activate": "init" | ||
| 13 | } | ||
| 11 | } | 14 | } |
| @@ -243,7 +243,7 @@ function handleCharacterRename(oldAvatar, newAvatar) { | |||
| 243 | } | 243 | } |
| 244 | } | 244 | } |
| 245 | 245 | ||
| 246 | jQuery(async () => { | 246 | export async function init() { |
| 247 | eventSource.on(event_types.APP_READY, cleanUpAttachments); | 247 | eventSource.on(event_types.APP_READY, cleanUpAttachments); |
| 248 | eventSource.on(event_types.CHARACTER_DELETED, cleanUpCharacterAttachments); | 248 | eventSource.on(event_types.CHARACTER_DELETED, cleanUpCharacterAttachments); |
| 249 | eventSource.on(event_types.CHARACTER_RENAMED, handleCharacterRename); | 249 | eventSource.on(event_types.CHARACTER_RENAMED, handleCharacterRename); |
| @@ -407,4 +407,4 @@ jQuery(async () => { | |||
| 407 | }), | 407 | }), |
| 408 | ], | 408 | ], |
| 409 | })); | 409 | })); |
| 410 | }); | 410 | } |
| @@ -7,5 +7,8 @@ | |||
| 7 | "css": "style.css", | 7 | "css": "style.css", |
| 8 | "author": "Cohee1207", | 8 | "author": "Cohee1207", |
| 9 | "version": "1.0.0", | 9 | "version": "1.0.0", |
| 10 | "homePage": "https://github.com/SillyTavern/SillyTavern" | 10 | "homePage": "https://github.com/SillyTavern/SillyTavern", |
| 11 | "hooks": { | ||
| 12 | "activate": "init" | ||
| 13 | } | ||
| 11 | } | 14 | } |
| @@ -455,7 +455,7 @@ function isVideoCaptioningAvailable() { | |||
| 455 | return ['google', 'vertexai', 'zai'].includes(extension_settings.caption.multimodal_api); | 455 | return ['google', 'vertexai', 'zai'].includes(extension_settings.caption.multimodal_api); |
| 456 | } | 456 | } |
| 457 | 457 | ||
| 458 | jQuery(async function () { | 458 | export async function init() { |
| 459 | function addSendPictureButton() { | 459 | function addSendPictureButton() { |
| 460 | const sendButton = $(` | 460 | const sendButton = $(` |
| 461 | <div id="send_picture" class="list-group-item flex-container flexGap5"> | 461 | <div id="send_picture" class="list-group-item flex-container flexGap5"> |
| @@ -808,4 +808,4 @@ jQuery(async function () { | |||
| 808 | })); | 808 | })); |
| 809 | 809 | ||
| 810 | document.body.classList.add('caption'); | 810 | document.body.classList.add('caption'); |
| 811 | }); | 811 | } |
| @@ -9,5 +9,8 @@ | |||
| 9 | "css": "style.css", | 9 | "css": "style.css", |
| 10 | "author": "Cohee#1207", | 10 | "author": "Cohee#1207", |
| 11 | "version": "1.0.0", | 11 | "version": "1.0.0", |
| 12 | "homePage": "https://github.com/SillyTavern/SillyTavern" | 12 | "homePage": "https://github.com/SillyTavern/SillyTavern", |
| 13 | "hooks": { | ||
| 14 | "activate": "init" | ||
| 15 | } | ||
| 13 | } | 16 | } |
| @@ -474,7 +474,7 @@ async function renderDetailsContent(detailsContent) { | |||
| 474 | } | 474 | } |
| 475 | } | 475 | } |
| 476 | 476 | ||
| 477 | (async function () { | 477 | export async function init() { |
| 478 | extension_settings.connectionManager = extension_settings.connectionManager || structuredClone(DEFAULT_SETTINGS); | 478 | extension_settings.connectionManager = extension_settings.connectionManager || structuredClone(DEFAULT_SETTINGS); |
| 479 | 479 | ||
| 480 | for (const key of Object.keys(DEFAULT_SETTINGS)) { | 480 | for (const key of Object.keys(DEFAULT_SETTINGS)) { |
| @@ -824,4 +824,4 @@ async function renderDetailsContent(detailsContent) { | |||
| 824 | return JSON.stringify(profile); | 824 | return JSON.stringify(profile); |
| 825 | }, | 825 | }, |
| 826 | })); | 826 | })); |
| 827 | })(); | 827 | } |
| @@ -7,5 +7,8 @@ | |||
| 7 | "css": "style.css", | 7 | "css": "style.css", |
| 8 | "author": "Cohee1207", | 8 | "author": "Cohee1207", |
| 9 | "version": "1.0.0", | 9 | "version": "1.0.0", |
| 10 | "homePage": "https://github.com/SillyTavern/SillyTavern" | 10 | "homePage": "https://github.com/SillyTavern/SillyTavern", |
| 11 | "hooks": { | ||
| 12 | "activate": "init" | ||
| 13 | } | ||
| 11 | } | 14 | } |
| @@ -2140,7 +2140,7 @@ function migrateSettings() { | |||
| 2140 | } | 2140 | } |
| 2141 | } | 2141 | } |
| 2142 | 2142 | ||
| 2143 | (async function () { | 2143 | export async function init() { |
| 2144 | function addExpressionImage() { | 2144 | function addExpressionImage() { |
| 2145 | const html = ` | 2145 | const html = ` |
| 2146 | <div id="expression-wrapper"> | 2146 | <div id="expression-wrapper"> |
| @@ -2511,4 +2511,4 @@ function migrateSettings() { | |||
| 2511 | </div> | 2511 | </div> |
| 2512 | `, | 2512 | `, |
| 2513 | })); | 2513 | })); |
| 2514 | })(); | 2514 | } |
| @@ -9,5 +9,8 @@ | |||
| 9 | "css": "style.css", | 9 | "css": "style.css", |
| 10 | "author": "Cohee#1207", | 10 | "author": "Cohee#1207", |
| 11 | "version": "1.0.0", | 11 | "version": "1.0.0", |
| 12 | "homePage": "https://github.com/SillyTavern/SillyTavern" | 12 | "homePage": "https://github.com/SillyTavern/SillyTavern", |
| 13 | "hooks": { | ||
| 14 | "activate": "init" | ||
| 15 | } | ||
| 13 | } | 16 | } |
| @@ -818,7 +818,7 @@ function addGalleryWandButton() { | |||
| 818 | } | 818 | } |
| 819 | 819 | ||
| 820 | // On extension load, ensure the settings are initialized | 820 | // On extension load, ensure the settings are initialized |
| 821 | (function () { | 821 | export async function init() { |
| 822 | initSettings(); | 822 | initSettings(); |
| 823 | eventSource.on(event_types.CHARACTER_RENAMED, (oldAvatar, newAvatar) => { | 823 | eventSource.on(event_types.CHARACTER_RENAMED, (oldAvatar, newAvatar) => { |
| 824 | const context = SillyTavern.getContext(); | 824 | const context = SillyTavern.getContext(); |
| @@ -850,4 +850,4 @@ function addGalleryWandButton() { | |||
| 850 | }), | 850 | }), |
| 851 | ); | 851 | ); |
| 852 | addGalleryWandButton(); | 852 | addGalleryWandButton(); |
| 853 | })(); | 853 | } |
| @@ -8,5 +8,8 @@ | |||
| 8 | "css": "style.css", | 8 | "css": "style.css", |
| 9 | "author": "City-Unit", | 9 | "author": "City-Unit", |
| 10 | "version": "1.5.0", | 10 | "version": "1.5.0", |
| 11 | "homePage": "https://github.com/SillyTavern/SillyTavern" | 11 | "homePage": "https://github.com/SillyTavern/SillyTavern", |
| 12 | "hooks": { | ||
| 13 | "activate": "init" | ||
| 14 | } | ||
| 12 | } | 15 | } |
| @@ -1063,7 +1063,7 @@ function setupListeners() { | |||
| 1063 | }); | 1063 | }); |
| 1064 | } | 1064 | } |
| 1065 | 1065 | ||
| 1066 | jQuery(async function () { | 1066 | export async function init() { |
| 1067 | async function addExtensionControls() { | 1067 | async function addExtensionControls() { |
| 1068 | const settingsHtml = await renderExtensionTemplateAsync('memory', 'settings', { defaultSettings }); | 1068 | const settingsHtml = await renderExtensionTemplateAsync('memory', 'settings', { defaultSettings }); |
| 1069 | $('#summarize_container').append(settingsHtml); | 1069 | $('#summarize_container').append(settingsHtml); |
| @@ -1128,4 +1128,4 @@ jQuery(async function () { | |||
| 1128 | () => summaryMacroHandler(), | 1128 | () => summaryMacroHandler(), |
| 1129 | 'Returns the latest memory/summary from the current chat.'); | 1129 | 'Returns the latest memory/summary from the current chat.'); |
| 1130 | } | 1130 | } |
| 1131 | }); | 1131 | } |
| @@ -9,5 +9,8 @@ | |||
| 9 | "css": "style.css", | 9 | "css": "style.css", |
| 10 | "author": "Cohee#1207", | 10 | "author": "Cohee#1207", |
| 11 | "version": "1.0.0", | 11 | "version": "1.0.0", |
| 12 | "homePage": "https://github.com/SillyTavern/SillyTavern" | 12 | "homePage": "https://github.com/SillyTavern/SillyTavern", |
| 13 | "hooks": { | ||
| 14 | "activate": "init" | ||
| 15 | } | ||
| 13 | } | 16 | } |
| @@ -169,7 +169,7 @@ const handleCharChange = () => { | |||
| 169 | settings.charConfig = charConfig; | 169 | settings.charConfig = charConfig; |
| 170 | }; | 170 | }; |
| 171 | 171 | ||
| 172 | const init = async () => { | 172 | export async function init() { |
| 173 | await loadSets(); | 173 | await loadSets(); |
| 174 | await loadSettings(); | 174 | await loadSettings(); |
| 175 | log('settings: ', settings); | 175 | log('settings: ', settings); |
| @@ -214,7 +214,8 @@ const init = async () => { | |||
| 214 | eventSource.on(event_types.APP_READY, async () => await finalizeInit()); | 214 | eventSource.on(event_types.APP_READY, async () => await finalizeInit()); |
| 215 | 215 | ||
| 216 | globalThis.quickReplyApi = quickReplyApi; | 216 | globalThis.quickReplyApi = quickReplyApi; |
| 217 | }; | 217 | } |
| 218 | |||
| 218 | const finalizeInit = async () => { | 219 | const finalizeInit = async () => { |
| 219 | debug('executing startup'); | 220 | debug('executing startup'); |
| 220 | await autoExec.handleStartup(); | 221 | await autoExec.handleStartup(); |
| @@ -229,7 +230,7 @@ const finalizeInit = async () => { | |||
| 229 | isReady = true; | 230 | isReady = true; |
| 230 | debug('READY'); | 231 | debug('READY'); |
| 231 | }; | 232 | }; |
| 232 | await init(); | 233 | |
| 233 | 234 | ||
| 234 | const purgeCharacterQuickReplySets = ({ character }) => { | 235 | const purgeCharacterQuickReplySets = ({ character }) => { |
| 235 | // Remove the character's Quick Reply Sets from the settings. | 236 | // Remove the character's Quick Reply Sets from the settings. |
| @@ -7,5 +7,8 @@ | |||
| 7 | "css": "style.css", | 7 | "css": "style.css", |
| 8 | "author": "RossAscends#1779", | 8 | "author": "RossAscends#1779", |
| 9 | "version": "2.0.0", | 9 | "version": "2.0.0", |
| 10 | "homePage": "https://github.com/SillyTavern/SillyTavern" | 10 | "homePage": "https://github.com/SillyTavern/SillyTavern", |
| 11 | "hooks": { | ||
| 12 | "activate": "init" | ||
| 13 | } | ||
| 11 | } | 14 | } |
| @@ -1709,7 +1709,7 @@ function onPresetRenamed({ apiId, oldName, newName }) { | |||
| 1709 | 1709 | ||
| 1710 | // Workaround for loading in sequence with other extensions | 1710 | // Workaround for loading in sequence with other extensions |
| 1711 | // NOTE: Always puts extension at the top of the list, but this is fine since it's static | 1711 | // NOTE: Always puts extension at the top of the list, but this is fine since it's static |
| 1712 | jQuery(async () => { | 1712 | export async function init() { |
| 1713 | if (!Array.isArray(extension_settings.regex)) { | 1713 | if (!Array.isArray(extension_settings.regex)) { |
| 1714 | extension_settings.regex = []; | 1714 | extension_settings.regex = []; |
| 1715 | } | 1715 | } |
| @@ -2154,4 +2154,4 @@ jQuery(async () => { | |||
| 2154 | 2154 | ||
| 2155 | presetManager.setupEventListeners(); | 2155 | presetManager.setupEventListeners(); |
| 2156 | presetManager.registerSlashCommands(); | 2156 | presetManager.registerSlashCommands(); |
| 2157 | }); | 2157 | } |
| @@ -7,5 +7,8 @@ | |||
| 7 | "css": "style.css", | 7 | "css": "style.css", |
| 8 | "author": "kingbri", | 8 | "author": "kingbri", |
| 9 | "version": "1.0.0", | 9 | "version": "1.0.0", |
| 10 | "homePage": "https://github.com/SillyTavern/SillyTavern" | 10 | "homePage": "https://github.com/SillyTavern/SillyTavern", |
| 11 | "hooks": { | ||
| 12 | "activate": "init" | ||
| 13 | } | ||
| 11 | } | 14 | } |
| @@ -5470,7 +5470,7 @@ function registerFunctionTool() { | |||
| 5470 | }); | 5470 | }); |
| 5471 | } | 5471 | } |
| 5472 | 5472 | ||
| 5473 | jQuery(async () => { | 5473 | export async function init() { |
| 5474 | await addSDGenButtons(); | 5474 | await addSDGenButtons(); |
| 5475 | 5475 | ||
| 5476 | const getSelectEnumProvider = (id, text) => () => Array.from(document.querySelectorAll(`#${id} > [value]`)).map(x => new SlashCommandEnumValue(x.getAttribute('value'), text ? x.textContent : null)); | 5476 | const getSelectEnumProvider = (id, text) => () => Array.from(document.querySelectorAll(`#${id} > [value]`)).map(x => new SlashCommandEnumValue(x.getAttribute('value'), text ? x.textContent : null)); |
| @@ -5977,4 +5977,4 @@ jQuery(async () => { | |||
| 5977 | t`Character's negative Image Generation prompt prefix`, | 5977 | t`Character's negative Image Generation prompt prefix`, |
| 5978 | ); | 5978 | ); |
| 5979 | } | 5979 | } |
| 5980 | }); | 5980 | } |
| @@ -10,5 +10,8 @@ | |||
| 10 | "css": "style.css", | 10 | "css": "style.css", |
| 11 | "author": "Cohee#1207", | 11 | "author": "Cohee#1207", |
| 12 | "version": "1.0.0", | 12 | "version": "1.0.0", |
| 13 | "homePage": "https://github.com/SillyTavern/SillyTavern" | 13 | "homePage": "https://github.com/SillyTavern/SillyTavern", |
| 14 | "hooks": { | ||
| 15 | "activate": "init" | ||
| 16 | } | ||
| 14 | } | 17 | } |
| @@ -101,7 +101,7 @@ async function doCount() { | |||
| 101 | return count; | 101 | return count; |
| 102 | } | 102 | } |
| 103 | 103 | ||
| 104 | jQuery(() => { | 104 | export function init() { |
| 105 | const buttonHtml = ` | 105 | const buttonHtml = ` |
| 106 | <div id="token_counter" class="list-group-item flex-container flexGap5"> | 106 | <div id="token_counter" class="list-group-item flex-container flexGap5"> |
| 107 | <div class="fa-solid fa-1 extensionsMenuExtensionButton" /></div>` + | 107 | <div class="fa-solid fa-1 extensionsMenuExtensionButton" /></div>` + |
| @@ -115,4 +115,4 @@ jQuery(() => { | |||
| 115 | returns: 'number of tokens', | 115 | returns: 'number of tokens', |
| 116 | helpString: 'Counts the number of tokens in the current chat.', | 116 | helpString: 'Counts the number of tokens in the current chat.', |
| 117 | })); | 117 | })); |
| 118 | }); | 118 | } |
| @@ -7,5 +7,8 @@ | |||
| 7 | "css": "style.css", | 7 | "css": "style.css", |
| 8 | "author": "Cohee#1207", | 8 | "author": "Cohee#1207", |
| 9 | "version": "1.0.0", | 9 | "version": "1.0.0", |
| 10 | "homePage": "https://github.com/SillyTavern/SillyTavern" | 10 | "homePage": "https://github.com/SillyTavern/SillyTavern", |
| 11 | "hooks": { | ||
| 12 | "activate": "init" | ||
| 13 | } | ||
| 11 | } | 14 | } |
| @@ -707,7 +707,7 @@ const handleMessageReasoningDelete = createEventHandler(removeReasoningDisplayTe | |||
| 707 | 707 | ||
| 708 | globalThis.translate = translate; | 708 | globalThis.translate = translate; |
| 709 | 709 | ||
| 710 | jQuery(async () => { | 710 | export async function init() { |
| 711 | const html = await renderExtensionTemplateAsync('translate', 'index'); | 711 | const html = await renderExtensionTemplateAsync('translate', 'index'); |
| 712 | const buttonHtml = await renderExtensionTemplateAsync('translate', 'buttons'); | 712 | const buttonHtml = await renderExtensionTemplateAsync('translate', 'buttons'); |
| 713 | 713 | ||
| @@ -801,4 +801,4 @@ jQuery(async () => { | |||
| 801 | }, | 801 | }, |
| 802 | returns: ARGUMENT_TYPE.STRING, | 802 | returns: ARGUMENT_TYPE.STRING, |
| 803 | })); | 803 | })); |
| 804 | }); | 804 | } |
| @@ -7,5 +7,8 @@ | |||
| 7 | "css": "style.css", | 7 | "css": "style.css", |
| 8 | "author": "Cohee#1207", | 8 | "author": "Cohee#1207", |
| 9 | "version": "1.0.0", | 9 | "version": "1.0.0", |
| 10 | "homePage": "https://github.com/SillyTavern/SillyTavern" | 10 | "homePage": "https://github.com/SillyTavern/SillyTavern", |
| 11 | "hooks": { | ||
| 12 | "activate": "init" | ||
| 13 | } | ||
| 11 | } | 14 | } |
| @@ -1531,7 +1531,7 @@ async function initVoiceMapInternal(unrestricted) { | |||
| 1531 | updateVoiceMap(); | 1531 | updateVoiceMap(); |
| 1532 | } | 1532 | } |
| 1533 | 1533 | ||
| 1534 | jQuery(async function () { | 1534 | export async function init() { |
| 1535 | async function addExtensionControls() { | 1535 | async function addExtensionControls() { |
| 1536 | const settingsHtml = $(await renderExtensionTemplateAsync('tts', 'settings')); | 1536 | const settingsHtml = $(await renderExtensionTemplateAsync('tts', 'settings')); |
| 1537 | $('#tts_container').append(settingsHtml); | 1537 | $('#tts_container').append(settingsHtml); |
| @@ -1619,4 +1619,4 @@ jQuery(async function () { | |||
| 1619 | })); | 1619 | })); |
| 1620 | 1620 | ||
| 1621 | document.body.appendChild(audioElement); | 1621 | document.body.appendChild(audioElement); |
| 1622 | }); | 1622 | } |
| @@ -11,5 +11,8 @@ | |||
| 11 | "css": "style.css", | 11 | "css": "style.css", |
| 12 | "author": "Ouoertheo#7264", | 12 | "author": "Ouoertheo#7264", |
| 13 | "version": "1.0.0", | 13 | "version": "1.0.0", |
| 14 | "homePage": "None" | 14 | "homePage": "None", |
| 15 | "hooks": { | ||
| 16 | "activate": "init" | ||
| 17 | } | ||
| 15 | } | 18 | } |
| @@ -1760,7 +1760,7 @@ async function activateWorldInfo(chat) { | |||
| 1760 | await eventSource.emit(event_types.WORLDINFO_FORCE_ACTIVATE, activatedEntries); | 1760 | await eventSource.emit(event_types.WORLDINFO_FORCE_ACTIVATE, activatedEntries); |
| 1761 | } | 1761 | } |
| 1762 | 1762 | ||
| 1763 | jQuery(async () => { | 1763 | export async function init() { |
| 1764 | if (!extension_settings.vectors) { | 1764 | if (!extension_settings.vectors) { |
| 1765 | extension_settings.vectors = settings; | 1765 | extension_settings.vectors = settings; |
| 1766 | } | 1766 | } |
| @@ -2376,4 +2376,4 @@ jQuery(async () => { | |||
| 2376 | } | 2376 | } |
| 2377 | await purgeAllVectorIndexes(); | 2377 | await purgeAllVectorIndexes(); |
| 2378 | }); | 2378 | }); |
| 2379 | }); | 2379 | } |
| @@ -10,5 +10,8 @@ | |||
| 10 | "css": "style.css", | 10 | "css": "style.css", |
| 11 | "author": "Cohee#1207", | 11 | "author": "Cohee#1207", |
| 12 | "version": "1.0.0", | 12 | "version": "1.0.0", |
| 13 | "homePage": "https://github.com/SillyTavern/SillyTavern" | 13 | "homePage": "https://github.com/SillyTavern/SillyTavern", |
| 14 | "hooks": { | ||
| 15 | "activate": "init" | ||
| 16 | } | ||
| 14 | } | 17 | } |