// Force strict mode and setup for ESM
"use strict";
import {
  JsonOutputAdapter
} from "./chunk-KQQOQW2G.js";
import {
  StreamJsonOutputAdapter
} from "./chunk-77DA5V36.js";
import "./chunk-YYQUSZ7E.js";
import {
  validateAuthMethod
} from "./chunk-4NI5ZHZX.js";
import "./chunk-NE6ZKPLE.js";
import "./chunk-GUPCOLB6.js";
import "./chunk-JZSY4WP3.js";
import "./chunk-OWNGLJFY.js";
import "./chunk-UIDXQNMV.js";
import "./chunk-332PWN27.js";
import "./chunk-3TBL4BB6.js";
import "./chunk-SAIILPQ3.js";
import "./chunk-KYMBIKIW.js";
import "./chunk-PC4ZXHU2.js";
import "./chunk-MRO43B25.js";
import "./chunk-LH3NWRM6.js";
import "./chunk-3GONHQOA.js";
import "./chunk-ZBMICDVO.js";
import "./chunk-TBAZMRW3.js";
import "./chunk-FAOIINFF.js";
import "./chunk-HVZGJ6K6.js";
import "./chunk-LGFAYIKX.js";
import "./chunk-54YZOP7P.js";
import "./chunk-H7CFVAK4.js";
import "./chunk-KHDZHZMH.js";
import "./chunk-FL6R4YJT.js";
import "./chunk-GCBZFZIM.js";
import "./chunk-E7KNELIZ.js";
import "./chunk-AHNXYU4O.js";
import "./chunk-RNBYOUGV.js";
import "./chunk-F32H6DLU.js";
import "./chunk-BJBWRCSK.js";
import "./chunk-PJM2CCVW.js";
import "./chunk-2NPS2UDH.js";
import "./chunk-S6RLAIUR.js";
import "./chunk-MX2YXRER.js";
import "./chunk-MZ7BABX3.js";
import "./chunk-T2VZET4K.js";
import "./chunk-QENLOLC3.js";
import "./chunk-TLRYABYP.js";
import "./chunk-4RQIB5UZ.js";
import "./chunk-ER3BKOLB.js";
import "./chunk-G7ZG7CA6.js";
import "./chunk-VRDMOSQS.js";
import "./chunk-3RW4AZJV.js";
import "./chunk-GD236YPV.js";
import "./chunk-43W4YSO6.js";
import "./chunk-OBKTTPVV.js";
import {
  writeStderrLine
} from "./chunk-Y6Z2O3WR.js";
import "./chunk-QYUE6W3T.js";
import "./chunk-3WF4AE5A.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-VEB3NYSO.js";
import "./chunk-GO6LNQXT.js";
import "./chunk-NQKLOAVJ.js";
import "./chunk-WMPVYQ4P.js";
import "./chunk-TLWA7TPR.js";
import "./chunk-QYNNN7BK.js";
import "./chunk-42UAVOGU.js";
import "./chunk-E6US47KI.js";
import "./chunk-UWCTAVOD.js";
import "./chunk-OFEVLU4C.js";
import "./chunk-OMX7CUOE.js";
import "./chunk-4KJ2BPIT.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-DZP5BAZF.js";
import {
  runExitCleanup
} from "./chunk-ZDFW7D5C.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
 */
