Fix tool argument parsing

This commit is contained in:
Alex Gleason committed 2025-08-28 14:33:31 -05:00
1 parent 027c4f4fd2
commit 1b04be3c46
5 files changed
+64 -67

No files matched your search

+1 -1
View File
@@ -3,5 +3,5 @@ import type z from "zod";
export interface Tool<TParams> {
description: string;
inputSchema: z.ZodType<TParams>;
execute(args: TParams): Promise<unknown>;
execute(args: TParams): Promise<string>;
}
-23
View File
@@ -96,27 +96,4 @@ function convertZodField(field: unknown): Record<string, unknown> {
description: fieldObj._def?.description || ''
};
}
}
/**
* Execute a tool with the given arguments
*/
export async function executeTool<TParams>(
tool: Tool<TParams>,
args: unknown
): Promise<string> {
try {
// Parse and validate arguments using the tool's schema
const validatedArgs = tool.inputSchema.parse(args);
const result = await tool.execute(validatedArgs);
// Convert result to string for the AI
if (typeof result === 'string') {
return result;
}
return JSON.stringify(result, null, 2);
} catch (error) {
throw new Error(`Tool execution failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
}
}