feat(frontend): enhance chat markdown rendering and streaming behavior

- Introduce functions to stabilize rendering of dangling inline markers during streaming, preventing flickering and layout shifts.
- Implement tagging for standalone strong paragraphs to ensure consistent styling as subtitles.
- Update CSS for chat components to improve animation smoothness and visual feedback during typing.
- Add tests for new markdown rendering features, including handling of incomplete emphasis and citation tags.
This commit is contained in:
wizardchen
2026-06-19 23:05:20 +08:00
committed by lyingbug
parent ae9038732a
commit 58461a5b68
9 changed files with 477 additions and 21 deletions
@@ -43,9 +43,9 @@
aria-hidden="true" />
<span v-if="event.title" class="action-name action-preamble-title">{{ event.title }}</span>
<span v-else-if="isEventExpanded(event.event_id)" class="action-name">{{ $t('agent.think')
}}</span>
<span v-else-if="getThinkingSummary(event)" class="action-summary">{{ getThinkingSummary(event)
}}</span>
<span v-else-if="getThinkingSummary(event)" class="action-summary">{{ getThinkingSummary(event)
}}</span>
</div>
</div>
<div v-if="event.content && isEventExpanded(event.event_id)" class="action-details">
@@ -243,7 +243,7 @@
<span class="action-title-icon icon-mask" :style="maskIconStyle(thinkingIcon)" aria-hidden="true" />
<span class="action-name">{{ $t('agent.think') }}</span>
<span v-if="event.tool_data?.thought_number" class="action-badge">{{ event.tool_data.thought_number
}}/{{ event.tool_data.total_thoughts }}</span>
}}/{{ event.tool_data.total_thoughts }}</span>
<span v-if="getThinkingSummary(event) && !isEventExpanded(event.tool_call_id)"
class="action-summary">{{ getThinkingSummary(event) }}</span>
</div>
@@ -260,7 +260,8 @@
<div v-else-if="event.type === 'answer' && (event.done || (event.content && event.content.trim()))"
class="answer-event">
<div v-if="event.content && event.content.trim()" class="answer-content markdown-content">
<div v-stable-html="renderAnswerContent(event === activeAnswerEventRef ? typedAnswer : event.content)"></div>
<div v-stable-html="renderAnswerContent(event === activeAnswerEventRef ? typedAnswer : event.content)">
</div>
</div>
<div v-if="event.done && event.content && event.content.trim() && !embeddedMode" class="answer-toolbar">
<t-button size="small" variant="outline" shape="round" @click.stop="handleCopyAnswer(event)"
@@ -2621,11 +2622,11 @@ const handleAddToKnowledge = (answerEvent: any) => {
0%,
60%,
100% {
transform: translateY(0);
transform: translate3d(0, 0, 0);
}
30% {
transform: translateY(-8px);
transform: translate3d(0, -5px, 0);
}
}
@@ -2962,6 +2963,10 @@ const handleAddToKnowledge = (answerEvent: any) => {
border-radius: 50%;
background: var(--td-text-color-placeholder);
animation: typingBounce 1.4s ease-in-out infinite;
// Composite each dot so the bounce stays smooth and ghost-free while the
// streaming answer relayouts every token.
will-change: transform;
backface-visibility: hidden;
&:nth-child(1) {
animation-delay: 0s;
@@ -459,6 +459,10 @@ onBeforeUnmount(() => {
border-radius: 50%;
background: var(--td-brand-color);
animation: typingBounce 1.4s ease-in-out infinite;
// Composite the dots so the bounce stays smooth and ghost-free while the
// answer relayouts each streamed token.
will-change: transform;
backface-visibility: hidden;
&:nth-child(1) {
animation-delay: 0s;
@@ -479,11 +483,11 @@ onBeforeUnmount(() => {
0%,
60%,
100% {
transform: translateY(0);
transform: translate3d(0, 0, 0);
}
30% {
transform: translateY(-8px);
transform: translate3d(0, -6px, 0);
}
}
+39 -3
View File
@@ -145,6 +145,9 @@ const renderStreamMarkdown = (raw: string): string => {
renderer: mermaidRenderer,
escapeMarkdown: (markdown) => markdown,
sanitizeHtml: sanitizeMarkdownHTML,
// Match production: the live chat marks unfinished answers as streaming so
// mid-stream guards (dangling emphasis, trailing rules) are exercised here.
streaming: isStreaming.value,
cachedMermaidSvgHtml: streamMermaidSvgHtml.value,
prepareMarkdown: prepareStreamingMermaidMarkdown,
injectCachedMermaidSvg,
@@ -260,7 +263,38 @@ graph TD
`;
// --- Streaming Simulation ---
const fullStreamText = `The energy-mass equivalence is $E = mc^2$.
const fullStreamText = `
**XBRL(eXtensible Business Reporting Language,可扩展商业报告语言)**是一种基于XML的标准化标记语言,专门用于电子化商业和财务报告的编制、交换和分析
该数据集包含90个文本和方程对,挑战模型提取、解释和推理相互关联的财务术语和公式的能力,例如:
\`\`\`
APR = ((Fees + Interest) / Principal) × (365 / Days in Loan Term)
\`\`\`
<kb doc="2502.08127v1.pdf" chunk_id="1ecdce8a-f922-4d0c-b124-257ab4634da2" />
### 重要性
1. **AAAAA**
- **BBBBB**
- **CCCCC**
1. **AAA**
2. **BBB**
3. **CCC**
4. **DDD**
5. **EEE**
6. **FFF**
7. **GGG**
8. **HHH**
9. **III**
**标题:JJJ**
**标题:KKK**
The energy-mass equivalence is $E = mc^2$.
In chemistry, the neutralization reaction:
@@ -530,6 +564,8 @@ watch(customInput, () => {
border-radius: 50%;
background: var(--td-brand-color, #0052d9);
animation: typingBounce 1.4s ease-in-out infinite;
will-change: transform;
backface-visibility: hidden;
&:nth-child(1) {
animation-delay: 0s;
@@ -550,11 +586,11 @@ watch(customInput, () => {
0%,
60%,
100% {
transform: translateY(0);
transform: translate3d(0, 0, 0);
}
30% {
transform: translateY(-8px);
transform: translate3d(0, -6px, 0);
}
}