ReferenceAsk
Remy Reference/interface/events.connect
?

events.connect

Opens a managed subscription to the app's realtime events, handling reconnection and grant renewal for you.
events.connect({ getToken, onEvent, onConnect?, onError? }) EventsSubscription

Opens a subscription to the app's realtime stream and returns a handle you close when the view goes away. You pass a getToken that mints a grant through one of your backend methods and an onEvent for the payloads; the SDK manages the connection, reconnects with backoff on a network drop, and re-mints the grant on expiry. Put your state refetch in onConnect, which fires on every connect, because events are at-most-once and nothing is replayed on reconnect.

Parameters
getToken
() => Promise<string> | string
RequiredReturns a subscribe token, typically by calling the backend method that mints the grant. Called on first connect and again after every grant expiry; throwing is terminal.
onEvent
(event: AppEvent) => void
RequiredReceives each published event on a channel the grant names.
onConnect
() => void
Fires on every connect and reconnect. Refetch current state here, since events are at-most-once.
onError
(error: Error) => void
Fires only on a terminal failure (a getToken refusal). Reconnects are silent.
Subscribe, then close on unmount
import { createClient, events } from '@mindstudio-ai/interface';
const api = createClient<{ watchInbox(): Promise<{ token: string }> }>();

const sub = events.connect({
  getToken: () => api.watchInbox().then((r) => r.token),
  onEvent: (e) => { if ((e.data as any)?.type === 'ticket') refreshTicket((e.data as any).id); },
  onConnect: () => refetchInbox(), // reconcile on every (re)connect
});

// on unmount:
sub.close();