use serde_json::Value;
use crate::JsonObject;
use crate::event::Event;
use crate::event::activity::{ActivityDeltaEvent, ActivitySnapshotEvent};
use crate::event::lifecycle::{
RunErrorEvent, RunFinishedEvent, RunStartedEvent, StepFinishedEvent, StepStartedEvent,
};
use crate::event::reasoning::{
ReasoningEncryptedValueEvent, ReasoningEncryptedValueSubtype, ReasoningEndEvent,
ReasoningMessageChunkEvent, ReasoningMessageContentEvent, ReasoningMessageEndEvent,
ReasoningMessageStartEvent, ReasoningStartEvent, ThinkingEndEvent, ThinkingStartEvent,
ThinkingTextMessageContentEvent, ThinkingTextMessageEndEvent, ThinkingTextMessageStartEvent,
};
use crate::event::special::{CustomEvent, RawEvent};
use crate::event::state::{MessagesSnapshotEvent, StateDeltaEvent, StateSnapshotEvent};
use crate::event::text::{
TextMessageChunkEvent, TextMessageContentEvent, TextMessageEndEvent, TextMessageRole,
TextMessageStartEvent,
};
use crate::event::tool::{
ToolCallArgsEvent, ToolCallChunkEvent, ToolCallEndEvent, ToolCallResultEvent,
ToolCallStartEvent,
};
use crate::ids::{MessageId, RunId, StepName, ThreadId, ToolCallId};
use crate::message::Message;
use crate::outcome::{Interrupt, RunOutcome};
use crate::patch::PatchOperation;
impl Event {
pub fn text_message_start(message_id: impl Into<MessageId>, role: TextMessageRole) -> Self {
TextMessageStartEvent::new(message_id, role).into()
}
pub fn text_message_content(
message_id: impl Into<MessageId>,
delta: impl Into<String>,
) -> Self {
TextMessageContentEvent::new(message_id, delta).into()
}
pub fn text_message_end(message_id: impl Into<MessageId>) -> Self {
TextMessageEndEvent::new(message_id).into()
}
pub fn text_message_chunk(message_id: Option<MessageId>, delta: Option<String>) -> Self {
TextMessageChunkEvent::new(message_id, delta).into()
}
pub fn tool_call_start(
tool_call_id: impl Into<ToolCallId>,
tool_call_name: impl Into<String>,
) -> Self {
ToolCallStartEvent::new(tool_call_id, tool_call_name).into()
}
pub fn tool_call_args(tool_call_id: impl Into<ToolCallId>, delta: impl Into<String>) -> Self {
ToolCallArgsEvent::new(tool_call_id, delta).into()
}
pub fn tool_call_end(tool_call_id: impl Into<ToolCallId>) -> Self {
ToolCallEndEvent::new(tool_call_id).into()
}
pub fn tool_call_chunk(
tool_call_id: Option<ToolCallId>,
tool_call_name: Option<String>,
delta: Option<String>,
) -> Self {
ToolCallChunkEvent::new(tool_call_id, tool_call_name, delta).into()
}
pub fn tool_call_result(
message_id: impl Into<MessageId>,
tool_call_id: impl Into<ToolCallId>,
content: impl Into<String>,
) -> Self {
ToolCallResultEvent::new(message_id, tool_call_id, content).into()
}
#[deprecated(note = "use Event::reasoning_start")]
pub fn thinking_start(title: Option<String>) -> Self {
ThinkingStartEvent::new(title).into()
}
#[deprecated(note = "use Event::reasoning_end")]
pub fn thinking_end() -> Self {
ThinkingEndEvent::default().into()
}
#[deprecated(note = "use Event::reasoning_message_start")]
pub fn thinking_text_message_start() -> Self {
ThinkingTextMessageStartEvent::default().into()
}
#[deprecated(note = "use Event::reasoning_message_content")]
pub fn thinking_text_message_content(delta: impl Into<String>) -> Self {
ThinkingTextMessageContentEvent::new(delta).into()
}
#[deprecated(note = "use Event::reasoning_message_end")]
pub fn thinking_text_message_end() -> Self {
ThinkingTextMessageEndEvent::default().into()
}
pub fn state_snapshot(snapshot: impl Into<Value>) -> Self {
StateSnapshotEvent::new(snapshot).into()
}
pub fn state_delta(delta: impl Into<Vec<PatchOperation>>) -> Self {
StateDeltaEvent::new(delta).into()
}
pub fn messages_snapshot(messages: impl Into<Vec<Message>>) -> Self {
MessagesSnapshotEvent::new(messages).into()
}
pub fn activity_snapshot(
message_id: impl Into<MessageId>,
activity_type: impl Into<String>,
content: JsonObject,
) -> Self {
ActivitySnapshotEvent::new(message_id, activity_type, content).into()
}
pub fn activity_delta(
message_id: impl Into<MessageId>,
activity_type: impl Into<String>,
patch: impl Into<Vec<PatchOperation>>,
) -> Self {
ActivityDeltaEvent::new(message_id, activity_type, patch).into()
}
pub fn raw(event: impl Into<Value>) -> Self {
RawEvent::new(event).into()
}
pub fn custom(name: impl Into<String>, value: impl Into<Value>) -> Self {
CustomEvent::new(name, value).into()
}
pub fn run_started(thread_id: impl Into<ThreadId>, run_id: impl Into<RunId>) -> Self {
RunStartedEvent::new(thread_id, run_id).into()
}
pub fn run_finished(thread_id: impl Into<ThreadId>, run_id: impl Into<RunId>) -> Self {
RunFinishedEvent::new(thread_id, run_id).into()
}
pub fn run_finished_success(thread_id: impl Into<ThreadId>, run_id: impl Into<RunId>) -> Self {
RunFinishedEvent::new(thread_id, run_id)
.with_outcome(RunOutcome::Success)
.into()
}
pub fn run_finished_interrupt(
thread_id: impl Into<ThreadId>,
run_id: impl Into<RunId>,
interrupts: impl Into<Vec<Interrupt>>,
) -> Self {
RunFinishedEvent::new(thread_id, run_id)
.with_outcome(RunOutcome::interrupt(interrupts))
.into()
}
pub fn run_error(message: impl Into<String>) -> Self {
RunErrorEvent::new(message).into()
}
pub fn step_started(step_name: impl Into<StepName>) -> Self {
StepStartedEvent::new(step_name).into()
}
pub fn step_finished(step_name: impl Into<StepName>) -> Self {
StepFinishedEvent::new(step_name).into()
}
pub fn reasoning_start(message_id: impl Into<MessageId>) -> Self {
ReasoningStartEvent::new(message_id).into()
}
pub fn reasoning_message_start(message_id: impl Into<MessageId>) -> Self {
ReasoningMessageStartEvent::new(message_id).into()
}
pub fn reasoning_message_content(
message_id: impl Into<MessageId>,
delta: impl Into<String>,
) -> Self {
ReasoningMessageContentEvent::new(message_id, delta).into()
}
pub fn reasoning_message_end(message_id: impl Into<MessageId>) -> Self {
ReasoningMessageEndEvent::new(message_id).into()
}
pub fn reasoning_message_chunk(message_id: Option<MessageId>, delta: Option<String>) -> Self {
ReasoningMessageChunkEvent::new(message_id, delta).into()
}
pub fn reasoning_end(message_id: impl Into<MessageId>) -> Self {
ReasoningEndEvent::new(message_id).into()
}
pub fn reasoning_encrypted_value(
subtype: ReasoningEncryptedValueSubtype,
entity_id: impl Into<String>,
encrypted_value: impl Into<String>,
) -> Self {
ReasoningEncryptedValueEvent::new(subtype, entity_id, encrypted_value).into()
}
}