mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2026-05-30 02:49:12 -04:00
refactor: Move out agent roles from Chat root view controller
This commit is contained in:
@@ -69,6 +69,7 @@ qt_add_qml_module(QodeAssistChatView
|
|||||||
FileItem.hpp FileItem.cpp
|
FileItem.hpp FileItem.cpp
|
||||||
ChatFileManager.hpp ChatFileManager.cpp
|
ChatFileManager.hpp ChatFileManager.cpp
|
||||||
ChatCompressor.hpp ChatCompressor.cpp
|
ChatCompressor.hpp ChatCompressor.cpp
|
||||||
|
AgentRoleController.hpp AgentRoleController.cpp
|
||||||
FileMentionItem.hpp FileMentionItem.cpp
|
FileMentionItem.hpp FileMentionItem.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
#include <utils/theme/theme.h>
|
#include <utils/theme/theme.h>
|
||||||
#include <utils/utilsicons.h>
|
#include <utils/utilsicons.h>
|
||||||
|
|
||||||
#include "AgentRole.hpp"
|
#include "AgentRoleController.hpp"
|
||||||
#include "ChatAssistantSettings.hpp"
|
#include "ChatAssistantSettings.hpp"
|
||||||
#include "ChatCompressor.hpp"
|
#include "ChatCompressor.hpp"
|
||||||
#include "ChatSerializer.hpp"
|
#include "ChatSerializer.hpp"
|
||||||
@@ -51,6 +51,7 @@ ChatRootView::ChatRootView(QQuickItem *parent)
|
|||||||
, m_fileManager(new ChatFileManager(this))
|
, m_fileManager(new ChatFileManager(this))
|
||||||
, m_isRequestInProgress(false)
|
, m_isRequestInProgress(false)
|
||||||
, m_chatCompressor(new ChatCompressor(this))
|
, m_chatCompressor(new ChatCompressor(this))
|
||||||
|
, m_agentRoleController(new AgentRoleController(this))
|
||||||
{
|
{
|
||||||
m_isSyncOpenFiles = Settings::chatAssistantSettings().linkOpenFiles();
|
m_isSyncOpenFiles = Settings::chatAssistantSettings().linkOpenFiles();
|
||||||
connect(
|
connect(
|
||||||
@@ -128,8 +129,18 @@ ChatRootView::ChatRootView(QQuickItem *parent)
|
|||||||
updateInputTokensCount();
|
updateInputTokensCount();
|
||||||
});
|
});
|
||||||
connect(
|
connect(
|
||||||
&Settings::chatAssistantSettings().systemPrompt,
|
m_agentRoleController,
|
||||||
&Utils::BaseAspect::changed,
|
&AgentRoleController::availableRolesChanged,
|
||||||
|
this,
|
||||||
|
&ChatRootView::availableAgentRolesChanged);
|
||||||
|
connect(
|
||||||
|
m_agentRoleController,
|
||||||
|
&AgentRoleController::currentRoleChanged,
|
||||||
|
this,
|
||||||
|
&ChatRootView::currentAgentRoleChanged);
|
||||||
|
connect(
|
||||||
|
m_agentRoleController,
|
||||||
|
&AgentRoleController::baseSystemPromptChanged,
|
||||||
this,
|
this,
|
||||||
&ChatRootView::baseSystemPromptChanged);
|
&ChatRootView::baseSystemPromptChanged);
|
||||||
|
|
||||||
@@ -246,7 +257,6 @@ ChatRootView::ChatRootView(QQuickItem *parent)
|
|||||||
updateInputTokensCount();
|
updateInputTokensCount();
|
||||||
refreshRules();
|
refreshRules();
|
||||||
loadAvailableConfigurations();
|
loadAvailableConfigurations();
|
||||||
loadAvailableAgentRoles();
|
|
||||||
|
|
||||||
connect(
|
connect(
|
||||||
ProjectExplorer::ProjectManager::instance(),
|
ProjectExplorer::ProjectManager::instance(),
|
||||||
@@ -1557,99 +1567,42 @@ QString ChatRootView::currentConfiguration() const
|
|||||||
|
|
||||||
void ChatRootView::loadAvailableAgentRoles()
|
void ChatRootView::loadAvailableAgentRoles()
|
||||||
{
|
{
|
||||||
const QList<Settings::AgentRole> roles = Settings::AgentRolesManager::loadAllRoles();
|
m_agentRoleController->loadAvailableRoles();
|
||||||
|
|
||||||
m_availableAgentRoles.clear();
|
|
||||||
m_availableAgentRoles.append(Settings::AgentRolesManager::getNoRole().name);
|
|
||||||
|
|
||||||
for (const auto &role : roles)
|
|
||||||
m_availableAgentRoles.append(role.name);
|
|
||||||
|
|
||||||
const QString lastRoleId = Settings::chatAssistantSettings().lastUsedRoleId();
|
|
||||||
m_currentAgentRole = Settings::AgentRolesManager::getNoRole().name;
|
|
||||||
|
|
||||||
if (!lastRoleId.isEmpty()) {
|
|
||||||
for (const auto &role : roles) {
|
|
||||||
if (role.id == lastRoleId) {
|
|
||||||
m_currentAgentRole = role.name;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
emit availableAgentRolesChanged();
|
|
||||||
emit currentAgentRoleChanged();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatRootView::applyAgentRole(const QString &roleName)
|
void ChatRootView::applyAgentRole(const QString &roleName)
|
||||||
{
|
{
|
||||||
auto &settings = Settings::chatAssistantSettings();
|
m_agentRoleController->applyRole(roleName);
|
||||||
|
|
||||||
if (roleName == Settings::AgentRolesManager::getNoRole().name) {
|
|
||||||
settings.lastUsedRoleId.setValue("");
|
|
||||||
settings.writeSettings();
|
|
||||||
m_currentAgentRole = roleName;
|
|
||||||
emit currentAgentRoleChanged();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QList<Settings::AgentRole> roles = Settings::AgentRolesManager::loadAllRoles();
|
|
||||||
|
|
||||||
for (const auto &role : roles) {
|
|
||||||
if (role.name == roleName) {
|
|
||||||
settings.lastUsedRoleId.setValue(role.id);
|
|
||||||
settings.writeSettings();
|
|
||||||
m_currentAgentRole = role.name;
|
|
||||||
emit currentAgentRoleChanged();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList ChatRootView::availableAgentRoles() const
|
QStringList ChatRootView::availableAgentRoles() const
|
||||||
{
|
{
|
||||||
return m_availableAgentRoles;
|
return m_agentRoleController->availableRoles();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ChatRootView::currentAgentRole() const
|
QString ChatRootView::currentAgentRole() const
|
||||||
{
|
{
|
||||||
return m_currentAgentRole;
|
return m_agentRoleController->currentRole();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ChatRootView::baseSystemPrompt() const
|
QString ChatRootView::baseSystemPrompt() const
|
||||||
{
|
{
|
||||||
return Settings::chatAssistantSettings().systemPrompt();
|
return m_agentRoleController->baseSystemPrompt();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ChatRootView::currentAgentRoleDescription() const
|
QString ChatRootView::currentAgentRoleDescription() const
|
||||||
{
|
{
|
||||||
const QString lastRoleId = Settings::chatAssistantSettings().lastUsedRoleId();
|
return m_agentRoleController->currentRoleDescription();
|
||||||
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 ChatRootView::currentAgentRoleSystemPrompt() const
|
QString ChatRootView::currentAgentRoleSystemPrompt() const
|
||||||
{
|
{
|
||||||
const QString lastRoleId = Settings::chatAssistantSettings().lastUsedRoleId();
|
return m_agentRoleController->currentRoleSystemPrompt();
|
||||||
if (lastRoleId.isEmpty())
|
|
||||||
return QString();
|
|
||||||
|
|
||||||
const Settings::AgentRole role = Settings::AgentRolesManager::loadRole(lastRoleId);
|
|
||||||
if (role.id.isEmpty())
|
|
||||||
return QString();
|
|
||||||
|
|
||||||
return role.systemPrompt;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatRootView::openAgentRolesSettings()
|
void ChatRootView::openAgentRolesSettings()
|
||||||
{
|
{
|
||||||
Settings::showSettings(Utils::Id("QodeAssist.AgentRoles"));
|
m_agentRoleController->openSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatRootView::compressCurrentChat()
|
void ChatRootView::compressCurrentChat()
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
namespace QodeAssist::Chat {
|
namespace QodeAssist::Chat {
|
||||||
|
|
||||||
class ChatCompressor;
|
class ChatCompressor;
|
||||||
|
class AgentRoleController;
|
||||||
|
|
||||||
class ChatRootView : public QQuickItem
|
class ChatRootView : public QQuickItem
|
||||||
{
|
{
|
||||||
@@ -271,10 +272,8 @@ private:
|
|||||||
QStringList m_availableConfigurations;
|
QStringList m_availableConfigurations;
|
||||||
QString m_currentConfiguration;
|
QString m_currentConfiguration;
|
||||||
|
|
||||||
QStringList m_availableAgentRoles;
|
|
||||||
QString m_currentAgentRole;
|
|
||||||
|
|
||||||
ChatCompressor *m_chatCompressor;
|
ChatCompressor *m_chatCompressor;
|
||||||
|
AgentRoleController *m_agentRoleController;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace QodeAssist::Chat
|
} // namespace QodeAssist::Chat
|
||||||
|
|||||||
Reference in New Issue
Block a user