fix(discord): preserve fast-path chunk settings

This commit is contained in:
Rai Butera
2026-03-09 14:40:32 +00:00
committed by Altay
parent 8fd27ff54c
commit 107935dc51
2 changed files with 38 additions and 1 deletions

View File

@@ -256,6 +256,26 @@ describe("deliverDiscordReply", () => {
expect(sendDiscordTextMock.mock.calls[1]?.[1]).toBe("789");
});
it("passes maxLinesPerMessage and chunkMode through the fast path", async () => {
const fakeRest = {} as import("@buape/carbon").RequestClient;
await deliverDiscordReply({
replies: [{ text: Array.from({ length: 18 }, (_, index) => `line ${index + 1}`).join("\n") }],
target: "channel:789",
token: "token",
rest: fakeRest,
runtime,
textLimit: 2000,
maxLinesPerMessage: 120,
chunkMode: "newline",
});
expect(sendMessageDiscordMock).not.toHaveBeenCalled();
expect(sendDiscordTextMock).toHaveBeenCalledTimes(1);
expect(sendDiscordTextMock.mock.calls[0]?.[5]).toBe(120);
expect(sendDiscordTextMock.mock.calls[0]?.[8]).toBe("newline");
});
it("falls back to sendMessageDiscord when rest is not provided", async () => {
await deliverDiscordReply({
replies: [{ text: "single chunk" }],

View File

@@ -130,9 +130,11 @@ async function sendDiscordChunkWithFallback(params: {
text: string;
token: string;
accountId?: string;
maxLinesPerMessage?: number;
rest?: RequestClient;
replyTo?: string;
binding?: DiscordThreadBindingLookupRecord;
chunkMode?: ChunkMode;
username?: string;
avatarUrl?: string;
/** Pre-resolved channel ID to bypass redundant resolution per chunk. */
@@ -169,7 +171,18 @@ async function sendDiscordChunkWithFallback(params: {
if (params.channelId && params.request && params.rest) {
const { channelId, request, rest } = params;
await sendWithRetry(
() => sendDiscordText(rest, channelId, text, params.replyTo, request),
() =>
sendDiscordText(
rest,
channelId,
text,
params.replyTo,
request,
params.maxLinesPerMessage,
undefined,
undefined,
params.chunkMode,
),
params.retryConfig,
);
return;
@@ -294,8 +307,10 @@ export async function deliverDiscordReply(params: {
token: params.token,
rest: params.rest,
accountId: params.accountId,
maxLinesPerMessage: params.maxLinesPerMessage,
replyTo,
binding,
chunkMode: params.chunkMode,
username: persona.username,
avatarUrl: persona.avatarUrl,
channelId,
@@ -329,8 +344,10 @@ export async function deliverDiscordReply(params: {
token: params.token,
rest: params.rest,
accountId: params.accountId,
maxLinesPerMessage: params.maxLinesPerMessage,
replyTo: resolveReplyTo(),
binding,
chunkMode: params.chunkMode,
username: persona.username,
avatarUrl: persona.avatarUrl,
channelId,