forked from smallcloudai/refact
-
-
Notifications
You must be signed in to change notification settings - Fork 4
GUI Chat Flow
refact-planner edited this page Jun 7, 2026
·
1 revision
Chat messages are sent as commands and received through SSE events, with sequence checks and thread-level runtime transitions.
Chat uses two backend endpoints:
POST /v1/chats/{chatId}/commandsGET /v1/chats/subscribe?chat_id={id}
The command endpoint sends user intents, and the SSE stream returns snapshots and incremental updates.
sequenceDiagram
participant UI as GUI
participant API as Backend
UI->>API: POST /v1/chats/{id}/commands
API-->>UI: SSE snapshot
API-->>UI: SSE stream_delta*
API-->>UI: SSE stream_finished
UI->>UI: reducer applies events
| Event type | Purpose |
|---|---|
snapshot |
Full state sync; resets sequence to 0 |
stream_started |
Assistant generation begins |
stream_delta |
Incremental content via DeltaOp[]
|
stream_finished |
Completion with finish reason / usage |
message_added |
Insert message |
message_updated |
Update message |
message_removed |
Remove message |
messages_truncated |
Trim history |
thread_updated |
Thread metadata changed |
runtime_updated |
Runtime flags changed |
pause_required |
Tool confirmation pause |
pause_cleared |
Confirmation pause cleared |
ide_tool_required |
IDE tool action needed |
subchat_update |
Nested chat update |
queue_updated |
Command queue changed |
ack |
Command acknowledgment |
background_agent_updated |
Background agent update |
browser_* events |
Browser-related streaming and status updates |
process_completed |
Process completion event |
stream_delta uses DeltaOp[] with these operations:
append_contentappend_reasoningset_tool_callsset_thinking_blocksadd_citationadd_server_content_blockset_usagemerge_extra
Commands posted to /v1/chats/{chatId}/commands include:
user_messageabortregenerateupdate_messageremove_messagetool_decisiontool_decisionside_tool_resultset_paramsretry_from_indexbranch_from_chatbrowser_context_decision
-
snapshotestablishes the baseline and resets sequence tracking to0 - each following event increments by
1 - a gap in sequence numbers triggers reconnect logic to obtain a fresh snapshot
Per-thread runtime follows the backend-driven lifecycle rather than a single global chat state.
stateDiagram-v2
[*] --> IDLE
IDLE --> WAITING: command sent / awaiting result
WAITING --> STREAMING: stream_started or stream_delta
STREAMING --> IDLE: stream_finished
WAITING --> PAUSED: pause_required
PAUSED --> WAITING: pause_cleared or tool decision
WAITING --> STOPPED: abort / terminal error
STREAMING --> STOPPED: abort / terminal error
STOPPED --> IDLE
The concrete runtime booleans and states observed in the code include streaming, waiting_for_response, confirmation.pause, session_state, and error.
- Commands are issued with a client request id.
-
user_messagemay carry content as a string or rich content array. -
priorityis supported on commands and queued items. -
abort,regenerate, and tool decision commands are explicit command types rather than local state mutations. -
snapshot_receivedgates whether a thread is considered synchronized enough for follow-up actions.
Refact on GitHub: https://github.com/JegernOUTT/refact
- Agent Modes
- Agent Tools
- Task Planner & Cards
- Worktrees
- Subagents
- Memory & Knowledge
- Hidden Roles & Plans
- Context Compression
- Scheduler & Cron
- Processes & PTY
- Buddy
- MCP
- Skills, Commands & Hooks
- Marketplace
- Chat System
- Providers
- Caps & Models
- Code Completion (FIM)
- AST
- VecDB
- Exec Runtime
- HTTP API
- Checkpoints & Git
- Voice