weavegraph 0.7.0

Graph-driven, concurrent agent workflow framework with versioned state, deterministic barrier merges, and rich diagnostics.
Documentation
//! Reducer that shallow-merges extra key-value pairs into the extras channel.
//!
//! Follows [JSON Merge Patch](https://www.rfc-editor.org/rfc/rfc7396) (RFC 7396):
//! a `null` value removes the corresponding key from state rather than writing null.
//! This gives [`NodePartial::clear_extra_keys`](crate::node::NodePartial::clear_extra_keys)
//! and [`NodePartial::clear_typed_extra_key`](crate::node::NodePartial::clear_typed_extra_key)
//! full key-deletion semantics without a separate cleanup reducer.
use super::Reducer;
use crate::{channels::Channel, node::NodePartial, state::VersionedState};

/// Merges extra key-value pairs from a [`NodePartial`] into the state extras channel.
///
/// Uses JSON Merge Patch semantics (RFC 7396): an incoming `null` deletes the key;
/// any other value overwrites it. This makes
/// [`NodePartial::clear_extra_keys`](crate::node::NodePartial::clear_extra_keys) and
/// [`NodePartial::clear_typed_extra_key`](crate::node::NodePartial::clear_typed_extra_key)
/// perform a complete key deletion — no cleanup reducer required.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct MapMerge;

impl Reducer for MapMerge {
    fn apply(&self, state: &mut VersionedState, update: &NodePartial) {
        if let Some(patch) = &update.extra
            && !patch.is_empty()
        {
            let map = state.extra.get_mut();
            for (k, v) in patch {
                if v.is_null() {
                    map.remove(k);
                } else {
                    map.insert(k.clone(), v.clone());
                }
            }
        }
    }
}