// Copyright (C) 2025-2026 Petr Mironychev // SPDX-License-Identifier: GPL-3.0-or-later #pragma once #include namespace QodeAssist::Providers { class OllamaMessage : public QObject { Q_OBJECT public: explicit OllamaMessage(QObject *parent = nullptr); void handleContentDelta(const QString &content); void handleToolCall(const QJsonObject &toolCall); void handleThinkingDelta(const QString &thinking); void handleThinkingComplete(const QString &signature); void handleDone(bool done); QJsonObject toProviderFormat() const; QJsonArray createToolResultMessages(const QHash &toolResults) const; PluginLLMCore::MessageState state() const { return m_state; } QList getCurrentToolUseContent() const; QList getCurrentThinkingContent() const; QList currentBlocks() const { return m_currentBlocks; } void startNewContinuation(); private: bool m_done = false; PluginLLMCore::MessageState m_state = PluginLLMCore::MessageState::Building; QList m_currentBlocks; QString m_accumulatedContent; bool m_contentAddedToTextBlock = false; PluginLLMCore::ThinkingContent *m_currentThinkingContent = nullptr; void updateStateFromDone(); bool tryParseToolCall(); bool isLikelyToolCallJson(const QString &content) const; PluginLLMCore::TextContent *getOrCreateTextContent(); PluginLLMCore::ThinkingContent *getOrCreateThinkingContent(); template T *addCurrentContent(Args &&...args) { T *content = new T(std::forward(args)...); content->setParent(this); m_currentBlocks.append(content); return content; } }; } // namespace QodeAssist::Providers