Resources

The SAM resources and waffle switches that an extension creates.

Manifests are applied through the real SAM brokers, exactly as manage.py apply_manifest does, so a resource that an extension creates is the same as one a person applies. Each is recorded as an ExtensionResource, so that uninstalling the extension deletes exactly what it created.

smarter.apps.llmtool.extension.resources.apply_extension_manifest(extension, manifest, user_profile, version, managed=True)[source]

Apply a SAM manifest for an extension, and record the resource it creates.

Parameters:
  • extension (Extension) – The extension.

  • manifest (str) – The manifest, as YAML or JSON.

  • user_profile (UserProfile) – The resource’s owner.

  • version (str) – The extension version that applies it.

  • managed (bool) – Whether it comes from the package’s manifests/ directory.

Return type:

tuple[str, str]

Returns:

The resource’s kind and name.

Raises:

SmarterExtensionInstallError – If the manifest is not valid, or cannot be applied.

smarter.apps.llmtool.extension.resources.create_switches(manifest)[source]

Create an extension’s waffle switches, leaving any that already exist as they are.

Parameters:

manifest (ExtensionManifest) – The extension’s manifest.

Return type:

list[str]

Returns:

The names of the switches.

smarter.apps.llmtool.extension.resources.delete_extension_resource(extension, kind, name, user_profile)[source]

Delete a resource that an extension created, and forget it.

A resource that no longer exists is simply forgotten. A failure is logged, and the resource is forgotten anyway, so that an uninstall always finishes.

Parameters:
  • extension (Extension) – The extension.

  • kind (str) – The resource’s kind.

  • name (str) – The resource’s name.

  • user_profile (UserProfile) – The resource’s owner.

Return type:

None

smarter.apps.llmtool.extension.resources.delete_switches(manifest, keep=frozenset({}))[source]

Delete an extension’s waffle switches.

Parameters:
  • manifest (ExtensionManifest) – The manifest whose switches are deleted.

  • keep (frozenset[str]) – Names, without the prefix, of switches not to delete, e.g. those the new version still declares.

Return type:

None