| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120 |
- import { VSCodeBadge, VSCodeButton, VSCodeProgressRing } from "@vscode/webview-ui-toolkit/react"
- import deepEqual from "fast-deep-equal"
- import React, { memo, useEffect, useMemo, useRef, useState } from "react"
- import { useSize } from "react-use"
- import { useCopyToClipboard } from "../../utils/clipboard"
- import { useTranslation, Trans } from "react-i18next"
- import {
- ClineApiReqInfo,
- ClineAskUseMcpServer,
- ClineMessage,
- ClineSayTool,
- } from "../../../../src/shared/ExtensionMessage"
- import { COMMAND_OUTPUT_STRING } from "../../../../src/shared/combineCommandSequences"
- import { useExtensionState } from "../../context/ExtensionStateContext"
- import { findMatchingResourceOrTemplate } from "../../utils/mcp"
- import { vscode } from "../../utils/vscode"
- import CodeAccordian, { removeLeadingNonAlphanumeric } from "../common/CodeAccordian"
- import CodeBlock, { CODE_BLOCK_BG_COLOR } from "../common/CodeBlock"
- import MarkdownBlock from "../common/MarkdownBlock"
- import { ReasoningBlock } from "./ReasoningBlock"
- import Thumbnails from "../common/Thumbnails"
- import McpResourceRow from "../mcp/McpResourceRow"
- import McpToolRow from "../mcp/McpToolRow"
- import { highlightMentions } from "./TaskHeader"
- import { CheckpointSaved } from "./checkpoints/CheckpointSaved"
- import FollowUpSuggest from "./FollowUpSuggest"
- interface ChatRowProps {
- message: ClineMessage
- lastModifiedMessage?: ClineMessage
- isExpanded: boolean
- isLast: boolean
- isStreaming: boolean
- onToggleExpand: () => void
- onHeightChange: (isTaller: boolean) => void
- onSuggestionClick?: (answer: string) => void
- }
- interface ChatRowContentProps extends Omit<ChatRowProps, "onHeightChange"> {}
- const ChatRow = memo(
- (props: ChatRowProps) => {
- const { isLast, onHeightChange, message } = props
- // Store the previous height to compare with the current height
- // This allows us to detect changes without causing re-renders
- const prevHeightRef = useRef(0)
- const [chatrow, { height }] = useSize(
- <div className="px-[15px] py-[10px] pr-[6px]">
- <ChatRowContent {...props} />
- </div>,
- )
- useEffect(() => {
- // used for partials, command output, etc.
- // NOTE: it's important we don't distinguish between partial or complete here since our scroll effects in chatview need to handle height change during partial -> complete
- const isInitialRender = prevHeightRef.current === 0 // prevents scrolling when new element is added since we already scroll for that
- // height starts off at Infinity
- if (isLast && height !== 0 && height !== Infinity && height !== prevHeightRef.current) {
- if (!isInitialRender) {
- onHeightChange(height > prevHeightRef.current)
- }
- prevHeightRef.current = height
- }
- }, [height, isLast, onHeightChange, message])
- // we cannot return null as virtuoso does not support it, so we use a separate visibleMessages array to filter out messages that should not be rendered
- return chatrow
- },
- // memo does shallow comparison of props, so we need to do deep comparison of arrays/objects whose properties might change
- deepEqual,
- )
- export default ChatRow
- export const ChatRowContent = ({
- message,
- lastModifiedMessage,
- isExpanded,
- isLast,
- isStreaming,
- onToggleExpand,
- onSuggestionClick,
- }: ChatRowContentProps) => {
- const { t } = useTranslation()
- const { mcpServers, alwaysAllowMcp, currentCheckpoint } = useExtensionState()
- const [reasoningCollapsed, setReasoningCollapsed] = useState(true)
- const [cost, apiReqCancelReason, apiReqStreamingFailedMessage] = useMemo(() => {
- if (message.text !== null && message.text !== undefined && message.say === "api_req_started") {
- const info: ClineApiReqInfo = JSON.parse(message.text)
- return [info.cost, info.cancelReason, info.streamingFailedMessage]
- }
- return [undefined, undefined, undefined]
- }, [message.text, message.say])
- // When resuming task, last wont be api_req_failed but a resume_task
- // message, so api_req_started will show loading spinner. That's why we just
- // remove the last api_req_started that failed without streaming anything.
- const apiRequestFailedMessage =
- isLast && lastModifiedMessage?.ask === "api_req_failed" // if request is retried then the latest message is a api_req_retried
- ? lastModifiedMessage?.text
- : undefined
- const isCommandExecuting =
- isLast && lastModifiedMessage?.ask === "command" && lastModifiedMessage?.text?.includes(COMMAND_OUTPUT_STRING)
- const isMcpServerResponding = isLast && lastModifiedMessage?.say === "mcp_server_request_started"
- const type = message.type === "ask" ? message.ask : message.say
- const normalColor = "var(--vscode-foreground)"
- const errorColor = "var(--vscode-errorForeground)"
- const successColor = "var(--vscode-charts-green)"
- const cancelledColor = "var(--vscode-descriptionForeground)"
- const [icon, title] = useMemo(() => {
- switch (type) {
- case "error":
- return [
- <span
- className="codicon codicon-error"
- style={{ color: errorColor, marginBottom: "-1.5px" }}></span>,
- <span style={{ color: errorColor, fontWeight: "bold" }}>{t("chat:error")}</span>,
- ]
- case "mistake_limit_reached":
- return [
- <span
- className="codicon codicon-error"
- style={{ color: errorColor, marginBottom: "-1.5px" }}></span>,
- <span style={{ color: errorColor, fontWeight: "bold" }}>{t("chat:troubleMessage")}</span>,
- ]
- case "command":
- return [
- isCommandExecuting ? (
- <ProgressIndicator />
- ) : (
- <span
- className="codicon codicon-terminal"
- style={{ color: normalColor, marginBottom: "-1.5px" }}></span>
- ),
- <span style={{ color: normalColor, fontWeight: "bold" }}>{t("chat:runCommand.title")}:</span>,
- ]
- case "use_mcp_server":
- const mcpServerUse = JSON.parse(message.text || "{}") as ClineAskUseMcpServer
- return [
- isMcpServerResponding ? (
- <ProgressIndicator />
- ) : (
- <span
- className="codicon codicon-server"
- style={{ color: normalColor, marginBottom: "-1.5px" }}></span>
- ),
- <span style={{ color: normalColor, fontWeight: "bold" }}>
- {mcpServerUse.type === "use_mcp_tool"
- ? t("chat:mcp.wantsToUseTool", { serverName: mcpServerUse.serverName })
- : t("chat:mcp.wantsToAccessResource", { serverName: mcpServerUse.serverName })}
- </span>,
- ]
- case "completion_result":
- return [
- <span
- className="codicon codicon-check"
- style={{ color: successColor, marginBottom: "-1.5px" }}></span>,
- <span style={{ color: successColor, fontWeight: "bold" }}>{t("chat:taskCompleted")}</span>,
- ]
- case "api_req_retry_delayed":
- return []
- case "api_req_started":
- const getIconSpan = (iconName: string, color: string) => (
- <div
- style={{
- width: 16,
- height: 16,
- display: "flex",
- alignItems: "center",
- justifyContent: "center",
- }}>
- <span
- className={`codicon codicon-${iconName}`}
- style={{
- color,
- fontSize: 16,
- marginBottom: "-1.5px",
- }}></span>
- </div>
- )
- return [
- apiReqCancelReason !== null && apiReqCancelReason !== undefined ? (
- apiReqCancelReason === "user_cancelled" ? (
- getIconSpan("error", cancelledColor)
- ) : (
- getIconSpan("error", errorColor)
- )
- ) : cost !== null && cost !== undefined ? (
- getIconSpan("check", successColor)
- ) : apiRequestFailedMessage ? (
- getIconSpan("error", errorColor)
- ) : (
- <ProgressIndicator />
- ),
- apiReqCancelReason !== null && apiReqCancelReason !== undefined ? (
- apiReqCancelReason === "user_cancelled" ? (
- <span style={{ color: normalColor, fontWeight: "bold" }}>
- {t("chat:apiRequest.cancelled")}
- </span>
- ) : (
- <span style={{ color: errorColor, fontWeight: "bold" }}>
- {t("chat:apiRequest.streamingFailed")}
- </span>
- )
- ) : cost !== null && cost !== undefined ? (
- <span style={{ color: normalColor, fontWeight: "bold" }}>{t("chat:apiRequest.title")}</span>
- ) : apiRequestFailedMessage ? (
- <span style={{ color: errorColor, fontWeight: "bold" }}>{t("chat:apiRequest.failed")}</span>
- ) : (
- <span style={{ color: normalColor, fontWeight: "bold" }}>{t("chat:apiRequest.streaming")}</span>
- ),
- ]
- case "followup":
- return [
- <span
- className="codicon codicon-question"
- style={{ color: normalColor, marginBottom: "-1.5px" }}></span>,
- <span style={{ color: normalColor, fontWeight: "bold" }}>{t("chat:questions.hasQuestion")}</span>,
- ]
- default:
- return [null, null]
- }
- }, [type, isCommandExecuting, message, isMcpServerResponding, apiReqCancelReason, cost, apiRequestFailedMessage, t])
- const headerStyle: React.CSSProperties = {
- display: "flex",
- alignItems: "center",
- gap: "10px",
- marginBottom: "10px",
- }
- const pStyle: React.CSSProperties = {
- margin: 0,
- whiteSpace: "pre-wrap",
- wordBreak: "break-word",
- overflowWrap: "anywhere",
- }
- const tool = useMemo(() => {
- if (message.ask === "tool" || message.say === "tool") {
- return JSON.parse(message.text || "{}") as ClineSayTool
- }
- return null
- }, [message.ask, message.say, message.text])
- const followUpData = useMemo(() => {
- if (message.type === "ask" && message.ask === "followup" && !message.partial) {
- return JSON.parse(message.text || "{}")
- }
- return null
- }, [message.type, message.ask, message.partial, message.text])
- if (tool) {
- const toolIcon = (name: string) => (
- <span
- className={`codicon codicon-${name}`}
- style={{ color: "var(--vscode-foreground)", marginBottom: "-1.5px" }}></span>
- )
- switch (tool.tool) {
- case "editedExistingFile":
- case "appliedDiff":
- return (
- <>
- <div style={headerStyle}>
- {toolIcon(tool.tool === "appliedDiff" ? "diff" : "edit")}
- <span style={{ fontWeight: "bold" }}>
- {tool.isOutsideWorkspace
- ? t("chat:fileOperations.wantsToEditOutsideWorkspace")
- : t("chat:fileOperations.wantsToEdit")}
- </span>
- </div>
- <CodeAccordian
- progressStatus={message.progressStatus}
- isLoading={message.partial}
- diff={tool.diff!}
- path={tool.path!}
- isExpanded={isExpanded}
- onToggleExpand={onToggleExpand}
- />
- </>
- )
- case "newFileCreated":
- return (
- <>
- <div style={headerStyle}>
- {toolIcon("new-file")}
- <span style={{ fontWeight: "bold" }}>{t("chat:fileOperations.wantsToCreate")}</span>
- </div>
- <CodeAccordian
- isLoading={message.partial}
- code={tool.content!}
- path={tool.path!}
- isExpanded={isExpanded}
- onToggleExpand={onToggleExpand}
- />
- </>
- )
- case "readFile":
- return (
- <>
- <div style={headerStyle}>
- {toolIcon("file-code")}
- <span style={{ fontWeight: "bold" }}>
- {message.type === "ask"
- ? tool.isOutsideWorkspace
- ? t("chat:fileOperations.wantsToReadOutsideWorkspace")
- : t("chat:fileOperations.wantsToRead")
- : t("chat:fileOperations.didRead")}
- </span>
- </div>
- {/* <CodeAccordian
- code={tool.content!}
- path={tool.path!}
- isExpanded={isExpanded}
- onToggleExpand={onToggleExpand}
- /> */}
- <div
- style={{
- borderRadius: 3,
- backgroundColor: CODE_BLOCK_BG_COLOR,
- overflow: "hidden",
- border: "1px solid var(--vscode-editorGroup-border)",
- }}>
- <div
- style={{
- color: "var(--vscode-descriptionForeground)",
- display: "flex",
- alignItems: "center",
- padding: "9px 10px",
- cursor: "pointer",
- userSelect: "none",
- WebkitUserSelect: "none",
- MozUserSelect: "none",
- msUserSelect: "none",
- }}
- onClick={() => {
- vscode.postMessage({ type: "openFile", text: tool.content })
- }}>
- {tool.path?.startsWith(".") && <span>.</span>}
- <span
- style={{
- whiteSpace: "nowrap",
- overflow: "hidden",
- textOverflow: "ellipsis",
- marginRight: "8px",
- direction: "rtl",
- textAlign: "left",
- }}>
- {removeLeadingNonAlphanumeric(tool.path ?? "") + "\u200E"}
- </span>
- <div style={{ flexGrow: 1 }}></div>
- <span
- className={`codicon codicon-link-external`}
- style={{ fontSize: 13.5, margin: "1px 0" }}></span>
- </div>
- </div>
- </>
- )
- case "fetchInstructions":
- return (
- <>
- <div style={headerStyle}>
- {toolIcon("file-code")}
- <span style={{ fontWeight: "bold" }}>{t("chat:instructions.wantsToFetch")}</span>
- </div>
- <CodeAccordian
- isLoading={message.partial}
- code={tool.content!}
- isExpanded={isExpanded}
- onToggleExpand={onToggleExpand}
- />
- </>
- )
- case "listFilesTopLevel":
- return (
- <>
- <div style={headerStyle}>
- {toolIcon("folder-opened")}
- <span style={{ fontWeight: "bold" }}>
- {message.type === "ask"
- ? t("chat:directoryOperations.wantsToViewTopLevel")
- : t("chat:directoryOperations.didViewTopLevel")}
- </span>
- </div>
- <CodeAccordian
- code={tool.content!}
- path={tool.path!}
- language="shell-session"
- isExpanded={isExpanded}
- onToggleExpand={onToggleExpand}
- />
- </>
- )
- case "listFilesRecursive":
- return (
- <>
- <div style={headerStyle}>
- {toolIcon("folder-opened")}
- <span style={{ fontWeight: "bold" }}>
- {message.type === "ask"
- ? t("chat:directoryOperations.wantsToViewRecursive")
- : t("chat:directoryOperations.didViewRecursive")}
- </span>
- </div>
- <CodeAccordian
- code={tool.content!}
- path={tool.path!}
- language="shell-session"
- isExpanded={isExpanded}
- onToggleExpand={onToggleExpand}
- />
- </>
- )
- case "listCodeDefinitionNames":
- return (
- <>
- <div style={headerStyle}>
- {toolIcon("file-code")}
- <span style={{ fontWeight: "bold" }}>
- {message.type === "ask"
- ? t("chat:directoryOperations.wantsToViewDefinitions")
- : t("chat:directoryOperations.didViewDefinitions")}
- </span>
- </div>
- <CodeAccordian
- code={tool.content!}
- path={tool.path!}
- isExpanded={isExpanded}
- onToggleExpand={onToggleExpand}
- />
- </>
- )
- case "searchFiles":
- return (
- <>
- <div style={headerStyle}>
- {toolIcon("search")}
- <span style={{ fontWeight: "bold" }}>
- {message.type === "ask" ? (
- <Trans
- i18nKey="chat:directoryOperations.wantsToSearch"
- components={{ code: <code>{tool.regex}</code> }}
- values={{ regex: tool.regex }}
- />
- ) : (
- <Trans
- i18nKey="chat:directoryOperations.didSearch"
- components={{ code: <code>{tool.regex}</code> }}
- values={{ regex: tool.regex }}
- />
- )}
- </span>
- </div>
- <CodeAccordian
- code={tool.content!}
- path={tool.path! + (tool.filePattern ? `/(${tool.filePattern})` : "")}
- language="plaintext"
- isExpanded={isExpanded}
- onToggleExpand={onToggleExpand}
- />
- </>
- )
- case "switchMode":
- return (
- <>
- <div style={headerStyle}>
- {toolIcon("symbol-enum")}
- <span style={{ fontWeight: "bold" }}>
- {message.type === "ask" ? (
- <>
- {tool.reason ? (
- <Trans
- i18nKey="chat:modes.wantsToSwitchWithReason"
- components={{ code: <code>{tool.mode}</code> }}
- values={{ mode: tool.mode, reason: tool.reason }}
- />
- ) : (
- <Trans
- i18nKey="chat:modes.wantsToSwitch"
- components={{ code: <code>{tool.mode}</code> }}
- values={{ mode: tool.mode }}
- />
- )}
- </>
- ) : (
- <>
- {tool.reason ? (
- <Trans
- i18nKey="chat:modes.didSwitchWithReason"
- components={{ code: <code>{tool.mode}</code> }}
- values={{ mode: tool.mode, reason: tool.reason }}
- />
- ) : (
- <Trans
- i18nKey="chat:modes.didSwitch"
- components={{ code: <code>{tool.mode}</code> }}
- values={{ mode: tool.mode }}
- />
- )}
- </>
- )}
- </span>
- </div>
- </>
- )
- case "newTask":
- return (
- <>
- <div style={headerStyle}>
- {toolIcon("new-file")}
- <span style={{ fontWeight: "bold" }}>
- <Trans
- i18nKey="chat:subtasks.wantsToCreate"
- components={{ code: <code>{tool.mode}</code> }}
- values={{ mode: tool.mode }}
- />
- </span>
- </div>
- <div style={{ paddingLeft: "26px", marginTop: "4px" }}>
- <code>{tool.content}</code>
- </div>
- </>
- )
- case "finishTask":
- return (
- <>
- <div style={headerStyle}>
- {toolIcon("checklist")}
- <span style={{ fontWeight: "bold" }}>{t("chat:subtasks.wantsToFinish")}</span>
- </div>
- <div style={{ paddingLeft: "26px", marginTop: "4px" }}>
- <code>{tool.content}</code>
- </div>
- </>
- )
- default:
- return null
- }
- }
- switch (message.type) {
- case "say":
- switch (message.say) {
- case "reasoning":
- return (
- <ReasoningBlock
- content={message.text || ""}
- elapsed={isLast && isStreaming ? Date.now() - message.ts : undefined}
- isCollapsed={reasoningCollapsed}
- onToggleCollapse={() => setReasoningCollapsed(!reasoningCollapsed)}
- />
- )
- case "api_req_started":
- return (
- <>
- <div
- style={{
- ...headerStyle,
- marginBottom:
- ((cost === null || cost === undefined) && apiRequestFailedMessage) ||
- apiReqStreamingFailedMessage
- ? 10
- : 0,
- justifyContent: "space-between",
- cursor: "pointer",
- userSelect: "none",
- WebkitUserSelect: "none",
- MozUserSelect: "none",
- msUserSelect: "none",
- }}
- onClick={onToggleExpand}>
- <div style={{ display: "flex", alignItems: "center", gap: "10px", flexGrow: 1 }}>
- {icon}
- {title}
- <VSCodeBadge
- style={{ opacity: cost !== null && cost !== undefined && cost > 0 ? 1 : 0 }}>
- ${Number(cost || 0)?.toFixed(4)}
- </VSCodeBadge>
- </div>
- <span className={`codicon codicon-chevron-${isExpanded ? "up" : "down"}`}></span>
- </div>
- {(((cost === null || cost === undefined) && apiRequestFailedMessage) ||
- apiReqStreamingFailedMessage) && (
- <>
- <p style={{ ...pStyle, color: "var(--vscode-errorForeground)" }}>
- {apiRequestFailedMessage || apiReqStreamingFailedMessage}
- {apiRequestFailedMessage?.toLowerCase().includes("powershell") && (
- <>
- <br />
- <br />
- {t("chat:powershell.issues")}{" "}
- <a
- href="https://github.com/cline/cline/wiki/TroubleShooting-%E2%80%90-%22PowerShell-is-not-recognized-as-an-internal-or-external-command%22"
- style={{ color: "inherit", textDecoration: "underline" }}>
- troubleshooting guide
- </a>
- .
- </>
- )}
- </p>
- {/* {apiProvider === "" && (
- <div
- style={{
- display: "flex",
- alignItems: "center",
- backgroundColor:
- "color-mix(in srgb, var(--vscode-errorForeground) 20%, transparent)",
- color: "var(--vscode-editor-foreground)",
- padding: "6px 8px",
- borderRadius: "3px",
- margin: "10px 0 0 0",
- fontSize: "12px",
- }}>
- <i
- className="codicon codicon-warning"
- style={{
- marginRight: 6,
- fontSize: 16,
- color: "var(--vscode-errorForeground)",
- }}></i>
- <span>
- Uh-oh, this could be a problem on end. We've been alerted and
- will resolve this ASAP. You can also{" "}
- <a
- href=""
- style={{ color: "inherit", textDecoration: "underline" }}>
- contact us
- </a>
- .
- </span>
- </div>
- )} */}
- </>
- )}
- {isExpanded && (
- <div style={{ marginTop: "10px" }}>
- <CodeAccordian
- code={JSON.parse(message.text || "{}").request}
- language="markdown"
- isExpanded={true}
- onToggleExpand={onToggleExpand}
- />
- </div>
- )}
- </>
- )
- case "api_req_finished":
- return null // we should never see this message type
- case "text":
- return (
- <div>
- <Markdown markdown={message.text} partial={message.partial} />
- </div>
- )
- case "user_feedback":
- return (
- <div
- style={{
- backgroundColor: "var(--vscode-badge-background)",
- color: "var(--vscode-badge-foreground)",
- borderRadius: "3px",
- padding: "9px",
- overflow: "hidden",
- whiteSpace: "pre-wrap",
- wordBreak: "break-word",
- overflowWrap: "anywhere",
- }}>
- <div
- style={{
- display: "flex",
- justifyContent: "space-between",
- alignItems: "flex-start",
- gap: "10px",
- }}>
- <span style={{ display: "block", flexGrow: 1, padding: "4px" }}>
- {highlightMentions(message.text)}
- </span>
- <VSCodeButton
- appearance="icon"
- style={{
- padding: "3px",
- flexShrink: 0,
- height: "24px",
- marginTop: "-3px",
- marginBottom: "-3px",
- marginRight: "-6px",
- }}
- disabled={isStreaming}
- onClick={(e) => {
- e.stopPropagation()
- vscode.postMessage({
- type: "deleteMessage",
- value: message.ts,
- })
- }}>
- <span className="codicon codicon-trash"></span>
- </VSCodeButton>
- </div>
- {message.images && message.images.length > 0 && (
- <Thumbnails images={message.images} style={{ marginTop: "8px" }} />
- )}
- </div>
- )
- case "user_feedback_diff":
- const tool = JSON.parse(message.text || "{}") as ClineSayTool
- return (
- <div
- style={{
- marginTop: -10,
- width: "100%",
- }}>
- <CodeAccordian
- diff={tool.diff!}
- isFeedback={true}
- isExpanded={isExpanded}
- onToggleExpand={onToggleExpand}
- />
- </div>
- )
- case "error":
- return (
- <>
- {title && (
- <div style={headerStyle}>
- {icon}
- {title}
- </div>
- )}
- <p style={{ ...pStyle, color: "var(--vscode-errorForeground)" }}>{message.text}</p>
- </>
- )
- case "completion_result":
- return (
- <>
- <div style={headerStyle}>
- {icon}
- {title}
- </div>
- <div style={{ color: "var(--vscode-charts-green)", paddingTop: 10 }}>
- <Markdown markdown={message.text} />
- </div>
- </>
- )
- case "shell_integration_warning":
- return (
- <>
- <div
- style={{
- display: "flex",
- flexDirection: "column",
- backgroundColor: "rgba(255, 191, 0, 0.1)",
- padding: 8,
- borderRadius: 3,
- fontSize: 12,
- }}>
- <div style={{ display: "flex", alignItems: "center", marginBottom: 4 }}>
- <i
- className="codicon codicon-warning"
- style={{
- marginRight: 8,
- fontSize: 18,
- color: "#FFA500",
- }}></i>
- <span style={{ fontWeight: 500, color: "#FFA500" }}>
- {t("chat:shellIntegration.unavailable")}
- </span>
- </div>
- <div>
- <strong>{message.text}</strong>
- <br />
- <br />
- Please update VSCode (<code>CMD/CTRL + Shift + P</code> → "Update") and make sure
- you're using a supported shell: zsh, bash, fish, or PowerShell (
- <code>CMD/CTRL + Shift + P</code> → "Terminal: Select Default Profile").{" "}
- <a
- href="http://docs.roocode.com/troubleshooting/shell-integration/"
- style={{ color: "inherit", textDecoration: "underline" }}>
- {t("chat:shellIntegration.troubleshooting")}
- </a>
- </div>
- </div>
- </>
- )
- case "mcp_server_response":
- return (
- <>
- <div style={{ paddingTop: 0 }}>
- <div
- style={{
- marginBottom: "4px",
- opacity: 0.8,
- fontSize: "12px",
- textTransform: "uppercase",
- }}>
- {t("chat:response")}
- </div>
- <CodeAccordian
- code={message.text}
- language="json"
- isExpanded={true}
- onToggleExpand={onToggleExpand}
- />
- </div>
- </>
- )
- case "checkpoint_saved":
- return (
- <CheckpointSaved
- ts={message.ts!}
- commitHash={message.text!}
- currentHash={currentCheckpoint}
- checkpoint={message.checkpoint}
- />
- )
- default:
- return (
- <>
- {title && (
- <div style={headerStyle}>
- {icon}
- {title}
- </div>
- )}
- <div style={{ paddingTop: 10 }}>
- <Markdown markdown={message.text} partial={message.partial} />
- </div>
- </>
- )
- }
- case "ask":
- switch (message.ask) {
- case "mistake_limit_reached":
- return (
- <>
- <div style={headerStyle}>
- {icon}
- {title}
- </div>
- <p style={{ ...pStyle, color: "var(--vscode-errorForeground)" }}>{message.text}</p>
- </>
- )
- case "command":
- const splitMessage = (text: string) => {
- const outputIndex = text.indexOf(COMMAND_OUTPUT_STRING)
- if (outputIndex === -1) {
- return { command: text, output: "" }
- }
- return {
- command: text.slice(0, outputIndex).trim(),
- output: text
- .slice(outputIndex + COMMAND_OUTPUT_STRING.length)
- .trim()
- .split("")
- .map((char) => {
- switch (char) {
- case "\t":
- return "→ "
- case "\b":
- return "⌫"
- case "\f":
- return "⏏"
- case "\v":
- return "⇳"
- default:
- return char
- }
- })
- .join(""),
- }
- }
- const { command, output } = splitMessage(message.text || "")
- return (
- <>
- <div style={headerStyle}>
- {icon}
- {title}
- </div>
- {/* <Terminal
- rawOutput={command + (output ? "\n" + output : "")}
- shouldAllowInput={!!isCommandExecuting && output.length > 0}
- /> */}
- <div
- style={{
- borderRadius: 3,
- border: "1px solid var(--vscode-editorGroup-border)",
- overflow: "hidden",
- backgroundColor: CODE_BLOCK_BG_COLOR,
- }}>
- <CodeBlock source={`${"```"}shell\n${command}\n${"```"}`} forceWrap={true} />
- {output.length > 0 && (
- <div style={{ width: "100%" }}>
- <div
- onClick={onToggleExpand}
- style={{
- display: "flex",
- alignItems: "center",
- gap: "4px",
- width: "100%",
- justifyContent: "flex-start",
- cursor: "pointer",
- padding: `2px 8px ${isExpanded ? 0 : 8}px 8px`,
- }}>
- <span
- className={`codicon codicon-chevron-${isExpanded ? "down" : "right"}`}></span>
- <span style={{ fontSize: "0.8em" }}>{t("chat:commandOutput")}</span>
- </div>
- {isExpanded && <CodeBlock source={`${"```"}shell\n${output}\n${"```"}`} />}
- </div>
- )}
- </div>
- </>
- )
- case "use_mcp_server":
- const useMcpServer = JSON.parse(message.text || "{}") as ClineAskUseMcpServer
- const server = mcpServers.find((server) => server.name === useMcpServer.serverName)
- return (
- <>
- <div style={headerStyle}>
- {icon}
- {title}
- </div>
- <div
- style={{
- background: "var(--vscode-textCodeBlock-background)",
- borderRadius: "3px",
- padding: "8px 10px",
- marginTop: "8px",
- }}>
- {useMcpServer.type === "access_mcp_resource" && (
- <McpResourceRow
- item={{
- // Use the matched resource/template details, with fallbacks
- ...(findMatchingResourceOrTemplate(
- useMcpServer.uri || "",
- server?.resources,
- server?.resourceTemplates,
- ) || {
- name: "",
- mimeType: "",
- description: "",
- }),
- // Always use the actual URI from the request
- uri: useMcpServer.uri || "",
- }}
- />
- )}
- {useMcpServer.type === "use_mcp_tool" && (
- <>
- <div onClick={(e) => e.stopPropagation()}>
- <McpToolRow
- tool={{
- name: useMcpServer.toolName || "",
- description:
- server?.tools?.find(
- (tool) => tool.name === useMcpServer.toolName,
- )?.description || "",
- alwaysAllow:
- server?.tools?.find(
- (tool) => tool.name === useMcpServer.toolName,
- )?.alwaysAllow || false,
- }}
- serverName={useMcpServer.serverName}
- alwaysAllowMcp={alwaysAllowMcp}
- />
- </div>
- {useMcpServer.arguments && useMcpServer.arguments !== "{}" && (
- <div style={{ marginTop: "8px" }}>
- <div
- style={{
- marginBottom: "4px",
- opacity: 0.8,
- fontSize: "12px",
- textTransform: "uppercase",
- }}>
- {t("chat:arguments")}
- </div>
- <CodeAccordian
- code={useMcpServer.arguments}
- language="json"
- isExpanded={true}
- onToggleExpand={onToggleExpand}
- />
- </div>
- )}
- </>
- )}
- </div>
- </>
- )
- case "completion_result":
- if (message.text) {
- return (
- <div>
- <div style={headerStyle}>
- {icon}
- {title}
- </div>
- <div style={{ color: "var(--vscode-charts-green)", paddingTop: 10 }}>
- <Markdown markdown={message.text} partial={message.partial} />
- </div>
- </div>
- )
- } else {
- return null // Don't render anything when we get a completion_result ask without text
- }
- case "followup":
- return (
- <>
- {title && (
- <div style={headerStyle}>
- {icon}
- {title}
- </div>
- )}
- <div style={{ paddingTop: 10, paddingBottom: 15 }}>
- <Markdown
- markdown={message.partial === true ? message?.text : followUpData?.question}
- />
- </div>
- <FollowUpSuggest
- suggestions={followUpData?.suggest}
- onSuggestionClick={onSuggestionClick}
- ts={message?.ts}
- />
- </>
- )
- default:
- return null
- }
- }
- }
- export const ProgressIndicator = () => (
- <div
- style={{
- width: "16px",
- height: "16px",
- display: "flex",
- alignItems: "center",
- justifyContent: "center",
- }}>
- <div style={{ transform: "scale(0.55)", transformOrigin: "center" }}>
- <VSCodeProgressRing />
- </div>
- </div>
- )
- const Markdown = memo(({ markdown, partial }: { markdown?: string; partial?: boolean }) => {
- const [isHovering, setIsHovering] = useState(false)
- const { copyWithFeedback } = useCopyToClipboard(200) // shorter feedback duration for copy button flash
- return (
- <div
- onMouseEnter={() => setIsHovering(true)}
- onMouseLeave={() => setIsHovering(false)}
- style={{ position: "relative" }}>
- <div style={{ wordBreak: "break-word", overflowWrap: "anywhere", marginBottom: -15, marginTop: -15 }}>
- <MarkdownBlock markdown={markdown} />
- </div>
- {markdown && !partial && isHovering && (
- <div
- style={{
- position: "absolute",
- bottom: "-4px",
- right: "8px",
- opacity: 0,
- animation: "fadeIn 0.2s ease-in-out forwards",
- borderRadius: "4px",
- }}>
- <style>
- {`
- @keyframes fadeIn {
- from { opacity: 0; }
- to { opacity: 1.0; }
- }
- `}
- </style>
- <VSCodeButton
- className="copy-button"
- appearance="icon"
- style={{
- height: "24px",
- border: "none",
- background: "var(--vscode-editor-background)",
- transition: "background 0.2s ease-in-out",
- }}
- onClick={async () => {
- const success = await copyWithFeedback(markdown)
- if (success) {
- const button = document.activeElement as HTMLElement
- if (button) {
- button.style.background = "var(--vscode-button-background)"
- setTimeout(() => {
- button.style.background = ""
- }, 200)
- }
- }
- }}
- title="Copy as markdown">
- <span className="codicon codicon-copy"></span>
- </VSCodeButton>
- </div>
- )}
- </div>
- )
- })
|