diff --git a/core/tools/definitions/editFile.ts b/core/tools/definitions/editFile.ts
index 1ff44f7c7..6ee5cee6b 100644
--- a/core/tools/definitions/editFile.ts
+++ b/core/tools/definitions/editFile.ts
@@ -1,6 +1,11 @@
import { Tool } from "../..";
import { BUILT_IN_GROUP_NAME, BuiltInToolNames } from "../builtIn";
+export interface EditToolArgs {
+ filepath: string;
+ new_contents: string;
+}
+
export const editFileTool: Tool = {
type: "function",
displayTitle: "Edit File",
@@ -12,16 +17,20 @@ export const editFileTool: Tool = {
function: {
name: BuiltInToolNames.EditExistingFile,
description:
- "To edit an existing file, call this tool and follow the returned instructions. If you don't have the contents of the file, read it first.",
+ "Use this tool to edit an existing file. If you don't know the contents of the file, read it first.",
parameters: {
type: "object",
- required: ["filepath"],
+ required: ["filepath", "new_contents"],
properties: {
filepath: {
type: "string",
description:
"The path of the file to edit, relative to the root of the workspace.",
},
+ new_contents: {
+ type: "string",
+ description: "The new file contents",
+ },
},
},
},
diff --git a/gui/src/components/markdown/StyledMarkdownPreview.tsx b/gui/src/components/markdown/StyledMarkdownPreview.tsx
index fbd6801b9..4c2635ce1 100644
--- a/gui/src/components/markdown/StyledMarkdownPreview.tsx
+++ b/gui/src/components/markdown/StyledMarkdownPreview.tsx
@@ -130,6 +130,7 @@ interface StyledMarkdownPreviewProps {
scrollLocked?: boolean;
itemIndex?: number;
useParentBackgroundColor?: boolean;
+ autoApplyCodeblocks?: boolean;
}
const HLJS_LANGUAGE_CLASSNAME_PREFIX = "language-";
@@ -330,7 +331,7 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview(
relativeFilepath={relativeFilePath}
isGeneratingCodeBlock={isGeneratingCodeBlock}
range={range}
- autoApply={false}
+ autoApply={props.autoApplyCodeblocks}
codeBlockStreamId={codeblockStreamId}
>
diff --git a/gui/src/pages/gui/ToolCallDiv/EditFile.tsx b/gui/src/pages/gui/ToolCallDiv/EditFile.tsx
new file mode 100644
index 000000000..0dee7ab2b
--- /dev/null
+++ b/gui/src/pages/gui/ToolCallDiv/EditFile.tsx
@@ -0,0 +1,19 @@
+import { getMarkdownLanguageTagForFile } from "core/util";
+import StyledMarkdownPreview from "../../../components/markdown/StyledMarkdownPreview";
+
+type EditToolCallProps = {
+ relativeFilePath: string;
+ newContents: string;
+};
+
+export function EditFile(props: EditToolCallProps) {
+ const src = `\`\`\`${getMarkdownLanguageTagForFile(props.relativeFilePath ?? "test.txt")} ${props.relativeFilePath}\n${props.newContents ?? ""}\n\`\`\``;
+
+ return props.relativeFilePath ? (
+
+ ) : null;
+}
diff --git a/gui/src/pages/gui/ToolCallDiv/FunctionSpecificToolCallDiv.tsx b/gui/src/pages/gui/ToolCallDiv/FunctionSpecificToolCallDiv.tsx
index 52b41f505..8592960eb 100644
--- a/gui/src/pages/gui/ToolCallDiv/FunctionSpecificToolCallDiv.tsx
+++ b/gui/src/pages/gui/ToolCallDiv/FunctionSpecificToolCallDiv.tsx
@@ -1,5 +1,7 @@
-import { ToolCall, ToolCallDelta, ToolCallState } from "core";
+import { ToolCallDelta, ToolCallState } from "core";
+import { BuiltInToolNames } from "core/tools/builtIn";
import { CreateFile } from "./CreateFile";
+import { EditFile } from "./EditFile";
import { RunTerminalCommand } from "./RunTerminalCommand";
function FunctionSpecificToolCallDiv({
@@ -12,14 +14,21 @@ function FunctionSpecificToolCallDiv({
const args = toolCallState.parsedArgs;
switch (toolCall.function?.name) {
- case "builtin_create_new_file":
+ case BuiltInToolNames.CreateNewFile:
return (
);
- case "builtin_run_terminal_command":
+ case BuiltInToolNames.EditExistingFile:
+ return (
+
+ );
+ case BuiltInToolNames.RunTerminalCommand:
return (