// Force strict mode and setup for ESM
"use strict";
import {
  JsonOutputAdapter
} from "./chunk-5T2GZ5CP.js";
import {
  StreamJsonOutputAdapter
} from "./chunk-5FIALBMB.js";
import "./chunk-2YHZUN7M.js";
import {
  validateAuthMethod
} from "./chunk-NASYZDJN.js";
import "./chunk-5DTTYNB7.js";
import "./chunk-QVF3E7VR.js";
import "./chunk-4MCQKI27.js";
import "./chunk-4LVZNIDO.js";
import "./chunk-4WGODMVR.js";
import "./chunk-GIOUOCJ6.js";
import "./chunk-YAF2MQZ6.js";
import "./chunk-7Z6JQEL6.js";
import "./chunk-JAC6VCSS.js";
import "./chunk-6H67XLET.js";
import "./chunk-C4AQMY3Z.js";
import "./chunk-YBR3URXS.js";
import "./chunk-Z6AKQMO4.js";
import "./chunk-4K7VDKAD.js";
import "./chunk-RS7MT2QG.js";
import "./chunk-5GVLCSA5.js";
import "./chunk-H2XVO6NE.js";
import "./chunk-QHTIBUWB.js";
import "./chunk-QTERJVPZ.js";
import "./chunk-L573Z2QZ.js";
import "./chunk-RXFQM6FQ.js";
import "./chunk-64WEC2SN.js";
import "./chunk-E5Z2AVNV.js";
import "./chunk-YA423L5V.js";
import "./chunk-REGJ73RR.js";
import "./chunk-QLJUC7TG.js";
import "./chunk-TYMRUJIG.js";
import "./chunk-4PFHRCCL.js";
import "./chunk-57OAHC2Y.js";
import "./chunk-QD6BRERJ.js";
import "./chunk-6ZBPS62S.js";
import "./chunk-V6WHFGST.js";
import "./chunk-6RLROE6G.js";
import "./chunk-COH43MRJ.js";
import "./chunk-QKTHJXCS.js";
import "./chunk-TJTKSVIV.js";
import "./chunk-M5GB774H.js";
import "./chunk-RV4C2ZFG.js";
import "./chunk-2LI23QA6.js";
import "./chunk-RVLZCXEE.js";
import "./chunk-UDXSXLER.js";
import "./chunk-TFAO33UY.js";
import "./chunk-45LUTRWI.js";
import "./chunk-RKUWKYED.js";
import "./chunk-NIIX6Y2O.js";
import "./chunk-6KNRVSRI.js";
import "./chunk-7L3CIBDY.js";
import "./chunk-GOXKNSDZ.js";
import "./chunk-QRUIS3DN.js";
import "./chunk-2RFKHEXL.js";
import "./chunk-IDS7MSUP.js";
import "./chunk-XFSFZCM5.js";
import "./chunk-27CLX4FV.js";
import "./chunk-VJNBRRZG.js";
import "./chunk-Z4ZEXUZG.js";
import "./chunk-ALGGS7UH.js";
import "./chunk-MR3PXB6E.js";
import {
  writeStderrLine
} from "./chunk-OWAK7LMW.js";
import "./chunk-2MWHVNSM.js";
import "./chunk-T4TZQJ7W.js";
import "./chunk-H6XPXXMH.js";
import "./chunk-5M6IDOMF.js";
import "./chunk-T2L47JJK.js";
import "./chunk-GPSKDNEE.js";
import "./chunk-X6N25LXS.js";
import "./chunk-E2UVIFI2.js";
import "./chunk-Q2YKNMLS.js";
import "./chunk-XU457J4V.js";
import "./chunk-VDDGDZMA.js";
import "./chunk-KHOVYUHX.js";
import "./chunk-SZRN75WQ.js";
import "./chunk-6PVPNMXU.js";
import "./chunk-VWYINXDB.js";
import "./chunk-CPBF7KYF.js";
import "./chunk-NABLFI57.js";
import "./chunk-QBUDF33N.js";
import "./chunk-LIZRAKPB.js";
import "./chunk-WHGVTP7Q.js";
import "./chunk-6AM5D4ME.js";
import "./chunk-JCW2R7WC.js";
import "./chunk-57FIIFJN.js";
import "./chunk-HTO4JFDZ.js";
import "./chunk-XVNQMZ2I.js";
import "./chunk-FODK6UMO.js";
import "./chunk-GLNBDYUX.js";
import "./chunk-5YMPVE5X.js";
import "./chunk-JESCGQM3.js";
import "./chunk-TULTPXPE.js";
import "./chunk-EHPOFGVJ.js";
import "./chunk-DJ2GSRLV.js";
import "./chunk-5I5BM454.js";
import "./chunk-TMSMMRTT.js";
import "./chunk-VGC4I5JJ.js";
import "./chunk-4K56OJFJ.js";
import "./chunk-JYS55H6Z.js";
import "./chunk-A4UCTEB5.js";
import "./chunk-XWRJCPHC.js";
import "./chunk-QNLNLENL.js";
import "./chunk-6X4GWOPW.js";
import "./chunk-TYQMGACW.js";
import "./chunk-TYAMGABM.js";
import "./chunk-FCMNKVXT.js";
import "./chunk-IS2SBY6T.js";
import "./chunk-HTR4WV6U.js";
import "./chunk-M7WBGLYP.js";
import "./chunk-U7ZFW55U.js";
import "./chunk-NPQDJGKU.js";
import "./chunk-YM3SZTH4.js";
import "./chunk-OQB4EXO4.js";
import "./chunk-RMIRGNC4.js";
import {
  runExitCleanup
} from "./chunk-ZH3WKF33.js";
import "./chunk-75DOP5OR.js";
import "./chunk-DMTGGOSA.js";
import "./chunk-YQ3U5MUC.js";
import "./chunk-THJNPLI4.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
 */
