Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix: hold whitespace-only leftover prefixes
Dash4a8775ff69e2
diff --git a/packages/maker-shared/src/internalCitation.test.ts b/packages/maker-shared/src/internalCitation.test.tsindex 12b2ecd762..011cfc45e6 100644--- a/packages/maker-shared/src/internalCitation.test.ts+++ b/packages/maker-shared/src/internalCitation.test.ts@@ -84,7 +84,16 @@ describe('leaked model stop tokens', () => {const buffer = { pending: '', emitted: false };const padded = `${' '.repeat(23)}<|eos|>`;expect(holdStandaloneStopTokenDelta(buffer, padded)).toBeNull();- expect(buffer).toEqual({ pending: padded, emitted: false });+ expect(buffer.emitted).toBe(false);+ expect(buffer.pending.endsWith('<|eos|>')).toBe(true);+ });++ it('holds whitespace-only deltas without releasing a later leftover token', () => {+ const buffer = { pending: '', emitted: false };+ expect(holdStandaloneStopTokenDelta(buffer, ' '.repeat(23))).toBeNull();+ expect(holdStandaloneStopTokenDelta(buffer, '<|eos|>')).toBeNull();+ expect(buffer.emitted).toBe(false);+ expect(buffer.pending.trim()).toBe('<|eos|>');});it('holds a one-character leftover prefix until the closer arrives', () => {diff --git a/packages/maker-shared/src/internalCitation.ts b/packages/maker-shared/src/internalCitation.tsindex 765524a6b2..b3fa2c963b 100644--- a/packages/maker-shared/src/internalCitation.ts+++ b/packages/maker-shared/src/internalCitation.ts@@ -93,9 +93,9 @@ export function stripStandaloneModelStopToken(text: string): string {*/export function isPossibleStandaloneStopPrefix(text: string): boolean {const candidate = text.trim();- if (candidate.length === 0) return text.length <= MAX_STANDALONE_STOP_PREFIX;+ if (candidate.length === 0) return true;if (MODEL_STOP_TOKENS.has(candidate)) return true;- if (text.length > MAX_STANDALONE_STOP_PREFIX) return false;+ if (candidate.length > MAX_STANDALONE_STOP_PREFIX) return false;return [...MODEL_STOP_TOKENS].some((token) => token.startsWith(candidate));}@@ -127,7 +127,13 @@ export function holdStandaloneStopTokenDelta(): string | null {const combined = buffer.pending + delta;if (!buffer.emitted && isPossibleStandaloneStopPrefix(combined)) {- buffer.pending = combined;+ const candidate = combined.trim();+ if (candidate.length === 0) {+ buffer.pending = combined.slice(-MAX_STANDALONE_STOP_PREFIX);+ } else {+ const tokenStart = combined.lastIndexOf(candidate);+ buffer.pending = `${combined.slice(0, tokenStart).slice(-MAX_STANDALONE_STOP_PREFIX)}${candidate}`;+ }return null;}const citationEnd = stableInternalWebCitationBoundary(combined);