/** * World Heartbeat Scheduler * * Purpose: * - Provide reusable heartbeat scheduling helpers for worlds. * * Key Features: * - Cron validation with strict 5-field contract. * - Start/stop helpers that publish world heartbeat messages. * - Guards for disabled/invalid/missing heartbeat config. * * Implementation Notes: * - Scheduling is opt-in; this module does not self-register jobs. * - Tick publishing uses canonical queued world-message flow. * * Recent Changes: * - 2026-03-14: Added runtime heartbeat prompt datetime placeholder expansion for single-brace * formats such as `{yyyy-mm-dd hh:mm:ss}`. * - 2026-03-14: Replaced direct heartbeat `console` traces with categorized structured logger * events (`heartbeat`) so cron diagnostics can be enabled via env (for example `LOG_HEARTBEAT=debug`). * - 2026-03-06: Removed `world.currentChatId` fallback from heartbeat dispatch; scheduled jobs now require explicit `chatId`. * - 2026-03-04: Added initial world heartbeat scheduler helpers. */ import { type ScheduledTask } from 'node-cron'; import type { World } from './types.js'; export interface HeartbeatHandle { task: ScheduledTask; } export interface HeartbeatCallbacks { onRun?: () => void; } export declare function isValidCronExpression(expr: string): boolean; export declare function startHeartbeat(world: World, chatId: string, callbacks?: HeartbeatCallbacks): HeartbeatHandle | null; export declare function stopHeartbeat(handle: HeartbeatHandle | null | undefined): void;