fix: truncate webfetch content to fit context

This commit is contained in:
2026-09-30 15:01:28 +02:00
parent e700a4f96b
commit e2786a3f1e
31 changed files with 1386 additions and 135 deletions
+9 -1
View File
@@ -20,7 +20,9 @@ class WebFetchTool : public LlmTool {
static constexpr int MaxResponseBytes = 5 * 1024 * 1024;
static constexpr int DefaultTimeoutSeconds = 30;
static constexpr int MaxTimeoutSeconds = 120;
static constexpr int MaxOutputChars = 64 * 1024;
// Where the full (untruncated) output of each call is stored so the
// model can page through it with the readfile tool.
static const QString StoragePath;
explicit WebFetchTool(QObject* parent = nullptr);
~WebFetchTool() override;
@@ -29,6 +31,7 @@ class WebFetchTool : public LlmTool {
QString description() const override;
QJsonObject parameters() const override;
void execute(
const QString& toolCallId,
const QJsonObject& args,
std::function<void(const QJsonObject& result)> done) override;
void cancel() override;
@@ -43,10 +46,15 @@ class WebFetchTool : public LlmTool {
QByteArray body;
bool tooLarge = false;
QString format;
QString toolCallId;
std::function<void(const QJsonObject& result)> done;
};
void completeJob(Job* job, QJsonObject result);
// Writes the full output to StoragePath; returns the file path, or an
// empty string when saving failed.
QString saveToFile(const Job& job, const QString& content,
const QString& mime) const;
QNetworkAccessManager m_manager;
QList<Job*> m_jobs;