Files
odoo-ai/addons/activeblue_ai/models/ab_ai_registry.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

88 lines
3.0 KiB
Python

from odoo import models, fields, api
import requests
import logging
_logger = logging.getLogger(__name__)
class AbAiAgentRegistry(models.Model):
_name = 'ab.ai.agent.registry'
_description = 'AI Agent Registry'
_rec_name = 'agent_name'
agent_name = fields.Char(string='Agent Name', required=True, index=True)
domain = fields.Char(string='Domain')
active = fields.Boolean(default=True, index=True)
backend = fields.Selection(
[('ollama', 'Ollama (Local)'), ('claude', 'Claude (Cloud)')],
string='LLM Backend',
default='ollama',
)
description = fields.Text(string='Description')
last_sweep = fields.Datetime(string='Last Sweep', readonly=True)
sweep_count = fields.Integer(string='Sweep Count', default=0, readonly=True)
error_count = fields.Integer(string='Error Count', default=0, readonly=True)
_sql_constraints = [
('agent_name_uniq', 'unique(agent_name)', 'Agent name must be unique'),
]
@api.model
def sync_from_service(self):
bot = self.env['ab.ai.bot'].search([('active', '=', True)], limit=1)
if not bot:
_logger.warning('No active bot — cannot sync registry')
return 0
url = bot._get_service_url() + '/registry/agents'
try:
resp = requests.get(url, headers=bot._build_headers(), timeout=10)
resp.raise_for_status()
agents = resp.json()
except Exception as exc:
_logger.error('Registry sync failed: %s', exc)
return 0
synced = 0
for agent_data in agents:
name = agent_data.get('name', '')
if not name:
continue
existing = self.search([('agent_name', '=', name)], limit=1)
vals = {
'agent_name': name,
'domain': agent_data.get('domain', ''),
'active': agent_data.get('active', True),
'backend': agent_data.get('backend', 'ollama'),
}
if existing:
existing.write(vals)
else:
self.create(vals)
synced += 1
_logger.info('Synced %d agents from service', synced)
return synced
def action_set_backend_claude(self):
self._set_backend('claude')
def action_set_backend_ollama(self):
self._set_backend('ollama')
def _set_backend(self, backend):
self.ensure_one()
bot = self.env['ab.ai.bot'].search([('active', '=', True)], limit=1)
if not bot:
return
url = bot._get_service_url() + '/registry/backend'
payload = {
'agent_name': self.agent_name,
'backend': backend,
'set_by': str(self.env.user.id),
}
try:
resp = requests.post(url, json=payload, headers=bot._build_headers(), timeout=10)
resp.raise_for_status()
self.write({'backend': backend})
except Exception as exc:
_logger.error('set_backend failed: %s', exc)