Update readmes and imporve UI
This commit is contained in:
@@ -29,14 +29,17 @@ Services → RabbitMQ → [Alert Processor] → PostgreSQL
|
||||
|
||||
### Enrichment Pipeline
|
||||
|
||||
1. **Message Generator**: Creates i18n keys and parameters from metadata
|
||||
2. **Orchestrator Client**: Queries AI orchestrator for context
|
||||
3. **Business Impact Analyzer**: Calculates financial and operational impact
|
||||
4. **Urgency Analyzer**: Assesses time sensitivity and deadlines
|
||||
5. **User Agency Analyzer**: Determines user's ability to act
|
||||
6. **Priority Scorer**: Calculates weighted priority score (0-100)
|
||||
7. **Smart Action Generator**: Creates contextual action buttons
|
||||
8. **Entity Link Extractor**: Maps metadata to entity references
|
||||
1. **Duplicate Detection**: Checks for duplicate alerts within 24-hour window
|
||||
2. **Message Generator**: Creates i18n keys and parameters from metadata
|
||||
3. **Orchestrator Client**: Queries AI orchestrator for context
|
||||
4. **AI Reasoning Extractor**: Extracts AI reasoning details and confidence scores
|
||||
5. **Business Impact Analyzer**: Calculates financial and operational impact
|
||||
6. **Urgency Analyzer**: Assesses time sensitivity and deadlines
|
||||
7. **User Agency Analyzer**: Determines user's ability to act
|
||||
8. **Priority Scorer**: Calculates weighted priority score (0-100)
|
||||
9. **Type Classifier**: Determines if action needed or issue prevented
|
||||
10. **Smart Action Generator**: Creates contextual action buttons
|
||||
11. **Entity Link Extractor**: Maps metadata to entity references
|
||||
|
||||
## Service Structure
|
||||
|
||||
@@ -177,12 +180,15 @@ await publisher.publish_alert(
|
||||
|
||||
### 2. Alert Processor Enriches
|
||||
|
||||
- **Checks for duplicates**: Searches 24-hour window for similar alerts
|
||||
- Generates i18n: `alerts.critical_stock_shortage.title` with params
|
||||
- Queries orchestrator for AI context
|
||||
- Extracts AI reasoning and confidence scores (if available)
|
||||
- Analyzes business impact: €197.50 financial impact
|
||||
- Assesses urgency: 12 hours until consequence
|
||||
- Determines user agency: Can create PO, requires supplier
|
||||
- Calculates priority: Score 78 → "important"
|
||||
- Classifies type: `action_needed` or `prevented_issue`
|
||||
- Generates smart actions: [Create PO, Call Supplier, Dismiss]
|
||||
- Extracts entity links: `{ingredient: "..."}`
|
||||
|
||||
@@ -192,8 +198,12 @@ await publisher.publish_alert(
|
||||
{
|
||||
"id": "...",
|
||||
"event_type": "critical_stock_shortage",
|
||||
"event_domain": "inventory",
|
||||
"severity": "urgent",
|
||||
"type_class": "action_needed",
|
||||
"priority_score": 78,
|
||||
"priority_level": "important",
|
||||
"confidence_score": 95,
|
||||
"i18n": {
|
||||
"title_key": "alerts.critical_stock_shortage.title",
|
||||
"title_params": {"ingredient_name": "Flour"},
|
||||
@@ -206,7 +216,10 @@ await publisher.publish_alert(
|
||||
"business_impact": {...},
|
||||
"urgency": {...},
|
||||
"user_agency": {...},
|
||||
"smart_actions": [...]
|
||||
"ai_reasoning_details": {...},
|
||||
"orchestrator_context": {...},
|
||||
"smart_actions": [...],
|
||||
"entity_links": {"ingredient": "..."}
|
||||
}
|
||||
```
|
||||
|
||||
@@ -249,30 +262,83 @@ Publishes to Redis channel `alerts:{tenant_id}` for real-time frontend updates.
|
||||
|
||||
See [app/utils/message_templates.py](app/utils/message_templates.py) for complete list.
|
||||
|
||||
Key alert types:
|
||||
- `critical_stock_shortage`
|
||||
- `low_stock_warning`
|
||||
- `production_delay`
|
||||
- `equipment_failure`
|
||||
- `po_approval_needed`
|
||||
- `temperature_breach`
|
||||
- `delivery_overdue`
|
||||
- `expired_products`
|
||||
### Standard Alerts
|
||||
- `critical_stock_shortage` - Urgent stock shortages
|
||||
- `low_stock_warning` - Stock running low
|
||||
- `production_delay` - Production behind schedule
|
||||
- `equipment_failure` - Equipment issues
|
||||
- `po_approval_needed` - Purchase order approval required
|
||||
- `temperature_breach` - Temperature control violations
|
||||
- `delivery_overdue` - Late deliveries
|
||||
- `expired_products` - Product expiration warnings
|
||||
|
||||
### AI Recommendations
|
||||
- `ai_yield_prediction` - AI-predicted production yields
|
||||
- `ai_safety_stock_optimization` - AI stock level recommendations
|
||||
- `ai_supplier_recommendation` - AI supplier suggestions
|
||||
- `ai_price_forecast` - AI price predictions
|
||||
- `ai_demand_forecast` - AI demand forecasts
|
||||
- `ai_business_rule` - AI-suggested business rules
|
||||
|
||||
## Database Schema
|
||||
|
||||
**events table** with JSONB enrichment:
|
||||
- Core: `id`, `tenant_id`, `created_at`, `event_type`
|
||||
- Core: `id`, `tenant_id`, `created_at`, `event_type`, `event_domain`, `severity`
|
||||
- i18n: `i18n_title_key`, `i18n_title_params`, `i18n_message_key`, `i18n_message_params`
|
||||
- Priority: `priority_score` (0-100), `priority_level` (critical/important/standard/info)
|
||||
- Enrichment: `orchestrator_context`, `business_impact`, `urgency`, `user_agency` (JSONB)
|
||||
- AI Fields: `ai_reasoning_details`, `confidence_score`, `ai_reasoning_summary_key`, `ai_reasoning_summary_params`
|
||||
- Classification: `type_class` (action_needed/prevented_issue)
|
||||
- Actions: `smart_actions` (JSONB array)
|
||||
- Entities: `entity_links` (JSONB)
|
||||
- Status: `status` (active/acknowledged/resolved/dismissed)
|
||||
- Metadata: `raw_metadata` (JSONB)
|
||||
|
||||
## Key Features
|
||||
|
||||
### Duplicate Alert Detection
|
||||
|
||||
The service automatically detects and prevents duplicate alerts:
|
||||
- **24-hour window**: Checks for similar alerts in the past 24 hours
|
||||
- **Smart matching**: Compares `tenant_id`, `event_type`, and key metadata fields
|
||||
- **Update strategy**: Updates existing alert instead of creating duplicates
|
||||
- **Metadata preservation**: Keeps enriched data while preventing alert fatigue
|
||||
|
||||
### Type Classification
|
||||
|
||||
Events are classified into two types:
|
||||
- **action_needed**: User action required (default for alerts)
|
||||
- **prevented_issue**: AI already handled the situation (for AI recommendations)
|
||||
|
||||
This helps the frontend display appropriate UI and messaging.
|
||||
|
||||
### AI Reasoning Integration
|
||||
|
||||
When AI orchestrator has acted on an event:
|
||||
- Extracts complete reasoning data structure
|
||||
- Stores confidence scores (0-100)
|
||||
- Generates i18n-friendly reasoning summaries
|
||||
- Links to orchestrator context for full details
|
||||
|
||||
### Notification Service Integration
|
||||
|
||||
Enriched events are automatically sent to the notification service for delivery via:
|
||||
- WhatsApp
|
||||
- Email
|
||||
- Push notifications
|
||||
- SMS
|
||||
|
||||
Priority mapping:
|
||||
- `critical` → urgent priority
|
||||
- `important` → high priority
|
||||
- `standard` → medium priority
|
||||
- `info` → low priority
|
||||
|
||||
## Monitoring
|
||||
|
||||
Structured JSON logs with:
|
||||
- `enrichment_started` - Event received
|
||||
- `duplicate_detected` - Duplicate alert found and updated
|
||||
- `enrichment_completed` - Enrichment pipeline finished
|
||||
- `event_stored` - Saved to database
|
||||
- `notification_sent` - Notification queued
|
||||
|
||||
Reference in New Issue
Block a user