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
outboundMessageToken (@zhin.js/core/runtime)OutboundMessageServicereceive / send(request) → DeliveryReceipt / sendEndpointMessage / onMessage / registerInteractiveHandler
outboundHostToken (zhin.js)OutboundHostsend({ adapter, endpointId, conversation, content }) — cross-platform outbound, addressed by ConversationRef
runtimeEventPublisherToken (zhin.js)RuntimeEventPublisherBroadcasts runtime events (source of inbox/Console message stream)

Persistence

TokenYieldsKey methods
databaseHostToken (zhin.js)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, root only)DatabaseHostProcess-wide host for Console administration and custom composition roots

Scheduling

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

Agent

TokenYieldsKey methods
agentHostToken (@zhin.js/agent/runtime)Agent Host portEnumerate Agent bindings, submit canonical TurnRequests, and read Console/diagnostic projections; concrete ZhinAgent / AIService instances are not exposed
turnIntentResolverToken (@zhin.js/agent/runtime)Trusted intent resolver provided by the endpoint ownerResolve messages by adapter/scene to supersede, new, steer, follow_up, or observe; only this resolver may issue authorizedBy: 'product_policy' for cross-participant control

Rendering & HTTP

TokenYieldsKey methods
htmlRendererToken (zhin.js)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(outboundMessageToken);
    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.

AI fallback is not a mutable OutboundMessageService plugin API. During generation setup, the composition root provides the internal ingressRouteToken in root resources; ImRuntime.receive resolves it only from the snapshot held by that message. Regular plugins must not register or replace this token.