gui: track agents by name, not by index
- setActiveSessionId: only auto-select agent when exactly ONE exists. With multiple agents, clear m_agentId and let user click on an agent node in the tree to activate it. - startStateStream: verify current agent directory still exists instead of always re-discovering to the first agent. Only fall back to first agent if current agent is gone. - Emit activeAgentIdChanged so QML reacts to agent changes.
This commit is contained in:
parent
e3fc0c49dd
commit
5fc4ebe64e
|
|
@ -48,40 +48,38 @@ Ollie9pClient::~Ollie9pClient()
|
||||||
|
|
||||||
void Ollie9pClient::setActiveSessionId(const QString &id)
|
void Ollie9pClient::setActiveSessionId(const QString &id)
|
||||||
{
|
{
|
||||||
if (m_activeSessionId == id) return;
|
if (m_activeSessionId == id) return;
|
||||||
|
|
||||||
stopStreams();
|
stopStreams();
|
||||||
m_activeSessionId = id;
|
m_activeSessionId = id;
|
||||||
m_agentId.clear();
|
m_agentId.clear();
|
||||||
m_activeState = "idle";
|
m_activeState = "idle";
|
||||||
|
|
||||||
if (id.isEmpty()) {
|
if (id.isEmpty()) {
|
||||||
emit activeSessionIdChanged();
|
emit activeSessionIdChanged();
|
||||||
emit activeStateChanged();
|
emit activeStateChanged();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Discover agent ID BEFORE emitting signals
|
// Discover agents. If exactly one, use it automatically (backward compat).
|
||||||
QStringList agents = getAgents(id);
|
QStringList agents = getAgents(id);
|
||||||
if (!agents.isEmpty()) {
|
if (agents.size() == 1) {
|
||||||
m_agentId = agents.first();
|
m_agentId = agents.first();
|
||||||
|
|
||||||
// Read initial state immediately (state, not statewait)
|
QByteArray stateOut = run9p({"read", agentPath() + "/state"});
|
||||||
QByteArray stateOut = run9p({"read", agentPath() + "/state"});
|
QString stateStr = QString::fromUtf8(stateOut).trimmed();
|
||||||
QString stateStr = QString::fromUtf8(stateOut).trimmed();
|
if (!stateStr.isEmpty())
|
||||||
if (!stateStr.isEmpty())
|
m_activeState = stateStr;
|
||||||
m_activeState = stateStr;
|
}
|
||||||
|
|
||||||
emit activeSessionIdChanged();
|
emit activeSessionIdChanged();
|
||||||
emit activeStateChanged();
|
emit activeAgentIdChanged();
|
||||||
|
emit activeStateChanged();
|
||||||
|
|
||||||
startChatStream();
|
if (!m_agentId.isEmpty()) {
|
||||||
startStateStream();
|
startChatStream();
|
||||||
} else {
|
startStateStream();
|
||||||
// Empty session — no agent yet
|
}
|
||||||
emit activeSessionIdChanged();
|
|
||||||
emit activeStateChanged();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Ollie9pClient::refreshSessions()
|
void Ollie9pClient::refreshSessions()
|
||||||
|
|
@ -443,22 +441,22 @@ void Ollie9pClient::startChatStream()
|
||||||
|
|
||||||
void Ollie9pClient::startStateStream()
|
void Ollie9pClient::startStateStream()
|
||||||
{
|
{
|
||||||
if (m_stateProc) return;
|
if (m_stateProc) return;
|
||||||
|
|
||||||
// Check if session still exists before starting
|
// Check if session still exists before starting
|
||||||
if (m_activeSessionId.isEmpty() || m_agentId.isEmpty()) return;
|
if (m_activeSessionId.isEmpty() || m_agentId.isEmpty()) return;
|
||||||
|
|
||||||
// Re-discover agent ID — directory may have been renamed
|
// Verify the current agent directory still exists
|
||||||
QStringList agents = getAgents(m_activeSessionId);
|
QStringList agents = getAgents(m_activeSessionId);
|
||||||
if (agents.isEmpty()) {
|
if (agents.isEmpty()) {
|
||||||
// Session or agent directory gone — don't start
|
// Session or agent directory gone — don't start
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QString newId = agents.first();
|
if (!agents.contains(m_agentId)) {
|
||||||
if (newId != m_agentId) {
|
// Current agent no longer exists — fall back to first available
|
||||||
m_agentId = newId;
|
m_agentId = agents.first();
|
||||||
emit activeAgentIdChanged();
|
emit activeAgentIdChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_stateProc = new QProcess(this);
|
m_stateProc = new QProcess(this);
|
||||||
connect(m_stateProc, &QProcess::readyReadStandardOutput, this, &Ollie9pClient::onStateReadyRead);
|
connect(m_stateProc, &QProcess::readyReadStandardOutput, this, &Ollie9pClient::onStateReadyRead);
|
||||||
|
|
|
||||||
Reference in New Issue