fix: truncate context logic
C++ / fmt (pull_request) Successful in 4s
C++ / build (pull_request) Failing after 2m6s
C++ / clang-tidy (pull_request) Failing after 2m5s
JS/TS / fmt (pull_request) Failing after 3m8s
Python / static (pull_request) Successful in 24s
Python / verify (pull_request) Successful in 1m21s
JS/TS / lint (pull_request) Successful in 5m10s
Rust / fmt (pull_request) Successful in 30s
Rust / build (pull_request) Successful in 56s
Rust / clippy (pull_request) Successful in 46s

This commit is contained in:
2026-09-04 02:20:37 +02:00
parent 34dde4bbfb
commit cd3da1941b
15 changed files with 238 additions and 126 deletions
+5 -8
View File
@@ -10,6 +10,7 @@
#include <QPointer>
#include <QString>
#include <QStringList>
#include <QTimer>
#include <functional>
@@ -42,7 +43,8 @@ class LlmClient : public QObject {
void setModel(const QString& value);
void setTemperature(double value);
void setContextSize(int size);
void probeContextSize();
void probeContextSize(std::function<void()> done = {});
Q_INVOKABLE void refreshFromServer();
[[nodiscard]] bool busy() const { return m_busy; }
[[nodiscard]] bool toolsEnabled() const { return m_tools->enabled(); }
@@ -56,10 +58,6 @@ class LlmClient : public QObject {
void clearOnFinish(ChatSession* session);
void sessionRemoved(ChatSession* session);
// Tool calls are executed only after the user approves the batch the
// model requested. The per-generation state (toolApprovalPending,
// pendingToolCalls) is mirrored onto ChatGeneration; these are the
// entry points QML reaches through it.
void approveTools();
void denyTools();
@@ -118,9 +116,7 @@ class LlmClient : public QObject {
ToolRegistry* m_tools = nullptr;
QNetworkReply* m_reply = nullptr;
QByteArray m_buffer;
// QPointer: these objects are owned by the ChatStore tree, which Qt
// destroys *before* this client on shutdown (children die in creation
// order). The pointers must self-null instead of dangling.
QTimer m_refreshTimer;
QPointer<ChatSession> m_active;
QPointer<ChatGeneration> m_streaming;
QPointer<ChatSession> m_pendingClear;
@@ -146,6 +142,7 @@ class LlmClient : public QObject {
bool m_roundDone = false;
bool m_toolPhase = false;
bool m_approvalPending = false;
bool m_contextRetryUsed = false;
int m_pendingCalls = 0;
static constexpr int kMaxToolRounds = 12;
};