mirror of
https://github.com/zvx-echo6/meshai.git
synced 2026-06-11 01:14:45 +02:00
feat(notifications): v0.5.0 -- Master Toggles UX redesign + Central Connection GUI + grouped categories + region scoping
Per-family notification policy (PagerDuty/Grafana-style): each family gets a
severity threshold + region scope + a severity->channel routing matrix, so an
operator opts in per family rather than hand-writing rules.
SECTION 1 -- BACKEND
- config.py: new NotificationToggle dataclass (enabled, min_severity, regions,
severity_channels{severity->[channel types]}, quiet_hours_override, + per-channel
delivery config: broadcast_channel/node_ids/smtp_*/recipients/webhook_*).
notifications.toggles is now a dict[family]->NotificationToggle with 8 family
defaults (mesh_health, weather, fire, rf_propagation, roads, avalanche, seismic,
tracking), all enabled=false (opt-in), min_severity=priority,
severity_channels={priority:[mesh_broadcast], immediate:[mesh_broadcast, mesh_dm]},
quiet_hours_override=true. (Old TogglesConfig.enabled was only read by
build_pipeline via getattr -> degrades to ToggleFilter no-op, so the pipeline
filter is unchanged; toggles now drive the Dispatcher instead.)
- region_scope:list added to NotificationRuleConfig; _matching_rules filters by
event.region/regions ([] = all).
- Dispatcher: _dispatch_toggles runs IN PARALLEL to rule matching -- looks up
get_toggle(event.category), checks enabled + region scope + severity threshold,
then for each channel in severity_channels[event.severity] builds a synthetic
rule (override_quiet set only for immediate when quiet_hours_override) and
delivers. 'digest' channel is skipped in live dispatch (handled by accumulator).
- categories.py: get_toggle() prefix fallback maps the live phases-2.7-2.14
categories (weather_warning, wildfire_incident, earthquake_event,
traffic_congestion, geomagnetic/rf_*, stream_*, ...) to their family, fixing the
v0.4 "category -> other" gap.
- config_loader.py: SECRET_FIELDS += notifications.toggles.*.smtp_password.
- _dataclass_to_dict now recurses dict-of-dataclasses, and the loader coerces the
toggles dict -> NotificationToggle on both the full-load and section-PUT paths
(so GUI save round-trips correctly).
- tests/test_notification_toggles.py (11): enabled/disabled, region filter
(empty+populated+regions-list), severity threshold, per-severity channel routing,
digest-skipped-live, quiet-hours-override immediate-only, category->family,
rules+toggles both fire. Full suite: 294 passed (283 + 11).
SECTION 2 -- FRONTEND
- Notifications.tsx: MasterToggles component above the rules section -- 8 family
cards (icon + enable toggle; collapsed summary 'OFF' or 'N regions, M channels at
<sev>+'; expanded: severity threshold, severity x channel checkbox matrix,
region list, quiet-hours-override toggle, per-channel config:
broadcast_channel/DM node IDs/recipients/SMTP host+port/webhook URL).
- Environment.tsx: CentralConnectionPanel above the family tabs (url, durable,
enabled) wired to environmental.central.
- npm run build clean (tsc strict); rebuilt static committed (index-CfYlhn4e.js).
SECTION 3 -- VERIFICATION
- py_compile + tsc strict clean; pytest 294 passed.
- Rebuilt prod: /notifications serves Master Toggles, /environment serves Central
Connection (strings confirmed in the served bundle); 8 adapters, pipeline
started, no tracebacks, healthy.
- GUI round-trip: enable weather toggle (min_severity=priority,
regions=[Magic Valley], severity_channels.priority=[mesh_broadcast]) -> PUT
{saved:true} -> notifications.yaml reflects it; env_feeds traffic.api_key stayed
${TOMTOM_API_KEY} (C.3.1 secret preservation holds). Restored to clean opt-in
baseline.
- Synthetic NWS weather_warning/priority/Magic Valley -> routes through the weather
toggle to mesh_broadcast; out-of-region and below-threshold events correctly
dropped.
DEFERRED (noted for a follow-up, not blocking Matt's morning config): Section 2B
rules-editor polish -- grouped-by-family category checkboxes, region_scope
multi-select in the rule editor (backend field + filtering ARE in), tooltips, and
the fire-count Active/No-activity badge -- were not built tonight to keep the build
shippable and verified; the Advanced Rules section is otherwise unchanged and
still functional.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
11e37c4f48
commit
b90afc3a74
10 changed files with 574 additions and 143 deletions
|
|
@ -480,6 +480,7 @@ class NotificationRuleConfig:
|
|||
# Condition trigger fields
|
||||
categories: list = field(default_factory=list) # Empty = all categories
|
||||
min_severity: str = "routine"
|
||||
region_scope: list = field(default_factory=list) # [] = all regions
|
||||
|
||||
# Schedule trigger fields
|
||||
schedule_frequency: str = "daily" # daily, twice_daily, weekly, custom
|
||||
|
|
@ -522,6 +523,56 @@ class NotificationRuleConfig:
|
|||
|
||||
|
||||
|
||||
@dataclass
|
||||
class NotificationToggle:
|
||||
"""Per-family master toggle: severity threshold + region scope + per-severity
|
||||
channel routing (PagerDuty/Grafana-style notification policy)."""
|
||||
|
||||
name: str = ""
|
||||
enabled: bool = False
|
||||
min_severity: str = "priority" # routine|priority|immediate
|
||||
regions: list = field(default_factory=list) # [] = all regions
|
||||
# severity -> list of channel types (digest|mesh_broadcast|mesh_dm|email|webhook)
|
||||
severity_channels: dict = field(default_factory=dict)
|
||||
quiet_hours_override: bool = True # immediate-only quiet-hours bypass
|
||||
# per-channel delivery config (mirrors NotificationRuleConfig channel fields)
|
||||
broadcast_channel: Optional[int] = None
|
||||
node_ids: list = field(default_factory=list)
|
||||
smtp_host: str = ""
|
||||
smtp_port: int = 587
|
||||
smtp_user: str = ""
|
||||
smtp_password: str = ""
|
||||
smtp_tls: bool = True
|
||||
from_address: str = ""
|
||||
recipients: list = field(default_factory=list)
|
||||
webhook_url: str = ""
|
||||
webhook_headers: dict = field(default_factory=dict)
|
||||
|
||||
|
||||
TOGGLE_FAMILIES = [
|
||||
"mesh_health", "weather", "fire", "rf_propagation",
|
||||
"roads", "avalanche", "seismic", "tracking",
|
||||
]
|
||||
|
||||
|
||||
def _default_toggles() -> dict:
|
||||
"""8 family master-toggles, all opt-in (disabled) by default."""
|
||||
return {
|
||||
fam: NotificationToggle(
|
||||
name=fam,
|
||||
enabled=False,
|
||||
min_severity="priority",
|
||||
regions=[],
|
||||
severity_channels={
|
||||
"priority": ["mesh_broadcast"],
|
||||
"immediate": ["mesh_broadcast", "mesh_dm"],
|
||||
},
|
||||
quiet_hours_override=True,
|
||||
)
|
||||
for fam in TOGGLE_FAMILIES
|
||||
}
|
||||
|
||||
|
||||
@dataclass
|
||||
class TogglesConfig:
|
||||
"""Master toggle filter settings."""
|
||||
|
|
@ -545,7 +596,7 @@ class NotificationsConfig:
|
|||
quiet_hours_enabled: bool = True # Master toggle for quiet hours
|
||||
quiet_hours_start: str = "22:00"
|
||||
quiet_hours_end: str = "06:00"
|
||||
toggles: TogglesConfig = field(default_factory=TogglesConfig)
|
||||
toggles: dict = field(default_factory=_default_toggles) # family -> NotificationToggle
|
||||
digest: DigestConfig = field(default_factory=DigestConfig)
|
||||
rules: list = field(default_factory=list) # List of NotificationRuleConfig
|
||||
|
||||
|
|
@ -687,6 +738,11 @@ def _dict_to_dataclass(cls, data: dict):
|
|||
_dict_to_dataclass(NotificationRuleConfig, r) if isinstance(r, dict) else r
|
||||
for r in value["rules"]
|
||||
]
|
||||
if "toggles" in value and isinstance(value["toggles"], dict):
|
||||
notifications.toggles = {
|
||||
name: _dict_to_dataclass(NotificationToggle, t) if isinstance(t, dict) else t
|
||||
for name, t in value["toggles"].items()
|
||||
}
|
||||
if "channels" in value and isinstance(value["channels"], list) and value["channels"]:
|
||||
_migrate_legacy_channels(notifications, value)
|
||||
kwargs[key] = notifications
|
||||
|
|
@ -734,7 +790,11 @@ def _dict_to_dataclass(cls, data: dict):
|
|||
elif key == "dashboard" and isinstance(value, dict):
|
||||
kwargs[key] = _dict_to_dataclass(DashboardConfig, value)
|
||||
elif key == "toggles" and isinstance(value, dict):
|
||||
kwargs[key] = _dict_to_dataclass(TogglesConfig, value)
|
||||
# v0.5: notifications.toggles is a dict of family -> NotificationToggle
|
||||
kwargs[key] = {
|
||||
fam: _dict_to_dataclass(NotificationToggle, t) if isinstance(t, dict) else t
|
||||
for fam, t in value.items()
|
||||
}
|
||||
elif key == "digest" and isinstance(value, dict):
|
||||
kwargs[key] = _dict_to_dataclass(DigestConfig, value)
|
||||
else:
|
||||
|
|
@ -761,6 +821,12 @@ def _dataclass_to_dict(obj) -> dict:
|
|||
_dataclass_to_dict(item) if hasattr(item, "__dataclass_fields__") else item
|
||||
for item in value
|
||||
]
|
||||
elif isinstance(value, dict):
|
||||
# Handle dict of dataclasses (like notifications.toggles)
|
||||
result[field_name] = {
|
||||
k: _dataclass_to_dict(v) if hasattr(v, "__dataclass_fields__") else v
|
||||
for k, v in value.items()
|
||||
}
|
||||
else:
|
||||
result[field_name] = value
|
||||
return result
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue