> ## Documentation Index
> Fetch the complete documentation index at: https://docs.thesys.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Conversational UI Concepts

> Additional concepts specific to building Chatbot Style interfaces

Here we cover the flow of a conversation and the data model (`Thread`, `Message`) used by C1Chat.

### The Flow of a Conversation

```mermaid theme={null}
sequenceDiagram
    autonumber
    actor U as User
    participant F as Chat UI
    participant T as Thread (History)
    participant B as Backend Server
    participant C1 as C1 API

    U->>F: Types a prompt and hits send
    F->>T: Create & append "User Message" to current thread
    F->>B: Send new user message + relevant thread context
    B->>C1: Construct payload & call C1 API<br/>(system prompt + history + user msg)
    C1-->>B: Return assistant response
    B-->>F: Deliver C1 response
    F->>T: Store as "Assistant Message" in thread
    F-->>U: Render "Assistant Message" in the UI

```

* User Input: The user types a prompt into the chat composer and sends it.
* Message Creation: The application creates a user message from this input and adds it to the current Thread's history.
* Backend Request: The frontend sends the new user message (often along with the thread context) to your backend server.
* API Call: Your backend constructs the full payload for the C1 API. This typically includes a predefined system prompt, the conversation history from the Thread, and the new user message.
* Assistant Response: The C1 API processes the request and returns a response, which your application stores as an assistant message.
* UI Update: The frontend receives this C1 response, adds it to the Thread as a new assistant message, and displays it in the UI.

#### Message

C1 API is openai compatible. So the message is the same as openai.

A `Message` is a basic unit in a conversation. Each message has a `role` that defines its author:

* **`user`**: Represents an input from the end-user.
* **`assistant`**: Represents a response from the AI. The content can be standard text or a C1 DSL string for rendering interactive UI.
* **`system`**: Provides high-level instructions to the AI and is typically not visible in the UI.

#### Thread: A Single Conversation

A `Thread` is an ordered list of `Message` objects. It represents a single, continuous conversation.

#### ThreadList: Managing Multiple Conversations

A `ThreadList` is the collection of all threads for a user. In a typical UI, this is represented by the chat history sidebar.
