import { _ as applySchema, g as vaultStore, h as saveConfig, m as loadConfig, p as ensureConfigDir, v as closeDatabase, y as openDatabase } from "./index.mjs";
import { i as detectMcpClients, n as generateDaemonService, o as getModelPreset, r as registerMcpInAllClients, t as validateCredential } from "./validate-DxDJSvmm.mjs";

//#region src/setup/silent-setup.ts
function log(message) {
	process.stdout.write(`${message}\n`);
}
async function runSilentSetup(options) {
	const { provider, apiKey, validate } = options;
	if (validate && provider !== "ollama") {
		log("Validating credentials...");
		const result = await validateCredential(provider, apiKey);
		if (!result.isValid) return {
			success: false,
			error: result.error ?? "Invalid credentials",
			mcpClients: []
		};
		log(`Credentials valid: ${result.accountInfo ?? "OK"}`);
	}
	log("Initializing...");
	await ensureConfigDir();
	if (provider !== "ollama" && apiKey) await vaultStore(`${provider}-api-key`, apiKey);
	const db = openDatabase();
	applySchema(db);
	closeDatabase(db);
	const preset = getModelPreset(provider);
	const config = await loadConfig();
	await saveConfig({
		...config,
		models: { ...preset },
		auth: {
			...config.auth,
			[provider]: { method: provider === "ollama" ? "none" : "encrypted_file" }
		}
	});
	const registered = registerMcpInAllClients(detectMcpClients()).filter((r) => r.status === "registered" || r.status === "already_registered").map((r) => r.client);
	const daemon = generateDaemonService();
	log("Setup complete.");
	return {
		success: true,
		mcpClients: registered,
		daemonCommand: daemon?.activationCommand
	};
}

//#endregion
export { runSilentSetup };
//# sourceMappingURL=silent-setup-r2rmRnPR.mjs.map