From 6a4144f5372f19cb48a0963e00f8ddec020806cd Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 15 Feb 2026 18:55:01 +0000 Subject: [PATCH] refactor(auto-reply): dedupe chunk early returns --- src/auto-reply/chunk.ts | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/auto-reply/chunk.ts b/src/auto-reply/chunk.ts index 204f88ad39..e91b9e8683 100644 --- a/src/auto-reply/chunk.ts +++ b/src/auto-reply/chunk.ts @@ -298,7 +298,7 @@ function splitByNewline( return lines; } -export function chunkText(text: string, limit: number): string[] { +function resolveChunkEarlyReturn(text: string, limit: number): string[] | undefined { if (!text) { return []; } @@ -308,6 +308,14 @@ export function chunkText(text: string, limit: number): string[] { if (text.length <= limit) { return [text]; } + return undefined; +} + +export function chunkText(text: string, limit: number): string[] { + const early = resolveChunkEarlyReturn(text, limit); + if (early) { + return early; + } const chunks: string[] = []; let remaining = text; @@ -346,14 +354,9 @@ export function chunkText(text: string, limit: number): string[] { } export function chunkMarkdownText(text: string, limit: number): string[] { - if (!text) { - return []; - } - if (limit <= 0) { - return [text]; - } - if (text.length <= limit) { - return [text]; + const early = resolveChunkEarlyReturn(text, limit); + if (early) { + return early; } const chunks: string[] = [];