UNPKG

@mastra/core

Version:
93 lines • 4.38 kB
/** * Boot-time sync between the schedules a file-based agent declares on disk * (`agents/<id>/schedules/`) and the rows in schedule storage. * * Kept out of `mastra/index.ts` because none of it needs Mastra's private * state: it is a function of the registered agent map, the schedules store, and * a logger. `Mastra` keeps only the wiring — when to run this, and where the * store comes from. */ import type { Agent } from '../agent/index.js'; import type { IMastraLogger } from '../logger/index.js'; import type { AgentScheduleDefinition, AgentScheduleHandler, DeclaredAgentSchedule } from '../schedules/define.js'; import type { Schedule, SchedulesStorage } from '../storage/domains/schedules/base.js'; /** * Mastra's registered agent map: registration key to agent. The key is not the * agent's `id` — schedules key off `agent.id`, because that is what the worker * resolves against at fire time. */ export type RegisteredAgents = Record<string, Agent<any>>; /** One declared schedule resolved to the storage row it owns. */ export interface ResolvedFsAgentSchedule { scheduleId: string; agentId: string; key: string; definition: AgentScheduleDefinition; } /** * Two agents registered under different keys can still share an `id`, which * would map their schedules onto one row. The collector keeps the first and * reports the rest here so the caller can log once, at sync time, rather than * on every lookup. */ export interface FsAgentScheduleCollection { schedules: ResolvedFsAgentSchedule[]; duplicates: Array<{ agentId: string; key: string; }>; } /** * Reads the file-based schedules declared on a registered agent. * * Wrappers around an inner `Agent` (durable execution) delegate this * explicitly — see `DurableAgent.getDeclaredSchedules` — so there is nothing to * unwrap here. The optional call covers registrable shapes that are not * `Agent`s at all (`ToolLoopAgentLike`). */ export declare function declaredSchedulesOf(agent: unknown): DeclaredAgentSchedule[]; /** True when any registered agent declares schedules on disk. */ export declare function hasFsAgentSchedule(agents: RegisteredAgents | undefined): boolean; /** * Collect every declared schedule across the registered agents, keyed by * `fsa_<encoded(agentId)>__<encoded(key)>` so the prefix uniquely identifies * "all rows owned by this agent's schedules/ directory" even when ids contain * delimiter-like characters. * * Pure: duplicates are returned rather than logged, so callers that run per * fire don't re-emit the same warning forever. */ export declare function collectFsAgentSchedules(agents: RegisteredAgents | undefined): FsAgentScheduleCollection; /** * Resolve the handler for a handler-mode file-based schedule. Handlers are * functions and therefore cannot be persisted on the JSON schedule row, so the * agent-schedule worker looks them up in-process by row id at fire time. * * The row id already encodes the agent and the key, so this decodes it and * reads that one agent rather than rebuilding the whole cross-agent collection * on every fire. When two agents share an id the first wins, matching * {@link collectFsAgentSchedules}. */ export declare function findFsAgentScheduleHandler<TMastra>(agents: RegisteredAgents | undefined, scheduleId: string): AgentScheduleHandler<TMastra> | undefined; export interface SyncFsAgentSchedulesOptions { agents: RegisteredAgents | undefined; store: SchedulesStorage; logger?: IMastraLogger; /** * Rows already read by the caller, reused for both the upsert diff and the * orphan sweep instead of a second `listSchedules()` pass. */ knownRows?: Schedule[]; } /** * Sync schedules declared by file-based agents' `schedules/` directories into * schedule storage. * * Mirrors the declarative workflow sync: upsert declared rows, diff the config * fields and patch what changed, leave `status` alone so an out-of-band pause * survives a redeploy, and delete orphaned `fsa_` rows that code no longer * declares. Rows created imperatively through `mastra.schedules.create(...)` * use the `agent_` prefix and are never touched here. */ export declare function syncFsAgentSchedules({ agents, store, logger, knownRows, }: SyncFsAgentSchedulesOptions): Promise<void>; //# sourceMappingURL=fs-agent-schedules.d.ts.map