swink_agent_patterns/pipeline/
output.rs1use std::time::Duration;
4
5use swink_agent::Usage;
6
7use super::types::PipelineId;
8
9#[non_exhaustive]
13#[derive(Clone, Debug)]
14pub struct StepResult {
15 pub agent_name: String,
17 pub response: String,
19 pub duration: Duration,
21 pub usage: Usage,
23}
24
25impl StepResult {
26 #[must_use]
28 pub fn new(
29 agent_name: impl Into<String>,
30 response: impl Into<String>,
31 duration: Duration,
32 usage: Usage,
33 ) -> Self {
34 Self {
35 agent_name: agent_name.into(),
36 response: response.into(),
37 duration,
38 usage,
39 }
40 }
41}
42
43#[non_exhaustive]
47#[derive(Clone, Debug)]
48pub struct PipelineOutput {
49 pub pipeline_id: PipelineId,
51 pub final_response: String,
53 pub steps: Vec<StepResult>,
55 pub total_duration: Duration,
57 pub total_usage: Usage,
59}
60
61impl PipelineOutput {
62 #[must_use]
65 pub fn new(pipeline_id: PipelineId, final_response: impl Into<String>) -> Self {
66 Self {
67 pipeline_id,
68 final_response: final_response.into(),
69 steps: Vec::new(),
70 total_duration: Duration::ZERO,
71 total_usage: Usage::default(),
72 }
73 }
74
75 #[must_use]
77 pub fn with_steps(mut self, steps: Vec<StepResult>) -> Self {
78 self.steps = steps;
79 self
80 }
81
82 #[must_use]
84 pub fn with_total_duration(mut self, total_duration: Duration) -> Self {
85 self.total_duration = total_duration;
86 self
87 }
88
89 #[must_use]
91 pub fn with_total_usage(mut self, total_usage: Usage) -> Self {
92 self.total_usage = total_usage;
93 self
94 }
95}
96
97#[non_exhaustive]
101#[derive(Debug, thiserror::Error)]
102pub enum PipelineError {
103 #[error("agent not found: {name}")]
105 AgentNotFound { name: String },
106 #[error("pipeline not found: {id}")]
108 PipelineNotFound { id: PipelineId },
109 #[error("step {step_index} ({agent_name}) failed: {source}")]
111 StepFailed {
112 step_index: usize,
113 agent_name: String,
114 source: Box<dyn std::error::Error + Send + Sync>,
115 },
116 #[error("max iterations reached: {iterations}")]
118 MaxIterationsReached { iterations: usize },
119 #[error("pipeline cancelled")]
121 Cancelled,
122 #[error("invalid exit condition: {message}")]
124 InvalidExitCondition { message: String },
125}