Skip to main content

StepInterceptor

Trait StepInterceptor 

Source
pub trait StepInterceptor: Send + Sync {
    // Required method
    fn intercept(
        &self,
        config: &StepConfig,
    ) -> Option<Result<StepOutput, EngineError>>;

    // Provided methods
    fn intercept_approval(
        &self,
        name: &str,
        config: &ApprovalConfig,
    ) -> Option<ApprovalOutcome> { ... }
    fn intercept_human_input(
        &self,
        name: &str,
        config: &HumanInputConfig,
        schema: &Value,
    ) -> Option<HumanInputOutcome> { ... }
}
Expand description

Resolves steps without executing them.

§Examples

use ironflow_engine::config::{ShellConfig, StepConfig};
use ironflow_engine::error::EngineError;
use ironflow_engine::executor::{StepArtifacts, StepInterceptor, StepOutput};
use rust_decimal::Decimal;
use serde_json::json;

struct AlwaysOk;

impl StepInterceptor for AlwaysOk {
    fn intercept(&self, config: &StepConfig) -> Option<Result<StepOutput, EngineError>> {
        match config {
            StepConfig::Shell(_) => Some(Ok(StepOutput {
                output: json!({"stdout": "ok", "stderr": "", "exit_code": 0}),
                duration_ms: 0,
                cost_usd: Decimal::ZERO,
                input_tokens: None,
                cache_read_input_tokens: None,
                cache_creation_input_tokens: None,
                output_tokens: None,
                model: None,
                debug_messages: None,
                artifacts: StepArtifacts::default(),
            })),
            _ => None,
        }
    }
}

let config = StepConfig::Shell(ShellConfig::new("./deploy.sh"));
let intercepted = AlwaysOk.intercept(&config).expect("shell is intercepted");
assert_eq!(intercepted.expect("canned output").stdout(), "ok");

Required Methods§

Source

fn intercept( &self, config: &StepConfig, ) -> Option<Result<StepOutput, EngineError>>

Return Some(result) to short-circuit this step, None to execute it for real.

Provided Methods§

Source

fn intercept_approval( &self, name: &str, config: &ApprovalConfig, ) -> Option<ApprovalOutcome>

Resolve an approval gate instead of suspending the run.

The default implementation returns None: the gate suspends the run.

Source

fn intercept_human_input( &self, name: &str, config: &HumanInputConfig, schema: &Value, ) -> Option<HumanInputOutcome>

Answer a human input step instead of suspending the run.

schema is the JSON schema of the expected answer. The default implementation returns None: the input suspends the run.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§