新增日历式计划任务

This commit is contained in:
ji ruo committed 2026-10-09 23:05:44 +08:00
1 parent 9adbd54627
commit 3254c90a03
19 files changed
+1745 -33

No files matched your search

@@ -0,0 +1,419 @@
"use client";
import * as React from "react";
import { CalendarClock, Loader2, Pause, Play, Plus, Search, Trash2, Zap } from "lucide-react";
import { toast } from "sonner";
import { TimeSelect } from "@/components/time-select";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
import { Checkbox } from "@/components/ui/checkbox";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
import { api, type ScheduleInput } from "@/lib/api";
import type { Task, TaskSchedule } from "@/lib/types";
const weekdays = ["周一", "周二", "周三", "周四", "周五", "周六", "周日"];
const blank: ScheduleInput = {
name: "",
schedule_type: "weekly",
weekdays: [6, 7],
start_time: "18:00",
end_time: "",
task_ids: [],
timezone_mode: "beijing",
start_immediately: false,
};
function statusText(s: TaskSchedule) {
return (
(
{
waiting: "等待窗口",
running: "窗口运行中",
outside: "窗口外",
completed: "已完成",
error: "错误",
paused: "已暂停",
} as Record<string, string>
)[s.status] ?? s.status
);
}
function formatTime(value?: string) {
return value ? new Date(value).toLocaleString("zh-CN") : "—";
}
function statusVariant(status: TaskSchedule["status"]): "default" | "destructive" | "secondary" {
if (status === "running") return "default";
if (status === "error") return "destructive";
return "secondary";
}
function ScheduleForm({
value,
tasks,
onSave,
onCancel,
saving,
}: {
value: ScheduleInput;
tasks: Task[];
onSave: (v: ScheduleInput) => void;
onCancel?: () => void;
saving: boolean;
}) {
const [draft, setDraft] = React.useState(value);
const [taskQuery, setTaskQuery] = React.useState("");
const set = (patch: Partial<ScheduleInput>) => setDraft((v) => ({ ...v, ...patch }));
const toggleTask = (id: number, checked: boolean) =>
set({ task_ids: checked ? [...(draft.task_ids ?? []), id] : (draft.task_ids ?? []).filter((x) => x !== id) });
const toggleDay = (day: number) =>
set({
weekdays: (draft.weekdays ?? []).includes(day)
? (draft.weekdays ?? []).filter((x) => x !== day)
: [...(draft.weekdays ?? []), day].sort(),
});
const filteredTasks = React.useMemo(() => {
const query = taskQuery.trim().toLowerCase();
if (!query) return tasks;
return tasks.filter((task) =>
[String(task.id), task.name ?? "", task.description, task.goal].some((value) =>
value.toLowerCase().includes(query),
),
);
}, [taskQuery, tasks]);
let taskListContent: React.ReactNode;
if (tasks.length === 0) {
taskListContent = <span className="text-muted-foreground text-sm">暂无任务</span>;
} else if (filteredTasks.length === 0) {
taskListContent = <span className="text-muted-foreground text-sm">没有匹配的任务</span>;
} else {
taskListContent = filteredTasks.map((task) => (
<div key={task.id} className="flex items-center gap-2 py-1 text-sm">
<Checkbox
id={`schedule-task-${task.id}`}
checked={(draft.task_ids ?? []).includes(Number(task.id))}
onCheckedChange={(v) => toggleTask(Number(task.id), !!v)}
/>
<Label htmlFor={`schedule-task-${task.id}`} className="truncate">
#{task.id} {task.name || task.description}
</Label>
</div>
));
}
return (
<div className="grid gap-4 rounded-lg border p-4">
<div className="grid gap-2">
<Label>计划名称</Label>
<Input value={draft.name} onChange={(e) => set({ name: e.target.value })} placeholder="例如:周末持续扫描" />
</div>
<div className="grid grid-cols-2 gap-3">
<div className="grid gap-2">
<Label>规则</Label>
<Select
value={draft.schedule_type}
onValueChange={(value) => set({ schedule_type: value as ScheduleInput["schedule_type"] })}
>
<SelectTrigger className="h-10 w-full bg-background">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="weekly">按周</SelectItem>
<SelectItem value="once">指定日期</SelectItem>
</SelectContent>
</Select>
</div>
<div className="grid gap-2">
<Label>时区</Label>
<Select
value={draft.timezone_mode}
onValueChange={(value) => set({ timezone_mode: value as ScheduleInput["timezone_mode"] })}
>
<SelectTrigger className="h-10 w-full bg-background">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="beijing">中国北京时间</SelectItem>
<SelectItem value="system">系统当前时区</SelectItem>
</SelectContent>
</Select>
</div>
</div>
{draft.schedule_type === "once" ? (
<div className="grid gap-2">
<Label>执行日期</Label>
<Input type="date" value={draft.run_date ?? ""} onChange={(e) => set({ run_date: e.target.value })} />
</div>
) : (
<div className="grid gap-2">
<Label>星期</Label>
<div className="flex flex-wrap gap-3">
{weekdays.map((label, index) => (
<div key={label} className="flex items-center gap-2 text-sm">
<Checkbox
id={`schedule-weekday-${index + 1}`}
checked={(draft.weekdays ?? []).includes(index + 1)}
onCheckedChange={() => toggleDay(index + 1)}
/>
<Label htmlFor={`schedule-weekday-${index + 1}`}>{label}</Label>
</div>
))}
</div>
</div>
)}
<div className="grid grid-cols-2 gap-3">
<div className="grid gap-2">
<Label>开始时间</Label>
<TimeSelect
value={draft.start_time}
onValueChange={(value) => set({ start_time: value })}
aria-label="开始时间"
/>
</div>
<div className="grid gap-2">
<Label>结束时间(可选)</Label>
<TimeSelect
value={draft.end_time ?? ""}
onValueChange={(value) => set({ end_time: value })}
optional
aria-label="结束时间,可选"
/>
</div>
</div>
<p className="text-muted-foreground text-xs">
结束时间为空表示开始后持续运行;结束时间早于开始时间表示跨午夜窗口。
</p>
<div className="flex items-center gap-2 text-sm">
<Checkbox
id="schedule-start-immediately"
checked={draft.start_immediately}
onCheckedChange={(v) => set({ start_immediately: !!v })}
/>
<Label htmlFor="schedule-start-immediately">创建后立即启动,不等待第一个窗口</Label>
</div>
<div className="grid gap-2">
<div className="flex items-center justify-between gap-3">
<Label>绑定任务</Label>
<span className="text-muted-foreground text-xs">已选 {(draft.task_ids ?? []).length} 个</span>
</div>
<div className="relative">
<Search className="pointer-events-none absolute top-1/2 left-2.5 size-4 -translate-y-1/2 text-muted-foreground" />
<Input
value={taskQuery}
onChange={(event) => setTaskQuery(event.target.value)}
placeholder="检索任务名称、描述或 ID"
className="h-9 pl-8"
/>
</div>
<div className="max-h-40 overflow-auto rounded border p-2">{taskListContent}</div>
</div>
<div className="flex justify-end gap-2">
<Button variant="outline" onClick={onCancel}>
取消
</Button>
<Button disabled={saving} onClick={() => onSave(draft)}>
{saving && <Loader2 className="animate-spin" data-icon="inline-start" />}保存计划
</Button>
</div>
</div>
);
}
export default function SchedulesPage() {
const [items, setItems] = React.useState<TaskSchedule[]>([]);
const [tasks, setTasks] = React.useState<Task[]>([]);
const [loading, setLoading] = React.useState(true);
const [editing, setEditing] = React.useState<{ id?: number; value: ScheduleInput } | null>(null);
const [saving, setSaving] = React.useState(false);
const load = React.useCallback(async () => {
setLoading(true);
try {
const [s, t] = await Promise.all([api.schedules(), api.tasks()]);
setItems(s);
setTasks(t.tasks);
} catch (e) {
toast.error((e as Error).message);
} finally {
setLoading(false);
}
}, []);
React.useEffect(() => {
void load();
}, [load]);
const save = async (value: ScheduleInput) => {
if (
!value.name.trim() ||
!value.start_time ||
(value.schedule_type === "once" ? !value.run_date : !value.weekdays?.length)
) {
toast.error("请补全计划名称、日期/星期和开始时间");
return;
}
setSaving(true);
try {
if (editing?.id) await api.updateSchedule(editing.id, value);
else await api.createSchedule(value);
toast.success("计划已保存");
setEditing(null);
await load();
} catch (e) {
toast.error((e as Error).message);
} finally {
setSaving(false);
}
};
const remove = async (id: number) => {
if (!window.confirm("确定删除这个计划吗?")) return;
try {
await api.deleteSchedule(id);
await load();
} catch (e) {
toast.error((e as Error).message);
}
};
const action = async (id: number, type: "pause" | "resume" | "run") => {
try {
if (type === "pause") await api.pauseSchedule(id);
else if (type === "resume") await api.resumeSchedule(id);
else await api.runScheduleNow(id);
await load();
} catch (e) {
toast.error((e as Error).message);
}
};
let scheduleContent: React.ReactNode;
if (loading) {
scheduleContent = (
<div className="flex items-center gap-2 text-muted-foreground">
<Loader2 className="animate-spin" />
加载计划中…
</div>
);
} else if (items.length === 0) {
scheduleContent = (
<Card>
<CardContent className="py-10 text-center text-muted-foreground">
暂无计划任务,点击“新建计划”开始。
</CardContent>
</Card>
);
} else {
scheduleContent = (
<div className="grid gap-4 md:grid-cols-2">
{items.map((item) => (
<Card key={item.id}>
<CardHeader>
<div className="flex items-start justify-between gap-3">
<div>
<CardTitle className="text-base">{item.name}</CardTitle>
<CardDescription>
{item.schedule_type === "once"
? item.run_date
: (item.weekdays ?? []).map((d) => weekdays[d - 1]).join("、")}
</CardDescription>
</div>
<Badge variant={statusVariant(item.status)}>{statusText(item)}</Badge>
</div>
</CardHeader>
<CardContent className="grid gap-3 text-sm">
<div className="text-muted-foreground">
{item.start_time.slice(0, 5)}
{item.end_time ? ` - ${item.end_time.slice(0, 5)}` : " 起持续运行"} ·{" "}
{item.timezone_mode === "beijing" ? "北京时间" : item.timezone}
</div>
<div>绑定任务:{item.task_ids.length ? item.task_ids.map((id) => `#${id}`).join("、") : "无"}</div>
<div className="text-muted-foreground text-xs">
最近变化:{formatTime(item.last_transition_at)}
{item.last_error ? ` · ${item.last_error}` : ""}
</div>
<div className="flex flex-wrap gap-2">
<Button
size="sm"
variant="outline"
onClick={() =>
setEditing({
id: item.id,
value: {
name: item.name,
enabled: item.enabled,
timezone_mode: item.timezone_mode,
schedule_type: item.schedule_type,
run_date: item.run_date,
weekdays: item.weekdays,
start_time: item.start_time.slice(0, 5),
end_time: item.end_time?.slice(0, 5),
start_immediately: item.start_immediately,
task_ids: item.task_ids,
},
})
}
>
编辑
</Button>
{item.enabled ? (
<Button size="sm" variant="outline" onClick={() => void action(item.id, "pause")}>
<Pause data-icon="inline-start" />
暂停
</Button>
) : (
<Button size="sm" variant="outline" onClick={() => void action(item.id, "resume")}>
<Play data-icon="inline-start" />
启用
</Button>
)}
<Button size="sm" variant="outline" onClick={() => void action(item.id, "run")}>
<Zap data-icon="inline-start" />
立即运行
</Button>
<Button size="sm" variant="ghost" onClick={() => void remove(item.id)}>
<Trash2 data-icon="inline-start" />
删除
</Button>
</div>
</CardContent>
</Card>
))}
</div>
);
}
return (
<div className="flex flex-1 flex-col gap-5 p-5">
<div className="flex items-center justify-between">
<div>
<h1 className="flex items-center gap-2 font-semibold text-xl">
<CalendarClock />
计划任务
</h1>
<p className="mt-1 text-muted-foreground text-sm">按北京时间或系统时区控制扫描任务的开始、暂停和恢复。</p>
</div>
<Button onClick={() => setEditing({ value: { ...blank, task_ids: [] } })}>
<Plus data-icon="inline-start" />
新建计划
</Button>
</div>
{editing && (
<Card>
<CardHeader>
<CardTitle>{editing.id ? "编辑计划" : "新建计划"}</CardTitle>
<CardDescription>计划结束时会暂停任务,下一次有效窗口自动继续。</CardDescription>
</CardHeader>
<CardContent>
<ScheduleForm
value={editing.value}
tasks={tasks}
saving={saving}
onCancel={() => setEditing(null)}
onSave={save}
/>
</CardContent>
</Card>
)}
{scheduleContent}
</div>
);
}
+129 -1
View File
@@ -117,8 +117,9 @@ import { Switch } from "@/components/ui/switch";
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { Textarea } from "@/components/ui/textarea";
import { TimeSelect } from "@/components/time-select";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
import { api } from "@/lib/api";
import { api, type ScheduleInput } from "@/lib/api";
import { getLocalStorageValue, setLocalStorageValue } from "@/lib/local-storage.client";
import { type SortDirection, useStoredSortPreference } from "@/lib/sort-preference";
import type {
@@ -3096,6 +3097,17 @@ function CreateTaskSheet({
const [seedFirstIntent, setSeedFirstIntent] = React.useState(false); // 创建时下发种子意图,worker 免等首轮 planner 直接开跑;默认关闭,走标准先规划再执行
const [coverageEnabled, setCoverageEnabled] = React.useState(true); // 资产覆盖度功能;默认开。关闭=不计算/展示覆盖度、不累积范围、隐藏范围类工具(company 关联不受影响)
const [interceptRules, setInterceptRules] = React.useState<AssetInterceptRuleInput[]>([]); // 任务级资产拦截规则(仅本任务生效,不进全局表)
const [scheduleEnabled, setScheduleEnabled] = React.useState(false);
const [schedule, setSchedule] = React.useState<ScheduleInput>({
name: "新建任务计划",
schedule_type: "weekly",
weekdays: [6, 7],
start_time: "18:00",
end_time: "",
task_ids: [],
timezone_mode: "beijing",
start_immediately: false,
});
// 方式1 文件上传:建任务前把文件暂存到 drafts/<draftId>/uploads/,拿回绝对路径追加进描述。
const [uploading, setUploading] = React.useState(false);
const [uploadCount, setUploadCount] = React.useState(0);
@@ -3162,6 +3174,7 @@ function CreateTaskSheet({
seedFirstIntent,
planHeartbeatSeconds: heartbeatSec,
coverageEnabled,
schedule: scheduleEnabled ? { ...schedule, task_ids: [] } : undefined,
interceptRules: interceptRules
.map((r) => ({ ...r, pattern: r.pattern.trim() }))
.filter((r) => r.pattern !== ""),
@@ -3180,6 +3193,17 @@ function CreateTaskSheet({
setSeedFirstIntent(false);
setCoverageEnabled(true);
setInterceptRules([]);
setScheduleEnabled(false);
setSchedule({
name: "新建任务计划",
schedule_type: "weekly",
weekdays: [6, 7],
start_time: "18:00",
end_time: "",
task_ids: [],
timezone_mode: "beijing",
start_immediately: false,
});
setUploadCount(0);
draftIdRef.current = "";
setOpen(false);
@@ -3248,6 +3272,110 @@ function CreateTaskSheet({
/>
<FieldDescription>可选,单个分类;用于任务列表筛选和归档,不影响 Agent 执行。</FieldDescription>
</Field>
<FieldSet>
<FieldLegend>计划启动(可选)</FieldLegend>
<label className="flex items-center gap-2 text-sm">
<Checkbox checked={scheduleEnabled} onCheckedChange={(v) => setScheduleEnabled(!!v)} />
创建时附加计划,按时间窗口启动和暂停
</label>
{scheduleEnabled && (
<FieldGroup className="rounded-lg border p-3">
<Field>
<FieldLabel>计划名称</FieldLabel>
<Input value={schedule.name} onChange={(e) => setSchedule({ ...schedule, name: e.target.value })} />
</Field>
<div className="grid grid-cols-2 gap-3">
<Field>
<FieldLabel>规则</FieldLabel>
<Select
value={schedule.schedule_type}
onValueChange={(value) =>
setSchedule({ ...schedule, schedule_type: value as ScheduleInput["schedule_type"] })
}
>
<SelectTrigger className="h-10 w-full bg-background">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="weekly">按周</SelectItem>
<SelectItem value="once">指定日期</SelectItem>
</SelectContent>
</Select>
</Field>
<Field>
<FieldLabel>时区</FieldLabel>
<Select
value={schedule.timezone_mode}
onValueChange={(value) =>
setSchedule({ ...schedule, timezone_mode: value as ScheduleInput["timezone_mode"] })
}
>
<SelectTrigger className="h-10 w-full bg-background">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="beijing">北京时间</SelectItem>
<SelectItem value="system">系统时区</SelectItem>
</SelectContent>
</Select>
</Field>
</div>
{schedule.schedule_type === "once" ? (
<Field>
<FieldLabel>执行日期</FieldLabel>
<Input
type="date"
value={schedule.run_date ?? ""}
onChange={(e) => setSchedule({ ...schedule, run_date: e.target.value })}
/>
</Field>
) : (
<Field>
<FieldLabel>星期(1=周一,7=周日)</FieldLabel>
<Input
value={(schedule.weekdays ?? []).join(",")}
onChange={(e) =>
setSchedule({
...schedule,
weekdays: e.target.value
.split(",")
.map(Number)
.filter((n) => n >= 1 && n <= 7),
})
}
placeholder="例如 6,7"
/>
</Field>
)}
<div className="grid grid-cols-2 gap-3">
<Field>
<FieldLabel>开始时间</FieldLabel>
<TimeSelect
value={schedule.start_time}
onValueChange={(value) => setSchedule({ ...schedule, start_time: value })}
aria-label="开始时间"
/>
</Field>
<Field>
<FieldLabel>结束时间(可选)</FieldLabel>
<TimeSelect
value={schedule.end_time ?? ""}
onValueChange={(value) => setSchedule({ ...schedule, end_time: value })}
optional
aria-label="结束时间,可选"
/>
</Field>
</div>
<label className="flex items-center gap-2 text-sm">
<Checkbox
checked={schedule.start_immediately}
onCheckedChange={(v) => setSchedule({ ...schedule, start_immediately: !!v })}
/>
创建后立即启动,否则等待第一个计划窗口
</label>
</FieldGroup>
)}
</FieldSet>
<div className="grid gap-2">
<Label htmlFor="description">描述</Label>
<Textarea
+143
View File
@@ -0,0 +1,143 @@
"use client";
import * as React from "react";
import { X } from "lucide-react";
import { Button } from "@/components/ui/button";
import { Combobox, ComboboxContent, ComboboxInput, ComboboxItem, ComboboxList } from "@/components/ui/combobox";
const hours = Array.from({ length: 24 }, (_, index) => index.toString().padStart(2, "0"));
const minutes = Array.from({ length: 60 }, (_, index) => index.toString().padStart(2, "0"));
function splitTime(value?: string) {
const match = value?.slice(0, 5).match(/^(\d{2}):(\d{2})$/);
return match ? { hour: match[1], minute: match[2] } : { hour: undefined, minute: undefined };
}
function TimePart({
value,
items,
max,
placeholder,
ariaLabel,
onValueChange,
}: {
value?: string;
items: string[];
max: number;
placeholder: string;
ariaLabel: string;
onValueChange: (value: string) => void;
}) {
const [inputValue, setInputValue] = React.useState(value ?? "");
React.useEffect(() => setInputValue(value ?? ""), [value]);
const commit = (raw: string) => {
const digits = raw.replace(/\D/g, "").slice(0, 2);
if (!digits) {
setInputValue("");
return;
}
const number = Number(digits);
if (number > max) {
setInputValue(value ?? "");
return;
}
const next = digits.padStart(2, "0");
setInputValue(next);
onValueChange(next);
};
return (
<Combobox
items={items}
itemToStringLabel={(item) => item}
itemToStringValue={(item) => item}
value={value ?? null}
inputValue={inputValue}
onInputValueChange={(next) => setInputValue(next.replace(/\D/g, "").slice(0, 2))}
onValueChange={(next) => {
if (typeof next === "string") {
setInputValue(next);
onValueChange(next);
}
}}
>
<ComboboxInput
className="h-10 min-w-0"
placeholder={placeholder}
aria-label={ariaLabel}
inputMode="numeric"
maxLength={2}
onBlur={() => commit(inputValue)}
onKeyDown={(event) => {
if (event.key === "Enter") commit(inputValue);
}}
/>
<ComboboxContent className="max-h-64" sideOffset={4}>
<ComboboxList>
{(item) => (
<ComboboxItem key={item} value={item}>
{item}
</ComboboxItem>
)}
</ComboboxList>
</ComboboxContent>
</Combobox>
);
}
export function TimeSelect({
value,
onValueChange,
optional = false,
placeholder = "选择时间",
"aria-label": ariaLabel,
}: {
value?: string;
onValueChange: (value: string) => void;
optional?: boolean;
placeholder?: string;
"aria-label"?: string;
}) {
const selected = splitTime(value);
const hasValue = Boolean(selected.hour && selected.minute);
const updateHour = (hour: string) => onValueChange(`${hour}:${selected.minute ?? "00"}`);
const updateMinute = (minute: string) => onValueChange(`${selected.hour ?? "00"}:${minute}`);
return (
<div className="flex min-w-0 items-center gap-1" title={optional && !hasValue ? placeholder : undefined}>
<TimePart
value={selected.hour}
items={hours}
max={23}
placeholder="小时"
ariaLabel={ariaLabel ? `${ariaLabel} 小时` : "小时"}
onValueChange={updateHour}
/>
<span className="font-medium text-muted-foreground">:</span>
<TimePart
value={selected.minute}
items={minutes}
max={59}
placeholder="分钟"
ariaLabel={ariaLabel ? `${ariaLabel} 分钟` : "分钟"}
onValueChange={updateMinute}
/>
{optional && hasValue && (
<Button
type="button"
variant="ghost"
size="icon-sm"
className="shrink-0"
onClick={() => onValueChange("")}
aria-label="清除结束时间"
title="不设置结束时间"
>
<X />
</Button>
)}
</div>
);
}
+39
View File
@@ -84,6 +84,7 @@ import type {
SSTask,
Stats,
Task,
TaskSchedule,
TaskArchive,
TaskArchivePage,
TaskAssetMutation,
@@ -245,6 +246,34 @@ function interceptPageQuery(page: number, size: number, filter: InterceptApprova
return query.toString();
}
export type ScheduleInput = {
name: string;
enabled?: boolean;
timezone_mode?: "beijing" | "system";
schedule_type: "once" | "weekly";
run_date?: string;
weekdays?: number[];
start_time: string;
end_time?: string;
start_immediately?: boolean;
task_ids: number[];
};
function schedulePayload(input: ScheduleInput) {
return {
name: input.name,
enabled: input.enabled ?? true,
timezone_mode: input.timezone_mode ?? "beijing",
schedule_type: input.schedule_type,
run_date: input.run_date ?? "",
weekdays: input.weekdays ?? [],
start_time: input.start_time,
end_time: input.end_time ?? "",
start_immediately: input.start_immediately ?? false,
task_ids: input.task_ids,
};
}
export const api = {
// 后端应用版本号(release 时由 ldflags 注入,默认 "dev")。
health: () => get<{ ok: boolean; service: string; version: string }>("/health"),
@@ -273,6 +302,7 @@ export const api = {
planHeartbeatSeconds?: number;
coverageEnabled?: boolean;
interceptRules?: AssetInterceptRuleInput[];
schedule?: ScheduleInput;
}) =>
post<Task>("/tasks", {
name: input.name ?? "",
@@ -287,7 +317,16 @@ export const api = {
plan_heartbeat_seconds: input.planHeartbeatSeconds ?? 0, // 0 = 后端归一到默认 600(10min)
coverage_enabled: input.coverageEnabled ?? true, // 默认开;false=关闭资产覆盖度功能
intercept_rules: input.interceptRules ?? [], // 任务级资产拦截规则
schedule: input.schedule ? schedulePayload(input.schedule) : undefined,
}),
schedules: () => get<{ schedules: TaskSchedule[] }>("/schedules").then((r) => arr(r.schedules)),
schedule: (id: number) => get<TaskSchedule>(`/schedules/${id}`),
createSchedule: (input: ScheduleInput) => post<TaskSchedule>("/schedules", schedulePayload(input)),
updateSchedule: (id: number, input: ScheduleInput) => patch<TaskSchedule>(`/schedules/${id}`, schedulePayload(input)),
deleteSchedule: (id: number) => del<{ ok: boolean }>(`/schedules/${id}`),
pauseSchedule: (id: number) => post<{ ok: boolean }>(`/schedules/${id}/pause`, {}),
resumeSchedule: (id: number) => post<{ ok: boolean }>(`/schedules/${id}/resume`, {}),
runScheduleNow: (id: number) => post<{ ok: boolean }>(`/schedules/${id}/run-now`, {}),
taskCategories: () => get<{ categories: TaskCategory[] }>("/task-categories").then((r) => arr(r.categories)),
updateTask: (id: string, input: { name?: string; pinned?: boolean }) => patch<Task>(`/tasks/${id}`, input),
renameTask: (id: string, name: string) => patch<Task>(`/tasks/${id}`, { name }),
+29
View File
@@ -715,6 +715,35 @@ export interface AgentTrigger {
last_fire?: string;
}
export interface TaskSchedule {
id: number;
name: string;
enabled: boolean;
timezone_mode: "beijing" | "system";
timezone?: string;
schedule_type: "once" | "weekly";
run_date?: string;
weekdays: number[];
start_time: string;
end_time?: string;
start_immediately: boolean;
status: "waiting" | "running" | "outside" | "completed" | "error" | "paused";
last_window_key?: string;
last_transition_at?: string;
last_error?: string;
next_start?: string;
next_end?: string;
task_ids: number[];
history?: Array<{
id: number;
task_id?: number;
action: string;
success: boolean;
message: string;
created_at: string;
}>;
}
// ---- Conversations (chat page) ----
export interface ActiveFindingRetest {
id: number;
@@ -2,6 +2,7 @@ import {
Activity,
Ban,
BellRing,
CalendarClock,
Bot,
Brain,
Bug,
@@ -69,6 +70,7 @@ export const sidebarItems: NavGroup[] = [
{ id: "dashboard", title: "仪表盘", url: "/dashboard", icon: LayoutDashboard },
{ id: "chat", title: "对话", url: "/chat", icon: MessageSquare },
{ id: "tasks", title: "任务", url: "/function/tasks", icon: Target },
{ id: "schedules", title: "计划任务", url: "/function/schedules", icon: CalendarClock },
{ id: "findings", title: "发现", url: "/function/findings", icon: Bug },
{ id: "traffic", title: "流量", url: "/function/traffic", icon: Activity },
{ id: "commands", title: "工具执行", url: "/function/commands", icon: Terminal },