import type { ChatMessageMetadata, ChatUiMessageChunk } from "../../chat/protocol.js"; import { type AgentRunEventTimingOptions } from "../../runtime/model-call-context.js"; import { type ConversationRunEvent, ConversationRunEventEncoder } from "./run-events.js"; import { type ConversationRunMirror, type ConversationRunMirrorHighBacklogState, type ConversationRunMirrorRetryScheduledState, type ConversationRunMirrorSnapshot, type ConversationRunMirrorStoppedState } from "./run-mirror.js"; import { type ConversationRunEventQueueController } from "./durable.js"; /** Public API contract for conversation run chunk mirror. */ export interface ConversationRunChunkMirror { readonly timing?: AgentRunEventTimingOptions; handleChunk(chunk: ChatUiMessageChunk): Promise; appendEvents(events: ConversationRunEvent[]): Promise; flush(options?: { abortSignal?: AbortSignal; throwOnTimeoutRetry?: boolean; }): Promise; getSnapshot(): ReturnType; dispose(): void; } /** Public API contract for conversation run chunk mirror prepared chunk. */ export interface ConversationRunChunkMirrorPreparedChunk { chunk: ChatUiMessageChunk; events: ConversationRunEvent[]; } /** Public API contract for conversation run chunk mirror prepared events. */ export interface ConversationRunChunkMirrorPreparedEvents { events: ConversationRunEvent[]; } /** Input payload for conversation run chunk mirror prepare chunk events. */ export interface ConversationRunChunkMirrorPrepareChunkEventsInput { chunk: ChatUiMessageChunk; defaultPrepare: () => ConversationRunEvent[]; } /** Input payload for conversation run chunk mirror prepare external events. */ export interface ConversationRunChunkMirrorPrepareExternalEventsInput { events: ConversationRunEvent[]; defaultPrepare: () => ConversationRunEvent[]; } interface ConversationRunChunkMirrorSharedOptions { immediateFlushEventCount?: number; encoder?: ConversationRunEventEncoder; flushDelayMs?: number; getRetryDelayMs?: (consecutiveFailures: number) => number; highBacklogEventCount?: number; onHighBacklog?: (state: ConversationRunMirrorHighBacklogState) => Promise | void; onRetryScheduled?: (state: ConversationRunMirrorRetryScheduledState) => Promise | void; onStopped?: (state: ConversationRunMirrorStoppedState) => Promise | void; prepareChunkEvents?: (input: ConversationRunChunkMirrorPrepareChunkEventsInput) => Promise | ConversationRunEvent[]; prepareExternalEvents?: (input: ConversationRunChunkMirrorPrepareExternalEventsInput) => Promise | ConversationRunEvent[]; onChunkPrepared?: (input: ConversationRunChunkMirrorPreparedChunk) => Promise | void; onExternalEventsPrepared?: (input: ConversationRunChunkMirrorPreparedEvents) => Promise | void; } /** Options accepted by conversation run chunk mirror queue. */ export interface ConversationRunChunkMirrorQueueOptions extends ConversationRunChunkMirrorSharedOptions { queueController: ConversationRunEventQueueController; } /** Options accepted by conversation run chunk mirror API. */ export interface ConversationRunChunkMirrorApiOptions extends ConversationRunChunkMirrorSharedOptions { authToken: string; apiUrl: string; conversationId: string; runId: string; latestEventId: number; latestExternalEventSequence?: number; maxEventsPerBatch?: number; maxCursorResyncsPerFlush?: number; /** Explicit host-owned transport for trusted runtime composition and tests. */ fetch?: typeof globalThis.fetch; } /** Options accepted by conversation run chunk mirror. */ export type ConversationRunChunkMirrorOptions = ConversationRunChunkMirrorQueueOptions | ConversationRunChunkMirrorApiOptions; /** Public API contract for hosted conversation run chunk mirror trace attributes. */ export type HostedConversationRunChunkMirrorTraceAttributes = Record; /** Public API contract for hosted conversation run chunk mirror instrumentation. */ export interface HostedConversationRunChunkMirrorInstrumentation { trace?: (operationName: string, operation: () => Promise) => Promise; setTraceAttributes?: (attributes: HostedConversationRunChunkMirrorTraceAttributes) => void; debug?: (message: string, metadata: Record) => void; warn?: (message: string, metadata: Record) => void; error?: (message: string, metadata: Record) => void; } /** Options accepted by hosted conversation run chunk mirror. */ export interface HostedConversationRunChunkMirrorOptions { authToken: string; apiUrl: string; conversationId: string; runId: string; latestEventId: number; latestExternalEventSequence?: number; batchSize?: number; highBacklogEventCount?: number; instrumentation?: HostedConversationRunChunkMirrorInstrumentation; /** Explicit host-owned transport for trusted runtime composition and tests. */ fetch?: typeof globalThis.fetch; } /** Create conversation run chunk mirror. */ export declare function createConversationRunChunkMirror(input: ConversationRunChunkMirrorOptions): ConversationRunChunkMirror; /** Create hosted conversation run chunk mirror. */ export declare function createHostedConversationRunChunkMirror(input: HostedConversationRunChunkMirrorOptions): ConversationRunChunkMirror; export {}; //# sourceMappingURL=run-chunk-mirror.d.ts.map