// src/sessions/retry.ts
var MAX_RETRIES = 3;
var BASE_DELAYS = {
  model_rate_limited_error: 5e3,
  model_overloaded_error: 2e3
};
var retryCounts = /* @__PURE__ */ new Map();
function getRetryCount(sessionId) {
  return retryCounts.get(sessionId) ?? 0;
}
function incrementRetry(sessionId) {
  const count = getRetryCount(sessionId) + 1;
  retryCounts.set(sessionId, count);
  return count;
}
function resetRetry(sessionId) {
  retryCounts.delete(sessionId);
}
function shouldRetry(sessionId, classified) {
  if (!classified.retryable) return null;
  const count = getRetryCount(sessionId);
  if (count >= MAX_RETRIES) return null;
  const baseDelay = BASE_DELAYS[classified.type] ?? 5e3;
  const multiplier = Math.pow(3, count);
  const delay = baseDelay * multiplier;
  const jitter = delay * 0.2 * (Math.random() * 2 - 1);
  const delayMs = Math.round(delay + jitter);
  return { delayMs, attempt: count + 1 };
}
function retryDelay(ms) {
  return new Promise((resolve) => setTimeout(resolve, ms));
}

export {
  getRetryCount,
  incrementRetry,
  resetRetry,
  shouldRetry,
  retryDelay
};
