/** * Per-daemon task scheduler: one timer, one getTasks(agentIds) per tick, dispatch to registered runtimes. * * WHY: With N runtimes, N local timers would do N getTasks() every second. This module batches: one * getTasks(agentIds) for all dirty agents, then group by task.agentId and call runTick(tasks) per runtime. * Opt-in: host calls startTaskScheduler(adapter); TaskService registers when daemon is present. */ import type { IDatabaseAdapter } from "../types/database.js"; import type { UUID } from "../types/primitives.js"; import type { IAgentRuntime } from "../types/runtime.js"; import type { Task } from "../types/task.js"; /** Minimal type so we don't import TaskService. WHY: avoids circular dependency (task.ts imports this module). */ interface TaskServiceLike { runTick(tasks: Task[]): Promise; } /** Register host-owned work on the existing process timer. The disposer drains its active run. */ export declare function registerScheduledProcessTask(name: string, run: (signal: AbortSignal) => Promise): () => Promise; /** WHY: host provides the adapter so the scheduler can call getTasks without going through a specific runtime. */ export declare function startTaskScheduler(adapterInstance: IDatabaseAdapter): void; /** Fence the current generation now. Await the returned query drain before closing its adapter. */ export declare function stopTaskScheduler(): Promise; /** Runtime storage can own the shared adapter without owning any queried tasks. */ export declare function stopTaskSchedulerForAdapter(closingAdapter: IDatabaseAdapter): Promise; /** The caller confirms these handles share storage and retires the first. * Retain each pending query under both handles until it settles, including * when the replacement closes before the retiring host finishes its drain. */ export declare function handoffTaskSchedulerAdapter(retiringAdapter: IDatabaseAdapter, replacementAdapter: IDatabaseAdapter): Promise; /** Called by TaskService.startTimer() when getTaskSchedulerAdapter() != null. WHY: runtime opts into shared tick instead of local timer. */ export declare function registerTaskSchedulerRuntime(runtime: IAgentRuntime, taskService: TaskServiceLike): void; /** Detach now and drain this service's queries, including detached generations. */ export declare function unregisterTaskSchedulerRuntime(agentId: UUID, taskService?: TaskServiceLike): Promise; /** Called by TaskService.markDirty() when daemon is present. WHY: next tick will include this agent in the batched getTasks. */ export declare function markTaskSchedulerDirty(agentId: UUID): void; /** TaskService uses this to decide: register with daemon vs start local timer. */ export declare function getTaskSchedulerAdapter(): IDatabaseAdapter | null; export {};