2023-04-14 14:44:28 -04:00
|
|
|
#ifndef NETWORK_H
|
|
|
|
#define NETWORK_H
|
|
|
|
|
2024-06-06 11:59:28 -04:00
|
|
|
#include <QByteArray>
|
2023-05-02 20:31:17 -04:00
|
|
|
#include <QJsonValue>
|
2024-06-06 11:59:28 -04:00
|
|
|
#include <QList>
|
2024-06-04 14:47:11 -04:00
|
|
|
#include <QMap>
|
|
|
|
#include <QNetworkAccessManager>
|
2024-06-06 11:59:28 -04:00
|
|
|
#include <QNetworkReply>
|
2024-06-04 14:47:11 -04:00
|
|
|
#include <QObject>
|
2024-06-06 11:59:28 -04:00
|
|
|
#include <QSslError>
|
2024-06-04 14:47:11 -04:00
|
|
|
#include <QString>
|
|
|
|
#include <QVariant>
|
|
|
|
#include <QVector>
|
|
|
|
|
2023-05-02 20:31:17 -04:00
|
|
|
struct KeyValue {
|
|
|
|
QString key;
|
|
|
|
QJsonValue value;
|
|
|
|
};
|
2023-04-14 14:44:28 -04:00
|
|
|
|
|
|
|
class Network : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
static Network *globalInstance();
|
2024-07-25 10:02:52 -04:00
|
|
|
static bool isHttpUrlValid(const QUrl url);
|
2023-04-14 14:44:28 -04:00
|
|
|
|
|
|
|
Q_INVOKABLE QString generateUniqueId() const;
|
2023-04-23 21:05:38 -04:00
|
|
|
Q_INVOKABLE bool sendConversation(const QString &ingestId, const QString &conversation);
|
2024-04-25 13:16:52 -04:00
|
|
|
Q_INVOKABLE void trackChatEvent(const QString &event, QVariantMap props = QVariantMap());
|
|
|
|
Q_INVOKABLE void trackEvent(const QString &event, const QVariantMap &props = QVariantMap());
|
2023-04-14 14:44:28 -04:00
|
|
|
|
|
|
|
Q_SIGNALS:
|
2023-04-23 07:35:38 -04:00
|
|
|
void healthCheckFailed(int code);
|
2024-04-25 13:16:52 -04:00
|
|
|
void requestMixpanel(const QByteArray &json, bool isOptOut = false);
|
2023-04-14 14:44:28 -04:00
|
|
|
|
2023-04-26 22:05:56 -04:00
|
|
|
public Q_SLOTS:
|
|
|
|
void sendStartup();
|
|
|
|
|
2023-04-14 14:44:28 -04:00
|
|
|
private Q_SLOTS:
|
2023-04-26 22:05:56 -04:00
|
|
|
void handleIpifyFinished();
|
2023-04-23 07:35:38 -04:00
|
|
|
void handleHealthFinished();
|
2023-04-14 14:44:28 -04:00
|
|
|
void handleJsonUploadFinished();
|
2023-04-24 17:52:19 -04:00
|
|
|
void handleSslErrors(QNetworkReply *reply, const QList<QSslError> &errors);
|
2023-04-26 22:05:56 -04:00
|
|
|
void handleMixpanelFinished();
|
2023-06-28 20:42:40 -04:00
|
|
|
void handleIsActiveChanged();
|
|
|
|
void handleUsageStatsActiveChanged();
|
2024-05-01 12:08:40 -04:00
|
|
|
void sendMixpanel(const QByteArray &json);
|
2023-04-14 14:44:28 -04:00
|
|
|
|
|
|
|
private:
|
2024-04-25 13:16:52 -04:00
|
|
|
void sendOptOut();
|
2023-04-23 07:35:38 -04:00
|
|
|
void sendHealth();
|
2023-04-26 22:05:56 -04:00
|
|
|
void sendIpify();
|
2023-04-23 21:05:38 -04:00
|
|
|
bool packageAndSendJson(const QString &ingestId, const QString &json);
|
2023-04-14 14:44:28 -04:00
|
|
|
|
|
|
|
private:
|
2024-04-25 13:16:52 -04:00
|
|
|
bool m_sendUsageStats = false;
|
|
|
|
bool m_hasSentOptIn;
|
|
|
|
bool m_hasSentOptOut;
|
2023-04-26 22:05:56 -04:00
|
|
|
QString m_ipify;
|
2023-04-14 14:44:28 -04:00
|
|
|
QString m_uniqueId;
|
2024-04-25 13:16:52 -04:00
|
|
|
QString m_sessionId;
|
2023-04-14 14:44:28 -04:00
|
|
|
QNetworkAccessManager m_networkManager;
|
|
|
|
QVector<QNetworkReply*> m_activeUploads;
|
|
|
|
|
|
|
|
private:
|
|
|
|
explicit Network();
|
|
|
|
~Network() {}
|
|
|
|
friend class MyNetwork;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // LLM_H
|