mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2026-07-23 11:41:03 -04:00
* refactor: Migrate tests to Qt Creator plugin framework and update llmqore transports * refactor: Move conversation history into IDE-free session library * refactor: Extract turn context assembly behind injected ports * build: Add RunQodeAssistTests target for the plugin test suite * refactor: Route the chat through a Session and ChatBackend seam
73 lines
1.6 KiB
C++
73 lines
1.6 KiB
C++
// Copyright (C) 2024-2026 Petr Mironychev
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
// Additional attribution terms under GPLv3 §7(b) apply — see LICENSE
|
|
|
|
#pragma once
|
|
|
|
#include <QDateTime>
|
|
#include <QHash>
|
|
#include <QObject>
|
|
#include <QPointer>
|
|
#include <QStringList>
|
|
#include <QTimer>
|
|
|
|
namespace QodeAssist::Context {
|
|
class ContextManager;
|
|
}
|
|
|
|
namespace QodeAssist::Session {
|
|
class Session;
|
|
}
|
|
|
|
namespace QodeAssist::Chat {
|
|
|
|
class InputTokenCounter : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
InputTokenCounter(
|
|
Session::Session *session,
|
|
Context::ContextManager *contextManager,
|
|
QObject *parent = nullptr);
|
|
|
|
int inputTokens() const;
|
|
|
|
void setMessage(const QString &message);
|
|
void setAttachments(const QStringList &attachments);
|
|
void setLinkedFiles(const QStringList &linkedFiles);
|
|
void recompute();
|
|
void recomputeSoon();
|
|
|
|
void recordSent();
|
|
void recordServerUsage(int promptTokens);
|
|
|
|
signals:
|
|
void inputTokensChanged();
|
|
|
|
private:
|
|
struct CachedFileTokens
|
|
{
|
|
QDateTime modified;
|
|
int tokens = 0;
|
|
};
|
|
|
|
void rewireToolsChangedConnection();
|
|
int estimateFileTokens(const QStringList &paths);
|
|
|
|
QPointer<Session::Session> m_session;
|
|
Context::ContextManager *m_contextManager;
|
|
QMetaObject::Connection m_toolsChangedConn;
|
|
QTimer m_recomputeTimer;
|
|
QHash<QString, CachedFileTokens> m_fileTokens;
|
|
|
|
QStringList m_attachments;
|
|
QStringList m_linkedFiles;
|
|
int m_messageTokens{0};
|
|
int m_inputTokens{0};
|
|
int m_lastSentEstimate{0};
|
|
double m_calibrationFactor{1.0};
|
|
};
|
|
|
|
} // namespace QodeAssist::Chat
|