"""WebEventSink:实现 §7 A 的 sink 协议,把 AgentLoop.emit 桥到 RunBroker。

绑 task_id(0004 简化:run_id 已合并入 task 当前状态)。`emit({type, ...})` 直接转
broker.emit(task_id, event)。sink 实例由 web 层在启 run 时创建,传进 AgentLoop;
loop 完全不知 web 存在(§5 Less Scaffolding)。
"""
from __future__ import annotations

from typing import Any
from uuid import UUID

class WebEventSink:
    def __init__(self, broker, task_id: UUID) -> None:
        # broker: LocalRunBroker | RedisRunBroker(鸭子类型同接口,web/broker.py)
        self._broker = broker
        self._task_id = task_id

    def emit(self, event: dict[str, Any]) -> None:
        self._broker.emit(self._task_id, event)
