/** * Response handler + shutdown callback registries. * * Extracted from index.ts so that modules calling `registerResponseHandler()` * or `onShutdown()` at import time don't hit a TDZ error on the const-array * declarations. index.ts imports src/modules/index.js for its side effects, * which triggers module registrations that would otherwise happen before * index.ts's own const initializers have run. * * Keep this file dependency-free (log.js is fine, but nothing from * modules/* or index.ts itself). Any file imported here must not in turn * import from src/index.ts, or the cycle returns. */ export interface ResponsePayload { questionId: string; value: string; userId: string | null; channelType: string; platformId: string; threadId: string | null; } export type ResponseHandler = (payload: ResponsePayload) => Promise; const responseHandlers: ResponseHandler[] = []; export function registerResponseHandler(handler: ResponseHandler): void { responseHandlers.push(handler); } export function getResponseHandlers(): readonly ResponseHandler[] { return responseHandlers; } type ShutdownCallback = () => void | Promise; const shutdownCallbacks: ShutdownCallback[] = []; export function onShutdown(cb: ShutdownCallback): void { shutdownCallbacks.push(cb); } export function getShutdownCallbacks(): readonly ShutdownCallback[] { return shutdownCallbacks; }