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,
)
| 152 | /// `"agent_turn"` key in `change.unhashed`. Creates the unhashed |
| 153 | /// JSON object if it doesn't exist. |
| 154 | pub fn attach_unhashed( |
| 155 | change: &mut atomic_core::change::Change, |
| 156 | data: &UnhashedTurnData, |
| 157 | ) -> Result<(), serde_json::Error> { |
| 158 | let value = serde_json::to_value(data)?; |
| 159 | |
| 160 | let unhashed = change.unhashed.get_or_insert_with(|| serde_json::json!({})); |
| 161 | |
| 162 | if let Some(obj) = unhashed.as_object_mut() { |
| 163 | obj.insert(UNHASHED_KEY.to_string(), value); |
| 164 | } |
| 165 | |
| 166 | Ok(()) |
| 167 | } |
| 168 | |
| 169 | /// Extract unhashed turn data from a change. |
| 170 | /// |