Files
z-bar-qt/Plugins/ZShell/Llm/message.hpp
T
zach 99949ff255
C++ / fmt (pull_request) Failing after 5s
C++ / build (pull_request) Failing after 9s
C++ / clang-tidy (pull_request) Failing after 10s
JS/TS / fmt (pull_request) Failing after 11s
JS/TS / lint (pull_request) Successful in 9s
Python / static (pull_request) Failing after 31s
Rust / build (pull_request) Successful in 49s
Python / verify (pull_request) Successful in 1m37s
Rust / fmt (pull_request) Successful in 27s
Rust / clippy (pull_request) Successful in 58s
new chatlistview component, file attachments, performance & primitive test
2026-09-17 15:20:41 +02:00

87 lines
2.4 KiB
C++

#pragma once
#include "attachment.hpp"
#include "generation.hpp"
#include <QList>
#include <QObject>
#include <QString>
#include <QtQml>
namespace ZShell::llm {
class ChatMessage : public QObject {
Q_OBJECT
QML_ELEMENT
QML_UNCREATABLE("Chat messages are created by the Chat singleton")
Q_PROPERTY(Role role READ role CONSTANT)
Q_PROPERTY(qint64 timestamp READ timestamp CONSTANT)
Q_PROPERTY(
int generationCount READ generationCount NOTIFY generationsChanged)
Q_PROPERTY(
QList<ZShell::llm::ChatGeneration*> generations READ generations NOTIFY
generationsChanged)
Q_PROPERTY(
ZShell::llm::ChatGeneration* activeGeneration READ activeGeneration
NOTIFY activeGenerationChanged)
Q_PROPERTY(
int activeGenerationIndex READ activeGenerationIndex NOTIFY
activeGenerationChanged)
Q_PROPERTY(
QList<ZShell::llm::Attachment*> attachments READ attachments NOTIFY
attachmentsChanged)
public:
enum class Role : int { User = 0, Assistant };
Q_ENUM(Role)
explicit ChatMessage(Role role, qint64 timestamp, QObject* parent = nullptr);
[[nodiscard]] Role role() const { return m_role; }
[[nodiscard]] qint64 timestamp() const { return m_timestamp; }
[[nodiscard]] int generationCount() const {
return static_cast<int>(m_generations.size());
}
[[nodiscard]] QList<ChatGeneration*> generations() const {
return m_generations;
}
[[nodiscard]] ChatGeneration* activeGeneration() const {
return generation(m_active);
}
[[nodiscard]] int activeGenerationIndex() const { return m_active; }
[[nodiscard]] QList<Attachment*> attachments() const {
return m_attachments;
}
[[nodiscard]] ChatGeneration* generation(int index) const {
if (index < 0 || index >= m_generations.size()) return nullptr;
return m_generations.at(index);
}
Q_INVOKABLE void setActiveGeneration(int index);
void setAttachments(QList<Attachment*> attachments);
Q_INVOKABLE void edit(const QString& newContent);
Q_INVOKABLE void retry();
Q_INVOKABLE void generate();
ChatGeneration* addGeneration(qint64 timestamp);
ChatGeneration* appendGeneration(qint64 timestamp);
void removeGeneration(ChatGeneration* generation);
Q_SIGNALS:
void generationsChanged();
void activeGenerationChanged();
void attachmentsChanged();
private:
void setActiveInternal(int index);
Role m_role;
qint64 m_timestamp;
QList<ChatGeneration*> m_generations;
QList<Attachment*> m_attachments;
int m_active = -1;
};
} // namespace ZShell::llm