Skip to content

Commit f56f59c

Browse files
stevenhmaxkorp
authored andcommitted
chore(python-sdk): add type literals for new events
Add type literals for the new event types in the Python SDK, so users don't have to manually set the type field when creating event instances.
1 parent 5efeed4 commit f56f59c

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

python-sdk/ag_ui/core/events.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,24 +87,20 @@ class ThinkingTextMessageStartEvent(BaseEvent):
8787
"""
8888
Event indicating the start of a thinking text message.
8989
"""
90-
type: Literal[EventType.THINKING_TEXT_MESSAGE_START]
90+
type: Literal[EventType.THINKING_TEXT_MESSAGE_START] = EventType.THINKING_TEXT_MESSAGE_START # pyright: ignore[reportIncompatibleVariableOverride]
9191

9292
class ThinkingTextMessageContentEvent(BaseEvent):
9393
"""
9494
Event indicating a piece of a thinking text message.
9595
"""
96-
type: Literal[EventType.THINKING_TEXT_MESSAGE_CONTENT]
97-
delta: str # This should not be an empty string
98-
99-
def model_post_init(self, __context):
100-
if len(self.delta) == 0:
101-
raise ValueError("Delta must not be an empty string")
96+
type: Literal[EventType.THINKING_TEXT_MESSAGE_CONTENT] = EventType.THINKING_TEXT_MESSAGE_CONTENT # pyright: ignore[reportIncompatibleVariableOverride]
97+
delta: str = Field(min_length=1)
10298

10399
class ThinkingTextMessageEndEvent(BaseEvent):
104100
"""
105101
Event indicating the end of a thinking text message.
106102
"""
107-
type: Literal[EventType.THINKING_TEXT_MESSAGE_END]
103+
type: Literal[EventType.THINKING_TEXT_MESSAGE_END] = EventType.THINKING_TEXT_MESSAGE_END # pyright: ignore[reportIncompatibleVariableOverride]
108104

109105
class ToolCallStartEvent(BaseEvent):
110106
"""
@@ -147,7 +143,7 @@ class ToolCallResultEvent(BaseEvent):
147143
Event containing the result of a tool call.
148144
"""
149145
message_id: str
150-
type: Literal[EventType.TOOL_CALL_RESULT]
146+
type: Literal[EventType.TOOL_CALL_RESULT] = EventType.TOOL_CALL_RESULT # pyright: ignore[reportIncompatibleVariableOverride]
151147
tool_call_id: str
152148
content: str
153149
role: Optional[Literal["tool"]] = None
@@ -156,14 +152,14 @@ class ThinkingStartEvent(BaseEvent):
156152
"""
157153
Event indicating the start of a thinking step event.
158154
"""
159-
type: Literal[EventType.THINKING_START]
155+
type: Literal[EventType.THINKING_START] = EventType.THINKING_START # pyright: ignore[reportIncompatibleVariableOverride]
160156
title: Optional[str] = None
161157

162158
class ThinkingEndEvent(BaseEvent):
163159
"""
164160
Event indicating the end of a thinking step event.
165161
"""
166-
type: Literal[EventType.THINKING_END]
162+
type: Literal[EventType.THINKING_END] = EventType.THINKING_END # pyright: ignore[reportIncompatibleVariableOverride]
167163

168164
class StateSnapshotEvent(BaseEvent):
169165
"""

0 commit comments

Comments
 (0)