import type { AnySessionChannel, ControlEvent, SessionChannelIn, SessionChannelName, SessionChannelOut, SSEStreamPart } from "@trigger.dev/core/v3"; import type { UseApiClientOptions } from "./useApiClient.js"; type ChannelRecord = S extends "out" ? SessionChannelOut : SessionChannelIn; export type UseSessionStreamChannelInstance = { /** The records received so far on the channel, in arrival order. */ records: Array; /** The cursor of the last record seen; pass back as `lastEventId` to resume. */ lastEventId: string | undefined; /** The last control record seen on the channel. */ lastControl: ControlEvent | undefined; error: Error | undefined; /** Abort the current request immediately, keep the records received so far. */ stop: () => void; }; export type UseSessionStreamChannelOptions = UseApiClientOptions & { /** * The id or external id of the session that owns the channel. May be * undefined while it resolves; the subscription starts once it is set. */ sessionId?: string; id?: string; enabled?: boolean; /** * Which side of the channel to read. * * @default "out" */ io?: S; /** * The number of milliseconds to throttle the record updates. * * @default 16 */ throttleInMs?: number; /** * The number of seconds to wait for new data before the stream closes. * * @default 60 seconds */ timeoutInSeconds?: number; /** The cursor to resume from. If not provided, reads per `from`. */ lastEventId?: string | number; /** * Where a fresh subscription (no `lastEventId`) starts reading. * * - `"beginning"` (default): replay the full channel history, then live-tail. * - `"latest"`: start at the current tail, for a last-value / live view. * * Ignored when `lastEventId` is set. */ from?: "beginning" | "latest"; /** * Cap the number of records kept in `records`. Use `maxRecords: 1` with * `from: "latest"` for a bounded last-value view. */ maxRecords?: number; /** Invoked once per throttled flush with the batch of records (control records included). */ onRecords?: (records: Array>>) => void; /** Called when a control record is received on the channel. */ onControl?: (event: ControlEvent) => void; }; /** * Read one side of a named Session side channel, with record types inferred * from a `defineSessionChannel` declaration passed as the type argument. * * The channel name is typesafe (`SessionChannelName`) and `records` * is typed from the channel's `.out` / `.in` record type. Called without the * type argument, the channel name is any string and `records` is `unknown`. * * Requires a Public Access Token scoped to the session (or to the channel). * * @example * ```tsx * import type { screenshotsChannel } from "./shared/channels"; * * const { records } = useSessionStreamChannel("screenshots", { * sessionId, * accessToken, * io: "out", * from: "latest", * maxRecords: 1, * }); * ``` */ export declare function useSessionStreamChannel(channel: SessionChannelName, options: UseSessionStreamChannelOptions): UseSessionStreamChannelInstance>; export {};