33 lines
834 B
Python
33 lines
834 B
Python
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
from dataclasses import dataclass, field
|
||
|
|
from typing import Any
|
||
|
|
|
||
|
|
|
||
|
|
@dataclass
|
||
|
|
class PipelineContext:
|
||
|
|
event_type: str = ""
|
||
|
|
event_data: dict[str, Any] = field(default_factory=dict)
|
||
|
|
|
||
|
|
msg_id: str = ""
|
||
|
|
chat_id: str = ""
|
||
|
|
chat_type: str = ""
|
||
|
|
sender_id: str = ""
|
||
|
|
sender_name: str = ""
|
||
|
|
content: str = ""
|
||
|
|
metadata: dict[str, Any] = field(default_factory=dict)
|
||
|
|
|
||
|
|
_stop_reason: str | None = None
|
||
|
|
|
||
|
|
@property
|
||
|
|
def stopped(self) -> bool:
|
||
|
|
return self._stop_reason is not None
|
||
|
|
|
||
|
|
def stop(self, reason: str = "") -> None:
|
||
|
|
self._stop_reason = reason or "pipeline_stop"
|
||
|
|
|
||
|
|
def debug_summary(self) -> str:
|
||
|
|
return (
|
||
|
|
f"PipelineContext[{self.event_type}](sender={self.sender_id}, msg={self.msg_id}, stop={self._stop_reason})"
|
||
|
|
)
|