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