Installer
Install, update, configure, enable, disable, roll back and uninstall extensions.
ExtensionInstaller is the one place where an extension’s state changes. The admin
console, the management commands and the registry client all go through it, so every
action validates the archive, checks compatibility, runs the lifecycle hooks, and manages
the extension’s switches and SAM resources the same way.
An install or update proceeds in this order:
Validate the archive and its manifest, and check that the extension is compatible with this platform (Python, Smarter and dependency versions).
Import its code in this process, which proves that it loads and that its tools are valid, before anything is saved.
In a database transaction: save the version, run
pre_installorpre_upgrade, and make the version the installed one. A hook that raises rolls all of it back.Create its waffle switches, apply its manifests (and on an upgrade, delete the resources that the new version no longer ships), and run
post_installorpost_upgrade. A failure here leaves the extension installed but disabled, with the error recorded.
A new extension is installed disabled, as a WordPress plugin is installed inactive: an administrator configures its settings, then enables it.
- class smarter.apps.llmtool.extension.installer.ExtensionInstaller(user=None)[source]
Bases:
objectCarry out administrators’ actions on extensions.
- Parameters:
user (
User|None) – The superuser who carries out the actions. Resources that extensions create are owned by the platform’s admin user profile, not by this user, so that they outlive the user’s account.
Example usage:
installer = ExtensionInstaller(user=request.user) extension = installer.install(uploaded_file.read()) installer.configure(extension, {"google_maps_api_key": secret}) installer.enable(extension)
- apply_manifests(extension, loaded)[source]
Apply the SAM manifests in a version’s
manifests/directory, in filename order.Resources that an earlier version applied from its manifests, and that this version no longer ships, are deleted.
- Return type:
- configure(extension, values)[source]
Set some of an extension’s settings.
- Parameters:
- Raises:
SmarterExtensionInstallError – If a setting is not declared, or a value is not valid.
- Return type:
- context(extension, manifest, previous_version=None)[source]
Return the context of a lifecycle hook.
- Return type:
- disable(extension, reason='disabled by an administrator')[source]
Disable an extension, so that no LLM is offered its tools.
Takes effect on the next prompt in every pod.
An
on_disablehook that fails is logged, and the extension is disabled anyway.
- enable(extension)[source]
Enable an extension, so that LLMClients that list it offer its tools.
- Parameters:
extension (
Extension) – The extension.- Return type:
- Returns:
The extension.
- Raises:
SmarterExtensionInstallError – If it is not installed, is incompatible, or has required settings that are not configured.
SmarterExtensionLoadError – If its code does not load.
- finish_install(extension, version, loaded, lifecycle, previous_version)[source]
Create the switches, apply the manifests and run the post hook of a version that was just installed.
A failure leaves the extension installed but disabled, with the error recorded.
- Return type:
- install(data, source=ExtensionSource.UPLOAD, trust_badge=ExtensionTrustBadge.UNVERIFIED, publisher=None, source_url='')[source]
Install an extension archive, or update an installed extension to the archive’s version.
Installing the version that is already installed, from the same archive, does nothing.
- Parameters:
data (
bytes) – The archive’s bytes.source (
str) – Where the archive came from.trust_badge (
str) – The publisher’s trust badge, from the registry, orunverifiedfor an upload.publisher (
str|None) – The publisher’s registry id; defaults to the manifest’s authors.source_url (
str) – Where the archive was downloaded from, if anywhere.
- Return type:
- Returns:
The extension.
- Raises:
SmarterExtensionArchiveError – If the archive is not valid.
SmarterExtensionManifestError – If its manifest is not valid.
SmarterExtensionInstallError – If it is not compatible, conflicts with an installed version, or a pre hook refuses it.
SmarterExtensionLoadError – If its code does not load.
- installed_manifest(extension)[source]
Return the manifest of an extension’s installed version.
- Return type:
- rollback(extension, version)[source]
Make an earlier installed version the one that runs, as an update to it would.
- Parameters:
extension (
Extension) – The extension.version (
ExtensionVersion) – One of its versions.
- Return type:
- Returns:
The extension.
- uninstall(extension)[source]
Uninstall an extension: its resources, switches, settings, versions, and LLMClients’ links to it.
- Parameters:
extension (
Extension) – The extension.- Raises:
SmarterExtensionInstallError – If its
pre_uninstallhook refuses.- Return type:
- smarter.apps.llmtool.extension.installer.SettingInput = str | int | float | bool | smarter.apps.secret.models.Secret | None
text or a typed value, a Secret for a secret setting, or None to clear it.
- Type:
A value to configure