trading_agent.terminal.screens.chat_screen
¶
The chat with one desk: today's turns, the live progress line and the message box.
The screen reads today's journal of the desk when it opens, then takes live events from the application. Events that arrive while the journal is still loading are held and added afterwards; ChatTranscript drops the ones the journal already had.
The terminal program's own commands (/attach, /desk, /model with no name, /theme, /keys, /exit, and one per page such as /trading) are handled here. Files are attached with @path in a message, /attach, by dragging them onto the terminal, or with Ctrl+V for a picture on the clipboard; they upload at once and go with the next message. Every other message, including every other /command, goes to the desk, which answers commands such as /status itself.
Typical usage example:
app.push_screen(ChatScreen(gateway, history, 'general'))
ChatScreen
¶
Bases: Screen[None]
The chat screen.
Creates the screen.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gateway
|
GatewayClient
|
The gateway's routes. |
required |
history
|
PromptHistory
|
The earlier prompts. |
required |
desk_name
|
str
|
The desk to open on. |
required |
settings
|
TerminalSettings
|
The remembered choices, such as whether the side panel is shown. |
required |
opener
|
AttachmentOpener
|
Downloads and opens the desk's files. |
required |
Source code in src/trading_agent/terminal/screens/chat_screen.py
compose
¶
Builds the screen.
Yields:
| Type | Description |
|---|---|
Widget
|
The status line, the transcript, the progress line, the command menu, the message box and the key hints. |
Source code in src/trading_agent/terminal/screens/chat_screen.py
on_mount
¶
Loads the desk's chat and focuses the message box.
Source code in src/trading_agent/terminal/screens/chat_screen.py
take_event
¶
Adds one live event to the chat, when it belongs to this desk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
dict[str, Any]
|
The event. |
required |
Source code in src/trading_agent/terminal/screens/chat_screen.py
take_desks
¶
Updates the status line and placeholder from the desks' states.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
document
|
dict[str, Any]
|
The answer of GET /api/desks. |
required |
Source code in src/trading_agent/terminal/screens/chat_screen.py
take_connection
¶
Shows the event stream's state, and reloads the chat after a reconnect.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
str
|
"connecting", "live", "reconnecting" or "refused". |
required |
Source code in src/trading_agent/terminal/screens/chat_screen.py
desk
¶
The summary of the desk this chat shows.
Returns:
| Type | Description |
|---|---|
dict[str, Any] | None
|
The summary, or None before the desks are known. |
Source code in src/trading_agent/terminal/screens/chat_screen.py
load_desk
async
¶
Clears the chat and fills it with the desk's journal of today.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
desk_name
|
str
|
The desk. |
required |
Source code in src/trading_agent/terminal/screens/chat_screen.py
refresh_requests
async
¶
Reads the pending requests and shows this desk's first one in the dock.
Source code in src/trading_agent/terminal/screens/chat_screen.py
on_request_dock_answered
¶
Reads the requests again after one was answered.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
Answered
|
The notice. |
required |
Source code in src/trading_agent/terminal/screens/chat_screen.py
on_text_area_changed
¶
Opens or narrows the command menu as the user types.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
Changed
|
The change. |
required |
Source code in src/trading_agent/terminal/screens/chat_screen.py
on_composer_menu_moved
¶
Moves the command menu's highlight.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
MenuMoved
|
The move. |
required |
Source code in src/trading_agent/terminal/screens/chat_screen.py
on_composer_menu_picked
¶
Puts the highlighted command into the message box.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
MenuPicked
|
The pick. |
required |
Source code in src/trading_agent/terminal/screens/chat_screen.py
on_composer_submitted
¶
Sends the message, or completes the highlighted command first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
Submitted
|
The submission. |
required |
Source code in src/trading_agent/terminal/screens/chat_screen.py
on_composer_files_dropped
¶
Attaches files dragged onto the terminal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
FilesDropped
|
The files. |
required |
Source code in src/trading_agent/terminal/screens/chat_screen.py
on_composer_empty_backspace
¶
Removes the newest attached file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
EmptyBackspace
|
The key press. |
required |
Source code in src/trading_agent/terminal/screens/chat_screen.py
on_composer_picture_wanted
¶
Attaches a picture on the clipboard, or pastes text when there is none.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
PictureWanted
|
The key press. |
required |
Source code in src/trading_agent/terminal/screens/chat_screen.py
action_escape
¶
Closes the menu, stops the running turn, or clears the box on a second press.
Source code in src/trading_agent/terminal/screens/chat_screen.py
action_interrupt
¶
Clears the box, stops the running turn, or exits on a second press.
Source code in src/trading_agent/terminal/screens/chat_screen.py
action_exit_when_empty
¶
Exits on a second press while the box is empty; otherwise deletes forward.
Source code in src/trading_agent/terminal/screens/chat_screen.py
action_pick_desk
¶
Opens the desk list.
Source code in src/trading_agent/terminal/screens/chat_screen.py
action_pick_model
¶
Opens the model list for this desk.
Source code in src/trading_agent/terminal/screens/chat_screen.py
action_toggle_side_panel
¶
Shows or hides the side panel, and remembers the choice.
Source code in src/trading_agent/terminal/screens/chat_screen.py
action_focus_dock
¶
Moves to the waiting request's card, or to the next widget when nothing waits.
on_request_dock_left
¶
Goes back to the message box when the user leaves a card with Escape.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
Left
|
The notice. |
required |
Source code in src/trading_agent/terminal/screens/chat_screen.py
action_toggle_tools
¶
Opens or folds every tool call in the chat.
Source code in src/trading_agent/terminal/screens/chat_screen.py
action_search_history
¶
on_composer_keys_wanted
¶
Shows the keys when ? is typed into the empty message box.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
KeysWanted
|
The request. |
required |
Source code in src/trading_agent/terminal/screens/chat_screen.py
show_desk
¶
Shows another desk's chat, as the Desks page asks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
desk_name
|
str
|
The desk. |
required |