"""Outbound navi→Synapse events — the source side of the integration.
Navi emits low-level lifecycle facts (reaction finished / failed) through the
Synapse ingest API, where they are simply logged. Requires the source key
(`syn_*`) registered in the Synapse admin panel; without it nothing is sent.
"""
import structlog
from navi.config import settings
log = structlog.get_logger()
def synapse_source_ready() -> bool:
return bool(settings.synapse_source_url and settings.synapse_source_api_key)
async def emit_low_level(
subject: str,
action: str,
payload: dict,
priority: str = "low",
dedup_key: str | None = None,
) -> None:
"""Fire one ingest event; silently skip when source is not configured."""
if not synapse_source_ready():
return
from gnexus_synapse import AsyncSynapseClient
client = AsyncSynapseClient(
url=settings.synapse_source_url,
api_key=settings.synapse_source_api_key,
default_source=settings.synapse_source_name,
)
try:
event = await client.emit(
subject=subject,
action=action,
priority=priority,
payload=payload,
dedup_key=dedup_key,
)
if event is not None:
log.info(
"synapse.outbound_emitted", subject=subject, action=action, event_id=event.id,
)
finally:
await client.aclose()