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>
This commit is contained in:
+1
-1
@@ -741,7 +741,7 @@ async function firstLoadInit() {
|
||||
initKoboldSettings();
|
||||
initNovelAISettings();
|
||||
initSystemPrompts();
|
||||
initExtensions();
|
||||
await initExtensions();
|
||||
initExtensionSlashCommands();
|
||||
ToolManager.initToolSlashCommands();
|
||||
await initPresetManager();
|
||||
|
||||
@@ -435,7 +435,7 @@ async function updateCurrentAssets() {
|
||||
//#############################//
|
||||
|
||||
// This function is called when the extension is loaded
|
||||
jQuery(async () => {
|
||||
export async function init() {
|
||||
// This is an example of loading HTML from a file
|
||||
const windowTemplate = await renderExtensionTemplateAsync(MODULE_NAME, 'window', {});
|
||||
const windowHtml = $(windowTemplate);
|
||||
@@ -496,4 +496,4 @@ jQuery(async () => {
|
||||
eventSource.on(event_types.OPEN_CHARACTER_LIBRARY, async (forceDefault) => {
|
||||
openCharacterBrowser(forceDefault);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -7,5 +7,8 @@
|
||||
"css": "style.css",
|
||||
"author": "Keij#6799",
|
||||
"version": "0.1.0",
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern"
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern",
|
||||
"hooks": {
|
||||
"activate": "init"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -243,7 +243,7 @@ function handleCharacterRename(oldAvatar, newAvatar) {
|
||||
}
|
||||
}
|
||||
|
||||
jQuery(async () => {
|
||||
export async function init() {
|
||||
eventSource.on(event_types.APP_READY, cleanUpAttachments);
|
||||
eventSource.on(event_types.CHARACTER_DELETED, cleanUpCharacterAttachments);
|
||||
eventSource.on(event_types.CHARACTER_RENAMED, handleCharacterRename);
|
||||
@@ -407,4 +407,4 @@ jQuery(async () => {
|
||||
}),
|
||||
],
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -7,5 +7,8 @@
|
||||
"css": "style.css",
|
||||
"author": "Cohee1207",
|
||||
"version": "1.0.0",
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern"
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern",
|
||||
"hooks": {
|
||||
"activate": "init"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -455,7 +455,7 @@ function isVideoCaptioningAvailable() {
|
||||
return ['google', 'vertexai', 'zai'].includes(extension_settings.caption.multimodal_api);
|
||||
}
|
||||
|
||||
jQuery(async function () {
|
||||
export async function init() {
|
||||
function addSendPictureButton() {
|
||||
const sendButton = $(`
|
||||
<div id="send_picture" class="list-group-item flex-container flexGap5">
|
||||
@@ -808,4 +808,4 @@ jQuery(async function () {
|
||||
}));
|
||||
|
||||
document.body.classList.add('caption');
|
||||
});
|
||||
}
|
||||
|
||||
@@ -9,5 +9,8 @@
|
||||
"css": "style.css",
|
||||
"author": "Cohee#1207",
|
||||
"version": "1.0.0",
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern"
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern",
|
||||
"hooks": {
|
||||
"activate": "init"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -474,7 +474,7 @@ async function renderDetailsContent(detailsContent) {
|
||||
}
|
||||
}
|
||||
|
||||
(async function () {
|
||||
export async function init() {
|
||||
extension_settings.connectionManager = extension_settings.connectionManager || structuredClone(DEFAULT_SETTINGS);
|
||||
|
||||
for (const key of Object.keys(DEFAULT_SETTINGS)) {
|
||||
@@ -824,4 +824,4 @@ async function renderDetailsContent(detailsContent) {
|
||||
return JSON.stringify(profile);
|
||||
},
|
||||
}));
|
||||
})();
|
||||
}
|
||||
|
||||
@@ -7,5 +7,8 @@
|
||||
"css": "style.css",
|
||||
"author": "Cohee1207",
|
||||
"version": "1.0.0",
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern"
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern",
|
||||
"hooks": {
|
||||
"activate": "init"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2140,7 +2140,7 @@ function migrateSettings() {
|
||||
}
|
||||
}
|
||||
|
||||
(async function () {
|
||||
export async function init() {
|
||||
function addExpressionImage() {
|
||||
const html = `
|
||||
<div id="expression-wrapper">
|
||||
@@ -2511,4 +2511,4 @@ function migrateSettings() {
|
||||
</div>
|
||||
`,
|
||||
}));
|
||||
})();
|
||||
}
|
||||
|
||||
@@ -9,5 +9,8 @@
|
||||
"css": "style.css",
|
||||
"author": "Cohee#1207",
|
||||
"version": "1.0.0",
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern"
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern",
|
||||
"hooks": {
|
||||
"activate": "init"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -818,7 +818,7 @@ function addGalleryWandButton() {
|
||||
}
|
||||
|
||||
// On extension load, ensure the settings are initialized
|
||||
(function () {
|
||||
export async function init() {
|
||||
initSettings();
|
||||
eventSource.on(event_types.CHARACTER_RENAMED, (oldAvatar, newAvatar) => {
|
||||
const context = SillyTavern.getContext();
|
||||
@@ -850,4 +850,4 @@ function addGalleryWandButton() {
|
||||
}),
|
||||
);
|
||||
addGalleryWandButton();
|
||||
})();
|
||||
}
|
||||
|
||||
@@ -8,5 +8,8 @@
|
||||
"css": "style.css",
|
||||
"author": "City-Unit",
|
||||
"version": "1.5.0",
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern"
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern",
|
||||
"hooks": {
|
||||
"activate": "init"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1063,7 +1063,7 @@ function setupListeners() {
|
||||
});
|
||||
}
|
||||
|
||||
jQuery(async function () {
|
||||
export async function init() {
|
||||
async function addExtensionControls() {
|
||||
const settingsHtml = await renderExtensionTemplateAsync('memory', 'settings', { defaultSettings });
|
||||
$('#summarize_container').append(settingsHtml);
|
||||
@@ -1128,4 +1128,4 @@ jQuery(async function () {
|
||||
() => summaryMacroHandler(),
|
||||
'Returns the latest memory/summary from the current chat.');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -9,5 +9,8 @@
|
||||
"css": "style.css",
|
||||
"author": "Cohee#1207",
|
||||
"version": "1.0.0",
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern"
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern",
|
||||
"hooks": {
|
||||
"activate": "init"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,7 +169,7 @@ const handleCharChange = () => {
|
||||
settings.charConfig = charConfig;
|
||||
};
|
||||
|
||||
const init = async () => {
|
||||
export async function init() {
|
||||
await loadSets();
|
||||
await loadSettings();
|
||||
log('settings: ', settings);
|
||||
@@ -214,7 +214,8 @@ const init = async () => {
|
||||
eventSource.on(event_types.APP_READY, async () => await finalizeInit());
|
||||
|
||||
globalThis.quickReplyApi = quickReplyApi;
|
||||
};
|
||||
}
|
||||
|
||||
const finalizeInit = async () => {
|
||||
debug('executing startup');
|
||||
await autoExec.handleStartup();
|
||||
@@ -229,7 +230,7 @@ const finalizeInit = async () => {
|
||||
isReady = true;
|
||||
debug('READY');
|
||||
};
|
||||
await init();
|
||||
|
||||
|
||||
const purgeCharacterQuickReplySets = ({ character }) => {
|
||||
// Remove the character's Quick Reply Sets from the settings.
|
||||
|
||||
@@ -7,5 +7,8 @@
|
||||
"css": "style.css",
|
||||
"author": "RossAscends#1779",
|
||||
"version": "2.0.0",
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern"
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern",
|
||||
"hooks": {
|
||||
"activate": "init"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1709,7 +1709,7 @@ function onPresetRenamed({ apiId, oldName, newName }) {
|
||||
|
||||
// Workaround for loading in sequence with other extensions
|
||||
// NOTE: Always puts extension at the top of the list, but this is fine since it's static
|
||||
jQuery(async () => {
|
||||
export async function init() {
|
||||
if (!Array.isArray(extension_settings.regex)) {
|
||||
extension_settings.regex = [];
|
||||
}
|
||||
@@ -2154,4 +2154,4 @@ jQuery(async () => {
|
||||
|
||||
presetManager.setupEventListeners();
|
||||
presetManager.registerSlashCommands();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -7,5 +7,8 @@
|
||||
"css": "style.css",
|
||||
"author": "kingbri",
|
||||
"version": "1.0.0",
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern"
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern",
|
||||
"hooks": {
|
||||
"activate": "init"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5470,7 +5470,7 @@ function registerFunctionTool() {
|
||||
});
|
||||
}
|
||||
|
||||
jQuery(async () => {
|
||||
export async function init() {
|
||||
await addSDGenButtons();
|
||||
|
||||
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 () => {
|
||||
t`Character's negative Image Generation prompt prefix`,
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -10,5 +10,8 @@
|
||||
"css": "style.css",
|
||||
"author": "Cohee#1207",
|
||||
"version": "1.0.0",
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern"
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern",
|
||||
"hooks": {
|
||||
"activate": "init"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ async function doCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
jQuery(() => {
|
||||
export function init() {
|
||||
const buttonHtml = `
|
||||
<div id="token_counter" class="list-group-item flex-container flexGap5">
|
||||
<div class="fa-solid fa-1 extensionsMenuExtensionButton" /></div>` +
|
||||
@@ -115,4 +115,4 @@ jQuery(() => {
|
||||
returns: 'number of tokens',
|
||||
helpString: 'Counts the number of tokens in the current chat.',
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -7,5 +7,8 @@
|
||||
"css": "style.css",
|
||||
"author": "Cohee#1207",
|
||||
"version": "1.0.0",
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern"
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern",
|
||||
"hooks": {
|
||||
"activate": "init"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -707,7 +707,7 @@ const handleMessageReasoningDelete = createEventHandler(removeReasoningDisplayTe
|
||||
|
||||
globalThis.translate = translate;
|
||||
|
||||
jQuery(async () => {
|
||||
export async function init() {
|
||||
const html = await renderExtensionTemplateAsync('translate', 'index');
|
||||
const buttonHtml = await renderExtensionTemplateAsync('translate', 'buttons');
|
||||
|
||||
@@ -801,4 +801,4 @@ jQuery(async () => {
|
||||
},
|
||||
returns: ARGUMENT_TYPE.STRING,
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -7,5 +7,8 @@
|
||||
"css": "style.css",
|
||||
"author": "Cohee#1207",
|
||||
"version": "1.0.0",
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern"
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern",
|
||||
"hooks": {
|
||||
"activate": "init"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1531,7 +1531,7 @@ async function initVoiceMapInternal(unrestricted) {
|
||||
updateVoiceMap();
|
||||
}
|
||||
|
||||
jQuery(async function () {
|
||||
export async function init() {
|
||||
async function addExtensionControls() {
|
||||
const settingsHtml = $(await renderExtensionTemplateAsync('tts', 'settings'));
|
||||
$('#tts_container').append(settingsHtml);
|
||||
@@ -1619,4 +1619,4 @@ jQuery(async function () {
|
||||
}));
|
||||
|
||||
document.body.appendChild(audioElement);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -11,5 +11,8 @@
|
||||
"css": "style.css",
|
||||
"author": "Ouoertheo#7264",
|
||||
"version": "1.0.0",
|
||||
"homePage": "None"
|
||||
"homePage": "None",
|
||||
"hooks": {
|
||||
"activate": "init"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1760,7 +1760,7 @@ async function activateWorldInfo(chat) {
|
||||
await eventSource.emit(event_types.WORLDINFO_FORCE_ACTIVATE, activatedEntries);
|
||||
}
|
||||
|
||||
jQuery(async () => {
|
||||
export async function init() {
|
||||
if (!extension_settings.vectors) {
|
||||
extension_settings.vectors = settings;
|
||||
}
|
||||
@@ -2376,4 +2376,4 @@ jQuery(async () => {
|
||||
}
|
||||
await purgeAllVectorIndexes();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -10,5 +10,8 @@
|
||||
"css": "style.css",
|
||||
"author": "Cohee#1207",
|
||||
"version": "1.0.0",
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern"
|
||||
"homePage": "https://github.com/SillyTavern/SillyTavern",
|
||||
"hooks": {
|
||||
"activate": "init"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user