|
1 | 1 | import asyncio |
2 | 2 | from typing import TYPE_CHECKING |
3 | 3 |
|
4 | | -from textual.widgets import Markdown, TextArea |
| 4 | +from textual.widgets import Markdown |
5 | 5 | from textual.containers import VerticalScroll |
6 | 6 |
|
7 | 7 | from agent_chat_cli.components.chat_history import ChatHistory, MessagePosted |
8 | | -from agent_chat_cli.components.thinking_indicator import ThinkingIndicator |
9 | | -from agent_chat_cli.components.tool_permission_prompt import ToolPermissionPrompt |
10 | 8 | from agent_chat_cli.components.messages import ( |
11 | 9 | AgentMessage as AgentMessageWidget, |
12 | 10 | Message, |
@@ -46,11 +44,11 @@ async def handle_agent_message(self, message: AgentMessage) -> None: |
46 | 44 | case AgentMessageType.RESULT: |
47 | 45 | await self._handle_result() |
48 | 46 |
|
49 | | - async def _scroll_to_bottom(self) -> None: |
50 | | - await asyncio.sleep(0.1) |
| 47 | + async def on_message_posted(self, event: MessagePosted) -> None: |
| 48 | + chat_history = self.app.query_one(ChatHistory) |
| 49 | + chat_history.add_message(event.message) |
51 | 50 |
|
52 | | - container = self.app.query_one(VerticalScroll) |
53 | | - container.scroll_end(animate=False, immediate=True) |
| 51 | + await self._scroll_to_bottom() |
54 | 52 |
|
55 | 53 | async def _handle_stream_event(self, message: AgentMessage) -> None: |
56 | 54 | text_chunk = message.data.get("text", "") |
@@ -121,45 +119,31 @@ async def _handle_user(self, message: AgentMessage) -> None: |
121 | 119 | await self._scroll_to_bottom() |
122 | 120 |
|
123 | 121 | async def _handle_tool_permission_request(self, message: AgentMessage) -> None: |
124 | | - from agent_chat_cli.components.user_input import UserInput |
125 | | - |
126 | 122 | log_json( |
127 | 123 | { |
128 | 124 | "event": "showing_permission_prompt", |
129 | 125 | "tool_name": message.data.get("tool_name", ""), |
130 | 126 | } |
131 | 127 | ) |
132 | 128 |
|
133 | | - thinking_indicator = self.app.query_one(ThinkingIndicator) |
134 | | - thinking_indicator.is_thinking = False |
135 | | - |
136 | | - permission_prompt = self.app.query_one(ToolPermissionPrompt) |
137 | | - permission_prompt.tool_name = message.data.get("tool_name", "") |
138 | | - permission_prompt.tool_input = message.data.get("tool_input", {}) |
139 | | - permission_prompt.is_visible = True |
140 | | - |
141 | | - user_input = self.app.query_one(UserInput) |
142 | | - user_input.display = False |
| 129 | + self.app.ui_state.show_permission_prompt( |
| 130 | + tool_name=message.data.get("tool_name", ""), |
| 131 | + tool_input=message.data.get("tool_input", {}), |
| 132 | + ) |
143 | 133 |
|
144 | 134 | await self._scroll_to_bottom() |
145 | 135 |
|
146 | 136 | async def _handle_result(self) -> None: |
147 | | - # Check if there's a queued message (e.g., from custom permission response) |
148 | 137 | if not self.app.agent_loop.query_queue.empty(): |
149 | | - # Don't turn off thinking - there's more work to do |
150 | 138 | return |
151 | 139 |
|
152 | | - thinking_indicator = self.app.query_one(ThinkingIndicator) |
153 | | - thinking_indicator.is_thinking = False |
154 | | - |
155 | | - input_widget = self.app.query_one(TextArea) |
156 | | - input_widget.cursor_blink = True |
| 140 | + self.app.ui_state.stop_thinking() |
157 | 141 |
|
158 | 142 | self.current_agent_message = None |
159 | 143 | self.current_response_text = "" |
160 | 144 |
|
161 | | - async def on_message_posted(self, event: MessagePosted) -> None: |
162 | | - chat_history = self.app.query_one(ChatHistory) |
163 | | - chat_history.add_message(event.message) |
| 145 | + async def _scroll_to_bottom(self) -> None: |
| 146 | + await asyncio.sleep(0.1) |
164 | 147 |
|
165 | | - await self._scroll_to_bottom() |
| 148 | + container = self.app.query_one(VerticalScroll) |
| 149 | + container.scroll_end(animate=False, immediate=True) |
0 commit comments