Class SessionManager

java.lang.Object
uno.anahata.ai.context.session.SessionManager

public class SessionManager extends Object
Manages the persistence and summarization of chat sessions.

This class provides functionality to:

  • Save and load conversation history using Kryo serialization.
  • List available saved sessions.
  • Perform automatic background backups of the current session.
  • Generate a human-readable Markdown summary of the conversation context.

  • Constructor Details

    • SessionManager

      public SessionManager(ContextManager contextManager)
      Constructs a new SessionManager for the given ContextManager.
      Parameters:
      contextManager - The ContextManager to manage sessions for.
  • Method Details

    • saveSession

      public String saveSession(String name) throws IOException
      Saves the current conversation history to a file.
      Parameters:
      name - The name of the session (used as the filename).
      Returns:
      A success message.
      Throws:
      IOException - if an I/O error occurs during saving.
    • listSavedSessions

      public List<String> listSavedSessions() throws IOException
      Lists the names of all saved sessions in the sessions directory.
      Returns:
      A list of session names.
      Throws:
      IOException - if an I/O error occurs while listing files.
    • loadSession

      public void loadSession(String id) throws IOException
      Loads a conversation history from a saved session file.

      This method restores the context and resets the message and tool call ID counters to ensure consistency in the resumed session.

      Parameters:
      id - The name of the session to load.
      Throws:
      IOException - if the session file is not found or an error occurs during loading.
    • triggerAutobackup

      public void triggerAutobackup()
      Triggers an asynchronous automatic backup of the current session.
    • getSummaryAsString

      public String getSummaryAsString()
      Generates a human-readable Markdown table summarizing the entire conversation context.
      Returns:
      A Markdown string containing the context summary.
    • summarizeMessage

      public String summarizeMessage(ChatMessage msg)
      Summarizes a single ChatMessage into Markdown table rows.
      Parameters:
      msg - The message to summarize.
      Returns:
      A Markdown string representing the message's rows in the summary table.
    • describePart

      public String[] describePart(com.google.genai.types.Part p)
      Generates a concise description of a content part, including its type and a summary of its content.
      Parameters:
      p - The part to describe.
      Returns:
      A String array where the first element is the type and the second is the content summary.