//#region src/routes/brain/overview/+page.server.ts
function formatCount(n) {
	if (n >= 1e3) return `${(n / 1e3).toFixed(1)}k`;
	return String(n);
}
var load = async ({ fetch }) => {
	let stats = null;
	let tierDistribution = [];
	let upcomingPromotions = [];
	let recentObservations = [];
	let recentDecisions = [];
	let quality = null;
	try {
		const [tierRes, qualityRes, obsRes, decRes] = await Promise.all([
			fetch("/api/memory/tier-stats"),
			fetch("/api/memory/quality"),
			fetch("/api/memory/observations?limit=5"),
			fetch("/api/memory/decisions")
		]);
		if (tierRes.ok) {
			const body = await tierRes.json();
			tierDistribution = body.tables;
			upcomingPromotions = body.upcomingLongPromotions;
		}
		if (qualityRes.ok) quality = await qualityRes.json();
		if (obsRes.ok) recentObservations = (await obsRes.json()).observations.slice(0, 5);
		if (decRes.ok) recentDecisions = (await decRes.json()).decisions.slice().sort((a, b) => b.created_at.localeCompare(a.created_at)).slice(0, 5);
		const tierTotals = tierDistribution.reduce((acc, row) => ({
			entries: acc.entries + row.short + row.medium + row.long,
			long: acc.long + row.long
		}), {
			entries: 0,
			long: 0
		});
		const observationRow = tierDistribution.find((r) => r.table === "brain_observations");
		const decisionRow = tierDistribution.find((r) => r.table === "brain_decisions");
		const patternRow = tierDistribution.find((r) => r.table === "brain_patterns");
		const learningRow = tierDistribution.find((r) => r.table === "brain_learnings");
		const obsTotal = observationRow ? observationRow.short + observationRow.medium + observationRow.long : 0;
		const decTotal = decisionRow ? decisionRow.short + decisionRow.medium + decisionRow.long : 0;
		const patTotal = patternRow ? patternRow.short + patternRow.medium + patternRow.long : 0;
		const learnTotal = learningRow ? learningRow.short + learningRow.medium + learningRow.long : 0;
		stats = [
			{
				value: formatCount(tierTotals.entries),
				label: "Entries"
			},
			{
				value: formatCount(tierTotals.long),
				label: "Long-tier"
			},
			{
				value: formatCount(obsTotal),
				label: "Observations"
			},
			{
				value: formatCount(decTotal),
				label: "Decisions"
			},
			{
				value: formatCount(patTotal),
				label: "Patterns"
			},
			{
				value: formatCount(learnTotal),
				label: "Learnings"
			},
			{
				value: formatCount(quality?.observations.verified_count ?? 0),
				label: "Verified"
			},
			{
				value: formatCount(quality?.observations.prune_count ?? 0),
				label: "Prune candidates"
			}
		];
	} catch {}
	return {
		stats,
		tierDistribution,
		upcomingPromotions,
		recentObservations,
		recentDecisions,
		quality
	};
};

var _page_server_ts = /*#__PURE__*/Object.freeze({
	__proto__: null,
	load: load
});

const index = 10;
let component_cache;
const component = async () => component_cache ??= (await import('./_page.svelte-BVVTrzTL.js')).default;
const server_id = "src/routes/brain/overview/+page.server.ts";
const imports = ["_app/immutable/nodes/10.xe_Mc2Ko.js","_app/immutable/chunks/DyGQ_VXC.js","_app/immutable/chunks/DrKWWDpL.js","_app/immutable/chunks/CQCxd1p9.js","_app/immutable/chunks/BRgWBQlV.js","_app/immutable/chunks/CEqOYim7.js","_app/immutable/chunks/CqF5Lomf.js"];
const stylesheets = ["_app/immutable/assets/Tabs.CU9_rsWl.css","_app/immutable/assets/ui.CH-9N9-0.css","_app/immutable/assets/memory.BscouZPQ.css","_app/immutable/assets/10.BxJazN1A.css"];
const fonts = [];

export { component, fonts, imports, index, _page_server_ts as server, server_id, stylesheets };
//# sourceMappingURL=10-DvOD4ksa.js.map
