IAV-856/Refactor: Unify Main/Sub Agent Wizard into single module with bug fixes
Summary
Consolidates the Agent Wizard module by merging the separate Main Agent and Sub Agent wizard layers (controllers, services, paths) into a single unified module. This also fixes several critical bugs identified during the previous code review.
Motivation
The previous architecture had two parallel controller/service/path stacks (Main + Sub) that shared ~80% of the same logic. This caused significant code duplication — especially in initialization methods (languages, standard instructions, working hours) — and made the codebase harder to maintain. Additionally, several bugs were present in the old code that could cause runtime failures.
What changed
Architecture (refactor)
-
Controller:
MainAgentWizardController+SubAgentWizardController→AgentWizardController -
Service:
MainAgentWizardService+SubAgentWizardService→AgentWizardService -
Paths: 3 path classes → 1 unified
AgentWizardPaths -
Common service:
AgentWizardCommonService/AgentWizardCommonServiceImpl— unchanged
API changes
| Before | After |
|---|---|
POST /main-agent-wizard/company-context |
POST /agent-wizard/main-agent/company-context |
PUT /sub-agent-wizard/{subAgentUid}/company-context |
POST /agent-wizard/sub-agent/company-context |
GET /main-agent-wizard/company-context (via x-user-uid) |
GET /agent-wizard/{agentUid}/company-context |
GET /sub-agent-wizard/{subAgentUid}/company-context |
GET /agent-wizard/{agentUid}/company-context |
Bug fixes
-
Optional.get()without check — replaced withisEmpty()guard to preventNoSuchElementException -
Missing
parentAgenton sub-agent creation — now sets.parentAgent(mainAgent)in builder -
Wrong parameter in
initializeAgentWorkingHours— now receivesCustomerCareAgententity directly instead of a UID string that would fail lookup -
Added
outboundMessageWebhookUrldefault value on agent creation
Testing
-
Main agent wizard full flow (create + all steps) -
Sub-agent wizard full flow (create + all steps) -
Company context GET by agentUid (both main and sub) -
Verify sub-agent has parentAgent set after creation -
Verify working hours initialization works for both agent types
Closes IAV-856