// Force strict mode and setup for ESM
"use strict";
import {
  JsonOutputAdapter
} from "./chunk-JCEC4F3B.js";
import {
  StreamJsonOutputAdapter
} from "./chunk-VHYSSUL4.js";
import "./chunk-WTU4ESNU.js";
import {
  validateAuthMethod
} from "./chunk-ZUK7DUKT.js";
import "./chunk-CCNHOHUU.js";
import "./chunk-RWKXZNQI.js";
import "./chunk-KSPVDFE4.js";
import "./chunk-MRO43B25.js";
import "./chunk-QSH43RBM.js";
import "./chunk-KYMBIKIW.js";
import "./chunk-I4H7PRWQ.js";
import "./chunk-JZSY4WP3.js";
import "./chunk-3QGQ36XF.js";
import "./chunk-A6LL24PP.js";
import "./chunk-3GONHQOA.js";
import "./chunk-SDKIIW3X.js";
import "./chunk-CKQA6AWF.js";
import "./chunk-BW4KCQFD.js";
import "./chunk-NDOC6M5S.js";
import "./chunk-M2U5NM24.js";
import "./chunk-ZDGYN5JJ.js";
import "./chunk-R2BXK7SX.js";
import "./chunk-HUHK3GBD.js";
import "./chunk-KHDZHZMH.js";
import "./chunk-4MFEVJCC.js";
import "./chunk-YNCWXXEA.js";
import "./chunk-BC3C4F3Q.js";
import "./chunk-GT2FGICD.js";
import "./chunk-ALX6BUYW.js";
import "./chunk-YTN7HXEJ.js";
import "./chunk-3BPQCJOE.js";
import "./chunk-TLRYABYP.js";
import "./chunk-5DWXLGOM.js";
import "./chunk-UFC57OYT.js";
import "./chunk-CF6BB3LT.js";
import "./chunk-34N4MKYG.js";
import {
  writeStderrLine
} from "./chunk-Y6Z2O3WR.js";
import "./chunk-QYUE6W3T.js";
import "./chunk-35BVDZGM.js";
import "./chunk-K5PGHDBN.js";
import "./chunk-SKAZWEV5.js";
import "./chunk-XJYUPHRC.js";
import "./chunk-QLDPRILK.js";
import "./chunk-BVSVIN45.js";
import "./chunk-SBBN4BWR.js";
import "./chunk-S7AKE7HL.js";
import "./chunk-2MPVVENX.js";
import "./chunk-ZTQ26VBE.js";
import "./chunk-O2VBQ3Y2.js";
import "./chunk-MLZQVCF3.js";
import "./chunk-LQ7TMOCE.js";
import "./chunk-LD2XBG6Z.js";
import "./chunk-HYCC3XM3.js";
import "./chunk-NL4C3H6C.js";
import "./chunk-JOLIREYR.js";
import "./chunk-DDMOU62Q.js";
import "./chunk-NY5MEIAL.js";
import "./chunk-3PJXIDKI.js";
import "./chunk-UWCTAVOD.js";
import "./chunk-OFEVLU4C.js";
import "./chunk-OMX7CUOE.js";
import "./chunk-RD6YJJJ6.js";
import "./chunk-SKQZZVAV.js";
import "./chunk-BUUQ5HPX.js";
import "./chunk-BX5YO7UW.js";
import "./chunk-UO5GVXQE.js";
import "./chunk-KMGMKW5Q.js";
import "./chunk-22IFUCVR.js";
import "./chunk-3227DZO4.js";
import "./chunk-U3KSMM7G.js";
import "./chunk-BKXBARJZ.js";
import "./chunk-EJYJYJZ2.js";
import "./chunk-55ZMG67I.js";
import "./chunk-H6BD2ELD.js";
import "./chunk-5IFG2VC4.js";
import "./chunk-64WXLC72.js";
import "./chunk-UX4SGCGN.js";
import "./chunk-RHZUI73P.js";
import {
  runExitCleanup
} from "./chunk-YDUDLS3E.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
 */
