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>
This commit is contained in:
77
addons/activeblue_ai/models/ab_ai_directive.py
Normal file
77
addons/activeblue_ai/models/ab_ai_directive.py
Normal file
@@ -0,0 +1,77 @@
|
||||
from odoo import models, fields, api, _
|
||||
import logging
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class AbAiDirective(models.Model):
|
||||
_name = 'ab.ai.directive'
|
||||
_description = 'AI Directive Log'
|
||||
_order = 'create_date desc'
|
||||
_rec_name = 'directive_id'
|
||||
|
||||
directive_id = fields.Char(string='Directive ID', required=True, index=True, readonly=True)
|
||||
user_id = fields.Many2one('res.users', string='User', readonly=True, index=True)
|
||||
message = fields.Text(string='User Message', readonly=True)
|
||||
reply = fields.Text(string='AI Reply', readonly=True)
|
||||
status = fields.Selection(
|
||||
[
|
||||
('pending', 'Pending'),
|
||||
('running', 'Running'),
|
||||
('pending_approval', 'Pending Approval'),
|
||||
('approved', 'Approved'),
|
||||
('rejected', 'Rejected'),
|
||||
('completed', 'Completed'),
|
||||
('failed', 'Failed'),
|
||||
('timeout', 'Timeout'),
|
||||
],
|
||||
string='Status',
|
||||
default='pending',
|
||||
required=True,
|
||||
index=True,
|
||||
readonly=True,
|
||||
)
|
||||
agents_involved = fields.Char(string='Agents', readonly=True)
|
||||
escalations = fields.Text(string='Escalations', readonly=True)
|
||||
actions_taken = fields.Text(string='Actions Taken', readonly=True)
|
||||
session_id = fields.Char(string='Session ID', readonly=True, index=True)
|
||||
duration_ms = fields.Integer(string='Duration (ms)', readonly=True)
|
||||
error_message = fields.Text(string='Error', readonly=True)
|
||||
|
||||
def action_view_detail(self):
|
||||
self.ensure_one()
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'res_model': 'ab.ai.directive',
|
||||
'res_id': self.id,
|
||||
'view_mode': 'form',
|
||||
'target': 'new',
|
||||
}
|
||||
|
||||
@api.model
|
||||
def record_directive(self, directive_id, user_id, message, reply, status,
|
||||
agents=None, escalations=None, actions=None,
|
||||
session_id=None, duration_ms=None, error=None):
|
||||
import json
|
||||
vals = {
|
||||
'directive_id': directive_id,
|
||||
'user_id': user_id,
|
||||
'message': message,
|
||||
'reply': reply,
|
||||
'status': status,
|
||||
'agents_involved': ', '.join(agents) if agents else '',
|
||||
'escalations': json.dumps(escalations) if escalations else '',
|
||||
'actions_taken': json.dumps(actions) if actions else '',
|
||||
'session_id': session_id,
|
||||
'duration_ms': duration_ms or 0,
|
||||
'error_message': error or '',
|
||||
}
|
||||
return self.create(vals)
|
||||
|
||||
@api.model
|
||||
def cron_cleanup_old(self):
|
||||
cutoff = fields.Datetime.subtract(fields.Datetime.now(), days=90)
|
||||
old = self.search([('create_date', '<', cutoff), ('status', 'in', ['completed', 'failed', 'timeout'])])
|
||||
count = len(old)
|
||||
old.unlink()
|
||||
_logger.info('Cleaned up %d old directives', count)
|
||||
Reference in New Issue
Block a user