Principle:AIPexStudio AIPex UI Event Adaptation
| Knowledge Sources | |
|---|---|
| Domains | UI_Architecture, React |
| Last Updated | 2026-10-24 12:00 GMT |
Overview
A pattern that converts a stream of backend agent events into a message-based UI state model suitable for React rendering.
Description
Backend AI agent events (content deltas, tool calls, metrics) are optimized for streaming and stateless processing. React UIs, however, need a message-based model: a list of messages where each message has typed parts (text, tool, file, context). UI Event Adaptation maintains an internal state machine that accumulates content deltas into assistant messages, creates tool-call entries with pending/complete/error states, and tracks a chat status (idle, streaming, executing_tools, error). The adapter pattern decouples the event source from the UI framework, enabling the same agent event stream to drive different UIs.
Usage
Use this principle when connecting an event-streaming AI agent to a React (or component-based) UI. It is the standard bridge between imperative streaming and declarative rendering.
Theoretical Basis
The adapter maintains a state machine:
Status: idle → streaming → executing_tools → streaming → idle
processEvent(event):
content_delta → append to current assistant message
tool_call_start → add tool part to message, status=executing_tools
tool_call_complete → update tool part with result
tool_call_error → update tool part with error
execution_complete → status=idle
error → status=error
getMessages() → UIMessage[] with typed parts