import type { AuthorizationRequiredStreamEvent, TurnFailureStreamEvent, UnstampedMessageStreamEvent } from "#protocol/message.js"; import type { InputRequest } from "#shared/input.js"; /** A connection authorization challenge that remains unresolved at a turn boundary. */ interface PendingAuthorization { readonly authorization?: AuthorizationRequiredStreamEvent["data"]["authorization"]; readonly description: string; readonly name: string; readonly attemptId?: string; readonly webhookUrl?: string; } /** Canonical projection of the lifecycle state represented by one turn's events. */ interface TurnEventSummary { readonly boundary: UnstampedMessageStreamEvent | undefined; readonly failure: TurnFailureStreamEvent | undefined; readonly inputRequests: readonly InputRequest[]; readonly message: string | undefined; readonly pendingAuthorizations: readonly PendingAuthorization[]; readonly status: "completed" | "failed" | "waiting"; } /** Reduces one turn's protocol events into their client-facing lifecycle state. */ export declare function summarizeTurnEvents(events: readonly UnstampedMessageStreamEvent[]): TurnEventSummary; /** Collects one segment of an event stream through its current-turn boundary. */ export declare function collectTurnEvents(stream: AsyncIterable): Promise; /** * Returns true when a read of a session's events ends at `event`: at a current-turn boundary, or * at a `turn.waiting` on `"input"` (or while a request read in the segment is unanswered). The * turn stays open there until a person acts; a `turn.waiting` on `"tasks"` is informational and * reading goes on to the turn's real end. * A reader that follows sign-in callbacks reads past a sign-in's `turn.waiting` or * `session.waiting` while its callback is outstanding, because the callback resumes the same turn. */ export declare function endsTurnSegment(event: UnstampedMessageStreamEvent, open: { readonly callbacks: boolean; readonly requests: boolean; }): boolean; /** The requests and sign-ins one segment of a session's events leaves open. */ export declare class TurnSegment { #private; constructor(options?: { readonly followCallbacks?: boolean; }); get inputRequests(): readonly InputRequest[]; get pendingAuthorizations(): readonly PendingAuthorization[]; /** Records `event` and returns true when it ends the segment. */ observe(event: UnstampedMessageStreamEvent): boolean; } export declare function authorizationKey(data: { readonly name: string; readonly attemptId?: string; }): string; export {};