YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
feat: add think markdown component (#1468)
shaik-zeeshan52e3ca507695
diff --git a/pipes/rewind/src/components/chat-message.tsx b/pipes/rewind/src/components/chat-message.tsxindex 9b08f3d11..762f3031b 100644--- a/pipes/rewind/src/components/chat-message.tsx+++ b/pipes/rewind/src/components/chat-message.tsx@@ -1,14 +1,21 @@import { Message } from "ai";import remarkGfm from "remark-gfm";import remarkMath from "remark-math";+import { useState, useEffect, useRef } from "react";import { cn } from "@/lib/utils";import { CodeBlock } from "@/components/ui/codeblock";import { MemoizedReactMarkdown } from "@/components/markdown";-import { IconOpenAI, IconUser, IconOllama } from "@/components/ui/icons";+import {+ IconOpenAI,+ IconUser,+ IconClaude,+ IconGemini,+} from "@/components/ui/icons";import { ChatMessageActions } from "@/components/chat-message-actions";import { useSettings } from "@/lib/hooks/use-settings";import { VideoComponent } from "./video";+import { ArrowDown, ChevronDown } from "lucide-react";export interface ChatMessageProps {message: Message;@@ -16,6 +23,52 @@ export interface ChatMessageProps {export function ChatMessage({ message, ...props }: ChatMessageProps) {const { settings } = useSettings();+ const [isThinking, setIsThinking] = useState(false);+ const [thinkingContent, setThinkingContent] = useState<string[]>([]);+ const [thinkingTime, setThinkingTime] = useState(0);+ const [isExpanded, setIsExpanded] = useState(false);+ const timerRef = useRef<NodeJS.Timeout | null>(null);++ useEffect(() => {+ if (!message?.content) return;++ const openTag = /<think>/g.test(message.content);+ const closeTag = /<\/think>/g.test(message.content);++ const matches = message.content.match(/<think>([\s\S]*?)(?:<\/think>|$)/g);+ if (matches) {+ const contents = matches.map((match) =>+ match.replace(/<think>|<\/think>/g, "").trim(),+ );+ setThinkingContent(contents);+ }++ if (openTag && !closeTag) {+ setIsThinking(true);+ } else if (openTag && closeTag) {+ setIsThinking(true);+ clearTimeout(timerRef.current ?? undefined);+ } else {+ setIsThinking(false);+ setThinkingContent([]);+ setThinkingTime(0);+ }+ }, [message.content]);++ useEffect(() => {+ if (isThinking) {+ timerRef.current = setInterval(() => {+ setThinkingTime((prev) => prev + 1);+ }, 1000);+ }+ return () => {+ clearInterval(timerRef.current ?? undefined);+ };+ }, [isThinking]);++ const processThinkContent = (content: string) => {+ return content.replace(/<think>[\s\S]*?(<\/think>|$)/g, "").trim();+ };const hasMP4File = (content: string) =>content.trim().toLowerCase().includes(".mp4");@@ -39,14 +92,61 @@ export function ChatMessage({ message, ...props }: ChatMessageProps) {>{message.role === "user" ? (<IconUser />- ) : settings?.aiUrl?.includes("openai") ||- settings?.aiUrl?.includes("worker") ? (+ ) : settings?.aiModel?.includes("gpt") ? (<IconOpenAI />+ ) : settings?.aiModel?.includes("claude") ? (+ <IconClaude />+ ) : settings?.aiModel?.includes("gemini") ? (+ <IconGemini />) : (<>🦙</>)}</div><div className="flex-1 px-1 ml-4 space-y-2 overflow-hidden w-[96em]">+ {isThinking && thinkingContent.length > 0 && (+ <div+ className={cn(+ "my-2 rounded-lg border transition-all duration-300",+ "bg-muted/50 border-muted-foreground/20 text-muted-foreground",+ )}+ >+ <button+ onClick={() => setIsExpanded(!isExpanded)}+ className="w-full p-3 flex items-center gap-2 hover:bg-muted/70 transition-colors"+ >+ <span className="animate-pulse">💭</span>+ <span className="text-sm text-muted-foreground flex-1 text-left">+ {isThinking+ ? `Thinking... (${thinkingTime}s)`+ : `Thought for ${thinkingTime}s`}+ </span>+ <span+ className={cn(+ "transform transition-transform duration-200",+ isExpanded ? "rotate-180" : "",+ )}+ >+ <ChevronDown />+ </span>+ </button>+ <div+ className={cn(+ "transition-all duration-300 overflow-hidden",+ isExpanded ? "opacity-100" : "max-h-0 opacity-0",+ )}+ >+ <div className="p-3 pt-0">+ <div className="pl-4 border-l-2 border-muted-foreground/20">+ {thinkingContent.map((content, index) => (+ <p key={index} className="mb-2 last:mb-0">+ {content}+ </p>+ ))}+ </div>+ </div>+ </div>+ </div>+ )}<MemoizedReactMarkdownclassName="prose break-words dark:prose-invert prose-p:leading-relaxed prose-pre:p-0 w-full"remarkPlugins={[remarkGfm, remarkMath]}@@ -102,7 +202,7 @@ export function ChatMessage({ message, ...props }: ChatMessageProps) {},}}>- {message.content}+ {processThinkContent(message.content)}</MemoizedReactMarkdown><ChatMessageActions message={message} /></div>diff --git a/pipes/rewind/src/components/ui/icons.tsx b/pipes/rewind/src/components/ui/icons.tsxindex 492377647..cd613369b 100644--- a/pipes/rewind/src/components/ui/icons.tsx+++ b/pipes/rewind/src/components/ui/icons.tsx@@ -559,6 +559,61 @@ function IconOllama({ className, ...props }: React.ComponentProps<"svg">) {);}+function IconClaude({ className, ...props }: React.ComponentProps<"svg">) {+ return (+ <svg+ height="1em"+ style={{ flex: "none", lineHeight: "1" }}+ viewBox="0 0 24 24"+ width="1em"+ xmlns="http://www.w3.org/2000/svg"+ >+ <title>Claude</title>+ <path+ d="M4.709 15.955l4.72-2.647.08-.23-.08-.128H9.2l-.79-.048-2.698-.073-2.339-.097-2.266-.122-.571-.121L0 11.784l.055-.352.48-.321.686.06 1.52.103 2.278.158 1.652.097 2.449.255h.389l.055-.157-.134-.098-.103-.097-2.358-1.596-2.552-1.688-1.336-.972-.724-.491-.364-.462-.158-1.008.656-.722.881.06.225.061.893.686 1.908 1.476 2.491 1.833.365.304.145-.103.019-.073-.164-.274-1.355-2.446-1.446-2.49-.644-1.032-.17-.619a2.97 2.97 0 01-.104-.729L6.283.134 6.696 0l.996.134.42.364.62 1.414 1.002 2.229 1.555 3.03.456.898.243.832.091.255h.158V9.01l.128-1.706.237-2.095.23-2.695.08-.76.376-.91.747-.492.584.28.48.685-.067.444-.286 1.851-.559 2.903-.364 1.942h.212l.243-.242.985-1.306 1.652-2.064.73-.82.85-.904.547-.431h1.033l.76 1.129-.34 1.166-1.064 1.347-.881 1.142-1.264 1.7-.79 1.36.073.11.188-.02 2.856-.606 1.543-.28 1.841-.315.833.388.091.395-.328.807-1.969.486-2.309.462-3.439.813-.042.03.049.061 1.549.146.662.036h1.622l3.02.225.79.522.474.638-.079.485-1.215.62-1.64-.389-3.829-.91-1.312-.329h-.182v.11l1.093 1.068 2.006 1.81 2.509 2.33.127.578-.322.455-.34-.049-2.205-1.657-.851-.747-1.926-1.62h-.128v.17l.444.649 2.345 3.521.122 1.08-.17.353-.608.213-.668-.122-1.374-1.925-1.415-2.167-1.143-1.943-.14.08-.674 7.254-.316.37-.729.28-.607-.461-.322-.747.322-1.476.389-1.924.315-1.53.286-1.9.17-.632-.012-.042-.14.018-1.434 1.967-2.18 2.945-1.726 1.845-.414.164-.717-.37.067-.662.401-.589 2.388-3.036 1.44-1.882.93-1.086-.006-.158h-.055L4.132 18.56l-1.13.146-.487-.456.061-.746.231-.243 1.908-1.312-.006.006z"+ fill="#D97757"+ fillRule="nonzero"+ ></path>+ </svg>+ );+}++function IconGemini({ className, ...props }: React.ComponentProps<"svg">) {+ const id = React.useId();++ return (+ <svg+ height="1em"+ style={{ flex: "none", lineHeight: "1" }}+ viewBox="0 0 24 24"+ width="1em"+ xmlns="http://www.w3.org/2000/svg"+ className={cn("size-4", className)}+ {...props}+ >+ <title>Gemini</title>+ <defs>+ <linearGradient+ id={`gemini-gradient-${id}`}+ x1="0%"+ x2="68.73%"+ y1="100%"+ y2="30.395%"+ >+ <stop offset="0%" stopColor="#1C7DFF" />+ <stop offset="52.021%" stopColor="#1C69FF" />+ <stop offset="100%" stopColor="#F0DCD6" />+ </linearGradient>+ </defs>+ <path+ d="M12 24A14.304 14.304 0 000 12 14.304 14.304 0 0012 0a14.305 14.305 0 0012 12 14.305 14.305 0 00-12 12"+ fill={`url(#gemini-gradient-${id})`}+ fillRule="nonzero"+ />+ </svg>+ );+}+export {IconOllama,IconEdit,@@ -590,4 +645,6 @@ export {IconChevronUpDown,IconLlama,IconCode,+ IconClaude,+ IconGemini,};diff --git a/pipes/search/src/components/chat-message.tsx b/pipes/search/src/components/chat-message.tsxindex 969429bdd..b62c58f61 100644--- a/pipes/search/src/components/chat-message.tsx+++ b/pipes/search/src/components/chat-message.tsx@@ -1,6 +1,7 @@import { Message } from "ai";import remarkGfm from "remark-gfm";import remarkMath from "remark-math";+import { useState, useEffect, useRef } from "react";import { cn } from "@/lib/utils";import { CodeBlock } from "@/components/ui/codeblock";@@ -8,13 +9,13 @@ import { MemoizedReactMarkdown } from "@/components/markdown";import {IconOpenAI,IconUser,- IconOllama,IconClaude,IconGemini,} from "@/components/ui/icons";import { ChatMessageActions } from "@/components/chat-message-actions";import { useSettings } from "@/lib/hooks/use-settings";import { VideoComponent } from "./video";+import { ArrowDown, ChevronDown } from "lucide-react";export interface ChatMessageProps {message: Message;@@ -22,6 +23,52 @@ export interface ChatMessageProps {export function ChatMessage({ message, ...props }: ChatMessageProps) {const { settings } = useSettings();+ const [isThinking, setIsThinking] = useState(false);+ const [thinkingContent, setThinkingContent] = useState<string[]>([]);+ const [thinkingTime, setThinkingTime] = useState(0);+ const [isExpanded, setIsExpanded] = useState(false);+ const timerRef = useRef<NodeJS.Timeout | null>(null);++ useEffect(() => {+ if (!message?.content) return;++ const openTag = /<think>/g.test(message.content);+ const closeTag = /<\/think>/g.test(message.content);++ const matches = message.content.match(/<think>([\s\S]*?)(?:<\/think>|$)/g);+ if (matches) {+ const contents = matches.map((match) =>+ match.replace(/<think>|<\/think>/g, "").trim(),+ );+ setThinkingContent(contents);+ }++ if (openTag && !closeTag) {+ setIsThinking(true);+ } else if (openTag && closeTag) {+ setIsThinking(true);+ clearTimeout(timerRef.current ?? undefined);+ } else {+ setIsThinking(false);+ setThinkingContent([]);+ setThinkingTime(0);+ }+ }, [message.content]);++ useEffect(() => {+ if (isThinking) {+ timerRef.current = setInterval(() => {+ setThinkingTime((prev) => prev + 1);+ }, 1000);+ }+ return () => {+ clearInterval(timerRef.current ?? undefined);+ };+ }, [isThinking]);++ const processThinkContent = (content: string) => {+ return content.replace(/<think>[\s\S]*?(<\/think>|$)/g, "").trim();+ };const hasMP4File = (content: string) =>content.trim().toLowerCase().includes(".mp4");@@ -40,22 +87,66 @@ export function ChatMessage({ message, ...props }: ChatMessageProps) {"flex size-8 shrink-0 select-none items-center justify-center rounded-md border shadow",message.role === "user"? "bg-background"- : "bg-primary text-primary-foreground"+ : "bg-primary text-primary-foreground",)}>{message.role === "user" ? (<IconUser />- ) : settings.aiModel.includes("gpt") ? (+ ) : settings?.aiModel?.includes("gpt") ? (<IconOpenAI />- ) : settings.aiModel.includes("claude") ? (+ ) : settings?.aiModel?.includes("claude") ? (<IconClaude />- ) : settings.aiModel.includes("gemini") ? (+ ) : settings?.aiModel?.includes("gemini") ? (<IconGemini />) : (<>🦙</>)}</div><div className="flex-1 px-1 ml-4 space-y-2 overflow-hidden w-[96em]">+ {isThinking && thinkingContent.length > 0 && (+ <div+ className={cn(+ "my-2 rounded-lg border transition-all duration-300",+ "bg-muted/50 border-muted-foreground/20 text-muted-foreground",+ )}+ >+ <button+ onClick={() => setIsExpanded(!isExpanded)}+ className="w-full p-3 flex items-center gap-2 hover:bg-muted/70 transition-colors"+ >+ <span className="animate-pulse">💭</span>+ <span className="text-sm text-muted-foreground flex-1 text-left">+ {isThinking+ ? `Thinking... (${thinkingTime}s)`+ : `Thought for ${thinkingTime}s`}+ </span>+ <span+ className={cn(+ "transform transition-transform duration-200",+ isExpanded ? "rotate-180" : "",+ )}+ >+ <ChevronDown />+ </span>+ </button>+ <div+ className={cn(+ "transition-all duration-300 overflow-hidden",+ isExpanded ? "opacity-100" : "max-h-0 opacity-0",+ )}+ >+ <div className="p-3 pt-0">+ <div className="pl-4 border-l-2 border-muted-foreground/20">+ {thinkingContent.map((content, index) => (+ <p key={index} className="mb-2 last:mb-0">+ {content}+ </p>+ ))}+ </div>+ </div>+ </div>+ </div>+ )}<MemoizedReactMarkdownclassName="prose break-words dark:prose-invert prose-p:leading-relaxed prose-pre:p-0 w-full"remarkPlugins={[remarkGfm, remarkMath]}@@ -111,7 +202,7 @@ export function ChatMessage({ message, ...props }: ChatMessageProps) {},}}>- {message.content}+ {processThinkContent(message.content)}</MemoizedReactMarkdown><ChatMessageActions message={message} /></div>