from __future__ import annotations

from dataclasses import dataclass
from typing import Iterable, Protocol


@dataclass
class StreamEvent:
    event_id: int
    data: str
    prompt_tokens: int
    completion_tokens: int


class EventSink(Protocol):
    def emit(self, event: StreamEvent) -> None: ...


class StreamCoordinator:
    """Coordinates provider streaming emissions with replay persistence."""

    def __init__(self, *, sink: EventSink) -> None:
        self._sink = sink

    def forward(self, events: Iterable[StreamEvent]) -> None:
        for event in events:
            self._sink.emit(event)
