feat(KB-045): add scheduled tasks automation system
- Add AutomationStore and core automation types for cron-based scheduling - Implement CronRunner engine for executing scheduled automations - Add REST API routes for CRUD operations on automations - Create UI components: ScheduleCard, ScheduleForm, and ScheduledTasksModal - Integrate scheduled tasks into dashboard App.tsx and CLI dashboard command - Add comprehensive tests for store, runner, API, and UI components - Include changeset for the new scheduled tasks feature
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import type { Task, TaskDetail, TaskAttachment, TaskCreateInput, AgentLogEntry, Column, MergeResult, Settings } from "@kb/core";
|
||||
import type { PlanningQuestion, PlanningSummary, PlanningResponse } from "@kb/core";
|
||||
import type { ScheduledTask, ScheduledTaskCreateInput, ScheduledTaskUpdateInput, AutomationRunResult } from "@kb/core";
|
||||
|
||||
async function api<T = unknown>(path: string, opts: RequestInit = {}): Promise<T> {
|
||||
const res = await fetch(`/api${path}`, {
|
||||
@@ -838,3 +839,53 @@ export function connectPlanningStream(
|
||||
isConnected: () => !isClosed && eventSource.readyState === EventSource.OPEN,
|
||||
};
|
||||
}
|
||||
|
||||
// ── Automation / Scheduled Tasks ──────────────────────────────────
|
||||
|
||||
/** Response from the manual run trigger endpoint. */
|
||||
export interface AutomationRunResponse {
|
||||
schedule: ScheduledTask;
|
||||
result: AutomationRunResult;
|
||||
}
|
||||
|
||||
export function fetchAutomations(): Promise<ScheduledTask[]> {
|
||||
return api<ScheduledTask[]>("/automations");
|
||||
}
|
||||
|
||||
export function fetchAutomation(id: string): Promise<ScheduledTask> {
|
||||
return api<ScheduledTask>(`/automations/${id}`);
|
||||
}
|
||||
|
||||
export function createAutomation(input: ScheduledTaskCreateInput): Promise<ScheduledTask> {
|
||||
const { name, description, scheduleType, cronExpression, command, enabled, timeoutMs } = input;
|
||||
return api<ScheduledTask>("/automations", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ name, description, scheduleType, cronExpression, command, enabled, timeoutMs }),
|
||||
});
|
||||
}
|
||||
|
||||
export function updateAutomation(id: string, updates: ScheduledTaskUpdateInput): Promise<ScheduledTask> {
|
||||
const { name, description, scheduleType, cronExpression, command, enabled, timeoutMs } = updates;
|
||||
return api<ScheduledTask>(`/automations/${id}`, {
|
||||
method: "PATCH",
|
||||
body: JSON.stringify({ name, description, scheduleType, cronExpression, command, enabled, timeoutMs }),
|
||||
});
|
||||
}
|
||||
|
||||
export async function deleteAutomation(id: string): Promise<void> {
|
||||
await api(`/automations/${id}`, {
|
||||
method: "DELETE",
|
||||
});
|
||||
}
|
||||
|
||||
export function runAutomation(id: string): Promise<AutomationRunResponse> {
|
||||
return api<AutomationRunResponse>(`/automations/${id}/run`, {
|
||||
method: "POST",
|
||||
});
|
||||
}
|
||||
|
||||
export function toggleAutomation(id: string): Promise<ScheduledTask> {
|
||||
return api<ScheduledTask>(`/automations/${id}/toggle`, {
|
||||
method: "POST",
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user