initial commit

This commit is contained in:
2026-03-16 06:52:12 +01:00
parent b496d726d3
commit 251dc829b3
14 changed files with 465 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
from collections import defaultdict
from typing import Any, Callable
from domain.ports import EventBusPort
class EventBus(EventBusPort):
"""Prosta implementacja szyny zdarzeń (event bus).
Zgodnie z lekcją — architektura oparta o zdarzenia umożliwia:
- monitorowanie działań agenta
- podejmowanie akcji (np. kompresja kontekstu, logowanie)
- subskrypcję zdarzeń z różnych komponentów
"""
def __init__(self) -> None:
self._listeners: dict[str, list[Callable]] = defaultdict(list)
def emit(self, event: str, data: dict[str, Any]) -> None:
for callback in self._listeners[event]:
callback(data)
def on(self, event: str, callback: Callable) -> None:
self._listeners[event].append(callback)