repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
Mirrored from https://github.com/yingqi-z20/Agent-libOS
stars
latest
clone command
git clone gitlawb://did:key:z6MkqRzA...RfoM/yingqi-z20-Agen...git clone gitlawb://did:key:z6MkqRzA.../yingqi-z20-Agen...d98dd2c9IPC1d ago| #1 | from __future__ import annotations |
| #2 | |
| #3 | import builtins |
| #4 | from typing import Any |
| #5 | |
| #6 | from agent_libos.utils.ids import new_id, utc_now |
| #7 | from agent_libos.models import Event, EventPriority, EventType |
| #8 | from agent_libos.storage import SQLiteStore |
| #9 | |
| #10 | |
| #11 | class EventBus: |
| #12 | def __init__(self, store: SQLiteStore): |
| #13 | self.store = store |
| #14 | |
| #15 | def emit( |
| #16 | self, |
| #17 | event_type: EventType | str, |
| #18 | source: str, |
| #19 | target: str | None = None, |
| #20 | payload: dict[str, Any] | None = None, |
| #21 | priority: EventPriority | str = EventPriority.NORMAL, |
| #22 | correlation_id: str | None = None, |
| #23 | causality: dict[str, Any] | None = None, |
| #24 | ) -> Event: |
| #25 | event = Event( |
| #26 | event_id=new_id("evt"), |
| #27 | type=EventType(event_type), |
| #28 | source=source, |
| #29 | target=target, |
| #30 | payload=payload or {}, |
| #31 | priority=EventPriority(priority), |
| #32 | created_at=utc_now(), |
| #33 | correlation_id=correlation_id, |
| #34 | causality=causality or {}, |
| #35 | ) |
| #36 | self.store.insert_event(event) |
| #37 | return event |
| #38 | |
| #39 | def list(self, target: str | None = None) -> builtins.list[Event]: |
| #40 | return self.store.list_events(target=target) |
| #41 |