Live mode: advertise the channel in qet-assistant.json

The socket name and token now go in the "live" part of the one file the
qet MCP server reads about this QElectroTech, rather than in a
live-session.json of their own, and are cleared when the channel closes.
The file also says whether the live setting is on.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
ispyisail
2026-10-02 13:03:33 +13:00
parent 3a5b72c40f
commit 124173514d
3 changed files with 10 additions and 27 deletions
+6 -23
View File
@@ -17,6 +17,7 @@
*/
#include "liveserver.h"
#include "assistantinfo.h"
#include "qetscripting.h"
#include "scriptlibrary.h"
#include "../diagram.h"
@@ -67,17 +68,6 @@ LiveServer::LiveServer()
LiveServer::~LiveServer()
{
QFile::remove(sessionFile());
}
/**
@brief LiveServer::sessionFile
Where the channel's name and token are written for the MCP server:
next to the stored scripts, in the user's data folder.
*/
QString LiveServer::sessionFile()
{
return QETApp::dataDir() + QStringLiteral("/live-session.json");
}
/**
@@ -135,19 +125,12 @@ bool LiveServer::start()
}
m_token = randomHex(16);
const QJsonObject session{
{QStringLiteral("version"), 1},
//Where the MCP server finds the channel: the "live" part of
//qet-assistant.json, the one file it reads about this QElectroTech
AssistantInfo::setLive(QJsonObject{
{QStringLiteral("socket"), m_server->fullServerName()},
{QStringLiteral("token"), m_token},
{QStringLiteral("pid"), QCoreApplication::applicationPid()}};
QSaveFile file(sessionFile());
if (!file.open(QIODevice::WriteOnly)
|| file.write(QJsonDocument(session).toJson(QJsonDocument::Compact)) < 0
|| !file.commit()) {
stop();
return false;
}
QFile::setPermissions(sessionFile(), QFile::ReadOwner | QFile::WriteOwner);
{QStringLiteral("pid"), QCoreApplication::applicationPid()}});
connect(m_server, &QLocalServer::newConnection, this, &LiveServer::newConnection);
setState(Waiting);
@@ -169,7 +152,7 @@ void LiveServer::stop()
m_server->deleteLater();
m_server = nullptr;
}
QFile::remove(sessionFile());
if (!m_token.isEmpty()) AssistantInfo::setLive(QJsonObject());
m_token.clear();
m_buffer.clear();
setState(Off);