chore: restructure llm plugin to be more coherent & fix various bugs in llm ui
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

This commit is contained in:
2026-10-18 12:58:38 +02:00
parent fc81be922f
commit 1fe8a3a959
54 changed files with 3022 additions and 2559 deletions
+40 -29
View File
@@ -2,65 +2,76 @@
#include "session.hpp"
#include <QObject>
#include <QAbstractListModel>
#include <QHash>
#include <QList>
#include <QSet>
#include <QSqlDatabase>
#include <QString>
#include <QVariantList>
#include <QtQml>
namespace ZShell::llm {
class LlmClient;
class ChatStore : public QObject {
class ChatStore : public QAbstractListModel {
Q_OBJECT
QML_ANONYMOUS
Q_PROPERTY(int count READ count NOTIFY countChanged)
Q_PROPERTY(QVariantList values READ values NOTIFY valuesChanged)
QML_ELEMENT
QML_UNCREATABLE("Chat sessions are owned by the LlmClient singleton")
public:
explicit ChatStore(QObject* parent = nullptr);
explicit ChatStore(LlmClient* client, QObject* parent = nullptr);
~ChatStore() override;
[[nodiscard]] int count() const;
[[nodiscard]] QVariantList values() const;
[[nodiscard]] ChatSession* at(int index) const;
[[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;
Q_INVOKABLE ZShell::llm::ChatSession* insert(int index = -1);
Q_INVOKABLE void remove(int index);
[[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 move(int from, int to);
Q_INVOKABLE void clear();
[[nodiscard]] ChatSession* sessionById(const QString& id);
[[nodiscard]] LlmClient* llmClient() const { return m_llmClient; }
void setLlmClient(LlmClient* client);
void commitDraft(ZShell::llm::ChatSession* session);
void persist(ChatSession* session);
void saveMeta(ChatSession* session);
void loadMessagesInto(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 countChanged();
void valuesChanged();
void sessionRemoved(ZShell::llm::ChatSession* session);
private:
void openDb();
void load();
bool saveSession(ChatSession* session);
void sortAndNotify();
void removeSession(ChatSession* session);
void notify(const QList<ChatSession*>& before);
[[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;
LlmClient* m_llmClient = nullptr;
ChatSession* m_draft = nullptr;
QString m_connectionName;
QString m_dbPath;
QSet<ChatSession*> m_pendingPersists;
[[nodiscard]] QSqlDatabase db() const;
QSet<ChatSession*> m_pendingClears;
bool m_loading = false;
};
} // namespace ZShell::llm