Skip to content

Host Token Reference (Runtime API)

In the Plugin Runtime, plugins consume Host capabilities by token: context.use(token) during setup, or use(token) inside commands/tools at runtime. This page is the complete index; method surfaces are defined in the linked source packages.

Messaging & Delivery

TokenYieldsKey methods
messageGatewayToken (@zhin.js/core/runtime)MessageGatewayreceive / send(request) → DeliveryReceipt / sendEndpointMessage / onMessage / registerInteractiveHandler / setUnmatchedHandler
outboundHostToken (@zhin.js/plugin-runtime)OutboundHostsend({ adapter, endpointId, conversation, content }) — cross-platform outbound, addressed by ConversationRef
runtimeEventPublisherToken (@zhin.js/plugin-runtime)RuntimeEventPublisherBroadcasts runtime events (source of inbox/Console message stream)

Persistence

TokenYieldsKey methods
databaseHostToken (@zhin.js/plugin-runtime)PluginDatabaseHost (tables isolated per owner)define(name, def) / models.get(name)select / insert / update / delete / count; select() requires explicit column names ('*' rejected)
databaseRootHostToken (@zhin.js/plugin-runtime, root only)DatabaseHostProcess-wide host for Console administration and custom composition roots

Scheduling

TokenYieldsKey methods
scheduleHostToken (@zhin.js/plugin-runtime)PluginScheduleHost (isolated per owner)Register/cancel cron jobs; combine with messageGatewayToken for scheduled pushes
scheduleRootHostToken (@zhin.js/plugin-runtime, root only)ScheduleHostProcess-wide schedule host

Agent

TokenYieldsKey methods
agentHostToken (@zhin.js/agent, agent-host-port)Agent Host portAccess ZhinAgent / AI service (available when @zhin.js/agent is installed)
agentToolsHostToken (@zhin.js/plugin-runtime)AgentToolsHostregister(tool): register agent/tools into the Agent tool catalog

Rendering & HTTP

TokenYieldsKey methods
htmlRendererToken (@zhin.js/plugin-runtime)HtmlRendererHostrender(html, opts) → png (requires @zhin.js/html-renderer; outbound html degrades to text otherwise)
httpHostToken (@zhin.js/host-http)HttpHostroute(method, path, handler, meta?) — shared by Console/MCP/A2A/adapter webhooks

Example

ts
export default definePlugin({
  name: 'reminder',
  setup({ use }) {
    const schedule = use(scheduleHostToken);
    const gateway = use(messageGatewayToken);
    schedule.register('0 9 * * *', async () => {
      await gateway.send({ conversation, requester, content: 'Good morning' });
    });
  },
});

Rules: call use() during setup; use() throws when the backing Host is not installed (e.g. agentHostToken without @zhin.js/agent). Scoped tokens (database/schedule) isolate data per plugin owner automatically; root-level process tokens are for the composition root (basic/cli) or explicit root scenarios only.