🐛 fix sdk.addContextItem
This commit is contained in:
parent
93dd3d8f6f
commit
c09e84a0c6
2 changed files with 36 additions and 6 deletions
|
|
@ -5,6 +5,7 @@ import {
|
|||
ChatHistory,
|
||||
ChatHistoryItem,
|
||||
ChatMessage,
|
||||
ContinueSDK,
|
||||
LLMReturnValue,
|
||||
MessageContent,
|
||||
SlashCommand,
|
||||
|
|
@ -19,7 +20,7 @@ import { useSelector } from "react-redux";
|
|||
import resolveEditorContent from "../components/mainInput/resolveInput";
|
||||
import { defaultModelSelector } from "../redux/selectors/modelSelectors";
|
||||
import {
|
||||
addContextItems,
|
||||
addContextItemsAtIndex,
|
||||
addLogs,
|
||||
initNewActiveMessage,
|
||||
resubmitAtIndex,
|
||||
|
|
@ -120,19 +121,25 @@ function useChatHandler(dispatch: Dispatch) {
|
|||
async function _streamSlashCommand(
|
||||
messages: ChatMessage[],
|
||||
slashCommand: SlashCommand,
|
||||
input: string
|
||||
input: string,
|
||||
historyIndex: number
|
||||
) {
|
||||
let generator: AsyncGenerator<string>;
|
||||
if (slashCommand.runInNodeJs) {
|
||||
generator = _streamSlashCommandFromVsCode(messages, slashCommand, input);
|
||||
} else {
|
||||
const sdk = {
|
||||
const sdk: ContinueSDK = {
|
||||
input,
|
||||
history: messages,
|
||||
ide: new ExtensionIde(),
|
||||
llm: defaultModel,
|
||||
addContextItem: (item) => {
|
||||
dispatch(addContextItems([item]));
|
||||
dispatch(
|
||||
addContextItemsAtIndex({
|
||||
index: historyIndex,
|
||||
contextItems: [item],
|
||||
})
|
||||
);
|
||||
},
|
||||
contextItems,
|
||||
params: slashCommand.params,
|
||||
|
|
@ -181,10 +188,11 @@ function useChatHandler(dispatch: Dispatch) {
|
|||
};
|
||||
|
||||
let newHistory: ChatHistory = [...history.slice(0, index), historyItem];
|
||||
const historyIndex = index || newHistory.length - 1;
|
||||
dispatch(
|
||||
setMessageAtIndex({
|
||||
message,
|
||||
index: index || newHistory.length - 1,
|
||||
index: historyIndex,
|
||||
contextItems,
|
||||
})
|
||||
);
|
||||
|
|
@ -217,7 +225,12 @@ function useChatHandler(dispatch: Dispatch) {
|
|||
user_input: commandInput,
|
||||
},
|
||||
});
|
||||
await _streamSlashCommand(messages, slashCommand, commandInput);
|
||||
await _streamSlashCommand(
|
||||
messages,
|
||||
slashCommand,
|
||||
commandInput,
|
||||
historyIndex
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
console.log("Continue: error streaming response: ", e);
|
||||
|
|
|
|||
|
|
@ -264,6 +264,22 @@ export const stateSlice = createSlice({
|
|||
state.history[payload.index].message = payload.message;
|
||||
state.history[payload.index].contextItems = payload.contextItems || [];
|
||||
},
|
||||
addContextItemsAtIndex: (
|
||||
state,
|
||||
{
|
||||
payload,
|
||||
}: {
|
||||
payload: {
|
||||
index: number;
|
||||
contextItems: ContextItemWithId[];
|
||||
};
|
||||
}
|
||||
) => {
|
||||
console.log("addContextItemsAtIndex", payload, state.history);
|
||||
if (payload.index < state.history.length) {
|
||||
state.history[payload.index].contextItems.push(...payload.contextItems);
|
||||
}
|
||||
},
|
||||
setInactive: (state) => {
|
||||
return {
|
||||
...state,
|
||||
|
|
@ -450,6 +466,7 @@ export const stateSlice = createSlice({
|
|||
export const {
|
||||
setContextItemsAtIndex,
|
||||
addContextItems,
|
||||
addContextItemsAtIndex,
|
||||
setInactive,
|
||||
streamUpdate,
|
||||
newSession,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue