@mastra/core
Version:
72 lines • 3.01 kB
TypeScript
import type { Mastra } from '../mastra/index.js';
import type { ScheduleTarget } from '../storage/domains/schedules/base.js';
import { MastraWorker } from '../worker/worker.js';
import type { WorkerDeps } from '../worker/worker.js';
import type { ScheduleRunStatus } from './types.js';
/** PubSub topic on which the scheduler publishes `agent-schedule.fire` events. */
export declare const TOPIC_AGENT_SCHEDULES = "agent-schedules";
export interface AgentScheduleWorkerConfig {
group?: string;
}
export interface AgentScheduleFireEventData {
scheduleId: string;
claimId: string;
scheduledFireAt: number;
target: Extract<ScheduleTarget, {
type: 'agent';
}>;
/** Defaults to `'schedule-fire'`. `'manual'` for fire-now invocations. */
triggerKind?: 'schedule-fire' | 'manual';
}
/**
* Consumes `agent-schedule.fire` events published by the scheduler and runs
* the configured agent — either by `sendSignal` (threaded) or
* `agent.generate` (threadless). Mirrors `OrchestrationWorker`'s
* subscribe-on-start / unsubscribe-on-stop lifecycle.
*
* Records the schedule trigger after dispatching so the trigger row
* carries the agent's runId (not just the scheduler's claim id),
* letting the UI link triggers to real agent runs.
*/
export declare class AgentScheduleWorker extends MastraWorker {
#private;
readonly name = "agent-schedule";
constructor(config?: AgentScheduleWorkerConfig);
init(deps: WorkerDeps): Promise<void>;
start(): Promise<void>;
stop(): Promise<void>;
get isRunning(): boolean;
}
/** Outcome union written to the schedule trigger row for an agent-schedule fire. */
export type ScheduleTriggerOutcome = 'succeeded' | 'delivered' | 'persisted' | 'discarded' | 'skipped' | 'aborted' | 'failed';
type LooseLogger = {
error?: (message: string, ...args: any[]) => void;
debug?: (message: string, ...args: any[]) => void;
};
/** Optional context the `AgentScheduleWorker` passes to `executeAgentSchedule`. */
export interface ExecuteAgentScheduleContext {
triggerKind?: 'schedule-fire' | 'manual';
firedAt?: Date;
logger?: LooseLogger;
}
/**
* Resolves the agent, runs the user `prepare` hook (if any), applies
* idle filters, and either `sendSignal`s into the target
* thread or runs `agent.generate`. The returned `runId` is the agent
* run id from the SDK call (when a run was actually started), suitable
* for trigger-row linkability.
*
* `outcome` is the final outcome for the schedule trigger row and is
* also the one that drove the `onFinish`/`onError`/`onAbort` hook
* selection. `status` is retained for back-compat with existing tests.
*/
export declare function executeAgentSchedule(mastra: Mastra, scheduleId: string, target: Extract<ScheduleTarget, {
type: 'agent';
}>, ctx?: ExecuteAgentScheduleContext): Promise<{
status: ScheduleRunStatus;
outcome: ScheduleTriggerOutcome;
reason?: string;
runId?: string;
}>;
export {};
//# sourceMappingURL=worker.d.ts.map