mirror of
https://github.com/agent0ai/agent-zero.git
synced 2026-12-05 01:48:44 +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
78 lines
2.2 KiB
JavaScript
78 lines
2.2 KiB
JavaScript
import { createStore } from "/js/AlpineStore.js";
|
|
import { store as chatsStore } from "/components/sidebar/chats/chats-store.js";
|
|
import { store as sidebarStore } from "/components/sidebar/sidebar-store.js";
|
|
import { store as schedulerStore } from "/plugins/_scheduler/webui/scheduler/scheduler-store.js";
|
|
|
|
// Tasks sidebar store: tasks list and selected task id
|
|
const model = {
|
|
tasks: [],
|
|
selected: "",
|
|
|
|
init() {
|
|
// No-op: data is driven by poll() in index.js; this store provides a stable target
|
|
},
|
|
|
|
// Apply tasks coming from poll() and keep them sorted (newest first)
|
|
applyTasks(tasksList) {
|
|
try {
|
|
const tasks = Array.isArray(tasksList) ? tasksList : [];
|
|
const sorted = [...tasks].sort((a, b) => (b?.created_at || 0) - (a?.created_at || 0));
|
|
this.tasks = sorted;
|
|
|
|
// After updating tasks, ensure selection is still valid
|
|
if (this.selected && !this.contains(this.selected)) {
|
|
this.setSelected("");
|
|
}
|
|
} catch (e) {
|
|
console.error("tasks-store.applyTasks failed", e);
|
|
this.tasks = [];
|
|
}
|
|
},
|
|
|
|
// Update selected task and persist for tab restore
|
|
setSelected(taskId) {
|
|
this.selected = taskId || "";
|
|
try { localStorage.setItem("lastSelectedTask", this.selected); } catch {}
|
|
},
|
|
|
|
// Returns true if a task with the given id exists in the current list
|
|
contains(taskId) {
|
|
return Array.isArray(this.tasks) && this.tasks.some((t) => t?.id === taskId);
|
|
},
|
|
|
|
visibleTasks() {
|
|
return sidebarStore.sortRows("task", this.tasks);
|
|
},
|
|
|
|
// Convenience: id of the first task in the current list (or empty string)
|
|
firstId() {
|
|
return (Array.isArray(this.tasks) && this.tasks[0]?.id) || "";
|
|
},
|
|
|
|
// Action methods for task management
|
|
selectTask(taskId) {
|
|
this.setSelected(taskId);
|
|
chatsStore.selectChat(taskId);
|
|
},
|
|
|
|
openDetail(taskId) {
|
|
// Open lightweight task detail popup directly
|
|
if (schedulerStore?.showTaskDetail) {
|
|
schedulerStore.showTaskDetail(taskId);
|
|
}
|
|
},
|
|
|
|
reset(taskId) {
|
|
chatsStore.resetChat(taskId);
|
|
},
|
|
|
|
deleteTask(taskId) {
|
|
if (schedulerStore?.deleteTaskFromSidebar) {
|
|
schedulerStore.deleteTaskFromSidebar(taskId);
|
|
}
|
|
},
|
|
};
|
|
|
|
export const store = createStore("tasks", model);
|
|
|