File size: 1,862 Bytes
4e3c158
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Coding Canvas Tool"""
import logging
from typing import Any, Dict, Optional

logger = logging.getLogger(__name__)


async def present_coding_canvas(
    user_id: str,
    repo: str,
    branch: str,
    agent_id: Optional[str] = None,
    layout: str = "repo_view"
) -> Dict[str, Any]:
    """
    Present a coding canvas.

    Creates a code development workspace.
    """
    from core.canvas_coding_service import CodingCanvasService
    from core.database import get_db_session
    from tools.canvas_tool import present_specialized_canvas

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

            result = service.create_coding_canvas(
                user_id=user_id,
                repo=repo,
                branch=branch,
                agent_id=agent_id,
                layout=layout
            )

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

            canvas_id = result["canvas_id"]

            present_result = await present_specialized_canvas(
                user_id=user_id,
                canvas_type="coding",
                component_type="repo_browser",
                data={
                    "repo": repo,
                    "branch": branch
                },
                title=f"{repo} ({branch})",
                agent_id=agent_id,
                layout=layout
            )

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

            return {
                "success": True,
                "canvas_id": canvas_id,
                "repo": repo,
                "branch": branch,
                "message": f"Presented coding canvas: {repo}"
            }

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