fix(addon): seed ab.ai.bot and agent registry on install

The bot DM flow silently failed because ab_ai_mail.message_post override
bails when no active ab.ai.bot row exists, and the agent service loaded
0 agents from an empty ab.ai.agent.registry. Both tables stayed empty
because nothing populated them.

The post_init/post_migrate hook now seeds:
- One active ab.ai.bot pointing at http://activeblue-agent:8001
- The 8 specialist agents (finance, accounting, crm, sales, project,
  elearning, expenses, hr) plus master, all on the ollama backend

Idempotent: skips rows that already exist.
This commit is contained in:
Carlos Garcia
2026-04-24 22:51:37 -04:00
parent 79537a5e21
commit beb08b0b4b

View File

@@ -3,6 +3,42 @@ import logging
_logger = logging.getLogger(__name__)
DEFAULT_AGENTS = [
('master', 'Routing / orchestration'),
('finance', 'Finance reporting and analysis'),
('accounting', 'Accounting, journals, reconciliation'),
('crm', 'CRM, leads, opportunities'),
('sales', 'Sales orders, quotations, customers'),
('project', 'Project management and tasks'),
('elearning', 'eLearning courses and content'),
('expenses', 'Expense reports and approvals'),
('hr', 'Human Resources, employees, time off'),
]
def _ensure_default_bot_and_registry(env):
"""Seed an active ab.ai.bot row and the default agent registry entries."""
Bot = env['ab.ai.bot']
if not Bot.search([], limit=1):
Bot.create({
'display_name': 'ActiveBlue AI',
'agent_service_url': 'http://activeblue-agent:8001',
'privacy_mode': 'local',
'active': True,
})
_logger.info('Seeded default ab.ai.bot row')
Registry = env['ab.ai.agent.registry']
for name, domain in DEFAULT_AGENTS:
if not Registry.search([('agent_name', '=', name)], limit=1):
Registry.create({
'agent_name': name,
'domain': domain,
'active': True,
'backend': 'ollama',
})
_logger.info('Ensured %d default agent registry entries', len(DEFAULT_AGENTS))
def _ensure_ai_bot_user(env):
"""Create the ActiveBlue AI internal user so it appears in Discuss DM search.
@@ -54,3 +90,5 @@ def _ensure_ai_bot_user(env):
(user.id, user.id),
)
_logger.info('Marked ActiveBlue AI bot user id=%d as confirmed', user.id)
_ensure_default_bot_and_registry(env)