Converted all external tool calling to async
This commit is contained in:
@@ -3,8 +3,10 @@
|
||||
use crate::agent_log::AgentLogWriter;
|
||||
use crate::config::ProjectConfig;
|
||||
use crate::slog_error;
|
||||
use std::future::Future;
|
||||
use std::path::Path;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::pin::Pin;
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::broadcast;
|
||||
|
||||
use super::super::runtime::{
|
||||
@@ -38,48 +40,48 @@ impl AgentPool {
|
||||
/// `resume_context` (if any) is sent as the new message. This lets
|
||||
/// the agent re-enter the previous conversation without re-reading
|
||||
/// CLAUDE.md and README, satisfying story 543.
|
||||
pub async fn start_agent(
|
||||
&self,
|
||||
project_root: &Path,
|
||||
story_id: &str,
|
||||
agent_name: Option<&str>,
|
||||
resume_context: Option<&str>,
|
||||
pub fn start_agent<'a>(
|
||||
&'a self,
|
||||
project_root: &'a Path,
|
||||
story_id: &'a str,
|
||||
agent_name: Option<&'a str>,
|
||||
resume_context: Option<&'a str>,
|
||||
session_id_to_resume: Option<String>,
|
||||
) -> Result<AgentInfo, String> {
|
||||
self.start_agent_inner(
|
||||
) -> Pin<Box<dyn Future<Output = Result<AgentInfo, String>> + Send + 'a>> {
|
||||
Box::pin(self.start_agent_inner(
|
||||
project_root,
|
||||
story_id,
|
||||
agent_name,
|
||||
resume_context,
|
||||
session_id_to_resume,
|
||||
None,
|
||||
)
|
||||
))
|
||||
}
|
||||
|
||||
/// Start an agent with an `AppContext` for direct MCP tool dispatch.
|
||||
///
|
||||
/// API-based runtimes (Gemini, OpenAI) need the `AppContext` to invoke MCP
|
||||
/// tools without an HTTP round-trip. CLI-based runtimes (Claude Code) do not.
|
||||
pub fn start_agent_with_ctx(
|
||||
&self,
|
||||
project_root: &Path,
|
||||
story_id: &str,
|
||||
agent_name: Option<&str>,
|
||||
resume_context: Option<&str>,
|
||||
pub fn start_agent_with_ctx<'a>(
|
||||
&'a self,
|
||||
project_root: &'a Path,
|
||||
story_id: &'a str,
|
||||
agent_name: Option<&'a str>,
|
||||
resume_context: Option<&'a str>,
|
||||
session_id_to_resume: Option<String>,
|
||||
app_ctx: Arc<crate::http::context::AppContext>,
|
||||
) -> Result<AgentInfo, String> {
|
||||
self.start_agent_inner(
|
||||
) -> Pin<Box<dyn Future<Output = Result<AgentInfo, String>> + Send + 'a>> {
|
||||
Box::pin(self.start_agent_inner(
|
||||
project_root,
|
||||
story_id,
|
||||
agent_name,
|
||||
resume_context,
|
||||
session_id_to_resume,
|
||||
Some(app_ctx),
|
||||
)
|
||||
))
|
||||
}
|
||||
|
||||
fn start_agent_inner(
|
||||
async fn start_agent_inner(
|
||||
&self,
|
||||
project_root: &Path,
|
||||
story_id: &str,
|
||||
@@ -100,7 +102,8 @@ impl AgentPool {
|
||||
// Create name-independent shared resources before the lock so they are
|
||||
// ready for the atomic check-and-insert (story 132).
|
||||
let (tx, _) = broadcast::channel::<AgentEvent>(1024);
|
||||
let event_log: Arc<Mutex<Vec<AgentEvent>>> = Arc::new(Mutex::new(Vec::new()));
|
||||
let event_log: Arc<std::sync::Mutex<Vec<AgentEvent>>> =
|
||||
Arc::new(std::sync::Mutex::new(Vec::new()));
|
||||
let log_session_id = uuid::Uuid::new_v4().to_string();
|
||||
|
||||
// Create the per-session status buffer subscribed to this project's
|
||||
@@ -149,7 +152,7 @@ impl AgentPool {
|
||||
// agent turn (story 736).
|
||||
let prior_events: Option<String>;
|
||||
{
|
||||
let mut agents = self.agents.lock().map_err(|e| e.to_string())?;
|
||||
let mut agents = self.agents.lock().await;
|
||||
|
||||
resolved_name = match agent_name {
|
||||
Some(name) => name.to_string(),
|
||||
@@ -371,7 +374,7 @@ impl AgentPool {
|
||||
// the atomic resolution above).
|
||||
let log_writer =
|
||||
match AgentLogWriter::new(project_root, story_id, &resolved_name, &log_session_id) {
|
||||
Ok(w) => Some(Arc::new(Mutex::new(w))),
|
||||
Ok(w) => Some(Arc::new(std::sync::Mutex::new(w))),
|
||||
Err(e) => {
|
||||
eprintln!(
|
||||
"[agents] Failed to create log writer for {story_id}:{resolved_name}: {e}"
|
||||
@@ -436,7 +439,7 @@ impl AgentPool {
|
||||
|
||||
// Store the task handle while the agent is still Pending.
|
||||
{
|
||||
let mut agents = self.agents.lock().map_err(|e| e.to_string())?;
|
||||
let mut agents = self.agents.lock().await;
|
||||
if let Some(agent) = agents.get_mut(&key) {
|
||||
agent.task_handle = Some(handle);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user