/**
 * Proactive OAuth token refresh timer.
 *
 * Web clients use BaseTokenManager.scheduleRefresh() to refresh tokens before
 * they expire. The agent has no equivalent — it only refreshes reactively when
 * getApiKey() is called. If the TUI is idle, the token expires silently.
 *
 * This module adds a simple timer that calls getApiKey() periodically to
 * trigger the reactive refresh logic in AuthStorage before the token expires.
 */
const REFRESH_INTERVAL_MS = 60 * 1000; // Check every 60 seconds
let timer = null;
/**
 * Start a background timer that keeps OAuth tokens fresh.
 * Calls authStorage.getApiKey() periodically, which triggers refresh
 * when the token is within the buffer window of expiry.
 */
export function startProactiveRefresh(authStorage, providerId) {
    stopProactiveRefresh();
    timer = setInterval(() => {
        // Fire-and-forget — getApiKey() handles refresh internally
        void authStorage.getApiKey(providerId);
    }, REFRESH_INTERVAL_MS);
    // Don't block process exit
    timer.unref();
}
function stopProactiveRefresh() {
    if (timer) {
        clearInterval(timer);
        timer = null;
    }
}
//# sourceMappingURL=refresh-timer.js.map