mirror of
https://github.com/davidkaya/aryx.git
synced 2026-08-04 19:08:40 +02:00
fix: remove streaming text boundary heuristics that injected spurious spaces
The StreamingTextMerger (C#) and mergeStreamingText (TypeScript) contained custom word-boundary heuristics that inserted spaces between streaming deltas based on incorrect assumptions. Two bugs caused mid-word spaces: 1. Unconditional space insertion when incoming delta started with uppercase or digit characters, breaking acronyms (MDA -> M DA, UAG -> UA G) 2. LooksLikeWordBoundary using global token counts that fired on nearly every mid-word token split (writable -> wr itable, fragile -> frag ile) Both upstream projects (Copilot SDK and Agent Framework) use simple string concatenation for delta accumulation. LLM streaming tokens natively include whitespace when needed, so no boundary detection is required. Removed all boundary heuristic methods and replaced with plain concatenation. Kept overlap detection and snapshot handling for event redelivery scenarios. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -5,52 +5,6 @@ function tokenize(value: string): string[] {
|
||||
.filter((token) => token.length > 0);
|
||||
}
|
||||
|
||||
function shouldInsertNewlineBoundary(current: string, incoming: string): boolean {
|
||||
if (current.endsWith('\n')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return /^(?:#{1,6}\s|[-*+]\s|\d+\.\s|>\s|```)/.test(incoming.trimStart());
|
||||
}
|
||||
|
||||
function shouldInsertSpaceBoundary(current: string, incoming: string): boolean {
|
||||
const lastChar = current.at(-1);
|
||||
const firstChar = incoming[0];
|
||||
if (!lastChar || !firstChar) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (/\s/.test(lastChar) || /\s/.test(firstChar) || /[([{/"'`]/.test(lastChar)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (/^[.,!?;:%)\]}]/.test(firstChar)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (/^[*_`~\[]/.test(firstChar) || /^[A-Z0-9]/.test(firstChar)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const currentTokens = tokenize(current);
|
||||
const incomingTokens = tokenize(incoming);
|
||||
const firstIncomingToken = incomingTokens[0] ?? '';
|
||||
|
||||
return currentTokens.length >= 2 && incomingTokens.length >= 2 && firstIncomingToken.length >= 2;
|
||||
}
|
||||
|
||||
function appendWithNaturalBoundary(current: string, incoming: string): string {
|
||||
if (shouldInsertNewlineBoundary(current, incoming)) {
|
||||
return `${current}\n${incoming}`;
|
||||
}
|
||||
|
||||
if (shouldInsertSpaceBoundary(current, incoming)) {
|
||||
return `${current} ${incoming}`;
|
||||
}
|
||||
|
||||
return current + incoming;
|
||||
}
|
||||
|
||||
function computeSuffixPrefixOverlap(current: string, incoming: string): number {
|
||||
const maxOverlap = Math.min(current.length, incoming.length);
|
||||
for (let length = maxOverlap; length > 0; length -= 1) {
|
||||
@@ -109,5 +63,5 @@ export function mergeStreamingText(current: string, incoming: string): string {
|
||||
return incoming;
|
||||
}
|
||||
|
||||
return appendWithNaturalBoundary(current, incoming);
|
||||
return current + incoming;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user