import { loadSettings } from '../lib/settings.ts' import { loadEventCardLog, SOURCE_TOPICS } from '../events/cards.ts' import { TOPICS } from '../events/emit.ts' import { listPending, listWakeAlerts } from '../events/wake-transport.ts' /** * Read-only view of the factory's event wiring: wake settings, recent wake alerts, the * topics it emits and subscribes to, and the most recent event-card log * entries (what was filed, or in shadow mode what would have been filed). * * @param input - `{ limit? }` log entries to include (default 20, max 200) * @returns Switches, topics, and recent event-card log entries. No secrets. * * @example * import eventsStatus from 'kody:@kody/kody-factory/events/status' * await eventsStatus({ limit: 10 }) */ export default async function eventsStatus(input: { limit?: number } = {}) { const settings = await loadSettings() const limit = Math.min(Math.max(Number(input?.limit) || 20, 1), 200) return { switches: { wakePath: '@kody/wake-relay (only path)', wakeAlertMinutes: settings.wakeAlertMinutes, emitHealthEvents: settings.emitHealthEvents, eventCardsMode: settings.eventCardsMode, }, emits: Object.values(TOPICS), subscribes: [...Object.values(SOURCE_TOPICS), '@kody/wake-relay.wake.delivered', '@kody/wake-relay.wake.failed'], recentEventCards: (await loadEventCardLog()).slice(0, limit), recentEventWakes: await listPending(limit), wakeAlerts: await listWakeAlerts(limit), } }