feat: Improve showing tools in chat (#235)

This commit is contained in:
Petr Mironychev
2025-10-10 10:03:22 +02:00
committed by GitHub
parent bde58fb9aa
commit d2b28093a6
26 changed files with 464 additions and 59 deletions

View File

@ -16,6 +16,7 @@ qt_add_qml_module(QodeAssistChatView
qml/parts/TopBar.qml qml/parts/TopBar.qml
qml/parts/BottomBar.qml qml/parts/BottomBar.qml
qml/parts/AttachedFilesPlace.qml qml/parts/AttachedFilesPlace.qml
qml/ToolStatusItem.qml
RESOURCES RESOURCES
icons/attach-file-light.svg icons/attach-file-light.svg

View File

@ -23,6 +23,7 @@
#include <QtQml> #include <QtQml>
#include "ChatAssistantSettings.hpp" #include "ChatAssistantSettings.hpp"
#include "Logger.hpp"
namespace QodeAssist::Chat { namespace QodeAssist::Chat {
@ -91,10 +92,12 @@ void ChatModel::addMessage(
} }
} }
if (!m_messages.isEmpty() && !id.isEmpty() && m_messages.last().id == id) { if (!m_messages.isEmpty() && !id.isEmpty() && m_messages.last().id == id
&& m_messages.last().role == role) {
Message &lastMessage = m_messages.last(); Message &lastMessage = m_messages.last();
lastMessage.content = content; lastMessage.content = content;
lastMessage.attachments = attachments; lastMessage.attachments = attachments;
LOG_MESSAGE(QString("Updated message: role=%1, id=%2").arg(role).arg(id));
emit dataChanged(index(m_messages.size() - 1), index(m_messages.size() - 1)); emit dataChanged(index(m_messages.size() - 1), index(m_messages.size() - 1));
} else { } else {
beginInsertRows(QModelIndex(), m_messages.size(), m_messages.size()); beginInsertRows(QModelIndex(), m_messages.size(), m_messages.size());
@ -102,6 +105,10 @@ void ChatModel::addMessage(
newMessage.attachments = attachments; newMessage.attachments = attachments;
m_messages.append(newMessage); m_messages.append(newMessage);
endInsertRows(); endInsertRows();
LOG_MESSAGE(QString("Added new message: role=%1, id=%2, index=%3")
.arg(role)
.arg(id)
.arg(m_messages.size() - 1));
} }
} }
@ -224,4 +231,57 @@ void ChatModel::resetModelTo(int index)
} }
} }
void ChatModel::addToolExecutionStatus(
const QString &requestId, const QString &toolId, const QString &toolName)
{
QString content = toolName;
LOG_MESSAGE(QString("Adding tool execution status: requestId=%1, toolId=%2, toolName=%3")
.arg(requestId, toolId, toolName));
if (!m_messages.isEmpty() && !toolId.isEmpty() && m_messages.last().id == toolId
&& m_messages.last().role == ChatRole::Tool) {
Message &lastMessage = m_messages.last();
lastMessage.content = content;
LOG_MESSAGE(QString("Updated existing tool message at index %1").arg(m_messages.size() - 1));
emit dataChanged(index(m_messages.size() - 1), index(m_messages.size() - 1));
} else {
beginInsertRows(QModelIndex(), m_messages.size(), m_messages.size());
Message newMessage{ChatRole::Tool, content, toolId};
m_messages.append(newMessage);
endInsertRows();
LOG_MESSAGE(QString("Created new tool message at index %1 with toolId=%2")
.arg(m_messages.size() - 1)
.arg(toolId));
}
}
void ChatModel::updateToolResult(
const QString &requestId, const QString &toolId, const QString &toolName, const QString &result)
{
if (m_messages.isEmpty() || toolId.isEmpty()) {
LOG_MESSAGE(QString("Cannot update tool result: messages empty=%1, toolId empty=%2")
.arg(m_messages.isEmpty())
.arg(toolId.isEmpty()));
return;
}
LOG_MESSAGE(
QString("Updating tool result: requestId=%1, toolId=%2, toolName=%3, result length=%4")
.arg(requestId, toolId, toolName)
.arg(result.length()));
for (int i = m_messages.size() - 1; i >= 0; --i) {
if (m_messages[i].id == toolId && m_messages[i].role == ChatRole::Tool) {
m_messages[i].content = toolName + "\n" + result;
emit dataChanged(index(i), index(i));
LOG_MESSAGE(QString("Updated tool result at index %1").arg(i));
return;
}
}
LOG_MESSAGE(QString("WARNING: Tool message with requestId=%1 toolId=%2 not found!")
.arg(requestId, toolId));
}
} // namespace QodeAssist::Chat } // namespace QodeAssist::Chat

View File

@ -37,10 +37,11 @@ class ChatModel : public QAbstractListModel
QML_ELEMENT QML_ELEMENT
public: public:
enum ChatRole { System, User, Assistant }; enum ChatRole { System, User, Assistant, Tool };
Q_ENUM(ChatRole) Q_ENUM(ChatRole)
enum Roles { RoleType = Qt::UserRole, Content, Attachments }; enum Roles { RoleType = Qt::UserRole, Content, Attachments };
Q_ENUM(Roles)
struct Message struct Message
{ {
@ -75,6 +76,13 @@ public:
Q_INVOKABLE void resetModelTo(int index); Q_INVOKABLE void resetModelTo(int index);
void addToolExecutionStatus(
const QString &requestId, const QString &toolId, const QString &toolName);
void updateToolResult(
const QString &requestId,
const QString &toolId,
const QString &toolName,
const QString &result);
signals: signals:
void tokensThresholdChanged(); void tokensThresholdChanged();
void modelReseted(); void modelReseted();

View File

@ -139,6 +139,18 @@ void ClientInterface::sendMessage(
this, this,
&ClientInterface::handleRequestFailed, &ClientInterface::handleRequestFailed,
Qt::UniqueConnection); Qt::UniqueConnection);
connect(
provider,
&LLMCore::Provider::toolExecutionStarted,
m_chatModel,
&ChatModel::addToolExecutionStatus,
Qt::UniqueConnection);
connect(
provider,
&LLMCore::Provider::toolExecutionCompleted,
m_chatModel,
&ChatModel::updateToolResult,
Qt::UniqueConnection);
provider->sendRequest(requestId, config.url, config.providerRequest); provider->sendRequest(requestId, config.url, config.providerRequest);
} }

View File

@ -48,7 +48,6 @@ Rectangle {
property bool isUserMessage: false property bool isUserMessage: false
property int messageIndex: -1 property int messageIndex: -1
property real listViewContentY: 0
signal resetChatToMessage(int index) signal resetChatToMessage(int index)
@ -104,8 +103,6 @@ Rectangle {
id: codeBlockComponent id: codeBlockComponent
CodeBlockComponent { CodeBlockComponent {
itemData: msgCreatorDelegate.modelData itemData: msgCreatorDelegate.modelData
blockStart: root.y + msgCreatorDelegate.y
currentContentY: root.listViewContentY
} }
} }
} }

View File

@ -95,27 +95,14 @@ ChatRootView {
boundsBehavior: Flickable.StopAtBounds boundsBehavior: Flickable.StopAtBounds
cacheBuffer: 2000 cacheBuffer: 2000
delegate: ChatItem {
delegate: Loader {
required property var model required property var model
required property int index required property int index
width: ListView.view.width - scroll.width width: ListView.view.width - scroll.width
msgModel: root.chatModel.processMessageContent(model.content)
messageAttachments: model.attachments
isUserMessage: model.roleType === ChatModel.User
messageIndex: index
listViewContentY: chatListView.contentY
textFontFamily: root.textFontFamily
codeFontFamily: root.codeFontFamily
codeFontSize: root.codeFontSize
textFontSize: root.textFontSize
textFormat: root.textFormat
onResetChatToMessage: function(index) { sourceComponent: model.roleType === ChatModel.Tool ? toolMessageComponent : chatItemComponent
messageInput.text = model.content
messageInput.cursorPosition = model.content.length
root.chatModel.resetModelTo(index)
}
} }
header: Item { header: Item {
@ -136,6 +123,36 @@ ChatRootView {
root.scrollToBottom() root.scrollToBottom()
} }
} }
Component {
id: chatItemComponent
ChatItem {
msgModel: root.chatModel.processMessageContent(model.content)
messageAttachments: model.attachments
isUserMessage: model.roleType === ChatModel.User
messageIndex: index
textFontFamily: root.textFontFamily
codeFontFamily: root.codeFontFamily
codeFontSize: root.codeFontSize
textFontSize: root.textFontSize
textFormat: root.textFormat
onResetChatToMessage: function(idx) {
messageInput.text = model.content
messageInput.cursorPosition = model.content.length
root.chatModel.resetModelTo(idx)
}
}
}
Component {
id: toolMessageComponent
ToolStatusItem {
toolContent: model.content
}
}
} }
ScrollView { ScrollView {

View File

@ -0,0 +1,126 @@
/*
* Copyright (C) 2025 Petr Mironychev
*
* This file is part of QodeAssist.
*
* QodeAssist is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QodeAssist is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QodeAssist. If not, see <https://www.gnu.org/licenses/>.
*/
import QtQuick
Rectangle {
id: root
property string toolContent: ""
property bool expanded: false
readonly property int firstNewline: toolContent.indexOf('\n')
readonly property string toolName: firstNewline > 0 ? toolContent.substring(0, firstNewline) : toolContent
readonly property string toolResult: firstNewline > 0 ? toolContent.substring(firstNewline + 1) : ""
radius: 6
color: palette.base
clip: true
Behavior on implicitHeight {
NumberAnimation { duration: 200; easing.type: Easing.InOutQuad }
}
MouseArea {
id: header
width: parent.width
height: headerRow.height + 10
cursorShape: Qt.PointingHandCursor
onClicked: root.expanded = !root.expanded
Row {
id: headerRow
anchors {
verticalCenter: parent.verticalCenter
left: parent.left
leftMargin: 10
}
width: parent.width
spacing: 8
Text {
text: qsTr("Tool: %1").arg(root.toolName)
font.pixelSize: 13
font.bold: true
color: palette.text
}
Text {
anchors.verticalCenter: parent.verticalCenter
text: root.expanded ? "▼" : "▶"
font.pixelSize: 10
color: palette.mid
}
}
}
Column {
id: contentColumn
anchors {
left: parent.left
right: parent.right
top: header.bottom
margins: 10
}
spacing: 8
Text {
id: resultText
width: parent.width
text: root.toolResult
wrapMode: Text.Wrap
font.family: "monospace"
font.pixelSize: 11
color: palette.text
}
}
Rectangle {
id: messageMarker
anchors.verticalCenter: parent.verticalCenter
width: 3
height: root.height - root.radius
color: root.color.hslLightness > 0.5 ? Qt.darker(palette.alternateBase, 1.3)
: Qt.lighter(palette.alternateBase, 1.3)
radius: root.radius
}
states: [
State {
when: !root.expanded
PropertyChanges {
target: root
implicitHeight: header.height
}
},
State {
when: root.expanded
PropertyChanges {
target: root
implicitHeight: header.height + contentColumn.height + 20
}
}
]
}

View File

@ -27,27 +27,11 @@ Rectangle {
property string code: "" property string code: ""
property string language: "" property string language: ""
property bool expanded: false
property real currentContentY: 0
property real blockStart: 0
property alias codeFontFamily: codeText.font.family property alias codeFontFamily: codeText.font.family
property alias codeFontSize: codeText.font.pointSize property alias codeFontSize: codeText.font.pointSize
readonly property real collapsedHeight: copyButton.height + 10
readonly property real buttonTopMargin: 5
readonly property real blockEnd: blockStart + root.height
readonly property real maxButtonOffset: Math.max(0, root.height - copyButton.height - buttonTopMargin)
readonly property real buttonPosition: {
if (currentContentY > blockEnd) {
return buttonTopMargin;
}
else if (currentContentY > blockStart) {
let offset = currentContentY - blockStart;
return Math.min(offset, maxButtonOffset);
}
return buttonTopMargin;
}
color: palette.alternateBase color: palette.alternateBase
border.color: root.color.hslLightness > 0.5 ? Qt.darker(root.color, 1.3) border.color: root.color.hslLightness > 0.5 ? Qt.darker(root.color, 1.3)
@ -55,16 +39,65 @@ Rectangle {
border.width: 2 border.width: 2
radius: 4 radius: 4
implicitWidth: parent.width implicitWidth: parent.width
implicitHeight: codeText.implicitHeight + 20 clip: true
Behavior on implicitHeight {
NumberAnimation { duration: 200; easing.type: Easing.InOutQuad }
}
ChatUtils { ChatUtils {
id: utils id: utils
} }
HoverHandler {
id: hoverHandler
enabled: true
}
MouseArea {
id: header
width: parent.width
height: root.collapsedHeight
cursorShape: Qt.PointingHandCursor
onClicked: root.expanded = !root.expanded
Row {
id: headerRow
anchors {
verticalCenter: parent.verticalCenter
left: parent.left
leftMargin: 10
}
spacing: 6
Text {
text: root.language ? qsTr("Code (%1)").arg(root.language) :
qsTr("Code")
font.pixelSize: 12
font.bold: true
color: palette.text
}
Text {
anchors.verticalCenter: parent.verticalCenter
text: root.expanded ? "▼" : "▶"
font.pixelSize: 10
color: palette.mid
}
}
}
TextEdit { TextEdit {
id: codeText id: codeText
anchors.fill: parent
anchors.margins: 10 anchors {
left: parent.left
right: parent.right
top: header.bottom
margins: 10
}
text: root.code text: root.code
readOnly: true readOnly: true
selectByMouse: true selectByMouse: true
@ -73,29 +106,33 @@ Rectangle {
selectionColor: palette.highlight selectionColor: palette.highlight
} }
TextEdit {
anchors.top: parent.top
anchors.right: parent.right
anchors.margins: 5
readOnly: true
selectByMouse: true
text: root.language
color: root.color.hslLightness > 0.5 ? Qt.darker(root.color, 1.1)
: Qt.lighter(root.color, 1.1)
font.pointSize: codeText.font.pointSize - 4
}
QoAButton { QoAButton {
id: copyButton id: copyButton
anchors { anchors.right: parent.right
top: parent.top anchors.rightMargin: 5
topMargin: root.buttonPosition
right: parent.right y: {
rightMargin: root.buttonTopMargin if (!hoverHandler.hovered || !root.expanded) {
return 5
}
let mouseY = hoverHandler.point.position.y
let minY = header.height + 5
let maxY = root.height - copyButton.height - 5
return Math.max(minY, Math.min(mouseY - copyButton.height / 2, maxY))
}
Behavior on y {
NumberAnimation { duration: 100; easing.type: Easing.OutQuad }
}
Behavior on opacity {
NumberAnimation { duration: 150 }
} }
text: qsTr("Copy") text: qsTr("Copy")
onClicked: { onClicked: {
utils.copyToClipboard(root.code) utils.copyToClipboard(root.code)
text = qsTr("Copied") text = qsTr("Copied")
@ -108,4 +145,21 @@ Rectangle {
onTriggered: parent.text = qsTr("Copy") onTriggered: parent.text = qsTr("Copy")
} }
} }
states: [
State {
when: !root.expanded
PropertyChanges {
target: root
implicitHeight: root.collapsedHeight
}
},
State {
when: root.expanded
PropertyChanges {
target: root
implicitHeight: header.height + codeText.implicitHeight + 10
}
}
]
} }

View File

@ -37,6 +37,7 @@ public:
~BaseTool() override = default; ~BaseTool() override = default;
virtual QString name() const = 0; virtual QString name() const = 0;
virtual QString stringName() const = 0;
virtual QString description() const = 0; virtual QString description() const = 0;
virtual QJsonObject getDefinition(ToolSchemaFormat format) const = 0; virtual QJsonObject getDefinition(ToolSchemaFormat format) const = 0;

View File

@ -83,6 +83,14 @@ signals:
void fullResponseReceived( void fullResponseReceived(
const QodeAssist::LLMCore::RequestID &requestId, const QString &fullText); const QodeAssist::LLMCore::RequestID &requestId, const QString &fullText);
void requestFailed(const QodeAssist::LLMCore::RequestID &requestId, const QString &error); void requestFailed(const QodeAssist::LLMCore::RequestID &requestId, const QString &error);
signals:
void toolExecutionStarted(
const QString &requestId, const QString &toolId, const QString &toolName);
void toolExecutionCompleted(
const QString &requestId,
const QString &toolId,
const QString &toolName,
const QString &result);
protected: protected:
QJsonObject parseEventLine(const QString &line); QJsonObject parseEventLine(const QString &line);

View File

@ -281,6 +281,19 @@ void ClaudeProvider::onToolExecutionComplete(
LOG_MESSAGE(QString("Tool execution complete for Claude request %1").arg(requestId)); LOG_MESSAGE(QString("Tool execution complete for Claude request %1").arg(requestId));
for (auto it = toolResults.begin(); it != toolResults.end(); ++it) {
ClaudeMessage *message = m_messages[requestId];
auto toolContent = message->getCurrentToolUseContent();
for (auto tool : toolContent) {
if (tool->id() == it.key()) {
auto toolStringName = m_toolsManager->toolsFactory()->getStringName(tool->name());
emit toolExecutionCompleted(
requestId, tool->id(), toolStringName, toolResults[tool->id()]);
break;
}
}
}
ClaudeMessage *message = m_messages[requestId]; ClaudeMessage *message = m_messages[requestId];
QJsonObject continuationRequest = m_originalRequests[requestId]; QJsonObject continuationRequest = m_originalRequests[requestId];
QJsonArray messages = continuationRequest["messages"].toArray(); QJsonArray messages = continuationRequest["messages"].toArray();
@ -382,6 +395,8 @@ void ClaudeProvider::handleMessageComplete(const QString &requestId)
} }
for (auto toolContent : toolUseContent) { for (auto toolContent : toolUseContent) {
auto toolStringName = m_toolsManager->toolsFactory()->getStringName(toolContent->name());
emit toolExecutionStarted(requestId, toolContent->id(), toolStringName);
m_toolsManager->executeToolCall( m_toolsManager->executeToolCall(
requestId, toolContent->id(), toolContent->name(), toolContent->input()); requestId, toolContent->id(), toolContent->name(), toolContent->input());
} }

View File

@ -270,6 +270,19 @@ void LMStudioProvider::onToolExecutionComplete(
LOG_MESSAGE(QString("Tool execution complete for LMStudio request %1").arg(requestId)); LOG_MESSAGE(QString("Tool execution complete for LMStudio request %1").arg(requestId));
for (auto it = toolResults.begin(); it != toolResults.end(); ++it) {
OpenAIMessage *message = m_messages[requestId];
auto toolContent = message->getCurrentToolUseContent();
for (auto tool : toolContent) {
if (tool->id() == it.key()) {
auto toolStringName = m_toolsManager->toolsFactory()->getStringName(tool->name());
emit toolExecutionCompleted(
requestId, tool->id(), toolStringName, toolResults[tool->id()]);
break;
}
}
}
OpenAIMessage *message = m_messages[requestId]; OpenAIMessage *message = m_messages[requestId];
QJsonObject continuationRequest = m_originalRequests[requestId]; QJsonObject continuationRequest = m_originalRequests[requestId];
QJsonArray messages = continuationRequest["messages"].toArray(); QJsonArray messages = continuationRequest["messages"].toArray();
@ -368,6 +381,8 @@ void LMStudioProvider::handleMessageComplete(const QString &requestId)
} }
for (auto toolContent : toolUseContent) { for (auto toolContent : toolUseContent) {
auto toolStringName = m_toolsManager->toolsFactory()->getStringName(toolContent->name());
emit toolExecutionStarted(requestId, toolContent->id(), toolStringName);
m_toolsManager->executeToolCall( m_toolsManager->executeToolCall(
requestId, toolContent->id(), toolContent->name(), toolContent->input()); requestId, toolContent->id(), toolContent->name(), toolContent->input());
} }

View File

@ -274,6 +274,19 @@ void LlamaCppProvider::onToolExecutionComplete(
LOG_MESSAGE(QString("Tool execution complete for llama.cpp request %1").arg(requestId)); LOG_MESSAGE(QString("Tool execution complete for llama.cpp request %1").arg(requestId));
for (auto it = toolResults.begin(); it != toolResults.end(); ++it) {
OpenAIMessage *message = m_messages[requestId];
auto toolContent = message->getCurrentToolUseContent();
for (auto tool : toolContent) {
if (tool->id() == it.key()) {
auto toolStringName = m_toolsManager->toolsFactory()->getStringName(tool->name());
emit toolExecutionCompleted(
requestId, tool->id(), toolStringName, toolResults[tool->id()]);
break;
}
}
}
OpenAIMessage *message = m_messages[requestId]; OpenAIMessage *message = m_messages[requestId];
QJsonObject continuationRequest = m_originalRequests[requestId]; QJsonObject continuationRequest = m_originalRequests[requestId];
QJsonArray messages = continuationRequest["messages"].toArray(); QJsonArray messages = continuationRequest["messages"].toArray();
@ -372,6 +385,8 @@ void LlamaCppProvider::handleMessageComplete(const QString &requestId)
} }
for (auto toolContent : toolUseContent) { for (auto toolContent : toolUseContent) {
auto toolStringName = m_toolsManager->toolsFactory()->getStringName(toolContent->name());
emit toolExecutionStarted(requestId, toolContent->id(), toolStringName);
m_toolsManager->executeToolCall( m_toolsManager->executeToolCall(
requestId, toolContent->id(), toolContent->name(), toolContent->input()); requestId, toolContent->id(), toolContent->name(), toolContent->input());
} }

View File

@ -291,6 +291,19 @@ void MistralAIProvider::onToolExecutionComplete(
LOG_MESSAGE(QString("Tool execution complete for Mistral request %1").arg(requestId)); LOG_MESSAGE(QString("Tool execution complete for Mistral request %1").arg(requestId));
for (auto it = toolResults.begin(); it != toolResults.end(); ++it) {
OpenAIMessage *message = m_messages[requestId];
auto toolContent = message->getCurrentToolUseContent();
for (auto tool : toolContent) {
if (tool->id() == it.key()) {
auto toolStringName = m_toolsManager->toolsFactory()->getStringName(tool->name());
emit toolExecutionCompleted(
requestId, tool->id(), toolStringName, toolResults[tool->id()]);
break;
}
}
}
OpenAIMessage *message = m_messages[requestId]; OpenAIMessage *message = m_messages[requestId];
QJsonObject continuationRequest = m_originalRequests[requestId]; QJsonObject continuationRequest = m_originalRequests[requestId];
QJsonArray messages = continuationRequest["messages"].toArray(); QJsonArray messages = continuationRequest["messages"].toArray();
@ -389,6 +402,8 @@ void MistralAIProvider::handleMessageComplete(const QString &requestId)
} }
for (auto toolContent : toolUseContent) { for (auto toolContent : toolUseContent) {
auto toolStringName = m_toolsManager->toolsFactory()->getStringName(toolContent->name());
emit toolExecutionStarted(requestId, toolContent->id(), toolStringName);
m_toolsManager->executeToolCall( m_toolsManager->executeToolCall(
requestId, toolContent->id(), toolContent->name(), toolContent->input()); requestId, toolContent->id(), toolContent->name(), toolContent->input());
} }

View File

@ -248,6 +248,19 @@ void OpenAICompatProvider::onToolExecutionComplete(
LOG_MESSAGE(QString("Tool execution complete for OpenAICompat request %1").arg(requestId)); LOG_MESSAGE(QString("Tool execution complete for OpenAICompat request %1").arg(requestId));
for (auto it = toolResults.begin(); it != toolResults.end(); ++it) {
OpenAIMessage *message = m_messages[requestId];
auto toolContent = message->getCurrentToolUseContent();
for (auto tool : toolContent) {
if (tool->id() == it.key()) {
auto toolStringName = m_toolsManager->toolsFactory()->getStringName(tool->name());
emit toolExecutionCompleted(
requestId, tool->id(), toolStringName, toolResults[tool->id()]);
break;
}
}
}
OpenAIMessage *message = m_messages[requestId]; OpenAIMessage *message = m_messages[requestId];
QJsonObject continuationRequest = m_originalRequests[requestId]; QJsonObject continuationRequest = m_originalRequests[requestId];
QJsonArray messages = continuationRequest["messages"].toArray(); QJsonArray messages = continuationRequest["messages"].toArray();
@ -346,6 +359,8 @@ void OpenAICompatProvider::handleMessageComplete(const QString &requestId)
} }
for (auto toolContent : toolUseContent) { for (auto toolContent : toolUseContent) {
auto toolStringName = m_toolsManager->toolsFactory()->getStringName(toolContent->name());
emit toolExecutionStarted(requestId, toolContent->id(), toolStringName);
m_toolsManager->executeToolCall( m_toolsManager->executeToolCall(
requestId, toolContent->id(), toolContent->name(), toolContent->input()); requestId, toolContent->id(), toolContent->name(), toolContent->input());
} }

View File

@ -284,6 +284,19 @@ void OpenAIProvider::onToolExecutionComplete(
LOG_MESSAGE(QString("Tool execution complete for OpenAI request %1").arg(requestId)); LOG_MESSAGE(QString("Tool execution complete for OpenAI request %1").arg(requestId));
for (auto it = toolResults.begin(); it != toolResults.end(); ++it) {
OpenAIMessage *message = m_messages[requestId];
auto toolContent = message->getCurrentToolUseContent();
for (auto tool : toolContent) {
if (tool->id() == it.key()) {
auto toolStringName = m_toolsManager->toolsFactory()->getStringName(tool->name());
emit toolExecutionCompleted(
requestId, tool->id(), toolStringName, toolResults[tool->id()]);
break;
}
}
}
OpenAIMessage *message = m_messages[requestId]; OpenAIMessage *message = m_messages[requestId];
QJsonObject continuationRequest = m_originalRequests[requestId]; QJsonObject continuationRequest = m_originalRequests[requestId];
QJsonArray messages = continuationRequest["messages"].toArray(); QJsonArray messages = continuationRequest["messages"].toArray();
@ -382,6 +395,8 @@ void OpenAIProvider::handleMessageComplete(const QString &requestId)
} }
for (auto toolContent : toolUseContent) { for (auto toolContent : toolUseContent) {
auto toolStringName = m_toolsManager->toolsFactory()->getStringName(toolContent->name());
emit toolExecutionStarted(requestId, toolContent->id(), toolStringName);
m_toolsManager->executeToolCall( m_toolsManager->executeToolCall(
requestId, toolContent->id(), toolContent->name(), toolContent->input()); requestId, toolContent->id(), toolContent->name(), toolContent->input());
} }

View File

@ -41,6 +41,11 @@ QString ListProjectFilesTool::name() const
return "list_project_files"; return "list_project_files";
} }
QString ListProjectFilesTool::stringName() const
{
return {"Reading project files list"};
}
QString ListProjectFilesTool::description() const QString ListProjectFilesTool::description() const
{ {
return "Get a list of all source files in the current project. " return "Get a list of all source files in the current project. "

View File

@ -32,6 +32,7 @@ public:
explicit ListProjectFilesTool(QObject *parent = nullptr); explicit ListProjectFilesTool(QObject *parent = nullptr);
QString name() const override; QString name() const override;
QString stringName() const override;
QString description() const override; QString description() const override;
QJsonObject getDefinition(LLMCore::ToolSchemaFormat format) const override; QJsonObject getDefinition(LLMCore::ToolSchemaFormat format) const override;
QFuture<QString> executeAsync(const QJsonObject &input = QJsonObject()) override; QFuture<QString> executeAsync(const QJsonObject &input = QJsonObject()) override;

View File

@ -44,6 +44,11 @@ QString ReadProjectFileByNameTool::name() const
return "read_project_file_by_name"; return "read_project_file_by_name";
} }
QString ReadProjectFileByNameTool::stringName() const
{
return {"Reading project file by name"};
}
QString ReadProjectFileByNameTool::description() const QString ReadProjectFileByNameTool::description() const
{ {
return "Read the content of a specific file from the current project by providing its filename " return "Read the content of a specific file from the current project by providing its filename "

View File

@ -31,6 +31,7 @@ public:
explicit ReadProjectFileByNameTool(QObject *parent = nullptr); explicit ReadProjectFileByNameTool(QObject *parent = nullptr);
QString name() const override; QString name() const override;
QString stringName() const override;
QString description() const override; QString description() const override;
QJsonObject getDefinition(LLMCore::ToolSchemaFormat format) const override; QJsonObject getDefinition(LLMCore::ToolSchemaFormat format) const override;
QFuture<QString> executeAsync(const QJsonObject &input = QJsonObject()) override; QFuture<QString> executeAsync(const QJsonObject &input = QJsonObject()) override;

View File

@ -39,6 +39,11 @@ QString ReadVisibleFilesTool::name() const
return "read_visible_files"; return "read_visible_files";
} }
QString ReadVisibleFilesTool::stringName() const
{
return {"Reading currently opened and visible files in IDE editors"};
}
QString ReadVisibleFilesTool::description() const QString ReadVisibleFilesTool::description() const
{ {
return "Read the content of all currently visible files in editor tabs. " return "Read the content of all currently visible files in editor tabs. "

View File

@ -31,6 +31,7 @@ public:
explicit ReadVisibleFilesTool(QObject *parent = nullptr); explicit ReadVisibleFilesTool(QObject *parent = nullptr);
QString name() const override; QString name() const override;
QString stringName() const override;
QString description() const override; QString description() const override;
QJsonObject getDefinition(LLMCore::ToolSchemaFormat format) const override; QJsonObject getDefinition(LLMCore::ToolSchemaFormat format) const override;
QFuture<QString> executeAsync(const QJsonObject &input = QJsonObject()) override; QFuture<QString> executeAsync(const QJsonObject &input = QJsonObject()) override;

View File

@ -82,4 +82,9 @@ QJsonArray ToolsFactory::getToolsDefinitions(LLMCore::ToolSchemaFormat format) c
return toolsArray; return toolsArray;
} }
QString ToolsFactory::getStringName(const QString &name) const
{
return m_tools.contains(name) ? m_tools.value(name)->stringName() : QString("Unknown tools");
}
} // namespace QodeAssist::Tools } // namespace QodeAssist::Tools

View File

@ -35,6 +35,7 @@ public:
QList<LLMCore::BaseTool *> getAvailableTools() const; QList<LLMCore::BaseTool *> getAvailableTools() const;
LLMCore::BaseTool *getToolByName(const QString &name) const; LLMCore::BaseTool *getToolByName(const QString &name) const;
QJsonArray getToolsDefinitions(LLMCore::ToolSchemaFormat format) const; QJsonArray getToolsDefinitions(LLMCore::ToolSchemaFormat format) const;
QString getStringName(const QString &name) const;
private: private:
void registerTools(); void registerTools();

View File

@ -123,6 +123,11 @@ void ToolsManager::onToolFinished(
} }
} }
ToolsFactory *ToolsManager::toolsFactory() const
{
return m_toolsFactory;
}
bool ToolsManager::isExecutionComplete(const QString &requestId) const bool ToolsManager::isExecutionComplete(const QString &requestId) const
{ {
if (!m_pendingTools.contains(requestId)) { if (!m_pendingTools.contains(requestId)) {

View File

@ -56,6 +56,8 @@ public:
QJsonArray getToolsDefinitions(ToolSchemaFormat format) const; QJsonArray getToolsDefinitions(ToolSchemaFormat format) const;
void cleanupRequest(const QString &requestId); void cleanupRequest(const QString &requestId);
ToolsFactory *toolsFactory() const;
signals: signals:
void toolExecutionComplete(const QString &requestId, const QHash<QString, QString> &toolResults); void toolExecutionComplete(const QString &requestId, const QHash<QString, QString> &toolResults);