@runloop/agent-axon-client
    Preparing search index...

    Function createCustomEventGuard

    • Creates a type guard that matches unknown timeline events by event_type and narrows the data field to T.

      Unknown events are eagerly parsed by the classifier, so the data field already contains the parsed payload (or null when unparseable). The returned guard checks both kind === "unknown" and the event_type string, giving you a fully typed <T> without manual parsing.

      Type Parameters

      • T

        The expected shape of the parsed event payload.

      Parameters

      • eventType: string

        The axonEvent.event_type string to match.

      Returns (event: BaseTimelineEvent) => event is CustomTimelineEvent<T>

      A type guard function.

      interface AgentStartedPayload { agentType: string; model?: string; }

      const isAgentStarted = createCustomEventGuard<AgentStartedPayload>("agent_started");

      conn.onTimelineEvent((event) => {
      if (isAgentStarted(event)) {
      console.log(event.data.agentType); // fully typed
      }
      });