// Force strict mode and setup for ESM
"use strict";
import {
  JsonOutputAdapter
} from "./chunk-YTI63CQW.js";
import {
  StreamJsonOutputAdapter
} from "./chunk-37K24W4Y.js";
import "./chunk-H2S47HYW.js";
import {
  validateAuthMethod
} from "./chunk-A5AG664O.js";
import "./chunk-XL5WDTO5.js";
import "./chunk-RMXPR6HS.js";
import "./chunk-KSPVDFE4.js";
import "./chunk-MRO43B25.js";
import "./chunk-4FRUXVSE.js";
import "./chunk-KYMBIKIW.js";
import "./chunk-HTWHAN44.js";
import "./chunk-JZSY4WP3.js";
import "./chunk-ZHGT5WWW.js";
import "./chunk-3GONHQOA.js";
import "./chunk-V655JORE.js";
import "./chunk-ZI4MGBB5.js";
import "./chunk-L7QPM2YD.js";
import "./chunk-54YZOP7P.js";
import "./chunk-UVNBI7NN.js";
import "./chunk-PFS2I5LF.js";
import "./chunk-KHDZHZMH.js";
import "./chunk-A76FGLIX.js";
import "./chunk-YQARVN3E.js";
import "./chunk-NIOPRZNN.js";
import "./chunk-AHNXYU4O.js";
import "./chunk-RNBYOUGV.js";
import "./chunk-Q5JX2J3K.js";
import "./chunk-BJBWRCSK.js";
import "./chunk-QFVH4WQN.js";
import "./chunk-6BEOH4KK.js";
import "./chunk-S6RLAIUR.js";
import "./chunk-MX2YXRER.js";
import "./chunk-YHTNWGRR.js";
import "./chunk-AFPB2TZB.js";
import "./chunk-RYT2ET4O.js";
import "./chunk-TLRYABYP.js";
import "./chunk-4RQIB5UZ.js";
import "./chunk-SEZC2725.js";
import "./chunk-ALX6BUYW.js";
import "./chunk-VRDMOSQS.js";
import "./chunk-3RW4AZJV.js";
import "./chunk-SL2P3JUA.js";
import "./chunk-CJSSVQAR.js";
import {
  writeStderrLine
} from "./chunk-Y6Z2O3WR.js";
import "./chunk-QYUE6W3T.js";
import "./chunk-IQ7FOOIH.js";
import "./chunk-5P5XGNYH.js";
import "./chunk-SKAZWEV5.js";
import "./chunk-K5PGHDBN.js";
import "./chunk-CLQPBI4H.js";
import "./chunk-QOMAHFYI.js";
import "./chunk-G7OQ3RFJ.js";
import "./chunk-LKWAVAB5.js";
import "./chunk-5ES5YPED.js";
import "./chunk-2MPVVENX.js";
import "./chunk-ZTQ26VBE.js";
import "./chunk-DMSNJDWG.js";
import "./chunk-MLZQVCF3.js";
import "./chunk-LQ7TMOCE.js";
import "./chunk-E5A7LHNN.js";
import "./chunk-LM3YCCZJ.js";
import "./chunk-GO6LNQXT.js";
import "./chunk-B236XPGF.js";
import "./chunk-NVFJSIAX.js";
import "./chunk-TOAUDIS7.js";
import "./chunk-NPQWQYU6.js";
import "./chunk-4IUH45NF.js";
import "./chunk-E6US47KI.js";
import "./chunk-UWCTAVOD.js";
import "./chunk-OFEVLU4C.js";
import "./chunk-OMX7CUOE.js";
import "./chunk-MOUXUCXQ.js";
import "./chunk-BZHLWC6T.js";
import "./chunk-RZORUN6X.js";
import "./chunk-MJKMIQMK.js";
import "./chunk-TENOUWY2.js";
import "./chunk-GLPV75ES.js";
import "./chunk-22IFUCVR.js";
import "./chunk-T42ACHFI.js";
import "./chunk-SIUQ3YYX.js";
import "./chunk-KYTQOCDE.js";
import "./chunk-YPCPZSZB.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-D5KISTLW.js";
import "./chunk-AVQDCKNF.js";
import "./chunk-DTPH7UZK.js";
import {
  runExitCleanup
} from "./chunk-N2OMTT2Q.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
 */
