refactor: add to template agent roles

This commit is contained in:
Petr Mironychev
2026-06-04 16:21:34 +02:00
parent c151c5030b
commit 3179c0c358
113 changed files with 383 additions and 5292 deletions

View File

@@ -32,6 +32,7 @@
#include <SessionManager.hpp>
#include "ChatAgentController.hpp"
#include "AgentRole.hpp"
#include "ChatAssistantSettings.hpp"
#include "ChatCompressor.hpp"
#include "ChatHistoryStore.hpp"
@@ -393,6 +394,43 @@ void ChatRootView::setCurrentChatAgent(const QString &name)
m_agentController->setCurrentAgent(name);
}
QStringList ChatRootView::availableRoles() const
{
return m_availableRoles;
}
QString ChatRootView::currentRole() const
{
return m_currentRole;
}
void ChatRootView::setCurrentRole(const QString &roleId)
{
if (m_currentRole == roleId)
return;
m_currentRole = roleId;
emit currentRoleChanged();
}
void ChatRootView::loadAvailableRoles()
{
QStringList ids;
const QList<Settings::AgentRole> roles = Settings::AgentRolesManager::loadAllRoles();
ids.reserve(roles.size());
for (const auto &r : roles)
ids << r.id;
if (ids != m_availableRoles) {
m_availableRoles = ids;
emit availableRolesChanged();
}
if (!m_availableRoles.isEmpty() && !m_availableRoles.contains(m_currentRole))
setCurrentRole(m_availableRoles.contains(QStringLiteral("developer"))
? QStringLiteral("developer")
: m_availableRoles.first());
}
QVariantList ChatRootView::searchSkills(const QString &query) const
{
QVariantList results;
@@ -501,6 +539,7 @@ void ChatRootView::dispatchSend(
m_clientInterface->setSkillsManager(skillsManager());
m_clientInterface->setSessionManager(sessionManager());
m_clientInterface->setActiveAgent(currentChatAgent());
m_clientInterface->setActiveRole(currentRole());
m_clientInterface->sendMessage(message, attachments, linkedFiles);
m_fileManager->clearIntermediateStorage();

View File

@@ -59,6 +59,8 @@ class ChatRootView : public QQuickItem
Q_PROPERTY(bool isThinkingSupport READ isThinkingSupport NOTIFY isThinkingSupportChanged FINAL)
Q_PROPERTY(QStringList availableChatAgents READ availableChatAgents NOTIFY availableChatAgentsChanged FINAL)
Q_PROPERTY(QString currentChatAgent READ currentChatAgent WRITE setCurrentChatAgent NOTIFY currentChatAgentChanged FINAL)
Q_PROPERTY(QStringList availableRoles READ availableRoles NOTIFY availableRolesChanged FINAL)
Q_PROPERTY(QString currentRole READ currentRole WRITE setCurrentRole NOTIFY currentRoleChanged FINAL)
Q_PROPERTY(bool isCompressing READ isCompressing NOTIFY isCompressingChanged FINAL)
Q_PROPERTY(bool isInEditor READ isInEditor NOTIFY isInEditorChanged FINAL)
Q_PROPERTY(QString chatTitle READ chatTitle NOTIFY chatTitleChanged FINAL)
@@ -155,6 +157,11 @@ public:
QString currentChatAgent() const;
void setCurrentChatAgent(const QString &name);
Q_INVOKABLE void loadAvailableRoles();
QStringList availableRoles() const;
QString currentRole() const;
void setCurrentRole(const QString &roleId);
int currentMessageTotalEdits() const;
int currentMessageAppliedEdits() const;
int currentMessagePendingEdits() const;
@@ -208,6 +215,8 @@ signals:
void availableChatAgentsChanged();
void currentChatAgentChanged();
void availableRolesChanged();
void currentRoleChanged();
void isCompressingChanged();
void compressionCompleted(const QString &compressedChatPath);
@@ -262,6 +271,9 @@ private:
QString m_lastInfoMessage;
QString m_currentRole = QStringLiteral("developer");
QStringList m_availableRoles;
ChatCompressor *m_chatCompressor;
ChatAgentController *m_agentController;
FileEditController *m_fileEditController;

View File

@@ -30,7 +30,10 @@
#include <ConversationHistory.hpp>
#include <Message.hpp>
#include <ContextRenderer.hpp>
#include <Session.hpp>
#include <QDir>
#include <SessionManager.hpp>
#include <SystemPromptBuilder.hpp>
@@ -75,6 +78,11 @@ void ClientInterface::setActiveAgent(const QString &agentName)
m_activeAgent = agentName;
}
void ClientInterface::setActiveRole(const QString &roleId)
{
m_activeRoleId = roleId;
}
void ClientInterface::sendMessage(
const QString &message,
const QList<QString> &attachments,
@@ -175,9 +183,15 @@ void ClientInterface::sendMessage(
return;
}
Tools::registerQodeAssistTools(client->tools());
if (m_skillsManager)
Tools::registerSkillTool(client->tools(), m_skillsManager);
auto *project = ProjectExplorer::ProjectManager::startupProject();
Templates::ContextRenderer::Bindings bindings;
bindings.projectDir = project ? project->projectDirectory().toFSPathString() : QString();
bindings.homeDir = QDir::homePath();
bindings.roleId = m_activeRoleId;
session->setContextBindings(bindings);
if (m_sessionManager)
m_sessionManager->toolContributors().contribute(client->tools());
client->setMaxToolContinuations(Settings::toolsSettings().maxToolContinuations());
client->setTransferTimeout(
static_cast<int>(Settings::generalSettings().requestTimeout() * 1000));

View File

@@ -37,6 +37,7 @@ public:
void setSkillsManager(Skills::SkillsManager *skillsManager);
void setSessionManager(SessionManager *sessionManager);
void setActiveAgent(const QString &agentName);
void setActiveRole(const QString &roleId);
void sendMessage(
const QString &message,
@@ -98,6 +99,7 @@ private:
Skills::SkillsManager *m_skillsManager = nullptr;
QPointer<SessionManager> m_sessionManager;
QString m_activeAgent;
QString m_activeRoleId;
QString m_chatFilePath;
QHash<QString, RequestContext> m_activeRequests;

View File

@@ -152,6 +152,19 @@ ChatRootView {
root.loadAvailableChatAgents()
}
}
roleSelector {
model: root.availableRoles
displayText: root.currentRole
onActivated: function(index) {
root.currentRole = root.availableRoles[index]
}
Component.onCompleted: root.loadAvailableRoles()
popup.onAboutToShow: {
root.loadAvailableRoles()
}
}
}
RowLayout {

View File

@@ -25,6 +25,7 @@ Rectangle {
property alias contextButton: contextButtonId
property alias settingsButton: settingsButtonId
property alias agentSelector: agentSelectorId
property alias roleSelector: roleSelectorId
property alias relocateTooltip: relocateTooltipId
color: palette.window.hslLightness > 0.5 ?
@@ -141,7 +142,22 @@ Rectangle {
QoAToolTip {
visible: agentSelectorId.hovered
delay: 250
text: qsTr("Select chat agent (provider, model and role come from the agent)")
text: qsTr("Select chat agent (provider and model come from the agent)")
}
}
QoAComboBox {
id: roleSelectorId
implicitHeight: 25
model: []
currentIndex: 0
QoAToolTip {
visible: roleSelectorId.hovered
delay: 250
text: qsTr("Select the role (system prompt) for the chat")
}
}
}