Skip to main content
The Chat Interface is the primary operational surface of the Palyra Web Console. It facilitates real-time interaction with the Palyra daemon through a streaming NDJSON protocol, manages complex session lifecycles (branching, compaction, and checkpoints), and provides an integrated environment for tool approval and context management.

Chat Console Architecture

The chat interface is implemented as a multi-column React layout centered around the ChatConsolePanel. It coordinates state between the conversation transcript, the composer, and a diagnostic “Inspector” column.

Key Components

ComponentResponsibilitySource
ChatConsolePanelCentral orchestrator for chat state, streaming, and side-panel actions.apps/web/src/chat/ChatConsolePanel.tsx#71-77
ChatComposerHandles user input, slash commands, file uploads, and context budget visualization.apps/web/src/chat/ChatComposer.tsx#53-84
ChatTranscriptRenders the message history, including tool calls, A2UI frames, and inline approvals.apps/web/src/chat/ChatTranscript.tsx
ChatInspectorColumnDisplays workspace signals: budget, session lineage, background tasks, and search.apps/web/src/chat/ChatInspectorColumn.tsx#109-155

Data Flow: User Input to Daemon

The following diagram illustrates how a user message moves from the React UI to the Rust backend and starts a streamed run. Chat Run Initiation Flow Sources: apps/web/src/chat/ChatConsolePanel.tsx#120-156, crates/palyra-daemon/src/transport/http/handlers/console/chat.rs#139-182, apps/web/src/chat/useChatRunStream.ts

Run Streaming (NDJSON)

Palyra uses a line-delimited JSON (NDJSON) stream for real-time updates. This allows the UI to render incremental assistant tokens, tool execution status, and A2UI patches without waiting for the full run completion.

Stream Handling in the UI

The useChatRunStream hook manages the fetch request to the stream endpoint. It parses each line as a TranscriptEntry and updates the local state.
  • Incremental Tokens: Assistant tokens are buffered and appended to the active message entry.
  • Run Lifecycle: The hook tracks run_id, run_status, and run_tape (the event log of the current run).
  • Termination: Handles stream closure and error states (e.g., model timeouts or policy denials).
Sources: apps/web/src/chat/useChatRunStream.ts, apps/web/src/chat/ChatConsolePanel.tsx#120-150

Context Budget & Previews

To prevent context window overflow and provide transparency, the UI calculates a “Context Budget” before the user sends a message.

Budget Calculation

The buildContextBudgetSummary function estimates the token count for the current session baseline, the draft text, active attachments, and context references.

Context & Recall Previews

The UI provides real-time previews of what information will be “recalled” by the daemon:
  1. useContextReferencePreview: Parses the composer text for @path/to/file syntax and resolves file content previews via the daemon. apps/web/src/chat/useContextReferencePreview.ts
  2. useRecallPreview: Simulates the daemon’s RAG (Retrieval-Augmented Generation) process to show which memory items or workspace files will be auto-injected based on the current query. apps/web/src/chat/useRecallPreview.ts
Sources: apps/web/src/chat/chatShared.tsx#22-65, apps/web/src/chat/ChatComposer.tsx#131-187, crates/palyra-daemon/src/application/provider_input.rs#159-190

Tool Approvals & A2UI

Palyra integrates security and UI updates directly into the chat transcript.

Approval Request Handling

When a tool requires human-in-the-loop (HITL) authorization, the daemon emits an approval_request event.

A2UI (Agent-to-UI) Updates

Agents can publish structured UI updates via the a2ui event type. Sources: apps/web/src/chat/ChatTranscript.tsx, apps/web/src/chat/chatShared.tsx#170-210, apps/web/src/chat/ChatConsolePanel.test.tsx#119-162

Session Lifecycle Management

The console supports advanced session operations to manage long-running conversations.

Compaction & Checkpoints

Long sessions are managed through Compaction, which summarizes older events to free up context budget.

Branching

The /branch command creates a new child session from the current run’s state. This is useful for exploring alternative paths without polluting the main session history. apps/web/src/chat/chatShared.tsx#102-106 Entity Relationship: Session & Run Sources: crates/palyra-daemon/src/application/session_compaction.rs#76-126, apps/web/src/chat/chatShared.tsx#76-163, crates/palyra-daemon/src/transport/http/handlers/console/chat.rs#36-105