Repository navigation
fix: correct reasoning animation and skill execution toggle - #8190
Conversation
| <span class="-mx-1" :class="{ 'mk-dotting': content.status === 'RUNNING' && messageList?.streamLoading.value }"> | ||
| {{ content.status === 'RUNNING' ? t('chat.message.thinking') : t('chat.message.thinkingCompleted') }} | ||
| </span> | ||
| </template> |
There was a problem hiding this comment.
Here is the analysis of the code change:
1. Potential Issue: Direct .value Access on Injected Ref
Issue: messageList?.streamLoading.value
If MESSAGE_LIST_KEY injects a Vue Ref<boolean>, accessing it directly via .value in the template logic within <script setup> or the class binding requires careful handling.
- If
streamLoadingis a Ref, in the template itself (inside the:class), you typically do not need.value(Vue automatically unwraps refs in templates). However, since this expression is likely being evaluated within the render function context generated by the template compiler, behavior can sometimes be ambiguous depending on howmessageListis typed and structured. - Better Approach: Ensure
streamLoadingis correctly unwrapped. IfmessageListis an object containing a refstreamLoading, you should probably usemessageList.streamLoadingin the template if Vue's auto-unwrapping applies, ormessageList.streamLoading.valueif explicitly accessing the ref value outside of standard template binding evaluation (which is rare, but possible here).- Recommendation: Test if
messageList?.streamLoading(without.value) works. IfstreamLoadingis just a boolean property on the injected object, remove.valueentirely. If it is a Ref, keeping.valuemight be necessary if auto-unwrapping doesn't catch nested properties correctly in this specific context, but it's cleaner to expose a computedisStreamingproperty from the injected context instead.
- Recommendation: Test if
2. Logic Clarity & Edge Case: Null Safety vs. Intended Behavior
Current Logic: content.status === 'RUNNING' && messageList?.streamLoading.value
- Implication: The "thinking" dotting animation only shows if the specific message's status is running AND the global/streaming list indicator is active.
- Potential Problem: If
messageListis null (injected defaultnull), the condition fails silently. This is good for safety, but ensure thatmessageListis always expected to exist in this component's tree. IfmessageListis missing, the UI will behave as if the message is completed immediately after the stream ends locally, which might cause flicker or inconsistent UX if the injection fails temporarily. - Suggestion: Consider adding a default fallback for
messageListto avoid optional chaining in multiple places if the dependency is strict. Alternatively, document whystreamLoading(global state) is combined withstatus(local state).
3. Optimization: Computed Property for Complex Conditions
The class binding contains a somewhat complex boolean expression involving injections and local props.
Suggestion: Extract this into a computed property for better readability, testability, and reactivity tracking.
const showThinkingDots = computed(() => {
// Adjust .value access based on actual structure of messageList.streamLoading
const isGlobalStreaming = messageList?.streamLoading ?? false;
return content.status === 'RUNNING' && isGlobalStreaming;
});Then in template:
:class="{ 'mk-dotting': showThinkingDots }"Note: If streamLoading is a Ref inside messageList, you'd write messageList?.streamLoading.value inside the computed property. Vue tracks dependencies correctly in computed.
4. Code Style/Naming
useTemplateRef<HTMLElement>('reasoningScrollRef'): This is fine.- Class name
mk-dotting: Ensure this utility class exists in your CSS framework.
Summary of Recommendations
- Verify Ref Unwrapping: Check if
messageList.streamLoadingis a Ref. If so, using.valuein the template:classdirective might be unnecessary or incorrect depending on Vue version/compiler behavior. Moving logic to acomputedproperty is safer and clearer. - Use Computed Property: Move the boolean logic into a
computedvariable namedisThinkingActiveor similar. - Null Handling: Confirm that
inject(MESSAGE_LIST_KEY, null)returningnullis an acceptable state where animations stop. If not, provide a more robust default structure formessageList.
Optimized Version Example
<script setup lang="ts">
import { computed, inject, ref, useTemplateRef } from 'vue'
import { useI18n } from 'vue-i18n'
import { useBottomFollow } from '@/conversation-panel/core/bottom-follow'
import { MESSAGE_LIST_KEY } from '../../message-list'
defineOptions({ name: 'ConversationReasoningContent' })
// Use defineModel for props if content changes frequently, otherwise current defineProps is fine
defineProps<{ content: { content?: string | null; status?: string } }>()
const { t } = useI18n({ useScope: 'global' })
const messageList = inject(MESSAGE_LIST_KEY, null)
// Default collapsed, show status text even while thinking, manual expand reveals content
const isExpanded = ref(false)
// Extract complex condition to computed
const showDottedLine = computed(() => {
// Assuming streamLoading is a Ref inside messageList object:
const isStreamingGlobally = messageList?.streamLoading?.value ?? false
// If streamLoading is plain boolean: const isStreamingGlobally = messageList?.streamLoading ?? false
return content.status === 'RUNNING' && isStreamingGlobally
})
useBottomFollow(useTemplateRef<HTMLElement>('reasoningScrollRef'))
</script>
<template>
<!-- ... -->
<span
class="-mx-1"
:class="{ 'mk-dotting': showDottedLine }"
>
{{ content.status === 'RUNNING' ? t('chat.message.thinking') : t('chat.message.thinkingCompleted') }}
</span>
<!-- ... -->
</template>| <el-checkbox v-model="formData.mcp_output_enable">{{ t('application.skills.outputExecution') }}</el-checkbox> | ||
| </div> | ||
| <div class="mk-white-card w-full"> | ||
| <ResourceSetting :setting="formData" @update="updateNodeData" /> |
There was a problem hiding this comment.
Here are the findings and suggestions for the provided code diff:
1. Functional Issue (High Priority)
Problem: In the original line, :model-value="formData.mcp_output_enable" creates a one-way binding from state to view. Unless there is an external @change or @update:model-value handler (which is not shown and likely missing given the context of changing to v-model), the checkbox will not update the formData.mcp_output_enable state when clicked. It appears read-only or broken.
Fix: The change to v-model="formData.mcp_output_enable" is correct and necessary to establish two-way binding. This ensures that checking/unchecking the box updates the underlying data object.
2. Reactivity Concern (Vue 3/Composition API)
Check: Ensure that formData is defined as a reactive object (e.g., using ref, reactive, or shallowRef).
- If
formDatais a plain object assigned insetup(), modifying nested properties likeformData.mcp_output_enablemight not trigger re-renders depending on how Vue's reactivity system tracks it. - Recommendation: If
formDatacomes frompiniaorreactive(), you are safe. If it's a shallow ref object, ensure the property exists initially or use optional chaining if necessary (thoughv-modelusually handles this reasonably well).
3. Code Style & Readability
Suggestion: The added HTML comment <!-- 控制是否展示技能执行过程 --> is good for internal team understanding. However, consider if this behavior is obvious enough from the label t('application.skills.outputExecution'). If the project enforces strict cleanup of temporary comments before PR merge, remember to remove it. Otherwise, keeping it is fine for clarity.
4. Component Logic Assumption
Note: The el-checkbox is used here. Element Plus checkboxes work with v-model. Your change aligns with Element Plus documentation best practices. No further changes needed for the component usage itself.
Summary
The diff fixes a potential bug where the checkbox state didn't sync back to the data model. The change from :model-value to v-model is correct and recommended.
Final Verdict: ✅ Good fix. Just verify that formData is properly reactive.
fix: correct reasoning animation and skill execution toggle