File size: 1,988 Bytes
a37e6db
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Email Canvas Tool"""
import logging
from typing import Any, Dict, List, Optional

logger = logging.getLogger(__name__)


async def present_email_canvas(
    user_id: str,
    subject: str,
    recipients: List[str],
    agent_id: Optional[str] = None,
    template: Optional[str] = None,
    layout: str = "conversation"
) -> Dict[str, Any]:
    """
    Present an email canvas.

    Creates a compose interface for email creation.
    """
    from core.canvas_email_service import EmailCanvasService
    from core.database import get_db_session
    from tools.canvas_tool import present_specialized_canvas

    try:
        with get_db_session() as db:
            service = EmailCanvasService(db)

            result = service.create_email_canvas(
                user_id=user_id,
                subject=subject,
                recipients=recipients,
                agent_id=agent_id,
                layout=layout,
                template=template
            )

            if not result.get("success"):
                return result

            canvas_id = result["canvas_id"]

            present_result = await present_specialized_canvas(
                user_id=user_id,
                canvas_type="email",
                component_type="compose_form",
                data={
                    "subject": subject,
                    "recipients": recipients,
                    "template": template
                },
                title=subject,
                agent_id=agent_id,
                layout=layout
            )

            if not present_result.get("success"):
                return present_result

            return {
                "success": True,
                "canvas_id": canvas_id,
                "subject": subject,
                "message": f"Presented email canvas: {subject}"
            }

    except Exception as e:
        logger.error(f"Failed to present email canvas: {e}")
        return {"success": False, "error": str(e)}