| 1 | import { ToolCallDelta, ToolCallState } from "core"; |
| 2 | import { BuiltInToolNames } from "core/tools/builtIn"; |
| 3 | import { CreateFile } from "./CreateFile"; |
| 4 | import { EditFile } from "./EditFile"; |
| 5 | import { RunTerminalCommand } from "./RunTerminalCommand"; |
| 6 | |
| 7 | function FunctionSpecificToolCallDiv({ |
| 8 | toolCall, |
| 9 | toolCallState, |
| 10 | historyIndex, |
| 11 | }: { |
| 12 | toolCall: ToolCallDelta; |
| 13 | toolCallState: ToolCallState; |
| 14 | historyIndex: number; |
| 15 | }) { |
| 16 | const args = toolCallState.parsedArgs; |
| 17 | |
| 18 | switch (toolCall.function?.name) { |
| 19 | case BuiltInToolNames.CreateNewFile: |
| 20 | return ( |
| 21 | <CreateFile |
| 22 | relativeFilepath={args.filepath} |
| 23 | fileContents={args.contents} |
| 24 | historyIndex={historyIndex} |
| 25 | /> |
| 26 | ); |
| 27 | case BuiltInToolNames.EditExistingFile: |
| 28 | return ( |
| 29 | <EditFile |
| 30 | relativeFilePath={args.filepath ?? ""} |
| 31 | changes={args.changes ?? ""} |
| 32 | toolCallId={toolCall.id} |
| 33 | historyIndex={historyIndex} |
| 34 | /> |
| 35 | ); |
| 36 | case BuiltInToolNames.SearchAndReplaceInFile: |
| 37 | return ( |
| 38 | <EditFile |
| 39 | relativeFilePath={args.filepath ?? ""} |
| 40 | changes={args.diff ?? ""} |
| 41 | toolCallId={toolCall.id} |
| 42 | historyIndex={historyIndex} |
| 43 | /> |
| 44 | ); |
| 45 | case BuiltInToolNames.RunTerminalCommand: |
| 46 | return ( |
| 47 | <RunTerminalCommand |
| 48 | command={args.command} |
| 49 | toolCallState={toolCallState} |
| 50 | toolCallId={toolCall.id} |
| 51 | /> |
| 52 | ); |
| 53 | default: |
| 54 | return null; |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | export default FunctionSpecificToolCallDiv; |