Skip to content

Integrations

Build an export destination plugin

How a third-party plugin adds a Canvas export destination through the published CanvasExportTarget seam — contribution, approval card, receipt or typed refusal.

  • 7 min read
  • 7 sections

Build an export destination plugin ​

A Canvas export destination is a plugin that implements one published port: CanvasExportTarget from @octant/plugin-api/canvas-export. The host owns rendering, the share filter, the approval card, and the journal; the plugin is called to export only after the person approves the exact payload and the destination, and returns a receipt or a typed refusal. An optional destination description runs before approval without permission to upload. Nothing about the seam reaches host internals — the in-tree destinations (folder, GitHub Gist, sharehtml.org, public link) use this same port.

A callable reference factory lives at packages/plugin-api/examples/docs-md-export (share a Canvas as an unlisted page on an external REST host).

Platforms

Installed export destinations run on macOS. Linux and Windows refuse this worker capability until their confinement boundaries are in place.

An installed export destination ​

Put octant-canvas-export.json at the package root. Its top-level object contains manifest, the author-owned extension manifest. The host assigns the installed identity, source, content digest and review facts; do not provide those as package claims.

The manifest declares exactly one component with these fields:

FieldValue
kindcanvas-export-target
entryPointA bundled .mjs or .js module, with file mode 0644
declaredCapabilitiesEmpty, or network only; declare it at package and component level when origins are present
canvasExport.contributionThe existing CanvasExportContribution, naming the target, label and accepted formats
canvasExport.allowedOriginsAt most eight exact HTTPS origins

For example, this octant-canvas-export.json declares a Markdown destination. Replace the sample origin with your service's exact HTTPS origin, without a trailing slash or path.

json
{
  "manifest": {
    "manifestVersion": 1,
    "slug": "page-export",
    "displayName": "Page export",
    "version": "1.0.0",
    "license": { "kind": "spdx", "identifier": "MIT" },
    "compatibility": {
      "platforms": ["macos"],
      "modes": ["chat", "work", "code"],
      "providerFamilies": []
    },
    "declaredCapabilities": ["network"],
    "components": [
      {
        "id": "page-export",
        "kind": "canvas-export-target",
        "displayName": "Page export",
        "declaredCapabilities": ["network"],
        "entryPoint": "dist/export.mjs",
        "canvasExport": {
          "contribution": {
            "schemaVersion": 1,
            "kind": "canvas-export-contribution",
            "targetId": "page-export",
            "label": "Page export",
            "formats": ["markdown"]
          },
          "allowedOrigins": ["https://pages.example.invalid"]
        }
      }
    ]
  }
}

The entry module exports canvasExport, implementing the public target port. Bundle its dependencies into that module. The host runs it in a fresh supervised process for each description and each export; it never imports the package into the authoritative server process. Do not rely on memory carrying over from a description to an export. Installation runs no dependency resolution or package scripts, and the package must contain no executable files.

Import the package with the local folder picker in Settings → Skills & Extensions. This package layout currently accepts local folders only, not npm or catalog sources. Inspect the package, install it, trust its source and declared executable kind, then enable its package and component. These are separate decisions. The host offers only a target that passes the existing installed, trusted, enabled, compatible and effective checks. Disabling or revoking it invalidates a held approval; installing or trusting it never approves an export.

Build and install the reference package ​

The reference includes the package document and a callable factory. Use an Octant build that supports this package format and supervised Canvas export workers; older builds cannot load it. The example manifest declares a portable component, but native execution currently requires the macOS worker boundary.

From the application repository root, with its dependencies installed, build the module named by the reference manifest:

sh
bun build packages/plugin-api/examples/docs-md-export/index.mjs \
  --target=node --minify \
  --outfile packages/plugin-api/examples/docs-md-export/dist/index.mjs

The bundle includes the public SDK's runtime schemas. The unbundled source has a bare SDK import that an isolated installed package cannot resolve from the host checkout.

In Settings → Skills & Extensions, import packages/plugin-api/examples/docs-md-export as a local plugin folder. Inspect its manifest, install it, trust its source, then enable both the package and its export component. An effective destination appears in the Canvas export panel. Review the exact payload and destination before approving an export.

The anonymous example targets https://docs-md.com/api/v1. Its API is illustrative and has not been verified against the live service. For another compatible host, set the default entry's apiBase and the manifest's exact allowedOrigins before rebuilding and reviewing the package. Installed workers receive no inherited host environment: setting DOCS_MD_API_BASE on Octant does not configure this package. They also receive no host key or authenticated connection; a protected service can refuse an anonymous request.

Description before approval ​

describeDestination may return a value or a promise. Existing synchronous targets remain compatible. The description has an eight-second worker deadline within a ten-second host deadline and cannot use network access. Package inspection also makes no network request on the plugin's behalf. Describe the planned destination from local input; do not fetch an account or upload a draft.

Network after approval ​

Only an approved export can request host-mediated HTTPS access. Requests must match the manifest's exact origins and resolve to public IP addresses. The host never follows redirects; it returns their HTTP status to the plugin. Only Accept and Content-Type request headers are allowed. Ambient cookies, authentication and credential headers, and access outside the declared origins are unavailable. Each export is limited to eight requests, four concurrent requests and a thirty-second deadline. A request body is limited to 8 MiB and a response body to 1 MiB.

The worker has no filesystem, shell or credential grant. An export destination that needs an account key cannot obtain it through this installed-worker path. Selecting a profile, installing a package or approving one document does not provide a key or broaden that approval.

The public protocol is portable. Native confinement is a separate requirement: macOS is the first implementation target; unsupported or unverified platforms refuse instead of running the module without confinement.

Callable host-registration example ​

The host registers the factory's CanvasExportTarget alongside its destinations and supplies the installed, trusted, enabled, effective and connection facts. Those facts are host-owned; a package cannot assert them. The production export service applies the same activation policy and approval card to that target as it does to folder and Gist exports. Its integration test loads the actual example, proves each activation gate, approves one payload, replays its journaled receipt, and refuses a held approval after disablement. Preparation and denial upload nothing.

The reference package includes its manifest; installed execution also requires the bundled entry built above. Its callable factory's host-supplied integration port is separate from the installed worker's bounded network port. The host-registration test proves its contract independently of installed native execution.

The contract ​

ts
interface CanvasExportTarget {
  readonly contribution: CanvasExportContribution;
  readonly describeDestination?: (
    output,
  ) => CanvasExportDestination | undefined | Promise<CanvasExportDestination | undefined>;
  readonly exportDocument: (output, confirmed?) => Promise<CanvasExportDelivery>;
}
  1. contribution — targetId, label, and formats the destination accepts (markdown, html, share-document are rendered by the host; png/pdf are drawn in the host's browser and reach only a target that declared them). The host offers the destination only when the package is installed, trusted, enabled, and effective — installation never implies trust.
  2. describeDestination(output) — called while the approval card is built. It may be synchronous or asynchronous; installed workers remain offline and subject to the description deadlines above. Return the note the card shows (who can read the result, what the service can read), and for an account-based destination the account and visibility (secret = unlisted, public = visible to anyone). Every string is shown verbatim and must be bounded and free of paths and secrets.
  3. exportDocument(output, confirmed) — called only after approval. output.body is the rendered document in output.format; output.title names it. Return { kind: "receipt", receipt: { kind: "link", href, remoteId } } (or kind: "path" for a local write) or { kind: "refused", code, message }. Refusal codes: approval-required, not-offered, not-connected, refused, unsupported-format, malformed, too-large, unauthorized, unavailable, expired.

Before the payload reaches the plugin it has passed the share filter every export goes through: no absolute file paths, no secret-shaped values, no credential-bearing URLs. A plugin that still sees one must refuse, never ship it.

Credentials in the host-registration example ​

This section describes the callable factory, not an installed worker grant. The host passes IntegrationHostPort.fetch as the factory's fetch and an authorized opaque credentialRef. The example names that reference with x-octant-credential-ref; the host port checks the destination and attaches the key (see @octant/plugin-api/integration). The raw key never enters the plugin. A reference without the host port is refused before network access. An anonymous page host can omit both.

Successful responses are decoded through the public delivery schema. Invalid JSON or link/id fields return malformed; an unreadable response returns unavailable. Neither proves that an upload created nothing remotely. The example never retries uploads automatically.

Status reporting ​

While the offer list is built the host reads activation facts for the destination: not-connected, ready, or refused (with a standing refusal reason, e.g. an insecure credential store). Report honestly — a destination that cannot act must say so rather than fail at export time.

Journal and recovery ​

Every completed export is a canvas.export@1 journal event, rebuilt by replay. If the destination was called but the journal could not take the record, the host answers unrecorded with the destination's outcome — never a silent failure.

Octant documentation · local-first by design