mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2026-06-30 01:59:11 -04:00
fix: Remove isUserSource from tests
This commit is contained in:
@@ -33,14 +33,33 @@ Session::Session(Agent *agent, QObject *parent)
|
||||
|
||||
Session::Session(Agent *agent, ConversationHistory *externalHistory, QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_agent(agent)
|
||||
, m_history(externalHistory ? externalHistory : new ConversationHistory(this))
|
||||
, m_systemPrompt(new SystemPromptBuilder(this))
|
||||
{
|
||||
if (!m_agent) {
|
||||
m_invalidReason = QStringLiteral("Session: agent is null");
|
||||
if (agent)
|
||||
setAgent(agent);
|
||||
}
|
||||
|
||||
void Session::setAgent(Agent *agent)
|
||||
{
|
||||
if (agent == m_agent)
|
||||
return;
|
||||
|
||||
if (isInFlight())
|
||||
teardownInFlight();
|
||||
|
||||
if (m_router) {
|
||||
delete m_router;
|
||||
m_router = nullptr;
|
||||
}
|
||||
|
||||
delete m_agent;
|
||||
m_agent = agent;
|
||||
m_invalidReason.clear();
|
||||
|
||||
if (!m_agent)
|
||||
return;
|
||||
|
||||
m_agent->setParent(this);
|
||||
|
||||
if (!m_agent->isValid()) {
|
||||
@@ -55,8 +74,7 @@ Session::Session(Agent *agent, ConversationHistory *externalHistory, QObject *pa
|
||||
return;
|
||||
}
|
||||
if (!m_agent->promptTemplate()) {
|
||||
m_invalidReason
|
||||
= QStringLiteral("Session: agent has no inline prompt template");
|
||||
m_invalidReason = QStringLiteral("Session: agent has no inline prompt template");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -85,6 +103,16 @@ bool Session::isInFlight() const noexcept
|
||||
return !m_inFlight.isEmpty();
|
||||
}
|
||||
|
||||
bool Session::hasAgent() const noexcept
|
||||
{
|
||||
return m_agent != nullptr;
|
||||
}
|
||||
|
||||
bool Session::canSend() const noexcept
|
||||
{
|
||||
return isValid() && m_agent != nullptr && client() != nullptr;
|
||||
}
|
||||
|
||||
const ErrorInfo &Session::lastError() const noexcept
|
||||
{
|
||||
return m_lastError;
|
||||
@@ -128,8 +156,12 @@ void Session::unpinContext(const QString &id)
|
||||
|
||||
LLMQore::RequestID Session::send(std::vector<std::unique_ptr<LLMQore::ContentBlock>> userBlocks)
|
||||
{
|
||||
if (!isValid()) {
|
||||
m_lastError = makeError(ErrorCategory::Config, invalidReason());
|
||||
if (!canSend()) {
|
||||
const QString reason = m_agent ? (invalidReason().isEmpty()
|
||||
? QStringLiteral("Session: agent has no live client")
|
||||
: invalidReason())
|
||||
: QStringLiteral("Session: no agent bound");
|
||||
m_lastError = makeError(ErrorCategory::Config, reason);
|
||||
return {};
|
||||
}
|
||||
if (userBlocks.empty() || !m_history) {
|
||||
|
||||
@@ -46,6 +46,8 @@ public:
|
||||
bool isValid() const noexcept;
|
||||
QString invalidReason() const;
|
||||
bool isInFlight() const noexcept;
|
||||
bool hasAgent() const noexcept;
|
||||
bool canSend() const noexcept;
|
||||
const ErrorInfo &lastError() const noexcept;
|
||||
|
||||
using ContentLoader = ContextAssembler::ContentLoader;
|
||||
@@ -56,6 +58,7 @@ public:
|
||||
void unpinContext(const QString &id);
|
||||
|
||||
Agent *agent() noexcept { return m_agent; }
|
||||
void setAgent(Agent *agent);
|
||||
ConversationHistory *history() const noexcept { return m_history; }
|
||||
SystemPromptBuilder *systemPrompt() const noexcept { return m_systemPrompt; }
|
||||
|
||||
|
||||
@@ -59,6 +59,43 @@ Session *SessionManager::createSession(
|
||||
return session;
|
||||
}
|
||||
|
||||
Session *SessionManager::createDetachedSession(ConversationHistory *externalHistory, QObject *parent)
|
||||
{
|
||||
return new Session(/*agent=*/nullptr, externalHistory, parent);
|
||||
}
|
||||
|
||||
bool SessionManager::rebindAgentByName(Session *session, const QString &agentName, QString *errorOut)
|
||||
{
|
||||
if (!session) {
|
||||
if (errorOut)
|
||||
*errorOut = QStringLiteral("SessionManager: null session");
|
||||
return false;
|
||||
}
|
||||
if (!m_agentFactory) {
|
||||
if (errorOut)
|
||||
*errorOut = QStringLiteral("SessionManager: no AgentFactory bound");
|
||||
return false;
|
||||
}
|
||||
|
||||
QString agentErr;
|
||||
Agent *agent = m_agentFactory->create(agentName, /*parent=*/nullptr, &agentErr);
|
||||
if (!agent) {
|
||||
if (errorOut)
|
||||
*errorOut = agentErr.isEmpty()
|
||||
? QStringLiteral("SessionManager: agent '%1' not found").arg(agentName)
|
||||
: agentErr;
|
||||
return false;
|
||||
}
|
||||
|
||||
session->setAgent(agent);
|
||||
if (!session->isValid()) {
|
||||
if (errorOut)
|
||||
*errorOut = session->invalidReason();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Session *SessionManager::acquire(const QString &agentName, QString *errorOut)
|
||||
{
|
||||
auto &bucket = m_pool[agentName];
|
||||
|
||||
@@ -34,6 +34,10 @@ public:
|
||||
ConversationHistory *externalHistory,
|
||||
QString *errorOut = nullptr);
|
||||
|
||||
Session *createDetachedSession(ConversationHistory *externalHistory, QObject *parent);
|
||||
|
||||
bool rebindAgentByName(Session *session, const QString &agentName, QString *errorOut = nullptr);
|
||||
|
||||
Session *acquire(const QString &agentName, QString *errorOut = nullptr);
|
||||
void release(Session *session);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user