@adonis-agora/agent
Version:
Governed, durable-backed AI agent (chat + tool-calling + governance) for AdonisJS — part of the Agora ecosystem.
51 lines • 2.87 kB
TypeScript
import type { StreamFrame } from './spi/token-stream-sink.js';
/**
* What consecutive frames of a run merge under, or `undefined` for a frame that is always written on
* its own. Only the streamed deltas qualify — answer text, reasoning text, and the argument text of
* ONE tool call — and only in their plain shape, so a merge can never drop a field: every reader
* appends those deltas, which makes one frame holding their concatenation read the same as the run.
*/
export declare function coalesceKey(frame: StreamFrame): string | undefined;
/**
* The write half a shared sink puts in front of its transport: consecutive deltas of one kind
* (see {@link coalesceKey}) written within `flushMs` become ONE frame, and every frame of a run is
* appended in call order, one append at a time.
*
* A model streams token by token, and a round trip per token is what a transport shared across
* replicas can least afford. A gathered frame is written when its window passes (counted from its
* FIRST delta, so a steady stream still lands every `flushMs`), when a frame that does not merge
* with it arrives, and on `flush()`/`end()` — so order is always kept. `flushMs: 0` appends every
* frame as it comes.
*
* Writers opened for the same run in one process share what they are gathering, so a delegated
* run's text (forwarded through a `childSinkWriter`) and its parent's next frame keep the order they
* were written in.
*/
export declare class CoalescedWrites {
private readonly flushMs;
/** Append one frame to the run's stream, or (`null`) its end marker. */
private readonly append;
private readonly runs;
constructor(flushMs: number,
/** Append one frame to the run's stream, or (`null`) its end marker. */
append: (runId: string, frame: StreamFrame | null) => Promise<void>);
private state;
/** Forget a run's write state once nothing is gathered, queued or left to report. */
private release;
/** Queue `frame` behind every write already queued for the run, so frames land in call order. */
private enqueue;
/** Queue the gathered frame (if any). */
private flushHeld;
/** A write nobody awaits (a window that passed, a gathered frame a different one displaced). */
private flushUnawaited;
/** Raise, once, a gathered write that failed with nobody awaiting it. */
private raiseFailure;
write(runId: string, frame: StreamFrame): Promise<void>;
/** Write out the gathered frame and wait for every queued write, without ending the stream. */
flush(runId: string): Promise<void>;
/** Write out the gathered frame, then the end marker. */
end(runId: string): Promise<void>;
/** Drop what is gathered for the run and wait out the writes already queued. */
discard(runId: string): Promise<void>;
}
//# sourceMappingURL=coalesced-writes.d.ts.map