Skip to main content

StepflowClient

Struct StepflowClient 

Source
pub struct StepflowClient { /* private fields */ }
Expand description

High-level client for interacting with the Stepflow orchestrator.

Wraps the gRPC service clients for flows, runs, health, and component discovery, providing a convenient API for common operations.

§Example

use stepflow_client::{StepflowClient, FlowBuilder, ValueExpr};

let mut client = StepflowClient::connect("http://localhost:7840").await?;

let mut builder = FlowBuilder::new();
builder.add_step("hello", "/builtin/eval", ValueExpr::null());
let flow = builder.output(ValueExpr::step_output("hello")).build()?;

let flow_id = client.store_flow(&flow).await?;
let output = client.run(&flow_id, serde_json::json!({"name": "world"})).await?;
println!("{output}");

Implementations§

Source§

impl StepflowClient

Source

pub async fn connect(url: impl Into<String>) -> ClientResult<Self>

Connect to the Stepflow orchestrator at the given URL.

The URL should be in the form http://host:port (or https://... for TLS).

Source

pub async fn store_flow(&mut self, flow: &Flow) -> ClientResult<String>

Store a flow definition in the orchestrator, returning its flow ID.

The returned flow ID can be passed to run or submit.

Source

pub async fn run(&mut self, flow_id: &str, input: Value) -> ClientResult<Value>

Execute a flow synchronously, blocking until it completes, and return the output.

This is equivalent to submit + waiting for the run to complete.

Source

pub async fn submit( &mut self, flow_id: &str, input: Value, ) -> ClientResult<String>

Submit a flow for asynchronous execution, returning the run ID.

Use get_run to poll for completion and get_run_items to fetch outputs.

Source

pub async fn get_run( &mut self, run_id: &str, wait: bool, ) -> ClientResult<RunStatus>

Get the status of a run.

If wait is true, the request will block until the run completes (or fails).

Note: outputs are not included in the response — use get_run_items to fetch them after the run completes.

Source

pub async fn get_run_items(&mut self, run_id: &str) -> ClientResult<Vec<Value>>

Get the output of each item in a completed run.

Returns one serde_json::Value per input item, in submission order. Errors for individual items are currently surfaced as ClientError::InvalidResponse.

Source

pub async fn list_components( &mut self, exclude_schemas: bool, ) -> ClientResult<ListComponentsResult>

List all components registered across all plugins.

Set exclude_schemas to true to omit JSON Schemas from the response (faster when you only need component paths and descriptions).

Note: this triggers on-demand component discovery from all plugins and may take a moment if workers haven’t connected yet.

Source

pub async fn status_events( &mut self, run_id: &str, include_sub_runs: bool, include_results: bool, ) -> ClientResult<StatusEventStream>

Stream execution events for a run.

Returns a server-streaming response that emits stepflow_proto::StatusEvents as the run progresses. Drive the stream with stream.message().await.

Set include_sub_runs to also receive events from nested sub-flows. Set include_results to include step outputs in completion events.

§Example
let mut stream = client.status_events(run_id, false, false).await?;
while let Some(event) = stream.message().await? {
    println!("{event:?}");
}
Source

pub async fn get_flow_variables( &mut self, flow_id: &str, ) -> ClientResult<HashMap<String, FlowVariable>>

Get the variable definitions declared in a flow.

Returns a map of variable name → FlowVariable describing the schema, default value, and optional environment variable mapping for each variable.

Source

pub async fn is_healthy(&mut self) -> bool

Check whether the orchestrator is healthy.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> Erased for T