// Force strict mode and setup for ESM
"use strict";
import {
  JsonOutputAdapter
} from "./chunk-VRWF6GBH.js";
import {
  StreamJsonOutputAdapter
} from "./chunk-K5F7YFCW.js";
import "./chunk-OP2L5DEJ.js";
import "./chunk-RTA4523Y.js";
import {
  validateAuthMethod
} from "./chunk-SBVFRVWZ.js";
import "./chunk-XSFZYF3O.js";
import "./chunk-UIDXQNMV.js";
import "./chunk-MRO43B25.js";
import "./chunk-BGKMPXRD.js";
import "./chunk-JZSY4WP3.js";
import "./chunk-332PWN27.js";
import "./chunk-5BB7P4EY.js";
import "./chunk-SAIILPQ3.js";
import "./chunk-KYMBIKIW.js";
import "./chunk-PC4ZXHU2.js";
import "./chunk-KDP55F4Y.js";
import "./chunk-2XTGXPKN.js";
import "./chunk-LGFAYIKX.js";
import "./chunk-54YZOP7P.js";
import "./chunk-AHNXYU4O.js";
import "./chunk-RNBYOUGV.js";
import "./chunk-OO5PC2SN.js";
import "./chunk-BJBWRCSK.js";
import "./chunk-7LMKD6WU.js";
import "./chunk-3GONHQOA.js";
import "./chunk-2ICBEJ7Q.js";
import "./chunk-CD6USWHZ.js";
import "./chunk-Y7LCGSUV.js";
import "./chunk-KHDZHZMH.js";
import "./chunk-6FEODJFG.js";
import "./chunk-BPJGZ3LF.js";
import "./chunk-E7KNELIZ.js";
import "./chunk-3UP777ZS.js";
import "./chunk-GLE2YUPU.js";
import "./chunk-ER3BKOLB.js";
import "./chunk-VP4BSXT4.js";
import "./chunk-S6RLAIUR.js";
import "./chunk-MX2YXRER.js";
import "./chunk-IBY3Q3HG.js";
import "./chunk-VRDMOSQS.js";
import "./chunk-MZ7BABX3.js";
import "./chunk-AVTRLOL5.js";
import "./chunk-YDIHXLRH.js";
import "./chunk-TLRYABYP.js";
import "./chunk-P2XFY4TW.js";
import "./chunk-O2YT7VB4.js";
import "./chunk-Z3I3QJK3.js";
import "./chunk-3RW4AZJV.js";
import "./chunk-UXEW557D.js";
import "./chunk-43W4YSO6.js";
import "./chunk-JD32S2TT.js";
import {
  writeStderrLine
} from "./chunk-Y6Z2O3WR.js";
import "./chunk-QYUE6W3T.js";
import "./chunk-33JSFFSK.js";
import "./chunk-5P5XGNYH.js";
import "./chunk-SKAZWEV5.js";
import "./chunk-K5PGHDBN.js";
import "./chunk-3B26UVCX.js";
import "./chunk-W7EEOR7D.js";
import "./chunk-42XGFRJS.js";
import "./chunk-X2XNQQJI.js";
import "./chunk-VZ7HY3YU.js";
import "./chunk-2MPVVENX.js";
import "./chunk-ZTQ26VBE.js";
import "./chunk-FV7425LN.js";
import "./chunk-MLZQVCF3.js";
import "./chunk-LQ7TMOCE.js";
import "./chunk-E5A7LHNN.js";
import "./chunk-5MBO76SL.js";
import "./chunk-GO6LNQXT.js";
import "./chunk-NQKLOAVJ.js";
import "./chunk-WMPVYQ4P.js";
import "./chunk-TLWA7TPR.js";
import "./chunk-QYNNN7BK.js";
import "./chunk-G2DUQQCZ.js";
import "./chunk-E6US47KI.js";
import "./chunk-UWCTAVOD.js";
import "./chunk-OFEVLU4C.js";
import "./chunk-OMX7CUOE.js";
import "./chunk-OACJLMLD.js";
import "./chunk-SUAKHHK7.js";
import "./chunk-FEJ2FZ3U.js";
import "./chunk-X3YGAX7V.js";
import "./chunk-IJRL2S3D.js";
import "./chunk-AHNJGLFV.js";
import "./chunk-22IFUCVR.js";
import "./chunk-7LTB54MK.js";
import "./chunk-SIUQ3YYX.js";
import "./chunk-HW4N45EE.js";
import "./chunk-CCGOFQV3.js";
import "./chunk-IRJWHZWU.js";
import "./chunk-SYCJMSIJ.js";
import "./chunk-55ZMG67I.js";
import "./chunk-H6BD2ELD.js";
import "./chunk-5IFG2VC4.js";
import "./chunk-64WXLC72.js";
import "./chunk-H6EMK6QK.js";
import "./chunk-22MNNNXE.js";
import "./chunk-S4CI7EP4.js";
import {
  runExitCleanup
} from "./chunk-G5WBP2OU.js";
import "./chunk-ZERZSAZL.js";
import "./chunk-QN5NZ3UQ.js";
import "./chunk-BR4QREVK.js";
import "./chunk-Z2Z3GUXZ.js";
import {
  init_esbuild_shims
} from "./chunk-A4BMJM77.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
 */
