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>

f3521e70075af7cd1c59c22d58385fe48e7da815

Wolfsblvt <wolfsblvt@gmail.com>

Signed
29 files changed, +87 -44Showing whitespace changes
public/script.js+1 -1
@@ -741,7 +741,7 @@ async function firstLoadInit() {
741741 initKoboldSettings();
742742 initNovelAISettings();
743743 initSystemPrompts();
744744 await initExtensions();
745745 initExtensionSlashCommands();
746746 ToolManager.initToolSlashCommands();
747747 await initPresetManager();
public/scripts/extensions/assets/index.js+2 -2
@@ -435,7 +435,7 @@ async function updateCurrentAssets() {
435435//#############################//
436436
437437// This function is called when the extension is loaded
438438jQuery(export async function init() => {
439439 // This is an example of loading HTML from a file
440440 const windowTemplate = await renderExtensionTemplateAsync(MODULE_NAME, 'window', {});
441441 const windowHtml = $(windowTemplate);
@@ -496,4 +496,4 @@ jQuery(async () => {
496496 eventSource.on(event_types.OPEN_CHARACTER_LIBRARY, async (forceDefault) => {
497497 openCharacterBrowser(forceDefault);
498498 });
499499});
public/scripts/extensions/assets/manifest.json+4 -1
@@ -7,5 +7,8 @@
77 "css": "style.css",
88 "author": "Keij#6799",
99 "version": "0.1.0",
1010 "homePage": "https://github.com/SillyTavern/SillyTavern",
11+ "hooks": {
12+ "activate": "init"
13+ }
1114}
public/scripts/extensions/attachments/index.js+2 -2
@@ -243,7 +243,7 @@ function handleCharacterRename(oldAvatar, newAvatar) {
243243 }
244244}
245245
246246jQuery(export async function init() => {
247247 eventSource.on(event_types.APP_READY, cleanUpAttachments);
248248 eventSource.on(event_types.CHARACTER_DELETED, cleanUpCharacterAttachments);
249249 eventSource.on(event_types.CHARACTER_RENAMED, handleCharacterRename);
@@ -407,4 +407,4 @@ jQuery(async () => {
407407 }),
408408 ],
409409 }));
410410});
public/scripts/extensions/attachments/manifest.json+4 -1
@@ -7,5 +7,8 @@
77 "css": "style.css",
88 "author": "Cohee1207",
99 "version": "1.0.0",
1010 "homePage": "https://github.com/SillyTavern/SillyTavern",
11+ "hooks": {
12+ "activate": "init"
13+ }
1114}
public/scripts/extensions/caption/index.js+2 -2
@@ -455,7 +455,7 @@ function isVideoCaptioningAvailable() {
455455 return ['google', 'vertexai', 'zai'].includes(extension_settings.caption.multimodal_api);
456456}
457457
458458jQuery(export async function init() {
459459 function addSendPictureButton() {
460460 const sendButton = $(`
461461 <div id="send_picture" class="list-group-item flex-container flexGap5">
@@ -808,4 +808,4 @@ jQuery(async function () {
808808 }));
809809
810810 document.body.classList.add('caption');
811811});
public/scripts/extensions/caption/manifest.json+4 -1
@@ -9,5 +9,8 @@
99 "css": "style.css",
1010 "author": "Cohee#1207",
1111 "version": "1.0.0",
1212 "homePage": "https://github.com/SillyTavern/SillyTavern",
13+ "hooks": {
14+ "activate": "init"
15+ }
1316}
public/scripts/extensions/connection-manager/index.js+2 -2
@@ -474,7 +474,7 @@ async function renderDetailsContent(detailsContent) {
474474 }
475475}
476476
477477(export async function init() {
478478 extension_settings.connectionManager = extension_settings.connectionManager || structuredClone(DEFAULT_SETTINGS);
479479
480480 for (const key of Object.keys(DEFAULT_SETTINGS)) {
@@ -824,4 +824,4 @@ async function renderDetailsContent(detailsContent) {
824824 return JSON.stringify(profile);
825825 },
826826 }));
827-})();
827+}
public/scripts/extensions/connection-manager/manifest.json+4 -1
@@ -7,5 +7,8 @@
77 "css": "style.css",
88 "author": "Cohee1207",
99 "version": "1.0.0",
1010 "homePage": "https://github.com/SillyTavern/SillyTavern",
11+ "hooks": {
12+ "activate": "init"
13+ }
1114}
public/scripts/extensions/expressions/index.js+2 -2
@@ -2140,7 +2140,7 @@ function migrateSettings() {
21402140 }
21412141}
21422142
21432143(export async function init() {
21442144 function addExpressionImage() {
21452145 const html = `
21462146 <div id="expression-wrapper">
@@ -2511,4 +2511,4 @@ function migrateSettings() {
25112511 </div>
25122512 `,
25132513 }));
2514-})();
2514+}
public/scripts/extensions/expressions/manifest.json+4 -1
@@ -9,5 +9,8 @@
99 "css": "style.css",
1010 "author": "Cohee#1207",
1111 "version": "1.0.0",
1212 "homePage": "https://github.com/SillyTavern/SillyTavern",
13+ "hooks": {
14+ "activate": "init"
15+ }
1316}
public/scripts/extensions/gallery/index.js+2 -2
@@ -818,7 +818,7 @@ function addGalleryWandButton() {
818818}
819819
820820// On extension load, ensure the settings are initialized
821821(export async function init() {
822822 initSettings();
823823 eventSource.on(event_types.CHARACTER_RENAMED, (oldAvatar, newAvatar) => {
824824 const context = SillyTavern.getContext();
@@ -850,4 +850,4 @@ function addGalleryWandButton() {
850850 }),
851851 );
852852 addGalleryWandButton();
853-})();
853+}
public/scripts/extensions/gallery/manifest.json+4 -1
@@ -8,5 +8,8 @@
88 "css": "style.css",
99 "author": "City-Unit",
1010 "version": "1.5.0",
1111 "homePage": "https://github.com/SillyTavern/SillyTavern",
12+ "hooks": {
13+ "activate": "init"
14+ }
1215}
public/scripts/extensions/memory/index.js+2 -2
@@ -1063,7 +1063,7 @@ function setupListeners() {
10631063 });
10641064}
10651065
10661066jQuery(export async function init() {
10671067 async function addExtensionControls() {
10681068 const settingsHtml = await renderExtensionTemplateAsync('memory', 'settings', { defaultSettings });
10691069 $('#summarize_container').append(settingsHtml);
@@ -1128,4 +1128,4 @@ jQuery(async function () {
11281128 () => summaryMacroHandler(),
11291129 'Returns the latest memory/summary from the current chat.');
11301130 }
11311131});
public/scripts/extensions/memory/manifest.json+4 -1
@@ -9,5 +9,8 @@
99 "css": "style.css",
1010 "author": "Cohee#1207",
1111 "version": "1.0.0",
1212 "homePage": "https://github.com/SillyTavern/SillyTavern",
13+ "hooks": {
14+ "activate": "init"
15+ }
1316}
public/scripts/extensions/quick-reply/index.js+4 -3
@@ -169,7 +169,7 @@ const handleCharChange = () => {
169169 settings.charConfig = charConfig;
170170};
171171
172172const init =export async function init() => {
173173 await loadSets();
174174 await loadSettings();
175175 log('settings: ', settings);
@@ -214,7 +214,8 @@ const init = async () => {
214214 eventSource.on(event_types.APP_READY, async () => await finalizeInit());
215215
216216 globalThis.quickReplyApi = quickReplyApi;
217217};
218+
218219const finalizeInit = async () => {
219220 debug('executing startup');
220221 await autoExec.handleStartup();
@@ -229,7 +230,7 @@ const finalizeInit = async () => {
229230 isReady = true;
230231 debug('READY');
231232};
232-await init();
233+
233234
234235const purgeCharacterQuickReplySets = ({ character }) => {
235236 // Remove the character's Quick Reply Sets from the settings.
public/scripts/extensions/quick-reply/manifest.json+4 -1
@@ -7,5 +7,8 @@
77 "css": "style.css",
88 "author": "RossAscends#1779",
99 "version": "2.0.0",
1010 "homePage": "https://github.com/SillyTavern/SillyTavern",
11+ "hooks": {
12+ "activate": "init"
13+ }
1114}
public/scripts/extensions/regex/index.js+2 -2
@@ -1709,7 +1709,7 @@ function onPresetRenamed({ apiId, oldName, newName }) {
17091709
17101710// Workaround for loading in sequence with other extensions
17111711// NOTE: Always puts extension at the top of the list, but this is fine since it's static
17121712jQuery(export async function init() => {
17131713 if (!Array.isArray(extension_settings.regex)) {
17141714 extension_settings.regex = [];
17151715 }
@@ -2154,4 +2154,4 @@ jQuery(async () => {
21542154
21552155 presetManager.setupEventListeners();
21562156 presetManager.registerSlashCommands();
21572157});
public/scripts/extensions/regex/manifest.json+4 -1
@@ -7,5 +7,8 @@
77 "css": "style.css",
88 "author": "kingbri",
99 "version": "1.0.0",
1010 "homePage": "https://github.com/SillyTavern/SillyTavern",
11+ "hooks": {
12+ "activate": "init"
13+ }
1114}
public/scripts/extensions/stable-diffusion/index.js+2 -2
@@ -5470,7 +5470,7 @@ function registerFunctionTool() {
54705470 });
54715471}
54725472
54735473jQuery(export async function init() => {
54745474 await addSDGenButtons();
54755475
54765476 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 () => {
59775977 t`Character's negative Image Generation prompt prefix`,
59785978 );
59795979 }
59805980});
public/scripts/extensions/stable-diffusion/manifest.json+4 -1
@@ -10,5 +10,8 @@
1010 "css": "style.css",
1111 "author": "Cohee#1207",
1212 "version": "1.0.0",
1313 "homePage": "https://github.com/SillyTavern/SillyTavern",
14+ "hooks": {
15+ "activate": "init"
16+ }
1417}
public/scripts/extensions/token-counter/index.js+2 -2
@@ -101,7 +101,7 @@ async function doCount() {
101101 return count;
102102}
103103
104-jQuery(() => {
104+export function init() {
105105 const buttonHtml = `
106106 <div id="token_counter" class="list-group-item flex-container flexGap5">
107107 <div class="fa-solid fa-1 extensionsMenuExtensionButton" /></div>` +
@@ -115,4 +115,4 @@ jQuery(() => {
115115 returns: 'number of tokens',
116116 helpString: 'Counts the number of tokens in the current chat.',
117117 }));
118118});
public/scripts/extensions/token-counter/manifest.json+4 -1
@@ -7,5 +7,8 @@
77 "css": "style.css",
88 "author": "Cohee#1207",
99 "version": "1.0.0",
1010 "homePage": "https://github.com/SillyTavern/SillyTavern",
11+ "hooks": {
12+ "activate": "init"
13+ }
1114}
public/scripts/extensions/translate/index.js+2 -2
@@ -707,7 +707,7 @@ const handleMessageReasoningDelete = createEventHandler(removeReasoningDisplayTe
707707
708708globalThis.translate = translate;
709709
710710jQuery(export async function init() => {
711711 const html = await renderExtensionTemplateAsync('translate', 'index');
712712 const buttonHtml = await renderExtensionTemplateAsync('translate', 'buttons');
713713
@@ -801,4 +801,4 @@ jQuery(async () => {
801801 },
802802 returns: ARGUMENT_TYPE.STRING,
803803 }));
804804});
public/scripts/extensions/translate/manifest.json+4 -1
@@ -7,5 +7,8 @@
77 "css": "style.css",
88 "author": "Cohee#1207",
99 "version": "1.0.0",
1010 "homePage": "https://github.com/SillyTavern/SillyTavern",
11+ "hooks": {
12+ "activate": "init"
13+ }
1114}
public/scripts/extensions/tts/index.js+2 -2
@@ -1531,7 +1531,7 @@ async function initVoiceMapInternal(unrestricted) {
15311531 updateVoiceMap();
15321532}
15331533
15341534jQuery(export async function init() {
15351535 async function addExtensionControls() {
15361536 const settingsHtml = $(await renderExtensionTemplateAsync('tts', 'settings'));
15371537 $('#tts_container').append(settingsHtml);
@@ -1619,4 +1619,4 @@ jQuery(async function () {
16191619 }));
16201620
16211621 document.body.appendChild(audioElement);
16221622});
public/scripts/extensions/tts/manifest.json+4 -1
@@ -11,5 +11,8 @@
1111 "css": "style.css",
1212 "author": "Ouoertheo#7264",
1313 "version": "1.0.0",
1414 "homePage": "None",
15+ "hooks": {
16+ "activate": "init"
17+ }
1518}
public/scripts/extensions/vectors/index.js+2 -2
@@ -1760,7 +1760,7 @@ async function activateWorldInfo(chat) {
17601760 await eventSource.emit(event_types.WORLDINFO_FORCE_ACTIVATE, activatedEntries);
17611761}
17621762
17631763jQuery(export async function init() => {
17641764 if (!extension_settings.vectors) {
17651765 extension_settings.vectors = settings;
17661766 }
@@ -2376,4 +2376,4 @@ jQuery(async () => {
23762376 }
23772377 await purgeAllVectorIndexes();
23782378 });
23792379});
public/scripts/extensions/vectors/manifest.json+4 -1
@@ -10,5 +10,8 @@
1010 "css": "style.css",
1111 "author": "Cohee#1207",
1212 "version": "1.0.0",
1313 "homePage": "https://github.com/SillyTavern/SillyTavern",
14+ "hooks": {
15+ "activate": "init"
16+ }
1417}