-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
65 lines (48 loc) · 1.88 KB
/
app.py
File metadata and controls
65 lines (48 loc) · 1.88 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
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
from agent_chat_cli.components.thinking_indicator import ThinkingIndicator
from agent_chat_cli.components.tool_permission_prompt import ToolPermissionPrompt
from agent_chat_cli.components.user_input import UserInput
from agent_chat_cli.core.agent_loop import AgentLoop
from agent_chat_cli.core.renderer import Renderer
from agent_chat_cli.core.actions import Actions
from agent_chat_cli.core.ui_state import UIState
from agent_chat_cli.utils.logger import setup_logging
from dotenv import load_dotenv
load_dotenv()
setup_logging()
class AgentChatCLIApp(App):
CSS_PATH = "core/styles.tcss"
BINDINGS = [
Binding("ctrl+c", "quit", "Quit", show=False, priority=True),
Binding("ctrl+n", "new", "New", show=True),
Binding("escape", "interrupt", "Interrupt", show=True),
]
def __init__(self) -> None:
super().__init__()
self.ui_state = UIState(app=self)
self.renderer = Renderer(app=self)
self.actions = Actions(app=self)
self.agent_loop = AgentLoop(app=self)
def compose(self) -> ComposeResult:
with VerticalScroll():
yield Header()
yield ChatHistory()
yield ThinkingIndicator()
yield ToolPermissionPrompt(actions=self.actions)
yield UserInput(actions=self.actions)
async def on_mount(self) -> None:
asyncio.create_task(self.agent_loop.start())
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()