Files
z-bar-qt/Plugins/ZShell/Llm/chatstore.hpp
T
zach 52feb6006a
C++ / fmt (pull_request) Failing after 4s
C++ / build (pull_request) Failing after 9s
JS/TS / lint (pull_request) Successful in 9s
JS/TS / fmt (pull_request) Successful in 16s
C++ / clang-tidy (pull_request) Failing after 43s
Python / static (pull_request) Failing after 57s
Rust / fmt (pull_request) Successful in 1m30s
Rust / build (pull_request) Successful in 2m5s
Rust / clippy (pull_request) Successful in 1m55s
Python / verify (pull_request) Successful in 2m23s
chore: format llm c files
2026-08-31 19:02:26 +02:00

67 lines
1.6 KiB
C++

#pragma once
#include "session.hpp"
#include <QObject>
#include <QSet>
#include <QSqlDatabase>
#include <QString>
#include <QVariantList>
namespace ZShell::llm {
class LlmClient;
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);
~ChatStore() override;
[[nodiscard]] int count() const;
[[nodiscard]] QVariantList values() const;
[[nodiscard]] ChatSession* at(int index) const;
Q_INVOKABLE ZShell::llm::ChatSession* insert(int index = -1);
Q_INVOKABLE void remove(int index);
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 persist(ChatSession* session);
void saveMeta(ChatSession* session);
void loadMessagesInto(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);
QList<ChatSession*> m_sessions;
LlmClient* m_llmClient = nullptr;
QString m_connectionName;
QString m_dbPath;
QSet<ChatSession*> m_pendingPersists;
[[nodiscard]] QSqlDatabase db() const;
};
} // namespace ZShell::llm