mirror of
https://github.com/agent0ai/agent-zero.git
synced 2026-12-04 03:58:09 +00:00
Move the scheduler CRUD endpoints, modals, styles, sidebar tasks list, and task row into the _scheduler plugin and drop the core tasks components. The sidebar hosts plugin sections through a neutral sidebar-extensions point inside the extensions-section container instead of a tasks-specific one, so other plugins can contribute sections there too. The scheduler and datepicker styles load through the plugin page-head extension instead of core index.html preloads, and the shared flatpickr preload stays in core. Repoint the header scheduler entry at the plugin modal path and update the api and plugins DOX indexes. Pin indicators follow the relocated task row and the pin test reads it from the plugin. The chats store and core chat behavior adopt the plugin task store idiom, and the ws client surface test expects the plugin store accessor. The modals and css DOX drop their core scheduler ownership and the scheduler plugin DOX indexes its sidebar and page-head extensions. The plugin manifest becomes always enabled with a broader description so the Tasks UI stays core behavior, and the scheduler editor test follows the moved endpoint and store paths. Validation: pytest plugins/_pin_to_top/tests/test_pins.py tests/test_sidebar_row_actions.py tests/test_webui_extension_surfaces.py tests/test_ws_client_api_surface.py tests/test_webui_startup_assets.py::test_only_the_icon_guard_stylesheet_blocks_application_paint tests/test_chat_working_animation.py tests/test_scheduler_editor.py
94 lines
3.5 KiB
Python
94 lines
3.5 KiB
Python
from helpers.api import ApiHandler, Input, Output, Request
|
|
from helpers.task_scheduler import (
|
|
TaskScheduler, ScheduledTask, AdHocTask, PlannedTask, TaskState,
|
|
serialize_task, parse_task_schedule, parse_task_plan
|
|
)
|
|
from helpers.localization import Localization
|
|
|
|
|
|
class SchedulerTaskUpdate(ApiHandler):
|
|
async def process(self, input: Input, request: Request) -> Output:
|
|
"""
|
|
Update an existing task in the scheduler
|
|
"""
|
|
# Get timezone from input (do not set if not provided, we then rely on poll() to set it)
|
|
if timezone := input.get("timezone", None):
|
|
Localization.get().set_timezone(timezone)
|
|
|
|
scheduler = TaskScheduler.get()
|
|
await scheduler.reload()
|
|
|
|
# Get task ID from input
|
|
task_id: str = input.get("task_id", "")
|
|
|
|
if not task_id:
|
|
return {"error": "Missing required field: task_id"}
|
|
|
|
# Get the task to update
|
|
task = scheduler.get_task_by_uuid(task_id)
|
|
|
|
if not task:
|
|
return {"error": f"Task with ID {task_id} not found"}
|
|
|
|
# Update fields if provided using the task's update method
|
|
update_params = {}
|
|
|
|
if "name" in input:
|
|
update_params["name"] = input.get("name", "")
|
|
|
|
if "state" in input:
|
|
update_params["state"] = TaskState(input.get("state", TaskState.IDLE))
|
|
|
|
if "system_prompt" in input:
|
|
update_params["system_prompt"] = input.get("system_prompt", "")
|
|
|
|
if "prompt" in input:
|
|
update_params["prompt"] = input.get("prompt", "")
|
|
|
|
if "attachments" in input:
|
|
update_params["attachments"] = input.get("attachments", [])
|
|
|
|
if "project_name" in input or "project_color" in input:
|
|
return {"error": "Project changes are not allowed"}
|
|
|
|
# Update schedule if this is a scheduled task and schedule is provided
|
|
if isinstance(task, ScheduledTask) and "schedule" in input:
|
|
schedule_data = input.get("schedule", {})
|
|
try:
|
|
# Parse the schedule with timezone handling
|
|
task_schedule = parse_task_schedule(schedule_data)
|
|
|
|
# Set the timezone from the request if not already in schedule_data
|
|
if not schedule_data.get('timezone', None) and timezone:
|
|
task_schedule.timezone = timezone
|
|
|
|
update_params["schedule"] = task_schedule
|
|
except ValueError as e:
|
|
return {"error": f"Invalid schedule format: {str(e)}"}
|
|
elif isinstance(task, AdHocTask) and "token" in input:
|
|
token_value = input.get("token", "")
|
|
if token_value: # Only update if non-empty
|
|
update_params["token"] = token_value
|
|
elif isinstance(task, PlannedTask) and "plan" in input:
|
|
plan_data = input.get("plan", {})
|
|
try:
|
|
# Parse the plan data
|
|
task_plan = parse_task_plan(plan_data)
|
|
update_params["plan"] = task_plan
|
|
except ValueError as e:
|
|
return {"error": f"Invalid plan format: {str(e)}"}
|
|
|
|
# Use atomic update method to apply changes
|
|
updated_task = await scheduler.update_task(task_id, **update_params)
|
|
|
|
if not updated_task:
|
|
return {"error": f"Task with ID {task_id} not found or could not be updated"}
|
|
|
|
# Return the updated task using our standardized serialization function
|
|
task_dict = serialize_task(updated_task)
|
|
|
|
return {
|
|
"ok": True,
|
|
"task": task_dict
|
|
}
|