const ENGINE_AUTH_HINTS = {
  // GitHub code search returns 401 (or 403 for rate-limit-with-auth) when
  // the request is unauthenticated against private orgs or hits a hard
  // search limit. The token is read by the existing adapter; the hint names
  // the env var so users can set it in their MCP host config.
  "github-code": "set WIGOLO_GITHUB_TOKEN to lift GitHub API rate limits",
  // Slice S11a: Brave Image is gated behind the same key as the Brave web
  // engine. When the orchestrator dispatches the adapter and the key is
  // missing, the adapter raises `BRAVE_API_KEY not set ...` which we
  // detect below and convert to a `needs_key` warning code.
  "brave-image": "set BRAVE_API_KEY to enable Brave image search",
  brave: "set BRAVE_API_KEY to enable the Brave web engine"
};
const MISSING_KEY_PATTERN = /\b([A-Z][A-Z0-9_]+_API_KEY|GITHUB_TOKEN|BRAVE_API_KEY)\b.*not set\b|\bnot set\b.*\b([A-Z][A-Z0-9_]+_API_KEY|GITHUB_TOKEN|BRAVE_API_KEY)\b|set\s+([A-Z][A-Z0-9_]+_API_KEY|GITHUB_TOKEN|BRAVE_API_KEY)/;
function classifyError(message) {
  if (typeof message !== "string" || message.length === 0) {
    return { code: "error", httpStatus: null };
  }
  const httpMatch = message.match(/\b(\d{3})\b/);
  if (httpMatch) {
    const status = Number(httpMatch[1]);
    if (status >= 400 && status < 600) {
      return { code: `http_${status}`, httpStatus: status };
    }
  }
  if (MISSING_KEY_PATTERN.test(message)) {
    return { code: "needs_key", httpStatus: null };
  }
  if (/timeout|aborted|abort/i.test(message)) {
    return { code: "timeout", httpStatus: null };
  }
  if (/dns|ENOTFOUND|getaddrinfo/i.test(message)) {
    return { code: "dns", httpStatus: null };
  }
  return { code: "error", httpStatus: null };
}
function buildEngineWarnings(telemetry) {
  if (!telemetry || telemetry.length === 0) return [];
  const warnings = [];
  for (const t of telemetry) {
    if (t.outcome !== "error") continue;
    const { code, httpStatus } = classifyError(t.error);
    const warning = {
      engine: t.name,
      code,
      ...t.error ? { message: t.error } : {}
    };
    if ((httpStatus === 401 || httpStatus === 403) && ENGINE_AUTH_HINTS[t.name]) {
      warning.hint = ENGINE_AUTH_HINTS[t.name];
    }
    if (code === "needs_key" && ENGINE_AUTH_HINTS[t.name]) {
      warning.hint = ENGINE_AUTH_HINTS[t.name];
    }
    warnings.push(warning);
  }
  return warnings;
}
export {
  buildEngineWarnings
};
//# sourceMappingURL=engine-warnings.js.map