fix: separate preprocessed tool args (#8111)
This commit is contained in:
parent
8f0e5976eb
commit
2f1ed97e16
6 changed files with 22 additions and 71 deletions
1
core/index.d.ts
vendored
1
core/index.d.ts
vendored
|
|
@ -478,6 +478,7 @@ interface ToolCallState {
|
|||
toolCall: ToolCall;
|
||||
status: ToolStatus;
|
||||
parsedArgs: any;
|
||||
processedArgs?: Record<string, any>; // Added in preprocesing step
|
||||
output?: ContextItem[];
|
||||
tool?: Tool;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ function FunctionSpecificToolCallDiv({
|
|||
historyIndex: number;
|
||||
}) {
|
||||
const args = toolCallState.parsedArgs;
|
||||
const processedArgs = toolCallState.processedArgs;
|
||||
const toolCall = toolCallState.toolCall;
|
||||
|
||||
switch (toolCall.function?.name) {
|
||||
|
|
@ -28,8 +29,8 @@ function FunctionSpecificToolCallDiv({
|
|||
case BuiltInToolNames.EditExistingFile:
|
||||
return (
|
||||
<EditFile
|
||||
relativeFilePath={args?.filepath ?? ""}
|
||||
changes={args?.changes ?? ""}
|
||||
relativeFilePath={processedArgs?.filepath ?? args?.filepath ?? ""}
|
||||
changes={processedArgs?.changes ?? args?.changes ?? ""}
|
||||
toolCallId={toolCall.id}
|
||||
historyIndex={historyIndex}
|
||||
/>
|
||||
|
|
@ -37,17 +38,17 @@ function FunctionSpecificToolCallDiv({
|
|||
case BuiltInToolNames.SingleFindAndReplace:
|
||||
const edits: EditOperation[] = [
|
||||
{
|
||||
old_string: args?.old_string ?? "",
|
||||
new_string: args?.new_string ?? "",
|
||||
replace_all: args?.replace_all,
|
||||
old_string: processedArgs?.old_string ?? args?.old_string ?? "",
|
||||
new_string: processedArgs?.new_string ?? args?.new_string ?? "",
|
||||
replace_all: processedArgs?.replace_all ?? args?.replace_all,
|
||||
},
|
||||
];
|
||||
return (
|
||||
<FindAndReplaceDisplay
|
||||
editingFileContents={args?.editingFileContents}
|
||||
fileUri={args?.fileUri ?? ""}
|
||||
newFileContents={args?.newFileContents}
|
||||
relativeFilePath={args?.filepath ?? ""}
|
||||
editingFileContents={processedArgs?.editingFileContents}
|
||||
fileUri={processedArgs?.fileUri ?? ""}
|
||||
newFileContents={processedArgs?.newFileContents}
|
||||
relativeFilePath={processedArgs?.filepath ?? args?.filepath ?? ""}
|
||||
edits={edits}
|
||||
toolCallId={toolCall.id}
|
||||
historyIndex={historyIndex}
|
||||
|
|
@ -56,11 +57,11 @@ function FunctionSpecificToolCallDiv({
|
|||
case BuiltInToolNames.MultiEdit:
|
||||
return (
|
||||
<FindAndReplaceDisplay
|
||||
editingFileContents={args?.editingFileContents}
|
||||
relativeFilePath={args?.filepath ?? ""}
|
||||
fileUri={args?.fileUri ?? ""}
|
||||
newFileContents={args?.newFileContents}
|
||||
edits={args?.edits ?? []}
|
||||
editingFileContents={processedArgs?.editingFileContents}
|
||||
relativeFilePath={processedArgs?.filepath ?? args?.filepath ?? ""}
|
||||
fileUri={processedArgs?.fileUri ?? ""}
|
||||
newFileContents={processedArgs?.newFileContents}
|
||||
edits={processedArgs?.edits ?? args?.edits ?? []}
|
||||
toolCallId={toolCall.id}
|
||||
historyIndex={historyIndex}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -848,7 +848,7 @@ export const sessionSlice = createSlice({
|
|||
);
|
||||
}
|
||||
},
|
||||
setToolCallArgs: (
|
||||
setProcessedToolCallArgs: (
|
||||
state,
|
||||
action: PayloadAction<{
|
||||
toolCallId: string;
|
||||
|
|
@ -860,7 +860,7 @@ export const sessionSlice = createSlice({
|
|||
action.payload.toolCallId,
|
||||
);
|
||||
if (toolCallState) {
|
||||
toolCallState.parsedArgs = action.payload.newArgs;
|
||||
toolCallState.processedArgs = action.payload.newArgs;
|
||||
}
|
||||
},
|
||||
cancelToolCall: (
|
||||
|
|
@ -1038,7 +1038,7 @@ export const {
|
|||
acceptToolCall,
|
||||
setToolGenerated,
|
||||
updateToolCallOutput,
|
||||
setToolCallArgs,
|
||||
setProcessedToolCallArgs,
|
||||
setMode,
|
||||
setIsSessionMetadataLoading,
|
||||
setAllSessionMetadata,
|
||||
|
|
|
|||
|
|
@ -1,52 +0,0 @@
|
|||
import { BuiltInToolNames } from "core/tools/builtIn";
|
||||
import { resolveRelativePathInDir } from "core/util/ideUtils";
|
||||
import { getUriPathBasename } from "core/util/uri";
|
||||
import { IIdeMessenger } from "../../context/IdeMessenger";
|
||||
import { setToolCallArgs } from "../slices/sessionSlice";
|
||||
import { AppThunkDispatch } from "../store";
|
||||
|
||||
export async function enhanceParsedArgs(
|
||||
ideMessenger: IIdeMessenger,
|
||||
dispatch: AppThunkDispatch,
|
||||
toolName: string | undefined,
|
||||
toolCallId: string,
|
||||
currentArgs: undefined | Record<string, any>,
|
||||
) {
|
||||
// Add file content to parsedArgs for find/replace tools
|
||||
let enhancedArgs = { ...currentArgs };
|
||||
if (
|
||||
(toolName === BuiltInToolNames.SingleFindAndReplace ||
|
||||
toolName === BuiltInToolNames.MultiEdit) &&
|
||||
currentArgs?.filepath &&
|
||||
!currentArgs?.editingFileContents
|
||||
) {
|
||||
try {
|
||||
const fileUri = await resolveRelativePathInDir(
|
||||
currentArgs.filepath,
|
||||
ideMessenger.ide,
|
||||
);
|
||||
if (!fileUri) {
|
||||
throw new Error(`File ${currentArgs.filepath} not found`);
|
||||
}
|
||||
const baseName = getUriPathBasename(fileUri);
|
||||
const fileContent = await ideMessenger.ide.readFile(fileUri);
|
||||
enhancedArgs = {
|
||||
...currentArgs,
|
||||
fileUri,
|
||||
baseName,
|
||||
editingFileContents: fileContent,
|
||||
};
|
||||
dispatch(
|
||||
setToolCallArgs({
|
||||
toolCallId,
|
||||
newArgs: enhancedArgs,
|
||||
}),
|
||||
);
|
||||
} catch (error) {
|
||||
// If we can't read the file, let the tool handle the error
|
||||
console.warn(
|
||||
`Failed to enhance args: failed to read file ${currentArgs?.filepath}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -4,7 +4,7 @@ import posthog from "posthog-js";
|
|||
import { IIdeMessenger } from "../../context/IdeMessenger";
|
||||
import {
|
||||
errorToolCall,
|
||||
setToolCallArgs,
|
||||
setProcessedToolCallArgs,
|
||||
updateToolCallOutput,
|
||||
} from "../slices/sessionSlice";
|
||||
import { AppThunkDispatch } from "../store";
|
||||
|
|
@ -61,7 +61,7 @@ export async function preprocessToolCalls(
|
|||
);
|
||||
} else if (preprocessedArgs) {
|
||||
dispatch(
|
||||
setToolCallArgs({
|
||||
setProcessedToolCallArgs({
|
||||
toolCallId: tcState.toolCallId,
|
||||
newArgs: preprocessedArgs,
|
||||
}),
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { resolveRelativePathInDir } from "core/util/ideUtils";
|
|||
import { v4 as uuid } from "uuid";
|
||||
import { applyForEditTool } from "../../redux/thunks/handleApplyStateUpdate";
|
||||
import { ClientToolImpl } from "./callClientTool";
|
||||
|
||||
export const editToolImpl: ClientToolImpl = async (
|
||||
args,
|
||||
toolCallId,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue