2026-07-12 11:28:39 +07:00
|
|
|
//! Event variants that a running subagent can emit to its parent via the
|
|
|
|
|
//! shared mpsc channel.
|
|
|
|
|
|
2026-07-11 13:16:10 +07:00
|
|
|
use serde_json::Value;
|
|
|
|
|
|
2026-07-12 11:28:39 +07:00
|
|
|
/// Progress and outcome events emitted by `run_subagent` as it processes
|
|
|
|
|
/// LLM responses and tool calls.
|
2026-07-11 13:16:10 +07:00
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
pub enum SubagentEvent {
|
|
|
|
|
StepCompleted {
|
2026-07-13 08:12:02 +07:00
|
|
|
#[allow(dead_code)]
|
|
|
|
|
step: usize,
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
output: String,
|
2026-07-11 13:16:10 +07:00
|
|
|
},
|
|
|
|
|
StepFailed {
|
2026-07-13 08:12:02 +07:00
|
|
|
step: usize,
|
|
|
|
|
error: String,
|
2026-07-11 13:16:10 +07:00
|
|
|
},
|
|
|
|
|
Completed {
|
2026-07-13 08:12:02 +07:00
|
|
|
#[allow(dead_code)]
|
|
|
|
|
output: String,
|
2026-07-11 13:16:10 +07:00
|
|
|
},
|
|
|
|
|
ToolCall {
|
2026-07-13 08:12:02 +07:00
|
|
|
tool: String,
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
args: Value,
|
2026-07-11 13:16:10 +07:00
|
|
|
},
|
|
|
|
|
ToolResult {
|
2026-07-13 08:12:02 +07:00
|
|
|
tool: String,
|
2026-07-15 02:18:30 +07:00
|
|
|
args: Value,
|
2026-07-13 08:12:02 +07:00
|
|
|
#[allow(dead_code)]
|
|
|
|
|
output: String,
|
2026-07-11 13:16:10 +07:00
|
|
|
},
|
2026-07-15 02:14:10 +07:00
|
|
|
Progress(String),
|
2026-07-15 03:11:49 +07:00
|
|
|
/// Token usage reported by the LLM after one streaming call inside the
|
|
|
|
|
/// subagent. The drain thread accumulates these across all steps and
|
|
|
|
|
/// forwards the total to the parent's `TurnEvent::ReviewUsage` handler
|
|
|
|
|
/// so the Usage panel can split "main" tokens from "self-learning"
|
|
|
|
|
/// tokens (review, test-gen, arch-review, security-review, etc.).
|
|
|
|
|
///
|
|
|
|
|
/// Why a separate variant instead of folding into `Completed`: usage
|
|
|
|
|
/// is reported per-step, so the parent can update the running total
|
|
|
|
|
/// incrementally rather than waiting for the whole subagent run to
|
|
|
|
|
/// finish. The drain thread still aggregates before forwarding.
|
|
|
|
|
Usage {
|
|
|
|
|
tokens_in: u64,
|
|
|
|
|
tokens_out: u64,
|
|
|
|
|
},
|
2026-07-11 13:16:10 +07:00
|
|
|
}
|