pub struct EventBuilder { /* private fields */ }Expand description
Builder for creating Event instances with an ergonomic API.
Provides helper methods that group related fields together and accept
non-Option values directly, reducing verbosity compared to chained with_* calls.
§Method variants
- Regular setters (e.g.,
framework(),model()) accept values directly and always set the field. - Optional setters (e.g.,
framework_opt(),model_opt()) acceptOption<T>and only set the field ifSomeis passed;Nonepreserves any previously set value. - Grouped helpers (e.g.,
tokens(),cache_tokens(),tool()) set multiple related fields at once for common patterns.
§Example
use mi6_core::{EventBuilder, EventType};
// Building an API request event
let event = EventBuilder::new("machine-1", EventType::ApiRequest, "session-123")
.framework("claude")
.tokens(1000, 500)
.cache_tokens(200, 0)
.cost(0.05)
.model("claude-3-opus")
.build();
// Building a hook event
let event = EventBuilder::new("machine-1", EventType::PreToolUse, "session-123")
.framework("claude")
.tool("toolu_123", "Bash")
.payload(r#"{"command": "ls"}"#)
.build();
// Using _opt methods to conditionally set fields
let maybe_model: Option<String> = Some("claude-3-opus".to_string());
let event = EventBuilder::new("machine-1", EventType::ApiRequest, "session-123")
.model_opt(maybe_model) // Sets model to "claude-3-opus"
.model_opt(None) // Does nothing, preserves "claude-3-opus"
.build();Implementations§
Source§impl EventBuilder
impl EventBuilder
Sourcepub fn new(
machine_id: impl Into<String>,
event_type: EventType,
session_id: impl Into<String>,
) -> Self
pub fn new( machine_id: impl Into<String>, event_type: EventType, session_id: impl Into<String>, ) -> Self
Create a new EventBuilder with required fields.
The timestamp is set to the current time; use timestamp() to override.
Sourcepub fn cache_tokens(self, read: i64, write: i64) -> Self
pub fn cache_tokens(self, read: i64, write: i64) -> Self
Set cache read and cache write tokens together.
Sourcepub fn tool(
self,
tool_use_id: impl Into<String>,
tool_name: impl Into<String>,
) -> Self
pub fn tool( self, tool_use_id: impl Into<String>, tool_name: impl Into<String>, ) -> Self
Set tool_use_id and tool_name together (common for tool events).
Sourcepub fn duration_ms(self, duration: i64) -> Self
pub fn duration_ms(self, duration: i64) -> Self
Set the duration in milliseconds.
Sourcepub fn tool_use_id(self, tool_use_id: impl Into<String>) -> Self
pub fn tool_use_id(self, tool_use_id: impl Into<String>) -> Self
Set the tool_use_id.
Sourcepub fn spawned_agent_id(self, spawned_agent_id: impl Into<String>) -> Self
pub fn spawned_agent_id(self, spawned_agent_id: impl Into<String>) -> Self
Set the spawned_agent_id.
Sourcepub fn subagent_type(self, subagent_type: impl Into<String>) -> Self
pub fn subagent_type(self, subagent_type: impl Into<String>) -> Self
Set the subagent_type.
Sourcepub fn permission_mode(self, permission_mode: impl Into<String>) -> Self
pub fn permission_mode(self, permission_mode: impl Into<String>) -> Self
Set the permission_mode.
Sourcepub fn transcript_path(self, transcript_path: impl Into<String>) -> Self
pub fn transcript_path(self, transcript_path: impl Into<String>) -> Self
Set the transcript_path.
Sourcepub fn git_branch(self, git_branch: impl Into<String>) -> Self
pub fn git_branch(self, git_branch: impl Into<String>) -> Self
Set the git_branch.
Sourcepub fn process_start_time(self, start_time: i64) -> Self
pub fn process_start_time(self, start_time: i64) -> Self
Set the process_start_time.
Sourcepub fn framework_opt(self, framework: Option<String>) -> Self
pub fn framework_opt(self, framework: Option<String>) -> Self
Set the framework if Some.
Sourcepub fn timestamp_opt(self, timestamp: Option<DateTime<Utc>>) -> Self
pub fn timestamp_opt(self, timestamp: Option<DateTime<Utc>>) -> Self
Set the timestamp if Some.
Sourcepub fn tool_use_id_opt(self, tool_use_id: Option<String>) -> Self
pub fn tool_use_id_opt(self, tool_use_id: Option<String>) -> Self
Set the tool_use_id if Some.
Sourcepub fn tool_name_opt(self, tool_name: Option<String>) -> Self
pub fn tool_name_opt(self, tool_name: Option<String>) -> Self
Set the tool_name if Some.
Sourcepub fn spawned_agent_id_opt(self, spawned_agent_id: Option<String>) -> Self
pub fn spawned_agent_id_opt(self, spawned_agent_id: Option<String>) -> Self
Set the spawned_agent_id if Some.
Sourcepub fn subagent_type_opt(self, subagent_type: Option<String>) -> Self
pub fn subagent_type_opt(self, subagent_type: Option<String>) -> Self
Set the subagent_type if Some.
Sourcepub fn permission_mode_opt(self, permission_mode: Option<String>) -> Self
pub fn permission_mode_opt(self, permission_mode: Option<String>) -> Self
Set the permission_mode if Some.
Sourcepub fn transcript_path_opt(self, transcript_path: Option<String>) -> Self
pub fn transcript_path_opt(self, transcript_path: Option<String>) -> Self
Set the transcript_path if Some.
Sourcepub fn git_branch_opt(self, git_branch: Option<String>) -> Self
pub fn git_branch_opt(self, git_branch: Option<String>) -> Self
Set the git_branch if Some.
Sourcepub fn process_start_time_opt(self, start_time: Option<i64>) -> Self
pub fn process_start_time_opt(self, start_time: Option<i64>) -> Self
Set the process_start_time if Some.
Sourcepub fn tokens_cache_read_opt(self, tokens: Option<i64>) -> Self
pub fn tokens_cache_read_opt(self, tokens: Option<i64>) -> Self
Set the tokens_cache_read if Some.
Sourcepub fn tokens_cache_write_opt(self, tokens: Option<i64>) -> Self
pub fn tokens_cache_write_opt(self, tokens: Option<i64>) -> Self
Set the tokens_cache_write if Some.
Sourcepub fn duration_ms_opt(self, duration: Option<i64>) -> Self
pub fn duration_ms_opt(self, duration: Option<i64>) -> Self
Set the duration_ms if Some.
Sourcepub fn metadata_opt(self, metadata: Option<String>) -> Self
pub fn metadata_opt(self, metadata: Option<String>) -> Self
Set the metadata if Some.
Sourcepub fn payload_opt(self, payload: Option<String>) -> Self
pub fn payload_opt(self, payload: Option<String>) -> Self
Set the payload if Some.
Sourcepub fn source(self, source: impl Into<String>) -> Self
pub fn source(self, source: impl Into<String>) -> Self
Set the data source (hook, otel, transcript).
Sourcepub fn is_sidechain(self, is_sidechain: bool) -> Self
pub fn is_sidechain(self, is_sidechain: bool) -> Self
Set whether this is a sidechain request.
Sourcepub fn is_sidechain_opt(self, is_sidechain: Option<bool>) -> Self
pub fn is_sidechain_opt(self, is_sidechain: Option<bool>) -> Self
Set is_sidechain if Some.
Sourcepub fn context_size(self, context_size: i64) -> Self
pub fn context_size(self, context_size: i64) -> Self
Set the context window size.
Trait Implementations§
Source§impl Clone for EventBuilder
impl Clone for EventBuilder
Source§fn clone(&self) -> EventBuilder
fn clone(&self) -> EventBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more