iconsulting/packages/services/conversation-service/src
hailin 691a3523e8 feat(analytics): add Agent usage analytics to admin panel
Add full-stack Agent execution tracking and analytics:

**Database (conversation-service)**
- New `agent_executions` table: tracks each specialist Agent invocation
  with agentType, agentName, durationMs, success, tenantId
- Migration: AddAgentExecutionsTable1738800000000
- ORM entity: AgentExecutionORM with indexes on tenant, conversation,
  agentType, createdAt, and (tenant+date) composite

**Data Capture (conversation-service)**
- conversation.service.ts: captures `agent_start` and `agent_complete`
  StreamChunk events in the sendMessage() async generator loop
- Persists agent execution records to DB after each message completes
- Non-blocking: agent persistence failures are logged but don't break
  the main conversation flow

**Admin API (conversation-service)**
- GET /conversations/admin/statistics/agents?days=30
  Aggregated stats per agent type: totalCalls, successCount, failureCount,
  successRate, avgDurationMs, min/max duration
- GET /conversations/admin/statistics/agents/trend?days=7&agentType=
  Daily trend data: date, agentType, calls, avgDurationMs, successRate
- GET /conversations/admin/:id/agent-executions
  Per-conversation agent execution records ordered by createdAt

**Admin Client - Analytics Page**
- New AgentAnalyticsTab component with:
  - 4 summary cards (total calls, success rate, avg duration, top agent)
  - Agent statistics table (Ant Design Table with sortable columns,
    color-coded Tags, Progress bar for success rate)
  - Stacked bar trend chart (Recharts BarChart, color per agent type)
  - Time range selectors (7/14/30/90 days)
- Added as third tab "Agent 使用分析" in AnalyticsPage dimension tabs

**Admin Client - Conversations Page**
- Added "Agent 使用详情" section to conversation detail drawer
  (between Token Usage and Messages sections)
- Shows per-conversation agent execution table with agent name (color Tag),
  duration, success/failure status, and timestamp
- Empty state: "暂无 Agent 使用记录"

Agent color mapping: policy_expert=#1890ff, assessment_expert=#52c41a,
strategist=#722ed1, objection_handler=#eb2f96, case_analyst=#faad14,
memory_manager=#13c2c2

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-06 08:00:55 -08:00
..
adapters feat(analytics): add Agent usage analytics to admin panel 2026-02-06 08:00:55 -08:00
application feat(analytics): add Agent usage analytics to admin panel 2026-02-06 08:00:55 -08:00
conversation feat(analytics): add Agent usage analytics to admin panel 2026-02-06 08:00:55 -08:00
domain refactor(services): implement Clean Architecture across 4 services 2026-01-24 21:18:25 -08:00
health fix(docker): add health check endpoints and fix IPv6 issue 2026-01-10 02:13:42 -08:00
infrastructure feat(analytics): add Agent usage analytics to admin panel 2026-02-06 08:00:55 -08:00
migrations feat(analytics): add Agent usage analytics to admin panel 2026-02-06 08:00:55 -08:00
app.module.ts fix(tenant): use TenantContextModule.forRoot() for global tenant context 2026-01-26 04:31:56 -08:00
data-source.prod.ts refactor(services): implement Clean Architecture across 4 services 2026-01-24 21:18:25 -08:00
data-source.ts refactor(services): implement Clean Architecture across 4 services 2026-01-24 21:18:25 -08:00
main.ts fix(health): exclude /health endpoint from API prefix 2026-01-10 02:30:24 -08:00