diff --git a/frontend/src/components/css/chat-markdown.less b/frontend/src/components/css/chat-markdown.less
index 25d0fe19..1a3fe844 100644
--- a/frontend/src/components/css/chat-markdown.less
+++ b/frontend/src/components/css/chat-markdown.less
@@ -16,6 +16,21 @@
letter-spacing: normal;
-webkit-font-smoothing: antialiased;
+ // Trailing fade on the newest streamed characters: the tail is wrapped in
+ // this span (see applyStreamingTailFade) so its right edge dissolves, giving
+ // a soft "just typed" reveal that settles once streaming stops and the wrap
+ // is no longer emitted.
+ :deep(.stream-fade-tail) {
+ -webkit-mask-image: linear-gradient(to right,
+ rgba(0, 0, 0, 1) 0%,
+ rgba(0, 0, 0, 0.7) 30%,
+ rgba(0, 0, 0, 0) 100%);
+ mask-image: linear-gradient(to right,
+ rgba(0, 0, 0, 1) 0%,
+ rgba(0, 0, 0, 0.7) 30%,
+ rgba(0, 0, 0, 0) 100%);
+ }
+
:deep(p) {
margin: 0 0 0.25em;
line-height: 1.625;
diff --git a/frontend/src/components/css/chat-timeline-loading.less b/frontend/src/components/css/chat-timeline-loading.less
index dcd6f624..2a68dc44 100644
--- a/frontend/src/components/css/chat-timeline-loading.less
+++ b/frontend/src/components/css/chat-timeline-loading.less
@@ -23,6 +23,61 @@
}
}
+// A light sweep across in-progress text (the "光影" / shimmer effect). The base
+// is the muted secondary color and a brighter band slides across, signalling
+// "this step is still running" without the layout cost of a spinner.
+// One full gradient width (background-size is 200%) so the loop is seamless.
+@keyframes chatStreamShimmer {
+ 0% {
+ background-position: 100% 50%;
+ }
+
+ 100% {
+ background-position: -100% 50%;
+ }
+}
+
+.chat-stream-shimmer-text() {
+ // Stronger contrast: a dim placeholder base with a bright primary glint, so
+ // the sweeping band reads clearly rather than as a subtle shift.
+ background-image: linear-gradient(100deg,
+ var(--td-text-color-placeholder) 0%,
+ var(--td-text-color-placeholder) 36%,
+ var(--td-text-color-primary) 50%,
+ var(--td-text-color-placeholder) 64%,
+ var(--td-text-color-placeholder) 100%);
+ background-size: 200% 100%;
+ // Let the gradient tile (default repeat): the dim stops on both ends match,
+ // so the element is always fully painted and the band sweeps seamlessly.
+ // (no-repeat would leave the uncovered area transparent -> invisible text.)
+ -webkit-background-clip: text;
+ background-clip: text;
+ -webkit-text-fill-color: transparent;
+ color: transparent;
+ animation: chatStreamShimmer 1.5s linear infinite;
+ // Keep the sweep on its own compositor layer so it stays smooth while the
+ // surrounding timeline relayouts on each streamed token.
+ will-change: background-position;
+}
+
+// In-progress step / thinking / tool-call titles shimmer while pending. Both the
+// agent timeline (.action-pending) and the RAG pipeline (.is-running) opt in.
+.action-card.action-pending .action-name,
+.action-name.is-running {
+ .chat-stream-shimmer-text();
+}
+
+@media (prefers-reduced-motion: reduce) {
+
+ .action-card.action-pending .action-name,
+ .action-name.is-running {
+ animation: none;
+ background-image: none;
+ -webkit-text-fill-color: var(--td-text-color-secondary);
+ color: var(--td-text-color-secondary);
+ }
+}
+
.streaming-loading-node {
.tree-child-content {
position: relative;
diff --git a/frontend/src/components/css/chat-timeline-loading.test.mjs b/frontend/src/components/css/chat-timeline-loading.test.mjs
index 01e80735..45620ae2 100644
--- a/frontend/src/components/css/chat-timeline-loading.test.mjs
+++ b/frontend/src/components/css/chat-timeline-loading.test.mjs
@@ -14,3 +14,17 @@ test('timeline loading uses shared gray bounce dots on the axis', () => {
assert.match(css, /animation:\s*chatTimelineTypingBounce/)
assert.match(css, /animation-delay:\s*0\.2s/)
})
+
+test('in-progress step titles get the streaming shimmer sweep', () => {
+ // Both timelines opt into the shimmer: agent (.action-pending) and RAG (.is-running).
+ assert.match(css, /\.action-card\.action-pending \.action-name,\s*\.action-name\.is-running/)
+ assert.match(css, /-webkit-background-clip:\s*text/)
+ assert.match(css, /animation:\s*chatStreamShimmer/)
+ assert.match(css, /@keyframes chatStreamShimmer/)
+})
+
+test('shimmer is disabled under reduced motion', () => {
+ assert.match(css, /@media \(prefers-reduced-motion: reduce\)/)
+ const reducedBlock = css.slice(css.indexOf('@media (prefers-reduced-motion: reduce)'))
+ assert.match(reducedBlock, /animation:\s*none/)
+})
diff --git a/frontend/src/utils/_repro_gap.mjs b/frontend/src/utils/_repro_gap.mjs
index c5ccdd01..e42f3e50 100644
--- a/frontend/src/utils/_repro_gap.mjs
+++ b/frontend/src/utils/_repro_gap.mjs
@@ -1,30 +1,15 @@
-import {
- createChatMarkdownRenderer,
- renderChatMarkdown,
-} from './chatMarkdownRenderer.ts'
-import { joinCitationTagsToPreviousLine } from './citationMarkdown.ts'
+import { applyStreamingTailFade } from './chatMarkdownRenderer.ts'
-const renderer = createChatMarkdownRenderer()
-const snippet = [
- '该数据集...例如:',
- '```',
- 'APR = ((Fees + Interest) / Principal) × (365 / Days in Loan Term)',
- '```',
- '
Great, that narrows it down a lot. Two more quick
', + 'Great, that narrows it down a lot. Two more quick
\n', + '结尾是引用 doc
', + '', '', - '### 重要性', - '', - '1. **AAAAA**', -].join('\n') - -console.log('--- joinCitationTagsToPreviousLine output ---') -console.log(JSON.stringify(joinCitationTagsToPreviousLine(snippet))) - -console.log('\n--- final render ---') -console.log(renderChatMarkdown(snippet, { - renderer, - escapeMarkdown: (t) => t, - sanitizeHtml: (h) => h, - streaming: false, - knowledgeReferences: [{ doc: '2502.08127v1.pdf', chunk_id: '1ecdce8a-f922-4d0c-b124-257ab4634da2' }], -})) +] +for (const c of cases) { + console.log('IN :', JSON.stringify(c)) + console.log('OUT:', JSON.stringify(applyStreamingTailFade(c))) + console.log('') +} diff --git a/frontend/src/utils/chatMarkdownRenderer.test.ts b/frontend/src/utils/chatMarkdownRenderer.test.ts index 6e6af566..28ea9ce1 100644 --- a/frontend/src/utils/chatMarkdownRenderer.test.ts +++ b/frontend/src/utils/chatMarkdownRenderer.test.ts @@ -2,6 +2,7 @@ import assert from 'node:assert/strict' import test from 'node:test' import { + applyStreamingTailFade, closeDanglingStreamingEmphasis, createChatMarkdownRenderer, markStandaloneStrongParagraphs, @@ -25,6 +26,11 @@ const SAMPLE_CHUNK_B = '00000002-0000-4000-8000-000000000002' const SAMPLE_CHUNK_C = '00000003-0000-4000-8000-000000000003' const SAMPLE_CHUNK_PRESERVE = 'aaaaaaaa-bbbb-4ccc-8ddd-eeeeeeeeeeee' +/** Remove the streaming tail-fade wrapper so structural assertions stay focused. */ +function stripFadeTail(html: string): string { + return html.replace(/([\s\S]*?)<\/span>/g, '$1') +} + test('preprocessMathDelimiters converts escaped math delimiters for marked-katex', () => { assert.equal( preprocessMathDelimiters('inline \\(a+b\\) and block \\[x^2\\]'), @@ -103,7 +109,7 @@ test('renderChatMarkdown renders an unfinished bold line as bold immediately whi const partial = '**平台访问地址:chatbot.weixin.qq.com' // Streaming: optimistically bold so no raw `**` and no late layout jump. assert.match( - renderChatMarkdown(partial, { ...options, streaming: true }), + stripFadeTail(renderChatMarkdown(partial, { ...options, streaming: true })), /平台访问地址:chatbot\.weixin\.qq\.com<\/strong><\/p>/,
)
// Completed: a genuinely unterminated marker stays literal (we never invent
@@ -141,7 +147,7 @@ test('renderChatMarkdown bolds punctuation-adjacent emphasis both mid-stream and
const text = '**XBRL(语言)**是一种标准'
for (const streaming of [true, false]) {
assert.match(
- renderChatMarkdown(text, { ...options, streaming }),
+ stripFadeTail(renderChatMarkdown(text, { ...options, streaming })),
/XBRL(语言)<\/strong>是一种标准/,
)
}
@@ -172,7 +178,7 @@ test('renderChatMarkdown does not flash a setext heading when a nested bullet da
// must not flash Great, that narrows it down a lot. Two more quick
+ The "light sweep" applied to in-progress step titles in
+ AgentStreamDisplay / RagPipelineProgress. Running steps shimmer; finished ones are static.
+ , and the next bullet's `*`/`**` (before its text) must
// not flash an empty nested
/)
assert.match(html, /
\s*
`) are skipped so
+ // they do not win the "last run" and suppress the fade.
+ let lastMatch: RegExpExecArray | null = null
+ let match: RegExpExecArray | null
+ TAIL_TEXT_RE.lastIndex = 0
+ while ((match = TAIL_TEXT_RE.exec(html)) !== null) {
+ if (match[1].trim()) lastMatch = match
+ }
+ if (!lastMatch) return html
+
+ const text = lastMatch[1]
+
+ const textStart = lastMatch.index + 1
+ const textEnd = textStart + text.length
+ const chars = Array.from(text)
+ const tailChars = chars.slice(Math.max(0, chars.length - tailLength))
+ const tail = tailChars.join('')
+ // Fade only the trailing run, keeping any leading whitespace outside the span.
+ const tailTrimmed = tail.replace(/^\s+/, '')
+ if (!tailTrimmed) return html
+ const head = text.slice(0, text.length - tailTrimmed.length)
+ const wrapped = `${head}${tailTrimmed}`
+ return html.slice(0, textStart) + wrapped + html.slice(textEnd)
+}
+
export function createChatMarkdownRenderer(options: ChatMarkdownRendererOptions = {}): Renderer {
const renderer = new marked.Renderer()
@@ -335,7 +375,8 @@ export function renderChatMarkdown(rawMarkdown: unknown, options: RenderChatMark
const tableWrappedHtml = wrapChatMarkdownTables(citationHtml)
const strongTitleHtml = markStandaloneStrongParagraphs(tableWrappedHtml)
const sanitized = options.sanitizeHtml(strongTitleHtml)
- return options.injectCachedMermaidSvg
+ const withMermaid = options.injectCachedMermaidSvg
? options.injectCachedMermaidSvg(sanitized, options.cachedMermaidSvgHtml)
: sanitized
+ return options.streaming ? applyStreamingTailFade(withMermaid) : withMermaid
}
diff --git a/frontend/src/views/chat/components/RagPipelineProgress.vue b/frontend/src/views/chat/components/RagPipelineProgress.vue
index fc5a7842..e66b77cf 100644
--- a/frontend/src/views/chat/components/RagPipelineProgress.vue
+++ b/frontend/src/views/chat/components/RagPipelineProgress.vue
@@ -30,7 +30,7 @@
\n
')
+ assert.match(out, /Streaming Shimmer
+ Custom Input
@@ -441,6 +467,7 @@ watch(customInput, () => {
@import '../../components/css/chat-markdown.less';
@import '../../components/css/chat-citations.less';
@import '../../components/css/chat-message-shared.less';
+@import '../../components/css/chat-timeline-loading.less';
.markdown-test-page {
max-width: 860px;
@@ -594,6 +621,22 @@ watch(customInput, () => {
}
}
+.shimmer-demo {
+ display: flex;
+ flex-direction: column;
+ gap: 14px;
+
+ .action-card {
+ background: transparent;
+ }
+
+ .action-name {
+ font-size: 14px;
+ line-height: 1.55;
+ color: var(--td-text-color-secondary);
+ }
+}
+
// Chat answer markdown — shared with botmsg / AgentStreamDisplay / embed
.markdown-content {
// Dev page intentionally uses the same chat Markdown mixin as runtime chat.