Attach unhashed turn data to a change. Serializes `UnhashedTurnData` as JSON and stores it under the `"agent_turn"` key in `change.unhashed`. Creates the unhashed JSON object if it doesn't exist.
(
change: &mut atomic_core::change::Change,
data: &UnhashedTurnData,
)
| 120 | /// `"agent_turn"` key in `change.unhashed`. Creates the unhashed |
| 121 | /// JSON object if it doesn't exist. |
| 122 | pub fn attach_unhashed( |
| 123 | change: &mut atomic_core::change::Change, |
| 124 | data: &UnhashedTurnData, |
| 125 | ) -> Result<(), serde_json::Error> { |
| 126 | let value = serde_json::to_value(data)?; |
| 127 | |
| 128 | let unhashed = change.unhashed.get_or_insert_with(|| serde_json::json!({})); |
| 129 | |
| 130 | if let Some(obj) = unhashed.as_object_mut() { |
| 131 | obj.insert(UNHASHED_KEY.to_string(), value); |
| 132 | } |
| 133 | |
| 134 | Ok(()) |
| 135 | } |
| 136 | |
| 137 | /// Extract unhashed turn data from a change. |
| 138 | /// |