import type { ChatUiMessage, ChatUiMessageChunk, MessageMetadata } from "../../chat/types.js"; import type { HostedConversationRootRunContext } from "../conversation/root-run-lifecycle.js"; import type { ConversationRunChunkMirror } from "../conversation/run-chunk-mirror.js"; import { type CreateHostedRootRunLifecycleRuntimeAdapterInput, type HostedAgentRunSpanController, type HostedAgentRunTracer } from "./agent-run-lifecycle.js"; import type { HostedChatRuntimeAgent, HostedChatRuntimeStreamInput, HostedChatRuntimeStreamResult } from "./chat-runtime-contract.js"; import type { HostedLifecycleTerminalState } from "./lifecycle.js"; import { type ConversationHostedTerminalStateInput } from "../conversation/hosted-terminal.js"; import { type MirroredToolChunkState } from "../streaming/mirrored-tool-chunk-state.js"; import { type FinalizeHostedResponseOptions, type HostedDetachedFinalizationState, type HostedResponseFinalizationState } from "./stream-finalization.js"; import { createChatStreamWatchdog } from "../../chat/stream-watchdog.js"; import type { HostedChatExecutionLifecycleAdapter } from "./chat-execution-lifecycle-types.js"; import type { AgentRunEventSink } from "../../runtime/model-call-context.js"; export type { HostedChatExecutionLifecycleAdapter } from "./chat-execution-lifecycle-types.js"; /** Public API contract for hosted chat execution runtime. */ export interface HostedChatExecutionRuntime { agentUIStream: AsyncIterable>; fail: (error: unknown) => Promise; waitForFinish: () => Promise; } /** Public API contract for hosted chat execution runtime logger. */ export interface HostedChatExecutionRuntimeLogger { error: (message: string, metadata?: Record) => void; warn: (message: string, metadata?: Record) => void; } /** Context for hosted chat execution run. */ export interface HostedChatExecutionRunContext { withContext: (fn: () => T) => T; setMessageId?: (messageId: string) => void; } /** Public API contract for hosted chat execution root stream watchdog. */ export type HostedChatExecutionRootStreamWatchdog = ReturnType; /** Public API contract for hosted chat execution runtime bootstrap. */ export interface HostedChatExecutionRuntimeBootstrap { cleanup: () => Promise; lifecycleAdapter: HostedChatExecutionLifecycleAdapter; rootStreamWatchdog: HostedChatExecutionRootStreamWatchdog; streamResult: HostedChatRuntimeStreamResult; streamingMessageId: string | null; capturedMessageId: string | null; capturedConversationId?: string; mirroredToolChunkState: MirroredToolChunkState; runEventSink?: AgentRunEventSink; } /** Input payload for create hosted chat execution runtime bootstrap. */ export interface CreateHostedChatExecutionRuntimeBootstrapInput { agent: HostedChatRuntimeAgent; cleanup: () => Promise; lifecycleAdapter: HostedChatExecutionLifecycleAdapter; finalMessages: HostedChatRuntimeStreamInput["messages"]; conversationId?: string; abortSignal: AbortSignal; traceStream?: (operation: () => Promise) => Promise; createRootStreamWatchdog?: () => HostedChatExecutionRootStreamWatchdog; streamBootstrapKeepaliveIntervalMs?: number; streamBootstrapTimeoutMs?: number; durableRunEventMirror?: ConversationRunChunkMirror; } /** Input payload for create hosted chat execution runtime. */ export interface CreateHostedChatExecutionRuntimeInput { agentId: string; agentName?: string; agentAvatarUrl?: string; modelId: string; originalMessages: ChatUiMessage[]; responseMessageId?: string; runContext: HostedChatExecutionRunContext; abortSignal: AbortSignal; bootstrap: HostedChatExecutionRuntimeBootstrap; logger?: HostedChatExecutionRuntimeLogger; incompleteToolCallsPartErrorText?: string; } /** Input payload for create bootstrapped hosted chat execution runtime. */ export interface CreateBootstrappedHostedChatExecutionRuntimeInput { authToken: string; apiUrl: string; agent: HostedChatRuntimeAgent; agentId: string; agentName?: string; agentAvatarUrl?: string; modelId: string; cleanup: () => Promise; messages: ChatUiMessage[]; finalMessages: HostedChatRuntimeStreamInput["messages"]; conversationId?: string; projectId: string | null; userId: string; rootRunContext: HostedConversationRootRunContext; abortSignal: AbortSignal; responseMessageId?: string; upstreamParentConversationId?: string; upstreamParentRunId?: string; spawnedFromToolCallId?: string; traceAttributes?: Parameters[0]; tracer: HostedAgentRunTracer; resolveProvider: (modelId: string) => string; traceStream?: CreateHostedChatExecutionRuntimeBootstrapInput["traceStream"]; logger?: HostedChatExecutionRuntimeLogger; spanName?: string; terminalErrorCode?: string; incompleteToolCallsPartErrorText?: string; createRootStreamWatchdog?: CreateHostedChatExecutionRuntimeBootstrapInput["createRootStreamWatchdog"]; streamBootstrapKeepaliveIntervalMs?: CreateHostedChatExecutionRuntimeBootstrapInput["streamBootstrapKeepaliveIntervalMs"]; streamBootstrapTimeoutMs?: CreateHostedChatExecutionRuntimeBootstrapInput["streamBootstrapTimeoutMs"]; createTerminalAdapter?: CreateHostedRootRunLifecycleRuntimeAdapterInput["createTerminalAdapter"]; } /** Public API contract for bootstrapped hosted chat execution runtime. */ export interface BootstrappedHostedChatExecutionRuntime { agentRunSpan: HostedAgentRunSpanController; execution: HostedChatExecutionRuntime; } type SharedFinalizationHooks = Pick>, "resolveEmptyTerminalError" | "appendFallbackChunk" | "flushMirror" | "dispatchTerminalState" | "resolveTerminalState" | "cleanup" | "streamError">; /** State for to hosted chat execution final. */ export declare function toHostedChatExecutionFinalState(input: ConversationHostedTerminalStateInput): HostedLifecycleTerminalState; /** Cleanup after hosted chat execution finalization helper. */ export declare function cleanupAfterHostedChatExecutionFinalization(input: { cleanup: () => Promise; logger?: HostedChatExecutionRuntimeLogger; }): Promise; /** Create hosted chat execution runtime bootstrap. */ export declare function createHostedChatExecutionRuntimeBootstrap(input: CreateHostedChatExecutionRuntimeBootstrapInput): Promise; /** Create bootstrapped hosted chat execution runtime. */ export declare function createBootstrappedHostedChatExecutionRuntime(input: CreateBootstrappedHostedChatExecutionRuntimeInput): Promise; /** Create hosted chat stream finalization hooks. */ export declare function createHostedChatStreamFinalizationHooks(input: { lifecycleAdapter: HostedChatExecutionLifecycleAdapter; cleanup: () => Promise; streamError: unknown; logger?: HostedChatExecutionRuntimeLogger; }): SharedFinalizationHooks; /** State for create hosted chat finalize response build. */ export declare function createHostedChatFinalizeResponseBuildState(input: { responseMessage: ChatUiMessage; isAborted: boolean; lifecycleAdapter: HostedChatExecutionLifecycleAdapter; mirroredToolChunkState: MirroredToolChunkState; capturedMessageId: string | null; incompleteToolCallsPartErrorText: string; }): (finalStep: unknown) => Promise>>; /** State for create hosted chat finalize detached build. */ export declare function createHostedChatFinalizeDetachedBuildState(input: { capturedMessageId: string | null; isAborted: boolean; lifecycleAdapter: HostedChatExecutionLifecycleAdapter; mirroredToolChunkState: MirroredToolChunkState; mirroredDurableOutput: boolean; incompleteToolCallsPartErrorText: string; }): (finalStep: unknown) => Promise>>; /** Create hosted chat execution runtime. */ export declare function createHostedChatExecutionRuntime(input: CreateHostedChatExecutionRuntimeInput): HostedChatExecutionRuntime; //# sourceMappingURL=chat-execution-runtime.d.ts.map