import type { Frame, MessageFamily } from "../protocol/index.ts"; import type { AgenticHub } from "../channel/index.ts"; import { IncarnationFence } from "./incarnation.ts"; import { ReplayRing } from "./ring.ts"; /** The relay family key, from the S0 canonical family set (the one source of truth). */ export declare const RELAY_FAMILY: MessageFamily; /** * The minimal connection surface the relay module needs. It is a structural * subset of the hub's `HubConnection`, so the module is unit-testable with a * fake connection and needs no compile dependency on the hub's concrete type. */ export interface RelayConnection { readonly id: string; /** The shared registry — its `has(id)` is the liveness source of truth. */ readonly registry: { has(id: string): boolean; }; /** Send one already-built frame back on this connection. */ send(frame: Frame): void; } export interface RelayHubOptions { /** Retained chunks per stream (resume window). Default 1024. */ readonly ringCapacity?: number; /** Max buffered bulk frames per consumer before oldest is shed. Default 1024. */ readonly bulkCapacity?: number; /** Bulk credit a consumer starts with before it grants its own. Default 0. */ readonly defaultCredit?: number; /** Notified when a producer frame is fenced as a stale incarnation. */ readonly onFenced?: (stream: string, incarnation: number, current: number) => void; /** Notified of a malformed relay message or a send failure. */ readonly onError?: (err: unknown, connectionId?: string) => void; } /** * The hub-side relay state machine: per-stream replay rings + incarnation fence, * and per-consumer QoS schedulers. Construct via {@link registerRelayFamily}, or * directly for unit testing and then drive with {@link RelayHub.handle}. */ export declare class RelayHub { #private; constructor(options?: RelayHubOptions); /** Number of streams with a replay ring. */ get streamCount(): number; /** Number of tracked consumer subscribers. */ get subscriberCount(): number; /** The replay ring for a stream, if one exists (for inspection/tests). */ ring(stream: string): ReplayRing | undefined; /** The incarnation fence (for inspection/tests). */ get fence(): IncarnationFence; /** Whether a connection currently has a subscriber record. */ hasSubscriber(id: string): boolean; /** * Handle one inbound `relay` frame from `conn`. This is the function attached * to the hub's family seam; it is safe to call directly in tests. */ handle(frame: Frame, conn: RelayConnection): void; } /** Raised (to `onError`) when an inbound relay payload does not match the sub-protocol. */ export declare class RelayMessageError extends Error { readonly payload: unknown; constructor(payload: unknown); } /** * Attach the `relay` family to a hub via the S1 registration seam and return the * {@link RelayHub} driving it. This is the canonical entry point; it does NOT * edit any shared dispatch switch — the hub derives routing from this * registration, and a second registration of `relay` is rejected by the seam. */ export declare function registerRelayFamily(hub: AgenticHub, options?: RelayHubOptions): RelayHub;