import { SmrtCollection, SmrtObject } from '@happyvertical/smrt-core'; /** * Status of a scheduled agent */ export type ScheduleStatus = 'active' | 'paused' | 'disabled' | 'error'; /** * AgentSchedule model for cron-based agent scheduling * * This extends SmrtObject to store schedule metadata in the SMRT database. * Schedules are processed by the TaskRunner which creates jobs at scheduled times. * * @example * ```typescript * const schedule = new AgentSchedule({ * agentType: 'Praeco', * agentId: 'praeco-main', * cron: '0 2 * * *', // Run at 2 AM daily * enabled: true, * }); * await schedule.initialize(); * await schedule.save(); * ``` */ export declare class AgentSchedule extends SmrtObject { /** * Tenant ID for multi-tenant isolation * Nullable to support both tenant-scoped and global schedules */ tenantId: string | null; /** Canonical agent type to run (qualified name when available) */ agentType: string; /** Optional agent instance ID (for running specific instances) */ agentId: string | null; /** * Agent configuration to pass when running. * * Sensitive (#1540): may carry API keys/credentials, so it is excluded from * generated API/MCP responses and rejected as a `where` filter key. */ agentConfig: Record; /** Cron expression (e.g., '0 2 * * *' for 2 AM daily) */ cron: string; /** Timezone for cron interpretation (default: UTC) */ timezone: string; /** Whether the schedule is enabled */ enabled: boolean; /** Current schedule status */ status: ScheduleStatus; /** Last time the agent was run */ lastRun: Date | null; /** Next scheduled run time */ nextRun: Date | null; /** Status of the last run */ lastStatus: 'success' | 'failed' | null; /** Error message from last failed run */ lastError: string | null; /** Total number of runs */ runCount: number; /** Total number of successful runs */ successCount: number; /** Total number of failed runs */ failureCount: number; /** Maximum concurrent runs (prevent overlapping) */ maxConcurrent: number; /** Current number of running instances */ runningCount: number; /** Timeout for agent execution in milliseconds (default: 1 hour) */ timeout: number; /** Method to call on the agent (default: 'run') */ method: string; /** Arguments to pass to the method */ methodArgs: Record; /** * Enable the schedule */ enable(): Promise; /** * Disable the schedule */ disable(): Promise; /** * Pause the schedule temporarily */ pause(): Promise; /** * Resume a paused schedule */ resume(): Promise; /** * Calculate the next run time based on cron expression */ calculateNextRun(): void; /** * Get a human-readable description of the schedule */ getDescription(): string; /** * Lifecycle hook - calculate next run on save */ beforeSave(): Promise; } /** * Collection for managing AgentSchedule objects */ export declare class AgentScheduleCollection extends SmrtCollection { static readonly _itemClass: typeof AgentSchedule; /** * Find all schedules for a specific tenant * @param tenantId - Tenant ID to filter by * @returns Array of AgentSchedule objects for the tenant */ findByTenant(tenantId: string): Promise; /** * Find all global schedules (not associated with any tenant). * * Routes through the shared tenant-global helper so it does not throw under * an active tenant context (an explicit `tenant_id IS NULL` filter would be * flagged as an isolation violation). (#1600) * * @returns Array of global AgentSchedule objects */ findGlobal(): Promise; /** * Find schedules for a tenant including global schedules. * * Fails closed if an active tenant context requests a different tenant's * rows; the admin/system path keeps the cross-tenant capability. (#1600) * * @param tenantId - Tenant ID to include * @returns Array of AgentSchedule objects for the tenant and global schedules */ findWithGlobals(tenantId: string): Promise; /** * List schedules by status */ listByStatus(status: ScheduleStatus | ScheduleStatus[], options?: { limit?: number; }): Promise; /** * List schedules for a specific agent type */ listByAgentType(agentType: string, options?: { limit?: number; includeDisabled?: boolean; }): Promise; } /** * Parse a cron expression and get the next run date. * * Supports standard 5-field cron format: minute hour day-of-month month * day-of-week. Day-of-month / day-of-week follow POSIX OR semantics when both * are restricted (see the loop body). Matched against the host's local time * (not timezone-aware). * * Examples: * - '0 2 * * *' - 2:00 AM daily * - '0 0 * * 0' - Midnight on Sundays * - 'x/15 * * * *' - Every 15 minutes (where x is asterisk) * - '0 9 1 * *' - 9:00 AM on the 1st of every month * * Exported for unit testing of the matching logic. */ export declare function getNextCronDate(cron: string, _timezone?: string): Date; export default AgentSchedule; //# sourceMappingURL=schedule.d.ts.map