1use serde::{Deserialize, Serialize};
2
3#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
11pub enum MemoryRecord {
12 Item {
14 id: String,
15 kind: String,
16 body: Vec<u8>,
17 #[serde(default, skip_serializing_if = "Option::is_none")]
18 origin: Option<crate::graph::SourceRef>,
19 #[serde(default, skip_serializing_if = "Option::is_none")]
20 producer: Option<crate::graph::ProducerInfo>,
21 },
22 Forget {
25 target: String,
26 #[serde(default, skip_serializing_if = "Option::is_none")]
27 conversation: Option<String>,
28 },
29 Feedback {
33 target: String,
34 weight: f32,
35 #[serde(default, skip_serializing_if = "Option::is_none")]
36 conversation: Option<String>,
37 },
38}
39
40#[cfg(all(test, feature = "cbor"))]
41mod tests {
42 use super::*;
43 use crate::framing::{decode_named, encode_named};
44
45 #[test]
46 fn given_each_variant_when_round_tripped_then_should_preserve_fields() {
47 for record in [
48 MemoryRecord::Item {
49 id: "01KWM3K3XEP3NP5TN850J17YBP".to_owned(),
50 kind: "fact".to_owned(),
51 body: b"auth is slow".to_vec(),
52 origin: None,
53 producer: None,
54 },
55 MemoryRecord::Forget {
56 target: "01KWM3K3XEP3NP5TN850J17YBP".to_owned(),
57 conversation: Some("01KWM3K3XEP3NP5TN850J17YBQ".to_owned()),
58 },
59 MemoryRecord::Feedback {
60 target: "01KWM3K3XEP3NP5TN850J17YBP".to_owned(),
61 weight: 1.5,
62 conversation: None,
63 },
64 ] {
65 let bytes = encode_named(&record).expect("encodes");
66 let back: MemoryRecord = decode_named(&bytes).expect("decodes");
67 assert_eq!(back, record);
68 }
69 }
70}