mirror of
				https://github.com/SillyTavern/SillyTavern.git
				synced 2025-06-05 21:59:27 +02:00 
			
		
		
		
	Auto-update extensions on version change
This commit is contained in:
		| @@ -609,6 +609,15 @@ async function showExtensionsDetails() { | ||||
|  */ | ||||
| async function onUpdateClick() { | ||||
|     const extensionName = $(this).data('name'); | ||||
|     await updateExtension(extensionName, false); | ||||
| } | ||||
|  | ||||
| /** | ||||
|  * Updates a third-party extension via the API. | ||||
|  * @param {string} extensionName Extension folder name | ||||
|  * @param {boolean} quiet If true, don't show a success message | ||||
|  */ | ||||
| async function updateExtension(extensionName, quiet) { | ||||
|     try { | ||||
|         const response = await fetch('/api/extensions/update', { | ||||
|             method: 'POST', | ||||
| @@ -618,15 +627,20 @@ async function onUpdateClick() { | ||||
|  | ||||
|         const data = await response.json(); | ||||
|         if (data.isUpToDate) { | ||||
|             toastr.success('Extension is already up to date'); | ||||
|             if (!quiet) { | ||||
|                 toastr.success('Extension is already up to date'); | ||||
|             } | ||||
|         } else { | ||||
|             toastr.success(`Extension updated to ${data.shortCommitHash}`); | ||||
|             toastr.success(`Extension ${extensionName} updated to ${data.shortCommitHash}`); | ||||
|         } | ||||
|  | ||||
|         if (!quiet) { | ||||
|             showExtensionsDetails(); | ||||
|         } | ||||
|         showExtensionsDetails(); | ||||
|     } catch (error) { | ||||
|         console.error('Error:', error); | ||||
|     } | ||||
| }; | ||||
| } | ||||
|  | ||||
| /** | ||||
|  * Handles the click event for the delete button of an extension. | ||||
| @@ -706,11 +720,16 @@ export async function installExtension(url) { | ||||
|     const response = await request.json(); | ||||
|     toastr.success(`Extension "${response.display_name}" by ${response.author} (version ${response.version}) has been imported successfully!`, 'Extension import successful'); | ||||
|     console.debug(`Extension "${response.display_name}" has been imported successfully at ${response.extensionPath}`); | ||||
|     await loadExtensionSettings({}); | ||||
|     await loadExtensionSettings({}, false); | ||||
|     eventSource.emit(event_types.EXTENSION_SETTINGS_LOADED); | ||||
| } | ||||
|  | ||||
| async function loadExtensionSettings(settings) { | ||||
| /** | ||||
|  * Loads extension settings from the app settings. | ||||
|  * @param {object} settings App Settings | ||||
|  * @param {boolean} versionChanged Is this a version change? | ||||
|  */ | ||||
| async function loadExtensionSettings(settings, versionChanged) { | ||||
|     if (settings.extension_settings) { | ||||
|         Object.assign(extension_settings, settings.extension_settings); | ||||
|     } | ||||
| @@ -723,10 +742,25 @@ async function loadExtensionSettings(settings) { | ||||
|     eventSource.emit(event_types.EXTENSIONS_FIRST_LOAD); | ||||
|     extensionNames = await discoverExtensions(); | ||||
|     manifests = await getManifests(extensionNames) | ||||
|  | ||||
|     if (versionChanged) { | ||||
|         await autoUpdateExtensions(); | ||||
|     } | ||||
|  | ||||
|     await activateExtensions(); | ||||
|     if (extension_settings.autoConnect && extension_settings.apiUrl) { | ||||
|         connectToApi(extension_settings.apiUrl); | ||||
|     } | ||||
|  | ||||
| } | ||||
|  | ||||
| async function autoUpdateExtensions() { | ||||
|     for (const [id, manifest] of Object.entries(manifests)) { | ||||
|         if (manifest.auto_update && id.startsWith('third-party')) { | ||||
|             console.debug(`Auto-updating 3rd-party extension: ${manifest.display_name} (${id})`); | ||||
|             await updateExtension(id.replace('third-party', ''), true); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| async function runGenerationInterceptors(chat, contextSize) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user