fix(channels): drop compaction notices on channels without an in-place affordance (#5799)
* fix(channels): drop compaction notices on channels without an in-place affordance QQ's C2C/group message API has no edit or recall endpoint, so the compaction lifecycle reached the chat as two permanent standalone messages. Add a show_compaction_notices capability that defaults to true (Telegram/Discord/WebSocket keep their in-place lifecycle) and opt QQ out, with a per-channel showCompactionNotices config override. Fixes #5784 * fix(qq): keep compaction-notice suppression inside the QQ channel Per review on #5799: drop ContextCompactionEvent in QQChannel.send() based on a QQ-local QQConfig.show_compaction_notices (default false, camel alias showCompactionNotices) instead of a cross-channel BaseChannel capability plus manager-level configuration and dispatch policy. BaseChannel, ChannelManager and the manager compaction test return to their upstream shape. Also adds the missing zh-TW locale copy (plus es/id/ko/vi so all ten QQ locales carry the new setup field) and QQ-level tests covering the default drop, the enabled path, ordinary-message passthrough, and the camelCase config override.
This commit is contained in:
1 parent
a0a99f24da
commit
24c41a6af0
14 files changed
+173
No files matched your search
@@ -1654,6 +1654,18 @@ Normal tool workspace and media access rules still apply to attachment paths.
|
||||
}
|
||||
```
|
||||
|
||||
QQ `showCompactionNotices` defaults to `false`. It controls the context-compaction lifecycle notices ("Compressing context…" / "Context compacted."). Telegram, Discord and WebSocket present that lifecycle as one in-place-updated message or status, but QQ's C2C/group message API has no edit or recall endpoint, so each phase would land as a separate permanent message; the QQ channel therefore drops the notices by default (#5784). Set `channels.qq.showCompactionNotices: true` to post them anyway:
|
||||
|
||||
```json
|
||||
{
|
||||
"channels": {
|
||||
"qq": {
|
||||
"showCompactionNotices": true
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Telegram `richMessages` defaults to `false`. Enable it only to opt in to Bot API 10.1 `sendRichMessage` rendering; leave it disabled for Telegram Web clients that show unsupported-message errors for rich messages.
|
||||
|
||||
### Retry Behavior
|
||||
|
||||
@@ -11,6 +11,7 @@ SETUP_SPEC = ChannelSetupSpec(
|
||||
"allowFrom": field("list"),
|
||||
"msgFormat": field("enum", choices={"plain", "markdown"}, default="plain"),
|
||||
"ackMessage": field(default="⏳ Processing..."),
|
||||
"showCompactionNotices": field("bool", default=False),
|
||||
"mediaDir": field(),
|
||||
"downloadChunkSize": field("int", default=1024 * 256),
|
||||
"downloadMaxBytes": field("int", default=1024 * 1024 * 200),
|
||||
|
||||
@@ -37,6 +37,7 @@ from loguru import logger
|
||||
from pydantic import Field
|
||||
|
||||
from nanobot.bus.events import OutboundMessage
|
||||
from nanobot.bus.outbound_events import ContextCompactionEvent
|
||||
from nanobot.bus.queue import MessageBus
|
||||
from nanobot.channels.base import BaseChannel
|
||||
from nanobot.config.schema import Base
|
||||
@@ -192,6 +193,11 @@ class QQConfig(Base):
|
||||
download_chunk_size: int = 1024 * 256 # 256KB
|
||||
download_max_bytes: int = 1024 * 1024 * 200 # 200MB safety limit
|
||||
|
||||
# QQ's C2C/group message API has no edit or recall endpoint, so compaction
|
||||
# notices would land as separate permanent messages (#5784). Off by default;
|
||||
# set showCompactionNotices: true to post them anyway.
|
||||
show_compaction_notices: bool = False
|
||||
|
||||
|
||||
class QQChannel(BaseChannel):
|
||||
"""QQ channel using botpy SDK with WebSocket connection."""
|
||||
@@ -298,6 +304,17 @@ class QQChannel(BaseChannel):
|
||||
|
||||
async def send(self, msg: OutboundMessage) -> None:
|
||||
"""Send attachments first, then text."""
|
||||
# Compaction notices assume the channel can update one message in place
|
||||
# (Telegram/Discord edit their notice; WebSocket projects it as status).
|
||||
# QQ's C2C/group API has no edit or recall endpoint, so by default the
|
||||
# lifecycle is dropped here instead of posting two permanent messages
|
||||
# (#5784); showCompactionNotices: true restores them.
|
||||
if (
|
||||
isinstance(msg.event, ContextCompactionEvent)
|
||||
and not self.config.show_compaction_notices
|
||||
):
|
||||
return
|
||||
|
||||
try:
|
||||
if not self._client:
|
||||
raise RuntimeError("QQ client not initialized")
|
||||
|
||||
@@ -33,6 +33,13 @@
|
||||
},
|
||||
"downloadMaxBytes": {
|
||||
"label": "Maximum download size"
|
||||
},
|
||||
"showCompactionNotices": {
|
||||
"label": "Compaction notices",
|
||||
"choices": {
|
||||
"true": "On",
|
||||
"false": "Off"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,13 @@
|
||||
},
|
||||
"downloadMaxBytes": {
|
||||
"label": "Tamaño máximo de descarga"
|
||||
},
|
||||
"showCompactionNotices": {
|
||||
"label": "Avisos de compactación de contexto",
|
||||
"choices": {
|
||||
"true": "Activado",
|
||||
"false": "Desactivado"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,13 @@
|
||||
},
|
||||
"downloadMaxBytes": {
|
||||
"label": "Taille maximale de téléchargement"
|
||||
},
|
||||
"showCompactionNotices": {
|
||||
"label": "Avis de compactage du contexte",
|
||||
"choices": {
|
||||
"true": "Activé",
|
||||
"false": "Désactivé"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,13 @@
|
||||
},
|
||||
"downloadMaxBytes": {
|
||||
"label": "Ukuran unduhan maksimum"
|
||||
},
|
||||
"showCompactionNotices": {
|
||||
"label": "Notifikasi pemadatan konteks",
|
||||
"choices": {
|
||||
"true": "Aktif",
|
||||
"false": "Nonaktif"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,13 @@
|
||||
},
|
||||
"downloadMaxBytes": {
|
||||
"label": "最大ダウンロードサイズ"
|
||||
},
|
||||
"showCompactionNotices": {
|
||||
"label": "コンテキスト圧縮通知",
|
||||
"choices": {
|
||||
"true": "オン",
|
||||
"false": "オフ"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,13 @@
|
||||
},
|
||||
"downloadMaxBytes": {
|
||||
"label": "최대 다운로드 크기"
|
||||
},
|
||||
"showCompactionNotices": {
|
||||
"label": "컨텍스트 압축 알림",
|
||||
"choices": {
|
||||
"true": "켜기",
|
||||
"false": "끄기"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,13 @@
|
||||
},
|
||||
"downloadMaxBytes": {
|
||||
"label": "Tamanho máximo de download"
|
||||
},
|
||||
"showCompactionNotices": {
|
||||
"label": "Avisos de compactação de contexto",
|
||||
"choices": {
|
||||
"true": "Ativado",
|
||||
"false": "Desativado"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,13 @@
|
||||
},
|
||||
"downloadMaxBytes": {
|
||||
"label": "Kích thước tải xuống tối đa"
|
||||
},
|
||||
"showCompactionNotices": {
|
||||
"label": "Thông báo nén ngữ cảnh",
|
||||
"choices": {
|
||||
"true": "Bật",
|
||||
"false": "Tắt"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,13 @@
|
||||
},
|
||||
"downloadMaxBytes": {
|
||||
"label": "下载大小上限"
|
||||
},
|
||||
"showCompactionNotices": {
|
||||
"label": "上下文压缩通知",
|
||||
"choices": {
|
||||
"true": "开",
|
||||
"false": "关"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,13 @@
|
||||
},
|
||||
"downloadMaxBytes": {
|
||||
"label": "下載大小上限"
|
||||
},
|
||||
"showCompactionNotices": {
|
||||
"label": "上下文壓縮通知",
|
||||
"choices": {
|
||||
"true": "開",
|
||||
"false": "關"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
"""QQ drops compaction notices it cannot present as one message.
|
||||
|
||||
QQ's C2C/group message API has no edit or recall endpoint, so the
|
||||
compaction lifecycle would land as two separate permanent messages. The
|
||||
channel drops ``ContextCompactionEvent`` by default; ``showCompactionNotices:
|
||||
true`` restores the notices for anyone who wants them (#5784).
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
import pytest
|
||||
|
||||
pytest.importorskip("botpy")
|
||||
|
||||
from nanobot.bus.events import OutboundMessage
|
||||
from nanobot.bus.outbound_events import ContextCompactionEvent, outbound_message_for_event
|
||||
from nanobot.bus.queue import MessageBus
|
||||
from nanobot.channels.qq.runtime import QQChannel, QQConfig
|
||||
|
||||
|
||||
def _make_channel(**config_kwargs) -> QQChannel:
|
||||
config = QQConfig(app_id="test_app", secret="test_secret", **config_kwargs)
|
||||
channel = QQChannel(config, MessageBus())
|
||||
channel._client = object() # truthy: pass the initialized check
|
||||
return channel
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_compaction_notices_dropped_by_default(monkeypatch) -> None:
|
||||
channel = _make_channel()
|
||||
send_text = AsyncMock()
|
||||
monkeypatch.setattr(channel, "_send_text_only", send_text)
|
||||
|
||||
for phase in ("started", "succeeded"):
|
||||
await channel.send(outbound_message_for_event(
|
||||
channel="qq", chat_id="chat",
|
||||
event=ContextCompactionEvent(compaction_id="c1", phase=phase),
|
||||
))
|
||||
|
||||
send_text.assert_not_awaited()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_compaction_notices_sent_when_enabled(monkeypatch) -> None:
|
||||
channel = _make_channel(show_compaction_notices=True)
|
||||
send_text = AsyncMock()
|
||||
monkeypatch.setattr(channel, "_send_text_only", send_text)
|
||||
|
||||
await channel.send(outbound_message_for_event(
|
||||
channel="qq", chat_id="chat",
|
||||
event=ContextCompactionEvent(compaction_id="c1", phase="started"),
|
||||
))
|
||||
|
||||
send_text.assert_awaited_once()
|
||||
assert send_text.await_args.kwargs["content"] == "Compressing context…"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_ordinary_messages_unaffected(monkeypatch) -> None:
|
||||
channel = _make_channel()
|
||||
send_text = AsyncMock()
|
||||
monkeypatch.setattr(channel, "_send_text_only", send_text)
|
||||
|
||||
await channel.send(OutboundMessage(channel="qq", chat_id="chat", content="hello"))
|
||||
|
||||
send_text.assert_awaited_once()
|
||||
|
||||
|
||||
def test_config_accepts_camel_case_override() -> None:
|
||||
config = QQConfig.model_validate({"appId": "a", "secret": "s", "showCompactionNotices": True})
|
||||
assert config.show_compaction_notices is True
|
||||
Reference in new issue
Block a user