File size: 1,630 Bytes
02117ee
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
UIAgent — UI component generation (React/Next.js/Tailwind)
"""
from typing import Dict
import structlog
from .base_agent import BaseAgent

log = structlog.get_logger()

UI_SYSTEM = """You are an expert React/Next.js/Tailwind CSS UI engineer.
You generate beautiful, responsive, production-ready UI components.
Always use:
- TypeScript with proper types
- Tailwind CSS for styling
- shadcn/ui components when appropriate
- Framer Motion for animations
- Lucide React for icons
- Dark mode support
- Mobile-first responsive design
- Accessibility (aria labels, semantic HTML)
"""


class UIAgent(BaseAgent):
    def __init__(self, ws_manager=None, ai_router=None):
        super().__init__("UIAgent", ws_manager, ai_router)

    async def run(self, task: str, context: Dict = {}, **kwargs) -> str:
        session_id = kwargs.get("session_id", "")
        task_id = kwargs.get("task_id", "")

        await self.emit(task_id, "agent_start", {"agent": "UIAgent", "task": task[:80]}, session_id)

        messages = [
            {"role": "system", "content": UI_SYSTEM},
            {"role": "user", "content": (
                f"Generate a complete, production-ready UI component for: {task}\n\n"
                f"Requirements:\n"
                f"- TypeScript\n- Tailwind CSS\n- Dark mode\n- Mobile responsive\n"
                f"- Include all imports\n- Export as default"
            )},
        ]
        result = await self.llm(messages, task_id=task_id, session_id=session_id, temperature=0.3, max_tokens=6000)
        await self.emit(task_id, "ui_generated", {"agent": "UIAgent"}, session_id)
        return result