Fix newline chunkMode block streaming to preserve single-newline paragraphs
This commit is contained in:
committed by
Peter Steinberger
parent
03e9a076b8
commit
46fa1c1301
@@ -7,7 +7,7 @@ import {
|
|||||||
INTERNAL_MESSAGE_CHANNEL,
|
INTERNAL_MESSAGE_CHANNEL,
|
||||||
listDeliverableMessageChannels,
|
listDeliverableMessageChannels,
|
||||||
} from "../../utils/message-channel.js";
|
} from "../../utils/message-channel.js";
|
||||||
import { resolveChunkMode, resolveTextChunkLimit, type TextChunkProvider } from "../chunk.js";
|
import { resolveTextChunkLimit, type TextChunkProvider } from "../chunk.js";
|
||||||
|
|
||||||
const DEFAULT_BLOCK_STREAM_MIN = 800;
|
const DEFAULT_BLOCK_STREAM_MIN = 800;
|
||||||
const DEFAULT_BLOCK_STREAM_MAX = 1200;
|
const DEFAULT_BLOCK_STREAM_MAX = 1200;
|
||||||
@@ -69,15 +69,11 @@ export function resolveBlockStreamingChunking(
|
|||||||
});
|
});
|
||||||
const chunkCfg = cfg?.agents?.defaults?.blockStreamingChunk;
|
const chunkCfg = cfg?.agents?.defaults?.blockStreamingChunk;
|
||||||
|
|
||||||
// When chunkMode is "newline", use newline-based streaming
|
// Note: chunkMode="newline" used to imply splitting on each newline, but outbound
|
||||||
const channelChunkMode = resolveChunkMode(cfg, providerKey, accountId);
|
// delivery now treats it as paragraph-aware chunking (only split on blank lines).
|
||||||
if (channelChunkMode === "newline") {
|
// Block streaming should follow the same rule, so we do NOT special-case newline
|
||||||
// For newline mode: use very low minChars to flush quickly on newlines
|
// mode here.
|
||||||
const minChars = Math.max(1, Math.floor(chunkCfg?.minChars ?? 1));
|
// (chunkMode no longer alters block streaming behavior)
|
||||||
const maxRequested = Math.max(1, Math.floor(chunkCfg?.maxChars ?? textLimit));
|
|
||||||
const maxChars = Math.max(1, Math.min(maxRequested, textLimit));
|
|
||||||
return { minChars, maxChars, breakPreference: "newline" };
|
|
||||||
}
|
|
||||||
|
|
||||||
const maxRequested = Math.max(1, Math.floor(chunkCfg?.maxChars ?? DEFAULT_BLOCK_STREAM_MAX));
|
const maxRequested = Math.max(1, Math.floor(chunkCfg?.maxChars ?? DEFAULT_BLOCK_STREAM_MAX));
|
||||||
const maxChars = Math.max(1, Math.min(maxRequested, textLimit));
|
const maxChars = Math.max(1, Math.min(maxRequested, textLimit));
|
||||||
@@ -103,11 +99,8 @@ export function resolveBlockStreamingCoalescing(
|
|||||||
): BlockStreamingCoalescing | undefined {
|
): BlockStreamingCoalescing | undefined {
|
||||||
const providerKey = normalizeChunkProvider(provider);
|
const providerKey = normalizeChunkProvider(provider);
|
||||||
|
|
||||||
// When chunkMode is "newline", disable coalescing to send each line immediately
|
// Note: chunkMode="newline" is paragraph-aware in outbound delivery (blank-line splits),
|
||||||
const channelChunkMode = resolveChunkMode(cfg, providerKey, accountId);
|
// so block streaming should not disable coalescing or flush per single newline.
|
||||||
if (channelChunkMode === "newline") {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
const providerId = providerKey ? normalizeChannelId(providerKey) : null;
|
const providerId = providerKey ? normalizeChannelId(providerKey) : null;
|
||||||
const providerChunkLimit = providerId
|
const providerChunkLimit = providerId
|
||||||
|
|||||||
Reference in New Issue
Block a user