// Force strict mode and setup for ESM
"use strict";
import {
  JsonOutputAdapter
} from "./chunk-JM2HRNCR.js";
import {
  StreamJsonOutputAdapter
} from "./chunk-CZCOL7AA.js";
import "./chunk-GTXUNTZ6.js";
import "./chunk-NKIH7LA2.js";
import {
  validateAuthMethod
} from "./chunk-B2B76Q4B.js";
import "./chunk-7MNNWQRM.js";
import "./chunk-J56UI34H.js";
import "./chunk-4WGODMVR.js";
import "./chunk-PQNHRFJC.js";
import "./chunk-AQZNOOVK.js";
import "./chunk-L5UHQJTJ.js";
import "./chunk-IUT6F4IQ.js";
import "./chunk-6H67XLET.js";
import "./chunk-GBLM643L.js";
import "./chunk-H6EYAFJW.js";
import "./chunk-YAF2MQZ6.js";
import "./chunk-AOHDRF66.js";
import "./chunk-RHLZR4E5.js";
import "./chunk-IPUUTYMV.js";
import "./chunk-BP7V3NX5.js";
import "./chunk-2MIN6GRR.js";
import "./chunk-QHTIBUWB.js";
import "./chunk-QTERJVPZ.js";
import "./chunk-3Z43GZUQ.js";
import "./chunk-75NIYTE3.js";
import "./chunk-ZD6UTE4A.js";
import "./chunk-RXFQM6FQ.js";
import "./chunk-4F5SYMGA.js";
import "./chunk-CXUMU56B.js";
import "./chunk-57OAHC2Y.js";
import "./chunk-42LSOOZQ.js";
import "./chunk-E5Z2AVNV.js";
import "./chunk-GLWP3FDB.js";
import "./chunk-COH43MRJ.js";
import "./chunk-O74ZWNX7.js";
import "./chunk-X5XDDSSH.js";
import "./chunk-4WIZGAH3.js";
import "./chunk-7ZCNENPP.js";
import "./chunk-V6WHFGST.js";
import "./chunk-QOAKGEK5.js";
import "./chunk-23YHFIEF.js";
import "./chunk-2RFKHEXL.js";
import "./chunk-LK7CHLVP.js";
import "./chunk-JLU636DO.js";
import "./chunk-BK2UNYWD.js";
import "./chunk-M5GB774H.js";
import "./chunk-RWTEFFPU.js";
import "./chunk-UDXSXLER.js";
import "./chunk-BIQWWWJN.js";
import "./chunk-TKJIXYGV.js";
import "./chunk-RKUWKYED.js";
import "./chunk-GOXKNSDZ.js";
import "./chunk-IDS7MSUP.js";
import "./chunk-AOEKE5PW.js";
import "./chunk-PXVI2S5G.js";
import "./chunk-6PEXNQTX.js";
import "./chunk-YX324OPW.js";
import "./chunk-VJNBRRZG.js";
import "./chunk-5ED24675.js";
import "./chunk-ALGGS7UH.js";
import "./chunk-MR3PXB6E.js";
import {
  writeStderrLine
} from "./chunk-OWAK7LMW.js";
import "./chunk-XFSFZCM5.js";
import "./chunk-JRO73ZEG.js";
import "./chunk-5M6IDOMF.js";
import "./chunk-TWPJO254.js";
import "./chunk-H6XPXXMH.js";
import "./chunk-K4XWPEWB.js";
import "./chunk-TOFQCPDC.js";
import "./chunk-IRH27ZC2.js";
import "./chunk-VDDGDZMA.js";
import "./chunk-FNQ6T3CV.js";
import "./chunk-ZOIFNCKL.js";
import "./chunk-PWTZEM3C.js";
import "./chunk-KRXPRVGL.js";
import "./chunk-6PVPNMXU.js";
import "./chunk-M4BZUHPJ.js";
import "./chunk-SZRN75WQ.js";
import "./chunk-HTO4JFDZ.js";
import "./chunk-CPBF7KYF.js";
import "./chunk-L26JL52R.js";
import "./chunk-6AM5D4ME.js";
import "./chunk-JZA3JUDJ.js";
import "./chunk-3QMGYBFN.js";
import "./chunk-JCW2R7WC.js";
import "./chunk-M5JM7OSF.js";
import "./chunk-OHNBB4XR.js";
import "./chunk-E5TUC6CA.js";
import "./chunk-EPDRMGT4.js";
import "./chunk-JESCGQM3.js";
import "./chunk-NH6KE4JX.js";
import "./chunk-USTWD7QV.js";
import "./chunk-XVNQMZ2I.js";
import "./chunk-FODK6UMO.js";
import "./chunk-GLNBDYUX.js";
import "./chunk-DJ2GSRLV.js";
import "./chunk-LUR7PUCM.js";
import "./chunk-NIBLUX3Y.js";
import "./chunk-BPJSQIJX.js";
import "./chunk-P3QQPMQA.js";
import "./chunk-6FGBXPWM.js";
import "./chunk-LS77BEZP.js";
import "./chunk-HMPNUHLT.js";
import "./chunk-VGC4I5JJ.js";
import "./chunk-MUP3T3AD.js";
import "./chunk-XMGHVNVM.js";
import "./chunk-46UV252V.js";
import "./chunk-A4UCTEB5.js";
import "./chunk-XWRJCPHC.js";
import "./chunk-UW5EOVUN.js";
import "./chunk-2JZBVYTU.js";
import "./chunk-5I2IWRSH.js";
import "./chunk-A5L3JMUA.js";
import "./chunk-MB4MZHMJ.js";
import "./chunk-HTR4WV6U.js";
import "./chunk-BULDBTYC.js";
import "./chunk-U7ZFW55U.js";
import "./chunk-UUUTRMI2.js";
import "./chunk-PR75REBZ.js";
import "./chunk-NL7LTRLR.js";
import "./chunk-ORRBUII2.js";
import {
  runExitCleanup
} from "./chunk-B3OSEIVI.js";
import "./chunk-75DOP5OR.js";
import "./chunk-DMTGGOSA.js";
import "./chunk-YQ3U5MUC.js";
import "./chunk-AMDSOFFV.js";
import "./chunk-TARRHLLG.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
 */
