From e9a3f97473eb48d5b40584d12e2b309eb3acab7e Mon Sep 17 00:00:00 2001 From: ferenci84 Date: Tue, 11 Mar 2025 22:11:10 +0100 Subject: [PATCH] add inProgress prop and update ThinkingBlockPeek component to handle thinking state and elapsed time --- .../mainInput/ThinkingBlockPeek.tsx | 127 ++++++++++++++---- gui/src/pages/gui/Chat.tsx | 1 + 2 files changed, 103 insertions(+), 25 deletions(-) diff --git a/gui/src/components/mainInput/ThinkingBlockPeek.tsx b/gui/src/components/mainInput/ThinkingBlockPeek.tsx index 013415e73..851635230 100644 --- a/gui/src/components/mainInput/ThinkingBlockPeek.tsx +++ b/gui/src/components/mainInput/ThinkingBlockPeek.tsx @@ -1,15 +1,71 @@ // src/components/ThinkingBlockPeek.tsx -import { - ChevronDownIcon, - ChevronRightIcon, - LightBulbIcon, -} from "@heroicons/react/24/outline"; +import { ChevronDownIcon } from "@heroicons/react/24/outline"; +import { ChevronUpIcon } from "@heroicons/react/24/solid"; import { ChatHistoryItem } from "core"; -import { useState } from "react"; +import { useEffect, useState } from "react"; import styled from "styled-components"; -import { lightGray, vscBackground } from ".."; +import { defaultBorderRadius, lightGray, vscBackground } from ".."; +import { getFontSize } from "../../util"; import StyledMarkdownPreview from "../markdown/StyledMarkdownPreview"; +const SpoilerButton = styled.div` + background-color: ${vscBackground}; + width: fit-content; + margin: 8px 6px 0px 2px; + font-size: ${getFontSize() - 2}px; + border: 0.5px solid ${lightGray}; + border-radius: ${defaultBorderRadius}; + padding: 4px 8px; + color: ${lightGray}; + cursor: pointer; + box-shadow: + 0 4px 6px rgba(0, 0, 0, 0.1), + 0 1px 3px rgba(0, 0, 0, 0.08); + transition: box-shadow 0.3s ease; + + &:hover { + box-shadow: + 0 6px 8px rgba(0, 0, 0, 0.15), + 0 3px 6px rgba(0, 0, 0, 0.1); + } +`; + +const ButtonContent = styled.div` + display: flex; + align-items: center; + gap: 6px; +`; + +export const ThinkingText = styled.span` + position: relative; + padding-right: 12px; + + &:after { + content: "..."; + position: absolute; + animation: ellipsis 1s steps(4, end) infinite; + width: 0px; + display: inline-block; + overflow: hidden; + } + + @keyframes ellipsis { + 0%, + 100% { + width: 0px; + } + 33% { + width: 8px; + } + 66% { + width: 16px; + } + 90% { + width: 24px; + } + } +`; + const MarkdownWrapper = styled.div` & > div > *:first-child { margin-top: 0 !important; @@ -21,7 +77,9 @@ interface ThinkingBlockPeekProps { redactedThinking?: string; index: number; prevItem: ChatHistoryItem | null; + inProgress?: boolean; signature?: string; + tokens?: number; } function ThinkingBlockPeek({ @@ -29,9 +87,13 @@ function ThinkingBlockPeek({ redactedThinking, index, prevItem, + inProgress, signature, + tokens, }: ThinkingBlockPeekProps) { const [open, setOpen] = useState(false); + const [startTime, setStartTime] = useState(null); + const [elapsedTime, setElapsedTime] = useState(""); const duplicateRedactedThinkingBlock = prevItem && @@ -39,30 +101,45 @@ function ThinkingBlockPeek({ redactedThinking && prevItem.message.redactedThinking; + useEffect(() => { + if (inProgress) { + setStartTime(Date.now()); + setElapsedTime(""); + } else if (startTime) { + const endTime = Date.now(); + const diff = endTime - startTime; + const diffString = `${(diff / 1000).toFixed(1)}s`; + setElapsedTime(diffString); + } + }, [inProgress]); + return duplicateRedactedThinkingBlock ? null : (
setOpen((prev) => !prev)} + className="flex items-center justify-start pl-2 text-xs text-gray-300" data-testid="thinking-block-peek" > -
- - -
- - - {redactedThinking ? "Redacted Thinking" : "AI Reasoning"} - + setOpen((prev) => !prev)}> + + {inProgress ? ( + + {redactedThinking ? "Redacted Thinking" : "Thinking"} + + ) : redactedThinking ? ( + "Redacted Thinking" + ) : ( + "Thought" + + (elapsedTime ? ` for ${elapsedTime}` : "") + + (tokens ? ` (${tokens} tokens)` : "") + )} + {open ? ( + + ) : ( + + )} + +
0 ? history[index - 1] : null} + inProgress={index === history.length - 1} signature={item.message.signature} /> ) : (