mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-03 09:14:12 +02:00
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:
@@ -102,6 +102,7 @@ void write()
|
||||
{QStringLiteral("scripting_available"), false},
|
||||
#endif
|
||||
{QStringLiteral("scripting_enabled"), QetSettings::scriptingEnabled()},
|
||||
{QStringLiteral("live_mode_setting"), QetSettings::liveAssistantEnabled()},
|
||||
{QStringLiteral("live_mode_open"), !s_live.isEmpty()}}},
|
||||
{QStringLiteral("script_api"), QJsonArray::fromStringList(QetScriptApi::signatures())},
|
||||
{QStringLiteral("stored_scripts"), scripts},
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -38,9 +38,9 @@ class QWidget;
|
||||
class opens nothing and QElectroTech behaves as if it did not exist.
|
||||
|
||||
The channel is a QLocalServer only the user's own account can open,
|
||||
with a random name and token written to live-session.json in the data
|
||||
folder, which the MCP server reads; the file goes when the channel
|
||||
closes. One JSON request per connection, one JSON answer back, then
|
||||
with a random name and token written to the "live" part of
|
||||
qet-assistant.json (AssistantInfo), which the MCP server reads, and
|
||||
cleared when the channel closes. One JSON request per connection, one JSON answer back, then
|
||||
the server closes the connection; every request carries the token.
|
||||
|
||||
Requests are never handled inside the socket's readyRead: each is
|
||||
@@ -56,7 +56,6 @@ class LiveServer : public QObject
|
||||
enum State { Off, Waiting, Connected };
|
||||
|
||||
static LiveServer &instance();
|
||||
static QString sessionFile();
|
||||
|
||||
void askAndStart(QWidget *parent);
|
||||
void stop();
|
||||
|
||||
Reference in New Issue
Block a user