Fix read-file from exploding with path not found error.

- There were a few hiccups here. Somehow 2.5-flash wasn't actually abiding by our tool schema. Instead it was inferring `path`. To semi-combat this I've renamed `file_path` -> `path`.
- We weren't elevating errors that were created via schema validation. Instead both the `glob` and `read-file.ts` now surface this.
- In error scenarios (like failing schema) we were improperly surfacing these as success cases because we were overriding tool status.
This commit is contained in:
Taylor Mullen 2025-04-20 22:10:23 -04:00 committed by N. Taylor Mullen
parent c095091853
commit 63f864cdd7
4 changed files with 21 additions and 13 deletions

View File

@ -38,8 +38,7 @@ export class ReadFileTool extends BaseTool<ReadFileToolParams, ToolResult> {
* Delegates validation to the core logic * Delegates validation to the core logic
*/ */
validateToolParams(_params: ReadFileToolParams): string | null { validateToolParams(_params: ReadFileToolParams): string | null {
// Currently allowing any path. Add validation if needed. return this.coreLogic.validateToolParams(_params);
return null;
} }
/** /**
@ -62,7 +61,7 @@ export class ReadFileTool extends BaseTool<ReadFileToolParams, ToolResult> {
/** /**
* Delegates execution to the core logic * Delegates execution to the core logic
*/ */
async execute(params: ReadFileToolParams): Promise<ToolResult> { execute(params: ReadFileToolParams): Promise<ToolResult> {
return this.coreLogic.execute(params); return this.coreLogic.execute(params);
} }
} }

View File

@ -330,7 +330,13 @@ export const useGeminiStream = (
...item, ...item,
tools: item.tools.map((tool) => tools: item.tools.map((tool) =>
tool.callId === callId tool.callId === callId
? { ...tool, status: ToolCallStatus.Invoked } ? {
...tool,
status:
tool.status === ToolCallStatus.Error
? ToolCallStatus.Error
: ToolCallStatus.Invoked,
}
: tool, : tool,
), ),
}; };
@ -362,7 +368,10 @@ export const useGeminiStream = (
tool.callId === callId tool.callId === callId
? { ? {
...tool, ...tool,
status: ToolCallStatus.Success, status:
tool.status === ToolCallStatus.Error
? ToolCallStatus.Error
: ToolCallStatus.Success,
resultDisplay: result.returnDisplay, resultDisplay: result.returnDisplay,
} }
: tool, : tool,

View File

@ -149,7 +149,7 @@ export class GlobLogic extends BaseTool<GlobToolParams, ToolResult> {
if (validationError) { if (validationError) {
return { return {
llmContent: `Error: Invalid parameters provided. Reason: ${validationError}`, llmContent: `Error: Invalid parameters provided. Reason: ${validationError}`,
returnDisplay: `Error: Failed to execute tool.`, returnDisplay: validationError,
}; };
} }

View File

@ -17,7 +17,7 @@ export interface ReadFileToolParams {
/** /**
* The absolute path to the file to read * The absolute path to the file to read
*/ */
file_path: string; path: string;
/** /**
* The line number to start reading from (optional) * The line number to start reading from (optional)
@ -46,7 +46,7 @@ export class ReadFileLogic extends BaseTool<ReadFileToolParams, ToolResult> {
'', // Description handled by CLI wrapper '', // Description handled by CLI wrapper
{ {
properties: { properties: {
file_path: { path: {
description: description:
"The absolute path to the file to read (e.g., '/home/user/project/file.txt'). Relative paths are not supported.", "The absolute path to the file to read (e.g., '/home/user/project/file.txt'). Relative paths are not supported.",
type: 'string', type: 'string',
@ -62,7 +62,7 @@ export class ReadFileLogic extends BaseTool<ReadFileToolParams, ToolResult> {
type: 'number', type: 'number',
}, },
}, },
required: ['file_path'], required: ['path'],
type: 'object', type: 'object',
}, },
); );
@ -101,7 +101,7 @@ export class ReadFileLogic extends BaseTool<ReadFileToolParams, ToolResult> {
) { ) {
return 'Parameters failed schema validation.'; return 'Parameters failed schema validation.';
} }
const filePath = params.file_path; const filePath = params.path;
if (!path.isAbsolute(filePath)) { if (!path.isAbsolute(filePath)) {
return `File path must be absolute: ${filePath}`; return `File path must be absolute: ${filePath}`;
} }
@ -185,7 +185,7 @@ export class ReadFileLogic extends BaseTool<ReadFileToolParams, ToolResult> {
* @returns A string describing the file being read * @returns A string describing the file being read
*/ */
getDescription(params: ReadFileToolParams): string { getDescription(params: ReadFileToolParams): string {
const relativePath = makeRelative(params.file_path, this.rootDirectory); const relativePath = makeRelative(params.path, this.rootDirectory);
return shortenPath(relativePath); return shortenPath(relativePath);
} }
@ -199,11 +199,11 @@ export class ReadFileLogic extends BaseTool<ReadFileToolParams, ToolResult> {
if (validationError) { if (validationError) {
return { return {
llmContent: `Error: Invalid parameters provided. Reason: ${validationError}`, llmContent: `Error: Invalid parameters provided. Reason: ${validationError}`,
returnDisplay: '**Error:** Failed to execute tool.', returnDisplay: validationError,
}; };
} }
const filePath = params.file_path; const filePath = params.path;
try { try {
if (!fs.existsSync(filePath)) { if (!fs.existsSync(filePath)) {
return { return {