-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactions.py
More file actions
70 lines (52 loc) · 2.35 KB
/
actions.py
File metadata and controls
70 lines (52 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from typing import TYPE_CHECKING
from agent_chat_cli.utils.enums import ControlCommand
from agent_chat_cli.components.chat_history import ChatHistory
from agent_chat_cli.components.messages import RoleType
from agent_chat_cli.components.tool_permission_prompt import ToolPermissionPrompt
from agent_chat_cli.utils.logger import log_json
if TYPE_CHECKING:
from agent_chat_cli.app import AgentChatCLIApp
class Actions:
def __init__(self, app: "AgentChatCLIApp") -> None:
self.app = app
def quit(self) -> None:
self.app.exit()
async def submit_user_message(self, message: str) -> None:
await self.app.renderer.add_message(RoleType.USER, message)
await self._query(message)
async def post_system_message(self, message: str) -> None:
await self.app.renderer.add_message(RoleType.SYSTEM, message)
async def handle_app_event(self, event) -> None:
await self.app.renderer.handle_app_event(event)
async def interrupt(self) -> None:
permission_prompt = self.app.query_one(ToolPermissionPrompt)
if permission_prompt.is_visible:
return
self.app.ui_state.set_interrupting(True)
await self.app.agent_loop.client.interrupt()
self.app.ui_state.stop_thinking()
async def clear(self) -> None:
chat_history = self.app.query_one(ChatHistory)
await chat_history.remove_children()
self.app.ui_state.stop_thinking()
async def new(self) -> None:
await self.app.agent_loop.query_queue.put(ControlCommand.NEW_CONVERSATION)
await self.clear()
async def respond_to_tool_permission(self, response: str) -> None:
log_json(
{
"event": "permission_response_action",
"response": response,
}
)
await self.app.agent_loop.permission_response_queue.put(response)
self.app.ui_state.hide_permission_prompt()
self.app.ui_state.start_thinking()
normalized = response.lower().strip()
if normalized not in ["y", "yes", "allow", ""]:
if normalized in ["n", "no", "deny"]:
await self._query("The user has denied the tool")
else:
await self.submit_user_message(response)
async def _query(self, user_input: str) -> None:
await self.app.agent_loop.query_queue.put(user_input)