* @brief Executes an API command and wraps its response into an {ok,result|error} envelope. */
| 664 | * @brief Executes an API command and wraps its response into an {ok,result|error} envelope. |
| 665 | */ |
| 666 | static QJsonObject runCommand(const QString& name, const QJsonObject& args = {}) |
| 667 | { |
| 668 | const auto callId = QUuid::createUuid().toString(QUuid::WithoutBraces); |
| 669 | const auto response = API::CommandRegistry::instance().execute(name, callId, args); |
| 670 | |
| 671 | QJsonObject reply; |
| 672 | reply[QStringLiteral("ok")] = response.success; |
| 673 | if (response.success) |
| 674 | reply[QStringLiteral("result")] = response.result; |
| 675 | else { |
| 676 | QJsonObject error; |
| 677 | error[QStringLiteral("code")] = response.errorCode; |
| 678 | error[QStringLiteral("message")] = response.errorMessage; |
| 679 | if (!response.errorData.isEmpty()) |
| 680 | error[QStringLiteral("data")] = response.errorData; |
| 681 | |
| 682 | reply[QStringLiteral("error")] = error; |
| 683 | } |
| 684 | return reply; |
| 685 | } |
| 686 | |
| 687 | /** |
| 688 | * @brief Builds command-specific repair hints attached to failed tool replies. |
no test coverage detected