working and disable input when pending tool call stream
This commit is contained in:
parent
e1ff2a9e57
commit
2efd3ff03a
16 changed files with 112 additions and 71 deletions
|
|
@ -871,8 +871,7 @@ export class Core {
|
|||
}
|
||||
});
|
||||
|
||||
on("tools/call", async (msg) => {
|
||||
const { toolCall, selectedModelTitle } = msg.data;
|
||||
on("tools/call", async ({ data: { toolCall, selectedModelTitle } }) => {
|
||||
const { config } = await this.configHandler.loadConfig();
|
||||
if (!config) {
|
||||
throw new Error("Config not loaded");
|
||||
|
|
|
|||
1
core/index.d.ts
vendored
1
core/index.d.ts
vendored
|
|
@ -1141,6 +1141,7 @@ export interface ApplyState {
|
|||
numDiffs?: number;
|
||||
filepath?: string;
|
||||
fileContent?: string;
|
||||
toolCallId?: string;
|
||||
}
|
||||
|
||||
export interface RangeInFileWithContents {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import { ToWebviewFromIdeOrCoreProtocol } from "./webview";
|
|||
import type {
|
||||
ApplyState,
|
||||
CodeToEdit,
|
||||
ContextSubmenuItem,
|
||||
EditStatus,
|
||||
MessageContent,
|
||||
RangeInFileWithContents,
|
||||
|
|
@ -20,6 +19,7 @@ export type ToIdeFromWebviewProtocol = ToIdeFromWebviewOrCoreProtocol & {
|
|||
streamId: string;
|
||||
curSelectedModelTitle: string;
|
||||
filepath?: string;
|
||||
toolCallId?: string;
|
||||
},
|
||||
void,
|
||||
];
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ export const exactSearchTool: Tool = {
|
|||
displayTitle: "Exact Search",
|
||||
wouldLikeTo: 'search for "{{{ query }}}" in the repository',
|
||||
isCurrently: 'getting search results for "{{{ query }}}"',
|
||||
hasAlready: 'retreived search results for "{{{ query }}}"',
|
||||
hasAlready: 'retrieved search results for "{{{ query }}}"',
|
||||
readonly: true,
|
||||
group: BUILT_IN_GROUP_NAME,
|
||||
function: {
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
// Edit has custom handling on the GUI side
|
||||
|
|
@ -12,7 +12,8 @@ data class ApplyToFileParams(
|
|||
val text: String,
|
||||
val streamId: String,
|
||||
val curSelectedModelTitle: String,
|
||||
val filepath: String?
|
||||
val filepath: String?,
|
||||
val toolCallId: String?
|
||||
)
|
||||
|
||||
data class InsertAtCursorParams(
|
||||
|
|
|
|||
|
|
@ -247,6 +247,7 @@ async function processDiff(
|
|||
verticalDiffManager: VerticalDiffManager,
|
||||
newFileUri?: string,
|
||||
streamId?: string,
|
||||
toolCallId?: string,
|
||||
) {
|
||||
captureCommandTelemetry(`${action}Diff`);
|
||||
|
||||
|
|
@ -280,6 +281,7 @@ async function processDiff(
|
|||
streamId,
|
||||
status: "closed",
|
||||
numDiffs: 0,
|
||||
toolCallId,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -190,6 +190,7 @@ export class VerticalDiffManager {
|
|||
diffStream: AsyncGenerator<DiffLine>,
|
||||
instant: boolean,
|
||||
streamId: string,
|
||||
toolCallId?: string,
|
||||
) {
|
||||
vscode.commands.executeCommand("setContext", "continue.diffVisible", true);
|
||||
|
||||
|
|
@ -226,6 +227,7 @@ export class VerticalDiffManager {
|
|||
numDiffs,
|
||||
fileContent,
|
||||
filepath: fileUri,
|
||||
toolCallId,
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
|
@ -276,6 +278,7 @@ export class VerticalDiffManager {
|
|||
quickEdit?: string,
|
||||
range?: vscode.Range,
|
||||
newCode?: string,
|
||||
toolCallId?: string,
|
||||
): Promise<string | undefined> {
|
||||
vscode.commands.executeCommand("setContext", "continue.diffVisible", true);
|
||||
|
||||
|
|
@ -351,6 +354,7 @@ export class VerticalDiffManager {
|
|||
numDiffs,
|
||||
fileContent,
|
||||
filepath: fileUri,
|
||||
toolCallId,
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import { stripImages } from "core/util/messageContent";
|
|||
import { getUriPathBasename } from "core/util/uri";
|
||||
import * as vscode from "vscode";
|
||||
|
||||
import { ILLM } from "core";
|
||||
import { VerticalDiffManager } from "../diff/vertical/manager";
|
||||
import EditDecorationManager from "../quickEdit/EditDecorationManager";
|
||||
import {
|
||||
|
|
@ -28,7 +29,6 @@ import { showTutorial } from "../util/tutorial";
|
|||
import { getExtensionUri } from "../util/vscode";
|
||||
import { VsCodeIde } from "../VsCodeIde";
|
||||
import { VsCodeWebviewProtocol } from "../webviewProtocol";
|
||||
import { ILLM } from "core";
|
||||
|
||||
/**
|
||||
* A shared messenger class between Core and Webview
|
||||
|
|
@ -133,6 +133,7 @@ export class VsCodeMessenger {
|
|||
streamId: data.streamId,
|
||||
status: "streaming",
|
||||
fileContent: data.text,
|
||||
toolCallId: data.toolCallId,
|
||||
});
|
||||
|
||||
if (data.filepath) {
|
||||
|
|
@ -164,6 +165,7 @@ export class VsCodeMessenger {
|
|||
status: "closed",
|
||||
numDiffs: 0,
|
||||
fileContent: data.text,
|
||||
toolCallId: data.toolCallId,
|
||||
});
|
||||
|
||||
return;
|
||||
|
|
@ -232,6 +234,7 @@ export class VsCodeMessenger {
|
|||
undefined,
|
||||
rangeToApplyTo,
|
||||
data.text,
|
||||
data.toolCallId,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -98,11 +98,16 @@ function InputToolbar(props: InputToolbarProps) {
|
|||
const hasCodeToEdit = useAppSelector(selectHasCodeToEdit);
|
||||
const toolCallState = useAppSelector(selectCurrentToolCall);
|
||||
const isEditModeAndNoCodeToEdit = isInEditMode && !hasCodeToEdit;
|
||||
const activeToolCallStreamId = useAppSelector(
|
||||
(store) => store.session.activeToolStreamId,
|
||||
);
|
||||
|
||||
const isEnterDisabled =
|
||||
props.disabled ||
|
||||
isEditModeAndNoCodeToEdit ||
|
||||
toolCallState?.status === "generated";
|
||||
toolCallState?.status === "generated" ||
|
||||
activeToolCallStreamId;
|
||||
|
||||
const toolsSupported = defaultModel && modelSupportsTools(defaultModel);
|
||||
|
||||
const supportsImages =
|
||||
|
|
|
|||
|
|
@ -131,7 +131,7 @@ interface StyledMarkdownPreviewProps {
|
|||
itemIndex?: number;
|
||||
useParentBackgroundColor?: boolean;
|
||||
disableManualApply?: boolean;
|
||||
firstCodeblockStreamId?: string;
|
||||
singleCodeblockStreamId?: string;
|
||||
}
|
||||
|
||||
const HLJS_LANGUAGE_CLASSNAME_PREFIX = "language-";
|
||||
|
|
@ -199,15 +199,18 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview(
|
|||
const pastFileInfoRef = useUpdatingRef(pastFileInfo);
|
||||
|
||||
const codeblockState = useRef<{ streamId: string; isGenerating: boolean }[]>(
|
||||
props.firstCodeblockStreamId
|
||||
? [
|
||||
{
|
||||
streamId: props.firstCodeblockStreamId,
|
||||
isGenerating: false,
|
||||
},
|
||||
]
|
||||
: [],
|
||||
[],
|
||||
);
|
||||
useEffect(() => {
|
||||
if (props.singleCodeblockStreamId) {
|
||||
codeblockState.current = [
|
||||
{
|
||||
streamId: props.singleCodeblockStreamId,
|
||||
isGenerating: false,
|
||||
},
|
||||
];
|
||||
}
|
||||
}, [props.singleCodeblockStreamId]);
|
||||
|
||||
const [reactContent, setMarkdownSource] = useRemark({
|
||||
remarkPlugins: [
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import { useCallback, useContext, useEffect, useRef } from "react";
|
||||
import { useCallback, useContext, useEffect, useMemo, useRef } from "react";
|
||||
import { VSC_THEME_COLOR_VARS } from "../components";
|
||||
import { IdeMessengerContext } from "../context/IdeMessenger";
|
||||
|
||||
import { ConfigResult } from "@continuedev/config-yaml";
|
||||
import { BrowserSerializedContinueConfig } from "core";
|
||||
import { BrowserSerializedContinueConfig, ContextItem } from "core";
|
||||
import {
|
||||
initializeProfilePreferencesThunk,
|
||||
selectProfileThunk,
|
||||
|
|
@ -16,11 +16,13 @@ import {
|
|||
} from "../redux/slices/configSlice";
|
||||
import { updateIndexingStatus } from "../redux/slices/indexingSlice";
|
||||
import {
|
||||
acceptToolCall,
|
||||
addContextItemsAtIndex,
|
||||
selectLastEditToolApplyState,
|
||||
setInactive,
|
||||
setToolCallOutput,
|
||||
} from "../redux/slices/sessionSlice";
|
||||
import { setTTSActive } from "../redux/slices/uiSlice";
|
||||
import { streamResponseAfterToolCall } from "../redux/thunks";
|
||||
import { refreshSessionMetadata } from "../redux/thunks/session";
|
||||
import { streamResponseThunk } from "../redux/thunks/streamResponse";
|
||||
import { updateFileSymbolsFromHistory } from "../redux/thunks/updateFileSymbols";
|
||||
|
|
@ -247,12 +249,38 @@ function useSetup() {
|
|||
[defaultModel],
|
||||
);
|
||||
|
||||
const lastEditToolApplyState = useAppSelector(selectLastEditToolApplyState);
|
||||
const activeToolStreamId = useAppSelector(
|
||||
(store) => store.session.activeToolStreamId,
|
||||
);
|
||||
const applyStates = useAppSelector(
|
||||
(store) => store.session.codeBlockApplyStates,
|
||||
);
|
||||
const activeToolApplyState = useMemo(() => {
|
||||
if (!activeToolStreamId) {
|
||||
return undefined;
|
||||
}
|
||||
return applyStates.states.find(
|
||||
(state) => state.streamId && state.streamId === activeToolStreamId,
|
||||
);
|
||||
}, [applyStates, activeToolStreamId]);
|
||||
|
||||
useEffect(() => {
|
||||
ideMessenger.post("showToast", ["info", "updated last apply state"]);
|
||||
// dispatch(setToolCallOutput(output));
|
||||
// dispatch(acceptToolCall());
|
||||
}, [lastEditToolApplyState]);
|
||||
if (activeToolApplyState?.status === "closed") {
|
||||
const output: ContextItem = {
|
||||
name: "Edit tool output",
|
||||
content: "Completed edit",
|
||||
description: "",
|
||||
};
|
||||
dispatch(acceptToolCall());
|
||||
dispatch(setToolCallOutput([output]));
|
||||
dispatch(
|
||||
streamResponseAfterToolCall({
|
||||
toolCallId: activeToolApplyState.toolCallId!,
|
||||
toolOutput: [output],
|
||||
}),
|
||||
);
|
||||
}
|
||||
}, [activeToolApplyState?.status]);
|
||||
}
|
||||
|
||||
export default useSetup;
|
||||
|
|
|
|||
|
|
@ -2,32 +2,25 @@ import { getMarkdownLanguageTagForFile } from "core/util";
|
|||
import { useMemo } from "react";
|
||||
import StyledMarkdownPreview from "../../../components/markdown/StyledMarkdownPreview";
|
||||
import AcceptRejectAllButtons from "../../../components/StepContainer/AcceptRejectAllButtons";
|
||||
import { useAppDispatch, useAppSelector } from "../../../redux/hooks";
|
||||
import { selectApplyStateByStreamId } from "../../../redux/slices/sessionSlice";
|
||||
import { useAppSelector } from "../../../redux/hooks";
|
||||
|
||||
type EditToolCallProps = {
|
||||
relativeFilePath: string;
|
||||
newContents: string;
|
||||
toolCallId?: string;
|
||||
};
|
||||
|
||||
export function EditFile(props: EditToolCallProps) {
|
||||
const src = `\`\`\`${getMarkdownLanguageTagForFile(props.relativeFilePath ?? "test.txt")} ${props.relativeFilePath}\n${props.newContents ?? ""}\n\`\`\``;
|
||||
|
||||
const dispatch = useAppDispatch();
|
||||
|
||||
const isStreaming = useAppSelector((state) => state.session.isStreaming);
|
||||
const lastApplyToolStreamId = useAppSelector(
|
||||
(state) => state.session.lastApplyToolStreamId,
|
||||
);
|
||||
const streamId = useMemo(() => {
|
||||
return lastApplyToolStreamId;
|
||||
}, []);
|
||||
const states = useAppSelector((store) => store.session.codeBlockApplyStates);
|
||||
|
||||
console.log("STREAM ID", streamId);
|
||||
|
||||
const applyState = useAppSelector((state) =>
|
||||
selectApplyStateByStreamId(state, streamId),
|
||||
);
|
||||
const applyState = useMemo(() => {
|
||||
return states.states.find(
|
||||
(state) => state.toolCallId && state.toolCallId === props.toolCallId,
|
||||
);
|
||||
}, [states, props.toolCallId]);
|
||||
|
||||
if (!props.relativeFilePath) {
|
||||
return null;
|
||||
|
|
@ -39,11 +32,15 @@ export function EditFile(props: EditToolCallProps) {
|
|||
isRenderingInStepContainer={true}
|
||||
source={src}
|
||||
disableManualApply={true}
|
||||
firstCodeblockStreamId={streamId}
|
||||
singleCodeblockStreamId={applyState?.streamId}
|
||||
/>
|
||||
|
||||
{isStreaming && applyState?.status === "streaming" && (
|
||||
<div className={`m-2 flex items-center justify-center`}>
|
||||
Generating...
|
||||
</div>
|
||||
)}
|
||||
{!isStreaming && applyState?.status === "done" && (
|
||||
<div className={`mx-2 mb-2 mt-2 flex h-7 items-center justify-center`}>
|
||||
<div className={`m-2 flex items-center justify-center`}>
|
||||
<AcceptRejectAllButtons
|
||||
pendingApplyStates={[applyState]}
|
||||
onAcceptOrReject={async (outcome) => {}}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ function FunctionSpecificToolCallDiv({
|
|||
<EditFile
|
||||
relativeFilePath={args.filepath}
|
||||
newContents={args.new_contents}
|
||||
toolCallId={toolCall.id}
|
||||
/>
|
||||
);
|
||||
case BuiltInToolNames.RunTerminalCommand:
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import {
|
|||
ToolCallDelta,
|
||||
ToolCallState,
|
||||
} from "core";
|
||||
import { BuiltInToolNames } from "core/tools/builtIn";
|
||||
import { NEW_SESSION_TITLE } from "core/util/constants";
|
||||
import { incrementalParseJson } from "core/util/incrementalParseJson";
|
||||
import { renderChatMessage } from "core/util/messageContent";
|
||||
|
|
@ -54,7 +55,7 @@ type SessionState = {
|
|||
curIndex: number;
|
||||
};
|
||||
newestCodeblockForInput: Record<string, string>;
|
||||
lastApplyToolStreamId?: string;
|
||||
activeToolStreamId?: string;
|
||||
};
|
||||
|
||||
function isCodeToEditEqual(a: CodeToEdit, b: CodeToEdit) {
|
||||
|
|
@ -367,6 +368,19 @@ export const sessionSlice = createSlice({
|
|||
);
|
||||
}
|
||||
|
||||
if (
|
||||
toolCallDelta.id &&
|
||||
toolCallDelta.function?.name ===
|
||||
BuiltInToolNames.EditExistingFile
|
||||
) {
|
||||
const streamId = uuidv4();
|
||||
state.codeBlockApplyStates.states.push({
|
||||
streamId,
|
||||
toolCallId: toolCallDelta.id,
|
||||
status: "streaming",
|
||||
});
|
||||
state.activeToolStreamId = streamId;
|
||||
}
|
||||
historyItem.toolCallState = toolCallDeltaToState(toolCallDelta);
|
||||
}
|
||||
state.history.push(historyItem);
|
||||
|
|
@ -552,9 +566,7 @@ export const sessionSlice = createSlice({
|
|||
|
||||
state.history[state.history.length - 1].contextItems = contextItems;
|
||||
},
|
||||
setLastToolApplyStreamId: (state, { payload }: PayloadAction<string>) => {
|
||||
state.lastApplyToolStreamId = payload;
|
||||
},
|
||||
|
||||
updateCurCheckpoint: (
|
||||
state,
|
||||
{ payload }: PayloadAction<{ filepath: string; content: string }>,
|
||||
|
|
@ -632,6 +644,7 @@ export const sessionSlice = createSlice({
|
|||
toolCallState.status = "canceled";
|
||||
},
|
||||
acceptToolCall: (state) => {
|
||||
state.activeToolStreamId = undefined;
|
||||
const toolCallState = findCurrentToolCall(state.history);
|
||||
if (!toolCallState) return;
|
||||
|
||||
|
|
@ -729,16 +742,6 @@ export const selectApplyStateByStreamId = createSelector(
|
|||
},
|
||||
);
|
||||
|
||||
export const selectLastEditToolApplyState = createSelector(
|
||||
[
|
||||
(state: RootState) => state.session.codeBlockApplyStates.states,
|
||||
(state: RootState) => state.session.lastApplyToolStreamId,
|
||||
],
|
||||
(states, streamId) => {
|
||||
return states.find((state) => state.streamId === streamId);
|
||||
},
|
||||
);
|
||||
|
||||
export const {
|
||||
updateFileSymbols,
|
||||
setContextItemsAtIndex,
|
||||
|
|
@ -776,7 +779,6 @@ export const {
|
|||
deleteSessionMetadata,
|
||||
setNewestCodeblocksForInput,
|
||||
cycleMode,
|
||||
setLastToolApplyStreamId,
|
||||
} = sessionSlice.actions;
|
||||
|
||||
export const {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ import { ContextItem } from "core";
|
|||
import { BuiltInToolNames } from "core/tools/builtIn";
|
||||
import { EditToolArgs } from "core/tools/definitions/editFile";
|
||||
import { resolveRelativePathInDir } from "core/util/ideUtils";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import { IIdeMessenger } from "../../context/IdeMessenger";
|
||||
import { selectCurrentToolCall } from "../selectors/selectCurrentToolCall";
|
||||
import { selectDefaultModel } from "../slices/configSlice";
|
||||
|
|
@ -11,7 +10,6 @@ import {
|
|||
acceptToolCall,
|
||||
cancelToolCall,
|
||||
setCalling,
|
||||
setLastToolApplyStreamId,
|
||||
setToolCallOutput,
|
||||
} from "../slices/sessionSlice";
|
||||
import { ThunkApiType } from "../store";
|
||||
|
|
@ -44,17 +42,19 @@ export const callTool = createAsyncThunk<void, undefined, ThunkApiType>(
|
|||
if (
|
||||
toolCallState.toolCall.function.name === BuiltInToolNames.EditExistingFile
|
||||
) {
|
||||
const newToolStreamId = uuidv4();
|
||||
dispatch(setLastToolApplyStreamId(newToolStreamId));
|
||||
const args = JSON.parse(
|
||||
toolCallState.toolCall.function.arguments || "{}",
|
||||
);
|
||||
try {
|
||||
if (!state.session.activeToolStreamId) {
|
||||
throw new Error("Invalid apply state");
|
||||
}
|
||||
await customGuiEditImpl(
|
||||
args,
|
||||
extra.ideMessenger,
|
||||
newToolStreamId,
|
||||
state.session.activeToolStreamId,
|
||||
defaultModel.title,
|
||||
toolCallState.toolCallId,
|
||||
);
|
||||
} catch (e) {
|
||||
errorMessage = "Failed to call edit tool";
|
||||
|
|
@ -85,7 +85,7 @@ export const callTool = createAsyncThunk<void, undefined, ThunkApiType>(
|
|||
icon: "problems",
|
||||
name: "Tool Call Error",
|
||||
description: "Tool Call Failed",
|
||||
content: `The tool call failed with the message:\n\n${errorMessage}\n\nPlease try something else or request further instructions.`,
|
||||
content: `${toolCallState.toolCall.function.name} failed with the message:\n\n${errorMessage}\n\nPlease try something else or request further instructions.`,
|
||||
hidden: false,
|
||||
},
|
||||
],
|
||||
|
|
@ -114,23 +114,19 @@ async function customGuiEditImpl(
|
|||
ideMessenger: IIdeMessenger,
|
||||
streamId: string,
|
||||
modelTitle: string,
|
||||
toolCallId: string,
|
||||
) {
|
||||
const firstUriMatch = await resolveRelativePathInDir(
|
||||
args.filepath,
|
||||
ideMessenger.ide,
|
||||
);
|
||||
if (!firstUriMatch) {
|
||||
return [
|
||||
{
|
||||
name: "Edit failure",
|
||||
description: `editing ${args.filepath}`,
|
||||
content: `Failed to edit ${args.filepath}: does not exist`,
|
||||
},
|
||||
];
|
||||
throw new Error(`${args.filepath} does not exist`);
|
||||
}
|
||||
ideMessenger.post("applyToFile", {
|
||||
streamId,
|
||||
text: args.new_contents,
|
||||
curSelectedModelTitle: modelTitle,
|
||||
toolCallId,
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue