never executed always true always false
    1 module PureClaw.Handles.Memory
    2   ( -- * Memory types
    3     SearchConfig (..)
    4   , SearchResult (..)
    5   , MemorySource (..)
    6   , MemoryEntry (..)
    7   , defaultSearchConfig
    8     -- * Handle type
    9   , MemoryHandle (..)
   10     -- * Implementations
   11   , mkNoOpMemoryHandle
   12   ) where
   13 
   14 import Data.Map (Map)
   15 import Data.Text (Text)
   16 import Data.Time
   17 
   18 import PureClaw.Core.Types
   19 
   20 -- | Configuration for memory search operations.
   21 data SearchConfig = SearchConfig
   22   { _sc_maxResults :: Int
   23   , _sc_minScore   :: Double
   24   }
   25   deriving stock (Show, Eq)
   26 
   27 -- | Sensible defaults for memory search.
   28 defaultSearchConfig :: SearchConfig
   29 defaultSearchConfig = SearchConfig
   30   { _sc_maxResults = 10
   31   , _sc_minScore   = 0.0
   32   }
   33 
   34 -- | A single result from a memory search.
   35 data SearchResult = SearchResult
   36   { _sr_memoryId :: MemoryId
   37   , _sr_content  :: Text
   38   , _sr_score    :: Double
   39   }
   40   deriving stock (Show, Eq)
   41 
   42 -- | Source material to save into memory.
   43 data MemorySource = MemorySource
   44   { _ms_content  :: Text
   45   , _ms_metadata :: Map Text Text
   46   }
   47   deriving stock (Show, Eq)
   48 
   49 -- | A recalled memory entry with its metadata and creation time.
   50 data MemoryEntry = MemoryEntry
   51   { _me_memoryId  :: MemoryId
   52   , _me_content   :: Text
   53   , _me_metadata  :: Map Text Text
   54   , _me_createdAt :: UTCTime
   55   }
   56   deriving stock (Show, Eq)
   57 
   58 -- | Memory capability interface. Concrete implementations (SQLite,
   59 -- Markdown, None) live in @PureClaw.Memory.*@ modules.
   60 data MemoryHandle = MemoryHandle
   61   { _mh_search :: Text -> SearchConfig -> IO [SearchResult]
   62   , _mh_save   :: MemorySource -> IO (Maybe MemoryId)
   63   , _mh_recall :: MemoryId -> IO (Maybe MemoryEntry)
   64   }
   65 
   66 -- | No-op memory handle. Search returns empty, save returns Nothing,
   67 -- recall returns Nothing.
   68 mkNoOpMemoryHandle :: MemoryHandle
   69 mkNoOpMemoryHandle = MemoryHandle
   70   { _mh_search = \_ _ -> pure []
   71   , _mh_save   = \_ -> pure Nothing
   72   , _mh_recall = \_ -> pure Nothing
   73   }