edit tool ui take zero
This commit is contained in:
parent
e02741cb5e
commit
9c0f43342e
4 changed files with 44 additions and 6 deletions
|
|
@ -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",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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}
|
||||
>
|
||||
<SyntaxHighlightedPre {...preProps} />
|
||||
|
|
|
|||
19
gui/src/pages/gui/ToolCallDiv/EditFile.tsx
Normal file
19
gui/src/pages/gui/ToolCallDiv/EditFile.tsx
Normal file
|
|
@ -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 ? (
|
||||
<StyledMarkdownPreview
|
||||
isRenderingInStepContainer={true}
|
||||
source={src}
|
||||
autoApplyCodeblocks={true}
|
||||
/>
|
||||
) : null;
|
||||
}
|
||||
|
|
@ -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 (
|
||||
<CreateFile
|
||||
relativeFilepath={args.filepath}
|
||||
fileContents={args.contents}
|
||||
/>
|
||||
);
|
||||
case "builtin_run_terminal_command":
|
||||
case BuiltInToolNames.EditExistingFile:
|
||||
return (
|
||||
<EditFile
|
||||
relativeFilePath={args.filepath}
|
||||
newContents={args.newContents}
|
||||
/>
|
||||
);
|
||||
case BuiltInToolNames.RunTerminalCommand:
|
||||
return (
|
||||
<RunTerminalCommand
|
||||
command={args.command}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue