Files
z-bar-qt/Plugins/ZShell/Llm/chatstore.hpp
T

58 lines
1.3 KiB
C++

#pragma once
#include "session.hpp"
#include <QJsonObject>
#include <QObject>
#include <QVariantList>
namespace ZShell {
class Chat;
class ChatStore : public QObject {
Q_OBJECT
QML_ANONYMOUS
Q_PROPERTY(int count READ count NOTIFY countChanged)
Q_PROPERTY(QVariantList values READ values NOTIFY valuesChanged)
public:
explicit ChatStore(QObject* parent = nullptr);
[[nodiscard]] int count() const;
[[nodiscard]] QVariantList values() const;
[[nodiscard]] ChatSession* at(int index) const;
Q_INVOKABLE ChatSession* insert(int index = -1);
Q_INVOKABLE void remove(int index);
Q_INVOKABLE void remove(ChatSession* chat);
Q_INVOKABLE void move(int from, int to);
Q_INVOKABLE void clear();
[[nodiscard]] ChatSession* sessionById(const QString& id);
void persist(ChatSession* session);
Q_SIGNALS:
void countChanged();
void valuesChanged();
private:
void load();
void migrateLegacy();
void sortAndNotify();
void removeSession(ChatSession* session);
bool isStreaming(ChatSession* session) const;
void notify(const QList<ChatSession*>& before);
QList<ChatSession*> m_sessions;
static QString dir();
static QString pathFor(const QString& id);
static bool writeFile(const QString& path, const QJsonObject& doc);
friend class Chat;
};
} // namespace ZShell