fix: ignore empty text blocks in stacks

This commit is contained in:
JOJO 2026-02-25 13:20:15 +08:00
parent 6af1fe6364
commit 8d0c187bbf
2 changed files with 12 additions and 11 deletions

View File

@ -421,6 +421,13 @@ function formatImageName(path: string): string {
}
const isStackable = (action: any) => action && (action.type === 'thinking' || action.type === 'tool');
const isEmptyTextAction = (action: any) => {
if (!action || action.type !== 'text') {
return false;
}
const content = typeof action.content === 'string' ? action.content : '';
return !content.trim();
};
const splitActionGroups = (actions: any[] = [], messageIndex = 0) => {
const result: Array<
| { kind: 'stack'; actions: any[]; key: string }
@ -448,6 +455,9 @@ const splitActionGroups = (actions: any[] = [], messageIndex = 0) => {
};
actions.forEach((action, idx) => {
if (isEmptyTextAction(action)) {
return;
}
if (isStackable(action)) {
buffer.push(action);
} else {

View File

@ -380,11 +380,6 @@ export async function initializeLegacySocket(ctx: any) {
remainderToAppendLength: remainderToAppend.length,
finalLength: finalText.length
});
if (finalText && !ensureActiveTextAction()) {
ensureActiveMessageBinding();
const action = ctx.chatStartTextAction();
streamingState.activeTextAction = action || ensureActiveTextAction();
}
if (remainderToAppend) {
applyTextChunk(remainderToAppend);
}
@ -935,9 +930,10 @@ export async function initializeLegacySocket(ctx: any) {
logStreamingDebug('socket:text_start');
finalizeStreamingText({ force: true });
resetStreamingBuffer();
const action = ctx.chatStartTextAction();
streamingState.activeMessageIndex =
typeof ctx.currentMessageIndex === 'number' ? ctx.currentMessageIndex : null;
streamingState.activeTextAction = null;
streamingState.activeTextAction = action || ensureActiveTextAction();
ensureActiveMessageBinding();
ctx.$forceUpdate();
});
@ -962,11 +958,6 @@ export async function initializeLegacySocket(ctx: any) {
console.warn('上报chunk日志失败:', error);
}
if (data && typeof data.content === 'string' && data.content.length) {
if (!ensureActiveTextAction()) {
ensureActiveMessageBinding();
const action = ctx.chatStartTextAction();
streamingState.activeTextAction = action || ensureActiveTextAction();
}
if (STREAMING_ENABLED) {
enqueueStreamingContent(data.content);
} else {