Contracts
New to the idea? Read How PocketOne fits together first. This page is the list of every contract and how to write one.
Every API a PocketOne extension offers is a contract: a versioned Go interface, and the HTTP API, hooks and MCP tools
that come with it, at /api/_c/<id>/. Extensions have no routes of their own. An extension says what it
implements, requires and works with in terms of these contracts, never another extension's name, so any
extension that implements a contract can stand in for another. PocketOne answers "who provides this contract on this
app?" at startup and prints the answer.
Every contract lives here, standard or community; extensions live in ext/<name>. Each contract is a package named
for its id and major version: deploy/v1 is pocketone.dev/ext/contracts/deploy/v1,
mail.fallback/v1 is .../mail/fallback/v1. A change to what a contract promises is a new major version (v2) next
to the old one.
The table is generated from each contract's README and every extension's Contracts(): run
go run ./.github/extensions contracts (CI fails when it's stale).
| Contract | What it promises | Provided by | Required by | Works with | Owners |
|---|---|---|---|---|---|
api-tokens.verify/v1 |
Another server checks an app's API token: who it acts as and what it may do. | api-tokens | @benallfree | ||
api-tokens/v1 |
An app's API tokens: check one, register scopes, read a request's token, limit in-process requests; the token API. | api-tokens | deploy, mcp, remotes | @benallfree | |
billing/v1 |
Sell subscriptions and one-time purchases from an app: checkout, who bought what, entitlements and item events, whatever processor takes the money. | billing (default) | @benallfree | ||
bulkmail/v1 |
Run bulk mail campaigns: count an audience; start, pause, resume, cancel, preview and test a campaign. | bulkmail | @benallfree | ||
cache.clear/v1 |
Emptying an app's cache buckets, one or all, from the dashboard, the CLI or an agent. | cache (default) | @benallfree | ||
cache/v1 |
Named buckets of bytes an app keeps for a while, with limits and eviction; memory, disk or a shared cache behind it. | cache (default) | mothership | pages | @benallfree |
cli.commands/v1 |
The pocketone command tree: every contract operation as a remote command by default; extensions replace or add commands. | desktop | @benallfree | ||
deploy/v1 |
A project's code files on an app: check, upload, commit, list, read, write, delete, tree. | deploy (default) | @benallfree | ||
gate/v1 |
What admits requests on a multisite host: peer checks, client IPs and rate limits, in order. | firewall | @benallfree | ||
http.wrap/v1 |
Middleware around everything a multisite host serves, nested in order. | servertiming | @benallfree | ||
instance.fs/v1 |
An instance's code files on disk: its folder, a cache folder, one writers' lock and a restart around a change. | deploy (default), docker, pocker | deploy | @benallfree | |
instance.lookup/v1 |
A multisite host asks what a hostname it doesn't know serves. | mothership | @benallfree | ||
instance.resolve/v1 |
On a control plane: what a hostname serves for an edge, and the records the answer was built from. | mothership (default) | mothership | @benallfree | |
instance.source/v1 |
The instance record a multisite host serves, and where the records come from. | mothership | pocker | @benallfree | |
instance.status/v1 |
A multisite host reports each instance's state (starting, running, idle, failed) as it changes. | @benallfree | |||
instance.tokens/v1 |
A multisite host checks an API token one of its instances issued, to accept it on the routes it answers. | pocker | @benallfree | ||
instance.watch/v1 |
An edge follows a control plane lazily: one stream, hostnames watched as requests name them. | mothership | @benallfree | ||
kv/v1 |
An app's key-value store: named JSON values with no collection or migration, kept in PocketBase's _params. | kv (default) | api-tokens, billing, bulkmail, creem, llm, llm-search, paddle, stripe | @benallfree | |
llm.align/v1 |
Forced alignment: audio and the exact words spoken in it in, the time of every line and word out. | llm | @benallfree | ||
llm.chat/v1 |
Stored conversations with a language model: start a chat, send to it, read its history, find and forget chats by the app's own meta. | llm-chat | @benallfree | ||
llm.embed/v1 |
Turn texts into vectors for search by meaning: texts in, one vector each out. | llm | llm-search | @benallfree | |
llm.image/v1 |
Make pictures from a prompt, and from reference pictures you give it; they come back as files. | llm | @benallfree | ||
llm.ledger/v1 |
What an app's model calls used and cost, from the ledger every llm.* call leaves, and how much of each limit is left. | llm | @benallfree | ||
llm.music/v1 |
Make music from a prompt and lyrics, as a job: start it, follow it, fetch its files (or wait for them). | llm | @benallfree | ||
llm.search/v1 |
RAG knowledge bases (buckets) with hybrid search: sources (files, folders, zips, pages, Git repositories, collections) kept current, one embedding model per app. | llm-search | llm-chat | @benallfree | |
llm.speech/v1 |
Read text aloud: text in, an audio file out, in a voice the model offers or one cloned from a clip. | llm | @benallfree | ||
llm.text/v1 |
Ask a language model: a prompt or a conversation in, text (or JSON matching a schema) out, whole or streamed. | llm | llm-chat | @benallfree | |
llm.transcribe/v1 |
Write down what's said in audio: an audio file in, text out. | llm | @benallfree | ||
llm.video/v1 |
Make video from a prompt (and a first frame), as a job: start it, follow it, fetch its files (or wait for them). | llm | @benallfree | ||
mail.fallback/v1 |
Where an app's mail goes when SMTP is off: a chain of providers that send it or pass it on. | mailrelay, mailtrap | @benallfree | ||
mail.feedback/v1 |
Mail providers' reports (bounces, complaints, unsubscribes) received at one place and raised as events any extension can act on. | bulkmail (default) | @benallfree | ||
mail.suppression/v1 |
Addresses an app must not send bulk mail to, and the unsubscribe link every bulk message carries. | bulkmail (default) | @benallfree | ||
mcp/v1 |
The app's MCP endpoint at /mcp, with every provided contract's operations as tools. | mcp (default) | wasm | @benallfree | |
oauth/v1 |
The app's OAuth 2.1 authorization server, so the CLI and MCP clients can sign in. | api-tokens | mcp | @benallfree | |
payments/v1 |
What a payment processor does for an app (checkout, portal, subscriptions, refunds, webhooks), one interface for Stripe, Paddle, Creem and the rest. | creem, paddle, stripe | billing | @benallfree | |
remote/v1 |
Remote control of an app: whoami, status, restart, logs. The base every client starts from. | docker, remotes (default) | deploy | @benallfree | |
restore/v1 |
Put an app's data back as it was at a moment: from continuous history, or the latest backup before it. | backups (default), pitr | @benallfree | ||
runtime/v1 |
What runs a multisite host's instances (as isolates, in containers): one per host. | docker, pocker | @benallfree | ||
settings/v1 |
The settings an app's admins change for its extensions, one API for all of them. | settings (default) | billing, bulkmail, creem, llm, mailrelay, paddle, pitr, stripe, vacuum | @benallfree | |
templates/v1 |
An extension's own pages as Go templates a project can eject and edit. | templates | api-tokens | @benallfree | |
tls/v1 |
The TLS of a multisite host's listener: automatic certificates instead of certificate files. | autotls | @benallfree | ||
vacuum/v1 |
Compacting an app's databases so freed space goes back to the disk, and when it last happened. | vacuum | @benallfree |
internal/example/v1 is a test-only wire contract that exercises the generated code.
Three kinds
- Service: a Go interface, looked up in the same process (
fallbackv1.Contract.Of(app)). - Wire: a service with an HTTP API under
/api/_c/<id>/, generated from its interface: each method is an operation with its own HTTP method, path and token scope (//op: POST restart scope=remote); inputs and results are JSON, uploads (extkit.RawIn), downloads (extkit.RawOut) or streams (extkit.Stream, sent as server-sent events: a GET or a POST, pushed as they happen withRunor polled withPoll). It gets action hooks (remotev1.OnRestart,onRemoteRestartinpb_hooks), an MCP tool per JSON operation and a client. Every caller (HTTP, MCP, Go) passes the same scope check and hooks. - Routed: a contract whose provider is an
http.Handlerserving everything under/api/_c/<id>/as it is, for an API a protocol shapes (OAuth) or an existing API moved under a contract (deploy/v1).
A multisite host can provide a wire or routed contract for its instances, so it works for instances that run stock PocketBase.
A contract can bring its own dashboard screen (Contract.UI(name, fsys)): it shows on every app that provides the
contract, whichever extension does, and calls only the contract's API. restore/v1's "Restore to a moment" works this
way.
An extension that calls a contract for its own work (bulk mail checking whoever keeps the suppression list) passes
extkit.Internal as the auth, and can ask who provides it with Contract.Provider(app).
Add a contract
A contract is a folder ext/contracts/<id path>/vN/ (mail.fallback/v1 → mail/fallback/v1/) with:
-
the Go package: the interface, its
//contract:directives andzz_contract.go; -
a
README.md, its page on pocketone.dev, with front matter and four sections in this order:--- owners: ["@your-github-handle"] summary: "One line: what the contract promises." --- # mail.fallback/v1 ## Use how to call it: HTTP, Go, pb_hooks, MCP, CLI ## Provide how to implement it ## Extensions (generated: who provides, requires and works with it) ## License MIT
Whoever first creates a contract owns it; an extension author who adds one owns both the contract and the extension
that provides it. Ids are unique across PocketOne. Pick a name for what the contract does (restore/v1), not for the
extension that first provides it.
Write the interface
A contract is an interface with //contract: directives; contractgen writes the rest
(zz_contract.go) with go generate ./.... A test fails when a generated file is stale.
//go:generate go run pocketone.dev/ext/contracts/cmd/contractgen
// Deployer sends a project's code to an app.
//
//contract:id deploy/v1
//contract:kind wire
//contract:scope deploy
//contract:host
//contract:js hooks
type Deployer interface {
// Upload writes changed files to the app.
Upload(ctx context.Context, a extkit.Auth, in UploadInput) (UploadResult, error)
}
Methods take ctx, then (wire) extkit.Auth, then at most one input; they return error or one value and error.
A contract pb_hooks can touch (//contract:js hooks or open) also gets zz_contract.d.ts, its TypeScript for
types.d.ts: each action hook typed with its operation's input (onExampleUpload(handler: (e: contracts.CallEvent<contracts.example.v1.UploadInput>) => void)), and for open the interface e.provide checks
(contracts.Providers["mail.fallback/v1"]). Hooks see the Go value, so fields carry Go names with the first letter
lowered (maxTokens); a JS provider gets JSON, so fields carry their json names, omitempty ones optional.
The doc comment of a wire method is its MCP tool's description. Contracts are reviewed like PocketOne's core: a
contract is a promise every implementation keeps.
Use one
// provide (in Register)
deployv1.Contract.ProvideDefault(app, myDeployer{})
// consume (after registration: in hooks, at serve time)
d := deployv1.Contract.Must(app)
// declare it, so PocketOne can order and switch extensions
func (e *Extension) Contracts() extkit.Contracts {
return extkit.Contracts{Implements: extkit.IDs("deploy/v1"), Defaults: extkit.IDs("deploy/v1")}
}
Choose between providers in pocketone.yaml:
providers:
mail.fallback/v1: mailrelay
License
MIT
Questions and comments
Comments are a GitHub Discussions thread; sign in with GitHub to post.