// Force strict mode and setup for ESM
"use strict";
import {
  JsonOutputAdapter
} from "./chunk-PZQTNXXD.js";
import {
  StreamJsonOutputAdapter
} from "./chunk-MSGD6WJD.js";
import "./chunk-HKBYM45F.js";
import {
  validateAuthMethod
} from "./chunk-LI3LTGRG.js";
import "./chunk-T433G753.js";
import "./chunk-5DTTYNB7.js";
import "./chunk-QKYTTBYW.js";
import "./chunk-V2OFM4AY.js";
import "./chunk-4WGODMVR.js";
import "./chunk-AYCDXHZB.js";
import "./chunk-UBEMOPYV.js";
import "./chunk-7EUOQGFB.js";
import "./chunk-DC346ZP2.js";
import "./chunk-YAF2MQZ6.js";
import "./chunk-IHARV3L2.js";
import "./chunk-KTUQMDEP.js";
import "./chunk-HOQLTDZY.js";
import "./chunk-RS7MT2QG.js";
import "./chunk-H2XVO6NE.js";
import "./chunk-QHTIBUWB.js";
import "./chunk-QTERJVPZ.js";
import "./chunk-L573Z2QZ.js";
import "./chunk-RXFQM6FQ.js";
import "./chunk-PG4PA3M6.js";
import "./chunk-6H67XLET.js";
import "./chunk-KUCV7UYM.js";
import "./chunk-NUBKIBLY.js";
import "./chunk-E5Z2AVNV.js";
import "./chunk-IM67MGWO.js";
import "./chunk-J7VO4A7Y.js";
import "./chunk-BVLROR2T.js";
import "./chunk-6RLROE6G.js";
import "./chunk-COH43MRJ.js";
import "./chunk-DE4IIWWG.js";
import "./chunk-L5D4ICBV.js";
import "./chunk-57OAHC2Y.js";
import "./chunk-YWEW33JY.js";
import "./chunk-4ODB7WIB.js";
import "./chunk-V6WHFGST.js";
import "./chunk-W7FJ3N32.js";
import "./chunk-Y2ENGUD6.js";
import "./chunk-TJTKSVIV.js";
import "./chunk-M5GB774H.js";
import "./chunk-RFIAR4YL.js";
import "./chunk-2HOVDT7W.js";
import "./chunk-NIJEXGV6.js";
import "./chunk-UDXSXLER.js";
import "./chunk-RBTX5M7N.js";
import "./chunk-XBGU2P5H.js";
import "./chunk-RKUWKYED.js";
import "./chunk-GOXKNSDZ.js";
import "./chunk-IDS7MSUP.js";
import "./chunk-2NUWYH6U.js";
import "./chunk-MEVD5Z6X.js";
import "./chunk-QRUIS3DN.js";
import "./chunk-OWCALFEG.js";
import "./chunk-VJNBRRZG.js";
import "./chunk-AMLC67CK.js";
import "./chunk-ALGGS7UH.js";
import "./chunk-MR3PXB6E.js";
import {
  writeStderrLine
} from "./chunk-OWAK7LMW.js";
import "./chunk-XFSFZCM5.js";
import "./chunk-RAKX2BKU.js";
import "./chunk-5M6IDOMF.js";
import "./chunk-T4TZQJ7W.js";
import "./chunk-H6XPXXMH.js";
import "./chunk-EAUYY7SS.js";
import "./chunk-FSL5W5TI.js";
import "./chunk-OONJNQ42.js";
import "./chunk-D2VIDMVM.js";
import "./chunk-E2UVIFI2.js";
import "./chunk-XU457J4V.js";
import "./chunk-VDDGDZMA.js";
import "./chunk-EIAK6Q2B.js";
import "./chunk-SZRN75WQ.js";
import "./chunk-HTO4JFDZ.js";
import "./chunk-CPBF7KYF.js";
import "./chunk-CPCVCKKF.js";
import "./chunk-6AM5D4ME.js";
import "./chunk-G45X5TRN.js";
import "./chunk-PBATSWUQ.js";
import "./chunk-ZEOZL37W.js";
import "./chunk-OOCI5VVU.js";
import "./chunk-6CVQNKKX.js";
import "./chunk-PX4YS37M.js";
import "./chunk-JESCGQM3.js";
import "./chunk-Q6CQFB7U.js";
import "./chunk-4WKAA4KS.js";
import "./chunk-CR3C7WXL.js";
import "./chunk-VGC4I5JJ.js";
import "./chunk-JD3MKVKL.js";
import "./chunk-UEY4AYUL.js";
import "./chunk-BDBMYST4.js";
import "./chunk-EZVDJFZ7.js";
import "./chunk-OP4MOGXF.js";
import "./chunk-XVNQMZ2I.js";
import "./chunk-FEOZBUMT.js";
import "./chunk-DJ2GSRLV.js";
import "./chunk-6EFTQYW7.js";
import "./chunk-MAQQGNQ5.js";
import "./chunk-A4UCTEB5.js";
import "./chunk-XWRJCPHC.js";
import "./chunk-TYQMGACW.js";
import "./chunk-TYAMGABM.js";
import "./chunk-FCMNKVXT.js";
import "./chunk-C27BYUX6.js";
import "./chunk-2CFF2ZBS.js";
import {
  runExitCleanup
} from "./chunk-YSMWPOYZ.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
 */
