@adonis-agora/agent
Version:
Governed, durable-backed AI agent (chat + tool-calling + governance) for AdonisJS — part of the Agora ecosystem.
49 lines • 2.78 kB
TypeScript
import { type AgUiEncoderOptions } from './encoder.js';
import type { AgUiEvent, AgUiSourceFrame } from './types.js';
export interface AgUiStreamOptions extends AgUiEncoderOptions {
/**
* How long the library stream may stay silent, while the run waits on a person AND has other work
* announced, before the AG-UI run is reported interrupted. Default 750 ms.
*
* Only that mixed case needs a clock. A run whose every open tool call is waiting on someone is
* reported at once; a run waiting on no one is never cut short.
*/
quietMs?: number;
/** Events to write right after `RUN_STARTED` (warnings about input that was dropped). */
preamble?: AgUiEvent[];
/**
* Kept at the run's own sequence number (the native stream's SSE `id:`) of the library frame
* whose events are being yielded — `0` before the first. Write it as each event's SSE `id:`
* ({@link agUiSse}) and a consumer can re-attach to the native stream with `?after=` exactly where
* this AG-UI run left off. Read from {@link withFrameSeq}; a frame not tagged leaves it as it is.
*/
cursor?: AgUiCursor;
}
/** See {@link AgUiStreamOptions.cursor}. */
export interface AgUiCursor {
seq: number;
}
/**
* Tag a source frame with the run's own sequence number through it — the SSE `id:` of the last
* event the native stream writes for it — for {@link AgUiStreamOptions.cursor}.
*/
export declare function withFrameSeq<T extends AgUiSourceFrame>(frame: T, seq: number): T;
/** The run's own sequence number of a frame tagged by {@link withFrameSeq}, if any. */
export declare function frameSeq(frame: AgUiSourceFrame): number | undefined;
/**
* One AG-UI run over a library run's stream.
*
* AG-UI has no mid-run channel from the consumer: a run that needs an approval or an answer does not
* wait with the connection open — it ENDS, saying what it waits for, and a later run carries the
* answers. The library run underneath does wait (parked, durably when the runner is durable). So this
* stops reading when the run is waiting on someone and nothing else is moving, closes the AG-UI run
* with the interrupt outcome, and leaves the library run parked for the resume to pick up.
*/
export declare function agUiEvents(frames: AsyncIterable<AgUiSourceFrame>, options: AgUiStreamOptions): AsyncGenerator<AgUiEvent>;
/**
* One AG-UI event as an SSE frame: a single `data:` line, LF-terminated, as the binding pins. With a
* positive `id`, an SSE `id:` line first — the run's sequence number ({@link AgUiStreamOptions.cursor}),
* which AG-UI clients ignore and this package's React client re-attaches with.
*/
export declare function agUiSse(event: AgUiEvent, id?: number): string;
//# sourceMappingURL=stream.d.ts.map