mirror of
https://github.com/fabro-sh/fabro.git
synced 2026-09-15 23:32:46 +00:00
refactor: remove dead code and unnecessary clones in run event types
Remove unused RunEventHeader and AssistantUsageProps structs, simplify identity RunNoticeLevel conversion, and return references from event_name()/properties() instead of cloning. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
1ce4a4ca4d
commit
264576ea85
7 changed files with 9 additions and 53 deletions
|
|
@ -439,11 +439,7 @@ pub(super) fn from_run_event(stored: &RunEvent) -> Option<ProgressEvent> {
|
|||
duration_ms: props.duration_ms,
|
||||
}),
|
||||
EventBody::RunNotice(props) => Some(ProgressEvent::RunNotice {
|
||||
level: match props.level {
|
||||
fabro_types::RunNoticeLevel::Info => RunNoticeLevel::Info,
|
||||
fabro_types::RunNoticeLevel::Warn => RunNoticeLevel::Warn,
|
||||
fabro_types::RunNoticeLevel::Error => RunNoticeLevel::Error,
|
||||
},
|
||||
level: props.level,
|
||||
code: props.code.clone(),
|
||||
message: props.message.clone(),
|
||||
}),
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
|
||||
use super::TokenUsage;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct ParallelStartedProps {
|
||||
pub visit: u32,
|
||||
|
|
@ -234,26 +232,3 @@ pub struct RetroFailedProps {
|
|||
pub error: String,
|
||||
pub duration_ms: u64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct AssistantUsageProps {
|
||||
pub model: String,
|
||||
pub input_tokens: u64,
|
||||
pub output_tokens: u64,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub speed: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub cost: Option<f64>,
|
||||
}
|
||||
|
||||
impl From<TokenUsage> for AssistantUsageProps {
|
||||
fn from(value: TokenUsage) -> Self {
|
||||
Self {
|
||||
model: String::new(),
|
||||
input_tokens: u64::try_from(value.input_tokens).unwrap_or_default(),
|
||||
output_tokens: u64::try_from(value.output_tokens).unwrap_or_default(),
|
||||
speed: value.speed,
|
||||
cost: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -338,12 +338,12 @@ impl RunEvent {
|
|||
Ok(Value::Object(map))
|
||||
}
|
||||
|
||||
pub fn event_name(&self) -> String {
|
||||
self.event.clone()
|
||||
pub fn event_name(&self) -> &str {
|
||||
&self.event
|
||||
}
|
||||
|
||||
pub fn properties(&self) -> Value {
|
||||
self.properties.clone()
|
||||
pub fn properties(&self) -> &Value {
|
||||
&self.properties
|
||||
}
|
||||
|
||||
pub fn refresh_cache(&mut self) {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use std::collections::BTreeMap;
|
|||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{Graph, RunId, Settings, StatusReason};
|
||||
use crate::{Graph, Settings, StatusReason};
|
||||
|
||||
use super::{RunNoticeLevel, TokenUsage};
|
||||
|
||||
|
|
@ -93,18 +93,3 @@ pub struct RunNoticeProps {
|
|||
pub code: String,
|
||||
pub message: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct RunEventHeader {
|
||||
pub id: String,
|
||||
pub ts: chrono::DateTime<chrono::Utc>,
|
||||
pub run_id: RunId,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub node_id: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub node_label: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub session_id: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub parent_session_id: Option<String>,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ impl RunLifecycle<WorkflowGraph> for EventLifecycle {
|
|||
// Reset run_start for duration measurement
|
||||
*self.run_start.lock().unwrap() = Instant::now();
|
||||
|
||||
// Emit WorkflowRunStarted
|
||||
// Emit RunStarted
|
||||
self.emitter.emit(&Event::WorkflowRunStarted {
|
||||
name: self.graph_name.clone(),
|
||||
run_id: self.run_id,
|
||||
|
|
|
|||
|
|
@ -938,7 +938,7 @@ async fn run_with_lifecycle_emits_initialize_and_setup_events() {
|
|||
let events_clone = Arc::clone(&events);
|
||||
let emitter = test_emitter("order-test");
|
||||
emitter.on_event(move |event| {
|
||||
let name = match event.event_name().as_str() {
|
||||
let name = match event.event_name() {
|
||||
"sandbox.initialized" => "SandboxInitialized",
|
||||
"setup.started" => "SetupStarted",
|
||||
"setup.completed" => "SetupCompleted",
|
||||
|
|
|
|||
|
|
@ -829,7 +829,7 @@ mod tests {
|
|||
let seen = Arc::new(std::sync::Mutex::new(Vec::new()));
|
||||
emitter.on_event({
|
||||
let seen = Arc::clone(&seen);
|
||||
move |event| seen.lock().unwrap().push(event.event_name())
|
||||
move |event| seen.lock().unwrap().push(event.event_name().to_string())
|
||||
});
|
||||
store_logger.register(&emitter);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue