Chat UI Components

chevron-rightRelevant source fileshashtag

This page covers the frontend components that implement the real-time streaming chat interface, including message rendering, multimodal input, widget integration, tool suggestions, and layout management.

For backend chat orchestration, see 7.1 Chat API & Streaming. For the widget system architecture and widget types, see 7.7 Widget System. For agent routing displayed in chat messages, see 8 Universal Router.


Component Architecture Overview

The chat interface is composed of three primary components working together:

Component
File
Purpose

Chat

frontend/components/chatbot/chat.tsx

Main chat container, message list, widget integration, SSE event handling

MultimodalInput

frontend/components/chatbot/multimodal-input.tsx

Text input, file attachments, agent selector, model selector, tool icons

PilotHelperWidget

frontend/components/chatbot/chat-widget.tsx

Contextual help and bug reporting overlay

The Chat component manages three distinct layout modes based on content type:

  1. Normal mode — Chat messages only, no side panels

  2. Widget mode (PRD-38.1) — Split view with chat on left (35%), widget canvas on right (65%)

  3. Artifact viewer mode (legacy) — Split view with chat on left, single artifact on right

Sources: frontend/components/chatbot/chat.tsx:1-50, frontend/components/chatbot/multimodal-input.tsx:1-30


Chat Component Structure

Component Hierarchy

spinner

Sources: frontend/components/chatbot/chat.tsx:43-105

Key Props and State

The Chat component accepts the following props:

State variables:

State
Type
Purpose

widgetIds

string[]

Active widget IDs from workspace store (PRD-38.1)

selectedArtifact

Artifact | null

Legacy artifact for artifact viewer mode

activeTool

string | null

Currently active tool for suggestions (PRD-40)

toolSuggestions

string[]

Suggested prompts for active tool

selectedAgentId

number | null

User-selected agent (overrides auto-routing)

lastRoutingDecision

ref

Stores agent ID from most recent routing for corrections (PRD-50)

Sources: frontend/components/chatbot/chat.tsx:33-125


Widget Integration (PRD-38.1)

The chat component automatically creates widgets when tool execution results arrive via SSE tool-data events. This replaces the legacy artifact viewer with a composable multi-widget canvas.

Auto-Widget Creation Flow

spinner

Sources: frontend/components/chatbot/chat.tsx:145-380

Widget Type Transformations

The chat component transforms backend tool results into widget data structures:

Backend Structure
Widget Type
Transformation Logic

database_results[]

data

Extract columns, rows, sql, charts from PandasAI chat.tsx:156-192

documents[]

document

Map chunks[] to widget format with similarity scores chat.tsx:196-230

code_snippets[]

code

Extract code, language, filePath, symbolName chat.tsx:233-255

emails[]

email

Parse email addresses (handles "Name <email>" format) chat.tsx:260-317

generated_document

document

Attach content, downloadUrl, mark hasFullContent: true chat.tsx:320-341

terminal_output

terminal

Extract command, stdout, stderr, exitCode chat.tsx:344-366

Email Address Parsing Example:

The chat component includes a helper to normalize email formats from Composio integrations:

Sources: frontend/components/chatbot/chat.tsx:263-283

Document Widget Lazy Loading

When a document widget is created without full content (has_full_content: false), the chat component fetches the full text asynchronously:

This prevents blocking the UI while large documents are retrieved from S3.

Sources: frontend/components/chatbot/chat.tsx:653-679


Tool Suggestion System (PRD-40/41)

The chat interface displays dynamic tool suggestions when users click tool icons in the input bar. This feature has two phases:

Phase 1: Basic Suggestions (PRD-40)

Tool icons are displayed for the active agent's connected apps. Clicking an icon fetches pre-configured suggestions from the backend:

spinner

State Management:

State Variable
Purpose

activeTool

Name of tool with open suggestions (e.g. "gmail")

toolSuggestions

Array of prompt strings fetched from API

isLoadingSuggestions

Loading indicator during API call

Sources: frontend/components/chatbot/chat.tsx:489-556

Phase 2: Context-Aware Suggestions (PRD-41)

When user_id and session_id are available, the backend personalizes suggestions based on conversation history:

The ToolSuggestionBar displays a context indicator when hasContext: true.

Sources: frontend/components/chatbot/chat.tsx:506-540, frontend/components/chatbot/multimodal-input.tsx:232-261


Layout System

The chat component supports three layout modes using ResizablePanelGroup:

Layout Modes Diagram

spinner

Sources: frontend/components/chatbot/chat.tsx:737-900

Normal Mode (Welcome State)

When messages.length === 0 and not streaming, displays a welcome card with personalized greeting:

The card includes quick links to agents, workflows, documents, and tools pages.

Sources: frontend/components/chatbot/chat.tsx:905-940

Widget Mode (PRD-38.1)

When hasWidgets is true (i.e., widgetIds.length > 0), the component renders a full-screen overlay with resizable panels:

The Canvas component (from @/components/workspace) renders all active widgets as floating panels with tabs.

Sources: frontend/components/chatbot/chat.tsx:737-817

Artifact Viewer Mode (Legacy)

For backward compatibility, the component still supports viewing single artifacts (code, markdown, HTML). This mode is deprecated in favor of widgets but maintained for existing links:

Sources: frontend/components/chatbot/chat.tsx:820-899


MultimodalInput Component

The input component handles text input, file attachments, agent selection, model selection, and tool icon displays.

Component Structure

spinner

Sources: frontend/components/chatbot/multimodal-input.tsx:1-295

File Upload Flow

The input component supports drag-and-drop and paste-to-upload for documents:

Uploaded documents are sent as file parts in the message:

Sources: frontend/components/chatbot/multimodal-input.tsx:114-149, frontend/components/chatbot/multimodal-input.tsx:75-90

Agent-Based Tool Icons (PRD-40)

When an agent is selected via AgentSelector, the component displays tool logos for the agent's connected apps:

Clicking a tool icon triggers onToolIconClick(appName), which opens the ToolSuggestionBar in the parent Chat component.

Sources: frontend/components/chatbot/multimodal-input.tsx:232-261


Message Flow and Event Handling

The Chat component integrates with the useChat hook to handle SSE streaming:

Event Handling Flow

spinner

Sources: frontend/components/chatbot/chat.tsx:140-416

Routing Decision Display (PRD-50)

When a message is auto-routed to an agent, the onRoutingDecision callback resolves the agent name:

If the user manually changes the agent after auto-routing, a correction is sent to /api/routing/corrections:

This feedback loop improves routing accuracy over time (see 8.7 Routing Corrections & Learning).

Sources: frontend/components/chatbot/chat.tsx:383-439


PilotHelperWidget (Jira Integration)

The PilotHelperWidget provides contextual help and bug reporting. It's rendered as a floating Jira-branded button in the bottom-right corner.

Widget Features

Tab
Purpose

Help

Context-aware help items based on current page (dashboard, agents, workflows, etc.)

Report Bug

Bug report form with title, description, severity, category, screenshot paste

Bug Report Submission

The widget captures console errors and page context, submitting to /api/bug-report:

The backend creates a Jira issue and returns jira_key (e.g., "AUTO-123") and jira_url for linking to the created ticket.

Sources: frontend/components/chatbot/chat-widget.tsx:192-233

Contextual Help Content

Help items are defined per page in PAGE_HELP_CONTENT:

The widget selects the appropriate help items based on context.currentPage.

Sources: frontend/components/chatbot/chat-widget.tsx:40-86


State Management Integration

The chat component integrates with two primary state stores:

useChat Hook Integration

The useChat hook (from lib/chat/hooks) manages message state and SSE streaming:

Sources: frontend/components/chatbot/chat.tsx:140-416

Workspace Store Integration (PRD-38.1)

The chat component uses useWorkspaceStore for widget state:

These dispatchers allow memory and workflow widgets (if implemented) to react to SSE events.

Sources: frontend/components/chatbot/chat.tsx:56-66


Auto-Scroll and Scroll Detection

The chat component tracks scroll position to show/hide a "scroll to bottom" button:

During streaming, the component auto-scrolls to the bottom:

Sources: frontend/components/chatbot/chat.tsx:442-471


Title Generation

The chat component auto-generates a title after the first user-assistant exchange:

The generateTitle utility function (from lib/utils) truncates the first message to 50 characters for use as the conversation title in the sidebar.

Sources: frontend/components/chatbot/chat.tsx:474-486


Summary

The chat UI components form a sophisticated interface layer that:

  1. Renders streaming messages with routing indicators, tool calls, and artifacts

  2. Auto-creates widgets from tool execution results (database queries, documents, code, emails, terminal output)

  3. Provides contextual tool suggestions with Phase 1 (basic) and Phase 2 (context-aware) support

  4. Manages three layout modes (normal, widget canvas, artifact viewer) using resizable panels

  5. Handles multimodal input with text, file attachments, agent selection, and tool icon shortcuts

  6. Integrates with help and bug reporting via the Jira-branded PilotHelperWidget

  7. Dispatches SSE events to workspace store for memory and workflow widgets

  8. Records routing corrections when users manually override agent selection

For the backend chat orchestration that powers these components, see 7.1 Chat API & Streaming. For widget rendering details, see 7.7 Widget System.


Last updated