@adonis-agora/agent
Version:
Governed, durable-backed AI agent (chat + tool-calling + governance) for AdonisJS — part of the Agora ecosystem.
42 lines • 2.2 kB
TypeScript
import type { SinkWriter, StreamFrame, TokenStreamSink } from './spi/token-stream-sink.js';
/** What a failed stream write reports: the run, the step of the writer that failed, the error. */
export interface StreamFailure {
runId: string;
stage: 'open' | 'write' | 'end' | 'flush';
error: unknown;
}
export interface ResilientTokenStreamSinkOptions {
/**
* Told once per run, at the first failure (later ones on the same run are the same outage).
* Default: a `console.warn`.
*/
onFailure?: (failure: StreamFailure) => void;
}
/**
* Keep a run alive when its live stream breaks.
*
* The sink is the TRANSPORT of a turn's tokens to whoever is watching; the turn's outcome is the
* message the store persists. Without this, a sink that throws — Redis out of memory, a dropped
* connection, a table the Lucid sink can't write — rejects the loop's `await writer.write(…)` and
* fails the whole run: the model's answer is never written, even though only the live view was
* broken.
*
* Wrapped, the first failure of a run is reported and that run's writer goes quiet: its later
* frames are dropped and `end()` is still attempted (a subscriber may yet get the end marker), but
* nothing throws back into the loop. The run finishes, the answer is persisted, and a reload — the
* thread read, not the stream — shows it whole. Reading (`subscribe`, `has`, `close`) is untouched:
* a broken read is the SSE route's to report, and does not affect the run.
*/
export declare class ResilientTokenStreamSink implements TokenStreamSink {
private readonly inner;
private readonly report;
/** The wrapped sink's, when it has one (the SSE route reads its absence as "subscribe anyway"). */
readonly has?: (runId: string) => boolean | Promise<boolean>;
constructor(inner: TokenStreamSink, options?: ResilientTokenStreamSinkOptions);
open(runId: string): Promise<SinkWriter>;
subscribe(runId: string): AsyncIterable<StreamFrame>;
close(runId: string): void | Promise<void>;
/** A failing reporter must not be the thing that breaks the run. */
private safeReport;
}
//# sourceMappingURL=resilient-token-stream-sink.d.ts.map