Files
odoo-ai/addons/activeblue_ai/controllers/approval.py
ActiveBlue Build 29409ed71d feat(odoo): add activeblue_ai Odoo 18 module with OWL2 frontend
Models:
- ab.ai.bot: service URL, webhook secret, privacy mode, ping/dispatch
- ab.ai.directive: full directive lifecycle log with status tracking
- ab.ai.log: activity log with level/agent/record linkage
- ab.ai.agent.registry: agent list synced from agent service

Controllers:
- webhook.py: /ai/webhook/callback handles directive_completed, escalation, sweep_findings
- health_proxy.py: /ai/health proxies agent service detailed health
- approval.py: /ai/chat dispatch, /ai/approval/pending, /ai/approval/respond

Security:
- group_ai_user (chat) + group_ai_manager (configure, approve, logs)
- ir.model.access.csv for all 4 models

Views: list/form for bot, directives, logs, registry; main menu with AI brain icon

OWL2 frontend:
- systray_button.js: brain icon in top bar, status dot, pending approval badge
- ai_panel.js: slide-in chat panel, approval workflow, 30s poll for pending items
- CSS: slide-in animation, message bubbles, loading dots, approval section

Data: 4 cron jobs (ping, registry sync, directive/log cleanup)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-12 17:59:02 -04:00

61 lines
2.3 KiB
Python

import json
import logging
import requests
from odoo import http
from odoo.http import request
_logger = logging.getLogger(__name__)
class AiApprovalController(http.Controller):
@http.route('/ai/approval/pending', type='json', auth='user', methods=['GET'])
def list_pending(self):
if not request.env.user.has_group('activeblue_ai.group_ai_manager'):
return {'error': 'Access denied', 'items': []}
bot = request.env['ab.ai.bot'].sudo().search([('active', '=', True)], limit=1)
if not bot:
return {'items': []}
url = bot._get_service_url() + '/approval/pending'
try:
resp = requests.get(url, headers=bot._build_headers(), timeout=10)
resp.raise_for_status()
return {'items': resp.json()}
except Exception as exc:
_logger.error('list_pending failed: %s', exc)
return {'error': str(exc), 'items': []}
@http.route('/ai/approval/respond', type='json', auth='user', methods=['POST'])
def respond(self, directive_id, approved, note=None):
if not request.env.user.has_group('activeblue_ai.group_ai_manager'):
return {'error': 'Access denied'}
bot = request.env['ab.ai.bot'].sudo().search([('active', '=', True)], limit=1)
if not bot:
return {'error': 'No bot configured'}
url = bot._get_service_url() + '/approval/respond'
payload = {
'directive_id': directive_id,
'approved': approved,
'approver_id': str(request.env.user.id),
'note': note or '',
}
try:
resp = requests.post(url, json=payload, headers=bot._build_headers(), timeout=10)
resp.raise_for_status()
return resp.json()
except Exception as exc:
_logger.error('respond approval failed: %s', exc)
return {'error': str(exc)}
@http.route('/ai/chat', type='json', auth='user', methods=['POST'])
def chat(self, message, context=None, session_id=None):
bot = request.env['ab.ai.bot'].sudo().get_active_bot()
result = bot.dispatch_message(
user_id=request.env.user.id,
message=message,
context=context or {},
session_id=session_id,
)
return result