refactor(auto-reply): dedupe chunk early returns

This commit is contained in:
Peter Steinberger
2026-02-15 18:55:01 +00:00
parent 9a5e617a55
commit 6a4144f537

View File

@@ -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[] = [];