-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessages.py
More file actions
65 lines (45 loc) · 1.58 KB
/
messages.py
File metadata and controls
65 lines (45 loc) · 1.58 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
from dataclasses import dataclass
from enum import Enum
from typing import Any
from textual.widget import Widget
from textual.widgets import Label, Markdown
from textual.app import ComposeResult
from rich.markup import escape
from agent_chat_cli.utils import get_tool_info, format_tool_input
class RoleType(Enum):
SYSTEM = "system"
USER = "user"
AGENT = "agent"
TOOL = "tool"
@dataclass
class Message:
type: RoleType
content: str
metadata: dict[str, Any] | None = None
class SystemMessage(Widget):
message: str = ""
def compose(self) -> ComposeResult:
yield Label("[bold][#debd00]System:[/][/bold]")
yield Label(self.message, classes="dim")
class UserMessage(Widget):
message: str = ""
def compose(self) -> ComposeResult:
yield Label("[bold][#a3c1ad]You:[/][/bold]")
yield Markdown(self.message)
class AgentMessage(Widget):
message: str = ""
def compose(self) -> ComposeResult:
yield Label("[bold][#1995bb]Agent:[/][/bold]")
yield Markdown(self.message)
class ToolMessage(Widget):
tool_name: str = ""
tool_input: dict = {}
def compose(self) -> ComposeResult:
tool_info = get_tool_info(self.tool_name)
formatted_input = format_tool_input(self.tool_input)
if tool_info["server_name"]:
label = f"[#FFD281]{escape(f'[{tool_info["server_name"]}]')}: {tool_info['tool_name']}[/]"
else:
label = f"[#FFD281]{escape('[tool]')} {self.tool_name}[/]"
yield Label(label)
yield Label(formatted_input, classes="tool-message dim")