fix: ignore empty text blocks in stacks
This commit is contained in:
parent
6af1fe6364
commit
8d0c187bbf
@ -421,6 +421,13 @@ function formatImageName(path: string): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const isStackable = (action: any) => action && (action.type === 'thinking' || action.type === 'tool');
|
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 splitActionGroups = (actions: any[] = [], messageIndex = 0) => {
|
||||||
const result: Array<
|
const result: Array<
|
||||||
| { kind: 'stack'; actions: any[]; key: string }
|
| { kind: 'stack'; actions: any[]; key: string }
|
||||||
@ -448,6 +455,9 @@ const splitActionGroups = (actions: any[] = [], messageIndex = 0) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
actions.forEach((action, idx) => {
|
actions.forEach((action, idx) => {
|
||||||
|
if (isEmptyTextAction(action)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (isStackable(action)) {
|
if (isStackable(action)) {
|
||||||
buffer.push(action);
|
buffer.push(action);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -380,11 +380,6 @@ export async function initializeLegacySocket(ctx: any) {
|
|||||||
remainderToAppendLength: remainderToAppend.length,
|
remainderToAppendLength: remainderToAppend.length,
|
||||||
finalLength: finalText.length
|
finalLength: finalText.length
|
||||||
});
|
});
|
||||||
if (finalText && !ensureActiveTextAction()) {
|
|
||||||
ensureActiveMessageBinding();
|
|
||||||
const action = ctx.chatStartTextAction();
|
|
||||||
streamingState.activeTextAction = action || ensureActiveTextAction();
|
|
||||||
}
|
|
||||||
if (remainderToAppend) {
|
if (remainderToAppend) {
|
||||||
applyTextChunk(remainderToAppend);
|
applyTextChunk(remainderToAppend);
|
||||||
}
|
}
|
||||||
@ -935,9 +930,10 @@ export async function initializeLegacySocket(ctx: any) {
|
|||||||
logStreamingDebug('socket:text_start');
|
logStreamingDebug('socket:text_start');
|
||||||
finalizeStreamingText({ force: true });
|
finalizeStreamingText({ force: true });
|
||||||
resetStreamingBuffer();
|
resetStreamingBuffer();
|
||||||
|
const action = ctx.chatStartTextAction();
|
||||||
streamingState.activeMessageIndex =
|
streamingState.activeMessageIndex =
|
||||||
typeof ctx.currentMessageIndex === 'number' ? ctx.currentMessageIndex : null;
|
typeof ctx.currentMessageIndex === 'number' ? ctx.currentMessageIndex : null;
|
||||||
streamingState.activeTextAction = null;
|
streamingState.activeTextAction = action || ensureActiveTextAction();
|
||||||
ensureActiveMessageBinding();
|
ensureActiveMessageBinding();
|
||||||
ctx.$forceUpdate();
|
ctx.$forceUpdate();
|
||||||
});
|
});
|
||||||
@ -962,11 +958,6 @@ export async function initializeLegacySocket(ctx: any) {
|
|||||||
console.warn('上报chunk日志失败:', error);
|
console.warn('上报chunk日志失败:', error);
|
||||||
}
|
}
|
||||||
if (data && typeof data.content === 'string' && data.content.length) {
|
if (data && typeof data.content === 'string' && data.content.length) {
|
||||||
if (!ensureActiveTextAction()) {
|
|
||||||
ensureActiveMessageBinding();
|
|
||||||
const action = ctx.chatStartTextAction();
|
|
||||||
streamingState.activeTextAction = action || ensureActiveTextAction();
|
|
||||||
}
|
|
||||||
if (STREAMING_ENABLED) {
|
if (STREAMING_ENABLED) {
|
||||||
enqueueStreamingContent(data.content);
|
enqueueStreamingContent(data.content);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user