From b19c4c0c0cf3d390749b762b651d91f8921fd20b Mon Sep 17 00:00:00 2001 From: Petr Mironychev <9195189+Palm1r@users.noreply.github.com> Date: Mon, 1 Dec 2025 12:31:06 +0100 Subject: [PATCH] fix: Check Request id for tool block --- ChatView/ClientInterface.cpp | 33 +++++++++++++++++++++++++++++---- ChatView/ClientInterface.hpp | 7 +++++++ 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/ChatView/ClientInterface.cpp b/ChatView/ClientInterface.cpp index 477aee1..2924c52 100644 --- a/ChatView/ClientInterface.cpp +++ b/ChatView/ClientInterface.cpp @@ -289,14 +289,14 @@ void ClientInterface::sendMessage( connect( provider, &LLMCore::Provider::toolExecutionStarted, - m_chatModel, - &ChatModel::addToolExecutionStatus, + this, + &ClientInterface::handleToolExecutionStarted, Qt::UniqueConnection); connect( provider, &LLMCore::Provider::toolExecutionCompleted, - m_chatModel, - &ChatModel::updateToolResult, + this, + &ClientInterface::handleToolExecutionCompleted, Qt::UniqueConnection); connect( provider, @@ -498,6 +498,31 @@ void ClientInterface::handleRedactedThinkingBlockReceived( m_chatModel->addRedactedThinkingBlock(requestId, signature); } +void ClientInterface::handleToolExecutionStarted( + const QString &requestId, const QString &toolId, const QString &toolName) +{ + if (!m_activeRequests.contains(requestId)) { + LOG_MESSAGE(QString("Ignoring tool execution start for non-chat request: %1").arg(requestId)); + return; + } + + m_chatModel->addToolExecutionStatus(requestId, toolId, toolName); +} + +void ClientInterface::handleToolExecutionCompleted( + const QString &requestId, + const QString &toolId, + const QString &toolName, + const QString &toolOutput) +{ + if (!m_activeRequests.contains(requestId)) { + LOG_MESSAGE(QString("Ignoring tool execution result for non-chat request: %1").arg(requestId)); + return; + } + + m_chatModel->updateToolResult(requestId, toolId, toolName, toolOutput); +} + bool ClientInterface::isImageFile(const QString &filePath) const { static const QSet imageExtensions = {"png", "jpg", "jpeg", "gif", "webp", "bmp", "svg"}; diff --git a/ChatView/ClientInterface.hpp b/ChatView/ClientInterface.hpp index 0fd895c..5155b36 100644 --- a/ChatView/ClientInterface.hpp +++ b/ChatView/ClientInterface.hpp @@ -66,6 +66,13 @@ private slots: void handleThinkingBlockReceived( const QString &requestId, const QString &thinking, const QString &signature); void handleRedactedThinkingBlockReceived(const QString &requestId, const QString &signature); + void handleToolExecutionStarted( + const QString &requestId, const QString &toolId, const QString &toolName); + void handleToolExecutionCompleted( + const QString &requestId, + const QString &toolId, + const QString &toolName, + const QString &toolOutput); private: void handleLLMResponse(const QString &response, const QJsonObject &request);