🚧 inspect prompt
This commit is contained in:
parent
daaecd1985
commit
fd4c256fba
16 changed files with 388 additions and 759 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -8,7 +8,7 @@ import {
|
|||
} from "./util/vscode";
|
||||
import { RangeInFile } from "../schema/RangeInFile";
|
||||
import { setFocusedOnContinueInput } from "./commands";
|
||||
import { windowId } from "./activation/activate";
|
||||
import { ideProtocolClient, windowId } from "./activation/activate";
|
||||
import * as io from "socket.io-client";
|
||||
|
||||
let sockets: { [url: string]: io.Socket | undefined } = {};
|
||||
|
|
@ -165,6 +165,10 @@ export function setupDebugPanel(
|
|||
openEditorAndRevealRange(data.path, undefined, vscode.ViewColumn.One);
|
||||
break;
|
||||
}
|
||||
case "showVirtualFile": {
|
||||
ideProtocolClient.showVirtualFile(data.name, data.content);
|
||||
break;
|
||||
}
|
||||
case "toggleDevTools": {
|
||||
vscode.commands.executeCommand("workbench.action.toggleDevTools");
|
||||
vscode.commands.executeCommand("continue.viewLogs");
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ import {
|
|||
TrashIcon,
|
||||
XMarkIcon,
|
||||
} from "@heroicons/react/24/outline";
|
||||
import { postVscMessage } from "../vscode";
|
||||
import { postToIde } from "../vscode";
|
||||
import { GUIClientContext } from "../App";
|
||||
import { MeiliSearch } from "meilisearch";
|
||||
import { setBottomMessage } from "../redux/slices/uiStateSlice";
|
||||
|
|
@ -1054,8 +1054,8 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => {
|
|||
onMouseEnter={() => setIsHovered(true)}
|
||||
onMouseLeave={(e) => {
|
||||
if (
|
||||
e.relatedTarget === deleteButtonDivRef.current
|
||||
// || deleteButtonDivRef.current?.contains(e.relatedTarget as Node)
|
||||
e.relatedTarget === deleteButtonDivRef.current ||
|
||||
deleteButtonDivRef.current?.contains(e.relatedTarget as Node)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -1077,14 +1077,14 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => {
|
|||
dispatch(setBottomMessage(undefined));
|
||||
},
|
||||
onBlur: (e) => {
|
||||
// if (
|
||||
// // topRef.current?.contains(e.relatedTarget as Node) ||
|
||||
// document
|
||||
// .getElementById("toggle-context-div")
|
||||
// ?.contains(e.relatedTarget as Node)
|
||||
// ) {
|
||||
// return;
|
||||
// }
|
||||
if (
|
||||
topRef.current?.contains(e.relatedTarget as Node) ||
|
||||
document
|
||||
.getElementById("toggle-context-div")
|
||||
?.contains(e.relatedTarget as Node)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
setInputFocused(false);
|
||||
},
|
||||
onKeyDown: (event) => {
|
||||
|
|
@ -1197,7 +1197,7 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => {
|
|||
// Remove focus from the input
|
||||
inputRef.current?.blur();
|
||||
// Move cursor back over to the editor
|
||||
postVscMessage("focusEditor", {});
|
||||
postToIde("focusEditor", {});
|
||||
}
|
||||
}
|
||||
// Home and end keys
|
||||
|
|
@ -1241,8 +1241,20 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => {
|
|||
<HeaderButtonWithText
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
if (props.groupIndices)
|
||||
client?.showLogsAtIndex(props.groupIndices[1]);
|
||||
if (props.groupIndices) {
|
||||
const content =
|
||||
"This is the exact prompt sent to the LLM: \n\n" +
|
||||
timeline
|
||||
.filter((_, i) => {
|
||||
return props.groupIndices?.includes(i);
|
||||
})
|
||||
.flatMap((s) => s.logs || [])
|
||||
.join("\n");
|
||||
postToIde("showVirtualFile", {
|
||||
name: "Inspect Prompt",
|
||||
content,
|
||||
});
|
||||
}
|
||||
}}
|
||||
text="Inspect Prompt"
|
||||
>
|
||||
|
|
@ -1400,8 +1412,6 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => {
|
|||
disabled={!(inputRef.current as any)?.value && !active}
|
||||
onClick={() => {
|
||||
if (active) {
|
||||
// TODO: Stop running steps
|
||||
// client?.deleteAtIndex(sessionHistory.current_index);
|
||||
client?.stopSession();
|
||||
dispatch(setActive(false));
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1,355 +0,0 @@
|
|||
import React, {
|
||||
useCallback,
|
||||
useContext,
|
||||
useEffect,
|
||||
useRef,
|
||||
useState,
|
||||
} from "react";
|
||||
import styled, { keyframes } from "styled-components";
|
||||
import {
|
||||
defaultBorderRadius,
|
||||
lightGray,
|
||||
secondaryDark,
|
||||
vscBackground,
|
||||
vscForeground,
|
||||
} from ".";
|
||||
import HeaderButtonWithText from "./HeaderButtonWithText";
|
||||
import {
|
||||
XMarkIcon,
|
||||
CheckIcon,
|
||||
ChevronDownIcon,
|
||||
ChevronRightIcon,
|
||||
MagnifyingGlassIcon,
|
||||
StopCircleIcon,
|
||||
} from "@heroicons/react/24/outline";
|
||||
import { GUIClientContext } from "../App";
|
||||
import {
|
||||
getFontSize,
|
||||
getMetaKeyLabel,
|
||||
isMetaEquivalentKeyPressed,
|
||||
} from "../util";
|
||||
import { RootStore } from "../redux/store";
|
||||
import { useSelector } from "react-redux";
|
||||
|
||||
interface UserInputContainerProps {
|
||||
onDelete: () => void;
|
||||
children: string;
|
||||
index: number;
|
||||
onToggle: (arg0: boolean) => void;
|
||||
onToggleAll: (arg0: boolean) => void;
|
||||
isToggleOpen: boolean;
|
||||
active: boolean;
|
||||
groupIndices: number[];
|
||||
}
|
||||
|
||||
const gradient = keyframes`
|
||||
0% {
|
||||
background-position: 0px 0;
|
||||
}
|
||||
100% {
|
||||
background-position: 100em 0;
|
||||
}
|
||||
`;
|
||||
|
||||
const ToggleDiv = styled.div`
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
cursor: pointer;
|
||||
|
||||
height: 100%;
|
||||
padding: 0 4px;
|
||||
|
||||
&:hover {
|
||||
background-color: ${vscBackground};
|
||||
}
|
||||
`;
|
||||
|
||||
const GradientBorder = styled.div<{
|
||||
borderWidth?: number;
|
||||
borderRadius?: string;
|
||||
borderColor?: string;
|
||||
isFirst: boolean;
|
||||
isLast: boolean;
|
||||
loading: boolean;
|
||||
}>`
|
||||
border-radius: ${(props) => props.borderRadius || "0"};
|
||||
padding: ${(props) =>
|
||||
`${(props.borderWidth || 1) / (props.isFirst ? 1 : 2)}px`};
|
||||
background: ${(props) =>
|
||||
props.borderColor
|
||||
? props.borderColor
|
||||
: `repeating-linear-gradient(
|
||||
101.79deg,
|
||||
#1BBE84 0%,
|
||||
#331BBE 16%,
|
||||
#BE1B55 33%,
|
||||
#A6BE1B 55%,
|
||||
#BE1B55 67%,
|
||||
#331BBE 85%,
|
||||
#1BBE84 99%
|
||||
)`};
|
||||
animation: ${(props) => (props.loading ? gradient : "")} 6s linear infinite;
|
||||
background-size: 200% 200%;
|
||||
`;
|
||||
|
||||
const StyledDiv = styled.div<{ editing: boolean; fontSize?: number }>`
|
||||
font-size: ${(props) => props.fontSize || getFontSize()}px;
|
||||
font-family: inherit;
|
||||
border-radius: ${defaultBorderRadius};
|
||||
height: auto;
|
||||
background-color: ${secondaryDark};
|
||||
color: ${vscForeground};
|
||||
align-items: center;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
overflow: hidden;
|
||||
display: grid;
|
||||
grid-template-columns: 1fr auto;
|
||||
|
||||
outline: ${(props) => (props.editing ? `1px solid ${lightGray}` : "none")};
|
||||
cursor: text;
|
||||
`;
|
||||
|
||||
const DeleteButtonDiv = styled.div`
|
||||
position: absolute;
|
||||
top: 8px;
|
||||
right: 8px;
|
||||
background-color: ${secondaryDark};
|
||||
box-shadow: 4px 4px 10px ${secondaryDark};
|
||||
border-radius: ${defaultBorderRadius};
|
||||
`;
|
||||
|
||||
const GridDiv = styled.div`
|
||||
display: grid;
|
||||
grid-template-columns: auto 1fr;
|
||||
grid-gap: 8px;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
`;
|
||||
|
||||
function stringWithEllipsis(str: string, maxLen: number) {
|
||||
if (str.length > maxLen) {
|
||||
return str.substring(0, maxLen - 3) + "...\n(Click to expand)";
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
const UserInputContainer = (props: UserInputContainerProps) => {
|
||||
const [isHovered, setIsHovered] = useState(false);
|
||||
const [isEditing, setIsEditing] = useState(false);
|
||||
|
||||
const divRef = useRef<HTMLDivElement>(null);
|
||||
const client = useContext(GUIClientContext);
|
||||
|
||||
const [prevContent, setPrevContent] = useState("");
|
||||
|
||||
const history = useSelector((state: RootStore) => state.sessionState.history);
|
||||
|
||||
useEffect(() => {
|
||||
if (isEditing && divRef.current) {
|
||||
setPrevContent(divRef.current.innerText);
|
||||
divRef.current.focus();
|
||||
|
||||
if (divRef.current.innerText !== "") {
|
||||
const range = document.createRange();
|
||||
const sel = window.getSelection();
|
||||
range.setStart(divRef.current, 0);
|
||||
range.setEnd(divRef.current, 1);
|
||||
sel?.removeAllRanges();
|
||||
sel?.addRange(range);
|
||||
}
|
||||
}
|
||||
}, [isEditing, divRef.current]);
|
||||
|
||||
const onBlur = useCallback(() => {
|
||||
setIsEditing(false);
|
||||
if (divRef.current) {
|
||||
divRef.current.innerText = prevContent;
|
||||
divRef.current.blur();
|
||||
}
|
||||
}, [divRef.current, prevContent]);
|
||||
|
||||
useEffect(() => {
|
||||
const handleKeyDown = (event: KeyboardEvent) => {
|
||||
if (event.key === "Escape") {
|
||||
onBlur();
|
||||
}
|
||||
};
|
||||
divRef.current?.addEventListener("keydown", handleKeyDown);
|
||||
return () => {
|
||||
divRef.current?.removeEventListener("keydown", handleKeyDown);
|
||||
};
|
||||
}, [prevContent, divRef.current, isEditing, onBlur]);
|
||||
|
||||
const doneEditing = (e: any) => {
|
||||
if (!divRef.current?.innerText) {
|
||||
return;
|
||||
}
|
||||
setPrevContent(divRef.current.innerText);
|
||||
client?.editStepAtIndex(divRef.current.innerText, props.index);
|
||||
setIsEditing(false);
|
||||
e.stopPropagation();
|
||||
divRef.current?.blur();
|
||||
};
|
||||
|
||||
const [divTextContent, setDivTextContent] = useState("");
|
||||
|
||||
const checkButtonRef = useRef<HTMLButtonElement>(null);
|
||||
|
||||
return (
|
||||
<GradientBorder
|
||||
loading={props.active}
|
||||
isFirst={false}
|
||||
isLast={false}
|
||||
borderColor={props.active ? undefined : vscBackground}
|
||||
borderRadius={defaultBorderRadius}
|
||||
>
|
||||
<StyledDiv
|
||||
fontSize={getFontSize()}
|
||||
editing={isEditing}
|
||||
onMouseEnter={() => {
|
||||
setIsHovered(true);
|
||||
}}
|
||||
onMouseLeave={() => {
|
||||
setIsHovered(false);
|
||||
}}
|
||||
onClick={() => {
|
||||
setIsEditing(true);
|
||||
}}
|
||||
>
|
||||
<GridDiv>
|
||||
<ToggleDiv
|
||||
onClick={
|
||||
props.isToggleOpen
|
||||
? (e) => {
|
||||
e.stopPropagation();
|
||||
if (isMetaEquivalentKeyPressed(e)) {
|
||||
props.onToggleAll(false);
|
||||
} else {
|
||||
props.onToggle(false);
|
||||
}
|
||||
}
|
||||
: (e) => {
|
||||
e.stopPropagation();
|
||||
if (isMetaEquivalentKeyPressed(e)) {
|
||||
props.onToggleAll(true);
|
||||
} else {
|
||||
props.onToggle(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
>
|
||||
{props.isToggleOpen ? (
|
||||
<ChevronDownIcon width="1.4em" height="1.4em" />
|
||||
) : (
|
||||
<ChevronRightIcon width="1.4em" height="1.4em" />
|
||||
)}
|
||||
</ToggleDiv>
|
||||
<div
|
||||
style={{
|
||||
padding: "8px",
|
||||
paddingTop: "4px",
|
||||
paddingBottom: "4px",
|
||||
width: "100%",
|
||||
}}
|
||||
>
|
||||
<div
|
||||
ref={divRef}
|
||||
onBlur={(e) => {
|
||||
if (e.relatedTarget !== checkButtonRef.current) onBlur();
|
||||
}}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Enter" && !e.shiftKey) {
|
||||
e.preventDefault();
|
||||
doneEditing(e);
|
||||
}
|
||||
}}
|
||||
onInput={(e) => {
|
||||
setDivTextContent((e.target as any).innerText);
|
||||
}}
|
||||
contentEditable={true}
|
||||
suppressContentEditableWarning={true}
|
||||
className="mr-6 ml-1 cursor-text w-full py-2 flex items-center content-center outline-none"
|
||||
>
|
||||
{isEditing
|
||||
? props.children
|
||||
: stringWithEllipsis(props.children, 600)}
|
||||
</div>
|
||||
<DeleteButtonDiv>
|
||||
{(isHovered || isEditing) && (
|
||||
<div className="flex">
|
||||
{isEditing ? (
|
||||
<HeaderButtonWithText
|
||||
onClick={(e) => {
|
||||
doneEditing(e);
|
||||
e.stopPropagation();
|
||||
}}
|
||||
text="Done"
|
||||
disabled={
|
||||
divTextContent === "" || divTextContent === prevContent
|
||||
}
|
||||
ref={checkButtonRef}
|
||||
>
|
||||
<CheckIcon
|
||||
width="1.4em"
|
||||
height="1.4em"
|
||||
color={
|
||||
divTextContent === "" ||
|
||||
divTextContent === prevContent
|
||||
? lightGray
|
||||
: vscForeground
|
||||
}
|
||||
/>
|
||||
</HeaderButtonWithText>
|
||||
) : (
|
||||
<>
|
||||
{history
|
||||
.filter(
|
||||
(h, i: number) =>
|
||||
props.groupIndices.includes(i) && h.logs
|
||||
)
|
||||
.some((h) => h.logs!.length > 0) && (
|
||||
<HeaderButtonWithText
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
client?.showLogsAtIndex(props.groupIndices[1]);
|
||||
}}
|
||||
text="Context Used"
|
||||
>
|
||||
<MagnifyingGlassIcon width="1.4em" height="1.4em" />
|
||||
</HeaderButtonWithText>
|
||||
)}
|
||||
<HeaderButtonWithText
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
if (props.active) {
|
||||
client.stopSession();
|
||||
} else {
|
||||
props.onDelete();
|
||||
}
|
||||
}}
|
||||
text={
|
||||
props.active
|
||||
? `Stop (${getMetaKeyLabel()}⌫)`
|
||||
: "Delete"
|
||||
}
|
||||
>
|
||||
{props.active ? (
|
||||
<StopCircleIcon width="1.4em" height="1.4em" />
|
||||
) : (
|
||||
<XMarkIcon width="1.4em" height="1.4em" />
|
||||
)}
|
||||
</HeaderButtonWithText>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</DeleteButtonDiv>
|
||||
</div>
|
||||
</GridDiv>
|
||||
</StyledDiv>
|
||||
</GradientBorder>
|
||||
);
|
||||
};
|
||||
export default UserInputContainer;
|
||||
|
|
@ -1,12 +1,12 @@
|
|||
import React from "react";
|
||||
import { postVscMessage } from "../vscode";
|
||||
import { postToIde } from "../vscode";
|
||||
|
||||
function VSCodeFileLink(props: { path: string; text?: string }) {
|
||||
return (
|
||||
<a
|
||||
href={`file://${props.path}`}
|
||||
onClick={() => {
|
||||
postVscMessage("openFile", { path: props.path });
|
||||
postToIde("openFile", { path: props.path });
|
||||
}}
|
||||
>
|
||||
{props.text || props.path}
|
||||
|
|
|
|||
|
|
@ -26,8 +26,6 @@ abstract class AbstractContinueGUIClientProtocol {
|
|||
|
||||
abstract toggleAddingHighlightedCode(): void;
|
||||
|
||||
abstract showLogsAtIndex(index: number): void;
|
||||
|
||||
abstract showContextVirtualFile(): void;
|
||||
|
||||
abstract selectContextItem(id: string, query: string): void;
|
||||
|
|
|
|||
|
|
@ -133,10 +133,6 @@ class ContinueGUIClientProtocol extends AbstractContinueGUIClientProtocol {
|
|||
this.messenger?.send("toggle_adding_highlighted_code", {});
|
||||
}
|
||||
|
||||
showLogsAtIndex(index: number): void {
|
||||
this.messenger?.send("show_logs_at_index", { index });
|
||||
}
|
||||
|
||||
showContextVirtualFile(index?: number): void {
|
||||
this.messenger?.send("show_context_virtual_file", { index });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import {
|
|||
setHighlightedCode,
|
||||
setServerStatusMessage,
|
||||
} from "../redux/slices/miscSlice";
|
||||
import { postVscMessage } from "../vscode";
|
||||
import { postToIde } from "../vscode";
|
||||
import { useSelector } from "react-redux";
|
||||
import { RootStore } from "../redux/store";
|
||||
import {
|
||||
|
|
@ -21,18 +21,15 @@ async function clientSetup(
|
|||
) {
|
||||
// Listen for updates to the session state
|
||||
client.onSessionUpdate((update) => {
|
||||
console.log(update);
|
||||
dispatch(processSessionUpdate(update));
|
||||
});
|
||||
|
||||
fetch(`${serverUrl}/slash_commands`).then(async (resp) => {
|
||||
const sc = await resp.json();
|
||||
console.log(sc);
|
||||
dispatch(setSlashCommands(sc));
|
||||
});
|
||||
fetch(`${serverUrl}/context_providers`).then(async (resp) => {
|
||||
const cp = await resp.json();
|
||||
console.log(cp);
|
||||
dispatch(setContextProviders(cp));
|
||||
});
|
||||
}
|
||||
|
|
@ -63,7 +60,7 @@ function useSetup(
|
|||
}
|
||||
};
|
||||
window.addEventListener("message", eventListener);
|
||||
postVscMessage("onLoad", {});
|
||||
postToIde("onLoad", {});
|
||||
return () => window.removeEventListener("message", eventListener);
|
||||
}, []);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { postVscMessage } from "../vscode";
|
||||
import { postToIde } from "../vscode";
|
||||
// import { Messenger } from "../../../src/util/messenger";
|
||||
import { Messenger } from "./messenger";
|
||||
|
||||
|
|
@ -8,11 +8,11 @@ export class VscodeMessenger extends Messenger {
|
|||
constructor(serverUrl: string) {
|
||||
super();
|
||||
this.serverUrl = serverUrl;
|
||||
postVscMessage("websocketForwardingOpen", { url: this.serverUrl });
|
||||
postToIde("websocketForwardingOpen", { url: this.serverUrl });
|
||||
}
|
||||
|
||||
send(messageType: string, data: object) {
|
||||
postVscMessage("websocketForwardingMessage", {
|
||||
postToIde("websocketForwardingMessage", {
|
||||
message: { messageType, data },
|
||||
url: this.serverUrl,
|
||||
});
|
||||
|
|
@ -78,6 +78,6 @@ export class VscodeMessenger extends Messenger {
|
|||
}
|
||||
|
||||
close(): void {
|
||||
postVscMessage("websocketForwardingClose", { url: this.serverUrl });
|
||||
postToIde("websocketForwardingClose", { url: this.serverUrl });
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ import ComboBox from "../components/ComboBox";
|
|||
import { usePostHog } from "posthog-js/react";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import { RootStore } from "../redux/store";
|
||||
import { postVscMessage } from "../vscode";
|
||||
import { postToIde } from "../vscode";
|
||||
import { isMetaEquivalentKeyPressed } from "../util";
|
||||
import {
|
||||
setBottomMessage,
|
||||
|
|
@ -46,6 +46,7 @@ import { useNavigate } from "react-router-dom";
|
|||
import SuggestionsArea from "../components/Suggestions";
|
||||
import { setTakenActionTrue } from "../redux/slices/miscSlice";
|
||||
import {
|
||||
deleteAtIndex,
|
||||
newSession,
|
||||
setActive,
|
||||
setHistory,
|
||||
|
|
@ -597,7 +598,7 @@ function GUI(props: GUIProps) {
|
|||
opacity: 0.7,
|
||||
}}
|
||||
onClick={() => {
|
||||
postVscMessage("toggleDevTools", {});
|
||||
postToIde("toggleDevTools", {});
|
||||
}}
|
||||
>
|
||||
<u>View logs</u>
|
||||
|
|
@ -696,7 +697,8 @@ function GUI(props: GUIProps) {
|
|||
onDelete={() => {
|
||||
// Delete the input and all steps until the next user input
|
||||
getStepsInUserInputGroup(index).forEach((i) => {
|
||||
// client?.deleteAtIndex(i);
|
||||
console.log(i);
|
||||
dispatch(deleteAtIndex(i));
|
||||
});
|
||||
}}
|
||||
/>
|
||||
|
|
@ -731,8 +733,7 @@ function GUI(props: GUIProps) {
|
|||
onClose={() => onToggleAtIndex(index)}
|
||||
error={step.error}
|
||||
onDelete={() => {
|
||||
// TODO: Deleting steps, all UI
|
||||
// client?.deleteAtIndex(index)
|
||||
dispatch(deleteAtIndex(index));
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
|
|
@ -758,8 +759,7 @@ function GUI(props: GUIProps) {
|
|||
setWaitingForSteps(true);
|
||||
}}
|
||||
onDelete={() => {
|
||||
// TODO
|
||||
// client?.deleteAtIndex(index);
|
||||
dispatch(deleteAtIndex(index));
|
||||
}}
|
||||
noUserInputParent={
|
||||
getStepsInUserInputGroup(index).length === 0
|
||||
|
|
|
|||
|
|
@ -68,8 +68,6 @@ export const sessionStateSlice = createSlice({
|
|||
history[payload.index] = step;
|
||||
}
|
||||
|
||||
console.log("History: ", history);
|
||||
console.log("Payload: ", payload);
|
||||
return {
|
||||
...state,
|
||||
history,
|
||||
|
|
@ -112,9 +110,25 @@ export const sessionStateSlice = createSlice({
|
|||
history: payload,
|
||||
};
|
||||
},
|
||||
deleteAtIndex: (
|
||||
state: SessionFullState,
|
||||
{ payload }: { payload: number }
|
||||
) => {
|
||||
let newHistory = [...state.history];
|
||||
newHistory[payload] = {
|
||||
...newHistory[payload],
|
||||
hide: true,
|
||||
};
|
||||
return { ...state, history: newHistory };
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const { setActive, setHistory, processSessionUpdate, newSession } =
|
||||
sessionStateSlice.actions;
|
||||
export const {
|
||||
setActive,
|
||||
setHistory,
|
||||
processSessionUpdate,
|
||||
newSession,
|
||||
deleteAtIndex,
|
||||
} = sessionStateSlice.actions;
|
||||
export default sessionStateSlice.reducer;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
import { useEffect, useState } from "react";
|
||||
import "vscode-webview";
|
||||
|
||||
declare const vscode: any;
|
||||
|
||||
function _postVscMessage(type: string, data: any) {
|
||||
function _postToIde(type: string, data: any) {
|
||||
if (typeof vscode === "undefined") {
|
||||
if (localStorage.getItem("ide") === "jetbrains" || true) {
|
||||
if ((window as any).postIntellijMessage === undefined) {
|
||||
|
|
@ -27,14 +26,14 @@ function _postVscMessage(type: string, data: any) {
|
|||
});
|
||||
}
|
||||
|
||||
export function postVscMessage(type: string, data: any, attempt: number = 0) {
|
||||
export function postToIde(type: string, data: any, attempt: number = 0) {
|
||||
try {
|
||||
_postVscMessage(type, data);
|
||||
_postToIde(type, data);
|
||||
} catch (error) {
|
||||
if (attempt < 5) {
|
||||
console.log(`Attempt ${attempt} failed. Retrying...`);
|
||||
setTimeout(
|
||||
() => postVscMessage(type, data, attempt + 1),
|
||||
() => postToIde(type, data, attempt + 1),
|
||||
Math.pow(2, attempt) * 1000
|
||||
);
|
||||
} else {
|
||||
|
|
@ -43,7 +42,7 @@ export function postVscMessage(type: string, data: any, attempt: number = 0) {
|
|||
}
|
||||
}
|
||||
|
||||
export async function vscRequest(type: string, data: any): Promise<any> {
|
||||
export async function ideRequest(type: string, data: any): Promise<any> {
|
||||
return new Promise((resolve) => {
|
||||
const handler = (event: any) => {
|
||||
if (event.data.type === type) {
|
||||
|
|
@ -52,26 +51,13 @@ export async function vscRequest(type: string, data: any): Promise<any> {
|
|||
}
|
||||
};
|
||||
window.addEventListener("message", handler);
|
||||
postVscMessage(type, data);
|
||||
postToIde(type, data);
|
||||
});
|
||||
}
|
||||
|
||||
export function useVscMessageValue(
|
||||
messageType: string | string[],
|
||||
initialValue?: any
|
||||
) {
|
||||
const [value, setValue] = useState<any>(initialValue);
|
||||
window.addEventListener("message", (event) => {
|
||||
if (event.data.type === messageType) {
|
||||
setValue(event.data.value);
|
||||
}
|
||||
});
|
||||
return [value, setValue];
|
||||
}
|
||||
|
||||
export async function withProgress(title: string, fn: () => Promise<any>) {
|
||||
postVscMessage("withProgress", { title, done: false });
|
||||
postToIde("withProgress", { title, done: false });
|
||||
return fn().finally(() => {
|
||||
postVscMessage("withProgress", { title, done: true });
|
||||
postToIde("withProgress", { title, done: true });
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,8 +61,6 @@ class GUIProtocolServer:
|
|||
|
||||
elif msg.message_type == "set_current_session_title":
|
||||
self.set_current_session_title(data["title"])
|
||||
elif msg.message_type == "show_logs_at_index":
|
||||
self.on_show_logs_at_index(data["index"])
|
||||
elif msg.message_type == "show_context_virtual_file":
|
||||
self.show_context_virtual_file(data.get("index", None))
|
||||
elif msg.message_type == "load_session":
|
||||
|
|
@ -86,31 +84,6 @@ class GUIProtocolServer:
|
|||
elif msg.message_type == "preview_context_item":
|
||||
self.preview_context_item(data["id"])
|
||||
|
||||
def on_show_logs_at_index(self, index: int):
|
||||
name = "Continue Prompt"
|
||||
|
||||
logs = None
|
||||
timeline = self.session.autopilot.sdk.history.timeline
|
||||
while logs is None and index < len(timeline):
|
||||
if len(timeline[index].logs) > 0:
|
||||
logs = timeline[index].logs
|
||||
break
|
||||
elif timeline[index].step.name == "User Input":
|
||||
break
|
||||
index += 1
|
||||
|
||||
content = (
|
||||
"Logs not found"
|
||||
if logs is None
|
||||
else "\n\n############################################\n\n".join(
|
||||
["This is the prompt that was sent to the LLM during this step"] + logs
|
||||
)
|
||||
)
|
||||
create_async_task(
|
||||
self.session.autopilot.ide.showVirtualFile(name, content), self.on_error
|
||||
)
|
||||
posthog_logger.capture_event("show_logs_at_index", {})
|
||||
|
||||
def show_context_virtual_file(self, index: Optional[int] = None):
|
||||
async def async_stuff():
|
||||
if index is None:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue