Repository navigation
feat: Optimize the loading style of the conversation #8293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,14 @@ | ||
| <script setup lang="ts"> | ||
| import { inject, ref, useTemplateRef } from 'vue' | ||
| import { ref, useTemplateRef } from 'vue' | ||
| import { useI18n } from 'vue-i18n' | ||
| import { useBottomFollow } from '@/conversation-panel/core/bottom-follow' | ||
| import { MESSAGE_LIST_KEY } from '../../message-list' | ||
| import { useMessageStreaming } from '../../message-list' | ||
|
|
||
| defineOptions({ name: 'ConversationReasoningContent' }) | ||
|
|
||
| defineProps<{ content: { content?: string | null; status?: string } }>() | ||
| const { t } = useI18n({ useScope: 'global' }) | ||
| const messageList = inject(MESSAGE_LIST_KEY, null) | ||
| const streaming = useMessageStreaming() | ||
| // 默认收起,思考中也只显示状态文案,手动展开后查看内容 | ||
| const isExpanded = ref(false) | ||
|
|
||
|
|
@@ -29,7 +29,7 @@ useBottomFollow(useTemplateRef<HTMLElement>('reasoningScrollRef')) | |
| </template> | ||
| <template #label> | ||
| <MkIcon name="icon_two-ellipses_outlined" /> | ||
| <span class="-mx-1" :class="{ 'mk-dotting': content.status === 'RUNNING' && messageList?.streamLoading.value }"> | ||
| <span class="-mx-1" :class="{ 'mk-dotting': content.status === 'RUNNING' && streaming }"> | ||
| {{ content.status === 'RUNNING' ? t('chat.message.thinking') : t('chat.message.thinkingCompleted') }} | ||
| </span> | ||
| </template> | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Review of the diff🔴 Potential bugs
🟡 Redundancy / logic
🟢 Minor / style
Suggested shapeconst props = defineProps<{
content: { content?: string | null; status?: 'RUNNING' | 'COMPLETED' | string }
}>()
const { isStreaming } = useMessageStreaming() // confirm actual API
const isRunning = computed(() => props.content.status === 'RUNNING')
const showDotting = computed(() => isRunning.value && Boolean(unref(isStreaming)))<span class="-mx-1" :class="{ 'mk-dotting': showDotting }">Bottom line: the refactor is fine if |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,6 +45,8 @@ export function createMessageListStore(deps: MessageListDeps) { | |
| const messageRecordIds = computed(() => getMessageRecordIds(messages.value)) | ||
| const loading = ref(false) | ||
| const streamLoading = ref(false) | ||
| /** 正在流式输出的回答,与 streamLoading 同步复位;内容项据此只在所属回答输出期间显示运行中。 */ | ||
| const streamingMessage = shallowRef<ChatMessage | null>(null) | ||
|
|
||
| // ── 分页 ───────────────────────────────────────────── | ||
| const pageSize = 30 | ||
|
|
@@ -144,6 +146,7 @@ export function createMessageListStore(deps: MessageListDeps) { | |
| currentStream.cancel() | ||
| currentStream = null | ||
| streamLoading.value = false | ||
| streamingMessage.value = null | ||
| return true | ||
| } | ||
| return false | ||
|
|
@@ -164,9 +167,15 @@ export function createMessageListStore(deps: MessageListDeps) { | |
| }) | ||
|
|
||
| // onNext 逐段回调,onComplete(e?) 结束回调:e 为空表示正常结束,有值表示失败 | ||
| const runStream = (request: () => Promise<Response>, onNext: (chunk: StreamChunk) => void, onComplete: (e?: unknown) => void) => { | ||
| const runStream = ( | ||
| target: ChatMessage | null, | ||
| request: () => Promise<Response>, | ||
| onNext: (chunk: StreamChunk) => void, | ||
| onComplete: (e?: unknown) => void, | ||
| ) => { | ||
| closeStream() | ||
| streamLoading.value = true | ||
| streamingMessage.value = target | ||
| request() | ||
| .then((response) => { | ||
| currentStream = new ConversationStream( | ||
|
|
@@ -178,13 +187,15 @@ export function createMessageListStore(deps: MessageListDeps) { | |
| (e) => { | ||
| currentStream = null | ||
| streamLoading.value = false | ||
| streamingMessage.value = null | ||
| onComplete(e) | ||
| }, | ||
| ) | ||
| currentStream.start() | ||
| }) | ||
| .catch((e) => { | ||
| streamLoading.value = false | ||
| streamingMessage.value = null | ||
| onComplete(e ?? new Error('stream request failed')) | ||
| }) | ||
| } | ||
|
|
@@ -261,6 +272,7 @@ export function createMessageListStore(deps: MessageListDeps) { | |
| let replacementStarted = false | ||
| const speech = startSpeech(target) | ||
| runStream( | ||
| target, | ||
| () => chatMessage(cid, payload), | ||
| (chunk) => { | ||
| if (chunk?.chat_record_id && !target.recordId) target.recordId = chunk.chat_record_id | ||
|
|
@@ -319,6 +331,7 @@ export function createMessageListStore(deps: MessageListDeps) { | |
| if (!lastMsg || (lastMsg.content && lastMsg.content.length > 0)) return | ||
| const recordId = lastMsg.id.replace('_USER', '').replace('_ASSISTANT', '') | ||
| runStream( | ||
| lastMsg, | ||
| () => resumeMessage(cid, recordId), | ||
| (chunk) => { | ||
| const m = messages.value[messages.value.length - 1] | ||
|
|
@@ -352,6 +365,7 @@ export function createMessageListStore(deps: MessageListDeps) { | |
| messageRecordIds, | ||
| loading, | ||
| streamLoading, | ||
| streamingMessage: computed(() => streamingMessage.value), | ||
| hasMore, | ||
| load, | ||
| loadMore, | ||
|
|
@@ -383,6 +397,14 @@ export function useMessageRecordId(): Readonly<Ref<string | undefined>> { | |
| return inject(MESSAGE_RECORD_ID_KEY, ref(undefined)) | ||
| } | ||
|
|
||
| /** 消息所属回答是否正在流式输出,由消息列表逐行提供;内容项的运行中状态仅在输出期间显示,避免结束后残留。 */ | ||
| export const MESSAGE_STREAMING_KEY: InjectionKey<Readonly<Ref<boolean>>> = Symbol('message-streaming') | ||
|
|
||
| /** 未提供时(日志、分析、分享等只读视图)为 false,不显示运行中;实时执行的外部宿主按自身执行状态提供。 */ | ||
| export function useMessageStreaming(): Readonly<Ref<boolean>> { | ||
| return inject(MESSAGE_STREAMING_KEY, ref(false)) | ||
| } | ||
|
|
||
| // 通用发送能力,由消息列表或外部宿主(如工具调试结果抽屉)提供;内容项按自身场景组装参数。 | ||
| export type SendMessage = (opts: SendMessageOptions) => void | ||
|
|
||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here's my review of the code changes: SummaryThe changes add a Potential Issues1. Race condition risk with
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The patch is syntactically fine for Vue 3, but there are a few semantic and maintainability points to verify.
Potential issues
Scope of
useMessageStreaming()useMessageStreaming()returns the streaming state for this specific message/answer, not a global “any message is streaming” flag.Stale
RUNNINGstatus becomessuccessWhen streaming ends but a tool status is still
RUNNING,groupStatusfalls through to'success'. That avoids the spinner, but it may incorrectly display a successful group for an aborted/failed/incomplete stream.RUNNING:'success'.Import path / circular dependency risk
message-listcan create a circular dependency if that module indirectly imports this component.@/.../useMessageStreaming.Boolean prop type
In templates, top-level refs are auto-unwrapped, so this is correct if
streamingis a top-levelRef<boolean>. Do not change it tostreaming.valuein the template.streamingcan beundefined, consider forcing a boolean:Optimization suggestion
Extract the repeated condition into a single helper to keep
groupStatusand the template consistent:Then:
Minor notes
.valueusage insidecomputedis correct..valueis correct due to Vue ref auto-unwrapping.streaming = true+ toolRUNNING→ spinner shown.streaming = false+ toolRUNNING→ no spinner.streaming = false+ toolFAIL→ error state.Main risk: using a possibly global streaming state and mapping stale
RUNNINGtosuccess.