CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes48downloads
validateNonInterActiveAuth.js66 linesDownload Raw Back to src
1/**2 * @license3 * Copyright 2025 Google LLC4 * SPDX-License-Identifier: Apache-2.05 */6import { OutputFormat } from '@qwen-code/qwen-code-core';7import { validateAuthMethod } from './config/auth.js';8import {} from './config/settings.js';9import { JsonOutputAdapter } from './nonInteractive/io/JsonOutputAdapter.js';10import { StreamJsonOutputAdapter } from './nonInteractive/io/StreamJsonOutputAdapter.js';11import { runExitCleanup } from './utils/cleanup.js';12import { writeStderrLine } from './utils/stdioHelpers.js';13export async function validateNonInteractiveAuth(useExternalAuth, nonInteractiveConfig, settings) {14    try {15        // Get the actual authType from config which has already resolved CLI args, env vars, and settings16        const authType = nonInteractiveConfig17            .getModelsConfig()18            .getCurrentAuthType();19        if (!authType) {20            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.');21        }22        const resolvedAuthType = authType;23        const enforcedType = settings.merged.security?.auth?.enforcedType;24        if (enforcedType && enforcedType !== resolvedAuthType) {25            const message = `The configured auth type is ${enforcedType}, but the current auth type is ${resolvedAuthType}. Please re-authenticate with the correct type.`;26            throw new Error(message);27        }28        if (!useExternalAuth) {29            const err = validateAuthMethod(resolvedAuthType, nonInteractiveConfig);30            if (err != null) {31                throw new Error(err);32            }33        }34        await nonInteractiveConfig.refreshAuth(resolvedAuthType);35        return nonInteractiveConfig;36    }37    catch (error) {38        const outputFormat = nonInteractiveConfig.getOutputFormat();39        // In JSON and STREAM_JSON modes, emit error result and exit40        if (outputFormat === OutputFormat.JSON ||41            outputFormat === OutputFormat.STREAM_JSON) {42            let adapter;43            if (outputFormat === OutputFormat.JSON) {44                adapter = new JsonOutputAdapter(nonInteractiveConfig);45            }46            else {47                adapter = new StreamJsonOutputAdapter(nonInteractiveConfig, nonInteractiveConfig.getIncludePartialMessages());48            }49            const errorMessage = error instanceof Error ? error.message : String(error);50            adapter.emitResult({51                isError: true,52                errorMessage,53                durationMs: 0,54                apiDurationMs: 0,55                numTurns: 0,56                usage: undefined,57            });58            await runExitCleanup();59            process.exit(1);60        }61        // For other modes (text), use existing error handling62        writeStderrLine(error instanceof Error ? error.message : String(error));63        process.exit(1);64    }65}66//# sourceMappingURL=validateNonInterActiveAuth.js.map
basant307/AI_Governance_Project · CoolFace