* @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. */
| 1844 | * the model narrows the call instead of retrying it verbatim. |
| 1845 | */ |
| 1846 | static 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. |
no test coverage detected