File size: 3,062 Bytes
a31f556
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
from backend.agent.react_agent import Tool
from backend.services.automation_service import scheduler, pause_job, resume_job, delete_job, trigger_automation
import json

async def list_automations_handler() -> str:
    jobs = scheduler.get_jobs()
    if not jobs:
        return "No automations currently scheduled."
    
    out = []
    for j in jobs:
        out.append({
            "id": j.id,
            "name": j.name,
            "next_run_time": str(j.next_run_time) if j.next_run_time else "Paused"
        })
    return json.dumps(out, indent=2)

async def pause_automation_handler(job_id: str) -> str:
    try:
        pause_job(job_id)
        return f"Job {job_id} paused."
    except Exception as e:
        return f"Error pausing job: {e}"

async def resume_automation_handler(job_id: str) -> str:
    try:
        resume_job(job_id)
        return f"Job {job_id} resumed."
    except Exception as e:
        return f"Error resuming job: {e}"

async def delete_automation_handler(job_id: str) -> str:
    try:
        delete_job(job_id)
        return f"Job {job_id} deleted."
    except Exception as e:
        return f"Error deleting job: {e}"

async def trigger_automation_handler(job_id: str) -> str:
    try:
        await trigger_automation(job_id)
        return f"Automation {job_id} triggered."
    except Exception as e:
        return f"Error triggering automation: {e}"

list_automations_tool = Tool(
    name="list_automations",
    description="List all scheduled APScheduler automations and their status.",
    parameters={"type": "object", "properties": {}},
    handler=list_automations_handler
)

pause_automation_tool = Tool(
    name="pause_automation",
    description="Pause an active automation job.",
    parameters={
        "type": "object",
        "properties": {
            "job_id": {"type": "string", "description": "The ID of the job to pause"}
        },
        "required": ["job_id"]
    },
    handler=pause_automation_handler
)

resume_automation_tool = Tool(
    name="resume_automation",
    description="Resume a paused automation job.",
    parameters={
        "type": "object",
        "properties": {
            "job_id": {"type": "string", "description": "The ID of the job to resume"}
        },
        "required": ["job_id"]
    },
    handler=resume_automation_handler
)

delete_automation_tool = Tool(
    name="delete_automation",
    description="Delete an automation job.",
    parameters={
        "type": "object",
        "properties": {
            "job_id": {"type": "string", "description": "The ID of the job to delete"}
        },
        "required": ["job_id"]
    },
    handler=delete_automation_handler
)

trigger_automation_tool = Tool(
    name="trigger_automation",
    description="Trigger an automation job immediately.",
    parameters={
        "type": "object",
        "properties": {
            "job_id": {"type": "string", "description": "The ID of the automation to trigger"}
        },
        "required": ["job_id"]
    },
    handler=trigger_automation_handler
)