import { json } from '@sveltejs/kit';
import { checkLLMHealth } from '$lib/server/llm';

/**
 * Health check endpoint for LLM service
 * Tests connectivity to LM Studio or OpenAI-compatible endpoint
 */
export async function GET() {
	try {
		const isHealthy = await checkLLMHealth();

		if (isHealthy) {
			return json({ 
				status: 'healthy', 
				message: 'LLM service is accessible' 
			});
		} else {
			return json({ 
				status: 'unhealthy', 
				message: 'LLM service is not accessible' 
			}, { status: 503 });
		}
	} catch (error) {
		const errorMessage = error instanceof Error ? error.message : 'Unknown error';
		return json({ 
			status: 'error', 
			message: errorMessage 
		}, { status: 500 });
	}
}
