5#include "absl/strings/str_format.h"
30 LOG_INFO(
"AgentSessionManager",
"Created session '%s' with ID '%s'",
44 LOG_WARN(
"AgentSessionManager",
"Attempted to close unknown session: %s",
62 int new_active_index = std::max(0, index - 1);
64 sessions_[new_active_index].is_active =
true;
69 LOG_INFO(
"AgentSessionManager",
"Closed session: %s", agent_id.c_str());
77 const std::string& new_name) {
81 LOG_INFO(
"AgentSessionManager",
"Renamed session %s to '%s'",
82 agent_id.c_str(), new_name.c_str());
103 current->is_active =
false;
107 if (
auto* new_session =
GetSession(agent_id)) {
108 new_session->is_active =
true;
110 LOG_DEBUG(
"AgentSessionManager",
"Switched to session: %s (%s)",
111 new_session->display_name.c_str(), agent_id.c_str());
117 if (session.agent_id == agent_id) {
125 const std::string& agent_id)
const {
127 if (session.agent_id == agent_id) {
138 "Attempted to open card for unknown session: %s",
144 LOG_DEBUG(
"AgentSessionManager",
"Panel already open for session: %s",
150 LOG_INFO(
"AgentSessionManager",
"Opened card for session: %s (%s)",
169 LOG_INFO(
"AgentSessionManager",
"Closed card for session: %s",
178 const std::string& agent_id)
const {
184 std::vector<std::string> result;
186 if (session.has_card_open) {
187 result.push_back(session.agent_id);
194 static int id_counter = 0;
195 return absl::StrFormat(
"agent_%d", ++id_counter);
199 for (
size_t i = 0; i <
sessions_.size(); ++i) {
201 return static_cast<int>(i);
AgentSession * GetActiveSession()
Get the currently active session (shown in sidebar)
std::vector< std::string > GetOpenPanelSessionIds() const
Get list of session IDs with open cards.
void SetActiveSession(const std::string &agent_id)
Set the active session by ID.
void CloseSession(const std::string &agent_id)
Close and remove a session.
std::vector< AgentSession > sessions_
std::string active_session_id_
bool IsPanelOpenForSession(const std::string &agent_id) const
Check if a session has an open card.
SessionCreatedCallback on_session_created_
PanelClosedCallback on_card_closed_
std::string CreateSession(const std::string &name="")
Create a new agent session.
void RenameSession(const std::string &agent_id, const std::string &new_name)
Rename a session.
int FindSessionIndex(const std::string &agent_id) const
Find session index by ID.
SessionClosedCallback on_session_closed_
std::string GenerateAgentId()
Generate a unique agent ID.
void OpenPanelForSession(const std::string &agent_id)
Open a full dockable card for a session.
AgentSession * GetSession(const std::string &agent_id)
Get a session by ID.
void ClosePanelForSession(const std::string &agent_id)
Close the dockable card for a session.
PanelOpenedCallback on_card_opened_
#define LOG_DEBUG(category, format,...)
#define LOG_WARN(category, format,...)
#define LOG_INFO(category, format,...)
Represents a single agent session with its own chat history and config.