diff --git a/static/src/components/chat/ChatArea.vue b/static/src/components/chat/ChatArea.vue index 704b3c8..c260e09 100644 --- a/static/src/components/chat/ChatArea.vue +++ b/static/src/components/chat/ChatArea.vue @@ -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 { diff --git a/static/src/composables/useLegacySocket.ts b/static/src/composables/useLegacySocket.ts index 7e1cf9d..b8be6db 100644 --- a/static/src/composables/useLegacySocket.ts +++ b/static/src/composables/useLegacySocket.ts @@ -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 {