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 ):
@@ -46,36 +46,32 @@ class TextMessageStartEvent(BaseEvent):
46
46
"""
47
47
Event indicating the start of a text message.
48
48
"""
49
- type : Literal [EventType .TEXT_MESSAGE_START ]
49
+ type : Literal [EventType .TEXT_MESSAGE_START ] = Field ( EventType . TEXT_MESSAGE_START , init = False ) # pyright: ignore[reportIncompatibleVariableOverride]
50
50
message_id : str
51
- role : Literal ["assistant" ]
51
+ role : Literal [Role . ASSISTANT ] = Field ( Role . ASSISTANT , init = False )
52
52
53
53
54
54
class TextMessageContentEvent (BaseEvent ):
55
55
"""
56
56
Event containing a piece of text message content.
57
57
"""
58
- type : Literal [EventType .TEXT_MESSAGE_CONTENT ]
58
+ type : Literal [EventType .TEXT_MESSAGE_CONTENT ] = Field ( EventType . TEXT_MESSAGE_CONTENT , init = False ) # pyright: ignore[reportIncompatibleVariableOverride]
59
59
message_id : str
60
- delta : str # This should not be an empty string
61
-
62
- def model_post_init (self , __context ):
63
- if len (self .delta ) == 0 :
64
- raise ValueError ("Delta must not be an empty string" )
60
+ delta : str = Field (min_length = 1 ) # This should not be an empty string
65
61
66
62
67
63
class TextMessageEndEvent (BaseEvent ):
68
64
"""
69
65
Event indicating the end of a text message.
70
66
"""
71
- type : Literal [EventType .TEXT_MESSAGE_END ]
67
+ type : Literal [EventType .TEXT_MESSAGE_END ] = Field ( EventType . TEXT_MESSAGE_END , init = False ) # pyright: ignore[reportIncompatibleVariableOverride]
72
68
message_id : str
73
69
74
70
class TextMessageChunkEvent (BaseEvent ):
75
71
"""
76
72
Event containing a chunk of text message content.
77
73
"""
78
- type : Literal [EventType .TEXT_MESSAGE_CHUNK ]
74
+ type : Literal [EventType .TEXT_MESSAGE_CHUNK ] = Field ( EventType . TEXT_MESSAGE_CHUNK , init = False ) # pyright: ignore[reportIncompatibleVariableOverride]
79
75
message_id : Optional [str ] = None
80
76
role : Optional [Literal ["assistant" ]] = None
81
77
delta : Optional [str ] = None
@@ -84,7 +80,7 @@ class ToolCallStartEvent(BaseEvent):
84
80
"""
85
81
Event indicating the start of a tool call.
86
82
"""
87
- type : Literal [EventType .TOOL_CALL_START ]
83
+ type : Literal [EventType .TOOL_CALL_START ] = Field ( EventType . TOOL_CALL_START , init = False ) # pyright: ignore[reportIncompatibleVariableOverride]
88
84
tool_call_id : str
89
85
tool_call_name : str
90
86
parent_message_id : Optional [str ] = None
@@ -94,7 +90,7 @@ class ToolCallArgsEvent(BaseEvent):
94
90
"""
95
91
Event containing tool call arguments.
96
92
"""
97
- type : Literal [EventType .TOOL_CALL_ARGS ]
93
+ type : Literal [EventType .TOOL_CALL_ARGS ] = Field ( EventType . TOOL_CALL_ARGS , init = False ) # pyright: ignore[reportIncompatibleVariableOverride]
98
94
tool_call_id : str
99
95
delta : str
100
96
@@ -103,14 +99,14 @@ class ToolCallEndEvent(BaseEvent):
103
99
"""
104
100
Event indicating the end of a tool call.
105
101
"""
106
- type : Literal [EventType .TOOL_CALL_END ]
102
+ type : Literal [EventType .TOOL_CALL_END ] = Field ( EventType . TOOL_CALL_END , init = False ) # pyright: ignore[reportIncompatibleVariableOverride]
107
103
tool_call_id : str
108
104
109
105
class ToolCallChunkEvent (BaseEvent ):
110
106
"""
111
107
Event containing a chunk of tool call content.
112
108
"""
113
- type : Literal [EventType .TOOL_CALL_CHUNK ]
109
+ type : Literal [EventType .TOOL_CALL_CHUNK ] = Field ( EventType . TOOL_CALL_CHUNK , init = False ) # pyright: ignore[reportIncompatibleVariableOverride]
114
110
tool_call_id : Optional [str ] = None
115
111
tool_call_name : Optional [str ] = None
116
112
parent_message_id : Optional [str ] = None
@@ -120,31 +116,31 @@ class StateSnapshotEvent(BaseEvent):
120
116
"""
121
117
Event containing a snapshot of the state.
122
118
"""
123
- type : Literal [EventType .STATE_SNAPSHOT ]
119
+ type : Literal [EventType .STATE_SNAPSHOT ] = Field ( EventType . STATE_SNAPSHOT , init = False ) # pyright: ignore[reportIncompatibleVariableOverride]
124
120
snapshot : State
125
121
126
122
127
123
class StateDeltaEvent (BaseEvent ):
128
124
"""
129
125
Event containing a delta of the state.
130
126
"""
131
- type : Literal [EventType .STATE_DELTA ]
127
+ type : Literal [EventType .STATE_DELTA ] = Field ( EventType . STATE_DELTA , init = False ) # pyright: ignore[reportIncompatibleVariableOverride]
132
128
delta : List [Any ] # JSON Patch (RFC 6902)
133
129
134
130
135
131
class MessagesSnapshotEvent (BaseEvent ):
136
132
"""
137
133
Event containing a snapshot of the messages.
138
134
"""
139
- type : Literal [EventType .MESSAGES_SNAPSHOT ]
135
+ type : Literal [EventType .MESSAGES_SNAPSHOT ] = Field ( EventType . MESSAGES_SNAPSHOT , init = False ) # pyright: ignore[reportIncompatibleVariableOverride]
140
136
messages : List [Message ]
141
137
142
138
143
139
class RawEvent (BaseEvent ):
144
140
"""
145
141
Event containing a raw event.
146
142
"""
147
- type : Literal [EventType .RAW ]
143
+ type : Literal [EventType .RAW ] = Field ( EventType . RAW , init = False ) # pyright: ignore[reportIncompatibleVariableOverride]
148
144
event : Any
149
145
source : Optional [str ] = None
150
146
@@ -153,7 +149,7 @@ class CustomEvent(BaseEvent):
153
149
"""
154
150
Event containing a custom event.
155
151
"""
156
- type : Literal [EventType .CUSTOM ]
152
+ type : Literal [EventType .CUSTOM ] = Field ( EventType . CUSTOM , init = False ) # pyright: ignore[reportIncompatibleVariableOverride]
157
153
name : str
158
154
value : Any
159
155
@@ -162,7 +158,7 @@ class RunStartedEvent(BaseEvent):
162
158
"""
163
159
Event indicating that a run has started.
164
160
"""
165
- type : Literal [EventType .RUN_STARTED ]
161
+ type : Literal [EventType .RUN_STARTED ] = Field ( EventType . RUN_STARTED , init = False ) # pyright: ignore[reportIncompatibleVariableOverride]
166
162
thread_id : str
167
163
run_id : str
168
164
@@ -171,7 +167,7 @@ class RunFinishedEvent(BaseEvent):
171
167
"""
172
168
Event indicating that a run has finished.
173
169
"""
174
- type : Literal [EventType .RUN_FINISHED ]
170
+ type : Literal [EventType .RUN_FINISHED ] = Field ( EventType . RUN_FINISHED , init = False ) # pyright: ignore[reportIncompatibleVariableOverride]
175
171
thread_id : str
176
172
run_id : str
177
173
@@ -180,7 +176,7 @@ class RunErrorEvent(BaseEvent):
180
176
"""
181
177
Event indicating that a run has encountered an error.
182
178
"""
183
- type : Literal [EventType .RUN_ERROR ]
179
+ type : Literal [EventType .RUN_ERROR ] = Field ( EventType . RUN_ERROR , init = False ) # pyright: ignore[reportIncompatibleVariableOverride]
184
180
message : str
185
181
code : Optional [str ] = None
186
182
@@ -189,15 +185,15 @@ class StepStartedEvent(BaseEvent):
189
185
"""
190
186
Event indicating that a step has started.
191
187
"""
192
- type : Literal [EventType .STEP_STARTED ]
188
+ type : Literal [EventType .STEP_STARTED ] = Field ( EventType . STEP_STARTED , init = False ) # pyright: ignore[reportIncompatibleVariableOverride]
193
189
step_name : str
194
190
195
191
196
192
class StepFinishedEvent (BaseEvent ):
197
193
"""
198
194
Event indicating that a step has finished.
199
195
"""
200
- type : Literal [EventType .STEP_FINISHED ]
196
+ type : Literal [EventType .STEP_FINISHED ] = Field ( EventType . STEP_FINISHED , init = False ) # pyright: ignore[reportIncompatibleVariableOverride]
201
197
step_name : str
202
198
203
199
0 commit comments