|
1 | | -import { VSCodeButton } from "@vscode/webview-ui-toolkit/react" |
| 1 | +import { VSCodeButton, VSCodeLink } from "@vscode/webview-ui-toolkit/react" |
2 | 2 | import debounce from "debounce" |
3 | 3 | import { useCallback, useEffect, useMemo, useRef, useState } from "react" |
4 | 4 | import { useDeepCompareEffect, useEvent, useMount } from "react-use" |
@@ -88,6 +88,7 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie |
88 | 88 | const [isAtBottom, setIsAtBottom] = useState(false) |
89 | 89 |
|
90 | 90 | const [wasStreaming, setWasStreaming] = useState<boolean>(false) |
| 91 | + const [showCheckpointWarning, setShowCheckpointWarning] = useState<boolean>(false) |
91 | 92 |
|
92 | 93 | // UI layout depends on the last 2 messages |
93 | 94 | // (since it relies on the content of these messages, we are deep comparing. i.e. the button state after hitting button sets enableButtons to false, and this effect otherwise would have to true again even if messages didn't change |
@@ -882,6 +883,48 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie |
882 | 883 | }, []) |
883 | 884 | useEvent("wheel", handleWheel, window, { passive: true }) // passive improves scrolling performance |
884 | 885 |
|
| 886 | + // Effect to handle showing the checkpoint warning after a delay |
| 887 | + useEffect(() => { |
| 888 | + // Only show the warning when there's a task but no visible messages yet |
| 889 | + if (task && modifiedMessages.length === 0 && !isStreaming) { |
| 890 | + const timer = setTimeout(() => { |
| 891 | + setShowCheckpointWarning(true) |
| 892 | + }, 5000) // 5 seconds |
| 893 | + |
| 894 | + return () => clearTimeout(timer) |
| 895 | + } |
| 896 | + }, [task, modifiedMessages.length, isStreaming]) |
| 897 | + |
| 898 | + // Effect to hide the checkpoint warning when messages appear |
| 899 | + useEffect(() => { |
| 900 | + if (modifiedMessages.length > 0 || isStreaming) { |
| 901 | + setShowCheckpointWarning(false) |
| 902 | + } |
| 903 | + }, [modifiedMessages.length, isStreaming]) |
| 904 | + |
| 905 | + // Checkpoint warning component |
| 906 | + const CheckpointWarningMessage = useCallback( |
| 907 | + () => ( |
| 908 | + <div className="flex items-center p-3 my-3 bg-vscode-inputValidation-warningBackground border border-vscode-inputValidation-warningBorder rounded"> |
| 909 | + <span className="codicon codicon-loading codicon-modifier-spin mr-2" /> |
| 910 | + <span className="text-vscode-foreground"> |
| 911 | + Still initializing checkpoint... If this takes too long, you can{" "} |
| 912 | + <VSCodeLink |
| 913 | + href="#" |
| 914 | + onClick={(e) => { |
| 915 | + e.preventDefault() |
| 916 | + window.postMessage({ type: "action", action: "settingsButtonClicked" }, "*") |
| 917 | + }} |
| 918 | + className="inline px-0.5"> |
| 919 | + disable checkpoints in settings |
| 920 | + </VSCodeLink>{" "} |
| 921 | + and restart your task. |
| 922 | + </span> |
| 923 | + </div> |
| 924 | + ), |
| 925 | + [], |
| 926 | + ) |
| 927 | + |
885 | 928 | const placeholderText = useMemo(() => { |
886 | 929 | const baseText = task ? "Type a message..." : "Type your task here..." |
887 | 930 | const contextText = "(@ to add context, / to switch modes" |
@@ -1014,17 +1057,26 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie |
1014 | 1057 | overflow: "hidden", |
1015 | 1058 | }}> |
1016 | 1059 | {task ? ( |
1017 | | - <TaskHeader |
1018 | | - task={task} |
1019 | | - tokensIn={apiMetrics.totalTokensIn} |
1020 | | - tokensOut={apiMetrics.totalTokensOut} |
1021 | | - doesModelSupportPromptCache={selectedModelInfo.supportsPromptCache} |
1022 | | - cacheWrites={apiMetrics.totalCacheWrites} |
1023 | | - cacheReads={apiMetrics.totalCacheReads} |
1024 | | - totalCost={apiMetrics.totalCost} |
1025 | | - contextTokens={apiMetrics.contextTokens} |
1026 | | - onClose={handleTaskCloseButtonClick} |
1027 | | - /> |
| 1060 | + <> |
| 1061 | + <TaskHeader |
| 1062 | + task={task} |
| 1063 | + tokensIn={apiMetrics.totalTokensIn} |
| 1064 | + tokensOut={apiMetrics.totalTokensOut} |
| 1065 | + doesModelSupportPromptCache={selectedModelInfo.supportsPromptCache} |
| 1066 | + cacheWrites={apiMetrics.totalCacheWrites} |
| 1067 | + cacheReads={apiMetrics.totalCacheReads} |
| 1068 | + totalCost={apiMetrics.totalCost} |
| 1069 | + contextTokens={apiMetrics.contextTokens} |
| 1070 | + onClose={handleTaskCloseButtonClick} |
| 1071 | + /> |
| 1072 | + |
| 1073 | + {/* Checkpoint warning message */} |
| 1074 | + {showCheckpointWarning && ( |
| 1075 | + <div className="px-3"> |
| 1076 | + <CheckpointWarningMessage /> |
| 1077 | + </div> |
| 1078 | + )} |
| 1079 | + </> |
1028 | 1080 | ) : ( |
1029 | 1081 | <div |
1030 | 1082 | style={{ |
|
0 commit comments