From 4faeb90dc0521c1fe8b4a729bdca800b2fd9019c Mon Sep 17 00:00:00 2001 From: Petr Mironychev <9195189+Palm1r@users.noreply.github.com> Date: Fri, 15 May 2026 11:02:32 +0200 Subject: [PATCH] fix: Add missing files --- ChatView/AgentRoleController.cpp | 123 +++++++++++++++++++++++++++++++ ChatView/AgentRoleController.hpp | 38 ++++++++++ 2 files changed, 161 insertions(+) create mode 100644 ChatView/AgentRoleController.cpp create mode 100644 ChatView/AgentRoleController.hpp diff --git a/ChatView/AgentRoleController.cpp b/ChatView/AgentRoleController.cpp new file mode 100644 index 0000000..0b094c4 --- /dev/null +++ b/ChatView/AgentRoleController.cpp @@ -0,0 +1,123 @@ +// Copyright (C) 2024-2026 Petr Mironychev +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "AgentRoleController.hpp" + +#include + +#include "AgentRole.hpp" +#include "ChatAssistantSettings.hpp" +#include "GeneralSettings.hpp" + +namespace QodeAssist::Chat { + +AgentRoleController::AgentRoleController(QObject *parent) + : QObject(parent) +{ + connect( + &Settings::chatAssistantSettings().systemPrompt, + &Utils::BaseAspect::changed, + this, + &AgentRoleController::baseSystemPromptChanged); + + loadAvailableRoles(); +} + +QStringList AgentRoleController::availableRoles() const +{ + return m_availableRoles; +} + +QString AgentRoleController::currentRole() const +{ + return m_currentRole; +} + +QString AgentRoleController::baseSystemPrompt() const +{ + return Settings::chatAssistantSettings().systemPrompt(); +} + +QString AgentRoleController::currentRoleDescription() const +{ + const QString lastRoleId = Settings::chatAssistantSettings().lastUsedRoleId(); + if (lastRoleId.isEmpty()) + return Settings::AgentRolesManager::getNoRole().description; + + const Settings::AgentRole role = Settings::AgentRolesManager::loadRole(lastRoleId); + if (role.id.isEmpty()) + return Settings::AgentRolesManager::getNoRole().description; + + return role.description; +} + +QString AgentRoleController::currentRoleSystemPrompt() const +{ + const QString lastRoleId = Settings::chatAssistantSettings().lastUsedRoleId(); + if (lastRoleId.isEmpty()) + return QString(); + + const Settings::AgentRole role = Settings::AgentRolesManager::loadRole(lastRoleId); + if (role.id.isEmpty()) + return QString(); + + return role.systemPrompt; +} + +void AgentRoleController::loadAvailableRoles() +{ + const QList roles = Settings::AgentRolesManager::loadAllRoles(); + + m_availableRoles.clear(); + m_availableRoles.append(Settings::AgentRolesManager::getNoRole().name); + + for (const auto &role : roles) + m_availableRoles.append(role.name); + + const QString lastRoleId = Settings::chatAssistantSettings().lastUsedRoleId(); + m_currentRole = Settings::AgentRolesManager::getNoRole().name; + + if (!lastRoleId.isEmpty()) { + for (const auto &role : roles) { + if (role.id == lastRoleId) { + m_currentRole = role.name; + break; + } + } + } + + emit availableRolesChanged(); + emit currentRoleChanged(); +} + +void AgentRoleController::applyRole(const QString &roleName) +{ + auto &settings = Settings::chatAssistantSettings(); + + if (roleName == Settings::AgentRolesManager::getNoRole().name) { + settings.lastUsedRoleId.setValue(""); + settings.writeSettings(); + m_currentRole = roleName; + emit currentRoleChanged(); + return; + } + + const QList roles = Settings::AgentRolesManager::loadAllRoles(); + + for (const auto &role : roles) { + if (role.name == roleName) { + settings.lastUsedRoleId.setValue(role.id); + settings.writeSettings(); + m_currentRole = role.name; + emit currentRoleChanged(); + break; + } + } +} + +void AgentRoleController::openSettings() +{ + Settings::showSettings(Utils::Id("QodeAssist.AgentRoles")); +} + +} // namespace QodeAssist::Chat diff --git a/ChatView/AgentRoleController.hpp b/ChatView/AgentRoleController.hpp new file mode 100644 index 0000000..fbe54f1 --- /dev/null +++ b/ChatView/AgentRoleController.hpp @@ -0,0 +1,38 @@ +// Copyright (C) 2024-2026 Petr Mironychev +// SPDX-License-Identifier: GPL-3.0-or-later + +#pragma once + +#include +#include + +namespace QodeAssist::Chat { + +class AgentRoleController : public QObject +{ + Q_OBJECT + +public: + explicit AgentRoleController(QObject *parent = nullptr); + + QStringList availableRoles() const; + QString currentRole() const; + QString baseSystemPrompt() const; + QString currentRoleDescription() const; + QString currentRoleSystemPrompt() const; + + void loadAvailableRoles(); + void applyRole(const QString &roleName); + void openSettings(); + +signals: + void availableRolesChanged(); + void currentRoleChanged(); + void baseSystemPromptChanged(); + +private: + QStringList m_availableRoles; + QString m_currentRole; +}; + +} // namespace QodeAssist::Chat