mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2026-06-30 01:59:11 -04:00
fix: Improve agents profiles for Ollama
This commit is contained in:
@@ -18,7 +18,10 @@ namespace QodeAssist {
|
||||
SessionManager::SessionManager(AgentFactory *agentFactory, QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_agentFactory(agentFactory)
|
||||
{}
|
||||
{
|
||||
if (m_agentFactory)
|
||||
connect(m_agentFactory, &AgentFactory::agentsChanged, this, &SessionManager::flushPool);
|
||||
}
|
||||
|
||||
SessionManager::~SessionManager() = default;
|
||||
|
||||
@@ -101,7 +104,7 @@ Session *SessionManager::acquire(const QString &agentName, QString *errorOut)
|
||||
auto &bucket = m_pool[agentName];
|
||||
while (!bucket.isEmpty()) {
|
||||
QPointer<Session> pooled = bucket.takeLast();
|
||||
if (pooled && pooled->isValid()) {
|
||||
if (pooled && pooled->isValid() && pooledAgentMatchesCurrent(pooled, agentName)) {
|
||||
resetSession(pooled);
|
||||
m_sessions.append(pooled);
|
||||
return pooled.data();
|
||||
@@ -154,6 +157,32 @@ void SessionManager::resetSession(Session *session)
|
||||
}
|
||||
}
|
||||
|
||||
bool SessionManager::pooledAgentMatchesCurrent(Session *session, const QString &agentName) const
|
||||
{
|
||||
if (!m_agentFactory)
|
||||
return true;
|
||||
Agent *agent = session ? session->agent() : nullptr;
|
||||
if (!agent)
|
||||
return false;
|
||||
const AgentConfig *current = m_agentFactory->configByName(agentName);
|
||||
if (!current)
|
||||
return false;
|
||||
const AgentConfig &snapshot = agent->config();
|
||||
return snapshot.model == current->model
|
||||
&& snapshot.providerInstance == current->providerInstance;
|
||||
}
|
||||
|
||||
void SessionManager::flushPool()
|
||||
{
|
||||
for (auto &bucket : m_pool) {
|
||||
for (const QPointer<Session> &pooled : bucket) {
|
||||
if (pooled)
|
||||
pooled->deleteLater();
|
||||
}
|
||||
}
|
||||
m_pool.clear();
|
||||
}
|
||||
|
||||
void SessionManager::removeSession(Session *session)
|
||||
{
|
||||
if (!session)
|
||||
|
||||
Reference in New Issue
Block a user