fix: Improve tool handler tools execution

This commit is contained in:
Petr Mironychev
2025-10-12 11:18:20 +02:00
parent 5ae6f9e3bf
commit d285ab6117
2 changed files with 8 additions and 4 deletions

View File

@ -41,7 +41,7 @@ QFuture<QString> ToolHandler::executeToolAsync(
return QtConcurrent::run([]() -> QString { throw std::runtime_error("Tool is null"); });
}
auto execution = new ToolExecution();
auto execution = std::make_unique<ToolExecution>();
execution->requestId = requestId;
execution->toolId = toolId;
execution->toolName = tool->name();
@ -55,7 +55,7 @@ QFuture<QString> ToolHandler::executeToolAsync(
auto future = tool->executeAsync(input);
execution->watcher->setFuture(future);
m_activeExecutions.insert(toolId, execution);
m_activeExecutions.insert(toolId, execution.release());
return future;
}

View File

@ -86,8 +86,12 @@ QJsonArray ToolsManager::getToolsDefinitions(LLMCore::ToolSchemaFormat format) c
void ToolsManager::cleanupRequest(const QString &requestId)
{
m_pendingTools.remove(requestId);
m_toolHandler->cleanupRequest(requestId);
if (m_pendingTools.contains(requestId)) {
LOG_MESSAGE(QString("ToolsManager: Canceling pending tools for request %1").arg(requestId));
m_toolHandler->cleanupRequest(requestId);
m_pendingTools.remove(requestId);
}
LOG_MESSAGE(QString("ToolsManager: Cleaned up request %1").arg(requestId));
}