5#include "absl/strings/str_format.h"
31 LOG_INFO(
"AgentSessionManager",
"Created session '%s' with ID '%s'",
45 LOG_WARN(
"AgentSessionManager",
"Attempted to close unknown session: %s",
63 int new_active_index = std::max(0, index - 1);
65 sessions_[new_active_index].is_active =
true;
70 LOG_INFO(
"AgentSessionManager",
"Closed session: %s", agent_id.c_str());
78 const std::string& new_name) {
82 LOG_INFO(
"AgentSessionManager",
"Renamed session %s to '%s'",
83 agent_id.c_str(), new_name.c_str());
104 current->is_active =
false;
108 if (
auto* new_session =
GetSession(agent_id)) {
109 new_session->is_active =
true;
111 LOG_DEBUG(
"AgentSessionManager",
"Switched to session: %s (%s)",
112 new_session->display_name.c_str(), agent_id.c_str());
118 if (session.agent_id == agent_id) {
126 const std::string& agent_id)
const {
128 if (session.agent_id == agent_id) {
139 "Attempted to open card for unknown session: %s",
145 LOG_DEBUG(
"AgentSessionManager",
"Panel already open for session: %s",
151 LOG_INFO(
"AgentSessionManager",
"Opened card for session: %s (%s)",
170 LOG_INFO(
"AgentSessionManager",
"Closed card for session: %s",
179 const std::string& agent_id)
const {
185 std::vector<std::string> result;
187 if (session.has_card_open) {
188 result.push_back(session.agent_id);
195 static int id_counter = 0;
196 return absl::StrFormat(
"agent_%d", ++id_counter);
200 for (
size_t i = 0; i <
sessions_.size(); ++i) {
202 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.