C++ / fmt (pull_request) Failing after 6s
C++ / build (pull_request) Failing after 10s
C++ / clang-tidy (pull_request) Failing after 9s
JS/TS / fmt (pull_request) Successful in 10s
JS/TS / lint (pull_request) Successful in 8s
Python / static (pull_request) Successful in 30s
Rust / build (pull_request) Successful in 49s
Python / verify (pull_request) Successful in 1m35s
Rust / fmt (pull_request) Successful in 36s
Rust / clippy (pull_request) Successful in 54s
78 lines
2.1 KiB
C++
78 lines
2.1 KiB
C++
#pragma once
|
|
|
|
#include "session.hpp"
|
|
|
|
#include <QAbstractListModel>
|
|
#include <QHash>
|
|
#include <QList>
|
|
#include <QSet>
|
|
#include <QSqlDatabase>
|
|
#include <QString>
|
|
#include <QtQml>
|
|
|
|
namespace ZShell::llm {
|
|
|
|
class LlmClient;
|
|
|
|
class ChatStore : public QAbstractListModel {
|
|
Q_OBJECT
|
|
QML_ELEMENT
|
|
QML_UNCREATABLE("Chat sessions are owned by the LlmClient singleton")
|
|
|
|
public:
|
|
explicit ChatStore(LlmClient* client, QObject* parent = nullptr);
|
|
~ChatStore() override;
|
|
|
|
[[nodiscard]] int rowCount(
|
|
const QModelIndex& parent = QModelIndex()) const override;
|
|
[[nodiscard]] QVariant data(
|
|
const QModelIndex& index, int role = Qt::DisplayRole) const override;
|
|
[[nodiscard]] QHash<int, QByteArray> roleNames() const override;
|
|
|
|
[[nodiscard]] LlmClient* client() const { return m_client; }
|
|
|
|
[[nodiscard]] int rowOf(const ChatSession* session) const;
|
|
|
|
Q_INVOKABLE ZShell::llm::ChatSession* draft();
|
|
Q_INVOKABLE void remove(ZShell::llm::ChatSession* chat);
|
|
Q_INVOKABLE void clear();
|
|
|
|
void commitDraft(ZShell::llm::ChatSession* session);
|
|
|
|
void persist(ZShell::llm::ChatSession* session);
|
|
void saveFlags(ZShell::llm::ChatSession* session);
|
|
void loadMessagesInto(ZShell::llm::ChatSession* session);
|
|
|
|
void requestClear(ZShell::llm::ChatSession* session);
|
|
void applyPendingClear(ZShell::llm::ChatSession* session);
|
|
|
|
void reposition(ZShell::llm::ChatSession* session);
|
|
|
|
Q_SIGNALS:
|
|
void sessionRemoved(ZShell::llm::ChatSession* session);
|
|
|
|
private:
|
|
void openDb();
|
|
void load();
|
|
[[nodiscard]] int sortedRow(const ChatSession* session) const;
|
|
[[nodiscard]] static bool firstAfter(
|
|
const ChatSession* a, const ChatSession* b);
|
|
void insertRow(ChatSession* session);
|
|
void moveRow(int from, int to);
|
|
void removeRow(ChatSession* session);
|
|
[[nodiscard]] bool saveSession(ChatSession* session);
|
|
[[nodiscard]] bool writeSessionRow(ChatSession* session);
|
|
[[nodiscard]] QSqlDatabase db() const;
|
|
|
|
LlmClient* m_client;
|
|
QList<ChatSession*> m_sessions;
|
|
ChatSession* m_draft = nullptr;
|
|
QString m_connectionName;
|
|
QString m_dbPath;
|
|
QSet<ChatSession*> m_pendingPersists;
|
|
QSet<ChatSession*> m_pendingClears;
|
|
bool m_loading = false;
|
|
};
|
|
|
|
} // namespace ZShell::llm
|