Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(telegram): 避免缺失字段耗尽富文本节点预算

Dash7af638aae716
diff --git a/packages/lizi-im/src/telegram/__tests__/inbound.test.ts b/packages/lizi-im/src/telegram/__tests__/inbound.test.ts
index f7aef6081e..c2a8f1a105 100644
--- a/packages/lizi-im/src/telegram/__tests__/inbound.test.ts
+++ b/packages/lizi-im/src/telegram/__tests__/inbound.test.ts
@@ -228,6 +228,16 @@ describe('replyContextOf', () => {
expect(replyContextOf(m)).toBeNull();
});
+ it('keeps all 500 short paragraphs without charging absent fields to the node budget', () => {
+ const lines = Array.from({ length: 500 }, (_, i) => `段落 ${i}`);
+ const rich = msg({
+ text: undefined,
+ rich_message: { blocks: lines.map((text) => ({ type: 'paragraph', text })) },
+ });
+ expect(replyContextOf(msg({ reply_to_message: rich }))?.text).toBe(lines.join('\n'));
+ expect(groupWindowEntryOf(rich).text).toBe(lines.join('\n'));
+ });
+
it('reports unreadable rich references and bounds deeply nested or long content', () => {
const rich = msg({
text: undefined,
diff --git a/packages/lizi-im/src/telegram/messageText.ts b/packages/lizi-im/src/telegram/messageText.ts
index 3163547d65..628e8df252 100644
--- a/packages/lizi-im/src/telegram/messageText.ts
+++ b/packages/lizi-im/src/telegram/messageText.ts
@@ -16,6 +16,8 @@ export function telegramMessageText(message: TelegramTextContent): string {
let remaining = MAX_TEXT;
let nodes = 2048;
function visit(value: unknown, depth = 0, separator = '', childSeparator = ''): string {
+ // Missing optional fields are not nodes in the incoming document.
+ if (value === undefined || value === null) return '';
if (depth > 20 || --nodes < 0 || remaining <= 0) return '';
if (typeof value === 'string') {
const text = value.slice(0, remaining);