events.grant
Mints the token a client uses to subscribe, for an explicit list of channels named exactly (up to 100, no wildcards). Call it from one of your own methods and do the authorization check there first: the grant is the entire subscribe-side authorization, and the platform delivers the named channels to whoever holds the token. Return the result from your method and hand the token to the client.
Naming channels in the grant's publish list also lets the holder publish on them directly from the client, the fast path for ephemeral signals. Scope it tightly, since the browser-held token can inject events on those channels until it expires. The lifetime also sets the revocation window: a shorter TTL cuts off revoked access faster, at the cost of re-minting more often. Per-user channels with publish-time fan-out stop a removed member immediately, regardless of TTL.
import { auth, events } from '@mindstudio-ai/agent'; export async function watchInbox() { auth.requireRole('member'); // your checks first return await events.grant(`user:${auth.userId}`); }