diff --git a/components/message.tsx b/components/message.tsx index d9d7f17..3def9dc 100644 --- a/components/message.tsx +++ b/components/message.tsx @@ -6,6 +6,7 @@ import equal from 'fast-deep-equal'; import { AnimatePresence, motion } from 'framer-motion'; import { memo, useState } from 'react'; +import { useThinkingText } from '@/hooks/use-thinking-text'; import type { Vote } from '@/lib/db/schema'; import { cn } from '@/lib/utils'; @@ -206,6 +207,8 @@ export const PreviewMessage = memo( export const ThinkingMessage = () => { const role = 'assistant'; + const thinkingText = useThinkingText(); + return ( { -
-
- Thinking... -
+
+ + + {thinkingText} + +
diff --git a/hooks/use-thinking-text.ts b/hooks/use-thinking-text.ts new file mode 100644 index 0000000..d5f27d1 --- /dev/null +++ b/hooks/use-thinking-text.ts @@ -0,0 +1,30 @@ +import { useState, useEffect } from 'react'; + +/** + * A custom hook that returns a thinking text that changes every few seconds + * with an exponentially increasing interval. + * @param base - The base of the exponential function + * @returns The current thinking text + */ +export const useThinkingText = (base = 3) => { + const texts = [ + 'Thinking...', + 'Calling relevant tools...', + 'Fetching external data...', + 'Finalizing response...', + ]; + const [index, setIndex] = useState(0); + + useEffect(() => { + texts.slice(0, -1).map((_, textIndex) => { + setTimeout( + () => { + setIndex(textIndex + 1); + }, + 1000 * 3 ** (textIndex + 1), + ); + }); + }, []); + + return texts[index]; +};