mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2026-05-30 10:59:30 -04:00
refactor: Remove legacy code (#344)
This commit is contained in:
@@ -10,10 +10,6 @@ add_library(PluginLLMCore STATIC
|
||||
PromptTemplate.hpp
|
||||
PromptTemplateManager.hpp PromptTemplateManager.cpp
|
||||
ProviderID.hpp
|
||||
HttpClient.hpp HttpClient.cpp
|
||||
DataBuffers.hpp
|
||||
SSEBuffer.hpp SSEBuffer.cpp
|
||||
ContentBlocks.hpp
|
||||
RulesLoader.hpp RulesLoader.cpp
|
||||
ResponseCleaner.hpp
|
||||
)
|
||||
|
||||
@@ -1,236 +0,0 @@
|
||||
// Copyright (C) 2025-2026 Petr Mironychev
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QHash>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
|
||||
namespace QodeAssist::PluginLLMCore {
|
||||
|
||||
enum class MessageState { Building, Complete, RequiresToolExecution, Final };
|
||||
|
||||
enum class ProviderFormat { Claude, OpenAI };
|
||||
|
||||
class ContentBlock : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ContentBlock(QObject *parent = nullptr)
|
||||
: QObject(parent)
|
||||
{}
|
||||
virtual ~ContentBlock() = default;
|
||||
virtual QString type() const = 0;
|
||||
virtual QJsonValue toJson(ProviderFormat format) const = 0;
|
||||
};
|
||||
|
||||
class TextContent : public ContentBlock
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit TextContent(const QString &text = QString())
|
||||
: ContentBlock()
|
||||
, m_text(text)
|
||||
{}
|
||||
|
||||
QString type() const override { return "text"; }
|
||||
QString text() const { return m_text; }
|
||||
void appendText(const QString &text) { m_text += text; }
|
||||
void setText(const QString &text) { m_text = text; }
|
||||
|
||||
QJsonValue toJson(ProviderFormat format) const override
|
||||
{
|
||||
Q_UNUSED(format);
|
||||
return QJsonObject{{"type", "text"}, {"text", m_text}};
|
||||
}
|
||||
|
||||
private:
|
||||
QString m_text;
|
||||
};
|
||||
|
||||
class ImageContent : public ContentBlock
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum class ImageSourceType { Base64, Url };
|
||||
|
||||
ImageContent(const QString &data, const QString &mediaType, ImageSourceType sourceType = ImageSourceType::Base64)
|
||||
: ContentBlock()
|
||||
, m_data(data)
|
||||
, m_mediaType(mediaType)
|
||||
, m_sourceType(sourceType)
|
||||
{}
|
||||
|
||||
QString type() const override { return "image"; }
|
||||
QString data() const { return m_data; }
|
||||
QString mediaType() const { return m_mediaType; }
|
||||
ImageSourceType sourceType() const { return m_sourceType; }
|
||||
|
||||
QJsonValue toJson(ProviderFormat format) const override
|
||||
{
|
||||
if (format == ProviderFormat::Claude) {
|
||||
QJsonObject source;
|
||||
if (m_sourceType == ImageSourceType::Base64) {
|
||||
source["type"] = "base64";
|
||||
source["media_type"] = m_mediaType;
|
||||
source["data"] = m_data;
|
||||
} else {
|
||||
source["type"] = "url";
|
||||
source["url"] = m_data;
|
||||
}
|
||||
return QJsonObject{{"type", "image"}, {"source", source}};
|
||||
} else { // OpenAI format
|
||||
QJsonObject imageUrl;
|
||||
if (m_sourceType == ImageSourceType::Base64) {
|
||||
imageUrl["url"] = QString("data:%1;base64,%2").arg(m_mediaType, m_data);
|
||||
} else {
|
||||
imageUrl["url"] = m_data;
|
||||
}
|
||||
return QJsonObject{{"type", "image_url"}, {"image_url", imageUrl}};
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
QString m_data;
|
||||
QString m_mediaType;
|
||||
ImageSourceType m_sourceType;
|
||||
};
|
||||
|
||||
class ToolUseContent : public ContentBlock
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ToolUseContent(const QString &id, const QString &name, const QJsonObject &input = QJsonObject())
|
||||
: ContentBlock()
|
||||
, m_id(id)
|
||||
, m_name(name)
|
||||
, m_input(input)
|
||||
{}
|
||||
|
||||
QString type() const override { return "tool_use"; }
|
||||
QString id() const { return m_id; }
|
||||
QString name() const { return m_name; }
|
||||
QJsonObject input() const { return m_input; }
|
||||
void setInput(const QJsonObject &input) { m_input = input; }
|
||||
|
||||
QJsonValue toJson(ProviderFormat format) const override
|
||||
{
|
||||
if (format == ProviderFormat::Claude) {
|
||||
return QJsonObject{
|
||||
{"type", "tool_use"}, {"id", m_id}, {"name", m_name}, {"input", m_input}};
|
||||
} else { // OpenAI
|
||||
QJsonDocument doc(m_input);
|
||||
return QJsonObject{
|
||||
{"id", m_id},
|
||||
{"type", "function"},
|
||||
{"function",
|
||||
QJsonObject{
|
||||
{"name", m_name},
|
||||
{"arguments", QString::fromUtf8(doc.toJson(QJsonDocument::Compact))}}}};
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
QString m_id;
|
||||
QString m_name;
|
||||
QJsonObject m_input;
|
||||
};
|
||||
|
||||
class ToolResultContent : public ContentBlock
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ToolResultContent(const QString &toolUseId, const QString &result)
|
||||
: ContentBlock()
|
||||
, m_toolUseId(toolUseId)
|
||||
, m_result(result)
|
||||
{}
|
||||
|
||||
QString type() const override { return "tool_result"; }
|
||||
QString toolUseId() const { return m_toolUseId; }
|
||||
QString result() const { return m_result; }
|
||||
|
||||
QJsonValue toJson(ProviderFormat format) const override
|
||||
{
|
||||
if (format == ProviderFormat::Claude) {
|
||||
return QJsonObject{
|
||||
{"type", "tool_result"}, {"tool_use_id", m_toolUseId}, {"content", m_result}};
|
||||
} else { // OpenAI
|
||||
return QJsonObject{{"role", "tool"}, {"tool_call_id", m_toolUseId}, {"content", m_result}};
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
QString m_toolUseId;
|
||||
QString m_result;
|
||||
};
|
||||
|
||||
class ThinkingContent : public ContentBlock
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ThinkingContent(const QString &thinking = QString(), const QString &signature = QString())
|
||||
: ContentBlock()
|
||||
, m_thinking(thinking)
|
||||
, m_signature(signature)
|
||||
{}
|
||||
|
||||
QString type() const override { return "thinking"; }
|
||||
QString thinking() const { return m_thinking; }
|
||||
QString signature() const { return m_signature; }
|
||||
void appendThinking(const QString &text) { m_thinking += text; }
|
||||
void setThinking(const QString &text) { m_thinking = text; }
|
||||
void setSignature(const QString &signature) { m_signature = signature; }
|
||||
|
||||
QJsonValue toJson(ProviderFormat format) const override
|
||||
{
|
||||
Q_UNUSED(format);
|
||||
// Only include signature field if it's not empty
|
||||
// Empty signature is rejected by API with "Invalid signature" error
|
||||
// In streaming mode, signature is not provided, so we omit the field entirely
|
||||
QJsonObject obj{{"type", "thinking"}, {"thinking", m_thinking}};
|
||||
if (!m_signature.isEmpty()) {
|
||||
obj["signature"] = m_signature;
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
private:
|
||||
QString m_thinking;
|
||||
QString m_signature;
|
||||
};
|
||||
|
||||
class RedactedThinkingContent : public ContentBlock
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit RedactedThinkingContent(const QString &signature = QString())
|
||||
: ContentBlock()
|
||||
, m_signature(signature)
|
||||
{}
|
||||
|
||||
QString type() const override { return "redacted_thinking"; }
|
||||
QString signature() const { return m_signature; }
|
||||
void setSignature(const QString &signature) { m_signature = signature; }
|
||||
|
||||
QJsonValue toJson(ProviderFormat format) const override
|
||||
{
|
||||
Q_UNUSED(format);
|
||||
// Only include signature field if it's not empty
|
||||
// Empty signature is rejected by API with "Invalid signature" error
|
||||
QJsonObject obj{{"type", "redacted_thinking"}};
|
||||
if (!m_signature.isEmpty()) {
|
||||
obj["signature"] = m_signature;
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
private:
|
||||
QString m_signature;
|
||||
};
|
||||
|
||||
} // namespace QodeAssist::PluginLLMCore
|
||||
@@ -1,23 +0,0 @@
|
||||
// Copyright (C) 2025-2026 Petr Mironychev
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "SSEBuffer.hpp"
|
||||
#include <QString>
|
||||
|
||||
namespace QodeAssist::PluginLLMCore {
|
||||
|
||||
struct DataBuffers
|
||||
{
|
||||
SSEBuffer rawStreamBuffer;
|
||||
QString responseContent;
|
||||
|
||||
void clear()
|
||||
{
|
||||
rawStreamBuffer.clear();
|
||||
responseContent.clear();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace QodeAssist::PluginLLMCore
|
||||
@@ -1,260 +0,0 @@
|
||||
// Copyright (C) 2025-2026 Petr Mironychev
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "HttpClient.hpp"
|
||||
|
||||
#include <QJsonDocument>
|
||||
#include <QMutexLocker>
|
||||
|
||||
#include <Logger.hpp>
|
||||
|
||||
namespace QodeAssist::PluginLLMCore {
|
||||
|
||||
HttpClient::HttpClient(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_manager(new QNetworkAccessManager(this))
|
||||
{}
|
||||
|
||||
HttpClient::~HttpClient()
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
for (auto *reply : std::as_const(m_activeRequests)) {
|
||||
reply->abort();
|
||||
reply->deleteLater();
|
||||
}
|
||||
m_activeRequests.clear();
|
||||
}
|
||||
|
||||
QFuture<QByteArray> HttpClient::get(const QNetworkRequest &request)
|
||||
{
|
||||
LOG_MESSAGE(QString("HttpClient: GET %1").arg(request.url().toString()));
|
||||
|
||||
auto promise = std::make_shared<QPromise<QByteArray>>();
|
||||
promise->start();
|
||||
|
||||
QNetworkReply *reply = m_manager->get(request);
|
||||
setupNonStreamingReply(reply, promise);
|
||||
|
||||
return promise->future();
|
||||
}
|
||||
|
||||
QFuture<QByteArray> HttpClient::post(const QNetworkRequest &request, const QJsonObject &payload)
|
||||
{
|
||||
QJsonDocument doc(payload);
|
||||
LOG_MESSAGE(QString("HttpClient: POST %1, data: %2")
|
||||
.arg(request.url().toString(), doc.toJson(QJsonDocument::Indented)));
|
||||
|
||||
auto promise = std::make_shared<QPromise<QByteArray>>();
|
||||
promise->start();
|
||||
|
||||
QNetworkReply *reply = m_manager->post(request, doc.toJson(QJsonDocument::Compact));
|
||||
setupNonStreamingReply(reply, promise);
|
||||
|
||||
return promise->future();
|
||||
}
|
||||
|
||||
QFuture<QByteArray> HttpClient::del(const QNetworkRequest &request,
|
||||
std::optional<QJsonObject> payload)
|
||||
{
|
||||
auto promise = std::make_shared<QPromise<QByteArray>>();
|
||||
promise->start();
|
||||
|
||||
QNetworkReply *reply;
|
||||
if (payload) {
|
||||
QJsonDocument doc(*payload);
|
||||
LOG_MESSAGE(QString("HttpClient: DELETE %1, data: %2")
|
||||
.arg(request.url().toString(), doc.toJson(QJsonDocument::Indented)));
|
||||
reply = m_manager->sendCustomRequest(request, "DELETE", doc.toJson(QJsonDocument::Compact));
|
||||
} else {
|
||||
LOG_MESSAGE(QString("HttpClient: DELETE %1").arg(request.url().toString()));
|
||||
reply = m_manager->deleteResource(request);
|
||||
}
|
||||
|
||||
setupNonStreamingReply(reply, promise);
|
||||
|
||||
return promise->future();
|
||||
}
|
||||
|
||||
void HttpClient::setupNonStreamingReply(QNetworkReply *reply,
|
||||
std::shared_ptr<QPromise<QByteArray>> promise)
|
||||
{
|
||||
connect(reply, &QNetworkReply::finished, this, [this, reply, promise]() {
|
||||
int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||
QByteArray responseBody = reply->readAll();
|
||||
QNetworkReply::NetworkError networkError = reply->error();
|
||||
QString networkErrorString = reply->errorString();
|
||||
|
||||
reply->disconnect();
|
||||
reply->deleteLater();
|
||||
|
||||
LOG_MESSAGE(
|
||||
QString("HttpClient: Non-streaming request - HTTP Status: %1").arg(statusCode));
|
||||
|
||||
bool hasError = (networkError != QNetworkReply::NoError) || (statusCode >= 400);
|
||||
if (hasError) {
|
||||
QString errorMsg = parseErrorFromResponse(statusCode, responseBody, networkErrorString);
|
||||
LOG_MESSAGE(QString("HttpClient: Non-streaming request - Error: %1").arg(errorMsg));
|
||||
promise->setException(
|
||||
std::make_exception_ptr(std::runtime_error(errorMsg.toStdString())));
|
||||
} else {
|
||||
promise->addResult(responseBody);
|
||||
}
|
||||
promise->finish();
|
||||
});
|
||||
}
|
||||
|
||||
void HttpClient::postStreaming(const QString &requestId, const QNetworkRequest &request,
|
||||
const QJsonObject &payload)
|
||||
{
|
||||
QJsonDocument doc(payload);
|
||||
LOG_MESSAGE(QString("HttpClient: POST streaming %1, data: %2")
|
||||
.arg(request.url().toString(), doc.toJson(QJsonDocument::Indented)));
|
||||
|
||||
QNetworkReply *reply = m_manager->post(request, doc.toJson(QJsonDocument::Compact));
|
||||
addActiveRequest(reply, requestId);
|
||||
|
||||
connect(reply, &QNetworkReply::readyRead, this, &HttpClient::onReadyRead);
|
||||
connect(reply, &QNetworkReply::finished, this, &HttpClient::onStreamingFinished);
|
||||
}
|
||||
|
||||
void HttpClient::cancelRequest(const QString &requestId)
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
auto it = m_activeRequests.find(requestId);
|
||||
if (it != m_activeRequests.end()) {
|
||||
QNetworkReply *reply = it.value();
|
||||
if (reply) {
|
||||
reply->disconnect();
|
||||
reply->abort();
|
||||
reply->deleteLater();
|
||||
}
|
||||
m_activeRequests.erase(it);
|
||||
LOG_MESSAGE(QString("HttpClient: Cancelled request: %1").arg(requestId));
|
||||
}
|
||||
}
|
||||
|
||||
void HttpClient::onReadyRead()
|
||||
{
|
||||
QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender());
|
||||
if (!reply || reply->isFinished())
|
||||
return;
|
||||
|
||||
int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||
if (statusCode >= 400)
|
||||
return;
|
||||
|
||||
QString requestId = findRequestId(reply);
|
||||
if (requestId.isEmpty())
|
||||
return;
|
||||
|
||||
QByteArray data = reply->readAll();
|
||||
if (!data.isEmpty()) {
|
||||
emit dataReceived(requestId, data);
|
||||
}
|
||||
}
|
||||
|
||||
void HttpClient::onStreamingFinished()
|
||||
{
|
||||
QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender());
|
||||
if (!reply)
|
||||
return;
|
||||
|
||||
int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||
QByteArray responseBody = reply->readAll();
|
||||
QNetworkReply::NetworkError networkError = reply->error();
|
||||
QString networkErrorString = reply->errorString();
|
||||
|
||||
reply->disconnect();
|
||||
|
||||
QString requestId;
|
||||
std::optional<QString> error;
|
||||
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
for (auto it = m_activeRequests.begin(); it != m_activeRequests.end(); ++it) {
|
||||
if (it.value() == reply) {
|
||||
requestId = it.key();
|
||||
m_activeRequests.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (requestId.isEmpty()) {
|
||||
reply->deleteLater();
|
||||
return;
|
||||
}
|
||||
|
||||
bool hasError = (networkError != QNetworkReply::NoError) || (statusCode >= 400);
|
||||
if (hasError) {
|
||||
error = parseErrorFromResponse(statusCode, responseBody, networkErrorString);
|
||||
}
|
||||
|
||||
LOG_MESSAGE(
|
||||
QString("HttpClient: Request %1 - HTTP Status: %2").arg(requestId).arg(statusCode));
|
||||
|
||||
if (!responseBody.isEmpty()) {
|
||||
LOG_MESSAGE(QString("HttpClient: Request %1 - Response body (%2 bytes): %3")
|
||||
.arg(requestId)
|
||||
.arg(responseBody.size())
|
||||
.arg(QString::fromUtf8(responseBody)));
|
||||
}
|
||||
|
||||
if (error) {
|
||||
LOG_MESSAGE(QString("HttpClient: Request %1 - Error: %2").arg(requestId, *error));
|
||||
}
|
||||
}
|
||||
|
||||
reply->deleteLater();
|
||||
|
||||
if (!requestId.isEmpty()) {
|
||||
emit requestFinished(requestId, error);
|
||||
}
|
||||
}
|
||||
|
||||
QString HttpClient::findRequestId(QNetworkReply *reply)
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
for (auto it = m_activeRequests.begin(); it != m_activeRequests.end(); ++it) {
|
||||
if (it.value() == reply)
|
||||
return it.key();
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
void HttpClient::addActiveRequest(QNetworkReply *reply, const QString &requestId)
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
m_activeRequests[requestId] = reply;
|
||||
LOG_MESSAGE(QString("HttpClient: Added active request: %1").arg(requestId));
|
||||
}
|
||||
|
||||
QString HttpClient::parseErrorFromResponse(
|
||||
int statusCode, const QByteArray &responseBody, const QString &networkErrorString)
|
||||
{
|
||||
if (!responseBody.isEmpty()) {
|
||||
QJsonDocument errorDoc = QJsonDocument::fromJson(responseBody);
|
||||
if (!errorDoc.isNull() && errorDoc.isObject()) {
|
||||
QJsonObject errorObj = errorDoc.object();
|
||||
if (errorObj.contains("error")) {
|
||||
QJsonObject error = errorObj["error"].toObject();
|
||||
QString message = error["message"].toString();
|
||||
QString type = error["type"].toString();
|
||||
QString code = error["code"].toString();
|
||||
|
||||
QString errorMsg = QString("HTTP %1: %2").arg(statusCode).arg(message);
|
||||
if (!type.isEmpty())
|
||||
errorMsg += QString(" (type: %1)").arg(type);
|
||||
if (!code.isEmpty())
|
||||
errorMsg += QString(" (code: %1)").arg(code);
|
||||
return errorMsg;
|
||||
}
|
||||
return QString("HTTP %1: %2")
|
||||
.arg(statusCode)
|
||||
.arg(QString::fromUtf8(responseBody));
|
||||
}
|
||||
return QString("HTTP %1: %2").arg(statusCode).arg(QString::fromUtf8(responseBody));
|
||||
}
|
||||
return QString("HTTP %1: %2").arg(statusCode).arg(networkErrorString);
|
||||
}
|
||||
|
||||
} // namespace QodeAssist::PluginLLMCore
|
||||
@@ -1,60 +0,0 @@
|
||||
// Copyright (C) 2025-2026 Petr Mironychev
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
|
||||
#include <QFuture>
|
||||
#include <QHash>
|
||||
#include <QJsonObject>
|
||||
#include <QMutex>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
#include <QObject>
|
||||
#include <QPromise>
|
||||
|
||||
namespace QodeAssist::PluginLLMCore {
|
||||
|
||||
class HttpClient : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
HttpClient(QObject *parent = nullptr);
|
||||
~HttpClient();
|
||||
|
||||
// Non-streaming — return QFuture with full response
|
||||
QFuture<QByteArray> get(const QNetworkRequest &request);
|
||||
QFuture<QByteArray> post(const QNetworkRequest &request, const QJsonObject &payload);
|
||||
QFuture<QByteArray> del(const QNetworkRequest &request,
|
||||
std::optional<QJsonObject> payload = std::nullopt);
|
||||
|
||||
// Streaming — signal-based with requestId
|
||||
void postStreaming(const QString &requestId, const QNetworkRequest &request,
|
||||
const QJsonObject &payload);
|
||||
|
||||
void cancelRequest(const QString &requestId);
|
||||
|
||||
signals:
|
||||
void dataReceived(const QString &requestId, const QByteArray &data);
|
||||
void requestFinished(const QString &requestId, std::optional<QString> error);
|
||||
|
||||
private slots:
|
||||
void onReadyRead();
|
||||
void onStreamingFinished();
|
||||
|
||||
private:
|
||||
void setupNonStreamingReply(QNetworkReply *reply, std::shared_ptr<QPromise<QByteArray>> promise);
|
||||
|
||||
QString findRequestId(QNetworkReply *reply);
|
||||
void addActiveRequest(QNetworkReply *reply, const QString &requestId);
|
||||
QString parseErrorFromResponse(int statusCode, const QByteArray &responseBody,
|
||||
const QString &networkErrorString);
|
||||
|
||||
QNetworkAccessManager *m_manager;
|
||||
QHash<QString, QNetworkReply *> m_activeRequests;
|
||||
mutable QMutex m_mutex;
|
||||
};
|
||||
|
||||
} // namespace QodeAssist::PluginLLMCore
|
||||
@@ -1,35 +0,0 @@
|
||||
// Copyright (C) 2025-2026 Petr Mironychev
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "SSEBuffer.hpp"
|
||||
|
||||
namespace QodeAssist::PluginLLMCore {
|
||||
|
||||
QStringList SSEBuffer::processData(const QByteArray &data)
|
||||
{
|
||||
m_buffer += QString::fromUtf8(data);
|
||||
|
||||
QStringList lines = m_buffer.split('\n');
|
||||
m_buffer = lines.takeLast();
|
||||
|
||||
lines.removeAll(QString());
|
||||
|
||||
return lines;
|
||||
}
|
||||
|
||||
void SSEBuffer::clear()
|
||||
{
|
||||
m_buffer.clear();
|
||||
}
|
||||
|
||||
QString SSEBuffer::currentBuffer() const
|
||||
{
|
||||
return m_buffer;
|
||||
}
|
||||
|
||||
bool SSEBuffer::hasIncompleteData() const
|
||||
{
|
||||
return !m_buffer.isEmpty();
|
||||
}
|
||||
|
||||
} // namespace QodeAssist::PluginLLMCore
|
||||
@@ -1,26 +0,0 @@
|
||||
// Copyright (C) 2025-2026 Petr Mironychev
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
|
||||
namespace QodeAssist::PluginLLMCore {
|
||||
|
||||
class SSEBuffer
|
||||
{
|
||||
public:
|
||||
SSEBuffer() = default;
|
||||
|
||||
QStringList processData(const QByteArray &data);
|
||||
|
||||
void clear();
|
||||
QString currentBuffer() const;
|
||||
bool hasIncompleteData() const;
|
||||
|
||||
private:
|
||||
QString m_buffer;
|
||||
};
|
||||
|
||||
} // namespace QodeAssist::PluginLLMCore
|
||||
Reference in New Issue
Block a user