import type { AssistantMessage, AssistantMessageEvent } from "../types.js"; /** Anything a stream watchdog can consult for in-flight consumer-side local work. */ export interface LocalWorkSource { readonly hasPendingLocalWork: boolean; /** * Epoch ms at which tracked local work last drained to zero, or 0 if none * has completed. The provider cannot answer until it receives the local * result, so idle watchdogs measure provider silence from this instant. */ readonly localWorkSettledAt: number; } export declare class EventStream implements AsyncIterable { #private; /** * Events pushed while no consumer was waiting. The iterator dequeues by * advancing {@link #queueHead} instead of `shift()` — O(remaining) per event, * quadratic for a consumer draining a backlog — so while it drains, the * slots before the head are consumed (cleared) placeholders. Do not mutate * the array while the stream is being iterated. */ queue: T[]; waiting: Array<{ resolve: (value: IteratorResult) => void; reject: (err: unknown) => void; }>; done: boolean; /** True once finalResultPromise has been resolved or rejected. */ resultSettled: boolean; finalResultPromise: Promise; resolveFinalResult: (result: R) => void; rejectFinalResult: (err: unknown) => void; isComplete: (event: T) => boolean; extractResult: (event: T) => R; constructor(isComplete: (event: T) => boolean, extractResult: (event: T) => R); push(event: T): void; deliver(event: T): void; end(result?: R): void; endWaiting(): void; fail(err: unknown): void; [Symbol.asyncIterator](): AsyncIterator; result(): Promise; /** True while local work tracked via {@link trackLocalWork} — on this stream or a forwarded delegate — is pending. */ get hasPendingLocalWork(): boolean; /** Latest {@link LocalWorkSource.localWorkSettledAt} across this stream and a forwarded delegate. */ get localWorkSettledAt(): number; /** * Count `source`'s pending local work as this stream's own. Used when this * stream forwards another's events (Cursor discovered-id retry) so the * watchdog does not abort a live tool run happening on the inner stream. * Pass `undefined` to detach once forwarding ends. */ forwardLocalWorkFrom(source: LocalWorkSource | undefined): void; /** * Track a local-work promise so idle watchdogs on this stream do not treat * the event silence while it is pending as a provider stall. */ trackLocalWork(work: Promise): Promise; } export declare class AssistantMessageEventStream extends EventStream { constructor(); push(event: AssistantMessageEvent): void; end(result?: AssistantMessage): void; } /** Create an assistant-message event stream for legacy extension providers. */ export declare function createAssistantMessageEventStream(): AssistantMessageEventStream;