6
6
from typing import Any , List , Literal , Optional , Union , Annotated
7
7
from pydantic import Field
8
8
9
- from .types import Message , State , ConfiguredBaseModel
9
+ from .types import Message , State , ConfiguredBaseModel , Role
10
10
11
11
12
12
class EventType (str , Enum ):
@@ -52,36 +52,32 @@ class TextMessageStartEvent(BaseEvent):
52
52
"""
53
53
Event indicating the start of a text message.
54
54
"""
55
- type : Literal [EventType .TEXT_MESSAGE_START ]
55
+ type : Literal [EventType .TEXT_MESSAGE_START ] = Field ( EventType . TEXT_MESSAGE_START , init = False ) # pyright: ignore[reportIncompatibleVariableOverride]
56
56
message_id : str
57
- role : Literal ["assistant" ]
57
+ role : Literal [Role . ASSISTANT ] = Field ( Role . ASSISTANT , init = False )
58
58
59
59
60
60
class TextMessageContentEvent (BaseEvent ):
61
61
"""
62
62
Event containing a piece of text message content.
63
63
"""
64
- type : Literal [EventType .TEXT_MESSAGE_CONTENT ]
64
+ type : Literal [EventType .TEXT_MESSAGE_CONTENT ] = Field ( EventType . TEXT_MESSAGE_CONTENT , init = False ) # pyright: ignore[reportIncompatibleVariableOverride]
65
65
message_id : str
66
- delta : str # This should not be an empty string
67
-
68
- def model_post_init (self , __context ):
69
- if len (self .delta ) == 0 :
70
- raise ValueError ("Delta must not be an empty string" )
66
+ delta : str = Field (min_length = 1 )
71
67
72
68
73
69
class TextMessageEndEvent (BaseEvent ):
74
70
"""
75
71
Event indicating the end of a text message.
76
72
"""
77
- type : Literal [EventType .TEXT_MESSAGE_END ]
73
+ type : Literal [EventType .TEXT_MESSAGE_END ] = Field ( EventType . TEXT_MESSAGE_END , init = False ) # pyright: ignore[reportIncompatibleVariableOverride]
78
74
message_id : str
79
75
80
76
class TextMessageChunkEvent (BaseEvent ):
81
77
"""
82
78
Event containing a chunk of text message content.
83
79
"""
84
- type : Literal [EventType .TEXT_MESSAGE_CHUNK ]
80
+ type : Literal [EventType .TEXT_MESSAGE_CHUNK ] = Field ( EventType . TEXT_MESSAGE_CHUNK , init = False ) # pyright: ignore[reportIncompatibleVariableOverride]
85
81
message_id : Optional [str ] = None
86
82
role : Optional [Literal ["assistant" ]] = None
87
83
delta : Optional [str ] = None
@@ -113,7 +109,7 @@ class ToolCallStartEvent(BaseEvent):
113
109
"""
114
110
Event indicating the start of a tool call.
115
111
"""
116
- type : Literal [EventType .TOOL_CALL_START ]
112
+ type : Literal [EventType .TOOL_CALL_START ] = Field ( EventType . TOOL_CALL_START , init = False ) # pyright: ignore[reportIncompatibleVariableOverride]
117
113
tool_call_id : str
118
114
tool_call_name : str
119
115
parent_message_id : Optional [str ] = None
@@ -123,7 +119,7 @@ class ToolCallArgsEvent(BaseEvent):
123
119
"""
124
120
Event containing tool call arguments.
125
121
"""
126
- type : Literal [EventType .TOOL_CALL_ARGS ]
122
+ type : Literal [EventType .TOOL_CALL_ARGS ] = Field ( EventType . TOOL_CALL_ARGS , init = False ) # pyright: ignore[reportIncompatibleVariableOverride]
127
123
tool_call_id : str
128
124
delta : str
129
125
@@ -132,14 +128,14 @@ class ToolCallEndEvent(BaseEvent):
132
128
"""
133
129
Event indicating the end of a tool call.
134
130
"""
135
- type : Literal [EventType .TOOL_CALL_END ]
131
+ type : Literal [EventType .TOOL_CALL_END ] = Field ( EventType . TOOL_CALL_END , init = False ) # pyright: ignore[reportIncompatibleVariableOverride]
136
132
tool_call_id : str
137
133
138
134
class ToolCallChunkEvent (BaseEvent ):
139
135
"""
140
136
Event containing a chunk of tool call content.
141
137
"""
142
- type : Literal [EventType .TOOL_CALL_CHUNK ]
138
+ type : Literal [EventType .TOOL_CALL_CHUNK ] = Field ( EventType . TOOL_CALL_CHUNK , init = False ) # pyright: ignore[reportIncompatibleVariableOverride]
143
139
tool_call_id : Optional [str ] = None
144
140
tool_call_name : Optional [str ] = None
145
141
parent_message_id : Optional [str ] = None
@@ -172,31 +168,31 @@ class StateSnapshotEvent(BaseEvent):
172
168
"""
173
169
Event containing a snapshot of the state.
174
170
"""
175
- type : Literal [EventType .STATE_SNAPSHOT ]
171
+ type : Literal [EventType .STATE_SNAPSHOT ] = Field ( EventType . STATE_SNAPSHOT , init = False ) # pyright: ignore[reportIncompatibleVariableOverride]
176
172
snapshot : State
177
173
178
174
179
175
class StateDeltaEvent (BaseEvent ):
180
176
"""
181
177
Event containing a delta of the state.
182
178
"""
183
- type : Literal [EventType .STATE_DELTA ]
179
+ type : Literal [EventType .STATE_DELTA ] = Field ( EventType . STATE_DELTA , init = False ) # pyright: ignore[reportIncompatibleVariableOverride]
184
180
delta : List [Any ] # JSON Patch (RFC 6902)
185
181
186
182
187
183
class MessagesSnapshotEvent (BaseEvent ):
188
184
"""
189
185
Event containing a snapshot of the messages.
190
186
"""
191
- type : Literal [EventType .MESSAGES_SNAPSHOT ]
187
+ type : Literal [EventType .MESSAGES_SNAPSHOT ] = Field ( EventType . MESSAGES_SNAPSHOT , init = False ) # pyright: ignore[reportIncompatibleVariableOverride]
192
188
messages : List [Message ]
193
189
194
190
195
191
class RawEvent (BaseEvent ):
196
192
"""
197
193
Event containing a raw event.
198
194
"""
199
- type : Literal [EventType .RAW ]
195
+ type : Literal [EventType .RAW ] = Field ( EventType . RAW , init = False ) # pyright: ignore[reportIncompatibleVariableOverride]
200
196
event : Any
201
197
source : Optional [str ] = None
202
198
@@ -205,7 +201,7 @@ class CustomEvent(BaseEvent):
205
201
"""
206
202
Event containing a custom event.
207
203
"""
208
- type : Literal [EventType .CUSTOM ]
204
+ type : Literal [EventType .CUSTOM ] = Field ( EventType . CUSTOM , init = False ) # pyright: ignore[reportIncompatibleVariableOverride]
209
205
name : str
210
206
value : Any
211
207
@@ -214,7 +210,7 @@ class RunStartedEvent(BaseEvent):
214
210
"""
215
211
Event indicating that a run has started.
216
212
"""
217
- type : Literal [EventType .RUN_STARTED ]
213
+ type : Literal [EventType .RUN_STARTED ] = Field ( EventType . RUN_STARTED , init = False ) # pyright: ignore[reportIncompatibleVariableOverride]
218
214
thread_id : str
219
215
run_id : str
220
216
@@ -223,7 +219,7 @@ class RunFinishedEvent(BaseEvent):
223
219
"""
224
220
Event indicating that a run has finished.
225
221
"""
226
- type : Literal [EventType .RUN_FINISHED ]
222
+ type : Literal [EventType .RUN_FINISHED ] = Field ( EventType . RUN_FINISHED , init = False ) # pyright: ignore[reportIncompatibleVariableOverride]
227
223
thread_id : str
228
224
run_id : str
229
225
result : Optional [Any ] = None
@@ -233,7 +229,7 @@ class RunErrorEvent(BaseEvent):
233
229
"""
234
230
Event indicating that a run has encountered an error.
235
231
"""
236
- type : Literal [EventType .RUN_ERROR ]
232
+ type : Literal [EventType .RUN_ERROR ] = Field ( EventType . RUN_ERROR , init = False ) # pyright: ignore[reportIncompatibleVariableOverride]
237
233
message : str
238
234
code : Optional [str ] = None
239
235
@@ -242,15 +238,15 @@ class StepStartedEvent(BaseEvent):
242
238
"""
243
239
Event indicating that a step has started.
244
240
"""
245
- type : Literal [EventType .STEP_STARTED ]
241
+ type : Literal [EventType .STEP_STARTED ] = Field ( EventType . STEP_STARTED , init = False ) # pyright: ignore[reportIncompatibleVariableOverride]
246
242
step_name : str
247
243
248
244
249
245
class StepFinishedEvent (BaseEvent ):
250
246
"""
251
247
Event indicating that a step has finished.
252
248
"""
253
- type : Literal [EventType .STEP_FINISHED ]
249
+ type : Literal [EventType .STEP_FINISHED ] = Field ( EventType . STEP_FINISHED , init = False ) # pyright: ignore[reportIncompatibleVariableOverride]
254
250
step_name : str
255
251
256
252
0 commit comments