// Force strict mode and setup for ESM
"use strict";
import {
  JsonOutputAdapter
} from "./chunk-K2J5JZ6B.js";
import {
  StreamJsonOutputAdapter
} from "./chunk-L7FTDKCD.js";
import "./chunk-4AGGSHCH.js";
import {
  validateAuthMethod
} from "./chunk-QPSYIV2O.js";
import "./chunk-NYX53SV4.js";
import "./chunk-SKSF3LGQ.js";
import "./chunk-LZV2BZPL.js";
import "./chunk-3LGZEYOF.js";
import "./chunk-4WGODMVR.js";
import "./chunk-YWMDTMAU.js";
import "./chunk-KKN2IE7Q.js";
import "./chunk-BSKUTHLO.js";
import "./chunk-6H67XLET.js";
import "./chunk-MTR4JWQJ.js";
import "./chunk-EGYJRIDF.js";
import "./chunk-YAF2MQZ6.js";
import "./chunk-VUNRNRN6.js";
import "./chunk-DYA25Y7U.js";
import "./chunk-4NFY2S7N.js";
import "./chunk-N42C2FU3.js";
import "./chunk-2MIN6GRR.js";
import "./chunk-QHTIBUWB.js";
import "./chunk-EKTCKZV5.js";
import "./chunk-3Z43GZUQ.js";
import "./chunk-RXFQM6FQ.js";
import "./chunk-BKGA75MU.js";
import "./chunk-JELIWHXD.js";
import "./chunk-Z4X5MTRT.js";
import "./chunk-2LZCLQIS.js";
import "./chunk-D2GPKXCQ.js";
import "./chunk-57OAHC2Y.js";
import "./chunk-QWDVZH24.js";
import "./chunk-3SH53ANB.js";
import "./chunk-GLWP3FDB.js";
import "./chunk-XCGIMOLN.js";
import "./chunk-5VYFXHY2.js";
import "./chunk-LGT3YMLN.js";
import "./chunk-X6WUYMOV.js";
import "./chunk-VWOVHOTT.js";
import "./chunk-V6WHFGST.js";
import "./chunk-6PLDPT2C.js";
import "./chunk-FYJ7W2PI.js";
import "./chunk-QONSRAEV.js";
import "./chunk-24ER7UV4.js";
import "./chunk-ALMR3E6Q.js";
import "./chunk-BK2UNYWD.js";
import "./chunk-M5GB774H.js";
import "./chunk-XC2VAFVZ.js";
import "./chunk-WUC6ZFXO.js";
import "./chunk-DIEFUBV6.js";
import "./chunk-UDXSXLER.js";
import "./chunk-2MI7ZTRT.js";
import "./chunk-22YFMJBW.js";
import "./chunk-RKUWKYED.js";
import "./chunk-GOXKNSDZ.js";
import "./chunk-IDS7MSUP.js";
import "./chunk-KXWERR6P.js";
import "./chunk-6NE5NTHJ.js";
import "./chunk-6PEXNQTX.js";
import "./chunk-FXVHVCNA.js";
import "./chunk-BKXTHMOZ.js";
import "./chunk-VJNBRRZG.js";
import "./chunk-M5LIY7Y6.js";
import "./chunk-ALGGS7UH.js";
import "./chunk-MR3PXB6E.js";
import "./chunk-XFSFZCM5.js";
import "./chunk-UQDFEU47.js";
import "./chunk-GOFAQQZA.js";
import "./chunk-5M6IDOMF.js";
import "./chunk-TWPJO254.js";
import "./chunk-H6XPXXMH.js";
import "./chunk-VA5NLVPT.js";
import "./chunk-I7JDGNG6.js";
import "./chunk-A6SX5TAH.js";
import "./chunk-33FNCQSY.js";
import "./chunk-6PVPNMXU.js";
import "./chunk-XUMAD5IT.js";
import "./chunk-IRH27ZC2.js";
import "./chunk-QHWCP53L.js";
import "./chunk-MOHAWIAW.js";
import "./chunk-X6QNZOTC.js";
import "./chunk-O6GEWCJA.js";
import "./chunk-T26EAKDL.js";
import "./chunk-ZPJWUGCS.js";
import "./chunk-CPBF7KYF.js";
import "./chunk-MISUEWB4.js";
import "./chunk-KRXPRVGL.js";
import "./chunk-A5YZ3FA2.js";
import "./chunk-YAVY33G4.js";
import "./chunk-2UISUFHQ.js";
import "./chunk-HFVW54NL.js";
import "./chunk-TZTBZ25J.js";
import "./chunk-S6LOFUVP.js";
import "./chunk-SRY26X4H.js";
import "./chunk-K623ENWT.js";
import "./chunk-AQ37AY7B.js";
import "./chunk-432XCUHF.js";
import "./chunk-XC656O42.js";
import "./chunk-NAVJD2PQ.js";
import "./chunk-QYPT3QUD.js";
import "./chunk-QMBEW7EW.js";
import "./chunk-DGEIYUC3.js";
import "./chunk-MPHPFVKK.js";
import "./chunk-GLNBDYUX.js";
import "./chunk-DJ2GSRLV.js";
import "./chunk-EIMKVOSF.js";
import "./chunk-RPYYTL7E.js";
import "./chunk-2J3OJGTL.js";
import "./chunk-P3QQPMQA.js";
import "./chunk-6O5DVH27.js";
import "./chunk-GLCZKT5V.js";
import "./chunk-2DNKEBXY.js";
import "./chunk-4K3RV3OA.js";
import "./chunk-VGC4I5JJ.js";
import "./chunk-E4WHKETF.js";
import "./chunk-UEJESCS7.js";
import "./chunk-CFDR3GNL.js";
import "./chunk-H35Q5CEG.js";
import "./chunk-46UV252V.js";
import "./chunk-ZBVS26BY.js";
import "./chunk-BFHXDAR7.js";
import "./chunk-TYERNYH4.js";
import "./chunk-UH7Z7Y45.js";
import "./chunk-O2ZYHG33.js";
import "./chunk-W4RQUHY3.js";
import "./chunk-G7XXKQYS.js";
import "./chunk-3RXUYQJI.js";
import "./chunk-VOQXFAY5.js";
import "./chunk-R7XNRHYD.js";
import {
  runExitCleanup
} from "./chunk-QDWLUXKP.js";
import {
  writeStderrLine
} from "./chunk-OWAK7LMW.js";
import "./chunk-75DOP5OR.js";
import "./chunk-DMTGGOSA.js";
import "./chunk-YQ3U5MUC.js";
import "./chunk-AMDSOFFV.js";
import "./chunk-QUGAUQGJ.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
 */
