# Gadget Code Chat Turn

A "turn" in our Chat Sessions is defined as the user's input prompt, and all response data from the agent, along with some metadata such as when the turn was started, when it was completed, and some statistics gathered while running (tokens processed, etc.).

## Chat Turn Life Cycle

A turn begins when the User enters a prompt in the IDE's Chat Session view. The prompt is sent to gadget-code:web, where it becomes a Work Order, and gets bundled with information about the User, Project, ChatSession, and the current ChatTurn.

The Work Order is then sent to the gadget-drone that is locked to the Chat Session for processing. The agent will emit thinking, response, and tool call events while working. These are all captured into the Chat Turn and saved. When done, the agent closes the Work Order (and Chat Turn).

This back and forth process of Prompt => Events => Response continues in iterations throughout the Chat Session. Eventually, the Chat Session is closed.

## Rendering a Chat Turn

A Chat Turn is a component that renders the user's prompt and agent's responses in the scrolling Chat View within the Chat Session view. Turns are rendered into the view when the Chat Session view is loaded to display any available history. Then, new Turns are dynamically added to the messages list, and the data that streams in for them is added and rendered as the Agentic Workflow Loop executes in the gadget-drone.

```
                         Chat View
┌────────────────────────────────────────────────────────┐
│ User Display Name                                      │
│ The user's prompt as they entered it.                  │
│                                                        │
│                                                 Gadget │
│                                               Thinking │
│                                               Response │
├────────────────────────────────────────────────────────┤
│ User Display Name                                      │
│ The user's prompt as they entered it.                  │
│                                                        │
│                                                 Gadget │
│                                               Thinking │
│                                               Response │
└────────────────────────────────────────────────────────┘
```

Chat turns are meant to be rendered in order, presenting the User's prompt and Agent's responses, in turns, as a chat-like scrolling view. Message blocks (User Prompt, Agent Response) are 80% of the width of their container. The text within them is left-justified. User blocks are justified left in the container, leaving a right margin of 20%. Agent blocks are right-justified in the container leaving a left margin of 20%.
