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