fix: truncate context logic

This commit is contained in:
2026-09-30 15:01:28 +02:00
parent a59e4286ad
commit 5fc6fda804
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;
};