import { t as readCliStartupMetadata } from "./startup-metadata-CCK-kryO.js";
//#region src/cli/root-help-metadata.ts
let precomputedRootHelpText;
let precomputedBrowserHelpText;
let precomputedSecretsHelpText;
let precomputedNodesHelpText;
let precomputedSubcommandHelpText;
function loadPrecomputedHelpText(key, cache, setCache) {
	if (cache !== void 0) return cache;
	try {
		const parsed = readCliStartupMetadata(import.meta.url);
		if (parsed) {
			const value = parsed[key];
			if (typeof value === "string" && value.length > 0) {
				setCache(value);
				return value;
			}
		}
	} catch {}
	setCache(null);
	return null;
}
function outputPrecomputedHelpText(key, cache, setCache) {
	const helpText = loadPrecomputedHelpText(key, cache, setCache);
	if (!helpText) return false;
	process.stdout.write(helpText);
	return true;
}
function loadPrecomputedSubcommandHelpText(commandName) {
	if (!isPrecomputedSubcommandHelpName(commandName)) return null;
	const cache = precomputedSubcommandHelpText?.[commandName];
	if (cache !== void 0) return cache;
	try {
		const subcommandHelpText = readCliStartupMetadata(import.meta.url)?.subcommandHelpText;
		if (isSubcommandHelpTextRecord(subcommandHelpText)) {
			const value = subcommandHelpText[commandName];
			if (typeof value === "string" && value.length > 0) {
				setPrecomputedSubcommandHelpText(commandName, value);
				return value;
			}
		}
	} catch {}
	setPrecomputedSubcommandHelpText(commandName, null);
	return null;
}
function outputPrecomputedRootHelpText() {
	return outputPrecomputedHelpText("rootHelpText", precomputedRootHelpText, (value) => {
		precomputedRootHelpText = value;
	});
}
function outputPrecomputedBrowserHelpText() {
	return outputPrecomputedHelpText("browserHelpText", precomputedBrowserHelpText, (value) => {
		precomputedBrowserHelpText = value;
	});
}
function outputPrecomputedSecretsHelpText() {
	return outputPrecomputedHelpText("secretsHelpText", precomputedSecretsHelpText, (value) => {
		precomputedSecretsHelpText = value;
	});
}
function outputPrecomputedNodesHelpText() {
	return outputPrecomputedHelpText("nodesHelpText", precomputedNodesHelpText, (value) => {
		precomputedNodesHelpText = value;
	});
}
function outputPrecomputedSubcommandHelpText(commandName) {
	const helpText = loadPrecomputedSubcommandHelpText(commandName);
	if (!helpText) return false;
	process.stdout.write(helpText);
	return true;
}
function isPrecomputedSubcommandHelpName(commandName) {
	return commandName === "config" || commandName === "doctor" || commandName === "gateway" || commandName === "models" || commandName === "plugins" || commandName === "sessions" || commandName === "tasks";
}
function isSubcommandHelpTextRecord(value) {
	return typeof value === "object" && value !== null;
}
function setPrecomputedSubcommandHelpText(commandName, value) {
	precomputedSubcommandHelpText = {
		...precomputedSubcommandHelpText,
		[commandName]: value
	};
}
//#endregion
export { outputPrecomputedBrowserHelpText, outputPrecomputedNodesHelpText, outputPrecomputedRootHelpText, outputPrecomputedSecretsHelpText, outputPrecomputedSubcommandHelpText };
