Add some debug output and simplify overyl complex code
This commit is contained in:
parent
fd289edded
commit
bc0ae50be5
|
|
@ -22,6 +22,7 @@
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include "mcp/KomMcpServer.hpp"
|
#include "mcp/KomMcpServer.hpp"
|
||||||
#include "mcp/KompanionQtServer.hpp"
|
#include "mcp/KompanionQtServer.hpp"
|
||||||
#include "mcp/RegisterTools.hpp"
|
#include "mcp/RegisterTools.hpp"
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,10 @@
|
||||||
#include <QtCore/QStandardPaths>
|
#include <QtCore/QStandardPaths>
|
||||||
#include <QtCore/QStringList>
|
#include <QtCore/QStringList>
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
using namespace Qt::Literals::StringLiterals;
|
using namespace Qt::Literals::StringLiterals;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
const QString kSchemaResource = QStringLiteral(":/kompanion/ToolSchemas.json");
|
|
||||||
|
|
||||||
QString normaliseToolName(const QString &defaultNamespace, const QString &rawName)
|
QString normaliseToolName(const QString &defaultNamespace, const QString &rawName)
|
||||||
{
|
{
|
||||||
if (rawName.contains('.')) {
|
if (rawName.contains('.')) {
|
||||||
|
|
@ -103,31 +102,13 @@ KompanionQtServer::KompanionQtServer(const QString &backend, KomMcpServer *logic
|
||||||
QList<QMcpTool> KompanionQtServer::loadToolsFromSchema() const
|
QList<QMcpTool> KompanionQtServer::loadToolsFromSchema() const
|
||||||
{
|
{
|
||||||
QList<QMcpTool> tools;
|
QList<QMcpTool> tools;
|
||||||
const QStringList candidates = {
|
QFile kSchemaResource(":/kompanion/ToolSchemas.json");
|
||||||
kSchemaResource,
|
if (!kSchemaResource.open(QIODevice::ReadOnly)) {
|
||||||
QStringLiteral(":/ToolSchemas.json"),
|
qWarning() << "[KompanionQtServer] Failed to open tool schema";
|
||||||
QStandardPaths::locate(QStandardPaths::GenericDataLocation,
|
|
||||||
QStringLiteral("kompanion/mcp/ToolSchemas.json")),
|
|
||||||
QStandardPaths::locate(QStandardPaths::AppDataLocation,
|
|
||||||
QStringLiteral("kompanion/mcp/ToolSchemas.json"))
|
|
||||||
};
|
|
||||||
|
|
||||||
QFile schemaFile;
|
|
||||||
for (const QString &candidate : candidates) {
|
|
||||||
if (candidate.isEmpty())
|
|
||||||
continue;
|
|
||||||
schemaFile.setFileName(candidate);
|
|
||||||
if (schemaFile.open(QIODevice::ReadOnly)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!schemaFile.isOpen()) {
|
|
||||||
qWarning() << "[KompanionQtServer] Failed to open tool schema (resource or installed copy):" << candidates;
|
|
||||||
return tools;
|
return tools;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto doc = QJsonDocument::fromJson(schemaFile.readAll());
|
const auto doc = QJsonDocument::fromJson(kSchemaResource.readAll());
|
||||||
if (!doc.isObject()) {
|
if (!doc.isObject()) {
|
||||||
qWarning() << "[KompanionQtServer] Tool schema resource is not a JSON object";
|
qWarning() << "[KompanionQtServer] Tool schema resource is not a JSON object";
|
||||||
return tools;
|
return tools;
|
||||||
|
|
@ -143,7 +124,9 @@ if (!schemaFile.isOpen()) {
|
||||||
|
|
||||||
for (auto it = toolDefs.constBegin(); it != toolDefs.constEnd(); ++it) {
|
for (auto it = toolDefs.constBegin(); it != toolDefs.constEnd(); ++it) {
|
||||||
const QString fullName = normaliseToolName(defaultNamespace, it.key());
|
const QString fullName = normaliseToolName(defaultNamespace, it.key());
|
||||||
|
|
||||||
if (!m_logic->hasTool(fullName.toStdString())) {
|
if (!m_logic->hasTool(fullName.toStdString())) {
|
||||||
|
qDebug() << "skipping " << fullName << " that does not fit";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue