Elffuss BraidHub

kikocis/continue public

Merge pull request #6724 from continuedev/dallin/handle-invalid-tool-args

fix: Handle invalid tool call args
Changeset7cf5e158954e453ba11f099dd0d6429ef970bf6c1d7c9f4142574d18e97e9c27
AuthorDallin Romney <dallinromney@gmail.com> · 2025-07-22 00:24 +02:00
CommitterGitHub <noreply@github.com> · 2025-07-22 00:24 +02:00
Parents22e692d80113, b211d5ee5765

Browse the files at this changeset

17 files changed

modified core/tools/definitions/createRuleBlock.ts +1 −1
@@ -16,7 +16,7 @@
1616 'Creates a "rule" that can be referenced in future conversations. This should be used whenever you want to establish code standards / preferences that should be applied consistently, or when you want to avoid making a mistake again. To modify existing rules, use the edit tool instead.\n\nRule Types:\n- Always: Include only "rule" (always included in model context)\n- Auto Attached: Include "rule", "globs", and/or "regex" (included when files match patterns)\n- Agent Requested: Include "rule" and "description" (AI decides when to apply based on description)\n- Manual: Include only "rule" (only included when explicitly mentioned using @ruleName)',
1717 parameters: {
1818 type: "object",
19- required: ["name", "rule", "description"],
19+ required: ["name", "rule"],
2020 properties: {
2121 name: {
2222 type: "string",
modified core/tools/definitions/ls.ts +1 −2
@@ -16,12 +16,11 @@
1616 description: "List files and folders in a given directory",
1717 parameters: {
1818 type: "object",
19- required: ["dirPath", "recursive"],
2019 properties: {
2120 dirPath: {
2221 type: "string",
2322 description:
24- "The directory path relative to the root of the project. Always use forward slash paths like '/'. rather than e.g. '.'",
23+ "The directory path relative to the root of the project. Use forward slash paths like '/'. rather than e.g. '.'",
2524 },
2625 recursive: {
2726 type: "boolean",
modified core/tools/implementations/codebaseTool.ts +4 −11
@@ -1,22 +1,15 @@
11 import { ToolImpl } from ".";
22 import { RangeInFile } from "../..";
33 import { retrieveContextItemsFromEmbeddings } from "../../context/retrieval/retrieval";
4+import { getStringArg } from "../parseArgs";
45
56 export const codebaseToolImpl: ToolImpl = async (args, extras) => {
6- if (!args.query || args.query.trim() === "") {
7- return [
8- {
9- name: "Error",
10- description: "Codebase search error",
11- content: "Query parameter is required and cannot be empty.",
12- },
13- ];
14- }
7+ const query = getStringArg(args, "query");
158
169 try {
1710 const contextExtras = {
1811 config: extras.config,
19- fullInput: args.query,
12+ fullInput: query,
2013 embeddingsProvider: extras.config.selectedModelByRole.embed,
2114 reranker: extras.config.selectedModelByRole.rerank,
2215 llm: extras.llm,
@@ -39,7 +32,7 @@
3932 {
4033 name: "No Results",
4134 description: "Codebase search",
42- content: `No relevant code found for query: "${args.query}". This could mean:
35+ content: `No relevant code found for query: "${query}". This could mean:
4336 - The codebase hasn't been indexed yet
4437 - No code matches the search criteria
4538 - Embeddings provider is not configured
modified core/tools/implementations/createNewFile.ts +7 −3
@@ -2,20 +2,24 @@
22
33 import { ToolImpl } from ".";
44 import { getCleanUriPath, getUriPathBasename } from "../../util/uri";
5+import { getStringArg } from "../parseArgs";
56
67 export const createNewFileImpl: ToolImpl = async (args, extras) => {
8+ const filepath = getStringArg(args, "filepath");
9+ const contents = getStringArg(args, "contents", true);
10+
711 const resolvedFileUri = await inferResolvedUriFromRelativePath(
8- args.filepath,
12+ filepath,
913 extras.ide,
1014 );
1115 if (resolvedFileUri) {
1216 const exists = await extras.ide.fileExists(resolvedFileUri);
1317 if (exists) {
1418 throw new Error(
15- `File ${args.filepath} already exists. Use the edit tool to edit this file`,
19+ `File ${filepath} already exists. Use the edit tool to edit this file`,
1620 );
1721 }
18- await extras.ide.writeFile(resolvedFileUri, args.contents);
22+ await extras.ide.writeFile(resolvedFileUri, contents);
1923 await extras.ide.openFile(resolvedFileUri);
2024 await extras.ide.saveFile(resolvedFileUri);
2125 if (extras.codeBaseIndexer) {
modified core/tools/implementations/createRuleBlock.ts +21 −6
@@ -2,6 +2,11 @@
22 import { ToolImpl } from ".";
33 import { RuleWithSource } from "../..";
44 import { createRuleFilePath } from "../../config/markdown/utils";
5+import {
6+ getBooleanArg,
7+ getOptionalStringArg,
8+ getStringArg,
9+} from "../parseArgs";
510
611 export type CreateRuleBlockArgs = Pick<
712 Required<RuleWithSource>,
@@ -9,11 +14,21 @@
914 > &
1015 Pick<RuleWithSource, "globs" | "regex" | "description" | "alwaysApply">;
1116
12-export const createRuleBlockImpl: ToolImpl = async (
13- { name, rule, ...otherArgs }: CreateRuleBlockArgs,
14- extras,
15-) => {
16- const fileContent = createRuleMarkdown(name, rule, otherArgs);
17+export const createRuleBlockImpl: ToolImpl = async (args, extras) => {
18+ const name = getStringArg(args, "name");
19+ const rule = getStringArg(args, "rule");
20+
21+ const description = getOptionalStringArg(args, "description");
22+ const regex = getOptionalStringArg(args, "regex");
23+ const globs = getOptionalStringArg(args, "globs");
24+ const alwaysApply = getBooleanArg(args, "alwaysApply", false);
25+
26+ const fileContent = createRuleMarkdown(name, rule, {
27+ alwaysApply,
28+ description,
29+ globs,
30+ regex,
31+ });
1732
1833 const [localContinueDir] = await extras.ide.getWorkspaceDirs();
1934 const ruleFilePath = createRuleFilePath(localContinueDir, name);
@@ -24,7 +39,7 @@
2439 return [
2540 {
2641 name: "New Rule Block",
27- description: otherArgs.description || "",
42+ description: description || "",
2843 uri: {
2944 type: "file",
3045 value: ruleFilePath,
modified core/tools/implementations/fetchUrlContent.ts +5 −2
@@ -1,10 +1,13 @@
11 import { ToolImpl } from ".";
22 import { getUrlContextItems } from "../../context/providers/URLContextProvider";
3+import { getStringArg } from "../parseArgs";
34
45 const DEFAULT_FETCH_URL_CHAR_LIMIT = 20000;
56
67 export const fetchUrlContentImpl: ToolImpl = async (args, extras) => {
7- const contextItems = await getUrlContextItems(args.url, extras.fetch);
8+ const url = getStringArg(args, "url");
9+
10+ const contextItems = await getUrlContextItems(url, extras.fetch);
811
912 // Track truncated content
1013 const truncatedUrls: string[] = [];
@@ -12,7 +15,7 @@
1215 // Check and truncate each context item
1316 const processedItems = contextItems.map((item) => {
1417 if (item.content.length > DEFAULT_FETCH_URL_CHAR_LIMIT) {
15- truncatedUrls.push(args.url);
18+ truncatedUrls.push(url);
1619 return {
1720 ...item,
1821 content: item.content.substring(0, DEFAULT_FETCH_URL_CHAR_LIMIT),
modified core/tools/implementations/globSearch.ts +4 −1
@@ -1,10 +1,13 @@
11 import { ToolImpl } from ".";
22 import { ContextItem } from "../..";
3+import { getStringArg } from "../parseArgs";
34
45 const MAX_AGENT_GLOB_RESULTS = 100;
6+
57 export const fileGlobSearchImpl: ToolImpl = async (args, extras) => {
8+ const pattern = getStringArg(args, "pattern");
69 const results = await extras.ide.getFileResults(
7- args.pattern,
10+ pattern,
811 MAX_AGENT_GLOB_RESULTS,
912 );
1013 const contextItems: ContextItem[] = [
modified core/tools/implementations/grepSearch.ts +5 −2
@@ -1,6 +1,7 @@
11 import { ToolImpl } from ".";
22 import { ContextItem } from "../..";
33 import { formatGrepSearchResults } from "../../util/grepSearch";
4+import { getStringArg } from "../parseArgs";
45
56 const DEFAULT_GREP_SEARCH_RESULTS_LIMIT = 100;
67 const DEFAULT_GREP_SEARCH_CHAR_LIMIT = 5000; // ~1000 tokens, will keep truncation simply for now
@@ -41,8 +42,10 @@
4142 }
4243
4344 export const grepSearchImpl: ToolImpl = async (args, extras) => {
45+ const query = getStringArg(args, "query");
46+
4447 const results = await extras.ide.getSearchResults(
45- args.query,
48+ query,
4649 DEFAULT_GREP_SEARCH_RESULTS_LIMIT,
4750 );
4851 const { formatted, numResults, truncated } = formatGrepSearchResults(
@@ -63,7 +66,7 @@
6366
6467 let contextItems: ContextItem[] = [];
6568
66- const splitByFile: boolean = args.splitByFile || false;
69+ const splitByFile: boolean = args?.splitByFile || false;
6770 if (splitByFile) {
6871 contextItems = splitGrepResultsByFile(formatted);
6972 } else {
modified core/tools/implementations/readFile.ts +8 −8
@@ -2,28 +2,28 @@
22 import { getUriPathBasename } from "../../util/uri";
33
44 import { ToolImpl } from ".";
5+import { getStringArg } from "../parseArgs";
56 import { throwIfFileExceedsHalfOfContext } from "./readFileLimit";
67
78 export const readFileImpl: ToolImpl = async (args, extras) => {
8- const firstUriMatch = await resolveRelativePathInDir(
9- args.filepath,
10- extras.ide,
11- );
9+ const filepath = getStringArg(args, "filepath");
10+
11+ const firstUriMatch = await resolveRelativePathInDir(filepath, extras.ide);
1212 if (!firstUriMatch) {
13- throw new Error(`Could not find file ${args.filepath}`);
13+ throw new Error(`Could not find file ${filepath}`);
1414 }
1515 const content = await extras.ide.readFile(firstUriMatch);
1616
1717 await throwIfFileExceedsHalfOfContext(
18- args.filepath,
18+ filepath,
1919 content,
2020 extras.config.selectedModelByRole.chat,
2121 );
2222
2323 return [
2424 {
25- name: getUriPathBasename(args.filepath),
26- description: args.filepath,
25+ name: getUriPathBasename(firstUriMatch),
26+ description: filepath,
2727 content,
2828 uri: {
2929 type: "file",
modified core/tools/implementations/requestRule.ts +5 −4
@@ -1,13 +1,14 @@
11 import { ToolImpl } from ".";
2+import { getStringArg } from "../parseArgs";
23
34 export const requestRuleImpl: ToolImpl = async (args, extras) => {
5+ const name = getStringArg(args, "name");
6+
47 // Find the rule by name in the config
5- const rule = extras.config.rules.find((r) => r.name === args.name);
8+ const rule = extras.config.rules.find((r) => r.name === name);
69
710 if (!rule || !rule.ruleFile) {
8- throw new Error(
9- `Rule with name "${args.name}" not found or has no file path`,
10- );
11+ throw new Error(`Rule with name "${name}" not found or has no file path`);
1112 }
1213
1314 return [
modified core/tools/implementations/runTerminalCommand.ts +9 −5
@@ -24,6 +24,7 @@
2424 isProcessBackgrounded,
2525 removeBackgroundedProcess,
2626 } from "../../util/processTerminalBackgroundStates";
27+import { getBooleanArg, getStringArg } from "../parseArgs";
2728
2829 const asyncExec = util.promisify(childProcess.exec);
2930
@@ -50,8 +51,11 @@
5051 ];
5152
5253 export const runTerminalCommandImpl: ToolImpl = async (args, extras) => {
54+ const command = getStringArg(args, "command");
5355 // Default to waiting for completion if not specified
54- const waitForCompletion = args.waitForCompletion !== false;
56+ const waitForCompletion =
57+ getBooleanArg(args, "waitForCompletion", false) ?? true;
58+
5559 const ideInfo = await extras.ide.getIdeInfo();
5660 const toolCallId = extras.toolCallId || "";
5761
@@ -84,7 +88,7 @@
8488 }
8589
8690 // Use spawn with color environment
87- const childProc = childProcess.spawn(args.command, {
91+ const childProc = childProcess.spawn(command, {
8892 cwd,
8993 shell: true,
9094 env: getColorEnv(), // Add enhanced environment for colors
@@ -229,7 +233,7 @@
229233 // Standard execution, waiting for completion
230234 try {
231235 // Use color environment for exec as well
232- const output = await asyncExec(args.command, {
236+ const output = await asyncExec(command, {
233237 cwd,
234238 env: getColorEnv(),
235239 });
@@ -258,7 +262,7 @@
258262 // but don't attach any listeners other than error
259263 try {
260264 // Use spawn with color environment
261- const childProc = childProcess.spawn(args.command, {
265+ const childProc = childProcess.spawn(command, {
262266 cwd,
263267 shell: true,
264268 env: getColorEnv(), // Add color environment
@@ -309,7 +313,7 @@
309313
310314 // For remote environments, just run the command
311315 // Note: waitForCompletion is not supported in remote environments yet
312- await extras.ide.runCommand(args.command);
316+ await extras.ide.runCommand(command);
313317 return [
314318 {
315319 name: "Terminal",
modified core/tools/implementations/searchWeb.ts +4 −1
@@ -1,10 +1,13 @@
11 import { ToolImpl } from ".";
22 import { fetchSearchResults } from "../../context/providers/WebContextProvider";
3+import { getStringArg } from "../parseArgs";
34
45 const DEFAULT_WEB_SEARCH_CHAR_LIMIT = 8000;
56
67 export const searchWebImpl: ToolImpl = async (args, extras) => {
7- const webResults = await fetchSearchResults(args.query, 5, extras.fetch);
8+ const query = getStringArg(args, "query");
9+
10+ const webResults = await fetchSearchResults(query, 5, extras.fetch);
811
912 // Track truncated results
1013 const truncatedResults: string[] = [];
modified core/tools/implementations/viewSubdirectory.ts +3 −1
@@ -2,9 +2,11 @@
22 import { resolveRelativePathInDir } from "../../util/ideUtils";
33
44 import { ToolImpl } from ".";
5+import { getStringArg } from "../parseArgs";
56
67 export const viewSubdirectoryImpl: ToolImpl = async (args: any, extras) => {
7- const { directory_path } = args;
8+ const directory_path = getStringArg(args, "directory_path");
9+
810 const uri = await resolveRelativePathInDir(directory_path, extras.ide);
911
1012 if (!uri) {
modified core/tools/parseArgs.ts +49 −0
@@ -12,3 +12,52 @@
1212 return {};
1313 }
1414 }
15+
16+export function getStringArg(
17+ args: any,
18+ argName: string,
19+ allowEmpty = false,
20+): string {
21+ if (!args || !(argName in args) || typeof args[argName] !== "string") {
22+ throw new Error(
23+ `\`${argName}\` argument is required${allowEmpty ? "" : " and must not be empty"}. (type string)`,
24+ );
25+ }
26+ if (!allowEmpty && !args[argName].trim()) {
27+ throw new Error(`Argument ${argName} must not be empty`);
28+ }
29+ return args[argName];
30+}
31+
32+export function getOptionalStringArg(
33+ args: any,
34+ argName: string,
35+ allowEmpty = false,
36+) {
37+ if (typeof args?.[argName] === "undefined") {
38+ return undefined;
39+ }
40+ return getStringArg(args, argName, allowEmpty);
41+}
42+
43+export function getBooleanArg(args: any, argName: string, required = false) {
44+ if (!args || !(argName in args)) {
45+ if (required) {
46+ throw new Error(`Argument \`${argName}\` is required (type boolean)`);
47+ } else {
48+ return undefined;
49+ }
50+ }
51+ if (typeof args[argName] === "string") {
52+ if (args[argName].toLowerCase() === "false") {
53+ return false;
54+ }
55+ if (args[argName].toLowerCase() === "true") {
56+ return true;
57+ }
58+ }
59+ if (typeof args[argName] !== "boolean") {
60+ throw new Error(`Argument \`${argName}\` must be a boolean true or false`);
61+ }
62+ return args[argName];
63+}
added core/tools/parseArgs.vitest.ts +248 −0
@@ -0,0 +1,248 @@
1+import { describe, expect, it } from "vitest";
2+import { ToolCallDelta } from "..";
3+import {
4+ getBooleanArg,
5+ getOptionalStringArg,
6+ getStringArg,
7+ safeParseToolCallArgs,
8+} from "./parseArgs";
9+
10+describe("safeParseToolCallArgs", () => {
11+ it("should parse valid JSON arguments", () => {
12+ const toolCall: ToolCallDelta = {
13+ id: "1",
14+ function: {
15+ name: "testFunction",
16+ arguments: '{"name": "test", "value": 123}',
17+ },
18+ };
19+
20+ const result = safeParseToolCallArgs(toolCall);
21+ expect(result).toEqual({ name: "test", value: 123 });
22+ });
23+
24+ it("should parse valid JSON arguments with whitespace", () => {
25+ const toolCall: ToolCallDelta = {
26+ id: "1",
27+ function: {
28+ name: "testFunction",
29+ arguments: ' {"name": "test", "value": 123} ',
30+ },
31+ };
32+
33+ const result = safeParseToolCallArgs(toolCall);
34+ expect(result).toEqual({ name: "test", value: 123 });
35+ });
36+
37+ it("should return empty object for invalid JSON", () => {
38+ const toolCall: ToolCallDelta = {
39+ id: "1",
40+ function: {
41+ name: "testFunction",
42+ arguments: '{"name": "test", value: 123', // Invalid JSON
43+ },
44+ };
45+
46+ const result = safeParseToolCallArgs(toolCall);
47+ expect(result).toEqual({});
48+ });
49+
50+ it("should return empty object when arguments is empty", () => {
51+ const toolCall: ToolCallDelta = {
52+ id: "1",
53+ function: {
54+ name: "testFunction",
55+ arguments: "",
56+ },
57+ };
58+
59+ const result = safeParseToolCallArgs(toolCall);
60+ expect(result).toEqual({});
61+ });
62+
63+ it("should return empty object when arguments is null or undefined", () => {
64+ const toolCall1: ToolCallDelta = {
65+ id: "1",
66+ function: {
67+ name: "testFunction",
68+ arguments: null as any,
69+ },
70+ };
71+
72+ const toolCall2: ToolCallDelta = {
73+ id: "1",
74+ function: {
75+ name: "testFunction",
76+ arguments: undefined,
77+ },
78+ };
79+
80+ expect(safeParseToolCallArgs(toolCall1)).toEqual({});
81+ expect(safeParseToolCallArgs(toolCall2)).toEqual({});
82+ });
83+
84+ it("should handle case when function is undefined", () => {
85+ const toolCall: ToolCallDelta = {
86+ id: "1",
87+ function: undefined,
88+ };
89+
90+ const result = safeParseToolCallArgs(toolCall);
91+ expect(result).toEqual({});
92+ });
93+});
94+
95+describe("getStringArg", () => {
96+ it("should return string argument when valid", () => {
97+ const args = { name: "test" };
98+ const result = getStringArg(args, "name");
99+ expect(result).toBe("test");
100+ });
101+
102+ it("should throw error when argument is missing", () => {
103+ const args = { otherArg: "test" };
104+ expect(() => getStringArg(args, "name")).toThrowError(
105+ "`name` argument is required and must not be empty. (type string)",
106+ );
107+ });
108+
109+ it("should throw error when argument is not a string", () => {
110+ const args = { name: 123 };
111+ expect(() => getStringArg(args, "name")).toThrowError(
112+ "`name` argument is required and must not be empty. (type string)",
113+ );
114+ });
115+
116+ it("should throw error when argument is empty and empty not allowed", () => {
117+ const args = { name: "" };
118+ expect(() => getStringArg(args, "name")).toThrowError(
119+ "Argument name must not be empty",
120+ );
121+
122+ const argsWithSpace = { name: " " };
123+ expect(() => getStringArg(argsWithSpace, "name")).toThrowError(
124+ "Argument name must not be empty",
125+ );
126+ });
127+
128+ it("should accept empty string when allowEmpty is true", () => {
129+ const args = { name: "" };
130+ const result = getStringArg(args, "name", true);
131+ expect(result).toBe("");
132+
133+ const argsWithSpace = { name: " " };
134+ const resultWithSpace = getStringArg(argsWithSpace, "name", true);
135+ expect(resultWithSpace).toBe(" ");
136+ });
137+
138+ it("should handle null or undefined args", () => {
139+ expect(() => getStringArg(null, "name")).toThrowError(
140+ "`name` argument is required and must not be empty. (type string)",
141+ );
142+ expect(() => getStringArg(undefined, "name")).toThrowError(
143+ "`name` argument is required and must not be empty. (type string)",
144+ );
145+ });
146+});
147+
148+describe("getOptionalStringArg", () => {
149+ it("should return undefined when argument is not provided", () => {
150+ const args = { otherArg: "test" };
151+ const result = getOptionalStringArg(args, "name");
152+ expect(result).toBeUndefined();
153+ });
154+
155+ it("should return string argument when valid", () => {
156+ const args = { name: "test" };
157+ const result = getOptionalStringArg(args, "name");
158+ expect(result).toBe("test");
159+ });
160+
161+ it("should throw error when argument is not a string", () => {
162+ const args = { name: 123 };
163+ expect(() => getOptionalStringArg(args, "name")).toThrowError(
164+ "`name` argument is required and must not be empty. (type string)",
165+ );
166+ });
167+
168+ it("should throw error when argument is empty and empty not allowed", () => {
169+ const args = { name: "" };
170+ expect(() => getOptionalStringArg(args, "name")).toThrowError(
171+ "Argument name must not be empty",
172+ );
173+ });
174+
175+ it("should accept empty string when allowEmpty is true", () => {
176+ const args = { name: "" };
177+ const result = getOptionalStringArg(args, "name", true);
178+ expect(result).toBe("");
179+ });
180+
181+ it("should handle null or undefined args", () => {
182+ expect(getOptionalStringArg(null, "name")).toBeUndefined();
183+ expect(getOptionalStringArg(undefined, "name")).toBeUndefined();
184+ });
185+});
186+
187+describe("getBooleanArg", () => {
188+ it("should return boolean argument when valid", () => {
189+ const argsTrue = { flag: true };
190+ const argsFalse = { flag: false };
191+
192+ expect(getBooleanArg(argsTrue, "flag")).toBe(true);
193+ expect(getBooleanArg(argsFalse, "flag")).toBe(false);
194+ });
195+
196+ it("should return undefined when argument is not provided and not required", () => {
197+ const args = { otherArg: true };
198+ const result = getBooleanArg(args, "flag");
199+ expect(result).toBeUndefined();
200+ });
201+
202+ it("should throw error when argument is not provided and required", () => {
203+ const args = { otherArg: true };
204+ expect(() => getBooleanArg(args, "flag", true)).toThrowError(
205+ "Argument `flag` is required (type boolean)",
206+ );
207+ });
208+
209+ it('should handle string "true" and "false" values', () => {
210+ const argsStringTrue = { flag: "true" };
211+ const argsStringFalse = { flag: "false" };
212+ const argsStringTrueUppercase = { flag: "TRUE" };
213+ const argsStringFalseUppercase = { flag: "FALSE" };
214+
215+ expect(getBooleanArg(argsStringTrue, "flag")).toBe(true);
216+ expect(getBooleanArg(argsStringFalse, "flag")).toBe(false);
217+ expect(getBooleanArg(argsStringTrueUppercase, "flag")).toBe(true);
218+ expect(getBooleanArg(argsStringFalseUppercase, "flag")).toBe(false);
219+ });
220+
221+ it("should throw error when argument is not a boolean or valid boolean string", () => {
222+ const argsNumber = { flag: 1 };
223+ const argsInvalidString = { flag: "yes" };
224+ const argsObject = { flag: {} };
225+
226+ expect(() => getBooleanArg(argsNumber, "flag")).toThrowError(
227+ "Argument `flag` must be a boolean true or false",
228+ );
229+ expect(() => getBooleanArg(argsInvalidString, "flag")).toThrowError(
230+ "Argument `flag` must be a boolean true or false",
231+ );
232+ expect(() => getBooleanArg(argsObject, "flag")).toThrowError(
233+ "Argument `flag` must be a boolean true or false",
234+ );
235+ });
236+
237+ it("should handle null or undefined args", () => {
238+ expect(getBooleanArg(null, "flag")).toBeUndefined();
239+ expect(getBooleanArg(undefined, "flag")).toBeUndefined();
240+
241+ expect(() => getBooleanArg(null, "flag", true)).toThrowError(
242+ "Argument `flag` is required (type boolean)",
243+ );
244+ expect(() => getBooleanArg(undefined, "flag", true)).toThrowError(
245+ "Argument `flag` is required (type boolean)",
246+ );
247+ });
248+});
modified gui/src/pages/gui/ToolCallDiv/FunctionSpecificToolCallDiv.tsx +12 −7
@@ -18,25 +18,30 @@
1818 case BuiltInToolNames.CreateNewFile:
1919 return (
2020 <CreateFile
21- relativeFilepath={args.filepath}
22- fileContents={args.contents}
21+ relativeFilepath={args?.filepath ?? ""}
22+ fileContents={args?.contents ?? ""}
2323 historyIndex={historyIndex}
2424 />
2525 );
2626 case BuiltInToolNames.EditExistingFile:
2727 return (
2828 <EditFile
29- relativeFilePath={args.filepath ?? ""}
30- changes={args.changes ?? ""}
29+ relativeFilePath={args?.filepath ?? ""}
30+ changes={args?.changes ?? ""}
3131 toolCallId={toolCall.id}
3232 historyIndex={historyIndex}
3333 />
3434 );
3535 case BuiltInToolNames.SearchAndReplaceInFile:
36+ const changes = args.diffs
37+ ? Array.isArray(args.diffs)
38+ ? args.diffs.join("\n\n---\n\n")
39+ : args.diffs
40+ : "";
3641 return (
3742 <EditFile
38- relativeFilePath={args.filepath ?? ""}
39- changes={args.diffs ? args.diffs.join("\n\n---\n\n") : ""}
43+ relativeFilePath={args?.filepath ?? ""}
44+ changes={changes}
4045 toolCallId={toolCall.id}
4146 historyIndex={historyIndex}
4247 />
@@ -44,7 +49,7 @@
4449 case BuiltInToolNames.RunTerminalCommand:
4550 return (
4651 <RunTerminalCommand
47- command={args.command}
52+ command={args?.command ?? ""}
4853 toolCallState={toolCallState}
4954 toolCallId={toolCall.id}
5055 />
modified gui/src/util/clientTools/editImpl.ts +5 −0
@@ -6,6 +6,11 @@
66 toolCallId,
77 extras,
88 ) => {
9+ if (!args.filepath || !args.changes) {
10+ throw new Error(
11+ "`filepath` and `changes` arguments are required to edit an existing file.",
12+ );
13+ }
914 const firstUriMatch = await resolveRelativePathInDir(
1015 args.filepath,
1116 extras.ideMessenger.ide,