feat(supervisor): Phase 2 metrics ingest — AgentEvent/AgentSession rollup

- New AgentHistoryService: persistAgentEvent pairs START/END for durationS, patchCallTiming updates Call SLA fields
- Supervisor service wires handleCallEvent (CALL_START on Answered, CALL_END on Disconnect) and handleAgentEvent (LOGIN/LOGOUT/PAUSE/RESUME/ACW_START/ACW_END/READY) via priorState-aware mapping
- setInterval-based nightly-ish rollup: every 15min aggregates AgentEvent into AgentSession per IST day (idempotent upsert by agentId+date)
- Ozonetel dispose flow extracts HandlingTime/WrapupDuration/HoldDuration from CDR, patches Call timing fields
- Field names match platform truncation: durationS, loginDurationS, busyTimeS, idleTimeS, pauseTimeS, wrapupTimeS, avgHandlingTimeS, handlingTimeS, acwDurationS, holdDurationS, responseTimeS, sessionDate → date
- Skips cleanly on workspaces where AgentEvent entity isn't synced

Known issue: pending-pair map has single slot per agent, so ACW_START overwrites pending CALL_START and CALL_END computes 0s duration. Fix in followup.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-15 06:49:15 +05:30
parent fbe782b5ac
commit 4eb8cb80b2
4 changed files with 527 additions and 14 deletions

View File

@@ -4,6 +4,7 @@ import { OzonetelAgentModule } from '../ozonetel/ozonetel-agent.module';
import { SupervisorController } from './supervisor.controller';
import { SupervisorBargeController } from './supervisor-barge.controller';
import { SupervisorService } from './supervisor.service';
import { AgentHistoryService } from './agent-history.service';
import { OzonetelAdminAuthService } from '../ozonetel/ozonetel-admin-auth.service';
// Note: TelephonyConfigService is available without import because
@@ -12,7 +13,7 @@ import { OzonetelAdminAuthService } from '../ozonetel/ozonetel-admin-auth.servic
@Module({
imports: [PlatformModule, forwardRef(() => OzonetelAgentModule)],
controllers: [SupervisorController, SupervisorBargeController],
providers: [SupervisorService, OzonetelAdminAuthService],
exports: [SupervisorService, OzonetelAdminAuthService],
providers: [SupervisorService, AgentHistoryService, OzonetelAdminAuthService],
exports: [SupervisorService, AgentHistoryService, OzonetelAdminAuthService],
})
export class SupervisorModule {}