import { PROVIDER_ENTRIES } from "./providers.js";
import { existsSync, readFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";

//#region src/cli/status.ts
const isPackageInstalled = (cwd, pkg) => {
	return existsSync(join(cwd, "node_modules", ...pkg.split("/")));
};
function resolveVersion(cwd) {
	try {
		const nmPkgPath = join(cwd, "node_modules", "@amplitude", "ai", "package.json");
		if (existsSync(nmPkgPath)) {
			const pkg = JSON.parse(readFileSync(nmPkgPath, "utf8"));
			if (pkg.version) return pkg.version;
		}
	} catch {}
	try {
		const selfPkgPath = join(dirname(fileURLToPath(import.meta.url)), "..", "..", "package.json");
		if (existsSync(selfPkgPath)) {
			const pkg = JSON.parse(readFileSync(selfPkgPath, "utf8"));
			if (pkg.version) return pkg.version;
		}
	} catch {}
	return "unknown";
}
const runStatus = (cwd) => {
	const version = resolveVersion(cwd);
	const installedCache = /* @__PURE__ */ new Map();
	return {
		version,
		providers: PROVIDER_ENTRIES.map(({ name, npm }) => {
			if (!installedCache.has(npm)) installedCache.set(npm, isPackageInstalled(cwd, npm));
			return {
				name,
				installed: installedCache.get(npm) ?? false
			};
		}),
		env: {
			AMPLITUDE_AI_API_KEY: Boolean(process.env.AMPLITUDE_AI_API_KEY),
			AMPLITUDE_AI_CONTENT_MODE: Boolean(process.env.AMPLITUDE_AI_CONTENT_MODE),
			AMPLITUDE_AI_DEBUG: Boolean(process.env.AMPLITUDE_AI_DEBUG)
		},
		patchActive: false
	};
};

//#endregion
export { runStatus };
//# sourceMappingURL=status.js.map