Hide context blocks in KDE chat

This commit is contained in:
Ollie Agent 2026-08-20 17:34:53 +02:00
parent 07dcd60d19
commit bb6df3a073
2 changed files with 16 additions and 0 deletions

View File

@ -232,6 +232,7 @@ void ChatBlockModel::reset()
beginResetModel();
m_blocks.clear();
m_lineBuffer.clear();
m_inContext = false;
m_state = State::BlockStart;
m_inCodeFence = false;
m_fenceLanguage.clear();
@ -680,6 +681,18 @@ void ChatBlockModel::processLine(const QString &line)
}
case State::BlockEnd:
// Hide prompt context blocks from the rendered chat, matching olliesrv.
if (line.trimmed() == QStringLiteral("<context>")) {
m_inContext = true;
return;
}
if (line.trimmed() == QStringLiteral("</context>")) {
m_inContext = false;
return;
}
if (m_inContext)
return;
// [[[end]]] closes the current block
if (s_endRe.match(line).hasMatch()) {
// Emit final update so QML picks up the completed segment state.

View File

@ -134,6 +134,9 @@ private:
QList<ChatBlock> m_blocks;
QString m_lineBuffer;
// Context blocks are injected into prompts but hidden from chat rendering.
bool m_inContext = false;
// Code fence state (for streaming)
bool m_inCodeFence = false;
QString m_fenceLanguage;