-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
68 lines (48 loc) · 1.86 KB
/
app.py
File metadata and controls
68 lines (48 loc) · 1.86 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
import asyncio
from textual.app import App, ComposeResult
from textual.containers import VerticalScroll
from textual.binding import Binding
from agent_chat_cli.components.header import Header
from agent_chat_cli.components.chat_history import ChatHistory, MessagePosted
from agent_chat_cli.components.thinking_indicator import ThinkingIndicator
from agent_chat_cli.components.user_input import UserInput
from agent_chat_cli.system.agent_loop import AgentLoop
from agent_chat_cli.system.message_bus import MessageBus
from agent_chat_cli.system.actions import Actions
from agent_chat_cli.utils.logger import setup_logging
from dotenv import load_dotenv
load_dotenv()
setup_logging()
class AgentChatCLIApp(App):
CSS_PATH = "system/styles.tcss"
BINDINGS = [
Binding("ctrl+c", "quit", "Quit", show=False, priority=True),
Binding("escape", "interrupt", "Interrupt", show=True),
Binding("ctrl+n", "new", "New", show=True),
]
def __init__(self) -> None:
super().__init__()
self.message_bus = MessageBus(self)
self.agent_loop = AgentLoop(
on_message=self.message_bus.handle_agent_message,
)
self.actions = Actions(self)
def compose(self) -> ComposeResult:
with VerticalScroll():
yield Header()
yield ChatHistory()
yield ThinkingIndicator()
yield UserInput(actions=self.actions)
async def on_mount(self) -> None:
asyncio.create_task(self.agent_loop.start())
async def on_message_posted(self, event: MessagePosted) -> None:
await self.message_bus.on_message_posted(event)
async def action_interrupt(self) -> None:
await self.actions.interrupt()
async def action_new(self) -> None:
await self.actions.new()
def main():
app = AgentChatCLIApp()
app.run()
if __name__ == "__main__":
main()