Skip to main content

ragrig_gpui/model/
session.rs

1//! Saved conversations shown in the session picker.
2
3/// One saved conversation.
4///
5/// The host owns the store and formats `label`; the picker only reports the
6/// `id` back. This keeps date formatting and localization out of the library.
7#[derive(Clone, Debug, PartialEq, Eq)]
8pub struct SessionEntry {
9    /// Identifier the host uses to load the conversation.
10    pub id: String,
11    /// Preformatted row text, e.g. `12 turns ยท about the methods section`.
12    pub label: String,
13    /// Optional second line, e.g. a timestamp.
14    pub detail: Option<String>,
15}
16
17impl SessionEntry {
18    /// A session row with a label and no detail line.
19    pub fn new(id: impl Into<String>, label: impl Into<String>) -> Self {
20        Self {
21            id: id.into(),
22            label: label.into(),
23            detail: None,
24        }
25    }
26
27    /// Set the second line.
28    pub fn detail(mut self, detail: impl Into<String>) -> Self {
29        self.detail = Some(detail.into());
30        self
31    }
32}
33
34#[cfg(test)]
35mod tests {
36    use super::*;
37
38    #[test]
39    fn a_session_carries_an_id_and_preformatted_text() {
40        let session = SessionEntry::new("s1", "3 turns").detail("yesterday");
41        assert_eq!(session.id, "s1");
42        assert_eq!(session.label, "3 turns");
43        assert_eq!(session.detail.as_deref(), Some("yesterday"));
44    }
45}