checkChromeAiStatus function

Last updated: 2026-03-03T18:32:34.140Z

Metrics

LOC: 45 Complexity: 15 Params: 0

Signature

checkChromeAiStatus(): : Promise<void>

Architecture violations

View all

  • [warning] max-cyclomatic-complexity: 'checkChromeAiStatus' has cyclomatic complexity 15 (max 10)

Source Code

async function checkChromeAiStatus(): Promise<void> {
  const block = document.getElementById("chrome-ai-status-block");
  const statusText = document.getElementById("chrome-ai-status-text");
  const downloadBtn = document.getElementById(
    "btn-download-chrome-ai",
  ) as HTMLButtonElement | null;

  if (!block || !statusText) return;

  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  const LanguageModel = (globalThis as any).LanguageModel as
    | {
        availability?: (opts?: unknown) => Promise<string>;
        create?: () => Promise<unknown>;
      }
    | undefined;

  block.style.display = "block";

  if (!LanguageModel) {
    statusText.innerHTML = `<strong style="color: var(--danger)">${t("chromeAiNotAvailableHtml")}</strong>`;
    if (downloadBtn) downloadBtn.style.display = "none";
    return;
  }

  try {
    const result = await LanguageModel.availability?.({
      expectedInputs: [{ type: "text", languages: ["en"] }],
      expectedOutputs: [{ type: "text", languages: ["en"] }],
    });
    if (result === "available") {
      statusText.innerHTML = `<strong style="color: var(--success)">✅ ${t("chromeAiReady")}</strong>`;
      if (downloadBtn) downloadBtn.style.display = "none";
    } else if (result === "downloadable") {
      statusText.innerHTML = `<strong style="color: #f59e0b">⚠️ ${t("chromeAiDownloadable")}</strong>`;
      if (downloadBtn) downloadBtn.style.display = "";
    } else {
      statusText.innerHTML = `<strong style="color: var(--text-muted)">${escapeHtml(t("chromeAiStatusHtml", [String(result ?? "desconhecido")]))}</strong>`;
      if (downloadBtn) downloadBtn.style.display = "none";
    }
  } catch {
    statusText.innerHTML = `<strong style="color: var(--danger)">${t("chromeAiCheckError")}</strong>`;
    if (downloadBtn) downloadBtn.style.display = "none";
  }
}

No outgoing dependencies.

Impact (Incoming)

graph LR checkChromeAiStatus["checkChromeAiStatus"] loadSettings["loadSettings"] bindSettingsEvents["bindSettingsEvents"] loadSettings -->|calls| checkChromeAiStatus bindSettingsEvents -->|calls| checkChromeAiStatus style checkChromeAiStatus fill:#dbeafe,stroke:#2563eb,stroke-width:2px click checkChromeAiStatus "f0bcc646e70f0282.html" click loadSettings "6569479f3c7ea49f.html" click bindSettingsEvents "29719c6741ea9340.html"
SourceType
loadSettings calls
bindSettingsEvents calls