// ../core/src/platform/utils/debounce.ts
function debounce(fn, wait) {
  let timeoutId = null;
  const debounced = (...args) => {
    if (timeoutId !== null) {
      clearTimeout(timeoutId);
    }
    timeoutId = setTimeout(() => {
      fn(...args);
      timeoutId = null;
    }, wait);
  };
  debounced.cancel = () => {
    if (timeoutId !== null) {
      clearTimeout(timeoutId);
      timeoutId = null;
    }
  };
  return debounced;
}

// ../core/src/platform/utils/token-counter.ts
function estimateTokens(text) {
  const content = typeof text === "string" ? text : JSON.stringify(text);
  const chars = content.length;
  return Math.ceil(chars / 3.5);
}
function validateTokenLimit(text, limits) {
  const content = typeof text === "string" ? text : JSON.stringify(text);
  const characters = content.length;
  const tokens = estimateTokens(content);
  return {
    tokens,
    characters,
    withinLimit: tokens <= limits.maxTokens
  };
}
var TOKEN_LIMITS = {
  // User input limits (prompts)
  USER_MESSAGE: 25e3,
  // ~100KB text - allows large code pastes
  CHAT_MESSAGE: 1e4,
  // ~40KB text - typical chat message
  // WebSocket message limits
  WEBSOCKET_MESSAGE: 25e3,
  // Same as user message
  WEBSOCKET_TOTAL: 25e4,
  // Hard limit for entire payload (1MB)
  // AI model context windows (for reference)
  GPT4_TURBO: 128e3,
  CLAUDE_SONNET: 2e5,
  GPT35_TURBO: 16385
};

// ../core/src/operations/observability/utils.ts
function getTimeRangeDates(range) {
  const end = /* @__PURE__ */ new Date();
  const start = /* @__PURE__ */ new Date();
  switch (range) {
    case "1h":
      start.setHours(start.getHours() - 1);
      break;
    case "24h":
      start.setHours(start.getHours() - 24);
      break;
    case "7d":
      start.setDate(start.getDate() - 7);
      break;
    case "30d":
      start.setDate(start.getDate() - 30);
      break;
  }
  return {
    startDate: start.toISOString(),
    endDate: end.toISOString()
  };
}
function getTimeRangeLabel(range) {
  switch (range) {
    case "1h":
      return "Last 1 hour";
    case "24h":
      return "Last 24 hours";
    case "7d":
      return "Last 7 days";
    case "30d":
      return "Last 30 days";
  }
}
function formatBucketTime(timestamp, granularity) {
  const date = new Date(timestamp);
  if (granularity === "hour") {
    return date.toLocaleTimeString("en-US", {
      hour: "2-digit",
      minute: "2-digit",
      hour12: false
    });
  }
  return date.toLocaleDateString("en-US", {
    month: "short",
    day: "numeric"
  });
}

// src/utils/constants/polling.ts
var REFETCH_INTERVAL_DASHBOARD = 6e4;
var REFETCH_INTERVAL_REALTIME = 3e4;
var REFETCH_INTERVAL_RUNNING = 2e3;
var REFETCH_INTERVAL_RUNNING_FAST = 1e3;

// src/utils/constants/reconnection.ts
var SSE_TOKEN_REFRESH_DELAY = 2e3;
var SSE_CLOSE_GRACE_PERIOD = 5e3;
var WS_RECONNECT_BASE_DELAY = 1e3;
var WS_RECONNECT_MAX_DELAY = 3e4;
var WS_MAX_RETRIES_BEFORE_ERROR = 3;

export { REFETCH_INTERVAL_DASHBOARD, REFETCH_INTERVAL_REALTIME, REFETCH_INTERVAL_RUNNING, REFETCH_INTERVAL_RUNNING_FAST, SSE_CLOSE_GRACE_PERIOD, SSE_TOKEN_REFRESH_DELAY, TOKEN_LIMITS, WS_MAX_RETRIES_BEFORE_ERROR, WS_RECONNECT_BASE_DELAY, WS_RECONNECT_MAX_DELAY, debounce, formatBucketTime, getTimeRangeDates, getTimeRangeLabel, validateTokenLimit };
