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 )