// Force strict mode and setup for ESM
"use strict";
import {
  JsonOutputAdapter
} from "./chunk-IQTDXWNO.js";
import {
  StreamJsonOutputAdapter
} from "./chunk-JFAQSIKH.js";
import "./chunk-IOUTT7JI.js";
import {
  validateAuthMethod
} from "./chunk-BQJ6TBKZ.js";
import "./chunk-LZCPMLHE.js";
import "./chunk-MRO43B25.js";
import "./chunk-5R3TYJMX.js";
import "./chunk-JZSY4WP3.js";
import "./chunk-BHGGZQJW.js";
import "./chunk-KSPVDFE4.js";
import "./chunk-KYMBIKIW.js";
import "./chunk-IXZPFINU.js";
import "./chunk-3GONHQOA.js";
import "./chunk-MRUO7FTA.js";
import "./chunk-Z7XXFPGP.js";
import "./chunk-JXQ23SNT.js";
import "./chunk-TMBPDHXD.js";
import "./chunk-AGPXXQGK.js";
import "./chunk-OTMXHDIT.js";
import "./chunk-BRE6DKMG.js";
import "./chunk-KHDZHZMH.js";
import "./chunk-KTRBLEVJ.js";
import "./chunk-BS64PXY3.js";
import "./chunk-VKCEKYGE.js";
import "./chunk-R2BXK7SX.js";
import "./chunk-ALX6BUYW.js";
import "./chunk-5DWXLGOM.js";
import "./chunk-YIWSVFAL.js";
import "./chunk-MNFF5DCS.js";
import "./chunk-TLRYABYP.js";
import {
  writeStderrLine
} from "./chunk-Y6Z2O3WR.js";
import "./chunk-UFC57OYT.js";
import "./chunk-UN3C6GOR.js";
import "./chunk-Z3SLAUKQ.js";
import "./chunk-K5PGHDBN.js";
import "./chunk-5P5XGNYH.js";
import "./chunk-SKAZWEV5.js";
import "./chunk-TXVGVZYR.js";
import "./chunk-XU5P23GN.js";
import "./chunk-2BIF2NVV.js";
import "./chunk-BG4BIP7F.js";
import "./chunk-ZD3NW5KL.js";
import "./chunk-2MPVVENX.js";
import "./chunk-ZTQ26VBE.js";
import "./chunk-GZCJS5WH.js";
import "./chunk-MLZQVCF3.js";
import "./chunk-LQ7TMOCE.js";
import "./chunk-LD2XBG6Z.js";
import "./chunk-OTBK43JR.js";
import "./chunk-HGNSRCRB.js";
import "./chunk-EEEZIVFJ.js";
import "./chunk-PRYMDRBV.js";
import "./chunk-QSRNLMOT.js";
import "./chunk-3PJXIDKI.js";
import "./chunk-UWCTAVOD.js";
import "./chunk-OFEVLU4C.js";
import "./chunk-OMX7CUOE.js";
import "./chunk-BNXANYLH.js";
import "./chunk-T2VDEFUU.js";
import "./chunk-OIC6S73E.js";
import "./chunk-TOEGRAVX.js";
import "./chunk-BGUDAULQ.js";
import "./chunk-EW6C27XX.js";
import "./chunk-22IFUCVR.js";
import "./chunk-64WXLC72.js";
import "./chunk-3UALQ56H.js";
import "./chunk-F6XNTYNE.js";
import "./chunk-CGEGHF2C.js";
import "./chunk-IRJWHZWU.js";
import "./chunk-SYCJMSIJ.js";
import "./chunk-55ZMG67I.js";
import "./chunk-H6BD2ELD.js";
import "./chunk-5IFG2VC4.js";
import "./chunk-C4K3FEQ2.js";
import "./chunk-SREM22RZ.js";
import {
  runExitCleanup
} from "./chunk-UW64XR25.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
 */
