1use serde_json::Value;
19
20use crate::JsonObject;
21use crate::event::Event;
22use crate::event::activity::{ActivityDeltaEvent, ActivitySnapshotEvent};
23use crate::event::lifecycle::{
24 RunErrorEvent, RunFinishedEvent, RunStartedEvent, StepFinishedEvent, StepStartedEvent,
25};
26use crate::event::reasoning::{
27 ReasoningEncryptedValueEvent, ReasoningEncryptedValueSubtype, ReasoningEndEvent,
28 ReasoningMessageChunkEvent, ReasoningMessageContentEvent, ReasoningMessageEndEvent,
29 ReasoningMessageStartEvent, ReasoningStartEvent, ThinkingEndEvent, ThinkingStartEvent,
30 ThinkingTextMessageContentEvent, ThinkingTextMessageEndEvent, ThinkingTextMessageStartEvent,
31};
32use crate::event::special::{CustomEvent, RawEvent};
33use crate::event::state::{MessagesSnapshotEvent, StateDeltaEvent, StateSnapshotEvent};
34use crate::event::text::{
35 TextMessageChunkEvent, TextMessageContentEvent, TextMessageEndEvent, TextMessageRole,
36 TextMessageStartEvent,
37};
38use crate::event::tool::{
39 ToolCallArgsEvent, ToolCallChunkEvent, ToolCallEndEvent, ToolCallResultEvent,
40 ToolCallStartEvent,
41};
42use crate::ids::{MessageId, RunId, StepName, ThreadId, ToolCallId};
43use crate::message::Message;
44use crate::outcome::{Interrupt, RunOutcome};
45use crate::patch::PatchOperation;
46
47impl Event {
48 pub fn text_message_start(message_id: impl Into<MessageId>, role: TextMessageRole) -> Self {
50 TextMessageStartEvent::new(message_id, role).into()
51 }
52
53 pub fn text_message_content(
55 message_id: impl Into<MessageId>,
56 delta: impl Into<String>,
57 ) -> Self {
58 TextMessageContentEvent::new(message_id, delta).into()
59 }
60
61 pub fn text_message_end(message_id: impl Into<MessageId>) -> Self {
63 TextMessageEndEvent::new(message_id).into()
64 }
65
66 pub fn text_message_chunk(message_id: Option<MessageId>, delta: Option<String>) -> Self {
68 TextMessageChunkEvent::new(message_id, delta).into()
69 }
70
71 pub fn tool_call_start(
73 tool_call_id: impl Into<ToolCallId>,
74 tool_call_name: impl Into<String>,
75 ) -> Self {
76 ToolCallStartEvent::new(tool_call_id, tool_call_name).into()
77 }
78
79 pub fn tool_call_args(tool_call_id: impl Into<ToolCallId>, delta: impl Into<String>) -> Self {
81 ToolCallArgsEvent::new(tool_call_id, delta).into()
82 }
83
84 pub fn tool_call_end(tool_call_id: impl Into<ToolCallId>) -> Self {
86 ToolCallEndEvent::new(tool_call_id).into()
87 }
88
89 pub fn tool_call_chunk(
91 tool_call_id: Option<ToolCallId>,
92 tool_call_name: Option<String>,
93 delta: Option<String>,
94 ) -> Self {
95 ToolCallChunkEvent::new(tool_call_id, tool_call_name, delta).into()
96 }
97
98 pub fn tool_call_result(
100 message_id: impl Into<MessageId>,
101 tool_call_id: impl Into<ToolCallId>,
102 content: impl Into<String>,
103 ) -> Self {
104 ToolCallResultEvent::new(message_id, tool_call_id, content).into()
105 }
106
107 #[deprecated(note = "use Event::reasoning_start")]
109 pub fn thinking_start(title: Option<String>) -> Self {
110 ThinkingStartEvent::new(title).into()
111 }
112
113 #[deprecated(note = "use Event::reasoning_end")]
115 pub fn thinking_end() -> Self {
116 ThinkingEndEvent::default().into()
117 }
118
119 #[deprecated(note = "use Event::reasoning_message_start")]
121 pub fn thinking_text_message_start() -> Self {
122 ThinkingTextMessageStartEvent::default().into()
123 }
124
125 #[deprecated(note = "use Event::reasoning_message_content")]
127 pub fn thinking_text_message_content(delta: impl Into<String>) -> Self {
128 ThinkingTextMessageContentEvent::new(delta).into()
129 }
130
131 #[deprecated(note = "use Event::reasoning_message_end")]
133 pub fn thinking_text_message_end() -> Self {
134 ThinkingTextMessageEndEvent::default().into()
135 }
136
137 pub fn state_snapshot(snapshot: impl Into<Value>) -> Self {
139 StateSnapshotEvent::new(snapshot).into()
140 }
141
142 pub fn state_delta(delta: impl Into<Vec<PatchOperation>>) -> Self {
144 StateDeltaEvent::new(delta).into()
145 }
146
147 pub fn messages_snapshot(messages: impl Into<Vec<Message>>) -> Self {
149 MessagesSnapshotEvent::new(messages).into()
150 }
151
152 pub fn activity_snapshot(
154 message_id: impl Into<MessageId>,
155 activity_type: impl Into<String>,
156 content: JsonObject,
157 ) -> Self {
158 ActivitySnapshotEvent::new(message_id, activity_type, content).into()
159 }
160
161 pub fn activity_delta(
163 message_id: impl Into<MessageId>,
164 activity_type: impl Into<String>,
165 patch: impl Into<Vec<PatchOperation>>,
166 ) -> Self {
167 ActivityDeltaEvent::new(message_id, activity_type, patch).into()
168 }
169
170 pub fn raw(event: impl Into<Value>) -> Self {
172 RawEvent::new(event).into()
173 }
174
175 pub fn custom(name: impl Into<String>, value: impl Into<Value>) -> Self {
177 CustomEvent::new(name, value).into()
178 }
179
180 pub fn run_started(thread_id: impl Into<ThreadId>, run_id: impl Into<RunId>) -> Self {
182 RunStartedEvent::new(thread_id, run_id).into()
183 }
184
185 pub fn run_finished(thread_id: impl Into<ThreadId>, run_id: impl Into<RunId>) -> Self {
188 RunFinishedEvent::new(thread_id, run_id).into()
189 }
190
191 pub fn run_finished_success(thread_id: impl Into<ThreadId>, run_id: impl Into<RunId>) -> Self {
193 RunFinishedEvent::new(thread_id, run_id)
194 .with_outcome(RunOutcome::Success)
195 .into()
196 }
197
198 pub fn run_finished_interrupt(
201 thread_id: impl Into<ThreadId>,
202 run_id: impl Into<RunId>,
203 interrupts: impl Into<Vec<Interrupt>>,
204 ) -> Self {
205 RunFinishedEvent::new(thread_id, run_id)
206 .with_outcome(RunOutcome::interrupt(interrupts))
207 .into()
208 }
209
210 pub fn run_error(message: impl Into<String>) -> Self {
212 RunErrorEvent::new(message).into()
213 }
214
215 pub fn step_started(step_name: impl Into<StepName>) -> Self {
217 StepStartedEvent::new(step_name).into()
218 }
219
220 pub fn step_finished(step_name: impl Into<StepName>) -> Self {
222 StepFinishedEvent::new(step_name).into()
223 }
224
225 pub fn reasoning_start(message_id: impl Into<MessageId>) -> Self {
227 ReasoningStartEvent::new(message_id).into()
228 }
229
230 pub fn reasoning_message_start(message_id: impl Into<MessageId>) -> Self {
232 ReasoningMessageStartEvent::new(message_id).into()
233 }
234
235 pub fn reasoning_message_content(
237 message_id: impl Into<MessageId>,
238 delta: impl Into<String>,
239 ) -> Self {
240 ReasoningMessageContentEvent::new(message_id, delta).into()
241 }
242
243 pub fn reasoning_message_end(message_id: impl Into<MessageId>) -> Self {
245 ReasoningMessageEndEvent::new(message_id).into()
246 }
247
248 pub fn reasoning_message_chunk(message_id: Option<MessageId>, delta: Option<String>) -> Self {
250 ReasoningMessageChunkEvent::new(message_id, delta).into()
251 }
252
253 pub fn reasoning_end(message_id: impl Into<MessageId>) -> Self {
255 ReasoningEndEvent::new(message_id).into()
256 }
257
258 pub fn reasoning_encrypted_value(
260 subtype: ReasoningEncryptedValueSubtype,
261 entity_id: impl Into<String>,
262 encrypted_value: impl Into<String>,
263 ) -> Self {
264 ReasoningEncryptedValueEvent::new(subtype, entity_id, encrypted_value).into()
265 }
266}