fix: show answer generation status after retrieval
parent
91b2d31cd4
commit
747cbcbc02
|
|
@ -106,6 +106,8 @@ const messages = {
|
|||
"unableToGetKnowledgeBaseId": "无法获取知识库ID",
|
||||
"summaryInProgress": "正在总结答案……",
|
||||
"thinkingAlt": "正在思考",
|
||||
"preparingAnswer": "正在准备回答…",
|
||||
"connectingModelAndGeneratingAnswer": "正在连接模型并生成回答…",
|
||||
"deepThoughtCompleted": "已深度思考",
|
||||
"deepThoughtAlt": "深度思考完成",
|
||||
"referencesTitle": "参考了{count}个相关内容",
|
||||
|
|
@ -596,6 +598,8 @@ const messages = {
|
|||
"unableToGetKnowledgeBaseId": "Unable to get knowledge base ID",
|
||||
"summaryInProgress": "Summarizing answer…",
|
||||
"thinkingAlt": "Thinking in progress",
|
||||
"preparingAnswer": "Preparing an answer…",
|
||||
"connectingModelAndGeneratingAnswer": "Connecting to the model and generating an answer…",
|
||||
"deepThoughtCompleted": "Deep thinking completed",
|
||||
"deepThoughtAlt": "Deep thinking finished",
|
||||
"referencesTitle": "Referenced {count} related item(s)",
|
||||
|
|
@ -1048,6 +1052,8 @@ const koEmbedPublish = {
|
|||
followUpQuestions: '이어서 질문',
|
||||
followUpQuestionsLoading: '추천 질문 로딩 중',
|
||||
thinkingAlt: '생각 중',
|
||||
preparingAnswer: '답변을 준비하고 있습니다…',
|
||||
connectingModelAndGeneratingAnswer: '모델에 연결하여 답변을 생성하고 있습니다…',
|
||||
refreshSuggestedQuestions: '다른 질문',
|
||||
imageTooMany: '이미지는 최대 5장까지 업로드할 수 있습니다',
|
||||
imageTypeSizeError: 'JPG/PNG/GIF/WEBP만 지원하며, 각 파일은 10MB 이하여야 합니다',
|
||||
|
|
@ -1136,6 +1142,8 @@ const ruEmbedPublish = {
|
|||
followUpQuestions: 'Спрашивайте дальше',
|
||||
followUpQuestionsLoading: 'Загрузка рекомендуемых вопросов',
|
||||
thinkingAlt: 'Обдумывание...',
|
||||
preparingAnswer: 'Подготовка ответа…',
|
||||
connectingModelAndGeneratingAnswer: 'Подключение к модели и создание ответа…',
|
||||
refreshSuggestedQuestions: 'Ещё',
|
||||
imageTooMany: 'Можно загрузить не более 5 изображений',
|
||||
imageTypeSizeError: 'Поддерживаются только JPG/PNG/GIF/WEBP, каждый файл до 10 МБ',
|
||||
|
|
|
|||
|
|
@ -2558,6 +2558,8 @@ export default {
|
|||
refreshSuggestedQuestions: 'More',
|
||||
thinking: 'Thinking...',
|
||||
thinkingAlt: 'Thinking in progress',
|
||||
preparingAnswer: 'Preparing an answer…',
|
||||
connectingModelAndGeneratingAnswer: 'Connecting to the model and generating an answer…',
|
||||
deepThoughtCompleted: 'Deep thinking completed',
|
||||
deepThoughtAlt: 'Deep thinking finished',
|
||||
referencesTitle: 'Referenced {count} related item(s)',
|
||||
|
|
|
|||
|
|
@ -3046,6 +3046,8 @@ export default {
|
|||
refreshSuggestedQuestions: '다른 질문',
|
||||
thinking: '생각 중...',
|
||||
thinkingAlt: '생각 중',
|
||||
preparingAnswer: '답변을 준비하고 있습니다…',
|
||||
connectingModelAndGeneratingAnswer: '모델에 연결하여 답변을 생성하고 있습니다…',
|
||||
deepThoughtCompleted: '심층 분석 완료',
|
||||
deepThoughtAlt: '심층 분석 완료',
|
||||
referencesTitle: '{count}개의 관련 내용 참조',
|
||||
|
|
|
|||
|
|
@ -3046,6 +3046,8 @@ export default {
|
|||
refreshSuggestedQuestions: 'Ещё',
|
||||
thinking: 'Думаю...',
|
||||
thinkingAlt: 'Обдумывание...',
|
||||
preparingAnswer: 'Подготовка ответа…',
|
||||
connectingModelAndGeneratingAnswer: 'Подключение к модели и создание ответа…',
|
||||
deepThoughtCompleted: 'Глубокий анализ завершён',
|
||||
deepThoughtAlt: 'Глубокий анализ',
|
||||
referencesTitle: 'Использовано {count} связанного материала',
|
||||
|
|
|
|||
|
|
@ -3046,6 +3046,8 @@ export default {
|
|||
refreshSuggestedQuestions: '换一批',
|
||||
thinking: '思考中...',
|
||||
thinkingAlt: '正在思考',
|
||||
preparingAnswer: '正在准备回答…',
|
||||
connectingModelAndGeneratingAnswer: '正在连接模型并生成回答…',
|
||||
deepThoughtCompleted: '已深度思考',
|
||||
deepThoughtAlt: '深度思考完成',
|
||||
referencesTitle: '参考了{count}个相关内容',
|
||||
|
|
|
|||
|
|
@ -0,0 +1,52 @@
|
|||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
import { shouldShowRagModelAnswerWait } from './rag-pipeline-state.ts'
|
||||
|
||||
const completedRetrieval = {
|
||||
isCompleted: false,
|
||||
hasAnswer: false,
|
||||
hasThinkingEvent: false,
|
||||
stepCount: 2,
|
||||
allStepsDone: true,
|
||||
hasCompletedRetrievalStep: true,
|
||||
}
|
||||
|
||||
test('shows the model-answer wait state after the RAG pipeline finishes', () => {
|
||||
assert.equal(shouldShowRagModelAnswerWait(completedRetrieval), true)
|
||||
})
|
||||
|
||||
test('does not show the model-answer wait state while a pipeline step is pending', () => {
|
||||
assert.equal(shouldShowRagModelAnswerWait({
|
||||
...completedRetrieval,
|
||||
allStepsDone: false,
|
||||
}), false)
|
||||
})
|
||||
|
||||
test('does not show the model-answer wait state before pipeline events arrive', () => {
|
||||
assert.equal(shouldShowRagModelAnswerWait({
|
||||
...completedRetrieval,
|
||||
stepCount: 0,
|
||||
}), false)
|
||||
})
|
||||
|
||||
test('does not mistake a completed pre-retrieval step for the model-answer wait', () => {
|
||||
assert.equal(shouldShowRagModelAnswerWait({
|
||||
...completedRetrieval,
|
||||
hasCompletedRetrievalStep: false,
|
||||
}), false)
|
||||
})
|
||||
|
||||
test('hides the model-answer wait state when thinking, answer, or completion arrives', () => {
|
||||
assert.equal(shouldShowRagModelAnswerWait({
|
||||
...completedRetrieval,
|
||||
hasThinkingEvent: true,
|
||||
}), false)
|
||||
assert.equal(shouldShowRagModelAnswerWait({
|
||||
...completedRetrieval,
|
||||
hasAnswer: true,
|
||||
}), false)
|
||||
assert.equal(shouldShowRagModelAnswerWait({
|
||||
...completedRetrieval,
|
||||
isCompleted: true,
|
||||
}), false)
|
||||
})
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
export interface RagModelAnswerWaitState {
|
||||
isCompleted: boolean
|
||||
hasAnswer: boolean
|
||||
hasThinkingEvent: boolean
|
||||
stepCount: number
|
||||
allStepsDone: boolean
|
||||
hasCompletedRetrievalStep: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a model-answer wait state only in the quiet gap after every visible RAG
|
||||
* pipeline step has finished and before the model emits thinking or answer text.
|
||||
*/
|
||||
export function shouldShowRagModelAnswerWait(state: RagModelAnswerWaitState): boolean {
|
||||
return (
|
||||
!state.isCompleted &&
|
||||
!state.hasAnswer &&
|
||||
!state.hasThinkingEvent &&
|
||||
state.stepCount > 0 &&
|
||||
state.allStepsDone &&
|
||||
state.hasCompletedRetrievalStep
|
||||
)
|
||||
}
|
||||
|
|
@ -50,7 +50,7 @@ test('rag pipeline opens references from search steps and the drawer composable'
|
|||
test('rag pipeline uses a native pending step and lets the thinking title shimmer while pending', () => {
|
||||
assert.match(source, /showPrePipelineWait/)
|
||||
assert.match(source, /class="action-card action-pending"/)
|
||||
assert.match(source, /t\('chat\.thinkingAlt'\)/)
|
||||
assert.match(source, /t\('chat\.preparingAnswer'\)/)
|
||||
assert.match(source, /showThinkingStep/)
|
||||
assert.match(source, /'action-pending': thinkingPending/)
|
||||
assert.match(source, /hasThinkingEvent/)
|
||||
|
|
@ -58,6 +58,13 @@ test('rag pipeline uses a native pending step and lets the thinking title shimme
|
|||
assert.doesNotMatch(source, /showActivityIndicator/)
|
||||
})
|
||||
|
||||
test('rag pipeline shows a pending model-answer step after retrieval completes', () => {
|
||||
assert.match(source, /showModelAnswerWait/)
|
||||
assert.match(source, /shouldShowRagModelAnswerWait/)
|
||||
assert.match(source, /t\('chat\.connectingModelAndGeneratingAnswer'\)/)
|
||||
assert.match(source, /rag-model-wait-step/)
|
||||
})
|
||||
|
||||
test('done row appears only after the full turn completes', () => {
|
||||
assert.match(source, /const showDoneRow = computed\(\(\) => \{[\s\S]*hasAnswer\.value/)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
<div class="action-header no-results">
|
||||
<div class="action-title">
|
||||
<t-icon class="action-title-icon" name="lightbulb" />
|
||||
<span class="action-name">{{ t('chat.thinkingAlt') }}</span>
|
||||
<span class="action-name">{{ t('chat.preparingAnswer') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -20,6 +20,7 @@
|
|||
<div v-for="(step, index) in steps" :key="step.id" class="tree-child" :class="{
|
||||
'tree-child-last':
|
||||
!showDoneRow
|
||||
&& !showModelAnswerWait
|
||||
&& !showThinkingStep
|
||||
&& index === steps.length - 1,
|
||||
}">
|
||||
|
|
@ -52,6 +53,27 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="showModelAnswerWait"
|
||||
class="tree-child tree-child-last streaming-loading-node rag-model-wait-step"
|
||||
role="status"
|
||||
aria-live="polite"
|
||||
>
|
||||
<div class="tree-branch" />
|
||||
<div class="tree-child-content">
|
||||
<div class="tool-event">
|
||||
<div class="action-card action-pending">
|
||||
<div class="action-header no-results">
|
||||
<div class="action-title">
|
||||
<t-icon class="action-title-icon" name="lightbulb" />
|
||||
<span class="action-name">{{ t('chat.connectingModelAndGeneratingAnswer') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="showThinkingStep" class="tree-child rag-thinking-step"
|
||||
:class="{ 'tree-child-last': !showDoneRow }">
|
||||
<div class="tree-branch" />
|
||||
|
|
@ -188,7 +210,7 @@
|
|||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, nextTick, ref, watch } from 'vue'
|
||||
import { computed, nextTick, onBeforeUnmount, ref, watch } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { getAgentToolIconName } from '@/utils/agent-tool-icons'
|
||||
import {
|
||||
|
|
@ -200,6 +222,7 @@ import { getAttachmentParsingSummaryHtml } from '@/utils/attachmentParsingDispla
|
|||
import { RAG_TIMELINE_TOOL_NAMES } from '@/utils/rag-pipeline-history'
|
||||
import { useChatReferencesDrawer } from '@/composables/useChatReferencesDrawer'
|
||||
import { buildReferenceSections } from '@/utils/referenceSources'
|
||||
import { shouldShowRagModelAnswerWait } from '@/utils/rag-pipeline-state'
|
||||
|
||||
const props = defineProps<{
|
||||
session?: {
|
||||
|
|
@ -217,6 +240,8 @@ const referencesDrawer = useChatReferencesDrawer()
|
|||
const userExpanded = ref(false)
|
||||
const thinkingExpanded = ref(true)
|
||||
const rootElement = ref<HTMLElement | null>(null)
|
||||
const showModelAnswerWait = ref(false)
|
||||
let modelAnswerWaitTimer: ReturnType<typeof setTimeout> | undefined
|
||||
|
||||
const thinkingContent = computed(() => {
|
||||
const stream = props.session?.agentEventStream
|
||||
|
|
@ -289,6 +314,7 @@ const steps = computed(() => {
|
|||
|
||||
return {
|
||||
id: String(event.tool_call_id || `${toolName}-${event.timestamp || 0}`),
|
||||
toolName,
|
||||
pending,
|
||||
iconName: getAgentToolIconName(toolName, searchSource),
|
||||
title: getRagPipelineStepTitle(t, {
|
||||
|
|
@ -308,6 +334,21 @@ const allStepsDone = computed(
|
|||
() => steps.value.length > 0 && steps.value.every((step) => !step.pending),
|
||||
)
|
||||
|
||||
const hasCompletedRetrievalStep = computed(() => steps.value.some(
|
||||
(step) =>
|
||||
(step.toolName === 'knowledge_search' || step.toolName === 'search_knowledge') &&
|
||||
!step.pending,
|
||||
))
|
||||
|
||||
const shouldShowModelAnswerWait = computed(() => shouldShowRagModelAnswerWait({
|
||||
isCompleted: Boolean(props.session?.is_completed),
|
||||
hasAnswer: hasAnswer.value,
|
||||
hasThinkingEvent: hasThinkingEvent.value,
|
||||
stepCount: steps.value.length,
|
||||
allStepsDone: allStepsDone.value,
|
||||
hasCompletedRetrievalStep: hasCompletedRetrievalStep.value,
|
||||
}))
|
||||
|
||||
const showCollapsedRoot = computed(
|
||||
() =>
|
||||
(hasAnswer.value || Boolean(props.session?.is_completed)) &&
|
||||
|
|
@ -422,6 +463,27 @@ watch(thinkingPending, (pending) => {
|
|||
}
|
||||
})
|
||||
|
||||
watch(shouldShowModelAnswerWait, (shouldShow) => {
|
||||
if (modelAnswerWaitTimer) {
|
||||
clearTimeout(modelAnswerWaitTimer)
|
||||
modelAnswerWaitTimer = undefined
|
||||
}
|
||||
|
||||
if (!shouldShow) {
|
||||
showModelAnswerWait.value = false
|
||||
return
|
||||
}
|
||||
|
||||
// Avoid flashing the model-wait row when the first answer token arrives
|
||||
// immediately after retrieval completes.
|
||||
modelAnswerWaitTimer = setTimeout(() => {
|
||||
modelAnswerWaitTimer = undefined
|
||||
if (shouldShowModelAnswerWait.value) {
|
||||
showModelAnswerWait.value = true
|
||||
}
|
||||
}, 250)
|
||||
}, { immediate: true })
|
||||
|
||||
watch(hasAnswer, (answered) => {
|
||||
if (answered && hasThinking.value) {
|
||||
thinkingExpanded.value = false
|
||||
|
|
@ -437,6 +499,10 @@ watch(thinkingExpanded, (expanded) => {
|
|||
if (!expanded || !isThinkingStreaming.value) return
|
||||
scrollThinkingDetailToBottom()
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
if (modelAnswerWaitTimer) clearTimeout(modelAnswerWaitTimer)
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
|
|
|
|||
Loading…
Reference in New Issue