💄 small ui improvements
This commit is contained in:
parent
dde1139b61
commit
611521d21f
12 changed files with 220 additions and 172 deletions
5
core/index.d.ts
vendored
5
core/index.d.ts
vendored
|
|
@ -34,6 +34,11 @@ export interface ILLM extends LLMOptions {
|
|||
options?: LLMFullCompletionOptions
|
||||
): AsyncGenerator<ChatMessage>;
|
||||
|
||||
chat(
|
||||
messages: ChatMessage[],
|
||||
options?: LLMFullCompletionOptions
|
||||
): Promise<ChatMessage>;
|
||||
|
||||
countTokens(text: string): number;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import {
|
||||
ChatMessage,
|
||||
ChatMessageRole,
|
||||
CompletionOptions,
|
||||
ILLM,
|
||||
LLMFullCompletionOptions,
|
||||
|
|
@ -374,6 +375,14 @@ export abstract class BaseLLM implements ILLM {
|
|||
return completion;
|
||||
}
|
||||
|
||||
async chat(messages: ChatMessage[], options: LLMFullCompletionOptions = {}) {
|
||||
let completion = "";
|
||||
for await (const chunk of this.streamChat(messages, options)) {
|
||||
completion += chunk.content;
|
||||
}
|
||||
return { role: "assistant" as ChatMessageRole, content: completion };
|
||||
}
|
||||
|
||||
async *streamChat(
|
||||
messages: ChatMessage[],
|
||||
options: LLMFullCompletionOptions = {}
|
||||
|
|
|
|||
|
|
@ -77,6 +77,10 @@ class FreeTrial extends BaseLLM {
|
|||
}),
|
||||
});
|
||||
|
||||
if (response.status !== 200) {
|
||||
throw new Error(await response.text());
|
||||
}
|
||||
|
||||
const reader = response.body?.getReader();
|
||||
let decoder = new TextDecoder("utf-8");
|
||||
|
||||
|
|
|
|||
|
|
@ -83,6 +83,10 @@ class OpenAI extends BaseLLM {
|
|||
}),
|
||||
});
|
||||
|
||||
if (response.status !== 200) {
|
||||
throw new Error(await response.text());
|
||||
}
|
||||
|
||||
// Receive as SSE
|
||||
if (response.body === null) {
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ import {
|
|||
vscBackground,
|
||||
vscForeground,
|
||||
} from ".";
|
||||
import useHistory from "../hooks/useHistory";
|
||||
import { defaultModelSelector } from "../redux/selectors/modelSelectors";
|
||||
import {
|
||||
setBottomMessage,
|
||||
|
|
@ -151,8 +150,6 @@ const Layout = () => {
|
|||
};
|
||||
}, [timeline]);
|
||||
|
||||
const { saveSession } = useHistory();
|
||||
|
||||
useEffect(() => {
|
||||
const handler = (event: any) => {
|
||||
if (event.data.type === "addModel") {
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import {
|
|||
import { RootStore } from "../../redux/store";
|
||||
import { getFontSize } from "../../util";
|
||||
import { logDevData } from "../../util/ide";
|
||||
import HeaderButtonWithText from "../HeaderButtonWithText";
|
||||
import StyledMarkdownPreview from "../markdown/StyledMarkdownPreview";
|
||||
|
||||
interface StepContainerProps {
|
||||
|
|
@ -108,32 +109,36 @@ function StepContainer(props: StepContainerProps) {
|
|||
{(isHovered || typeof feedback !== "undefined") && !active && (
|
||||
<div className="flex items-center gap-2 bottom-0 right-2 absolute">
|
||||
{feedback === false || (
|
||||
<HandThumbUpIcon
|
||||
className={
|
||||
"cursor-pointer hover:text-green-500" +
|
||||
(feedback === true ? " text-green-500" : "")
|
||||
}
|
||||
width="1.2em"
|
||||
height="1.2em"
|
||||
color={lightGray}
|
||||
onClick={() => {
|
||||
sendFeedback(true);
|
||||
}}
|
||||
/>
|
||||
<HeaderButtonWithText text="Helpful">
|
||||
<HandThumbUpIcon
|
||||
className={
|
||||
"cursor-pointer hover:text-green-500" +
|
||||
(feedback === true ? " text-green-500" : "")
|
||||
}
|
||||
width="1.2em"
|
||||
height="1.2em"
|
||||
color={lightGray}
|
||||
onClick={() => {
|
||||
sendFeedback(true);
|
||||
}}
|
||||
/>
|
||||
</HeaderButtonWithText>
|
||||
)}
|
||||
{feedback === true || (
|
||||
<HandThumbDownIcon
|
||||
className={
|
||||
"cursor-pointer hover:text-red-500" +
|
||||
(feedback === false ? " text-red-500" : "")
|
||||
}
|
||||
width="1.2em"
|
||||
height="1.2em"
|
||||
color={lightGray}
|
||||
onClick={() => {
|
||||
sendFeedback(false);
|
||||
}}
|
||||
/>
|
||||
<HeaderButtonWithText text="Unhelpful">
|
||||
<HandThumbDownIcon
|
||||
className={
|
||||
"cursor-pointer hover:text-red-500" +
|
||||
(feedback === false ? " text-red-500" : "")
|
||||
}
|
||||
width="1.2em"
|
||||
height="1.2em"
|
||||
color={lightGray}
|
||||
onClick={() => {
|
||||
sendFeedback(false);
|
||||
}}
|
||||
/>
|
||||
</HeaderButtonWithText>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
|
|
|||
|
|
@ -7,8 +7,7 @@ export const lightGray = "#646464";
|
|||
export const buttonColor = "#1bbe84";
|
||||
export const buttonColorHover = "#1bbe84a8";
|
||||
|
||||
export const secondaryDark =
|
||||
"var(--vscode-list-hoverBackground, rgb(45 45 45))";
|
||||
export const secondaryDark = "var(--vscode-input-background, rgb(45 45 45))";
|
||||
// export const vscBackground = "var(--vscode-editor-background, rgb(30 30 30))";
|
||||
export const vscBackground = "var(--vscode-sideBar-background, rgb(30 30 30))";
|
||||
export const vscForeground = "var(--vscode-editor-foreground, #fff)";
|
||||
|
|
|
|||
|
|
@ -48,7 +48,6 @@ import {
|
|||
addContextItems,
|
||||
addContextItemsAtIndex,
|
||||
deleteContextWithIds,
|
||||
newSession,
|
||||
setInactive,
|
||||
} from "../../redux/slices/stateSlice";
|
||||
import { setBottomMessage } from "../../redux/slices/uiStateSlice";
|
||||
|
|
@ -371,7 +370,6 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => {
|
|||
const [miniSearch, firstResults] = useContext(SearchContext);
|
||||
|
||||
const dispatch = useDispatch();
|
||||
const workspacePaths = (window as any).workspacePaths || [];
|
||||
const state = useSelector((state: RootStore) => state.state);
|
||||
|
||||
const [history, setHistory] = React.useState<string[]>([]);
|
||||
|
|
@ -711,7 +709,7 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => {
|
|||
};
|
||||
}, []);
|
||||
|
||||
const { saveSession } = useHistory();
|
||||
const { saveSession } = useHistory(dispatch);
|
||||
|
||||
useEffect(() => {
|
||||
if (!inputRef.current || !props.isMainInput) {
|
||||
|
|
@ -725,14 +723,12 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => {
|
|||
inputRef.current!.focus();
|
||||
if (state.history.length > 0) {
|
||||
saveSession();
|
||||
dispatch(newSession());
|
||||
}
|
||||
dispatch(setTakenActionTrue(null));
|
||||
} else if (event.data.type === "focusContinueInputWithEdit") {
|
||||
inputRef.current!.focus();
|
||||
if (state.history.length > 0) {
|
||||
saveSession();
|
||||
dispatch(newSession());
|
||||
}
|
||||
|
||||
if (!inputRef.current?.value.startsWith("/edit")) {
|
||||
|
|
@ -741,7 +737,6 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => {
|
|||
dispatch(setTakenActionTrue(null));
|
||||
} else if (event.data.type === "focusContinueInputWithNewSession") {
|
||||
saveSession();
|
||||
dispatch(newSession());
|
||||
dispatch(setTakenActionTrue(null));
|
||||
}
|
||||
};
|
||||
|
|
@ -1221,7 +1216,7 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => {
|
|||
fontSize={getFontSize()}
|
||||
disabled={props.disabled}
|
||||
placeholder={
|
||||
history.length === 0
|
||||
state.history.length === 0
|
||||
? `Ask a question, '/' for slash commands, '@' to add context`
|
||||
: `Ask a follow-up`
|
||||
}
|
||||
|
|
@ -1665,7 +1660,6 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => {
|
|||
<NewSessionButton
|
||||
onClick={() => {
|
||||
saveSession();
|
||||
dispatch(newSession());
|
||||
}}
|
||||
className="mr-auto"
|
||||
>
|
||||
|
|
|
|||
|
|
@ -142,6 +142,7 @@ function useChatHandler(dispatch: Dispatch) {
|
|||
logs.push(log);
|
||||
};
|
||||
defaultModel.writeLog = writeLog;
|
||||
|
||||
if (!commandAndInput) {
|
||||
await _streamNormalInput(messages);
|
||||
} else {
|
||||
|
|
@ -149,17 +150,17 @@ function useChatHandler(dispatch: Dispatch) {
|
|||
await _streamSlashCommand(messages, slashCommand, commandInput);
|
||||
}
|
||||
|
||||
defaultModel.writeLog = undefined;
|
||||
const pairedLogs = [];
|
||||
for (let i = 0; i < logs.length; i += 2) {
|
||||
pairedLogs.push([logs[i], logs[i + 1]]);
|
||||
}
|
||||
dispatch(addLogs(pairedLogs));
|
||||
|
||||
dispatch(setInactive());
|
||||
} catch (e) {
|
||||
console.log("Continue: error streaming response: ", e);
|
||||
errorPopup(e.message);
|
||||
} finally {
|
||||
dispatch(setInactive());
|
||||
defaultModel.writeLog = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
import { Dispatch } from "@reduxjs/toolkit";
|
||||
import { PersistedSessionInfo, SessionInfo } from "core";
|
||||
import { ideRequest } from "core/ide/messaging";
|
||||
import { useSelector } from "react-redux";
|
||||
import { defaultModelSelector } from "../redux/selectors/modelSelectors";
|
||||
import { newSession } from "../redux/slices/stateSlice";
|
||||
import { RootStore } from "../redux/store";
|
||||
|
||||
function truncateText(text: string, maxLength: number) {
|
||||
|
|
@ -10,8 +13,9 @@ function truncateText(text: string, maxLength: number) {
|
|||
return text;
|
||||
}
|
||||
|
||||
function useHistory() {
|
||||
function useHistory(dispatch: Dispatch) {
|
||||
const state = useSelector((state: RootStore) => state.state);
|
||||
const defaultModel = useSelector(defaultModelSelector);
|
||||
|
||||
async function getHistory(): Promise<SessionInfo[]> {
|
||||
return await ideRequest("history", {});
|
||||
|
|
@ -19,13 +23,28 @@ function useHistory() {
|
|||
|
||||
async function saveSession() {
|
||||
if (state.history.length === 0) return;
|
||||
|
||||
const stateCopy = { ...state };
|
||||
dispatch(newSession());
|
||||
await new Promise((resolve) => setTimeout(resolve, 10));
|
||||
|
||||
const { content: title } = await defaultModel.chat(
|
||||
[
|
||||
...stateCopy.history.map((item) => item.message),
|
||||
{
|
||||
role: "user",
|
||||
content:
|
||||
"Give a maximum 40 character title to describe this conversation so far. The title should help me recall the conversation if I look for it later. DO NOT PUT QUOTES AROUND THE TITLE",
|
||||
},
|
||||
],
|
||||
{ maxTokens: 20 }
|
||||
);
|
||||
|
||||
const sessionInfo: PersistedSessionInfo = {
|
||||
history: state.history,
|
||||
title:
|
||||
state.title === "New Session"
|
||||
? truncateText(state.history[0].message.content, 50)
|
||||
: state.title,
|
||||
sessionId: state.sessionId,
|
||||
history: stateCopy.history,
|
||||
title,
|
||||
// truncateText(stateCopy.history[0].message.content, 50)
|
||||
sessionId: stateCopy.sessionId,
|
||||
workspaceDirectory: (window as any).workspacePaths?.[0] || "",
|
||||
};
|
||||
return await ideRequest("saveSession", sessionInfo);
|
||||
|
|
|
|||
|
|
@ -335,13 +335,12 @@ function GUI(props: GUIProps) {
|
|||
]
|
||||
);
|
||||
|
||||
const { saveSession } = useHistory();
|
||||
const { saveSession } = useHistory(dispatch);
|
||||
|
||||
useEffect(() => {
|
||||
const handler = (event: any) => {
|
||||
if (event.data.type === "newSession") {
|
||||
saveSession();
|
||||
dispatch(newSession());
|
||||
mainTextInputRef.current?.focus?.();
|
||||
}
|
||||
};
|
||||
|
|
@ -408,128 +407,137 @@ function GUI(props: GUIProps) {
|
|||
);
|
||||
|
||||
return (
|
||||
<TopGuiDiv
|
||||
ref={topGuiDivRef}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Enter" && e.ctrlKey) {
|
||||
onMainTextInput();
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div className="max-w-3xl m-auto">
|
||||
<StepsDiv>
|
||||
{state.history.map((item, index: number) => {
|
||||
return (
|
||||
<Fragment key={index}>
|
||||
<ErrorBoundary
|
||||
FallbackComponent={fallbackRender}
|
||||
onReset={() => {
|
||||
dispatch(newSession());
|
||||
}}
|
||||
>
|
||||
{item.message.role === "user" ? (
|
||||
<ComboBox
|
||||
isMainInput={false}
|
||||
value={item.message.content}
|
||||
isLastUserInput={isLastUserInput(index)}
|
||||
onEnter={(e, value) => {
|
||||
if (value) {
|
||||
dispatch(resubmitAtIndex({ index, content: value }));
|
||||
streamResponse(value, index);
|
||||
<>
|
||||
<TopGuiDiv
|
||||
ref={topGuiDivRef}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Enter" && e.ctrlKey) {
|
||||
onMainTextInput();
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div className="max-w-3xl m-auto">
|
||||
<StepsDiv>
|
||||
{state.history.map((item, index: number) => {
|
||||
return (
|
||||
<Fragment key={index}>
|
||||
<ErrorBoundary
|
||||
FallbackComponent={fallbackRender}
|
||||
onReset={() => {
|
||||
dispatch(newSession());
|
||||
}}
|
||||
>
|
||||
{item.message.role === "user" ? (
|
||||
<ComboBox
|
||||
isMainInput={false}
|
||||
value={item.message.content}
|
||||
isLastUserInput={isLastUserInput(index)}
|
||||
onEnter={(e, value) => {
|
||||
if (value) {
|
||||
dispatch(
|
||||
resubmitAtIndex({ index, content: value })
|
||||
);
|
||||
streamResponse(value, index);
|
||||
}
|
||||
e?.stopPropagation();
|
||||
e?.preventDefault();
|
||||
}}
|
||||
isToggleOpen={
|
||||
typeof stepsOpen[index] === "undefined"
|
||||
? true
|
||||
: stepsOpen[index]!
|
||||
}
|
||||
e?.stopPropagation();
|
||||
e?.preventDefault();
|
||||
}}
|
||||
isToggleOpen={
|
||||
typeof stepsOpen[index] === "undefined"
|
||||
? true
|
||||
: stepsOpen[index]!
|
||||
}
|
||||
index={index}
|
||||
/>
|
||||
) : (
|
||||
<TimelineItem
|
||||
item={item}
|
||||
iconElement={
|
||||
false ? (
|
||||
<CodeBracketSquareIcon width="16px" height="16px" />
|
||||
) : false ? (
|
||||
<ExclamationTriangleIcon
|
||||
width="16px"
|
||||
height="16px"
|
||||
color="red"
|
||||
index={index}
|
||||
/>
|
||||
) : (
|
||||
<TimelineItem
|
||||
item={item}
|
||||
iconElement={
|
||||
false ? (
|
||||
<CodeBracketSquareIcon width="16px" height="16px" />
|
||||
) : false ? (
|
||||
<ExclamationTriangleIcon
|
||||
width="16px"
|
||||
height="16px"
|
||||
color="red"
|
||||
/>
|
||||
) : (
|
||||
<ChatBubbleOvalLeftIcon
|
||||
width="16px"
|
||||
height="16px"
|
||||
/>
|
||||
)
|
||||
}
|
||||
open={
|
||||
typeof stepsOpen[index] === "undefined"
|
||||
? false
|
||||
? false
|
||||
: true
|
||||
: stepsOpen[index]!
|
||||
}
|
||||
onToggle={() => {}}
|
||||
>
|
||||
{false ? ( // Most of these falses were previously (step.error)
|
||||
<ErrorStepContainer
|
||||
onClose={() => {}}
|
||||
error={undefined}
|
||||
onDelete={() => {}}
|
||||
/>
|
||||
) : (
|
||||
<ChatBubbleOvalLeftIcon width="16px" height="16px" />
|
||||
)
|
||||
}
|
||||
open={
|
||||
typeof stepsOpen[index] === "undefined"
|
||||
? false
|
||||
? false
|
||||
: true
|
||||
: stepsOpen[index]!
|
||||
}
|
||||
onToggle={() => {}}
|
||||
>
|
||||
{false ? ( // Most of these falses were previously (step.error)
|
||||
<ErrorStepContainer
|
||||
onClose={() => {}}
|
||||
error={undefined}
|
||||
onDelete={() => {}}
|
||||
/>
|
||||
) : (
|
||||
<StepContainer
|
||||
index={index}
|
||||
isLast={index === sessionState.history.length - 1}
|
||||
isFirst={index === 0}
|
||||
open={
|
||||
typeof stepsOpen[index] === "undefined"
|
||||
? true
|
||||
: stepsOpen[index]!
|
||||
}
|
||||
key={index}
|
||||
onUserInput={(input: string) => {}}
|
||||
item={item}
|
||||
onReverse={() => {}}
|
||||
onRetry={() => {}}
|
||||
onDelete={() => {}}
|
||||
/>
|
||||
)}
|
||||
</TimelineItem>
|
||||
)}
|
||||
{/* <div className="h-2"></div> */}
|
||||
</ErrorBoundary>
|
||||
</Fragment>
|
||||
);
|
||||
})}
|
||||
</StepsDiv>
|
||||
<StepContainer
|
||||
index={index}
|
||||
isLast={index === sessionState.history.length - 1}
|
||||
isFirst={index === 0}
|
||||
open={
|
||||
typeof stepsOpen[index] === "undefined"
|
||||
? true
|
||||
: stepsOpen[index]!
|
||||
}
|
||||
key={index}
|
||||
onUserInput={(input: string) => {}}
|
||||
item={item}
|
||||
onReverse={() => {}}
|
||||
onRetry={() => {}}
|
||||
onDelete={() => {}}
|
||||
/>
|
||||
)}
|
||||
</TimelineItem>
|
||||
)}
|
||||
{/* <div className="h-2"></div> */}
|
||||
</ErrorBoundary>
|
||||
</Fragment>
|
||||
);
|
||||
})}
|
||||
</StepsDiv>
|
||||
|
||||
<div ref={aboveComboBoxDivRef} />
|
||||
{active ? (
|
||||
<StopButton
|
||||
onClick={() => {
|
||||
dispatch(setInactive());
|
||||
}}
|
||||
>
|
||||
{getMetaKeyLabel()} ⌫ Cancel
|
||||
</StopButton>
|
||||
) : (
|
||||
<ComboBox
|
||||
isLastUserInput={false}
|
||||
isMainInput={true}
|
||||
ref={mainTextInputRef}
|
||||
onEnter={(e, _) => {
|
||||
onMainTextInput(e);
|
||||
e?.stopPropagation();
|
||||
e?.preventDefault();
|
||||
}}
|
||||
onInputValueChange={() => {}}
|
||||
onToggleAddContext={() => {}}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</TopGuiDiv>
|
||||
<div ref={aboveComboBoxDivRef} />
|
||||
{active || (
|
||||
<ComboBox
|
||||
isLastUserInput={false}
|
||||
isMainInput={true}
|
||||
ref={mainTextInputRef}
|
||||
onEnter={(e, _) => {
|
||||
onMainTextInput(e);
|
||||
e?.stopPropagation();
|
||||
e?.preventDefault();
|
||||
}}
|
||||
onInputValueChange={() => {}}
|
||||
onToggleAddContext={() => {}}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</TopGuiDiv>
|
||||
{active && (
|
||||
<StopButton
|
||||
className="mt-auto"
|
||||
onClick={() => {
|
||||
dispatch(setInactive());
|
||||
}}
|
||||
>
|
||||
{getMetaKeyLabel()} ⌫ Cancel
|
||||
</StopButton>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,8 +37,10 @@ const SectionHeader = styled.tr`
|
|||
width: 100%;
|
||||
font-weight: bold;
|
||||
text-align: center;
|
||||
align-items: center;
|
||||
margin: 0;
|
||||
position: sticky;
|
||||
height: 1.5em;
|
||||
`;
|
||||
|
||||
const TdDiv = styled.div`
|
||||
|
|
@ -65,7 +67,7 @@ function TableRow({
|
|||
const workspacePaths = (window as any).workspacePaths || [""];
|
||||
const [hovered, setHovered] = useState(false);
|
||||
|
||||
const { saveSession, deleteSession, loadSession } = useHistory();
|
||||
const { saveSession, deleteSession, loadSession } = useHistory(dispatch);
|
||||
|
||||
return (
|
||||
<td
|
||||
|
|
@ -141,7 +143,8 @@ function History() {
|
|||
const stickyHistoryHeaderRef = React.useRef<HTMLDivElement>(null);
|
||||
const [headerHeight, setHeaderHeight] = useState(0);
|
||||
|
||||
const { getHistory } = useHistory();
|
||||
const dispatch = useDispatch();
|
||||
const { getHistory } = useHistory(dispatch);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchSessions = async () => {
|
||||
|
|
@ -241,21 +244,21 @@ function History() {
|
|||
return (
|
||||
<Fragment key={index}>
|
||||
{index === 0 && date > yesterday && (
|
||||
<SectionHeader style={{ top: `${headerHeight}px` }}>
|
||||
<SectionHeader style={{ top: `${headerHeight - 1}px` }}>
|
||||
Today
|
||||
</SectionHeader>
|
||||
)}
|
||||
{date < yesterday &&
|
||||
date > lastWeek &&
|
||||
prevDate > yesterday && (
|
||||
<SectionHeader style={{ top: `${headerHeight}px` }}>
|
||||
<SectionHeader style={{ top: `${headerHeight - 1}px` }}>
|
||||
This Week
|
||||
</SectionHeader>
|
||||
)}
|
||||
{date < lastWeek &&
|
||||
date > lastMonth &&
|
||||
prevDate > lastWeek && (
|
||||
<SectionHeader style={{ top: `${headerHeight}px` }}>
|
||||
<SectionHeader style={{ top: `${headerHeight - 1}px` }}>
|
||||
This Month
|
||||
</SectionHeader>
|
||||
)}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue