// Force strict mode and setup for ESM
"use strict";
import {
  JsonOutputAdapter
} from "./chunk-FM7AW6JB.js";
import {
  StreamJsonOutputAdapter
} from "./chunk-R55Q7NP5.js";
import "./chunk-XXCS42YL.js";
import {
  validateAuthMethod
} from "./chunk-GVENZZ4Q.js";
import "./chunk-XCFCWVQS.js";
import "./chunk-PQNHRFJC.js";
import "./chunk-M7OONWYU.js";
import "./chunk-QYQLZ4UT.js";
import "./chunk-4WGODMVR.js";
import "./chunk-GATT5TKW.js";
import "./chunk-JWWPIZMB.js";
import "./chunk-I3ODYH6F.js";
import "./chunk-NB3P23LM.js";
import "./chunk-YAF2MQZ6.js";
import "./chunk-OXCSAVAK.js";
import "./chunk-6H67XLET.js";
import "./chunk-RNXM4QMC.js";
import "./chunk-LGAOC3ZS.js";
import "./chunk-6AHBEO4X.js";
import "./chunk-YDLJGZHL.js";
import "./chunk-2MIN6GRR.js";
import "./chunk-QHTIBUWB.js";
import "./chunk-QTERJVPZ.js";
import "./chunk-3Z43GZUQ.js";
import "./chunk-RXFQM6FQ.js";
import "./chunk-W4L3R4WZ.js";
import "./chunk-ZHBO7WVX.js";
import "./chunk-YPCDBNIM.js";
import "./chunk-E5Z2AVNV.js";
import "./chunk-GLWP3FDB.js";
import "./chunk-XCGIMOLN.js";
import "./chunk-AZX3TTUP.js";
import "./chunk-Z4X5MTRT.js";
import "./chunk-CKAEPW6V.js";
import "./chunk-PQV4SXMU.js";
import "./chunk-57OAHC2Y.js";
import "./chunk-2XSLTRFZ.js";
import "./chunk-TFRMVU6R.js";
import "./chunk-XBYYDKAZ.js";
import "./chunk-V6WHFGST.js";
import "./chunk-2RFKHEXL.js";
import "./chunk-FYJ7W2PI.js";
import "./chunk-U4VTUMMK.js";
import "./chunk-GZ3RCT54.js";
import "./chunk-ALMR3E6Q.js";
import "./chunk-BK2UNYWD.js";
import "./chunk-M5GB774H.js";
import "./chunk-4G2BISNC.js";
import "./chunk-GEBV2JGB.js";
import "./chunk-7I5GTCT4.js";
import "./chunk-UDXSXLER.js";
import "./chunk-5S3WLLP2.js";
import "./chunk-O3JAFRIR.js";
import "./chunk-RKUWKYED.js";
import "./chunk-GAPR7Q3F.js";
import "./chunk-4NSIRXOI.js";
import "./chunk-5R6QYKY6.js";
import "./chunk-GOXKNSDZ.js";
import "./chunk-IDS7MSUP.js";
import "./chunk-6PEXNQTX.js";
import "./chunk-XFSFZCM5.js";
import "./chunk-VYOXCEPJ.js";
import "./chunk-VJNBRRZG.js";
import "./chunk-NHQGRBZG.js";
import "./chunk-ALGGS7UH.js";
import "./chunk-MR3PXB6E.js";
import {
  writeStderrLine
} from "./chunk-OWAK7LMW.js";
import "./chunk-QQOPXQYM.js";
import "./chunk-TWPJO254.js";
import "./chunk-H6XPXXMH.js";
import "./chunk-5M6IDOMF.js";
import "./chunk-UPUG4GXM.js";
import "./chunk-64LQLPL7.js";
import "./chunk-2LQTH543.js";
import "./chunk-KRXPRVGL.js";
import "./chunk-GNCIZTNJ.js";
import "./chunk-CVHIL5IG.js";
import "./chunk-IRH27ZC2.js";
import "./chunk-QHWCP53L.js";
import "./chunk-PONHVBRT.js";
import "./chunk-T26EAKDL.js";
import "./chunk-6PVPNMXU.js";
import "./chunk-CPBF7KYF.js";
import "./chunk-6QIGFD5W.js";
import "./chunk-XWWKIXVD.js";
import "./chunk-75GFAX4R.js";
import "./chunk-OKF7JF3R.js";
import "./chunk-JSD33JG6.js";
import "./chunk-S6LOFUVP.js";
import "./chunk-JCW2R7WC.js";
import "./chunk-2DN4J57Y.js";
import "./chunk-ZPJWUGCS.js";
import "./chunk-2LKVPASC.js";
import "./chunk-NAVJD2PQ.js";
import "./chunk-LW3RFMG7.js";
import "./chunk-W4MIWP6M.js";
import "./chunk-DGEIYUC3.js";
import "./chunk-MPHPFVKK.js";
import "./chunk-GLNBDYUX.js";
import "./chunk-DJ2GSRLV.js";
import "./chunk-6D2RWQMA.js";
import "./chunk-75MIQ3LV.js";
import "./chunk-2J3OJGTL.js";
import "./chunk-P3QQPMQA.js";
import "./chunk-RPLGZJV2.js";
import "./chunk-GLCZKT5V.js";
import "./chunk-DZLYR4U3.js";
import "./chunk-NKHOVMWF.js";
import "./chunk-VGC4I5JJ.js";
import "./chunk-SGFT55XI.js";
import "./chunk-Y4IHBGBP.js";
import "./chunk-Y6AXW2OG.js";
import "./chunk-2M3XQKPR.js";
import "./chunk-46UV252V.js";
import "./chunk-ZBVS26BY.js";
import "./chunk-WZRWHXFE.js";
import "./chunk-A3NDJ5SB.js";
import "./chunk-7XATOOE7.js";
import "./chunk-BGTQCTQW.js";
import "./chunk-W4RQUHY3.js";
import "./chunk-S7W2GKIO.js";
import "./chunk-UHUSJ6X7.js";
import "./chunk-VOQXFAY5.js";
import "./chunk-PY6OW25R.js";
import {
  runExitCleanup
} from "./chunk-7H2JHR74.js";
import "./chunk-75DOP5OR.js";
import "./chunk-DMTGGOSA.js";
import "./chunk-YQ3U5MUC.js";
import "./chunk-AMDSOFFV.js";
import "./chunk-QUGAUQGJ.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
 */
