mirror of
https://github.com/agent0ai/agent-zero.git
synced 2026-12-04 17:38:45 +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
54 lines
2.0 KiB
Python
54 lines
2.0 KiB
Python
from helpers.api import ApiHandler, Input, Output, Request
|
|
from helpers.task_scheduler import TaskScheduler, TaskState
|
|
from helpers.localization import Localization
|
|
from agent import AgentContext
|
|
from helpers import persist_chat
|
|
|
|
|
|
class SchedulerTaskDelete(ApiHandler):
|
|
async def process(self, input: Input, request: Request) -> Output:
|
|
"""
|
|
Delete a task from the scheduler by ID
|
|
"""
|
|
# 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"}
|
|
|
|
# Check if the task exists first
|
|
task = scheduler.get_task_by_uuid(task_id)
|
|
if not task:
|
|
return {"error": f"Task with ID {task_id} not found"}
|
|
|
|
context = None
|
|
if task.context_id:
|
|
context = self.use_context(task.context_id)
|
|
|
|
# If the task is running, update its state to IDLE first
|
|
if task.state == TaskState.RUNNING:
|
|
scheduler.cancel_running_task(task_id, terminate_thread=True)
|
|
if context:
|
|
context.reset()
|
|
# Update the state to IDLE so any ongoing processes know to terminate
|
|
await scheduler.update_task(task_id, state=TaskState.IDLE)
|
|
# Force a save to ensure the state change is persisted
|
|
await scheduler.save()
|
|
|
|
# This is a dedicated context for the task, so we remove it
|
|
if context and context.id == task.uuid:
|
|
AgentContext.remove(context.id)
|
|
persist_chat.remove_chat(context.id)
|
|
|
|
# Remove the task
|
|
await scheduler.remove_task_by_uuid(task_id)
|
|
|
|
return {"success": True, "message": f"Task {task_id} deleted successfully"}
|