* @brief Updates the status (and optional result) of an existing ToolCallCard. */
| 1767 | * @brief Updates the status (and optional result) of an existing ToolCallCard. |
| 1768 | */ |
| 1769 | void AI::Conversation::updateToolCallCard(const QString& callId, |
| 1770 | CallStatus status, |
| 1771 | const QJsonObject& result) |
| 1772 | { |
| 1773 | for (int i = m_uiMessages.size() - 1; i >= 0; --i) { |
| 1774 | auto map = m_uiMessages.at(i).toMap(); |
| 1775 | auto calls = map.value(QStringLiteral("toolCalls")).toList(); |
| 1776 | bool changed = false; |
| 1777 | for (int c = 0; c < calls.size(); ++c) { |
| 1778 | auto card = calls.at(c).toMap(); |
| 1779 | if (card.value(QStringLiteral("callId")).toString() != callId) |
| 1780 | continue; |
| 1781 | |
| 1782 | card.insert(QStringLiteral("status"), static_cast<int>(status)); |
| 1783 | if (!result.isEmpty()) |
| 1784 | card.insert(QStringLiteral("result"), |
| 1785 | QString::fromUtf8(QJsonDocument(result).toJson(QJsonDocument::Indented))); |
| 1786 | |
| 1787 | calls[c] = card; |
| 1788 | changed = true; |
| 1789 | break; |
| 1790 | } |
| 1791 | if (changed) { |
| 1792 | map.insert(QStringLiteral("toolCalls"), calls); |
| 1793 | m_uiMessages[i] = map; |
| 1794 | Q_EMIT messagesChanged(); |
| 1795 | return; |
| 1796 | } |
| 1797 | } |
| 1798 | } |
| 1799 | |
| 1800 | /** |
| 1801 | * @brief Executes a single tool call and feeds its result back. |