Skip to main content

Crate mfm_sdk

Crate mfm_sdk 

Source
Expand description

Orchestration SDK for planning and launching MFM runs.

mfm-sdk sits above mfm-machine and below transport layers such as the CLI and REST API. It provides stable identifiers, operation and pipeline traits, and launcher contracts for turning deterministic op descriptions into executable mfm-machine plans.

Source of truth: docs/redesign.md (v4) Appendix C.2.

§Examples

use async_trait::async_trait;
use std::sync::Arc;

use mfm_machine::config::RunConfig;
use mfm_machine::context::DynContext;
use mfm_machine::errors::StateError;
use mfm_machine::ids::{OpId, OpPath, StateId};
use mfm_machine::io::IoProvider;
use mfm_machine::meta::{DependencyStrategy, Idempotency, SideEffectKind, StateMeta};
use mfm_machine::plan::{StateGraph, StateNode};
use mfm_machine::recorder::EventRecorder;
use mfm_machine::state::{SnapshotPolicy, State, StateOutcome};
use mfm_sdk::errors::SdkError;
use mfm_sdk::op::{OpIo, Operation};
use mfm_sdk::unstable::HashMapOperationRegistry;

struct ExampleState;

#[async_trait]
impl State for ExampleState {
    fn meta(&self) -> StateMeta {
        StateMeta {
            tags: Vec::new(),
            depends_on: Vec::new(),
            depends_on_strategy: DependencyStrategy::Latest,
            side_effects: SideEffectKind::Pure,
            idempotency: Idempotency::None,
        }
    }

    async fn handle(
        &self,
        _ctx: &mut dyn DynContext,
        _io: &mut dyn IoProvider,
        _rec: &mut dyn EventRecorder,
    ) -> Result<StateOutcome, StateError> {
        Ok(StateOutcome {
            snapshot: SnapshotPolicy::OnSuccess,
        })
    }
}

struct ExampleOp;

impl Operation for ExampleOp {
    fn op_id(&self) -> OpId {
        OpId::must_new("example")
    }

    fn op_version(&self) -> String {
        "v1".to_string()
    }

    fn io(&self, _op_config: &serde_json::Value) -> Result<OpIo, SdkError> {
        Ok(OpIo {
            imports: Vec::new(),
            exports: Vec::new(),
        })
    }

    fn expand(
        &self,
        _op_path: OpPath,
        _op_config: &serde_json::Value,
        _run_config: &RunConfig,
    ) -> Result<StateGraph, SdkError> {
        Ok(StateGraph {
            states: vec![StateNode {
                id: StateId::must_new("example.main.report"),
                state: Arc::new(ExampleState),
            }],
            edges: Vec::new(),
        })
    }
}

let mut registry = HashMapOperationRegistry::default();
registry.register(Arc::new(ExampleOp));

Anything not listed in Appendix C.2 is internal or unstable, even if temporarily public.

Modules§

errors
Typed SDK errors returned by planners and launch helpers.
ids
Stable identifiers used by pipeline planners and operation definitions.
launcher
Contracts for launching and resuming pipeline runs.
op
Traits and types for deterministic operation definitions.
pipeline
Pipeline composition types used to flatten multi-op workflows into execution plans.
unstable
Unstable helper implementations for planning and launching.