hashbrown

ChatRuntime

A stateful client runtime for sending messages, processing AG-UI events, executing tools, and exposing reactive chat state.

API

interface ChatRuntime<Output, Tools extends Chat.AnyTool, State = unknown>  {
error:  StateSignal <
   Error  | undefined
>;
exhaustedRetries:  StateSignal <boolean>;
generatingError:  StateSignal <
   Error  | undefined
>;
getRecoveryConfiguration(): ConversationRecoveryConfiguration;
isGenerating:  StateSignal <boolean>;
isLoading:  StateSignal <boolean>;
isReceiving:  StateSignal <boolean>;
readonly isResuming: StateSignal<boolean>;
isRunningToolCalls:  StateSignal <boolean>;
isSending:  StateSignal <boolean>;
lastAssistantMessage:  StateSignal <
   Chat.AssistantMessage <Output, Tools> | undefined
>;
lastRunFinishReason:  StateSignal <
   FinishReason  | undefined
>;
lastRunResult:  StateSignal <
   JsonValue  | undefined
>;
lastRunUsage:  StateSignal <
  readonly  TokenUsage [] | undefined
>;
messages:  StateSignal <
   Chat.Message <Output, Tools>[]
>;
readonly pendingConversationRecovery: StateSignal<PendingConversationRecovery | undefined>;
readonly pendingInterrupts: StateSignal<PendingInterruptBatch | undefined>;
readonly recovery: StateSignal<ConversationRecoveryState>;
resendMessages: () => void;
restoreConversation(snapshot: ConversationSnapshot<State>, options: ConversationRestoreOptions): void;
resume(options: ResumeOptions): void;
resumeConversationRecovery(options: ResumeConversationRecoveryOptions): void;
sendingError:  StateSignal <
   Error  | undefined
>;
sendMessage: (message: Chat.MessageInput<Output, Tools>) => void;
setMessages: (messages: Chat.MessageInput<Output, Tools>[]) => void;
setState(state: State): void;
start: () => () => void;
readonly state: StateSignal<State | undefined>;
stop: (clearStreamingMessage?: boolean) => void;
readonly subagents: StateSignal<readonly SubagentRun[]>;
threadId:  StateSignal <string | undefined>;
updateOptions: (options: Partial<{
        debugName?: string;
        system: string;
        tools: Tools[];
        responseSchema: s.SchemaOutput;
        debounce: number;
        retries: number;
        transport: TransportOrFactory;
        ui?: boolean;
        threadId?: string | undefined;
    }>) => void;
}
ChatRuntime
@typeOutput
@typeTools
Chat.AnyTool
@typeState
error
StateSignal<Error | undefined>
exhaustedRetries
StateSignal<boolean>
generatingError
StateSignal<Error | undefined>
isGenerating
StateSignal<boolean>
isLoading
StateSignal<boolean>
isReceiving
StateSignal<boolean>
isResuming
StateSignal<boolean>

Whether the whole resumed interaction is still executing.

isRunningToolCalls
StateSignal<boolean>
isSending
StateSignal<boolean>
lastAssistantMessage
StateSignal<Chat.AssistantMessage<Output, Tools> | undefined>
lastRunFinishReason

Why the model stopped in the last run that completed, such as length when the answer was cut off, or undefined when the server did not say. Hashbrown's provider packages always report it. Cleared when the next run starts; interrupted, cancelled, and failed runs never set it.

lastRunResult
StateSignal<JsonValue | undefined>

The return value the agent attached to the last run that completed (AG-UI's RUN_FINISHED.result), or undefined when it attached none. Cleared when the next run starts, so it always belongs to the messages currently shown. Interrupted, cancelled, and failed runs never set it.

lastRunUsage
StateSignal<readonly TokenUsage[] | undefined>

The token usage of the last run that completed (AG-UI's RUN_FINISHED.usage), one entry per provider and model, or undefined when the server reported none. Cleared when the next run starts, so a turn that calls tools reports only its final run. Interrupted, cancelled, and failed runs never set it.

messages
StateSignal<Chat.Message<Output, Tools>[]>
pendingConversationRecovery

Inert browser calls and genuine interrupts awaiting explicit recovery settlement.

pendingInterrupts

The current batch, retained until the server acknowledges resume.

Local lookup revision and acknowledged-failure recovery disposition.

resendMessages
() => void

Resend messages and update state. Often used manually after an error.

sendingError
StateSignal<Error | undefined>
sendMessage
(message: Chat.MessageInput<Output, Tools>) => void

Send a new message to the LLM and update state.

setMessages
(messages: Chat.MessageInput<Output, Tools>[]) => void

Replace the current set of messages in the chat state.

start
() => () => void

Start the runtime effect loop and return a function that disposes it.

state
StateSignal<State | undefined>

The currently visible shared agent state.

stop
(clearStreamingMessage?: boolean) => void

Stop the current LLM interaction.

subagents

Observed native subagent invocations in the current conversation.

threadId
StateSignal<string | undefined>

The opaque AG-UI thread identity used by the current and subsequent runs.

updateOptions
(options: Partial<{
        debugName?: string;
        system: string;
        tools: Tools[];
        responseSchema: s.SchemaOutput;
        debounce: number;
        retries: number;
        transport: TransportOrFactory;
        ui?: boolean;
        threadId?: string | undefined;
    }>) => void

Update the chat options after initialization