import { a_ as runAssistantAkmCommand } from './src-CidJbygh.js';
import { g as getState } from './state-fxN45gBp.js';
import { d as getRequestId, r as requireAdmin, k as jsonResponse } from './helpers-kzwksNq1.js';
import { s as safeParseJsonObject } from './akm-BRiRim0P.js';
import './chunk-CLZ62Ad-.js';
import 'node:module';
import './provider-constants-DPrj3yBX.js';
import './dist-DOFcG0Zp.js';
import 'node:fs';
import 'node:path';
import 'buffer';
import 'fs';
import 'path';
import 'node:child_process';
import 'node:url';
import 'node:crypto';
import 'events';
import 'node:events';
import 'node:stream';
import 'node:string_decoder';
import 'assert';
import 'zlib';
import 'node:assert';
import 'node:fs/promises';
import 'node:os';
import './endpoints-UdQGgKsR.js';

//#region src/routes/admin/akm/health/+server.ts
var GET = async (event) => {
	const requestId = getRequestId(event);
	const denied = requireAdmin(event, requestId);
	if (denied) return denied;
	const state = getState();
	const [health, info] = await Promise.all([runAssistantAkmCommand(state, [
		"health",
		"--json",
		"--quiet"
	], 8e3), runAssistantAkmCommand(state, [
		"info",
		"--json",
		"--quiet"
	], 8e3)]);
	const parsedHealth = safeParseJsonObject(health.stdout);
	const parsedInfo = safeParseJsonObject(info.stdout);
	if (!parsedHealth && !parsedInfo) return jsonResponse(200, {
		available: false,
		reason: "assistant AKM unavailable"
	}, requestId);
	const checks = Array.isArray(parsedHealth?.hardChecks) ? parsedHealth.hardChecks : [];
	const checkCounts = {
		pass: 0,
		warn: 0,
		fail: 0
	};
	for (const c of checks) if (c.status === "pass") checkCounts.pass++;
	else if (c.status === "warn") checkCounts.warn++;
	else checkCounts.fail++;
	return jsonResponse(200, {
		available: true,
		status: parsedHealth?.status ?? "unknown",
		ok: typeof parsedHealth?.ok === "boolean" ? parsedHealth.ok : null,
		checks: checkCounts,
		metrics: parsedHealth?.metrics ?? null,
		index: parsedInfo?.indexStats ?? null
	}, requestId);
};

export { GET };
//# sourceMappingURL=_server.ts-CGqpENOm.js.map
