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:
131
addons/activeblue_ai/static/src/js/components/ai_panel.js
Normal file
131
addons/activeblue_ai/static/src/js/components/ai_panel.js
Normal file
@@ -0,0 +1,131 @@
|
||||
/** @odoo-module **/
|
||||
import { Component, useState, useRef, onMounted, onWillUnmount } from '@odoo/owl';
|
||||
import { useService } from '@web/core/utils/hooks';
|
||||
import { registry } from '@web/core/registry';
|
||||
|
||||
let _msgCounter = 0;
|
||||
function nextId() { return ++_msgCounter; }
|
||||
|
||||
export class AiPanel extends Component {
|
||||
static template = 'activeblue_ai.AiPanel';
|
||||
static props = {
|
||||
isOpen: Boolean,
|
||||
onClose: Function,
|
||||
serviceStatus: { type: String, optional: true },
|
||||
};
|
||||
|
||||
setup() {
|
||||
this.rpc = useService('rpc');
|
||||
this.notification = useService('notification');
|
||||
this.messagesRef = useRef('messagesContainer');
|
||||
this.inputRef = useRef('inputEl');
|
||||
|
||||
this.state = useState({
|
||||
messages: [],
|
||||
inputText: '',
|
||||
loading: false,
|
||||
pendingApprovals: [],
|
||||
sessionId: null,
|
||||
});
|
||||
|
||||
this._approvalPollInterval = null;
|
||||
onMounted(() => {
|
||||
this._startApprovalPoll();
|
||||
});
|
||||
onWillUnmount(() => {
|
||||
if (this._approvalPollInterval) {
|
||||
clearInterval(this._approvalPollInterval);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get statusDotClass() {
|
||||
const s = this.props.serviceStatus || 'unknown';
|
||||
return `ab-ai-status-dot ab-ai-status-dot--${s}`;
|
||||
}
|
||||
|
||||
get statusText() {
|
||||
return this.props.serviceStatus === 'online' ? 'Online' : 'Offline';
|
||||
}
|
||||
|
||||
onKeyDown(ev) {
|
||||
if (ev.key === 'Enter' && !ev.shiftKey) {
|
||||
ev.preventDefault();
|
||||
this.sendMessage();
|
||||
}
|
||||
}
|
||||
|
||||
async sendMessage() {
|
||||
const text = this.state.inputText.trim();
|
||||
if (!text || this.state.loading) return;
|
||||
|
||||
this.state.messages.push({ id: nextId(), role: 'user', content: text });
|
||||
this.state.inputText = '';
|
||||
this.state.loading = true;
|
||||
this._scrollToBottom();
|
||||
|
||||
try {
|
||||
const result = await this.rpc('/ai/chat', {
|
||||
message: text,
|
||||
context: {},
|
||||
session_id: this.state.sessionId,
|
||||
});
|
||||
const reply = result.reply || '(no response)';
|
||||
this.state.messages.push({
|
||||
id: nextId(),
|
||||
role: 'assistant',
|
||||
content: reply,
|
||||
escalations: result.escalations || [],
|
||||
});
|
||||
if (result.session_id) {
|
||||
this.state.sessionId = result.session_id;
|
||||
}
|
||||
} catch (err) {
|
||||
this.state.messages.push({
|
||||
id: nextId(),
|
||||
role: 'error',
|
||||
content: 'Error reaching AI service. Please try again.',
|
||||
});
|
||||
} finally {
|
||||
this.state.loading = false;
|
||||
this._scrollToBottom();
|
||||
}
|
||||
}
|
||||
|
||||
async approve(directiveId, approved) {
|
||||
try {
|
||||
await this.rpc('/ai/approval/respond', {
|
||||
directive_id: directiveId,
|
||||
approved,
|
||||
});
|
||||
this.state.pendingApprovals = this.state.pendingApprovals.filter(
|
||||
(a) => a.directive_id !== directiveId
|
||||
);
|
||||
this.notification.add(approved ? 'Directive approved' : 'Directive rejected', {
|
||||
type: approved ? 'success' : 'warning',
|
||||
});
|
||||
} catch (err) {
|
||||
this.notification.add('Failed to respond to approval request', { type: 'danger' });
|
||||
}
|
||||
}
|
||||
|
||||
_startApprovalPoll() {
|
||||
const poll = async () => {
|
||||
try {
|
||||
const result = await this.rpc('/ai/approval/pending', {});
|
||||
this.state.pendingApprovals = result.items || [];
|
||||
} catch {
|
||||
// Silently ignore poll errors
|
||||
}
|
||||
};
|
||||
poll();
|
||||
this._approvalPollInterval = setInterval(poll, 30000);
|
||||
}
|
||||
|
||||
_scrollToBottom() {
|
||||
const el = this.messagesRef.el;
|
||||
if (el) {
|
||||
setTimeout(() => { el.scrollTop = el.scrollHeight; }, 50);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/** @odoo-module **/
|
||||
import { Component, useState, onMounted, onWillUnmount } from '@odoo/owl';
|
||||
import { registry } from '@web/core/registry';
|
||||
import { useService } from '@web/core/utils/hooks';
|
||||
import { AiPanel } from './ai_panel';
|
||||
|
||||
export class SystrayButton extends Component {
|
||||
static template = 'activeblue_ai.SystrayButton';
|
||||
static components = { AiPanel };
|
||||
|
||||
setup() {
|
||||
this.rpc = useService('rpc');
|
||||
this.state = useState({
|
||||
panelOpen: false,
|
||||
serviceStatus: 'unknown',
|
||||
pendingCount: 0,
|
||||
});
|
||||
|
||||
this._statusInterval = null;
|
||||
onMounted(() => {
|
||||
this._checkStatus();
|
||||
this._statusInterval = setInterval(() => this._checkStatus(), 60000);
|
||||
});
|
||||
onWillUnmount(() => {
|
||||
if (this._statusInterval) clearInterval(this._statusInterval);
|
||||
});
|
||||
}
|
||||
|
||||
get iconClass() {
|
||||
return {
|
||||
'text-success': this.state.serviceStatus === 'online',
|
||||
'text-danger': this.state.serviceStatus === 'offline',
|
||||
'text-muted': this.state.serviceStatus === 'unknown',
|
||||
};
|
||||
}
|
||||
|
||||
get statusTitle() {
|
||||
return `ActiveBlue AI — ${this.state.serviceStatus}`;
|
||||
}
|
||||
|
||||
togglePanel() {
|
||||
this.state.panelOpen = !this.state.panelOpen;
|
||||
}
|
||||
|
||||
closePanel() {
|
||||
this.state.panelOpen = false;
|
||||
}
|
||||
|
||||
async _checkStatus() {
|
||||
try {
|
||||
const result = await fetch('/ai/health');
|
||||
if (result.ok) {
|
||||
const data = await result.json();
|
||||
this.state.serviceStatus = data.status === 'ok' ? 'online' : 'degraded';
|
||||
} else {
|
||||
this.state.serviceStatus = 'offline';
|
||||
}
|
||||
} catch {
|
||||
this.state.serviceStatus = 'offline';
|
||||
}
|
||||
try {
|
||||
const pending = await this.rpc('/ai/approval/pending', {});
|
||||
this.state.pendingCount = (pending.items || []).length;
|
||||
} catch {
|
||||
this.state.pendingCount = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
registry.category('systray').add('activeblue_ai.systray_button', {
|
||||
Component: SystrayButton,
|
||||
sequence: 1,
|
||||
});
|
||||
Reference in New Issue
Block a user