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

Function makeTruncatedResult

app/src/AI/Conversation.cpp:1846–1865  ·  view source on GitHub ↗

* @brief Builds a budget-respecting replacement for an oversized tool result: keeps the * ok/error fields, flags the cut, and carries a raw-JSON preview plus guidance so * the model narrows the call instead of retrying it verbatim. */

Source from the content-addressed store, hash-verified

1844 * the model narrows the call instead of retrying it verbatim.
1845 */
1846static QJsonObject makeTruncatedResult(const QJsonObject& scrubbed,
1847 const QByteArray& fullBytes,
1848 int budgetBytes)
1849{
1850 QJsonObject out;
1851 if (scrubbed.contains(QStringLiteral("ok")))
1852 out[QStringLiteral("ok")] = scrubbed.value(QStringLiteral("ok"));
1853
1854 if (scrubbed.contains(QStringLiteral("error")))
1855 out[QStringLiteral("error")] = scrubbed.value(QStringLiteral("error"));
1856
1857 out[QStringLiteral("truncated")] = true;
1858 out[QStringLiteral("note")] =
1859 QStringLiteral("Result exceeded the %1-byte budget; 'preview' holds the first bytes of "
1860 "the full JSON. Narrow the call (offset/limit, prefix, fewer fields) "
1861 "instead of repeating it.")
1862 .arg(budgetBytes);
1863 out[QStringLiteral("preview")] = QString::fromUtf8(fullBytes.left(budgetBytes - 512));
1864 return out;
1865}
1866
1867/**
1868 * @brief Stores a tool_result block to be sent back in the next request.

Callers 1

recordToolResultMethod · 0.85

Calls 2

containsMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected