Package-level declarations

Types

Link copied to clipboard
class Chat(val id: String = "chat", initialMessages: List<UIMessage> = emptyList(), transport: ChatTransport)
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
class ChatSession(chat: Chat)
Link copied to clipboard
Link copied to clipboard
data class ChatState(val id: String, val messages: List<UIMessage> = emptyList(), val status: ChatStatus = ChatStatus.Ready, val error: Throwable? = null)
Link copied to clipboard
Link copied to clipboard
interface ChatTransport
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

UI-to-model message conversion. Groups convertToModelMessages and its helpers so none remain loose top-level functions.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
class TextStreamChatTransport(handler: (ChatRequest) -> Flow<String>, assistantMessageId: (ChatRequest) -> String = { request -> UiMessageStreams.getResponseUiMessageId(request.messages) }) : ChatTransport
Link copied to clipboard
class TextStreamResponse(val textStream: Flow<String>, val status: Int = 200, val headers: Map<String, String> = UiMessageStreams.textStreamHeaders())
Link copied to clipboard

Streaming-vs-final state for UIMessagePart.Text and UIMessagePart.Reasoning (per historical parity gap #30, mirrors v6's TextUIPart.state: 'streaming' | 'done'). Renderers use this to drive a typing cursor / fade animation while the model is still producing the part, and to commit a final layout pass on Done.

Link copied to clipboard

Tool call lifecycle in the UI. v6 names — input-streaming / input-available / output-available, NOT v5's partial-call / call / result.

Link copied to clipboard

Registry of per-tool renderers. The SDK is UI-framework-agnostic — the registry holds renderer functions that take UIToolInvocation. An application can supply Compose composables, SwiftUI bridge closures, server-rendered nodes, or any other renderer value.

Link copied to clipboard
data class UIMessage(val id: String, val role: UIMessageRole, val parts: List<UIMessagePart>, val createdAtMs: Long = 0, val metadata: Map<String, JsonElement>? = null)

UI-shape message — what the chat surface renders. Carries an ordered list of UIMessageParts (Vercel AI SDK v6 message-parts model). The conversion from ai.torad.aisdk.StreamEvent flow into a growing list of these messages happens in streamToUiMessages.

Link copied to clipboard
Link copied to clipboard
sealed interface UIMessagePart
Link copied to clipboard
Link copied to clipboard
class UIMessageStreamResponse(val stream: Flow<UIMessage>, val status: Int = 200, val headers: Map<String, String> = UiMessageStreams.uiMessageStreamHeaders())
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
class UIToolInvocation<TInput, TOutput>(val toolCallId: String, val toolName: String, val state: ToolCallState, val payload: UIToolInvocationPayload<TInput, TOutput>, val metadata: UIToolInvocationMetadata = UIToolInvocationMetadata())
Link copied to clipboard
class UIToolInvocationMetadata(val preliminary: Boolean = false, val approvalId: String? = null, val signature: String? = null)
Link copied to clipboard
class UIToolInvocationPayload<TInput, TOutput>(val input: TInput?, val output: TOutput?, val error: String?)

Typed invocation handle — what a per-tool renderer receives. Carries the typed input + output via the tool's own serializers.

Functions

Link copied to clipboard
Link copied to clipboard
fun ChatSession(id: String = "chat", initialMessages: List<UIMessage> = emptyList(), transport: ChatTransport): ChatSession
Link copied to clipboard
fun CreateTextStreamResponse(textStream: Flow<String>, status: Int = 200, headers: Map<String, String> = UiMessageStreams.textStreamHeaders()): TextStreamResponse
Link copied to clipboard
fun CreateUiMessageStream(onError: (Throwable) -> UIMessage = { throwable -> UIMessage( id = "error", role = UIMessageRole.Assistant, parts = listOf(UIMessagePart.Error(throwable.message ?: "stream failed")), ) }, execute: suspend UIMessageStreamWriter.() -> Unit): Flow<UIMessage>
Link copied to clipboard
fun CreateUiMessageStreamResponse(stream: Flow<UIMessage>, status: Int = 200, headers: Map<String, String> = UiMessageStreams.uiMessageStreamHeaders()): UIMessageStreamResponse
Link copied to clipboard
Link copied to clipboard
fun StreamToUiMessages(events: Flow<StreamEvent>, assistantMessageId: String): Flow<UIMessage>
Link copied to clipboard
Link copied to clipboard

Bridge an agent StreamEvent flow to the v6 UI-message-stream wire protocol: each emission is a UIMessageChunk JSON object (e.g. { "type": "text-delta", "id": "...", "delta": "..." }) ready to be framed as an SSE data: line and consumed by a JS useChat client. Events with no wire counterpart (response-metadata, tool-input-end, raw) are dropped.

Link copied to clipboard
fun TransformTextToUiMessageStream(textStream: Flow<String>, assistantMessageId: String, metadata: Map<String, JsonElement>? = null): Flow<UIMessage>
Link copied to clipboard