refactor: Finalize agent template

This commit is contained in:
Petr Mironychev
2026-06-03 17:28:50 +02:00
parent 98a618cf87
commit c151c5030b
57 changed files with 1737 additions and 393 deletions

View File

@@ -7,6 +7,7 @@
#include <memory>
#include <mutex>
#include <optional>
#include <vector>
#include <QJsonObject>
#include <QString>
@@ -50,27 +51,30 @@ public:
const ContextData &context,
bool thinkingEnabled = false) const override;
const QJsonObject &sampling() const { return m_sampling; }
private:
JsonPromptTemplate() = default;
std::optional<QJsonObject> renderBody(const ContextData &context) const;
void applySampling(QJsonObject &request, bool thinkingEnabled) const;
QString m_name;
QString m_description;
// The literal request body, as a deep-mergeable object. String values
// that contain jinja are rendered and spliced as JSON at request time;
// literal strings and scalars pass through unchanged.
QJsonObject m_body;
// Roots searched (in order) by the `{% include %}` resolver. The first
// is the bundled qrc partials prefix; an optional second is the user
// agent's own directory, so user profiles can ship their own partials.
std::vector<QString> m_partialRoots;
// m_env is populated once in fromConfig() and never mutated again.
// It is `mutable` only because inja::Environment::render() is not a
// const member; m_renderMutex serialises those render() calls since
// inja's render path is not internally re-entrant on one Environment.
mutable inja::Environment m_env;
inja::Template m_template;
mutable std::mutex m_renderMutex;
QJsonObject m_sampling;
QJsonObject m_thinking;
};
} // namespace QodeAssist::Templates