mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2026-07-24 12:11:04 -04:00
feat: add support acp in common chat (#369)
This commit is contained in:
@@ -8,9 +8,19 @@
|
||||
|
||||
#include "ConfigurationManager.hpp"
|
||||
#include "GeneralSettings.hpp"
|
||||
#include "acp/AgentCatalogStore.hpp"
|
||||
|
||||
namespace QodeAssist::Chat {
|
||||
|
||||
namespace {
|
||||
|
||||
QString agentEntry(const QString &agentName)
|
||||
{
|
||||
return ChatConfigurationController::tr("Agent: %1").arg(agentName);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
ChatConfigurationController::ChatConfigurationController(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
@@ -29,6 +39,26 @@ ChatConfigurationController::ChatConfigurationController(QObject *parent)
|
||||
loadAvailableConfigurations();
|
||||
}
|
||||
|
||||
void ChatConfigurationController::setAgentCatalog(Acp::AgentCatalogStore *store)
|
||||
{
|
||||
if (m_agents == store)
|
||||
return;
|
||||
|
||||
if (m_agents)
|
||||
disconnect(m_agents, nullptr, this, nullptr);
|
||||
|
||||
m_agents = store;
|
||||
if (m_agents) {
|
||||
connect(
|
||||
m_agents,
|
||||
&Acp::AgentCatalogStore::catalogChanged,
|
||||
this,
|
||||
&ChatConfigurationController::loadAvailableConfigurations);
|
||||
}
|
||||
|
||||
loadAvailableConfigurations();
|
||||
}
|
||||
|
||||
QStringList ChatConfigurationController::availableConfigurations() const
|
||||
{
|
||||
return m_availableConfigurations;
|
||||
@@ -41,12 +71,33 @@ QString ChatConfigurationController::currentConfiguration() const
|
||||
|
||||
void ChatConfigurationController::updateCurrentConfiguration()
|
||||
{
|
||||
if (!m_boundAgentName.isEmpty()) {
|
||||
m_currentConfiguration = agentEntry(m_boundAgentName);
|
||||
emit currentConfigurationChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
auto &settings = Settings::generalSettings();
|
||||
m_currentConfiguration
|
||||
= QString("%1 - %2").arg(settings.caProvider.value(), settings.caModel.value());
|
||||
emit currentConfigurationChanged();
|
||||
}
|
||||
|
||||
void ChatConfigurationController::setBoundAgent(const Acp::AgentDefinition &agent)
|
||||
{
|
||||
m_boundAgentName = agent.name;
|
||||
updateCurrentConfiguration();
|
||||
}
|
||||
|
||||
void ChatConfigurationController::clearBoundAgent()
|
||||
{
|
||||
if (m_boundAgentName.isEmpty())
|
||||
return;
|
||||
|
||||
m_boundAgentName.clear();
|
||||
updateCurrentConfiguration();
|
||||
}
|
||||
|
||||
void ChatConfigurationController::loadAvailableConfigurations()
|
||||
{
|
||||
auto &manager = Settings::ConfigurationManager::instance();
|
||||
@@ -56,23 +107,56 @@ void ChatConfigurationController::loadAvailableConfigurations()
|
||||
Settings::ConfigurationType::Chat);
|
||||
|
||||
m_availableConfigurations.clear();
|
||||
m_agentIdByEntry.clear();
|
||||
m_availableConfigurations.append(QObject::tr("Current Settings"));
|
||||
|
||||
for (const Settings::AIConfiguration &config : configs) {
|
||||
m_availableConfigurations.append(config.name);
|
||||
}
|
||||
|
||||
if (m_agents) {
|
||||
for (const Acp::AgentDefinition &agent : m_agents->catalog().launchableAgents()) {
|
||||
const QString entry = agentEntry(agent.name);
|
||||
m_agentIdByEntry.insert(entry, agent.id);
|
||||
m_availableConfigurations.append(entry);
|
||||
}
|
||||
}
|
||||
|
||||
updateCurrentConfiguration();
|
||||
|
||||
emit availableConfigurationsChanged();
|
||||
}
|
||||
|
||||
std::optional<Acp::AgentDefinition> ChatConfigurationController::agentById(const QString &agentId)
|
||||
{
|
||||
if (agentId.isEmpty() || !m_agents)
|
||||
return std::nullopt;
|
||||
|
||||
if (auto agent = m_agents->catalog().agent(agentId))
|
||||
return agent;
|
||||
|
||||
m_agents->reload();
|
||||
return m_agents->catalog().agent(agentId);
|
||||
}
|
||||
|
||||
void ChatConfigurationController::applyConfiguration(const QString &configName)
|
||||
{
|
||||
if (configName == QObject::tr("Current Settings")) {
|
||||
const QString agentId = m_agentIdByEntry.value(configName);
|
||||
if (!agentId.isEmpty()) {
|
||||
if (!m_agents)
|
||||
return;
|
||||
if (const auto agent = m_agents->catalog().agent(agentId))
|
||||
emit agentRequested(*agent);
|
||||
return;
|
||||
}
|
||||
|
||||
if (configName == QObject::tr("Current Settings")) {
|
||||
emit llmRequested();
|
||||
return;
|
||||
}
|
||||
|
||||
emit llmRequested();
|
||||
|
||||
auto &manager = Settings::ConfigurationManager::instance();
|
||||
QVector<Settings::AIConfiguration> configs = manager.configurations(
|
||||
Settings::ConfigurationType::Chat);
|
||||
|
||||
Reference in New Issue
Block a user