-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstream_events.py
More file actions
43 lines (35 loc) · 1.15 KB
/
stream_events.py
File metadata and controls
43 lines (35 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""Streaming event types for real-time progress updates."""
from dataclasses import dataclass
from datetime import datetime, timezone
from typing import Any
import uuid
@dataclass
class StreamEvent:
"""A streaming event conforming to docs/schemas/stream-events.schema.json."""
type: str
payload: Any
agent: str | None = None
stage: str | None = None
sequence: int = 0
def to_dict(self) -> dict:
"""Convert to JSON-serializable dict matching the schema."""
return {
"id": str(uuid.uuid4()),
"timestamp": datetime.now(timezone.utc).isoformat().replace("+00:00", "Z"),
"type": self.type,
"agent": self.agent,
"stage": self.stage,
"sequence": self.sequence,
"payload": self.payload,
}
class StreamEventTypes:
"""Constants for event types."""
AGENT_START = "agent_start"
AGENT_COMPLETE = "agent_complete"
TEXT_DELTA = "text_delta"
TOOL_CALL = "tool_call"
TOOL_OUTPUT = "tool_output"
MESSAGE_COMPLETE = "message_complete"
LOOP_START = "loop_start"
LOOP_COMPLETE = "loop_complete"
ERROR = "error"