// Force strict mode and setup for ESM
"use strict";
import {
  JsonOutputAdapter
} from "./chunk-SAYQLXZH.js";
import {
  StreamJsonOutputAdapter
} from "./chunk-E7LZPYFT.js";
import "./chunk-HDLTQYGQ.js";
import {
  validateAuthMethod
} from "./chunk-GV2ATJZE.js";
import "./chunk-5DTTYNB7.js";
import "./chunk-SBLYV3PV.js";
import "./chunk-EM5Y5UEQ.js";
import "./chunk-4WGODMVR.js";
import "./chunk-7X7TEQNX.js";
import "./chunk-KW7NOTN6.js";
import "./chunk-A56Y57JE.js";
import "./chunk-HTHUX2T5.js";
import "./chunk-MXL5UP4X.js";
import "./chunk-ZWCCOM5N.js";
import "./chunk-6IG3II5H.js";
import "./chunk-NHDKSOEY.js";
import "./chunk-4WOUSFC6.js";
import "./chunk-KRAYLJ55.js";
import "./chunk-YAF2MQZ6.js";
import "./chunk-5OJ3CKHW.js";
import "./chunk-GF7DN6DM.js";
import "./chunk-PORZCTMD.js";
import "./chunk-QHTIBUWB.js";
import "./chunk-L573Z2QZ.js";
import "./chunk-R36BRABX.js";
import "./chunk-LK7KUE55.js";
import "./chunk-RXFQM6FQ.js";
import "./chunk-O6YRTRJ2.js";
import "./chunk-6H67XLET.js";
import "./chunk-AROQDALD.js";
import "./chunk-PHQYFSK3.js";
import "./chunk-57OAHC2Y.js";
import "./chunk-TO6QE22P.js";
import "./chunk-CZB7MTWL.js";
import "./chunk-E5Z2AVNV.js";
import "./chunk-W7FJ3N32.js";
import "./chunk-6RLROE6G.js";
import "./chunk-COH43MRJ.js";
import "./chunk-EZOVDYWW.js";
import "./chunk-DC5Z3DU6.js";
import "./chunk-V6WHFGST.js";
import "./chunk-CUMMSHH6.js";
import "./chunk-LA7NAGHS.js";
import "./chunk-OEXD6A4O.js";
import "./chunk-RKUWKYED.js";
import "./chunk-3KABBD2Y.js";
import "./chunk-Q6RNYJHR.js";
import "./chunk-3BTRNWWD.js";
import "./chunk-QRUIS3DN.js";
import "./chunk-X4NKFGFJ.js";
import "./chunk-TJTKSVIV.js";
import "./chunk-34Z3U5RQ.js";
import "./chunk-UDXSXLER.js";
import "./chunk-P4LSFDXT.js";
import "./chunk-RDJSGHZE.js";
import "./chunk-XFSFZCM5.js";
import "./chunk-3AHXV67U.js";
import "./chunk-VJNBRRZG.js";
import {
  writeStderrLine
} from "./chunk-YUZI3WAC.js";
import "./chunk-GTPXQPDZ.js";
import "./chunk-CU3L64TP.js";
import "./chunk-ZJE7NSL3.js";
import "./chunk-H6XPXXMH.js";
import "./chunk-MC23XKFE.js";
import "./chunk-LUODI7WD.js";
import "./chunk-ORBGV7NJ.js";
import "./chunk-KKNMOEZH.js";
import "./chunk-W2UIXQDL.js";
import "./chunk-XU457J4V.js";
import "./chunk-VDDGDZMA.js";
import "./chunk-CEA3E3JB.js";
import "./chunk-SZRN75WQ.js";
import "./chunk-HTO4JFDZ.js";
import "./chunk-CPBF7KYF.js";
import "./chunk-4GORAUCN.js";
import "./chunk-6AM5D4ME.js";
import "./chunk-7R3CZA3Q.js";
import "./chunk-GWHYEOV2.js";
import "./chunk-4QLQE5WJ.js";
import "./chunk-5XUCZNSY.js";
import "./chunk-Z6TQUGBD.js";
import "./chunk-4WKAA4KS.js";
import "./chunk-CR3C7WXL.js";
import "./chunk-CARU2RR2.js";
import "./chunk-VGC4I5JJ.js";
import "./chunk-YLV3XXFB.js";
import "./chunk-TDEXZKMT.js";
import "./chunk-J3JA76CF.js";
import "./chunk-B5ORX3FG.js";
import "./chunk-BZIFY5TF.js";
import "./chunk-UOZWKTQG.js";
import "./chunk-JESCGQM3.js";
import "./chunk-ZLXQN2QS.js";
import "./chunk-XVNQMZ2I.js";
import "./chunk-524RQP4Q.js";
import "./chunk-JSG7ZSBC.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-4ZVWQHEQ.js";
import "./chunk-J4TSQ5EQ.js";
import "./chunk-RYNHJV45.js";
import {
  runExitCleanup
} from "./chunk-T46HAIUL.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
 */
