import logging import requests from odoo import http from odoo.http import request _logger = logging.getLogger(__name__) class AiHealthProxyController(http.Controller): @http.route('/ai/health', type='http', auth='user', methods=['GET']) def ai_health(self): bot = request.env['ab.ai.bot'].sudo().search([('active', '=', True)], limit=1) if not bot: return request.make_response( '{"status":"no_bot_configured"}', headers=[('Content-Type', 'application/json')], status=503, ) url = bot._get_service_url() + '/health/detailed' try: resp = requests.get(url, headers=bot._build_headers(), timeout=5) return request.make_response( resp.text, headers=[('Content-Type', 'application/json')], status=resp.status_code, ) except Exception as exc: _logger.warning('health proxy failed: %s', exc) import json body = json.dumps({'status': 'unreachable', 'error': str(exc)}) return request.make_response( body, headers=[('Content-Type', 'application/json')], status=503, )