* refactor(events): unify scoped runtime notifications across clients * style(tests): sort auto-compaction event imports * refactor(events): scope connections and remove retry callback plumbing * docs: remove runtime notification design write-up * refactor(bus): route operation events through the message bus * fix(channels): isolate outbound sends by destination * style(events): group shared notification imports * refactor(events): converge runtime and hook delivery on MessageBus * test(events): migrate fixtures to unified message bus
38 lines
1.1 KiB
Python
38 lines
1.1 KiB
Python
"""Explicit audience policy for operation notifications."""
|
|
|
|
from typing import Literal
|
|
|
|
from nanobot.bus.outbound_events import (
|
|
FileEditEvent,
|
|
ProgressEvent,
|
|
StreamDeltaEvent,
|
|
StreamEndEvent,
|
|
)
|
|
from nanobot.events import AgentEvent, ContextCompactionEvent, RecoveryStateEvent, RetryWaitEvent
|
|
|
|
NotificationAudience = Literal["channel", "lifecycle", "interactive"]
|
|
|
|
NOTIFICATION_AUDIENCES: dict[type[AgentEvent], NotificationAudience] = {
|
|
ProgressEvent: "lifecycle",
|
|
FileEditEvent: "lifecycle",
|
|
StreamDeltaEvent: "channel",
|
|
StreamEndEvent: "channel",
|
|
ContextCompactionEvent: "channel",
|
|
RetryWaitEvent: "lifecycle",
|
|
RecoveryStateEvent: "interactive",
|
|
}
|
|
|
|
|
|
def notification_is_deliverable(
|
|
event_type: type[AgentEvent], *, channel: str, publish_lifecycle: bool,
|
|
) -> bool:
|
|
"""Admit operation notifications to a channel only by explicit policy."""
|
|
audience = NOTIFICATION_AUDIENCES.get(event_type)
|
|
if audience is None:
|
|
return False
|
|
if audience == "lifecycle":
|
|
return publish_lifecycle
|
|
if audience == "interactive":
|
|
return channel == "websocket"
|
|
return True
|