import { ar as listEnabledAddonIds } from './src-CidJbygh.js';
import { g as getState } from './state-fxN45gBp.js';
import { d as getRequestId, k as jsonResponse } from './helpers-kzwksNq1.js';
import { execFile } from 'node:child_process';
import { promisify } from 'node:util';
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: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/guardian/health/+server.ts
var execFileAsync = promisify(execFile);
var PORTAL_ADDON_IDS = [
	"api",
	"chat",
	"discord",
	"slack"
];
/**
* Guardian health — queries the running container directly.
*
* Guardian has no host port mapping in the 0.11.0+ layout (it's reachable
* only on the internal portal_net/assistant_net networks). The previous
* implementation read the UI's in-memory ControlPlaneState, which is stale
* whenever the stack was started by something other than the UI itself
* (CLI, docker compose directly, AppImage on a pre-existing stack).
*
* `docker container inspect ... --format '{{.State.Health.Status}}'` is the
* authoritative source: it reads the compose-defined healthcheck the
* guardian container already runs internally. Same approach as the
* admin-tools-plugin host-side health-check tool.
*/
var GET = async (event) => {
	const requestId = getRequestId(event);
	try {
		if (!listEnabledAddonIds(getState().homeDir).some((a) => PORTAL_ADDON_IDS.includes(a))) return jsonResponse(200, {
			status: "not_deployed",
			service: "guardian"
		}, requestId);
	} catch {}
	try {
		const { stdout } = await execFileAsync("docker", [
			"container",
			"inspect",
			"openpalm-guardian-1",
			"--format",
			"{{.State.Health.Status}}"
		], { timeout: 5e3 });
		const status = stdout.trim();
		if (status === "healthy") return jsonResponse(200, {
			status: "ok",
			service: "guardian"
		}, requestId);
		return jsonResponse(503, {
			status: status || "unknown",
			service: "guardian"
		}, requestId);
	} catch (err) {
		return jsonResponse(503, {
			status: "unreachable",
			service: "guardian",
			error: err instanceof Error ? err.message : String(err)
		}, requestId);
	}
};

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