fix(auto-reply): tighten block streaming defaults

This commit is contained in:
Peter Steinberger
2026-01-09 22:40:58 +01:00
parent f8bf041396
commit 79af03ba5e
13 changed files with 71 additions and 25 deletions

View File

@@ -53,6 +53,14 @@ export class EmbeddedBlockChunker {
const maxChars = Math.max(minChars, Math.floor(this.#chunking.maxChars));
if (this.#buffer.length < minChars && !force) return;
if (force && this.#buffer.length <= maxChars) {
if (this.#buffer.trim().length > 0) {
emit(this.#buffer);
}
this.#buffer = "";
return;
}
while (
this.#buffer.length >= minChars ||
(force && this.#buffer.length > 0)

View File

@@ -784,7 +784,7 @@ describe("subscribeEmbeddedPiSession", () => {
blockReplyBreak: "message_end",
blockReplyChunking: {
minChars: 5,
maxChars: 40,
maxChars: 25,
breakPreference: "paragraph",
},
});
@@ -836,7 +836,7 @@ describe("subscribeEmbeddedPiSession", () => {
blockReplyBreak: "message_end",
blockReplyChunking: {
minChars: 5,
maxChars: 50,
maxChars: 25,
breakPreference: "paragraph",
},
});
@@ -939,7 +939,7 @@ describe("subscribeEmbeddedPiSession", () => {
blockReplyBreak: "message_end",
blockReplyChunking: {
minChars: 5,
maxChars: 40,
maxChars: 25,
breakPreference: "paragraph",
},
});
@@ -986,7 +986,7 @@ describe("subscribeEmbeddedPiSession", () => {
blockReplyBreak: "message_end",
blockReplyChunking: {
minChars: 5,
maxChars: 45,
maxChars: 30,
breakPreference: "paragraph",
},
});
@@ -1035,7 +1035,7 @@ describe("subscribeEmbeddedPiSession", () => {
blockReplyBreak: "message_end",
blockReplyChunking: {
minChars: 10,
maxChars: 50,
maxChars: 30,
breakPreference: "paragraph",
},
});

View File

@@ -470,20 +470,26 @@ export async function getReplyFromConfig(
(agentCfg?.elevatedDefault as ElevatedLevel | undefined) ??
"on")
: "off";
const providerKey = sessionCtx.Provider?.trim().toLowerCase();
const explicitBlockStreamingEnable = opts?.disableBlockStreaming === false;
const resolvedBlockStreaming =
opts?.disableBlockStreaming === true
? "off"
: opts?.disableBlockStreaming === false
? "on"
: agentCfg?.blockStreamingDefault === "off"
? "off"
: "on";
: agentCfg?.blockStreamingDefault === "on"
? "on"
: "off";
const resolvedBlockStreamingBreak: "text_end" | "message_end" =
agentCfg?.blockStreamingBreak === "message_end"
? "message_end"
: "text_end";
const allowBlockStreaming =
providerKey === "telegram" || explicitBlockStreamingEnable;
const blockStreamingEnabled =
resolvedBlockStreaming === "on" && opts?.disableBlockStreaming !== true;
resolvedBlockStreaming === "on" &&
opts?.disableBlockStreaming !== true &&
allowBlockStreaming;
const blockReplyChunking = blockStreamingEnabled
? resolveBlockStreamingChunking(
cfg,

View File

@@ -5,6 +5,13 @@ import { resolveTextChunkLimit, type TextChunkProvider } from "../chunk.js";
const DEFAULT_BLOCK_STREAM_MIN = 800;
const DEFAULT_BLOCK_STREAM_MAX = 1200;
const DEFAULT_BLOCK_STREAM_COALESCE_IDLE_MS = 1000;
const PROVIDER_COALESCE_DEFAULTS: Partial<
Record<TextChunkProvider, { minChars: number; idleMs: number }>
> = {
signal: { minChars: 1500, idleMs: 1000 },
slack: { minChars: 1500, idleMs: 1000 },
discord: { minChars: 1500, idleMs: 1000 },
};
const BLOCK_CHUNK_PROVIDERS = new Set<TextChunkProvider>([
"whatsapp",
@@ -77,6 +84,9 @@ export function resolveBlockStreamingCoalescing(
const providerKey = normalizeChunkProvider(provider);
const textLimit = resolveTextChunkLimit(cfg, providerKey, accountId);
const normalizedAccountId = normalizeAccountId(accountId);
const providerDefaults = providerKey
? PROVIDER_COALESCE_DEFAULTS[providerKey]
: undefined;
const providerCfg = (() => {
if (!cfg || !providerKey) return undefined;
if (providerKey === "whatsapp") {
@@ -125,7 +135,10 @@ export function resolveBlockStreamingCoalescing(
const minRequested = Math.max(
1,
Math.floor(
coalesceCfg?.minChars ?? chunking?.minChars ?? DEFAULT_BLOCK_STREAM_MIN,
coalesceCfg?.minChars ??
providerDefaults?.minChars ??
chunking?.minChars ??
DEFAULT_BLOCK_STREAM_MIN,
),
);
const maxRequested = Math.max(
@@ -136,7 +149,11 @@ export function resolveBlockStreamingCoalescing(
const minChars = Math.min(minRequested, maxChars);
const idleMs = Math.max(
0,
Math.floor(coalesceCfg?.idleMs ?? DEFAULT_BLOCK_STREAM_COALESCE_IDLE_MS),
Math.floor(
coalesceCfg?.idleMs ??
providerDefaults?.idleMs ??
DEFAULT_BLOCK_STREAM_COALESCE_IDLE_MS,
),
);
const preference = chunking?.breakPreference ?? "paragraph";
const joiner =

View File

@@ -116,7 +116,7 @@ const FIELD_LABELS: Record<string, string> = {
"talk.apiKey": "Talk API Key",
"telegram.botToken": "Telegram Bot Token",
"telegram.dmPolicy": "Telegram DM Policy",
"telegram.streamMode": "Telegram Stream Mode",
"telegram.streamMode": "Telegram Draft Stream Mode",
"telegram.retry.attempts": "Telegram Retry Attempts",
"telegram.retry.minDelayMs": "Telegram Retry Min Delay (ms)",
"telegram.retry.maxDelayMs": "Telegram Retry Max Delay (ms)",
@@ -193,7 +193,7 @@ const FIELD_HELP: Record<string, string> = {
"telegram.dmPolicy":
'Direct message access control ("pairing" recommended). "open" requires telegram.allowFrom=["*"].',
"telegram.streamMode":
"Draft streaming mode for Telegram replies (off | partial | block). Requires private topics + sendMessageDraft.",
"Draft streaming mode for Telegram replies (off | partial | block). Separate from block streaming; requires private topics + sendMessageDraft.",
"telegram.retry.attempts":
"Max retry attempts for outbound Telegram API calls (default: 3).",
"telegram.retry.minDelayMs":