import { type AgentMessage } from "@oh-my-pi/pi-agent-core";
export interface YieldDispatcher
{
/** Drop entries already delivered through another path. Called per-entry at flush time. */
isStale?(entry: P): boolean;
/** Produce one batched AgentMessage from non-stale entries. Return null to skip. */
build(survivors: P[]): AgentMessage | null;
/** If true, entries for this kind are drained only by {@link drainLazy} and never trigger the idle flush. */
skipIdleFlush?: boolean;
}
export interface YieldQueueOptions {
isStreaming: () => boolean;
injectStreaming?(msg: AgentMessage): void;
injectIdle(messages: AgentMessage[]): Promise;
scheduleIdleFlush(run: () => Promise): void;
}
type YieldFlushMode = "streaming" | "idle";
export declare class YieldQueue {
#private;
constructor(options: YieldQueueOptions);
register(kind: string, dispatcher: YieldDispatcher
): () => void;
enqueue
(kind: string, entry: P): void;
enqueueWithReceipt
(kind: string, entry: P): Promise;
has(kind?: string): boolean;
/**
* Non-consuming check for an entry of `kind` that the drain would deliver.
* Unlike {@link has}, it skips entries the dispatcher reports stale, since
* the drain drops those without a message.
*/
hasDeliverable(kind: string): boolean;
/** Arrange an idle flush for entries queued near the end of a streaming run. */
requestIdleFlush(): void;
flush(mode: YieldFlushMode): Promise;
/**
* Snapshot and remove all queued entries, returning one lazy thunk per kind.
* Each thunk applies the dispatcher's staleness filter and builds the batched
* message only when called — so the consumer (the agent loop) decides, at the
* moment it injects, whether the message is still worth delivering (a thunk may
* return null to skip). Background-job completions and late diagnostics reach
* the model between requests without the agent having to stop.
*/
drainLazy(): Array<() => AgentMessage | null>;
/** Drop queued entries. With `kind`, drop only that kind's entries (leaving
* any pending idle-flush for other kinds intact); otherwise drop everything. */
clear(kind?: string): void;
/** Clear a scheduled-flush latch when its host task is cancelled before running. */
cancelIdleFlushScheduling(): void;
}
export {};