Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors
TypeScript a2aai-agentsai-gatewayanthropicclaudeclaude-codeclinecodexcopilotcursordeepseekfree-aigeminikimillm-gatewaymcpopenaiopenai-proxyqwentoken-saver
/** Singleton registry of ServiceSupervisor instances. */
import type { ServiceSupervisor } from "./ServiceSupervisor";
const supervisors = new Map<string, ServiceSupervisor>();
export function registerSupervisor(supervisor: ServiceSupervisor): void {
supervisors.set(supervisor.getStatus().tool, supervisor);
}
export function getSupervisor(tool: string): ServiceSupervisor | null {
return supervisors.get(tool) ?? null;
}
/** Remove a supervisor by tool name. Intended for use in tests. */
export function unregisterSupervisor(tool: string): void {
supervisors.delete(tool);
}
async function stopAll(): Promise<void> {
// Drive every supervisor stop to completion before the process exits so the
// DB status writes inside ServiceSupervisor.stop() flush. Otherwise the
// event loop drains immediately on SIGTERM and rows are stuck in "running"
// or "starting" until the next boot.
await Promise.allSettled(Array.from(supervisors.values()).map((supervisor) => supervisor.stop()));
}
function handleShutdownSignal(signal: NodeJS.Signals): void {
stopAll()
.catch(() => {
/* never throw out of a signal handler */
})
.finally(() => {
// Re-raise the signal with the default disposition so the process exit
// status reflects the original signal (128 + signal number) rather than
// a synthetic process.exit() code.
process.kill(process.pid, signal);
});
}
process.once("SIGINT", () => handleShutdownSignal("SIGINT"));
process.once("SIGTERM", () => handleShutdownSignal("SIGTERM"));