import { Condition, DeadLetterEntry, ExecutionCheckpoint, Plan, PlanExecution, PlanStore, PlanTemplate, ValueRef } from "./plan-types.mjs"; //#region extensions/crypto/src/services/plan-scheduler.d.ts type SchedulerEvent = { type: 'trigger_fired'; plan: Plan; executionId: string; } | { type: 'plan_expired'; plan: Plan; reason: string; } | { type: 'condition_check_error'; planId: string; error: string; } | { type: 'plan_added'; plan: Plan; } | { type: 'plan_cancelled'; planId: string; }; type SchedulerEventHandler = (event: SchedulerEvent) => void | Promise; interface RuntimeResolver { price(token: string): Promise; balance(token: string, chainId?: number): Promise; gasPrice(chainId?: number): Promise; timestamp(): number; blockNumber(chainId?: number): Promise; } /** Default no-op resolver for testing. */ declare const NULL_RESOLVER: RuntimeResolver; /** Shape of the scheduler runtime state that survives restarts. */ interface SchedulerState { intervalRunCounts: Record; lastConditionCheck: Record; /** Cron: number of times each cron plan has fired. */ cronRunCounts?: Record; /** Cron: timestamp (floored to minute) of the last fire for each plan. */ lastCronFire?: Record; } declare class FilePlanStore implements PlanStore { private dir; constructor(dir?: string); save(plan: Plan): void; load(planId: string): Plan | null; loadAll(userId?: string): Plan[]; delete(planId: string): boolean; saveExecution(exec: PlanExecution): void; loadExecutions(planId: string): PlanExecution[]; /** Persist scheduler runtime state (interval counts, last check times). */ saveState(state: SchedulerState): void; /** Restore scheduler runtime state. Returns null if no state file. */ loadState(): SchedulerState | null; private get templatesDir(); saveTemplate(template: PlanTemplate): void; loadTemplate(templateId: string): PlanTemplate | null; listTemplates(userId?: string): PlanTemplate[]; deleteTemplate(templateId: string): boolean; private get deadLetterDir(); saveDeadLetter(entry: DeadLetterEntry): void; loadDeadLetters(planId?: string): DeadLetterEntry[]; clearDeadLetters(planId?: string): number; private get checkpointsDir(); saveCheckpoint(cp: ExecutionCheckpoint): void; loadCheckpoint(executionId: string): ExecutionCheckpoint | null; loadAllCheckpoints(): ExecutionCheckpoint[]; deleteCheckpoint(executionId: string): boolean; private ensureDir; } declare class PlanScheduler { private store; private resolver; private handlers; private tickInterval; private plans; private lastConditionCheck; private intervalRunCounts; private cronRunCounts; private lastCronFire; private tickMs; private running; private stateDirty; private stateFlushTimer; constructor(opts?: { store?: PlanStore; resolver?: RuntimeResolver; tickMs?: number; }); /** Register an event handler. Returns unsubscribe function. */ on(handler: SchedulerEventHandler): () => void; /** Load persisted plans and start the tick loop. */ start(): void; /** Stop the tick loop. Flush pending state. Plans remain persisted. */ stop(): void; /** Add or update a plan. Persists immediately. */ addPlan(plan: Plan): void; /** Cancel a plan. */ cancelPlan(planId: string): boolean; /** Pause a plan (stops trigger checking, can be resumed). */ pausePlan(planId: string): boolean; /** Resume a paused plan. */ resumePlan(planId: string): boolean; /** Get a plan by ID. */ getPlan(planId: string): Plan | null; /** List all plans for a user. */ listPlans(userId?: string): Plan[]; /** Get execution history for a plan. */ getExecutions(planId: string): PlanExecution[]; saveTemplate(template: PlanTemplate): void; loadTemplate(templateId: string): PlanTemplate | null; listTemplates(userId?: string): PlanTemplate[]; deleteTemplate(templateId: string): boolean; saveDeadLetter(entry: DeadLetterEntry): void; loadDeadLetters(planId?: string): DeadLetterEntry[]; clearDeadLetters(planId?: string): number; saveCheckpoint(cp: ExecutionCheckpoint): void; loadCheckpoint(executionId: string): ExecutionCheckpoint | null; loadAllCheckpoints(): ExecutionCheckpoint[]; deleteCheckpoint(executionId: string): boolean; /** Mark a plan execution as complete (called by executor). */ markCompleted(planId: string, execution: PlanExecution): void; /** Mark a plan execution as failed (called by executor). */ markFailed(planId: string, execution: PlanExecution): void; /** Restore intervalRunCounts and lastConditionCheck from disk. */ private restoreState; /** Mark state as dirty; it will be flushed within 5s or at next tick boundary. */ private persistState; /** Write state to disk immediately if dirty. */ private flushState; /** How many plans are actively being watched. */ get activeCount(): number; /** Get all active in-memory plans. */ getActivePlans(): Plan[]; /** Is the scheduler running. */ get isRunning(): boolean; private ticking; private tick; private shouldTriggerFire; private fireTrigger; private evaluateCronTrigger; firePriceTrigger(planId: string): Promise; fireOnChainTrigger(planId: string): Promise; fireBalanceTrigger(planId: string): Promise; evaluateCondition(cond: Condition): Promise; resolveValue(ref: ValueRef): Promise; private resolveRuntimeFn; private compare; private emit; } /** Check if a date matches a 5-field cron expression. */ declare function matchesCron(expression: string, date: Date): boolean; declare function getScheduler(opts?: ConstructorParameters[0]): PlanScheduler; declare function resetScheduler(): void; //#endregion export { FilePlanStore, NULL_RESOLVER, PlanScheduler, RuntimeResolver, SchedulerEvent, SchedulerEventHandler, getScheduler, matchesCron, resetScheduler }; //# sourceMappingURL=plan-scheduler.d.mts.map