EventBuilder

Struct EventBuilder 

Source
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()) accept Option<T> and only set the field if Some is passed; None preserves 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

Source

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.

Source

pub fn build(self) -> Event

Build the final Event.

Source

pub fn tokens(self, input: i64, output: i64) -> Self

Set input and output tokens together.

Source

pub fn cache_tokens(self, read: i64, write: i64) -> Self

Set cache read and cache write tokens together.

Source

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).

Source

pub fn framework(self, framework: impl Into<String>) -> Self

Set the framework.

Source

pub fn model(self, model: impl Into<String>) -> Self

Set the model.

Source

pub fn cost(self, cost_usd: f64) -> Self

Set the cost in USD.

Source

pub fn duration_ms(self, duration: i64) -> Self

Set the duration in milliseconds.

Source

pub fn timestamp(self, timestamp: DateTime<Utc>) -> Self

Set the timestamp.

Source

pub fn payload(self, payload: impl Into<String>) -> Self

Set the payload JSON string.

Source

pub fn metadata(self, metadata: impl Into<String>) -> Self

Set the metadata JSON string.

Source

pub fn tool_use_id(self, tool_use_id: impl Into<String>) -> Self

Set the tool_use_id.

Source

pub fn tool_name(self, tool_name: impl Into<String>) -> Self

Set the tool_name.

Source

pub fn spawned_agent_id(self, spawned_agent_id: impl Into<String>) -> Self

Set the spawned_agent_id.

Source

pub fn subagent_type(self, subagent_type: impl Into<String>) -> Self

Set the subagent_type.

Source

pub fn permission_mode(self, permission_mode: impl Into<String>) -> Self

Set the permission_mode.

Source

pub fn transcript_path(self, transcript_path: impl Into<String>) -> Self

Set the transcript_path.

Source

pub fn cwd(self, cwd: impl Into<String>) -> Self

Set the cwd.

Source

pub fn git_branch(self, git_branch: impl Into<String>) -> Self

Set the git_branch.

Source

pub fn pid(self, pid: i32) -> Self

Set the pid.

Source

pub fn process_start_time(self, start_time: i64) -> Self

Set the process_start_time.

Source

pub fn framework_opt(self, framework: Option<String>) -> Self

Set the framework if Some.

Source

pub fn timestamp_opt(self, timestamp: Option<DateTime<Utc>>) -> Self

Set the timestamp if Some.

Source

pub fn tool_use_id_opt(self, tool_use_id: Option<String>) -> Self

Set the tool_use_id if Some.

Source

pub fn tool_name_opt(self, tool_name: Option<String>) -> Self

Set the tool_name if Some.

Source

pub fn spawned_agent_id_opt(self, spawned_agent_id: Option<String>) -> Self

Set the spawned_agent_id if Some.

Source

pub fn subagent_type_opt(self, subagent_type: Option<String>) -> Self

Set the subagent_type if Some.

Source

pub fn permission_mode_opt(self, permission_mode: Option<String>) -> Self

Set the permission_mode if Some.

Source

pub fn transcript_path_opt(self, transcript_path: Option<String>) -> Self

Set the transcript_path if Some.

Source

pub fn cwd_opt(self, cwd: Option<String>) -> Self

Set the cwd if Some.

Source

pub fn git_branch_opt(self, git_branch: Option<String>) -> Self

Set the git_branch if Some.

Source

pub fn pid_opt(self, pid: Option<i32>) -> Self

Set the pid if Some.

Source

pub fn process_start_time_opt(self, start_time: Option<i64>) -> Self

Set the process_start_time if Some.

Source

pub fn model_opt(self, model: Option<String>) -> Self

Set the model if Some.

Source

pub fn tokens_cache_read_opt(self, tokens: Option<i64>) -> Self

Set the tokens_cache_read if Some.

Source

pub fn tokens_cache_write_opt(self, tokens: Option<i64>) -> Self

Set the tokens_cache_write if Some.

Source

pub fn cost_opt(self, cost: Option<f64>) -> Self

Set the cost_usd if Some.

Source

pub fn duration_ms_opt(self, duration: Option<i64>) -> Self

Set the duration_ms if Some.

Source

pub fn metadata_opt(self, metadata: Option<String>) -> Self

Set the metadata if Some.

Source

pub fn payload_opt(self, payload: Option<String>) -> Self

Set the payload if Some.

Source

pub fn source(self, source: impl Into<String>) -> Self

Set the data source (hook, otel, transcript).

Source

pub fn is_sidechain(self, is_sidechain: bool) -> Self

Set whether this is a sidechain request.

Source

pub fn is_sidechain_opt(self, is_sidechain: Option<bool>) -> Self

Set is_sidechain if Some.

Source

pub fn context_size(self, context_size: i64) -> Self

Set the context window size.

Trait Implementations§

Source§

impl Clone for EventBuilder

Source§

fn clone(&self) -> EventBuilder

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for EventBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.