weavegraph 0.7.0

Graph-driven, concurrent agent workflow framework with versioned state, deterministic barrier merges, and rich diagnostics.
Documentation
//! Reducers apply [`NodePartial`] deltas to [`VersionedState`] channel-by-channel.
mod add_errors;
mod add_messages;
mod map_merge;
mod reducer_registry;

pub use add_errors::AddErrors;
pub use add_messages::AddMessages;
pub use map_merge::MapMerge;
pub use reducer_registry::*;

use crate::node::NodePartial;
use crate::state::VersionedState;
use crate::types::ChannelType;
use thiserror::Error;

/// Applies a [`NodePartial`] delta to [`VersionedState`] for one channel.
pub trait Reducer: Send + Sync {
    /// Stable identity string included in graph-definition metadata.
    ///
    /// Defaults to the concrete Rust type path. Override with a fixed label when
    /// the type path is too verbose for audit manifests.
    fn definition_label(&self) -> &'static str {
        std::any::type_name::<Self>()
    }

    /// Mutate `state` in-place using the delta in `update`.
    fn apply(&self, state: &mut VersionedState, update: &NodePartial);
}

/// Errors produced by the reducer pipeline.
#[derive(Debug, Error)]
#[cfg_attr(feature = "diagnostics", derive(miette::Diagnostic))]
pub enum ReducerError {
    /// No reducer is registered for the given channel.
    #[error("no reducers registered for channel: {0:?}")]
    #[cfg_attr(
        feature = "diagnostics",
        diagnostic(code(weavegraph::reducers::unknown_channel))
    )]
    UnknownChannel(ChannelType),

    /// A reducer returned an error while applying an update.
    #[error("reducer apply failed for channel {channel:?}: {message}")]
    #[cfg_attr(
        feature = "diagnostics",
        diagnostic(code(weavegraph::reducers::apply_failed))
    )]
    Apply {
        /// Channel the reducer failed on.
        channel: ChannelType,
        /// Description of the failure.
        message: String,
    },
}