// Force strict mode and setup for ESM
"use strict";
import {
  JsonOutputAdapter
} from "./chunk-RLQ2YLU2.js";
import {
  StreamJsonOutputAdapter
} from "./chunk-DZHNHLWJ.js";
import "./chunk-R2QLXT5B.js";
import "./chunk-TKWUGWY2.js";
import {
  validateAuthMethod
} from "./chunk-NIPAOHN7.js";
import "./chunk-HA265XCO.js";
import "./chunk-4WGODMVR.js";
import "./chunk-KW7NOTN6.js";
import "./chunk-OWT2CAEQ.js";
import "./chunk-5DTTYNB7.js";
import "./chunk-NHDKSOEY.js";
import "./chunk-7X7TEQNX.js";
import "./chunk-HTHUX2T5.js";
import "./chunk-3NSEG2TI.js";
import "./chunk-LNSBEROZ.js";
import "./chunk-YAF2MQZ6.js";
import "./chunk-Q6TUALBE.js";
import "./chunk-RUBITYOH.js";
import "./chunk-2LLVTJVN.js";
import "./chunk-SUARMD4Q.js";
import "./chunk-QHTIBUWB.js";
import "./chunk-L573Z2QZ.js";
import "./chunk-RXFQM6FQ.js";
import "./chunk-EDQSOIDV.js";
import "./chunk-6H67XLET.js";
import "./chunk-LOEHQQGN.js";
import "./chunk-C6FMZ4E2.js";
import "./chunk-T3LXCZZR.js";
import "./chunk-E5Z2AVNV.js";
import "./chunk-EP7UQGYV.js";
import "./chunk-2WNF6DDX.js";
import "./chunk-FSA7ERJ2.js";
import "./chunk-6RLROE6G.js";
import "./chunk-COH43MRJ.js";
import "./chunk-4D44WPU4.js";
import "./chunk-XPAQP74F.js";
import "./chunk-57OAHC2Y.js";
import "./chunk-5CNYZ7TN.js";
import "./chunk-FNX3LGAK.js";
import "./chunk-V6WHFGST.js";
import "./chunk-W7FJ3N32.js";
import "./chunk-KSZKSE23.js";
import "./chunk-TJTKSVIV.js";
import "./chunk-M5GB774H.js";
import "./chunk-LXLTBIDP.js";
import "./chunk-3DWIFU7L.js";
import "./chunk-ZQIYGQCG.js";
import "./chunk-UDXSXLER.js";
import "./chunk-IOCFZ7EG.js";
import "./chunk-BYFID5BL.js";
import "./chunk-RKUWKYED.js";
import "./chunk-W7RFHI5L.js";
import "./chunk-ENW2BPUW.js";
import "./chunk-GOXKNSDZ.js";
import "./chunk-IDS7MSUP.js";
import "./chunk-QRUIS3DN.js";
import "./chunk-FXXY6GR5.js";
import "./chunk-ALGGS7UH.js";
import "./chunk-MR3PXB6E.js";
import {
  writeStderrLine
} from "./chunk-YUZI3WAC.js";
import "./chunk-XFSFZCM5.js";
import "./chunk-GLNHPRZT.js";
import "./chunk-VJNBRRZG.js";
import "./chunk-KN5EBZLT.js";
import "./chunk-T4TZQJ7W.js";
import "./chunk-H6XPXXMH.js";
import "./chunk-5M6IDOMF.js";
import "./chunk-A2HWMJVO.js";
import "./chunk-RCEEXIOO.js";
import "./chunk-KKRTYONM.js";
import "./chunk-TV6K2FB4.js";
import "./chunk-E2UVIFI2.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-F333XEAU.js";
import "./chunk-6AM5D4ME.js";
import "./chunk-2Z5UX4KI.js";
import "./chunk-ARKANCNX.js";
import "./chunk-L5U3ELZX.js";
import "./chunk-TYLOFD2U.js";
import "./chunk-D5K5YBSN.js";
import "./chunk-4WKAA4KS.js";
import "./chunk-CR3C7WXL.js";
import "./chunk-RTV5TUYB.js";
import "./chunk-VGC4I5JJ.js";
import "./chunk-FBU7WRZI.js";
import "./chunk-Y66VOBRP.js";
import "./chunk-WTNZ6DXB.js";
import "./chunk-JGUT3LWZ.js";
import "./chunk-OKAIGAYW.js";
import "./chunk-ZPAHLFZU.js";
import "./chunk-JESCGQM3.js";
import "./chunk-WIEO4CWB.js";
import "./chunk-XVNQMZ2I.js";
import "./chunk-FEOZBUMT.js";
import "./chunk-VRR65QYW.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-5YAXXN3N.js";
import {
  runExitCleanup
} from "./chunk-B3ILMEBG.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
 */
