Expand description
JSON Patch utilities for AG-UI state delta generation.
This module provides utilities for working with JSON Patch (RFC 6902) operations, enabling efficient state synchronization between agents and frontends through delta updates.
§Overview
JSON Patch is a format for describing changes to a JSON document. Instead of sending the entire state on every update, you can send just the changes (patches) which is more efficient for large state objects.
§Example
use ag_ui_core::patch::{create_patch, apply_patch};
use serde_json::json;
// Create a patch from two states
let old_state = json!({"count": 0, "items": []});
let new_state = json!({"count": 1, "items": ["apple"]});
let patch = create_patch(&old_state, &new_state);
// Apply patch to recreate the new state
let mut state = old_state.clone();
apply_patch(&mut state, &patch).unwrap();
assert_eq!(state, new_state);Structs§
- AddOperation
- JSON Patch ‘add’ operation representation
- Copy
Operation - JSON Patch ‘copy’ operation representation
- Move
Operation - JSON Patch ‘move’ operation representation
- Patch
- Representation of JSON Patch (list of patch operations)
- Patch
Builder - A builder for constructing JSON Patches programmatically.
- Patch
Error - Error type for patch operations.
- Remove
Operation - JSON Patch ‘remove’ operation representation
- Replace
Operation - JSON Patch ‘replace’ operation representation
- Test
Operation - JSON Patch ‘test’ operation representation
Enums§
- Patch
Operation - JSON Patch single patch operation
Functions§
- apply_
patch - Applies a JSON Patch to a JSON value in place.
- apply_
patch_ from_ value - Applies a JSON Patch from a JSON array representation.
- can_
apply_ patch - Checks if applying a patch would succeed without actually modifying the target.
- create_
patch - Creates a JSON Patch representing the difference between two JSON values.
- merge_
patches - Merges two patches into one.
- patch_
to_ value - Converts a Patch to a JSON value for serialization.
- patch_
to_ vec - Converts a Patch to a vector of JSON values.