Merge pull request #2811 from continuedev/dallin/sticky-chat
Sticky chat
This commit is contained in:
commit
f7116eaa3f
6 changed files with 115 additions and 102 deletions
|
|
@ -2,5 +2,8 @@
|
|||
"tabWidth": 2,
|
||||
"useTabs": false,
|
||||
"trailingComma": "all",
|
||||
"semi": true,
|
||||
"singleQuote": false,
|
||||
"bracketSpacing": true,
|
||||
"plugins": ["prettier-plugin-tailwindcss"]
|
||||
}
|
||||
|
|
|
|||
2
gui/package-lock.json
generated
2
gui/package-lock.json
generated
|
|
@ -37,7 +37,7 @@
|
|||
"react-dom": "^18.2.0",
|
||||
"react-error-boundary": "^4.0.11",
|
||||
"react-hook-form": "^7.47.0",
|
||||
"react-intersection-observer": "^9.10.3",
|
||||
"react-intersection-observer": "^9.13.1",
|
||||
"react-markdown": "^9.0.1",
|
||||
"react-redux": "^8.0.5",
|
||||
"react-remark": "^2.1.0",
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@
|
|||
"react-dom": "^18.2.0",
|
||||
"react-error-boundary": "^4.0.11",
|
||||
"react-hook-form": "^7.47.0",
|
||||
"react-intersection-observer": "^9.10.3",
|
||||
"react-intersection-observer": "^9.13.1",
|
||||
"react-markdown": "^9.0.1",
|
||||
"react-redux": "^8.0.5",
|
||||
"react-remark": "^2.1.0",
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import {
|
||||
ArrowPathIcon,
|
||||
BarsArrowDownIcon,
|
||||
HandThumbDownIcon,
|
||||
HandThumbUpIcon,
|
||||
|
|
@ -14,7 +13,7 @@ import { vscBackground, vscInputBackground } from "..";
|
|||
import { IdeMessengerContext } from "../../context/IdeMessenger";
|
||||
import useUIConfig from "../../hooks/useUIConfig";
|
||||
import { RootState } from "../../redux/store";
|
||||
import { getFontSize } from "../../util";
|
||||
import { getFontSize, getMetaKeyLabel } from "../../util";
|
||||
import ButtonWithTooltip from "../ButtonWithTooltip";
|
||||
import { CopyButton } from "../markdown/CopyButton";
|
||||
import StyledMarkdownPreview from "../markdown/StyledMarkdownPreview";
|
||||
|
|
@ -50,7 +49,7 @@ function StepContainer(props: StepContainerProps) {
|
|||
|
||||
const isUserInput = props.item.message.role === "user";
|
||||
const uiConfig = useUIConfig();
|
||||
const shouldRenderActions = !props.isLast || (props.isLast && !active);
|
||||
const shouldRenderActions = !active || !props.isLast;
|
||||
|
||||
useEffect(() => {
|
||||
if (!active) {
|
||||
|
|
@ -84,7 +83,11 @@ function StepContainer(props: StepContainerProps) {
|
|||
};
|
||||
|
||||
return (
|
||||
<div className="relative">
|
||||
<div className="relative"
|
||||
style={{
|
||||
minHeight: props.isLast ? "50vh" : 0
|
||||
}}
|
||||
>
|
||||
<ContentDiv
|
||||
hidden={!props.open}
|
||||
isUserInput={isUserInput}
|
||||
|
|
@ -104,52 +107,55 @@ function StepContainer(props: StepContainerProps) {
|
|||
/>
|
||||
)}
|
||||
</ContentDiv>
|
||||
|
||||
{shouldRenderActions && (
|
||||
<div className="flex items-center justify-end gap-0.5 xs:flex text-xs text-gray-400 p-2 pb-0 cursor-default">
|
||||
{truncatedEarly && (
|
||||
<ButtonWithTooltip
|
||||
tabIndex={-1}
|
||||
text="Continue generation"
|
||||
onClick={props.onContinueGeneration}
|
||||
>
|
||||
<BarsArrowDownIcon className="h-3.5 w-3.5 text-gray-500" />
|
||||
</ButtonWithTooltip>
|
||||
)}
|
||||
|
||||
{props.index !== 1 && (
|
||||
<ButtonWithTooltip
|
||||
text="Delete"
|
||||
tabIndex={-1}
|
||||
onClick={props.onDelete}
|
||||
>
|
||||
<TrashIcon className="h-3.5 w-3.5 text-gray-500" />
|
||||
</ButtonWithTooltip>
|
||||
)}
|
||||
|
||||
<CopyButton
|
||||
tabIndex={-1}
|
||||
text={stripImages(props.item.message.content)}
|
||||
clipboardIconClassName="h-3.5 w-3.5 text-gray-500"
|
||||
/>
|
||||
|
||||
<div className="h-7 mb-2 mx-2 flex items-center justify-end gap-0.5 xs:flex text-xs text-gray-400 pb-0 cursor-default"
|
||||
style={{
|
||||
opacity: shouldRenderActions ? 1 : 0,
|
||||
pointerEvents: shouldRenderActions ? "auto" : "none"
|
||||
}}
|
||||
>
|
||||
{truncatedEarly && (
|
||||
<ButtonWithTooltip
|
||||
text="Helpful"
|
||||
tabIndex={-1}
|
||||
onClick={() => sendFeedback(true)}
|
||||
text="Continue generation"
|
||||
onClick={props.onContinueGeneration}
|
||||
>
|
||||
<HandThumbUpIcon className="h-3.5 w-3.5 text-gray-500 mx-0.5" />
|
||||
<BarsArrowDownIcon className="h-3.5 w-3.5 text-gray-500" />
|
||||
</ButtonWithTooltip>
|
||||
)}
|
||||
|
||||
{props.index !== 1 && (
|
||||
<ButtonWithTooltip
|
||||
text="Unhelpful"
|
||||
text="Delete"
|
||||
tabIndex={-1}
|
||||
onClick={() => sendFeedback(false)}
|
||||
onClick={props.onDelete}
|
||||
>
|
||||
<HandThumbDownIcon className="h-3.5 w-3.5 text-gray-500" />
|
||||
<TrashIcon className="h-3.5 w-3.5 text-gray-500" />
|
||||
</ButtonWithTooltip>
|
||||
</div>
|
||||
)}
|
||||
)}
|
||||
|
||||
<CopyButton
|
||||
tabIndex={-1}
|
||||
text={stripImages(props.item.message.content)}
|
||||
clipboardIconClassName="h-3.5 w-3.5 text-gray-500"
|
||||
checkIconClassName="h-3.5 w-3.5 text-green-400"
|
||||
/>
|
||||
|
||||
<ButtonWithTooltip
|
||||
text="Helpful"
|
||||
tabIndex={-1}
|
||||
onClick={() => sendFeedback(true)}
|
||||
>
|
||||
<HandThumbUpIcon className={`h-3.5 w-3.5 mx-0.5 ${feedback === true ? 'text-green-400' : 'text-gray-500'}`} />
|
||||
</ButtonWithTooltip>
|
||||
|
||||
<ButtonWithTooltip
|
||||
text="Unhelpful"
|
||||
tabIndex={-1}
|
||||
onClick={() => sendFeedback(false)}
|
||||
>
|
||||
<HandThumbDownIcon className={`h-3.5 w-3.5 ${feedback === false ? 'text-red-400' : 'text-gray-500'}`} />
|
||||
</ButtonWithTooltip>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ function ContinueInputBox(props: ContinueInputBoxProps) {
|
|||
}, [isGatheringContextStore]);
|
||||
|
||||
return (
|
||||
<div className={`mb-1 mt-3 ${props.hidden ? "hidden" : ""}`}>
|
||||
<div className={`mb-1 ${props.hidden ? "hidden" : ""}`}>
|
||||
<div className={`relative flex px-2`}>
|
||||
<GradientBorder
|
||||
loading={active && props.isLastUserInput ? 1 : 0}
|
||||
|
|
|
|||
|
|
@ -66,7 +66,6 @@ const TopGuiDiv = styled.div<{
|
|||
showScrollbar?: boolean;
|
||||
}>`
|
||||
overflow-y: auto;
|
||||
height: 100%;
|
||||
scrollbar-width: ${(props) => (props.showScrollbar ? "thin" : "none")};
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
|
|
@ -75,6 +74,7 @@ const TopGuiDiv = styled.div<{
|
|||
`;
|
||||
|
||||
const StopButton = styled.div`
|
||||
background-color: ${vscBackground};
|
||||
width: fit-content;
|
||||
margin-right: auto;
|
||||
margin-left: auto;
|
||||
|
|
@ -97,6 +97,7 @@ const StopButton = styled.div`
|
|||
`;
|
||||
|
||||
const StepsDiv = styled.div`
|
||||
margin-top: 8px;
|
||||
position: relative;
|
||||
background-color: transparent;
|
||||
|
||||
|
|
@ -147,16 +148,17 @@ export function Chat() {
|
|||
const { saveSession, getLastSessionId, loadLastSession } =
|
||||
useHistory(dispatch);
|
||||
|
||||
useEffect(() => {
|
||||
if (!active || !topGuiDivRef.current) return;
|
||||
|
||||
const scrollAreaElement = topGuiDivRef.current;
|
||||
|
||||
scrollAreaElement.scrollTop =
|
||||
scrollAreaElement.scrollHeight - scrollAreaElement.clientHeight;
|
||||
const scrollToBottom = useCallback(() => {
|
||||
if (!topGuiDivRef.current) return;
|
||||
const elem = topGuiDivRef.current;
|
||||
elem.scrollTop = elem.scrollHeight - elem.clientHeight;
|
||||
|
||||
setIsAtBottom(true);
|
||||
}, [active]);
|
||||
}, [topGuiDivRef, setIsAtBottom]);
|
||||
|
||||
useEffect(() => {
|
||||
if (active) scrollToBottom();
|
||||
}, [active, scrollToBottom]);
|
||||
|
||||
useEffect(() => {
|
||||
// Cmd + Backspace to delete current step
|
||||
|
|
@ -311,6 +313,7 @@ export function Chat() {
|
|||
return (
|
||||
<>
|
||||
<TopGuiDiv
|
||||
className={`${state.history.length > 0 ? "h-full" : ""}`}
|
||||
ref={topGuiDivRef}
|
||||
onScroll={handleScroll}
|
||||
showScrollbar={state.config.ui?.showChatScrollbar || false}
|
||||
|
|
@ -415,22 +418,56 @@ export function Chat() {
|
|||
</Fragment>
|
||||
))}
|
||||
</StepsDiv>
|
||||
</div>
|
||||
<ChatScrollAnchor
|
||||
scrollAreaRef={topGuiDivRef}
|
||||
isAtBottom={isAtBottom}
|
||||
trackVisibility={active}
|
||||
/>
|
||||
</TopGuiDiv>
|
||||
|
||||
<ContinueInputBox
|
||||
isMainInput
|
||||
isLastUserInput={false}
|
||||
hidden={active}
|
||||
onEnter={(editorContent, modifiers) => {
|
||||
sendInput(editorContent, modifiers);
|
||||
}}
|
||||
/>
|
||||
|
||||
{active ? (
|
||||
<>
|
||||
<br />
|
||||
<br />
|
||||
</>
|
||||
) : state.history.length > 0 ? (
|
||||
<div className={`relative`}>
|
||||
<div className="absolute -top-8 right-2 z-30">
|
||||
{ttsActive && (
|
||||
<StopButton
|
||||
className=""
|
||||
onClick={() => {
|
||||
ideMessenger.post("tts/kill", undefined);
|
||||
}}
|
||||
>
|
||||
■ Stop TTS
|
||||
</StopButton>
|
||||
)}
|
||||
{active && (
|
||||
<StopButton
|
||||
onClick={() => {
|
||||
dispatch(setInactive());
|
||||
if (
|
||||
state.history[state.history.length - 1]?.message.content
|
||||
.length === 0
|
||||
) {
|
||||
dispatch(clearLastResponse());
|
||||
}
|
||||
}}
|
||||
>
|
||||
{getMetaKeyLabel()} ⌫ Cancel
|
||||
</StopButton>
|
||||
)}
|
||||
</div>
|
||||
<ContinueInputBox
|
||||
isMainInput
|
||||
isLastUserInput={false}
|
||||
onEnter={(editorContent, modifiers) => {
|
||||
sendInput(editorContent, modifiers);
|
||||
}}
|
||||
/>
|
||||
<div
|
||||
style={{
|
||||
// opacity: active ? 0 : 1,
|
||||
pointerEvents: active ? "none" : "auto",
|
||||
}}
|
||||
>
|
||||
{state.history.length > 0 ? (
|
||||
<div className="xs:inline mt-2 hidden">
|
||||
<NewSessionButton
|
||||
onClick={() => {
|
||||
|
|
@ -475,40 +512,7 @@ export function Chat() {
|
|||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<ChatScrollAnchor
|
||||
scrollAreaRef={topGuiDivRef}
|
||||
isAtBottom={isAtBottom}
|
||||
trackVisibility={active}
|
||||
/>
|
||||
</TopGuiDiv>
|
||||
|
||||
{ttsActive && (
|
||||
<StopButton
|
||||
className="mb-4 mt-2"
|
||||
onClick={() => {
|
||||
ideMessenger.post("tts/kill", undefined);
|
||||
}}
|
||||
>
|
||||
■ Stop TTS
|
||||
</StopButton>
|
||||
)}
|
||||
{active && (
|
||||
<StopButton
|
||||
className="mb-4 mt-auto"
|
||||
onClick={() => {
|
||||
dispatch(setInactive());
|
||||
if (
|
||||
state.history[state.history.length - 1]?.message.content
|
||||
.length === 0
|
||||
) {
|
||||
dispatch(clearLastResponse());
|
||||
}
|
||||
}}
|
||||
>
|
||||
{getMetaKeyLabel()} ⌫ Cancel
|
||||
</StopButton>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue