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() {
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();
public/scripts/extensions/assets/index.js+2 -2
@@ -435,7 +435,7 @@ async function updateCurrentAssets() {
435//#############################//435//#############################//
436436
437// This function is called when the extension is loaded437// This function is called when the extension is loaded
438jQuery(async () => {438export async function init() {
439 // This is an example of loading HTML from a file439 // 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}
public/scripts/extensions/assets/manifest.json+4 -1
@@ -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}
public/scripts/extensions/attachments/index.js+2 -2
@@ -243,7 +243,7 @@ function handleCharacterRename(oldAvatar, newAvatar) {
243 }243 }
244}244}
245245
246jQuery(async () => {246export 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}
public/scripts/extensions/attachments/manifest.json+4 -1
@@ -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}
public/scripts/extensions/caption/index.js+2 -2
@@ -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}
457457
458jQuery(async function () {458export 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 }));
809809
810 document.body.classList.add('caption');810 document.body.classList.add('caption');
811});811}
public/scripts/extensions/caption/manifest.json+4 -1
@@ -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}
public/scripts/extensions/connection-manager/index.js+2 -2
@@ -474,7 +474,7 @@ async function renderDetailsContent(detailsContent) {
474 }474 }
475}475}
476476
477(async function () {477export async function init() {
478 extension_settings.connectionManager = extension_settings.connectionManager || structuredClone(DEFAULT_SETTINGS);478 extension_settings.connectionManager = extension_settings.connectionManager || structuredClone(DEFAULT_SETTINGS);
479479
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}
public/scripts/extensions/connection-manager/manifest.json+4 -1
@@ -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}
public/scripts/extensions/expressions/index.js+2 -2
@@ -2140,7 +2140,7 @@ function migrateSettings() {
2140 }2140 }
2141}2141}
21422142
2143(async function () {2143export 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}
public/scripts/extensions/expressions/manifest.json+4 -1
@@ -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}
public/scripts/extensions/gallery/index.js+2 -2
@@ -818,7 +818,7 @@ function addGalleryWandButton() {
818}818}
819819
820// On extension load, ensure the settings are initialized820// On extension load, ensure the settings are initialized
821(function () {821export 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}
public/scripts/extensions/gallery/manifest.json+4 -1
@@ -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}
public/scripts/extensions/memory/index.js+2 -2
@@ -1063,7 +1063,7 @@ function setupListeners() {
1063 });1063 });
1064}1064}
10651065
1066jQuery(async function () {1066export 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}
public/scripts/extensions/memory/manifest.json+4 -1
@@ -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}
public/scripts/extensions/quick-reply/index.js+4 -3
@@ -169,7 +169,7 @@ const handleCharChange = () => {
169 settings.charConfig = charConfig;169 settings.charConfig = charConfig;
170};170};
171171
172const init = async () => {172export 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());
215215
216 globalThis.quickReplyApi = quickReplyApi;216 globalThis.quickReplyApi = quickReplyApi;
217};217}
218
218const finalizeInit = async () => {219const 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};
232await init();233
233234
234const purgeCharacterQuickReplySets = ({ character }) => {235const purgeCharacterQuickReplySets = ({ character }) => {
235 // Remove the character's Quick Reply Sets from the settings.236 // Remove the character's Quick Reply Sets from the settings.
public/scripts/extensions/quick-reply/manifest.json+4 -1
@@ -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}
public/scripts/extensions/regex/index.js+2 -2
@@ -1709,7 +1709,7 @@ function onPresetRenamed({ apiId, oldName, newName }) {
17091709
1710// Workaround for loading in sequence with other extensions1710// 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 static1711// NOTE: Always puts extension at the top of the list, but this is fine since it's static
1712jQuery(async () => {1712export 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 () => {
21542154
2155 presetManager.setupEventListeners();2155 presetManager.setupEventListeners();
2156 presetManager.registerSlashCommands();2156 presetManager.registerSlashCommands();
2157});2157}
public/scripts/extensions/regex/manifest.json+4 -1
@@ -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}
public/scripts/extensions/stable-diffusion/index.js+2 -2
@@ -5470,7 +5470,7 @@ function registerFunctionTool() {
5470 });5470 });
5471}5471}
54725472
5473jQuery(async () => {5473export async function init() {
5474 await addSDGenButtons();5474 await addSDGenButtons();
54755475
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}
public/scripts/extensions/stable-diffusion/manifest.json+4 -1
@@ -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}
public/scripts/extensions/token-counter/index.js+2 -2
@@ -101,7 +101,7 @@ async function doCount() {
101 return count;101 return count;
102}102}
103103
104jQuery(() => {104export 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}
public/scripts/extensions/token-counter/manifest.json+4 -1
@@ -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}
public/scripts/extensions/translate/index.js+2 -2
@@ -707,7 +707,7 @@ const handleMessageReasoningDelete = createEventHandler(removeReasoningDisplayTe
707707
708globalThis.translate = translate;708globalThis.translate = translate;
709709
710jQuery(async () => {710export 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');
713713
@@ -801,4 +801,4 @@ jQuery(async () => {
801 },801 },
802 returns: ARGUMENT_TYPE.STRING,802 returns: ARGUMENT_TYPE.STRING,
803 }));803 }));
804});804}
public/scripts/extensions/translate/manifest.json+4 -1
@@ -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}
public/scripts/extensions/tts/index.js+2 -2
@@ -1531,7 +1531,7 @@ async function initVoiceMapInternal(unrestricted) {
1531 updateVoiceMap();1531 updateVoiceMap();
1532}1532}
15331533
1534jQuery(async function () {1534export 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 }));
16201620
1621 document.body.appendChild(audioElement);1621 document.body.appendChild(audioElement);
1622});1622}
public/scripts/extensions/tts/manifest.json+4 -1
@@ -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}
public/scripts/extensions/vectors/index.js+2 -2
@@ -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}
17621762
1763jQuery(async () => {1763export 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}
public/scripts/extensions/vectors/manifest.json+4 -1
@@ -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}