forked from bai/curriculum-project-hub
feat: improve outbound message chunking with code-block-aware splitting
- Increase max message length from 4000 to 8000 chars - Add splitAtBoundary: paragraph > newline > space priority, never split inside fenced code blocks (move split to before opening fence) - Add sendLongText: sends multi-chunk long messages sequentially - Update PatchableTextStream.flush to use splitAtBoundary - Add unit tests (6) for splitting edge cases
This commit is contained in:
@@ -2,7 +2,7 @@ import { describe, expect, it, vi } from "vitest";
|
||||
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { sendFile, sendTextMessage, type FeishuRuntime } from "../../src/feishu/client.js";
|
||||
import { sendFile, sendLongText, sendTextMessage, type FeishuRuntime } from "../../src/feishu/client.js";
|
||||
|
||||
describe("Feishu client helpers", () => {
|
||||
it("accepts top-level file_key from the Lark SDK file upload response", async () => {
|
||||
@@ -32,6 +32,21 @@ describe("Feishu client helpers", () => {
|
||||
|
||||
await expect(sendTextMessage(rt, "chat-1", "hello")).resolves.toBe("message-1");
|
||||
});
|
||||
|
||||
it("sends long text in chunks and returns the last successful message id", async () => {
|
||||
let messageNumber = 0;
|
||||
const messageCreate = vi.fn(async () => ({ data: { message_id: `message-${++messageNumber}` } }));
|
||||
const rt = mockRuntime({ fileCreate: vi.fn(), messageCreate });
|
||||
|
||||
await expect(sendLongText(rt, "chat-1", "x".repeat(16_005))).resolves.toBe("message-3");
|
||||
|
||||
expect(messageCreate).toHaveBeenCalledTimes(3);
|
||||
const sentTexts = messageCreate.mock.calls.map(([payload]) => {
|
||||
const content = (payload as { data: { content: string } }).data.content;
|
||||
return (JSON.parse(content) as { text: string }).text;
|
||||
});
|
||||
expect(sentTexts.map((text) => text.length)).toEqual([8000, 8000, 5]);
|
||||
});
|
||||
});
|
||||
|
||||
function mockRuntime(options: {
|
||||
|
||||
Reference in New Issue
Block a user