@smythos/sdk
Version:
274 lines (273 loc) • 9.59 kB
TypeScript
import { AccessCandidate, IScheduledJob, ISchedulerRequest, IJobMetadata, Job, Schedule } from '@smythos/sre';
import { SDKObject } from '../Core/SDKObject.class';
import { TSchedulerProvider } from '../types/generated/Scheduler.types';
import { Agent } from '../Agent/Agent.class';
/**
* Builder class for creating scheduled jobs with chainable syntax.
* Requires calling `.every()` or `.cron()` to actually schedule the job.
* After scheduling, provides methods to pause, resume, or delete the job.
*
* @internal
*/
declare class SchedulerJobCommand {
private _schedulerRequest;
private _jobId;
private _jobConfig;
private _scheduled;
private job;
private _scheduledJob;
constructor(schedulerRequest: ISchedulerRequest, jobId: string, jobConfig: any);
/**
* Complete the job scheduling with an interval.
* Returns the builder to allow job control operations.
*
* @param interval - Time interval (e.g., '5s', '10m', '1h', '1d')
* @returns The builder instance with pause, resume, and delete methods
*
* @example
* ```typescript
* const job = await scheduler.call('skill-name', args).every('5s');
* // Later, you can pause, resume, or delete the job
* await job.pause();
* await job.resume();
* await job.delete();
* ```
*/
every(interval: string): Promise<void>;
/**
* Complete the job scheduling with a cron expression.
*
* @param cronExpression - Cron expression (e.g., '0 0 * * *' for daily at midnight)
* @returns The builder instance with pause, resume, and delete methods
*
* @example
* ```typescript
* const job = await scheduler.call('backup', {}).cron('0 0 * * *');
* await job.pause();
* ```
*/
/**
* Pause the scheduled job.
*
* @returns Promise that resolves when the job is paused
*
* @example
* ```typescript
* const job = await scheduler.call('backup', {}).every('1h');
* await job.pause();
* ```
*/
pause(): Promise<void>;
/**
* Resume a paused job.
*
* @returns Promise that resolves when the job is resumed
*
* @example
* ```typescript
* const job = await scheduler.call('backup', {}).every('1h');
* await job.pause();
* // Later...
* await job.resume();
* ```
*/
resume(): Promise<void>;
/**
* Delete the scheduled job permanently.
*
* @returns Promise that resolves when the job is deleted
*
* @example
* ```typescript
* const job = await scheduler.call('backup', {}).every('1h');
* // Later, when no longer needed...
* await job.delete();
* ```
*/
delete(): Promise<void>;
/**
* Override the then() method to detect when the builder is awaited without calling .every() or .cron().
* This makes the builder thenable, but will warn if scheduling is not completed properly.
*/
then<TResult1 = void, TResult2 = never>(onfulfilled?: ((value: void) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
}
/**
* SDK wrapper for Scheduler operations.
* Provides a simplified interface for scheduling and managing jobs.
*
* @example
* ```typescript
* const scheduler = new SchedulerInstance('LocalScheduler', {}, AccessCandidate.agent('my-agent'));
*
* await scheduler.add('cleanup', Schedule.every('1h'), new Job(
* async () => console.log('Cleanup'),
* { name: 'Cleanup Job' }
* ));
* ```
*/
export declare class SchedulerInstance extends SDKObject {
private _candidate;
private _agent;
private _schedulerRequest;
private _teamId;
constructor(providerId?: TSchedulerProvider, schedulerSettings?: any, candidate?: AccessCandidate | Agent);
on(event: string, listener: (...args: any[]) => void): this;
off(event: string, listener: (...args: any[]) => void): this;
/**
* Add or update a scheduled job.
* If a job with the same ID exists, it will be updated.
*
* @param jobId - Unique identifier for the job
* @param schedule - Schedule definition (interval or cron)
* @param job - Job instance with execution function and metadata
* @returns Promise that resolves when the job is scheduled
*
* @example
* ```typescript
* await scheduler.add('backup',
* Schedule.every('6h'),
* new Job(async () => {
* console.log('Running backup...');
* }, {
* name: 'Backup Job',
* retryOnFailure: true
* })
* );
* ```
*/
add(jobId: string, job: Job, schedule: Schedule): Promise<boolean>;
/**
* List all scheduled jobs for this candidate.
*
* @returns Promise that resolves to an array of scheduled jobs
*
* @example
* ```typescript
* const jobs = await scheduler.list();
* jobs.forEach(job => {
* console.log(`${job.metadata.name}: ${job.status}`);
* });
* ```
*/
list(): Promise<IScheduledJob[]>;
/**
* Get details of a specific scheduled job.
*
* @param jobId - Unique identifier of the job
* @returns Promise that resolves to the job details, or undefined if not found
*
* @example
* ```typescript
* const job = await scheduler.get('backup');
* if (job) {
* console.log(`Status: ${job.status}`);
* console.log(`Next run: ${job.nextRun}`);
* }
* ```
*/
get(jobId: string): Promise<IScheduledJob | undefined>;
/**
* Pause a scheduled job.
* The job will not execute until resumed.
*
* @param jobId - Unique identifier of the job to pause
* @returns Promise that resolves when the job is paused
*
* @example
* ```typescript
* await scheduler.pause('backup');
* console.log('Backup job paused');
* ```
*/
pause(jobId: string): Promise<void>;
/**
* Resume a paused job.
* The job will start executing according to its schedule.
*
* @param jobId - Unique identifier of the job to resume
* @returns Promise that resolves when the job is resumed
*
* @example
* ```typescript
* await scheduler.resume('backup');
* console.log('Backup job resumed');
* ```
*/
resume(jobId: string): Promise<void>;
/**
* Delete a scheduled job.
* This removes the job permanently and stops all scheduled executions.
*
* @param jobId - Unique identifier of the job to delete
* @returns Promise that resolves when the job is deleted
*
* @example
* ```typescript
* await scheduler.delete('backup');
* console.log('Backup job deleted');
* ```
*/
delete(jobId: string): Promise<void>;
/**
* Schedule an agent skill execution with chainable syntax.
* Requires an agent to be associated with this scheduler instance.
*
* @param skillName - Name of the skill to execute
* @param args - Arguments to pass to the skill
* @param metadata - Optional job metadata (name, description, retryOnFailure, etc.)
* @returns SchedulerJobBuilder that can be chained with .every() or .cron()
*
* @throws Error if no agent is associated with this scheduler
*
* @example
* ```typescript
* // Schedule a skill to run every 5 seconds
* await scheduler.call('processData', { input: 'test' }, { name: 'Data Processor' }).every('5s');
*
* // Schedule with cron expression
* await scheduler.call('backup', {}, { retryOnFailure: true }).cron('0 0 * * *');
* ```
*/
call(skillName: string, args?: Record<string, any> | any[], metadata?: IJobMetadata): SchedulerJobCommand;
/**
* Schedule an agent prompt execution with chainable syntax.
* Requires an agent to be associated with this scheduler instance.
*
* @param prompt - The prompt text to send to the agent
* @param metadata - Optional job metadata (name, description, retryOnFailure, etc.)
* @returns SchedulerJobBuilder that can be chained with .every() or .cron()
*
* @throws Error if no agent is associated with this scheduler
*
* @example
* ```typescript
* // Schedule a prompt to run every hour
* await scheduler.prompt('Generate daily report', { name: 'Daily Report' }).every('1h');
*
* // Schedule with cron expression
* await scheduler.prompt('Summarize news', { name: 'News Summary' }).cron('0 9 * * *');
* ```
*/
prompt(prompt: string, metadata?: IJobMetadata): SchedulerJobCommand;
/**
* Schedule an agent trigger execution with chainable syntax.
* Requires an agent to be associated with this scheduler instance.
*
* @param triggerName - Name of the trigger to execute
* @param metadata - Optional job metadata (name, description, retryOnFailure, etc.)
* @returns SchedulerJobBuilder that can be chained with .every() or .cron()
*
* @throws Error if no agent is associated with this scheduler
*
* @example
* ```typescript
* // Schedule a trigger to run every day
* await scheduler.trigger('daily-sync', { name: 'Daily Sync' }).every('1d');
*
* // Schedule with cron expression
* await scheduler.trigger('weekly-report', { name: 'Weekly Report' }).cron('0 0 * * 0');
* ```
*/
trigger(triggerName: string, metadata?: IJobMetadata): SchedulerJobCommand;
}
export {};