Skip to content

Commit 7963477

Browse files
authored
fix(qqofficial): send complete stream snapshots (#2458)
1 parent bb36677 commit 7963477

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

src/langbot/pkg/platform/sources/qqofficial.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -650,13 +650,13 @@ async def reply_message_chunk(
650650
# 用第一个 chunk 的文本建立会话(不发 "..." 避免污染前缀)
651651
ctx['session_started'] = True
652652

653-
# 发送内容 = 全量累积文本
654-
# QQ API 的 replace 模式不允许修改已下发前缀,所以:
655-
# - 首次:发送全部文本,建立会话
656-
# - 后续:只能发送新增部分(append 行为)
657-
content_to_send = ctx['accumulated_text'][ctx['sent_length'] :]
658-
if not content_to_send and not is_final:
653+
# `replace` mode requires every update to contain the previously
654+
# delivered content as its prefix. `sent_length` only tells us whether
655+
# a non-final snapshot has new content; it must not truncate the
656+
# content sent to QQ.
657+
if len(ctx['accumulated_text']) <= ctx['sent_length'] and not is_final:
659658
return
659+
content_to_send = ctx['accumulated_text']
660660

661661
input_state = 10 if is_final else 1
662662

tests/unit_tests/platform/test_qqofficial_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def _stream_test_adapter():
108108

109109

110110
@pytest.mark.asyncio
111-
async def test_qq_stream_uses_cumulative_chunks_as_snapshots():
111+
async def test_qq_stream_replace_mode_sends_complete_snapshots():
112112
adapter = _stream_test_adapter()
113113
adapter._stream_ctx['message-1'] = {
114114
'user_openid': 'user-1',
@@ -138,7 +138,7 @@ async def test_qq_stream_uses_cumulative_chunks_as_snapshots():
138138

139139
assert [call.kwargs['content'] for call in adapter.bot.send_stream_msg.await_args_list] == [
140140
'<think>one',
141-
' two',
141+
'<think>one two',
142142
]
143143

144144

0 commit comments

Comments
 (0)