Api
The Extensions api’s handlers, which the web console’s Extensions pages and the REST api share, and the
REST api under /api/v1/extensions/.
The web console’s Extensions pages, and their api.
Superusers manage extensions on two pages of the single-page console (ADR-035), which renders
@smarter/extension-console’s list or an extension’s page at their paths. Every other user sees
the same pages read-only: the extensions that their account may use, without their settings, their
availability or the platform admin’s Secrets, and without any action.
Extensions (
/extensions/): the installed extensions, and the registry’s, which can be installed, and an archive’s upload.An extension (
/extensions/<slug>/): its documentation, tools, settings, availability, versions and resources, and every action on it.
The api is a set of POST endpoints in the web console’s api, under /api/web/llmtool/extensions/
(see smarter.apps.llmtool.extension.api.web.urls). The actions are for superusers only; the
list, the registry and an extension’s detail are read-only for everyone else. Each validates its request and builds its response with the models of
contract, and carries out its action with the
ExtensionInstaller or the
registry client, as the admin console and the management
commands do. An action’s failure is a 400 with {"error": "..."}, whose message is meant for
the person who tried it.
- class smarter.apps.llmtool.extension.views.ExtensionAccountsApiView(**kwargs)[source]
Bases:
ExtensionAccountsHandler,ExtensionApiViewEvery account, for the availability picker.
- class smarter.apps.llmtool.extension.views.ExtensionAccountsHandler[source]
Bases:
ExtensionApiHandlerEvery account, for the availability picker.
- class smarter.apps.llmtool.extension.views.ExtensionActionHandler[source]
Bases:
ExtensionApiHandlerThe base class of an action on one extension:
act()returns the message of its success.- handle(request, body, slug='', **kwargs)[source]
Act on an extension, then return the message and the extension as it now is.
- Parameters:
request – The request.
body – The request’s body, validated by
request_model, or None.slug (
str) – The extension’s slug, from the url.
- Return type:
ActionResponse- Returns:
The message, and the extension’s detail, or None if the action uninstalled it.
- class smarter.apps.llmtool.extension.views.ExtensionApiHandler[source]
Bases:
objectThe logic of one endpoint of the Extensions api, apart from how its request arrives and its response leaves.
Two transports mix it in:
ExtensionApiView, the web console’s api (POST only, a Django session, errors as{"error": ...}), andsmarter.apps.llmtool.extension.api.v1.views.ExtensionApiV1View, the REST api under/api/v1/extensions/(an api key, errors as{"detail": ...}). A transport implementsrequest_data(), callsrespond(), and turns its result into a response.Subclasses implement
handle(), which returns a contract model, and setrequest_modelif the request has a body.- extension(slug)[source]
Return an installed extension, or raise Extension.DoesNotExist.
- Return type:
- handle(request, body, **kwargs)[source]
Carry out the request, and return its response’s model.
- Parameters:
request – The request.
body (
BaseModel|None) – The request’s body, validated byrequest_model, or None if it has none.kwargs – Keyword arguments from the url.
- Return type:
ExtensionConsoleModel- Returns:
The response’s contract model.
- Raises:
ValueError – If the request is not valid.
Extension.DoesNotExist – If the extension is not installed.
SmarterExtensionException – If the extension cannot be acted on.
- parse(request)[source]
Validate the request’s data with
request_model.A request without a model is not read at all: a multipart upload’s body can’t be read again.
- Parameters:
request – The request.
- Return type:
BaseModel|None- Returns:
The validated request, or None if the endpoint takes none.
- Raises:
ValueError – If the request is not valid.
- read_only: bool = False
Whether every user may call it.
It then shows a user who is not a superuser only what they may see.
- request_data(request)[source]
Return the request’s data, as a dict, for
request_modelto validate: its JSON body.The web console’s api sends JSON. The REST api’s transport overrides it with DRF’s parsed data.
- Parameters:
request – The request.
- Return type:
- Returns:
The body, or an empty dict if it has none, or it is not an object.
- Raises:
ValueError – If the body is not JSON.
- respond(request, **kwargs)[source]
Check permission, validate the request, and call
handle(), turning its exceptions into errors.- Parameters:
request – The request.
kwargs – Keyword arguments from the url, e.g.
slug, passed tohandle().
- Return type:
tuple[HTTPStatus,ExtensionConsoleModel|str]- Returns:
The status and the model that
handle()returns, or an error’s status and message: 403 for a user who is not a superuser, unlessread_onlyis set, 400 for a request that is not valid or an extension error, 404 for an extension that is not installed, and 500 for anything else.
- class smarter.apps.llmtool.extension.views.ExtensionApiView(**kwargs)[source]
Bases:
ExtensionApiHandler,SmarterAuthenticatedNeverCachedWebViewThe base class of the web console’s Extensions api: POST only, JSON in and out, and a Django session.
Its concrete views mix a handler in before it, e.g.
ExtensionEnableApiView(ExtensionEnableHandler, ExtensionApiView). Errors are{"error": ...}.- error(message, status=HTTPStatus.BAD_REQUEST)[source]
Return an error response.
- Parameters:
message (
str) – What went wrong.status (
HTTPStatus) – The HTTP status.
- Return type:
- Returns:
{"error": message}, with the status.
- class smarter.apps.llmtool.extension.views.ExtensionAvailabilityApiView(**kwargs)[source]
Bases:
ExtensionAvailabilityHandler,ExtensionApiViewChange which accounts may use an extension.
- class smarter.apps.llmtool.extension.views.ExtensionAvailabilityHandler[source]
Bases:
ExtensionActionHandlerChange which accounts may use an extension.
- act(request, extension, body)[source]
Make the extension available to every account, or to the given accounts.
- Raises:
ValueError – If some of the accounts do not exist.
- Return type:
- request_model
alias of
AvailabilityRequest
- class smarter.apps.llmtool.extension.views.ExtensionCheckUpdatesApiView(**kwargs)[source]
Bases:
ExtensionCheckUpdatesHandler,ExtensionApiViewCheck the registry for updates now.
- class smarter.apps.llmtool.extension.views.ExtensionCheckUpdatesHandler[source]
Bases:
ExtensionApiHandlerCheck the registry for updates now.
- class smarter.apps.llmtool.extension.views.ExtensionConfigureApiView(**kwargs)[source]
Bases:
ExtensionConfigureHandler,ExtensionApiViewChange some of an extension’s settings.
- class smarter.apps.llmtool.extension.views.ExtensionConfigureHandler[source]
Bases:
ExtensionActionHandlerChange some of an extension’s settings.
- act(request, extension, body)[source]
Save the extension’s settings.
A secret setting is given a new value, which is saved, encrypted, in a Secret owned by the platform admin, or the id of one of the platform admin’s Secrets, or neither, which clears it.
- Raises:
ValueError – If the extension has no installed version, a secret setting does not exist, or a Secret is not one of the platform admin’s.
- Return type:
- request_model
alias of
ConfigureRequest
- class smarter.apps.llmtool.extension.views.ExtensionDetailApiView(**kwargs)[source]
Bases:
ExtensionDetailHandler,ExtensionApiViewAn extension’s detail page.
- class smarter.apps.llmtool.extension.views.ExtensionDetailHandler[source]
Bases:
ExtensionApiHandlerEverything that an extension’s detail page shows, and less to a user who is not a superuser.
- handle(request, body, slug='', **kwargs)[source]
Return an extension’s detail, or its read-only detail to a user who is not a superuser.
- Parameters:
request – The request.
body – None: the request has no body.
slug (
str) – The extension’s slug, from the url.
- Return type:
ExtensionDetailResponse- Returns:
The extension’s detail.
- Raises:
Extension.DoesNotExist – If it is not installed, or the requesting user may not see it.
- class smarter.apps.llmtool.extension.views.ExtensionDetailView(**kwargs)[source]
Bases:
ConsoleAppViewAn extension’s page,
/extensions/<slug>/: the single-page console’s.The console shows anyone the page, and the api refuses an extension that the requesting user may not see, as
ExtensionApiView.visible()decides.
- class smarter.apps.llmtool.extension.views.ExtensionDisableApiView(**kwargs)[source]
Bases:
ExtensionDisableHandler,ExtensionApiViewDisable an extension.
- class smarter.apps.llmtool.extension.views.ExtensionDisableHandler[source]
Bases:
ExtensionActionHandlerDisable an extension.
- class smarter.apps.llmtool.extension.views.ExtensionEnableApiView(**kwargs)[source]
Bases:
ExtensionEnableHandler,ExtensionApiViewEnable an extension.
- class smarter.apps.llmtool.extension.views.ExtensionEnableHandler[source]
Bases:
ExtensionActionHandlerEnable an extension.
- class smarter.apps.llmtool.extension.views.ExtensionInstallApiView(**kwargs)[source]
Bases:
ExtensionInstallHandler,ExtensionApiViewInstall, or update, an extension from the registry.
- class smarter.apps.llmtool.extension.views.ExtensionInstallHandler[source]
Bases:
ExtensionApiHandlerInstall, or update, an extension from the registry.
- handle(request, body, **kwargs)[source]
Install, or update, an extension from the registry.
- Parameters:
request – The request.
body (
BaseModel|None) – The extension’s slug, and optionally its version.
- Return type:
ActionResponse- Returns:
A message, and the installed extension.
- request_model
alias of
InstallRequest
- class smarter.apps.llmtool.extension.views.ExtensionListApiView(**kwargs)[source]
Bases:
ExtensionListHandler,ExtensionApiViewThe installed extensions that the requesting user may see, and the state of the registry.
- class smarter.apps.llmtool.extension.views.ExtensionListHandler[source]
Bases:
ExtensionApiHandlerThe installed extensions that the requesting user may see, and the state of the registry.
- handle(request, body, **kwargs)[source]
List the installed extensions that the requesting user may see, by display name.
- Parameters:
request – The request.
body – None: the request has no body.
- Return type:
ExtensionListResponse- Returns:
The extensions, whether the registry is enabled, and how many updates are available.
- class smarter.apps.llmtool.extension.views.ExtensionListView(**kwargs)[source]
Bases:
ConsoleAppViewThe Extensions page,
/extensions/: the single-page console’s, at the path that Django served it at.
- class smarter.apps.llmtool.extension.views.ExtensionRegistryApiView(**kwargs)[source]
Bases:
ExtensionRegistryHandler,ExtensionApiViewThe registry’s extensions, with what each offers on this platform.
- class smarter.apps.llmtool.extension.views.ExtensionRegistryHandler[source]
Bases:
ExtensionApiHandlerThe registry’s extensions, with what each offers on this platform.
Only a superuser may refresh it.
- handle(request, body, **kwargs)[source]
Return the registry’s extensions, from the cached index, or from the registry if a superuser asks to refresh it.
- Parameters:
request – The request.
body (
BaseModel|None) – Whether to refresh the index.
- Return type:
RegistryResponse- Returns:
The registry’s extensions, or an error if the registry is disabled or cannot be read.
- read_only: bool = True
Whether every user may call it.
It then shows a user who is not a superuser only what they may see.
- request_model
alias of
RegistryRequest
- class smarter.apps.llmtool.extension.views.ExtensionRollbackApiView(**kwargs)[source]
Bases:
ExtensionRollbackHandler,ExtensionApiViewMake an earlier version of an extension the one that runs.
- class smarter.apps.llmtool.extension.views.ExtensionRollbackHandler[source]
Bases:
ExtensionActionHandlerMake an earlier version of an extension the one that runs.
- act(request, extension, body)[source]
Make one of the extension’s installed versions the one that runs.
- Raises:
ValueError – If the version is not one of the extension’s.
- Return type:
- request_model
alias of
RollbackRequest
- class smarter.apps.llmtool.extension.views.ExtensionUninstallApiView(**kwargs)[source]
Bases:
ExtensionUninstallHandler,ExtensionApiViewUninstall an extension.
- class smarter.apps.llmtool.extension.views.ExtensionUninstallHandler[source]
Bases:
ExtensionActionHandlerUninstall an extension.
- class smarter.apps.llmtool.extension.views.ExtensionUpdateApiView(**kwargs)[source]
Bases:
ExtensionUpdateHandler,ExtensionApiViewUpdate an extension to the registry’s newest compatible version.
- class smarter.apps.llmtool.extension.views.ExtensionUpdateHandler[source]
Bases:
ExtensionActionHandlerUpdate an extension to the registry’s newest compatible version.
- class smarter.apps.llmtool.extension.views.ExtensionUploadApiView(**kwargs)[source]
Bases:
ExtensionUploadHandler,ExtensionApiViewInstall, or update, an extension from an uploaded archive.
- class smarter.apps.llmtool.extension.views.ExtensionUploadHandler[source]
Bases:
ExtensionApiHandlerInstall, or update, an extension from an uploaded archive: a multipart request with the file
archive.- handle(request, body, **kwargs)[source]
Install an extension from the uploaded archive.
- Parameters:
request – The multipart request, with the file
archive.body – None: the archive is a file, not a JSON body.
- Return type:
ActionResponse- Returns:
A message, and the installed extension.
- Raises:
ValueError – If no archive was uploaded, or it is larger than
MAX_UPLOAD_BYTES.
- smarter.apps.llmtool.extension.views.extension_detail(extension)[source]
Return everything that an extension’s detail page shows.
- Parameters:
extension (
Extension) – The extension.- Return type:
ExtensionDetail
- smarter.apps.llmtool.extension.views.read_only_detail(detail)[source]
Return what a user who is not a superuser may see of an extension’s detail page.
Its settings, the accounts that may use it, the platform admin’s Secrets and who installed each version are left out.
- Parameters:
detail (
ExtensionDetail) – Everything that the detail page shows a superuser.- Return type:
ExtensionDetail
- smarter.apps.llmtool.extension.views.registry_extensions(index)[source]
Return the registry’s extensions, with what each card offers on this platform.
- Parameters:
index (
RegistryIndex) – The registry’s verified index.- Return type:
list[RegistryExtension]
The Extensions REST api, under /api/v1/extensions/: what the web console’s Extensions pages do, with an api key.
GET extensions/: the installed extensions that the user may see, and the state of the registry.GET extensions/registry/: the registry’s extensions.?refresh=truedownloads the index again, for a superuser.POST extensions/check-updates/: check the registry for updates now.POST extensions/install/: install, or update, an extension from the registry,{"slug": ..., "version": ...}.POST extensions/upload/: install, or update, an extension from a .zip archive, as multipart/form-data with the filearchive.GET extensions/<slug>/: an extension’s detail, and less of it to a user who is not a superuser.POST extensions/<slug>/enable/,disable/,update/,rollback/,configure/,availability/anduninstall/: the actions on an extension.
The reads are for every user, who sees only the extensions that their account may use. Everything else is
for superusers only. Each view mixes one of the handlers of smarter.apps.llmtool.extension.views,
which the web console’s api uses too, into ExtensionApiV1View. The responses are the models of
smarter.apps.llmtool.extension.contract, which the Smarter api’s OpenAPI document publishes. Errors
are Django REST framework’s {"detail": ...}.
- class smarter.apps.llmtool.extension.api.v1.views.ExtensionApiV1ActionView(*args, **kwargs)[source]
Bases:
ExtensionApiV1ViewAn action: POST.
- class smarter.apps.llmtool.extension.api.v1.views.ExtensionApiV1ReadView(*args, **kwargs)[source]
Bases:
ExtensionApiV1ViewA read: GET.
- class smarter.apps.llmtool.extension.api.v1.views.ExtensionApiV1View(*args, **kwargs)[source]
Bases:
ExtensionApiHandler,SmarterAuthenticatedAPIViewThe base class of the Extensions REST api: an api key, JSON or multipart in, JSON out.
The data of a GET is its query string, and of a POST its body. Errors are
{"detail": ...}.
- class smarter.apps.llmtool.extension.api.v1.views.ExtensionV1AvailabilityView(*args, **kwargs)[source]
Bases:
ExtensionAvailabilityHandler,ExtensionApiV1ActionViewChange which accounts may use an extension.
- class smarter.apps.llmtool.extension.api.v1.views.ExtensionV1CheckUpdatesView(*args, **kwargs)[source]
Bases:
ExtensionCheckUpdatesHandler,ExtensionApiV1ActionViewCheck the registry for updates now.
- class smarter.apps.llmtool.extension.api.v1.views.ExtensionV1ConfigureView(*args, **kwargs)[source]
Bases:
ExtensionConfigureHandler,ExtensionApiV1ActionViewChange some of an extension’s settings.
- class smarter.apps.llmtool.extension.api.v1.views.ExtensionV1DetailView(*args, **kwargs)[source]
Bases:
ExtensionDetailHandler,ExtensionApiV1ReadViewAn installed extension.
- class smarter.apps.llmtool.extension.api.v1.views.ExtensionV1DisableView(*args, **kwargs)[source]
Bases:
ExtensionDisableHandler,ExtensionApiV1ActionViewDisable an extension.
- class smarter.apps.llmtool.extension.api.v1.views.ExtensionV1EnableView(*args, **kwargs)[source]
Bases:
ExtensionEnableHandler,ExtensionApiV1ActionViewEnable an extension.
- class smarter.apps.llmtool.extension.api.v1.views.ExtensionV1InstallView(*args, **kwargs)[source]
Bases:
ExtensionInstallHandler,ExtensionApiV1ActionViewInstall, or update, an extension from the registry.
- class smarter.apps.llmtool.extension.api.v1.views.ExtensionV1ListView(*args, **kwargs)[source]
Bases:
ExtensionListHandler,ExtensionApiV1ReadViewThe installed extensions that the user may see.
- class smarter.apps.llmtool.extension.api.v1.views.ExtensionV1RegistryView(*args, **kwargs)[source]
Bases:
ExtensionRegistryHandler,ExtensionApiV1ReadViewThe registry’s extensions.
- class smarter.apps.llmtool.extension.api.v1.views.ExtensionV1RollbackView(*args, **kwargs)[source]
Bases:
ExtensionRollbackHandler,ExtensionApiV1ActionViewMake an earlier version of an extension the one that runs.
- class smarter.apps.llmtool.extension.api.v1.views.ExtensionV1UninstallView(*args, **kwargs)[source]
Bases:
ExtensionUninstallHandler,ExtensionApiV1ActionViewUninstall an extension.
- class smarter.apps.llmtool.extension.api.v1.views.ExtensionV1UpdateView(*args, **kwargs)[source]
Bases:
ExtensionUpdateHandler,ExtensionApiV1ActionViewUpdate an extension to the registry’s newest compatible version.
- class smarter.apps.llmtool.extension.api.v1.views.ExtensionV1UploadView(*args, **kwargs)[source]
Bases:
ExtensionUploadHandler,ExtensionApiV1ActionViewInstall, or update, an extension from an uploaded .zip archive.