🐛 show active while context providers resolving
This commit is contained in:
parent
45e2b50b0a
commit
27a668b9cb
3 changed files with 26 additions and 30 deletions
|
|
@ -13,10 +13,11 @@ import { defaultModelSelector } from "../redux/selectors/modelSelectors";
|
|||
import {
|
||||
addContextItems,
|
||||
addLogs,
|
||||
initNewActiveMessage,
|
||||
resubmitAtIndex,
|
||||
setInactive,
|
||||
setMessageAtIndex,
|
||||
streamUpdate,
|
||||
submitMessage,
|
||||
} from "../redux/slices/stateSlice";
|
||||
import { RootStore } from "../redux/store";
|
||||
import { errorPopup } from "../util/ide";
|
||||
|
|
@ -126,9 +127,15 @@ function useChatHandler(dispatch: Dispatch) {
|
|||
}
|
||||
|
||||
async function streamResponse(editorState: JSONContent, index?: number) {
|
||||
const content = await resolveEditorContent(editorState, contextProviders);
|
||||
|
||||
try {
|
||||
if (typeof index === "number") {
|
||||
dispatch(resubmitAtIndex({ index, editorState }));
|
||||
} else {
|
||||
dispatch(initNewActiveMessage({ editorState }));
|
||||
}
|
||||
|
||||
// Resolve context providers and construct new history
|
||||
const content = await resolveEditorContent(editorState, contextProviders);
|
||||
const message: ChatMessage = {
|
||||
role: "user",
|
||||
content,
|
||||
|
|
@ -142,14 +149,10 @@ function useChatHandler(dispatch: Dispatch) {
|
|||
editorState,
|
||||
};
|
||||
|
||||
let newHistory: ChatHistory = [];
|
||||
if (typeof index === "number") {
|
||||
newHistory = [...history.slice(0, index), historyItem];
|
||||
dispatch(resubmitAtIndex({ index, content, editorState }));
|
||||
} else {
|
||||
newHistory = [...history, historyItem];
|
||||
dispatch(submitMessage({ message, editorState }));
|
||||
}
|
||||
let newHistory: ChatHistory = [...history.slice(0, index), historyItem];
|
||||
dispatch(
|
||||
setMessageAtIndex({ message, index: index || newHistory.length - 1 })
|
||||
);
|
||||
|
||||
// TODO: hacky way to allow rerender
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
|
|
|
|||
|
|
@ -29,15 +29,10 @@ import ErrorStepContainer from "../components/gui/ErrorStepContainer";
|
|||
import StepContainer from "../components/gui/StepContainer";
|
||||
import TimelineItem from "../components/gui/TimelineItem";
|
||||
import ContinueInputBox from "../components/mainInput/ContinueInputBox";
|
||||
import resolveEditorContent from "../components/mainInput/resolveInput";
|
||||
import useChatHandler from "../hooks/useChatHandler";
|
||||
import useHistory from "../hooks/useHistory";
|
||||
import { defaultModelSelector } from "../redux/selectors/modelSelectors";
|
||||
import {
|
||||
newSession,
|
||||
resubmitAtIndex,
|
||||
setInactive,
|
||||
} from "../redux/slices/stateSlice";
|
||||
import { newSession, setInactive } from "../redux/slices/stateSlice";
|
||||
import {
|
||||
setDialogEntryOn,
|
||||
setDialogMessage,
|
||||
|
|
@ -401,13 +396,6 @@ function GUI(props: GUIProps) {
|
|||
{item.message.role === "user" ? (
|
||||
<ContinueInputBox
|
||||
onEnter={async (editorState) => {
|
||||
const content = await resolveEditorContent(
|
||||
editorState,
|
||||
contextProviders
|
||||
);
|
||||
dispatch(
|
||||
resubmitAtIndex({ index, content, editorState })
|
||||
);
|
||||
streamResponse(editorState, index);
|
||||
}}
|
||||
isLastUserInput={isLastUserInput(index)}
|
||||
|
|
|
|||
|
|
@ -188,13 +188,12 @@ export const stateSlice = createSlice({
|
|||
}: {
|
||||
payload: {
|
||||
index: number;
|
||||
content: string;
|
||||
editorState: JSONContent;
|
||||
};
|
||||
}
|
||||
) => {
|
||||
if (payload.index < state.history.length) {
|
||||
state.history[payload.index].message.content = payload.content;
|
||||
state.history[payload.index].message.content = "";
|
||||
state.history[payload.index].editorState = payload.editorState;
|
||||
|
||||
// Cut off history after the resubmitted message
|
||||
|
|
@ -213,19 +212,18 @@ export const stateSlice = createSlice({
|
|||
state.active = true;
|
||||
}
|
||||
},
|
||||
submitMessage: (
|
||||
initNewActiveMessage: (
|
||||
state,
|
||||
{
|
||||
payload,
|
||||
}: {
|
||||
payload: {
|
||||
message: ChatMessage;
|
||||
editorState: JSONContent;
|
||||
};
|
||||
}
|
||||
) => {
|
||||
state.history.push({
|
||||
message: payload.message,
|
||||
message: { role: "user", content: "" },
|
||||
contextItems: state.contextItems,
|
||||
editorState: payload.editorState,
|
||||
});
|
||||
|
|
@ -239,6 +237,12 @@ export const stateSlice = createSlice({
|
|||
state.contextItems = [];
|
||||
state.active = true;
|
||||
},
|
||||
setMessageAtIndex: (
|
||||
state,
|
||||
{ payload }: { payload: { message: ChatMessage; index: number } }
|
||||
) => {
|
||||
state.history[payload.index].message = payload.message;
|
||||
},
|
||||
setInactive: (state) => {
|
||||
return {
|
||||
...state,
|
||||
|
|
@ -425,7 +429,6 @@ export const stateSlice = createSlice({
|
|||
export const {
|
||||
addContextItemsAtIndex,
|
||||
addContextItems,
|
||||
submitMessage,
|
||||
setInactive,
|
||||
streamUpdate,
|
||||
newSession,
|
||||
|
|
@ -438,5 +441,7 @@ export const {
|
|||
addLogs,
|
||||
setActive,
|
||||
setEditingContextItemAtIndex,
|
||||
initNewActiveMessage,
|
||||
setMessageAtIndex,
|
||||
} = stateSlice.actions;
|
||||
export default stateSlice.reducer;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue