Host capabilities
Reference for what a plugin can ask the host to do, including reading services and plugins, checking permissions, queueing jobs, and publishing events.
On this page
The context that a plugin receives is more than its settings. It carries capabilities that the host provides: catalogs of services and plugins, permission checks, a job queue, and the event log. The host keeps credentials private and checks permissions, so a plugin never sees a connection secret or another plugin’s internals.
Read services#
context.services is a catalog of the services that the caller can see. It works with any adapter, so a plugin never imports or names one.
| Method | Returns |
|---|---|
list({ cursor?, limit? }) | A page of service summaries, and a nextCursor when more follow |
get(id) | One summary, or null when the service doesn’t exist or isn’t visible |
listResources(id) | The adapter’s declared resources, with descriptions and input schemas, or null |
listActions(id) | The adapter’s declared actions, or null |
queryResource(id, resourceId, input) | The data of a resource |
executeAction(id, actionId, input) | The result of an action |
signals(id) | The signals that the service’s adapter can publish, as qualified IDs with their types, or null. Optional |
probe(id, { timeoutMs? }) | The service’s health, score, and checks, or null. The host opens the connection and calls the adapter’s health check |
datasets.list(id, { cursor?, limit? }, { signal?, timeoutMs? }) | A page of the datasets that the service’s adapter describes, or null. Optional |
datasets.observe(id, refs, { signal?, timeoutMs? }) | The measurements of up to 500 datasets, or null. Optional |
A summary has an id, a name, the adapter ID, an optional adapterName and iconUrl, and managedBy, which is configuration or ui. It also has capabilities, the optional abilities that the adapter declares, such as datasets. A host that predates the field omits it, so read a missing value as no capabilities.
const resources = await context.services.listResources(serviceId);
const data = await context.services.queryResource(serviceId, "status", {});
const result = await context.services.executeAction(serviceId, "check-now", {});Discovery doesn’t open a connection. The host validates every input against the adapter’s declaration, and it checks the inspect permission for resources and execute for actions. An optional method, such as signals, is missing on a host that doesn’t support it, so check that it exists before you rely on it.
Read datasets#
datasets reads what an adapter says about the tables, files, or assets behind a service. It needs only the inspect permission, because neither call changes anything in the connected system. Check that capabilities includes datasets first. A service whose adapter doesn’t declare it fails with a request error, status 422. The adapter side is described in Datasets.
const service = await context.services.get(serviceId);
if (service?.capabilities?.includes("datasets")) {
const page = await context.services.datasets?.list(serviceId, { limit: 500 });
const refs = page?.items.map((item) => item.ref) ?? [];
const observed = await context.services.datasets?.observe(serviceId, refs);
}Each call stops at timeoutMs, which defaults to 30,000 and which the host caps at 60,000. Pass a signal to cancel earlier. observe accepts at most DATASET_OBSERVE_MAX_REFS references, which is 500, so split a longer list into several calls. The host checks the caller’s access again after the adapter answers and drops the result if the access was revoked meanwhile.
Read other plugins#
context.plugins offers the same shape for plugins. It lists the plugins that the caller can see, with their status, resources, and actions, and it can query a resource or execute an action:
const plugins = await context.plugins.list();
const result = await context.plugins.executeAction(pluginId, "shout", { text: "hi" });The host filters discovery by the caller’s permission, validates inputs against their declarations, and checks the permission that an action declares. A plugin never receives another plugin’s context or storage.
Check permissions#
A permission on a procedure covers the plugin, not each service. When an operation affects a service, call access.require as well:
await context.access.require(serviceId, "execute");require(serviceId, permission) throws when the caller doesn’t hold the permission for that service. It checks the permission, and it doesn’t check that the service exists. The other access methods are:
| Method | Meaning |
|---|---|
principal() | The person who made the request, as { id, role }. Absent in background work |
requireAdmin() | Requires the owner or admin role and the manage permission on the plugin. Use it for settings and secrets that cover the installation |
requirePrincipal(principalId, serviceId, permission) | Checks the current role of a named person, for work that you do on their behalf. See below |
require(serviceId, permission, { actionId, actionInput }) | Checks a permission for one action on a service |
Work on someone’s behalf#
A job runs as trusted code without a signed-in person. When it acts for a person, such as an assistant that continues their request, call requirePrincipal before each operation. DSUI resolves the person again through the authentication plugin, so a removed or demoted person loses access at once. An authentication provider supports this by implementing resolvePrincipal(id), which returns the current role or null. Without that, the check fails safely. With no authentication plugin, only the local owner can be resolved.
Queue jobs and publish events#
context.jobs.enqueue(jobId, input): queues a job that your plugin owns. See jobscontext.events.emit(signalId, payload, serviceId?)andcontext.events.read(options): publish and read events. See signals and events
Depend on optional capabilities#
Some capabilities are optional, so an older host may not provide them. These include services.signals, events.read, access.requireAdmin, access.requirePrincipal, and storage.migrate. Calling a capability that the host lacks throws Plugin host capability is unavailable. The plugin API version 1 doesn’t promise that every optional capability exists. State the capabilities that your plugin needs in its README and release notes, and see versions and compatibility.