82 lines
2.7 KiB
Rust
82 lines
2.7 KiB
Rust
//! Progress reporting types for long-running agent and subagent operations.
|
|||
|
|
//!
|
||
|
|
//! These types are emitted onto the turn-event queue to drive the TUI's
|
||
|
|
//! spinner, progress bar, and agent-status sidebar. They are pure domain
|
||
|
|
//! types with no I/O or framework dependency.
|
||
|
|
|
||
|
|
use crate::agent::AgentStatus;
|
||
|
|
|
||
|
|
/// Describes progress within a single subagent or workflow-node execution.
|
||
|
|
///
|
||
|
|
/// Emitted as a `TurnEvent::AgentProgress` so the UI can show which tool
|
||
|
|
/// the subagent is currently invoking, or which step it has reached.
|
||
|
|
#[derive(Debug, Clone)]
|
||
|
|
pub struct AgentProgress {
|
||
|
|
/// Unique identifier for this agent (e.g. `"Node-0-1"`, `"auto-review"`).
|
||
|
|
pub agent_id: String,
|
||
|
|
/// Human-readable display name shown in the TUI sidebar.
|
||
|
|
pub agent_name: String,
|
||
|
|
/// Current lifecycle status.
|
||
|
|
pub status: AgentStatus,
|
||
|
|
/// Optional description of the current tool or step being executed.
|
||
|
|
/// Set to `None` when the agent is not actively executing a tool.
|
||
|
|
pub current_tool: Option<String>,
|
||
|
|
/// Optional progress range: (completed_steps, total_steps).
|
||
|
|
/// When `None`, the agent shows an indeterminate spinner.
|
||
|
|
pub steps: Option<(u32, u32)>,
|
||
|
|
}
|
||
|
|
|
||
|
|
impl AgentProgress {
|
||
|
|
/// Mark this agent as running with an optional tool name.
|
||
|
|
pub fn running(
|
||
|
|
agent_id: impl Into<String>,
|
||
|
|
agent_name: impl Into<String>,
|
||
|
|
current_tool: Option<String>,
|
||
|
|
) -> Self {
|
||
|
|
AgentProgress {
|
||
|
|
agent_id: agent_id.into(),
|
||
|
|
agent_name: agent_name.into(),
|
||
|
|
status: AgentStatus::Running,
|
||
|
|
current_tool,
|
||
|
|
steps: None,
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Mark this agent as pending (queued but not yet started).
|
||
|
|
pub fn pending(agent_id: impl Into<String>, agent_name: impl Into<String>) -> Self {
|
||
|
|
AgentProgress {
|
||
|
|
agent_id: agent_id.into(),
|
||
|
|
agent_name: agent_name.into(),
|
||
|
|
status: AgentStatus::Pending,
|
||
|
|
current_tool: None,
|
||
|
|
steps: None,
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Mark this agent as completed successfully.
|
||
|
|
pub fn completed(agent_id: impl Into<String>, agent_name: impl Into<String>) -> Self {
|
||
|
|
AgentProgress {
|
||
|
|
agent_id: agent_id.into(),
|
||
|
|
agent_name: agent_name.into(),
|
||
|
|
status: AgentStatus::Completed,
|
||
|
|
current_tool: None,
|
||
|
|
steps: None,
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Mark this agent as failed with an error message.
|
||
|
|
pub fn failed(
|
||
|
|
agent_id: impl Into<String>,
|
||
|
|
agent_name: impl Into<String>,
|
||
|
|
error: String,
|
||
|
|
) -> Self {
|
||
|
|
AgentProgress {
|
||
|
|
agent_id: agent_id.into(),
|
||
|
|
agent_name: agent_name.into(),
|
||
|
|
status: AgentStatus::Failed(error),
|
||
|
|
current_tool: None,
|
||
|
|
steps: None,
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|