Widget System

chevron-rightRelevant source fileshashtag

The Widget System provides dynamic, rich data visualization in the chat interface by automatically creating interactive widgets from tool execution results. When agents use tools that return structured data (database queries, documents, code snippets, emails, etc.), the system instantiates type-specific widgets in a split-screen canvas alongside the chat conversation.

For information about the chat interface itself, see Chat Interface. For tool execution and routing, see Tool Router & Execution.


Purpose and Scope

This page documents:

  • Widget type definitions and data structures

  • Automatic widget creation from SSE tool-data events

  • Widget state management via Zustand store

  • Split-panel layout architecture

  • Widget-specific rendering behaviors

This does not cover the legacy artifact viewer system, which is being deprecated in favor of widgets.


Architecture Overview

spinner

Sources: frontend/components/chatbot/chat.tsx:1-250, orchestrator/consumers/chatbot/service.py:1-950, orchestrator/modules/tools/tool_router.py:1-575


Widget Type Definitions

The system supports seven widget types, each with a specific data structure:

Widget Type
Trigger
Data Structure
Primary Use Case

data

tool-data.database_results[]

DataWidgetData

SQL query results with charts

document

tool-data.documents[]

DocumentWidgetData

RAG-retrieved documents

code

tool-data.code_snippets[]

CodeWidgetData

Code search results

email

tool-data.emails[]

EmailWidgetData

Gmail/Outlook messages

terminal

tool-data.terminal_output

TerminalWidgetData

Command execution output

document

tool-data.generated_document

DocumentWidgetData

PDF/DOCX/XLSX generation

coding_canvas

User action

CodingCanvasWidgetData

Workspace file editor

Sources: frontend/components/chatbot/chat.tsx:14-23, frontend/components/widgets/types


Widget Data Structures

Core Widget Schema

Every widget conforms to this base structure:

Data Widget Structure

Created when tools return database query results:

Sources: frontend/components/chatbot/chat.tsx:156-193

Document Widget Structure

Created from RAG retrieval or document generation:

Sources: frontend/components/chatbot/chat.tsx:196-230, frontend/components/chatbot/chat.tsx:319-341

Code Widget Structure

Created from codebase search results:

Sources: frontend/components/chatbot/chat.tsx:233-255

Email Widget Structure

Created from Gmail/Outlook tool execution:

Email address parsing normalizes various formats ("Name <email>", "email", objects) into a consistent structure using the parseEmailAddress helper.

Sources: frontend/components/chatbot/chat.tsx:259-317

Terminal Widget Structure

Created from workspace command execution:

Sources: frontend/components/chatbot/chat.tsx:343-366


Widget Lifecycle

spinner

Sources: frontend/components/chatbot/chat.tsx:140-380, frontend/components/chatbot/chat.tsx:650-680


Widget Store Architecture

The widget system uses Zustand for client-side state management:

Key operations:

  1. addWidget: Generates UUID, adds widget to store, pushes ID to widgetIds, returns ID

  2. updateWidget: Performs partial update on widget data (used for lazy-loading document content)

  3. clearWidgets: Resets store to empty state when closing canvas

  4. setActiveWidget: Controls which widget tab is visible in Canvas

Sources: frontend/components/chatbot/chat.tsx:56-65, frontend/stores/workspace-store


Layout System

When widgets exist, the chat interface switches from full-screen to split-panel mode:

spinner

Panel constraints:

  • Chat column: minSize={20}, maxSize={60}

  • Canvas column: minSize={30}, no max

  • Handle is draggable with visual indicator

Layout trigger logic:

Sources: frontend/components/chatbot/chat.tsx:738-817, frontend/components/chatbot/chat.tsx:902-1147


Widget Creation from Tool Data

The widget factory logic in the onData callback inspects SSE event payloads and dispatches to type-specific creators:

spinner

Key patterns:

  1. Array iteration: Most data types arrive as arrays (database_results[], documents[], etc.) — each item becomes a separate widget

  2. Metadata normalization: Each widget's metadata.source includes the tool name and provider

  3. Lazy loading: Document widgets may set state: 'loading' if has_full_content: false, then fetch via /api/documents/{id}/content

  4. Deduplication: Code and document widgets check if an existing widget with the same file path or symbol name exists before creating a new one

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


Data Widget Details

Data widgets visualize SQL query results with optional PandasAI analysis and charts.

Creation Logic

Backend source: The smart_query_database tool (NL2SQL service) returns structured results. PandasAI charts are generated server-side and embedded as base64 PNGs.

Sources: frontend/components/chatbot/chat.tsx:156-193, orchestrator/modules/nl2sql/service.py


Document Widget Details

Document widgets display RAG-retrieved or generated documents with optional lazy-loading.

RAG Document Flow

spinner

Chunk merging logic:

Sources: frontend/components/chatbot/chat.tsx:603-680

Generated Document Flow

Documents created by the generate_document tool are immediately available with full content:

The content field contains a Markdown representation of the document (see DocumentGenerationService._data_to_markdown() for rendering logic).

Sources: frontend/components/chatbot/chat.tsx:319-341, orchestrator/modules/documents/generation_service.py:398-504


Code Widget Details

Code widgets display syntax-highlighted source code from codebase search:

Deduplication: Before creating a code widget, the system checks if a widget with the same filePath and symbolName already exists. If found, it activates the existing widget instead of creating a duplicate.

Sources: frontend/components/chatbot/chat.tsx:233-255, frontend/components/chatbot/chat.tsx:564-601


Email Widget Details

Email widgets display messages from Gmail or Outlook integrations:

Email normalization: The parsing logic handles three email address formats:

  1. Plain string: "[email protected]"

  2. Named format: "John Doe <[email protected]>"

  3. Object format: { email: "[email protected]", name: "John Doe" }

Sources: frontend/components/chatbot/chat.tsx:259-317


Terminal Widget Details

Terminal widgets display command execution output from the workspace worker:

Title truncation: Command titles are limited to 30 characters with ellipsis to prevent overflow.

Sources: frontend/components/chatbot/chat.tsx:343-366


Coding Canvas Widget

The coding canvas is unique — it's created by user action rather than tool output:

This widget provides a Monaco editor connected to the workspace filesystem for direct code editing.

Sources: frontend/components/chatbot/chat.tsx:70-98


Widget Deduplication Strategy

To prevent duplicate widgets when agents repeatedly call the same tools:

Document Deduplication

Code Deduplication

Coding Canvas Deduplication

Rationale: Without deduplication, repeated tool calls (e.g., "show me that document again") would create many identical widget tabs, degrading UX.

Sources: frontend/components/chatbot/chat.tsx:569-579, frontend/components/chatbot/chat.tsx:609-616, frontend/components/chatbot/chat.tsx:77-84


SSE Event Dispatchers

Beyond widget creation, the chat component dispatches additional SSE events to the workspace store:

These events are consumed by other components (e.g., memory widgets, workflow progress indicators) that subscribe to the workspace store.

Sources: frontend/components/chatbot/chat.tsx:369-378, frontend/stores/workspace-store


Close Canvas Behavior

Closing the canvas clears all widgets and resets overlay states:

This ensures a clean slate when returning to full-screen chat mode.

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


Integration with Platform Actions

Platform actions (see Platform Action Definitions) can return data that automatically creates widgets. For example:

  • platform_get_llm_usage → Data widget with token usage table

  • platform_list_documents → Data widget with document list

  • platform_get_agent → JSON viewer widget (via generic data widget)

The PlatformActionExecutor returns structured JSON that matches widget data schemas:

When this result is streamed via tool-data, the widget factory can parse it as a database result and create a data widget.

Sources: orchestrator/modules/tools/discovery/platform_executor.py:280-324, orchestrator/modules/tools/discovery/platform_actions.py:146-172


Legacy Artifact Viewer

The system maintains backward compatibility with the pre-widget artifact viewer for gradual migration:

Deprecation path: The artifact viewer is being phased out in favor of widgets. It currently only activates when hasWidgets === false and an artifact is selected.

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


Summary

The Widget System provides:

  1. Seven widget types for different data modalities (database, document, code, email, terminal, generated document, coding canvas)

  2. Automatic creation from SSE tool-data events with zero configuration

  3. Split-panel layout with resizable columns via ResizablePanelGroup

  4. Zustand state management for widget CRUD operations

  5. Lazy loading for large documents with async content fetching

  6. Deduplication to prevent duplicate widgets from repeated tool calls

  7. Type-safe data structures with TypeScript interfaces for each widget type

The system bridges backend tool execution (RAG, NL2SQL, Composio, workspace worker) to frontend visualization through a simple event protocol, enabling rich multimodal chat interactions without explicit UI coding for each tool.

Sources: frontend/components/chatbot/chat.tsx:1-1200, frontend/components/widgets/, orchestrator/consumers/chatbot/service.py, orchestrator/modules/tools/tool_router.py


Last updated