MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / fetchHelpIndex

Method fetchHelpIndex

app/src/AI/Conversation.cpp:1625–1676  ·  view source on GitHub ↗

* @brief Fetches help.json so a guessed page-name 404 can be self-corrected. */

Source from the content-addressed store, hash-verified

1623 * @brief Fetches help.json so a guessed page-name 404 can be self-corrected.
1624 */
1625void AI::Conversation::fetchHelpIndex(const QString& callId, const QUrl& missedUrl)
1626{
1627 static const QUrl kIndexUrl(
1628 QStringLiteral("https://raw.githubusercontent.com/Serial-Studio/Serial-Studio/"
1629 "master/doc/help/help.json"));
1630
1631 qCDebug(serialStudioAI) << "meta.fetchHelp redirect-to-index after 404:" << missedUrl.toString();
1632
1633 QNetworkRequest req(kIndexUrl);
1634 req.setRawHeader("User-Agent", "SerialStudio-AIAssistant");
1635 req.setRawHeader("Accept", "application/json");
1636 req.setTransferTimeout(15 * 1000);
1637 auto* reply = m_helpFetchNam.get(req);
1638
1639 connect(reply, &QNetworkReply::finished, this, [this, callId, reply, missedUrl]() {
1640 QJsonObject result;
1641 result[QStringLiteral("url")] = missedUrl.toString();
1642 result[QStringLiteral("redirected")] = true;
1643
1644 if (reply->error() != QNetworkReply::NoError) {
1645 result[QStringLiteral("ok")] = false;
1646 result[QStringLiteral("error")] =
1647 QStringLiteral("404 on '%1', and the help index also failed: %2")
1648 .arg(missedUrl.toString(), reply->errorString());
1649 } else {
1650 const auto bytes = reply->readAll();
1651 result[QStringLiteral("ok")] = true;
1652 result[QStringLiteral("note")] =
1653 QStringLiteral("The page '%1' does not exist. Below is the full "
1654 "help index (help.json). Each entry has an `id` "
1655 "and a `file` -- pass the file name (without the "
1656 ".md extension and with hyphens preserved) to "
1657 "meta.fetchHelp on the next call. Common "
1658 "mistakes: pass 'Painter-Widget' not 'Painter', "
1659 "'API-Reference' not 'API'.")
1660 .arg(missedUrl.toString());
1661 result[QStringLiteral("content")] = QString::fromUtf8(bytes);
1662 }
1663
1664 reply->deleteLater();
1665
1666 recordToolResult(callId, QStringLiteral("meta.fetchHelp"), result);
1667 updateToolCallCard(callId,
1668 result.value(QStringLiteral("ok")).toBool() ? CallStatus::Done
1669 : CallStatus::Error,
1670 result);
1671 releaseOutstandingToolResult();
1672
1673 if (m_outstandingToolResults == 0 && m_awaitingConfirm.isEmpty() && !m_reply)
1674 resumeAfterToolBatch();
1675 });
1676}
1677
1678/**
1679 * @brief Adds a user message to both history and the UI message list.

Callers

nothing calls this directly

Calls 5

errorMethod · 0.80
errorStringMethod · 0.80
isEmptyMethod · 0.80
getMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected