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:

  1. Validate the archive and its manifest, and check that the extension is compatible with this platform (Python, Smarter and dependency versions).

  2. Import its code in this process, which proves that it loads and that its tools are valid, before anything is saved.

  3. In a database transaction: save the version, run pre_install or pre_upgrade, and make the version the installed one. A hook that raises rolls all of it back.

  4. Create its waffle switches, apply its manifests (and on an upgrade, delete the resources that the new version no longer ships), and run post_install or post_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: object

Carry 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)
__init__(user=None)[source]
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:

None

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:

None

context(extension, manifest, previous_version=None)[source]

Return the context of a lifecycle hook.

Return type:

LifecycleContext

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_disable hook that fails is logged, and the extension is disabled anyway.

Parameters:
  • extension (Extension) – The extension.

  • reason (str) – Why it is disabled.

Return type:

Extension

Returns:

The extension.

enable(extension)[source]

Enable an extension, so that LLMClients that list it offer its tools.

Parameters:

extension (Extension) – The extension.

Return type:

Extension

Returns:

The extension.

Raises:
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:

None

property formatted_class_name: str

The class name, for logging.

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, or unverified for 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:

Extension

Returns:

The extension.

Raises:
installed_manifest(extension)[source]

Return the manifest of an extension’s installed version.

Return type:

ExtensionManifest

record_failure(extension, message)[source]

Disable an extension, and record why.

Return type:

None

rollback(extension, version)[source]

Make an earlier installed version the one that runs, as an update to it would.

Parameters:
Return type:

Extension

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_uninstall hook refuses.

Return type:

None

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