feat: add turn_events to ToolCtx and implement live state updates in spawn tool
This commit is contained in:
@@ -536,6 +536,9 @@ pub fn apply_action(state: &mut AppStateRest, action: Action) {
|
||||
status,
|
||||
});
|
||||
}
|
||||
if state.misc.overlay != Overlay::Workflow {
|
||||
state.misc.overlay = Overlay::Workflow;
|
||||
}
|
||||
state.dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -268,6 +268,7 @@ impl AppStateRest {
|
||||
origin,
|
||||
graduated_checks: Vec::new(),
|
||||
lsp_manager: self.lsp_manager.clone(),
|
||||
turn_events: Some(self.turn_events.clone()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ pub struct ToolCtx {
|
||||
pub origin: crate::app::state::types::Origin,
|
||||
pub graduated_checks: Vec<GraduatedCheck>,
|
||||
pub lsp_manager: Arc<Mutex<crate::app::lsp::LspManager>>,
|
||||
pub turn_events: Option<Arc<Mutex<std::collections::VecDeque<crate::app::state::runtime::TurnEvent>>>>,
|
||||
}
|
||||
|
||||
/// Find which graduated checks apply to a given file path/content pair.
|
||||
@@ -86,6 +87,7 @@ pub struct ToolCtxBuilder {
|
||||
pub origin: crate::app::state::types::Origin,
|
||||
pub graduated_checks: Vec<GraduatedCheck>,
|
||||
pub lsp_manager: Arc<Mutex<crate::app::lsp::LspManager>>,
|
||||
pub turn_events: Option<Arc<Mutex<std::collections::VecDeque<crate::app::state::runtime::TurnEvent>>>>,
|
||||
}
|
||||
|
||||
impl Default for ToolCtxBuilder {
|
||||
@@ -100,6 +102,7 @@ impl Default for ToolCtxBuilder {
|
||||
origin: crate::app::state::types::Origin::Main,
|
||||
graduated_checks: Vec::new(),
|
||||
lsp_manager: Arc::new(Mutex::new(crate::app::lsp::LspManager::new())),
|
||||
turn_events: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -124,6 +127,7 @@ impl ToolCtxBuilder {
|
||||
origin: self.origin,
|
||||
graduated_checks: self.graduated_checks,
|
||||
lsp_manager: self.lsp_manager,
|
||||
turn_events: self.turn_events,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+34
-2
@@ -88,12 +88,28 @@ impl Tool for SpawnAgents {
|
||||
},
|
||||
};
|
||||
|
||||
use std::sync::Arc;
|
||||
let live: Option<crate::app::workflow::engine::LiveStateFn> = _ctx.turn_events.as_ref().map(|turn_events| {
|
||||
let turn_events = turn_events.clone();
|
||||
let f: crate::app::workflow::engine::LiveStateFn = Arc::new(move |agent_id: String, status| {
|
||||
let name = agent_id.chars().take(30).collect::<String>();
|
||||
if let Ok(mut q) = turn_events.lock() {
|
||||
q.push_back(crate::app::state::runtime::TurnEvent::WorkflowAgentUpdate {
|
||||
agent_id,
|
||||
agent_name: name,
|
||||
status,
|
||||
});
|
||||
}
|
||||
});
|
||||
f
|
||||
});
|
||||
|
||||
let results = crate::app::workflow::engine::execute_primitive(
|
||||
&wf.script,
|
||||
&HashMap::new(),
|
||||
max_concurrency,
|
||||
true,
|
||||
None,
|
||||
live.as_ref(),
|
||||
)?;
|
||||
format_results(results, "parallel")
|
||||
}
|
||||
@@ -155,12 +171,28 @@ impl Tool for SpawnPipeline {
|
||||
},
|
||||
};
|
||||
|
||||
use std::sync::Arc;
|
||||
let live: Option<crate::app::workflow::engine::LiveStateFn> = _ctx.turn_events.as_ref().map(|turn_events| {
|
||||
let turn_events = turn_events.clone();
|
||||
let f: crate::app::workflow::engine::LiveStateFn = Arc::new(move |agent_id: String, status| {
|
||||
let name = agent_id.chars().take(30).collect::<String>();
|
||||
if let Ok(mut q) = turn_events.lock() {
|
||||
q.push_back(crate::app::state::runtime::TurnEvent::WorkflowAgentUpdate {
|
||||
agent_id,
|
||||
agent_name: name,
|
||||
status,
|
||||
});
|
||||
}
|
||||
});
|
||||
f
|
||||
});
|
||||
|
||||
let results = crate::app::workflow::engine::execute_primitive(
|
||||
&wf.script,
|
||||
&HashMap::new(),
|
||||
1,
|
||||
false,
|
||||
None,
|
||||
live.as_ref(),
|
||||
)?;
|
||||
format_results(results, "pipeline")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user