// Force strict mode and setup for ESM
"use strict";
import {
  JsonOutputAdapter
} from "./chunk-QRJ36XWJ.js";
import {
  StreamJsonOutputAdapter
} from "./chunk-OZK4EO2V.js";
import "./chunk-SVWDDARG.js";
import {
  validateAuthMethod
} from "./chunk-L2TDXQN5.js";
import "./chunk-ZGPJFEEO.js";
import "./chunk-OJINH4QS.js";
import "./chunk-5DTTYNB7.js";
import "./chunk-52DZGXZP.js";
import "./chunk-4WGODMVR.js";
import "./chunk-NHDKSOEY.js";
import "./chunk-7X7TEQNX.js";
import "./chunk-HTHUX2T5.js";
import "./chunk-64TN6SIX.js";
import "./chunk-SL7MFP6Y.js";
import "./chunk-YAF2MQZ6.js";
import "./chunk-Q6TUALBE.js";
import "./chunk-KW7NOTN6.js";
import "./chunk-PQTA2QCW.js";
import "./chunk-KWD32WL5.js";
import "./chunk-JZZFWHB3.js";
import "./chunk-QHTIBUWB.js";
import "./chunk-L573Z2QZ.js";
import "./chunk-RXFQM6FQ.js";
import "./chunk-XO2KJCB5.js";
import "./chunk-6H67XLET.js";
import "./chunk-Y2U2KGFY.js";
import "./chunk-MKHZK6DV.js";
import "./chunk-YEHN33XD.js";
import "./chunk-E5Z2AVNV.js";
import "./chunk-IXFI4ABN.js";
import "./chunk-D22HYL53.js";
import "./chunk-FSA7ERJ2.js";
import "./chunk-6RLROE6G.js";
import "./chunk-COH43MRJ.js";
import "./chunk-U5C3AQCY.js";
import "./chunk-RWQ5PAC6.js";
import "./chunk-57OAHC2Y.js";
import "./chunk-OATTJGPJ.js";
import "./chunk-ZRKBI3DP.js";
import "./chunk-V6WHFGST.js";
import "./chunk-W7FJ3N32.js";
import "./chunk-GYTKQYDB.js";
import "./chunk-TJTKSVIV.js";
import "./chunk-OJAMDVF5.js";
import "./chunk-LXLTBIDP.js";
import "./chunk-BBNVFRGD.js";
import "./chunk-SXU3KKNI.js";
import "./chunk-UDXSXLER.js";
import "./chunk-4PL6UORQ.js";
import "./chunk-3HLJWG2D.js";
import "./chunk-RKUWKYED.js";
import "./chunk-XP6JY4LW.js";
import "./chunk-AEC7J3NZ.js";
import "./chunk-GOXKNSDZ.js";
import "./chunk-IDS7MSUP.js";
import "./chunk-QRUIS3DN.js";
import "./chunk-HBNOK3LO.js";
import "./chunk-ALGGS7UH.js";
import "./chunk-MR3PXB6E.js";
import {
  writeStderrLine
} from "./chunk-YUZI3WAC.js";
import "./chunk-XFSFZCM5.js";
import "./chunk-YU56QGXX.js";
import "./chunk-VJNBRRZG.js";
import "./chunk-YHRUZRL4.js";
import "./chunk-H6XPXXMH.js";
import "./chunk-5M6IDOMF.js";
import "./chunk-E67NFMF4.js";
import "./chunk-RCEEXIOO.js";
import "./chunk-KKRTYONM.js";
import "./chunk-TV6K2FB4.js";
import "./chunk-E2UVIFI2.js";
import "./chunk-6OATMEYN.js";
import "./chunk-XU457J4V.js";
import "./chunk-VDDGDZMA.js";
import "./chunk-SPJQO2CE.js";
import "./chunk-SZRN75WQ.js";
import "./chunk-HTO4JFDZ.js";
import "./chunk-CPBF7KYF.js";
import "./chunk-TXY2C3D2.js";
import "./chunk-6AM5D4ME.js";
import "./chunk-2Z5UX4KI.js";
import "./chunk-ARKANCNX.js";
import "./chunk-L5U3ELZX.js";
import "./chunk-TYLOFD2U.js";
import "./chunk-D3DWHKLI.js";
import "./chunk-4WKAA4KS.js";
import "./chunk-CR3C7WXL.js";
import "./chunk-CARU2RR2.js";
import "./chunk-VGC4I5JJ.js";
import "./chunk-FBU7WRZI.js";
import "./chunk-Y66VOBRP.js";
import "./chunk-WX6SD4IQ.js";
import "./chunk-2UUAIFQO.js";
import "./chunk-OKAIGAYW.js";
import "./chunk-ZPAHLFZU.js";
import "./chunk-JESCGQM3.js";
import "./chunk-WIEO4CWB.js";
import "./chunk-XVNQMZ2I.js";
import "./chunk-B7NUUEXC.js";
import "./chunk-TQBODCFD.js";
import "./chunk-A4UCTEB5.js";
import "./chunk-XWRJCPHC.js";
import "./chunk-4LD5APFL.js";
import "./chunk-TYAMGABM.js";
import "./chunk-FCMNKVXT.js";
import "./chunk-DJ2GSRLV.js";
import "./chunk-LQIDP6K5.js";
import "./chunk-7NFB7LBQ.js";
import "./chunk-3BCX2DDD.js";
import {
  runExitCleanup
} from "./chunk-KELQ5JU3.js";
import "./chunk-75DOP5OR.js";
import "./chunk-DMTGGOSA.js";
import "./chunk-YQ3U5MUC.js";
import "./chunk-TB6UDU4T.js";
import {
  init_esbuild_shims
} from "./chunk-5O2XNYP6.js";
import {
  __name
} from "./chunk-J2S4EL5Y.js";

// packages/cli/src/validateNonInterActiveAuth.ts
init_esbuild_shims();
async function validateNonInteractiveAuth(useExternalAuth, nonInteractiveConfig, settings) {
  try {
    const authType = nonInteractiveConfig.getModelsConfig().getCurrentAuthType();
    if (!authType) {
      throw new Error(
        "No auth type is selected. Please configure an auth type (e.g. via settings or `--auth-type`) before running in non-interactive mode."
      );
    }
    const resolvedAuthType = authType;
    const enforcedType = settings.merged.security?.auth?.enforcedType;
    if (enforcedType && enforcedType !== resolvedAuthType) {
      const message = `The configured auth type is ${enforcedType}, but the current auth type is ${resolvedAuthType}. Please re-authenticate with the correct type.`;
      throw new Error(message);
    }
    if (!useExternalAuth) {
      const err = validateAuthMethod(resolvedAuthType, nonInteractiveConfig);
      if (err != null) {
        throw new Error(err);
      }
    }
    await nonInteractiveConfig.refreshAuth(resolvedAuthType);
    return nonInteractiveConfig;
  } catch (error) {
    const outputFormat = nonInteractiveConfig.getOutputFormat();
    if (outputFormat === "json" /* JSON */ || outputFormat === "stream-json" /* STREAM_JSON */) {
      let adapter;
      if (outputFormat === "json" /* JSON */) {
        adapter = new JsonOutputAdapter(nonInteractiveConfig);
      } else {
        adapter = new StreamJsonOutputAdapter(
          nonInteractiveConfig,
          nonInteractiveConfig.getIncludePartialMessages()
        );
      }
      const errorMessage = error instanceof Error ? error.message : String(error);
      adapter.emitResult({
        isError: true,
        errorMessage,
        durationMs: 0,
        apiDurationMs: 0,
        numTurns: 0,
        usage: void 0
      });
      await runExitCleanup();
      process.exit(1);
    }
    writeStderrLine(error instanceof Error ? error.message : String(error));
    process.exit(1);
  }
}
__name(validateNonInteractiveAuth, "validateNonInteractiveAuth");
export {
  validateNonInteractiveAuth
};
/**
 * @license
 * Copyright 2025 Google LLC
 * SPDX-License-Identifier: Apache-2.0
 */
