feat(ai): add shiny text on ai reasoning

- Integrated `ShinyText` into `AIChainOfThought` for improved visual feedback during reasoning.
- Updated `AIMessageParts` to conditionally render reasoning parts only if text is present, enhancing logic clarity.
- Introduced `useDeferredValue` for low-priority rendering of display parts, optimizing performance.

These changes aim to improve the user experience by providing clearer visual cues and more efficient rendering in the AI chat interface.

Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
Innei
2025-09-23 21:15:26 +08:00
parent 304755aba3
commit c840fa62ca
4 changed files with 65 additions and 6 deletions
@@ -1,5 +1,6 @@
import type { CollapseCssRef } from "@follow/components/ui/collapse/CollapseCss.js"
import { CollapseCss, CollapseCssGroup } from "@follow/components/ui/collapse/CollapseCss.js"
import { ShinyText } from "@follow/components/ui/shiny-text/ShinyText.js"
import { cn } from "@follow/utils"
import type { ReasoningUIPart } from "ai"
import * as React from "react"
@@ -33,8 +34,6 @@ export const AIChainOfThought: React.FC<AIChainOfThoughtProps> = React.memo(
return (
<div className={cn("border-border min-w-0 max-w-full text-left", className)}>
<div className="w-[calc(var(--ai-chat-layout-width,65ch))] max-w-full" />
<CollapseCssGroup>
<CollapseCss
ref={collapseRef}
@@ -46,8 +45,9 @@ export const AIChainOfThought: React.FC<AIChainOfThoughtProps> = React.memo(
<div className="flex items-center gap-2 text-xs">
<span className="text-text-secondary">
{!currentChainReasoningIsFinished ? (
<span>
Thinking: <span className="font-medium">{currentReasoningTitle}</span>
<span className="flex items-center gap-2">
Thinking:{" "}
<ShinyText className="font-medium" text={currentReasoningTitle ?? ""} />
</span>
) : (
"Finished Thinking"
@@ -62,7 +62,7 @@ export const AIMessageParts: React.FC<AIMessagePartsProps> = React.memo(
parts.push(part)
} else if (part.type.startsWith("tool-display")) {
parts.push(part as ToolUIPart<BizUITools>)
} else if (part.type === "reasoning") {
} else if (part.type === "reasoning" && part.text) {
mergedReasoningParts.push(part as ReasoningUIPart)
}
}
@@ -73,9 +73,11 @@ export const AIMessageParts: React.FC<AIMessagePartsProps> = React.memo(
return parts
}, [message.parts])
const lowPriorityParts = React.useDeferredValue(displayParts)
return (
<>
{displayParts.map((partOrParts, index) => {
{lowPriorityParts.map((partOrParts, index) => {
const partKey = `${message.id}-${index}`
if (Array.isArray(partOrParts)) {
@@ -0,0 +1,29 @@
import { clsx } from "@follow/utils"
import * as React from "react"
import styles from "./index.module.css"
interface ShinyTextProps {
text: string
disabled?: boolean
speed?: number
className?: string
}
export const ShinyText: React.FC<ShinyTextProps> = ({
text,
disabled = false,
speed = 2,
className = "",
}) => {
const animationDuration = `${speed}s`
return (
<div
className={clsx(styles["shiny-text"], disabled ? styles["disabled"] : "", className)}
style={{ animationDuration }}
>
{text}
</div>
)
}
@@ -0,0 +1,28 @@
.shiny-text {
@apply text-text-secondary;
background-image: linear-gradient(
150deg,
rgba(255, 255, 255, 0) 40%,
rgba(255, 255, 255, 0.8) 50%,
rgba(255, 255, 255, 0) 60%
);
background-size: 200% 100%;
-webkit-background-clip: text;
background-clip: text;
display: inline-block;
animation: shine 5s linear infinite;
}
@keyframes shine {
0% {
background-position: 100%;
}
100% {
background-position: -100%;
}
}
.shiny-text.disabled {
animation: none;
}