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