Class StatusManager

java.lang.Object
uno.anahata.ai.status.StatusManager

public class StatusManager extends Object
Manages and broadcasts the operational status of a Chat session.

This class tracks the current ChatStatus, monitors API errors for retry logic, records token usage metadata, and notifies registered StatusListeners of state changes.

  • Constructor Details

    • StatusManager

      public StatusManager(Chat chat)
      Constructs a new StatusManager for the given Chat instance.
      Parameters:
      chat - The Chat instance to manage status for.
  • Method Details

    • addListener

      public void addListener(StatusListener listener)
      Adds a listener to be notified of status changes.
      Parameters:
      listener - The listener to add.
    • removeListener

      public void removeListener(StatusListener listener)
      Removes a previously added status listener.
      Parameters:
      listener - The listener to remove.
    • recordUserInputTime

      public void recordUserInputTime()
      Records the timestamp of the most recent user input.
    • setStatus

      public void setStatus(ChatStatus newStatus)
      Updates the current operational status and notifies listeners.
      Parameters:
      newStatus - The new status to set.
    • setLastUsage

      public void setLastUsage(com.google.genai.types.GenerateContentResponseUsageMetadata lastUsage)
      Sets the usage metadata from the last API response.
      Parameters:
      lastUsage - The usage metadata.
    • clearApiErrors

      public void clearApiErrors()
      Clears the history of API errors.
    • reset

      public void reset()
      Resets the status manager to its initial state.
    • recordApiError

      public void recordApiError(String modelId, String apiKey, int retryAttempt, long backoffAmount, Throwable throwable)
      Records an API error and updates the status to WAITING_WITH_BACKOFF.
      Parameters:
      modelId - The ID of the model being called.
      apiKey - The last 5 characters of the API key used.
      retryAttempt - The current retry attempt number.
      backoffAmount - The amount of time to wait before the next retry.
      throwable - The exception that occurred.
    • getApiErrors

      public List<ApiExceptionRecord> getApiErrors()
      Gets an unmodifiable list of all recorded API errors.
      Returns:
      The list of API error records.
    • getLastApiError

      public ApiExceptionRecord getLastApiError()
      Gets the most recent API error record.
      Returns:
      The last error record, or null if no errors have occurred.