import type { AgentResponse } from "../types.js"; /** Event emitted for AG-UI runtime stream. */ export type AgUiRuntimeStreamEvent = Record & { type: string; }; /** Public API contract for AG-UI run finished metadata. */ export interface AgUiRunFinishedMetadata { provider?: string; model?: string; inputTokens?: number; outputTokens?: number; totalTokens?: number; cachedInputTokens?: number; cacheCreationInputTokens?: number; cacheReadInputTokens?: number; reasoningTokens?: number; billableInputTokens?: number; billableOutputTokens?: number; costUsd?: number; providerInputCostUsd?: number; providerOutputCostUsd?: number; providerCostUsd?: number; veryfrontInputChargeUsd?: number; veryfrontOutputChargeUsd?: number; veryfrontChargeUsd?: number; veryfrontBilledUsd?: number; costCredits?: number; costSource?: "gateway" | "missing" | "partial"; billingMode?: "direct" | "deferred"; finishReason?: string; usageCaptureStatus?: "complete" | "partial" | "missing"; } /** State for AG-UI encoder. */ export interface AgUiEncoderState { messageId: string | null; textOpen: boolean; activeTextContentId: string | null; textContentIndex: number; reasoningMessageId: string | null; /** * How many reasoning spans have opened in this run. Optional so a state * object built before this counter existed stays valid; absent reads as 0. */ reasoningSpanIndex?: number; activeStepName: string | null; stepCount: number; streamedToolInputIds: Set; /** * Tool calls whose `ToolCallStart` has been emitted but not yet closed with * a `ToolCallEnd`. Distinct from `streamedToolInputIds`, which tracks * whether any args were streamed, not whether the call is still open. * * Optional, and populated lazily, so a state object built against the shape * this type had before the tracker existed stays valid — the same reason * `reasoningSpanIndex` above is optional. This type is re-exported from * `veryfront/agent`, so a required field would crash existing callers on the * first `tool-input-start`. */ openToolCallIds?: Set; sawVisibleOutput: boolean; sawTerminalError: boolean; metadata: AgUiRunFinishedMetadata; /** * Clock for `elapsedMs`, and the run-relative anchor it measures from. Absent * only when a caller opts out; see `createAgUiEncoderState`. */ nowMs?: () => number; startedMs?: number; /** * Wall clock for `emittedAt`, in epoch milliseconds. Separate from `nowMs` * because the two answer different questions and fail differently: * `elapsedMs` is monotonic and safe for durations inside one run, while * `emittedAt` is comparable across events, runs and services but can move * backwards if the host clock is adjusted. */ epochMs?: () => number; } /** Options for create AG-UI encoder state. */ export interface AgUiEncoderStateOptions { /** * Clock used to stamp `elapsedMs`. Defaults to `performance.now`. Pass null * to omit the stamp, which keeps exact-payload assertions deterministic. */ nowMs?: (() => number) | null; /** * Wall clock used to stamp `emittedAt`, in epoch milliseconds. Defaults to * `Date.now`. Pass null to omit the stamp. */ epochMs?: (() => number) | null; startedMs?: number; } /** Event emitted for AG-UI encoded. */ export interface AgUiEncodedEvent { event: string; payload: Record; } /** State for create AG-UI encoder. */ export declare function createAgUiEncoderState(options?: AgUiEncoderStateOptions): AgUiEncoderState; /** Response payload for build AG-UI finalize. */ export declare function buildAgUiFinalizeResponse(metadata: AgUiRunFinishedMetadata): AgentResponse | null; /** Map runtime stream event to AG-UI events. */ export declare function mapRuntimeStreamEventToAgUiEvents(state: AgUiEncoderState, event: AgUiRuntimeStreamEvent): AgUiEncodedEvent[]; export declare function stampAgUiEventTiming(state: AgUiEncoderState, events: AgUiEncodedEvent[]): AgUiEncodedEvent[]; /** Finalize AG-UI events helper. */ export declare function finalizeAgUiEvents(state: AgUiEncoderState, response: AgentResponse | null): AgUiEncodedEvent[]; //# sourceMappingURL=encoder.d.ts.map