惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
V2EX
量子位
博客园 - 司徒正美
IT之家
IT之家
V
Visual Studio Blog
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
Google DeepMind News
Google DeepMind News
Last Week in AI
Last Week in AI
Microsoft Security Blog
Microsoft Security Blog
T
Tailwind CSS Blog
aimingoo的专栏
aimingoo的专栏
GbyAI
GbyAI
Vercel News
Vercel News
B
Blog
大猫的无限游戏
大猫的无限游戏
D
DataBreaches.Net
小众软件
小众软件
罗磊的独立博客
博客园 - 叶小钗
雷峰网
雷峰网
Martin Fowler
Martin Fowler
Hugging Face - Blog
Hugging Face - Blog
WordPress大学
WordPress大学

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(streaming): preserve split final tags · openclaw/open...
steipete · 2026-04-29 · via Recent Commits to openclaw:main

@@ -42,8 +42,51 @@ import {

4242

import { hasNonzeroUsage, normalizeUsage, type UsageLike } from "./usage.js";

43434444

const FINAL_TAG_SCAN_RE = /<\s*(\/?)\s*final\s*>/gi;

45+

const STREAM_STRIPPED_BLOCK_TAG_NAMES = [

46+

"final",

47+

"think",

48+

"thinking",

49+

"thought",

50+

"antthinking",

51+

"antml:think",

52+

"antml:thinking",

53+

"antml:thought",

54+

] as const;

4555

const log = createSubsystemLogger("agent/embedded");

465657+

function isPotentialTrailingBlockTagFragment(fragment: string): boolean {

58+

if (!fragment.startsWith("<") || fragment.includes(">")) {

59+

return false;

60+

}

61+

const normalized = fragment.toLowerCase().replace(/\s+/g, "");

62+

if (!normalized.startsWith("<")) {

63+

return false;

64+

}

65+

const candidate = normalized.slice(1).replace(/^\//, "");

66+

if (!candidate) {

67+

return true;

68+

}

69+

return STREAM_STRIPPED_BLOCK_TAG_NAMES.some((name) => name.startsWith(candidate));

70+

}

71+72+

function splitTrailingBlockTagFragment(

73+

text: string,

74+

isInsideCodeSpan: (index: number) => boolean,

75+

): { text: string; pendingTagFragment?: string } {

76+

const fragmentStart = text.lastIndexOf("<");

77+

if (fragmentStart === -1 || isInsideCodeSpan(fragmentStart)) {

78+

return { text };

79+

}

80+

const fragment = text.slice(fragmentStart);

81+

if (!isPotentialTrailingBlockTagFragment(fragment)) {

82+

return { text };

83+

}

84+

return {

85+

text: text.slice(0, fragmentStart),

86+

pendingTagFragment: fragment,

87+

};

88+

}

89+4790

function collectPendingMediaFromInternalEvents(

4891

events: SubscribeEmbeddedPiSessionParams["internalEvents"],

4992

): string[] {

@@ -213,9 +256,11 @@ export function subscribeEmbeddedPiSession(params: SubscribeEmbeddedPiSessionPar

213256

state.blockState.thinking = false;

214257

state.blockState.final = false;

215258

state.blockState.inlineCode = createInlineCodeState();

259+

state.blockState.pendingTagFragment = undefined;

216260

state.partialBlockState.thinking = false;

217261

state.partialBlockState.final = false;

218262

state.partialBlockState.inlineCode = createInlineCodeState();

263+

state.partialBlockState.pendingTagFragment = undefined;

219264

state.lastStreamedAssistant = undefined;

220265

state.lastStreamedAssistantCleaned = undefined;

221266

state.emittedAssistantUpdate = false;

@@ -521,20 +566,36 @@ export function subscribeEmbeddedPiSession(params: SubscribeEmbeddedPiSessionPar

521566522567

const stripBlockTags = (

523568

text: string,

524-

state: { thinking: boolean; final: boolean; inlineCode?: InlineCodeState },

569+

state: {

570+

thinking: boolean;

571+

final: boolean;

572+

inlineCode?: InlineCodeState;

573+

pendingTagFragment?: string;

574+

},

575+

options?: { final?: boolean },

525576

): string => {

526-

if (!text) {

577+

const input = `${state.pendingTagFragment ?? ""}${text}`;

578+

state.pendingTagFragment = undefined;

579+

if (!input) {

527580

return text;

528581

}

529582530583

const inlineStateStart = state.inlineCode ?? createInlineCodeState();

531-

const codeSpans = buildCodeSpanIndex(text, inlineStateStart);

584+

const initialCodeSpans = buildCodeSpanIndex(input, inlineStateStart);

585+

const { text: scanText, pendingTagFragment } = options?.final

586+

? { text: input, pendingTagFragment: undefined }

587+

: splitTrailingBlockTagFragment(input, initialCodeSpans.isInside);

588+

state.pendingTagFragment = pendingTagFragment;

589+

if (!scanText) {

590+

return "";

591+

}

592+

const codeSpans = buildCodeSpanIndex(scanText, inlineStateStart);

532593533594

let processed = "";

534595

THINKING_TAG_SCAN_RE.lastIndex = 0;

535596

let lastIndex = 0;

536597

let inThinking = state.thinking;

537-

for (const match of text.matchAll(THINKING_TAG_SCAN_RE)) {

598+

for (const match of scanText.matchAll(THINKING_TAG_SCAN_RE)) {

538599

const idx = match.index ?? 0;

539600

if (codeSpans.isInside(idx)) {

540601

continue;

@@ -543,8 +604,8 @@ export function subscribeEmbeddedPiSession(params: SubscribeEmbeddedPiSessionPar

543604

if (!inThinking) {

544605

if (isClose) {

545606

const afterIndex = idx + match[0].length;

546-

const before = text.slice(lastIndex, idx);

547-

const after = text.slice(afterIndex);

607+

const before = scanText.slice(lastIndex, idx);

608+

const after = scanText.slice(afterIndex);

548609

if (hasOrphanReasoningCloseBoundary({ before, after })) {

549610

processed = "";

550611

} else {

@@ -553,13 +614,13 @@ export function subscribeEmbeddedPiSession(params: SubscribeEmbeddedPiSessionPar

553614

lastIndex = afterIndex;

554615

continue;

555616

}

556-

processed += text.slice(lastIndex, idx);

617+

processed += scanText.slice(lastIndex, idx);

557618

}

558619

inThinking = !isClose;

559620

lastIndex = idx + match[0].length;

560621

}

561622

if (!inThinking) {

562-

processed += text.slice(lastIndex);

623+

processed += scanText.slice(lastIndex);

563624

}

564625

state.thinking = inThinking;

565626