/** * 定时调度器 * * 提供 cron 风格的定时任务管理,用于自动化内容运营: * - 每天定时采集热点 → AI 生成内容 → 多平台发布 * - 灵活配置执行时间和目标平台 * - 任务历史记录和失败重试 * * 使用方法: * import { Scheduler, createAgent } from "@jarvis/agent-core"; * * const agent = createAgent(config); * const scheduler = new Scheduler(agent); * * scheduler.addJob({ * id: "daily-xhs", * cron: "0 9 * * *", // 每天 9:00 * instruction: "帮我发一篇小红书关于AI的文章", * }); * * scheduler.start(); */ import { AgentCore } from "./agent.js"; import type { AgentTask } from "./types.js"; export interface ScheduledJob { id: string; /** cron 表达式(简易版:支持 HH:MM 或 cron 5 段) */ cron: string; /** 自然语言指令(传给 Agent.run()) */ instruction: string; /** 是否启用 */ enabled: boolean; /** 上次执行时间 */ lastRun?: Date; /** 上次执行结果 */ lastResult?: "success" | "failed"; /** 执行历史 */ history: JobExecution[]; } export interface JobExecution { timestamp: Date; taskId: string; status: "success" | "failed"; duration: number; error?: string; } export interface SchedulerConfig { /** 检查间隔(毫秒),默认 60000(1 分钟) */ checkInterval?: number; /** 最大历史记录数,默认 100 */ maxHistory?: number; /** 失败重试次数,默认 1 */ retryCount?: number; /** 重试间隔(毫秒),默认 300000(5 分钟) */ retryDelay?: number; } export declare class Scheduler { private agent; private jobs; private timer; private config; private running; constructor(agent: AgentCore, config?: SchedulerConfig); /** 添加定时任务 */ addJob(job: Omit & { enabled?: boolean; }): void; /** 移除任务 */ removeJob(id: string): boolean; /** 启用/禁用任务 */ toggleJob(id: string, enabled: boolean): void; /** 获取所有任务 */ getJobs(): ScheduledJob[]; /** 手动触发任务 */ triggerJob(id: string): Promise; /** 启动调度器 */ start(): void; /** 停止调度器 */ stop(): void; /** 检查并执行到期任务 */ private check; /** 执行单个任务 */ private executeJob; } //# sourceMappingURL=scheduler.d.ts.map