feat: configurable outbound text chunk limits

This commit is contained in:
Peter Steinberger
2026-01-03 01:07:23 +01:00
parent 2d28fa34f5
commit 5684e2d658
12 changed files with 154 additions and 27 deletions

View File

@@ -1,4 +1,4 @@
import { chunkText } from "../auto-reply/chunk.js";
import { chunkText, resolveTextChunkLimit } from "../auto-reply/chunk.js";
import { formatAgentEnvelope } from "../auto-reply/envelope.js";
import { getReplyFromConfig } from "../auto-reply/reply.js";
import type { ReplyPayload } from "../auto-reply/types.js";
@@ -111,15 +111,16 @@ async function deliverReplies(params: {
client: Awaited<ReturnType<typeof createIMessageRpcClient>>;
runtime: RuntimeEnv;
maxBytes: number;
textLimit: number;
}) {
const { replies, target, client, runtime, maxBytes } = params;
const { replies, target, client, runtime, maxBytes, textLimit } = params;
for (const payload of replies) {
const mediaList =
payload.mediaUrls ?? (payload.mediaUrl ? [payload.mediaUrl] : []);
const text = payload.text ?? "";
if (!text && mediaList.length === 0) continue;
if (mediaList.length === 0) {
for (const chunk of chunkText(text, 4000)) {
for (const chunk of chunkText(text, textLimit)) {
await sendMessageIMessage(target, chunk, { maxBytes, client });
}
} else {
@@ -143,6 +144,7 @@ export async function monitorIMessageProvider(
): Promise<void> {
const runtime = resolveRuntime(opts);
const cfg = loadConfig();
const textLimit = resolveTextChunkLimit(cfg, "imessage");
const allowFrom = resolveAllowFrom(opts);
const mentionRegexes = resolveMentionRegexes(cfg);
const includeAttachments =
@@ -274,6 +276,7 @@ export async function monitorIMessageProvider(
client,
runtime,
maxBytes: mediaMaxBytes,
textLimit,
});
})
.catch((err) => {
@@ -302,6 +305,7 @@ export async function monitorIMessageProvider(
client,
runtime,
maxBytes: mediaMaxBytes,
textLimit,
});
};