🚧 fixed saving history
This commit is contained in:
parent
ba6db9cbf1
commit
cdd77a2cfe
15 changed files with 353 additions and 284 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -26,11 +26,13 @@ export type Editable = boolean;
|
|||
export type ContextItems = ContextItem[];
|
||||
export type Title1 = string;
|
||||
export type WorkspaceDirectory = string;
|
||||
export type SessionId = string;
|
||||
|
||||
export interface PersistedSessionInfo1 {
|
||||
session_state: SessionState;
|
||||
title: Title1;
|
||||
workspace_directory: WorkspaceDirectory;
|
||||
session_id: SessionId;
|
||||
[k: string]: unknown;
|
||||
}
|
||||
/**
|
||||
|
|
|
|||
2
extensions/vscode/schema/SessionUpdate.d.ts
vendored
2
extensions/vscode/schema/SessionUpdate.d.ts
vendored
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
export type SessionUpdate = SessionUpdate1;
|
||||
export type Index = number;
|
||||
export type Update = DeltaStep | SetStep;
|
||||
export type Update = DeltaStep | SetStep | SessionUpdate1;
|
||||
export type Name = string;
|
||||
export type Description = string;
|
||||
export type Observations = Observation[];
|
||||
|
|
|
|||
|
|
@ -889,6 +889,7 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => {
|
|||
{selectedContextItems.map((item, idx) => {
|
||||
return (
|
||||
<PillButton
|
||||
inputIndex={props.index}
|
||||
areMultipleItems={selectedContextItems.length > 1}
|
||||
key={`${item.description.id.item_id}${idx}`}
|
||||
item={item}
|
||||
|
|
|
|||
|
|
@ -18,8 +18,9 @@ import HeaderButtonWithText from "./HeaderButtonWithText";
|
|||
import FileIcon from "./FileIcon";
|
||||
import { ContextItem } from "../schema/ContextItem";
|
||||
import { postToIde } from "../vscode";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import { setEditingAtIds } from "../redux/slices/sessionStateReducer";
|
||||
import { RootStore } from "../redux/store";
|
||||
|
||||
const Button = styled.button<{ fontSize?: number }>`
|
||||
border: none;
|
||||
|
|
@ -81,6 +82,7 @@ interface PillButtonProps {
|
|||
editing: boolean;
|
||||
editingAny: boolean;
|
||||
index: number;
|
||||
inputIndex: number; // index of the ComboBox
|
||||
areMultipleItems?: boolean;
|
||||
onDelete?: (index?: number) => void;
|
||||
onClick?: (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;
|
||||
|
|
@ -159,6 +161,10 @@ const PillButton = (props: PillButtonProps) => {
|
|||
const pillContainerRef = useRef<HTMLDivElement>(null);
|
||||
const buttonRef = useRef<HTMLButtonElement>(null);
|
||||
|
||||
const selectedContextItems = useSelector(
|
||||
(store: RootStore) => store.sessionState.context_items
|
||||
);
|
||||
|
||||
return (
|
||||
<div style={{ position: "relative" }}>
|
||||
<Container previewing={props.previewing} ref={pillContainerRef}>
|
||||
|
|
@ -246,10 +252,16 @@ const PillButton = (props: PillButtonProps) => {
|
|||
}
|
||||
onClick={() => {
|
||||
if (!props.editing) {
|
||||
console.log(
|
||||
props.item.description.id,
|
||||
props.inputIndex,
|
||||
"edit",
|
||||
selectedContextItems
|
||||
);
|
||||
dispatch(
|
||||
setEditingAtIds({
|
||||
ids: [props.item.description.id],
|
||||
index: props.index,
|
||||
index: props.inputIndex,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ function useSetup(
|
|||
!requestedTitle &&
|
||||
!active &&
|
||||
title === "New Session" &&
|
||||
history.filter((step) => !step.hide).length > 2
|
||||
history.filter((step) => !step.hide).length >= 2
|
||||
) {
|
||||
setRequestedTitle(true);
|
||||
const title = await client.getSessionTitle(history);
|
||||
|
|
|
|||
|
|
@ -196,7 +196,9 @@ function History() {
|
|||
},
|
||||
title: currentSession.title,
|
||||
workspace_directory: workspaceDirectory,
|
||||
session_id: currentSession.session_id,
|
||||
};
|
||||
console.log(persistedSessionInfo);
|
||||
await fetch(`${apiUrl}/sessions/save`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(persistedSessionInfo),
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ export interface SessionFullState {
|
|||
context_items: ContextItem[];
|
||||
active: boolean;
|
||||
title: string;
|
||||
session_id: string;
|
||||
}
|
||||
|
||||
export const sessionStateSlice = createSlice({
|
||||
|
|
@ -22,6 +23,7 @@ export const sessionStateSlice = createSlice({
|
|||
active: false,
|
||||
title: "New Session",
|
||||
contextItemsAtIndex: {},
|
||||
session_id: v4(),
|
||||
},
|
||||
reducers: {
|
||||
processSessionUpdate: (
|
||||
|
|
@ -54,11 +56,11 @@ export const sessionStateSlice = createSlice({
|
|||
if (payload.update.observations) {
|
||||
step.observations = [
|
||||
...(step.observations ?? []),
|
||||
...payload.update.observations,
|
||||
...(payload.update.observations as any),
|
||||
];
|
||||
}
|
||||
if (payload.update.logs) {
|
||||
step.logs = [...(step.logs ?? []), ...payload.update.logs];
|
||||
step.logs = [...(step.logs ?? []), ...(payload.update.logs as any)];
|
||||
}
|
||||
} else if (payload.delta === false) {
|
||||
step = {
|
||||
|
|
@ -91,6 +93,7 @@ export const sessionStateSlice = createSlice({
|
|||
contextItemsAtIndex: {},
|
||||
active: false,
|
||||
title: payload.title,
|
||||
session_id: payload.session_id,
|
||||
};
|
||||
}
|
||||
return {
|
||||
|
|
@ -100,6 +103,7 @@ export const sessionStateSlice = createSlice({
|
|||
contextItemsAtIndex: {},
|
||||
active: false,
|
||||
title: "New Session",
|
||||
session_id: v4(),
|
||||
};
|
||||
},
|
||||
setTitle: (state: SessionFullState, { payload }: { payload: string }) => {
|
||||
|
|
@ -187,7 +191,7 @@ export const sessionStateSlice = createSlice({
|
|||
},
|
||||
},
|
||||
content: payload.rangeInFileWithContents.contents,
|
||||
editing: payload.edit,
|
||||
editing: true,
|
||||
editable: true,
|
||||
});
|
||||
|
||||
|
|
@ -233,19 +237,16 @@ export const sessionStateSlice = createSlice({
|
|||
payload,
|
||||
}: { payload: { ids: ContextItemId[]; index: number | undefined } }
|
||||
) => {
|
||||
const ids = payload.ids.map((id) => `${id.provider_title}-${id.item_id}`);
|
||||
const ids = payload.ids.map((id) => id.item_id);
|
||||
|
||||
if (typeof payload.index === "undefined") {
|
||||
return {
|
||||
...state,
|
||||
context_items: state.context_items.map((item) => {
|
||||
if (
|
||||
ids.includes(
|
||||
`${item.description.id.provider_title}-${item.description.id.item_id}`
|
||||
)
|
||||
) {
|
||||
return { ...item, editing: true };
|
||||
}
|
||||
return item;
|
||||
return {
|
||||
...item,
|
||||
editing: ids.includes(item.description.id.item_id),
|
||||
};
|
||||
}),
|
||||
};
|
||||
} else {
|
||||
|
|
@ -256,14 +257,10 @@ export const sessionStateSlice = createSlice({
|
|||
[payload.index]: (
|
||||
state.contextItemsAtIndex[payload.index] ?? []
|
||||
).map((item) => {
|
||||
if (
|
||||
ids.includes(
|
||||
`${item.description.id.provider_title}-${item.description.id.item_id}`
|
||||
)
|
||||
) {
|
||||
return { ...item, editing: true };
|
||||
}
|
||||
return item;
|
||||
return {
|
||||
...item,
|
||||
editing: ids.includes(item.description.id.item_id),
|
||||
};
|
||||
}),
|
||||
},
|
||||
};
|
||||
|
|
|
|||
2
gui/src/schema/PersistedSessionInfo.d.ts
vendored
2
gui/src/schema/PersistedSessionInfo.d.ts
vendored
|
|
@ -26,11 +26,13 @@ export type Editable = boolean;
|
|||
export type ContextItems = ContextItem[];
|
||||
export type Title1 = string;
|
||||
export type WorkspaceDirectory = string;
|
||||
export type SessionId = string;
|
||||
|
||||
export interface PersistedSessionInfo1 {
|
||||
session_state: SessionState;
|
||||
title: Title1;
|
||||
workspace_directory: WorkspaceDirectory;
|
||||
session_id: SessionId;
|
||||
[k: string]: unknown;
|
||||
}
|
||||
/**
|
||||
|
|
|
|||
2
gui/src/schema/SessionUpdate.d.ts
vendored
2
gui/src/schema/SessionUpdate.d.ts
vendored
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
export type SessionUpdate = SessionUpdate1;
|
||||
export type Index = number;
|
||||
export type Update = DeltaStep | SetStep;
|
||||
export type Update = DeltaStep | SetStep | SessionUpdate1;
|
||||
export type Name = string;
|
||||
export type Description = string;
|
||||
export type Observations = Observation[];
|
||||
|
|
|
|||
|
|
@ -191,12 +191,17 @@
|
|||
"workspace_directory": {
|
||||
"title": "Workspace Directory",
|
||||
"type": "string"
|
||||
},
|
||||
"session_id": {
|
||||
"title": "Session Id",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"session_state",
|
||||
"title",
|
||||
"workspace_directory"
|
||||
"workspace_directory",
|
||||
"session_id"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -116,6 +116,9 @@
|
|||
},
|
||||
{
|
||||
"$ref": "#/definitions/SetStep"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/continuedev__core__main__SessionUpdate"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
from typing import Type, Union
|
||||
|
||||
from ..steps.comment_code import CommentCodeStep
|
||||
|
||||
from ..steps.share_session import ShareSessionStep
|
||||
|
||||
from ..steps.chroma import AnswerQuestionChroma
|
||||
|
|
@ -21,6 +23,7 @@ REPLACEMENT_SLASH_COMMAND_STEPS = [
|
|||
GenerateShellCommandStep,
|
||||
EditHighlightedCodeStep,
|
||||
ShareSessionStep,
|
||||
CommentCodeStep,
|
||||
]
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ from typing import List
|
|||
import uuid
|
||||
|
||||
from pydantic import BaseModel
|
||||
from ..core.main import SessionInfo, SessionState
|
||||
from ..core.main import SessionInfo, SessionState, StepDescription
|
||||
|
||||
from fastapi import APIRouter
|
||||
|
||||
|
|
@ -13,6 +13,7 @@ from ..libs.util.paths import (
|
|||
getSessionFilePath,
|
||||
getSessionsListFilePath,
|
||||
)
|
||||
from ..libs.util.logging import logger
|
||||
|
||||
router = APIRouter(prefix="/sessions", tags=["sessions"])
|
||||
|
||||
|
|
@ -21,6 +22,7 @@ class PersistedSessionInfo(BaseModel):
|
|||
session_state: SessionState
|
||||
title: str
|
||||
workspace_directory: str
|
||||
session_id: str
|
||||
|
||||
|
||||
@router.get("/list")
|
||||
|
|
@ -43,21 +45,52 @@ async def load_session(session_id: str) -> PersistedSessionInfo:
|
|||
raise Exception(f"Session file {session_file} does not exist")
|
||||
session_state = json.load(open(session_file, "r"))
|
||||
try:
|
||||
# TODO: Migrate
|
||||
session_state = PersistedSessionInfo(**session_state)
|
||||
except Exception:
|
||||
if "active" in session_state:
|
||||
# Indicator of old version. Try to migrate
|
||||
def migrate_node(node):
|
||||
step = node["step"]
|
||||
return StepDescription(
|
||||
step_type=step["class_name"],
|
||||
name=step["name"],
|
||||
description=step["description"],
|
||||
params={},
|
||||
hide=step["hide"],
|
||||
depth=node["depth"],
|
||||
observations=[],
|
||||
logs=node["logs"] if "logs" in node else [],
|
||||
)
|
||||
|
||||
migrated_state = SessionState(
|
||||
context_items=session_state["selected_context_items"],
|
||||
history=list(map(migrate_node, session_state["history"]["timeline"])),
|
||||
)
|
||||
return PersistedSessionInfo(
|
||||
session_state=migrated_state,
|
||||
title=session_state["session_info"]["title"],
|
||||
workspace_directory=session_state["session_info"][
|
||||
"workspace_directory"
|
||||
],
|
||||
session_id=session_id,
|
||||
)
|
||||
|
||||
else:
|
||||
kwargs = session_state
|
||||
kwargs.update({"session_id": session_id})
|
||||
return PersistedSessionInfo(**kwargs)
|
||||
except Exception as e:
|
||||
logger.warning(f"Error migrating session: {e}")
|
||||
return PersistedSessionInfo(
|
||||
session_state=SessionState(history=[], context_items=[]),
|
||||
title="Old Session Format",
|
||||
workspace_directory="",
|
||||
session_id=session_id,
|
||||
)
|
||||
return session_state
|
||||
|
||||
|
||||
@router.post("/save")
|
||||
async def save_session(body: PersistedSessionInfo):
|
||||
session_id = uuid.uuid4().hex
|
||||
with open(getSessionFilePath(session_id), "w") as f:
|
||||
# Save the main session json file
|
||||
with open(getSessionFilePath(body.session_id), "w") as f:
|
||||
json.dump(body.dict(), f)
|
||||
|
||||
# Read and update the sessions list
|
||||
|
|
@ -69,10 +102,18 @@ async def save_session(body: PersistedSessionInfo):
|
|||
f"It looks like there is a JSON formatting error in your sessions.json file ({getSessionsListFilePath()}). Please fix this before creating a new session."
|
||||
)
|
||||
|
||||
session_ids = [s["session_id"] for s in sessions_list]
|
||||
if session_id not in session_ids:
|
||||
found = False
|
||||
for session_info in sessions_list:
|
||||
if session_info["session_id"] == body.session_id:
|
||||
session_info["title"] = body.title
|
||||
session_info["workspace_directory"] = body.workspace_directory
|
||||
session_info["date_created"] = str(time.time())
|
||||
found = True
|
||||
break
|
||||
|
||||
if not found:
|
||||
session_info = SessionInfo(
|
||||
session_id=session_id,
|
||||
session_id=body.session_id,
|
||||
title=body.title,
|
||||
date_created=str(time.time()),
|
||||
workspace_directory=body.workspace_directory,
|
||||
|
|
@ -80,6 +121,7 @@ async def save_session(body: PersistedSessionInfo):
|
|||
sessions_list.append(session_info.dict())
|
||||
|
||||
for session_info in sessions_list:
|
||||
# A migration
|
||||
if "workspace_directory" not in session_info:
|
||||
session_info["workspace_directory"] = ""
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue