// api/schedule.ts:定时任务(增删改查 / 启停 / 立即执行 / 执行记录)。 // // 响应形状均已对真实响应核实(2026-10): // GET /schedules → { tasks, total } // GET /schedules/{id} → { task } // GET /schedules/{id}/runs → { runs, task_id, total },runs[] 元素为 // { id, task_id, status, started_at, finished_at, duration_ms, input, output, error } // 命令类接口(增改删 / 启停 / 立即执行)的响应体没有调用方读取,声明为 unknown。 import { defHttp } from '/@/utils/http/axios/index'; import type { ScheduleTask } from '/@/views/ventAI/manageAssistent/types/index'; enum Api { schedules = '/ventAI/api/schedules', } export interface ScheduleListResponse { tasks: ScheduleTask[]; total: number; } /** * 一次执行记录(GET /schedules/{id}/runs 响应的 runs[] 元素)。 * 仍在执行中的记录只会填到 started_at,后续字段按可选处理(面板渲染也一律先判空)。 */ export interface ScheduleRun { id: number; task_id: number; /** running / success / failed / skipped(见 SchedulePanel 的 runStatusLabel) */ status: string; started_at: string; finished_at?: string; duration_ms?: number; input?: string; output?: string; error?: string; } export interface ScheduleRunsResponse { runs: ScheduleRun[]; task_id: number; total: number; } /** 单条定时任务详情(GET /schedules/{id}):外层是 { task } 而不是裸对象,已对真实响应核实 */ export interface ScheduleDetailResponse { task: ScheduleTask; } /** * 定时任务接口 */ export const createSchedule = (data: { name: string; schedule?: { freq: string; hour?: number; minute?: number; day_of_week?: number; day_of_month?: number }; cron_expr?: string; prompt: string; notify_webhook?: string; }): Promise => defHttp.post({ url: Api.schedules, data }, { isTransformResponse: false }); export const getScheduleList = (include_disabled = true): Promise => defHttp.get({ url: Api.schedules, params: { include_disabled } }, { joinParamsToUrl: true, isTransformResponse: false }); export const getScheduleDetail = (task_id: number): Promise => defHttp.get({ url: `${Api.schedules}/${task_id}` }, { isTransformResponse: false }); export const updateSchedule = ( task_id: number, data: { name?: string; schedule?: Record; cron_expr?: string; prompt?: string; notify_webhook?: string } ): Promise => defHttp.put({ url: `${Api.schedules}/${task_id}`, data }, { isTransformResponse: false }); export const pauseSchedule = (task_id: number): Promise => defHttp.post({ url: `${Api.schedules}/${task_id}/pause` }, { isTransformResponse: false }); export const resumeSchedule = (task_id: number): Promise => defHttp.post({ url: `${Api.schedules}/${task_id}/resume` }, { isTransformResponse: false }); export const deleteSchedule = (id: number): Promise => defHttp.delete({ url: `${Api.schedules}/${id}` }, { isTransformResponse: false }); export const getScheduleRuns = (task_id: number, limit = 50): Promise => defHttp.get({ url: `${Api.schedules}/${task_id}/runs`, params: { limit } }, { joinParamsToUrl: true, isTransformResponse: false }); export const runScheduleNow = (task_id: number): Promise => defHttp.post({ url: `${Api.schedules}/${task_id}/run` }, { isTransformResponse: false });