Rename invalidParams to validateToolParams (#12)
Methods should be verbs. Fixes #4.
This commit is contained in:
parent
7cd3b95317
commit
e1fac40256
|
@ -92,7 +92,7 @@ export class GlobTool extends BaseTool<GlobToolParams, ToolResult> {
|
||||||
* @param params Parameters to validate
|
* @param params Parameters to validate
|
||||||
* @returns An error message string if invalid, null otherwise
|
* @returns An error message string if invalid, null otherwise
|
||||||
*/
|
*/
|
||||||
invalidParams(params: GlobToolParams): string | null {
|
validateToolParams(params: GlobToolParams): string | null {
|
||||||
if (
|
if (
|
||||||
this.schema.parameters &&
|
this.schema.parameters &&
|
||||||
!SchemaValidator.validate(
|
!SchemaValidator.validate(
|
||||||
|
@ -161,7 +161,7 @@ export class GlobTool extends BaseTool<GlobToolParams, ToolResult> {
|
||||||
* @returns Result of the glob search
|
* @returns Result of the glob search
|
||||||
*/
|
*/
|
||||||
async execute(params: GlobToolParams): Promise<ToolResult> {
|
async execute(params: GlobToolParams): Promise<ToolResult> {
|
||||||
const validationError = this.invalidParams(params);
|
const validationError = this.validateToolParams(params);
|
||||||
if (validationError) {
|
if (validationError) {
|
||||||
return {
|
return {
|
||||||
llmContent: `Error: Invalid parameters provided. Reason: ${validationError}`,
|
llmContent: `Error: Invalid parameters provided. Reason: ${validationError}`,
|
||||||
|
|
|
@ -127,7 +127,7 @@ export class GrepTool extends BaseTool<GrepToolParams, ToolResult> {
|
||||||
* @param params Parameters to validate
|
* @param params Parameters to validate
|
||||||
* @returns An error message string if invalid, null otherwise
|
* @returns An error message string if invalid, null otherwise
|
||||||
*/
|
*/
|
||||||
invalidParams(params: GrepToolParams): string | null {
|
validateToolParams(params: GrepToolParams): string | null {
|
||||||
if (
|
if (
|
||||||
this.schema.parameters &&
|
this.schema.parameters &&
|
||||||
!SchemaValidator.validate(
|
!SchemaValidator.validate(
|
||||||
|
@ -161,7 +161,7 @@ export class GrepTool extends BaseTool<GrepToolParams, ToolResult> {
|
||||||
* @returns Result of the grep search
|
* @returns Result of the grep search
|
||||||
*/
|
*/
|
||||||
async execute(params: GrepToolParams): Promise<ToolResult> {
|
async execute(params: GrepToolParams): Promise<ToolResult> {
|
||||||
const validationError = this.invalidParams(params);
|
const validationError = this.validateToolParams(params);
|
||||||
if (validationError) {
|
if (validationError) {
|
||||||
console.error(`GrepTool Parameter Validation Failed: ${validationError}`);
|
console.error(`GrepTool Parameter Validation Failed: ${validationError}`);
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -135,9 +135,10 @@ export class LSTool extends BaseTool<LSToolParams, LSToolResult> {
|
||||||
* @param params Parameters to validate
|
* @param params Parameters to validate
|
||||||
* @returns An error message string if invalid, null otherwise
|
* @returns An error message string if invalid, null otherwise
|
||||||
*/
|
*/
|
||||||
invalidParams(params: LSToolParams): string | null {
|
validateToolParams(params: LSToolParams): string | null {
|
||||||
if (this.schema.parameters &&
|
if (this.schema.parameters &&
|
||||||
!SchemaValidator.validate(this.schema.parameters as Record<string, unknown>, params)) {
|
!SchemaValidator.validate(this.schema.parameters as Record<string, unknown>, params)
|
||||||
|
) {
|
||||||
return 'Parameters failed schema validation.';
|
return 'Parameters failed schema validation.';
|
||||||
}
|
}
|
||||||
if (!path.isAbsolute(params.path)) {
|
if (!path.isAbsolute(params.path)) {
|
||||||
|
@ -199,7 +200,7 @@ export class LSTool extends BaseTool<LSToolParams, LSToolResult> {
|
||||||
* @returns Result of the LS operation
|
* @returns Result of the LS operation
|
||||||
*/
|
*/
|
||||||
async execute(params: LSToolParams): Promise<LSToolResult> {
|
async execute(params: LSToolParams): Promise<LSToolResult> {
|
||||||
const validationError = this.invalidParams(params);
|
const validationError = this.validateToolParams(params);
|
||||||
if (validationError) {
|
if (validationError) {
|
||||||
return this.errorResult(
|
return this.errorResult(
|
||||||
params,
|
params,
|
||||||
|
|
|
@ -106,7 +106,7 @@ export class ReadFileTool extends BaseTool<
|
||||||
* @param params Parameters to validate
|
* @param params Parameters to validate
|
||||||
* @returns True if parameters are valid, false otherwise
|
* @returns True if parameters are valid, false otherwise
|
||||||
*/
|
*/
|
||||||
invalidParams(params: ReadFileToolParams): string | null {
|
validateToolParams(params: ReadFileToolParams): string | null {
|
||||||
if (
|
if (
|
||||||
this.schema.parameters &&
|
this.schema.parameters &&
|
||||||
!SchemaValidator.validate(
|
!SchemaValidator.validate(
|
||||||
|
@ -210,8 +210,7 @@ export class ReadFileTool extends BaseTool<
|
||||||
* @returns Result with file contents
|
* @returns Result with file contents
|
||||||
*/
|
*/
|
||||||
async execute(params: ReadFileToolParams): Promise<ToolResult> {
|
async execute(params: ReadFileToolParams): Promise<ToolResult> {
|
||||||
const validationError = this.invalidParams(params);
|
const validationError = this.validateToolParams(params);
|
||||||
const filePath = params.file_path;
|
|
||||||
if (validationError) {
|
if (validationError) {
|
||||||
return {
|
return {
|
||||||
llmContent: `Error: Invalid parameters provided. Reason: ${validationError}`,
|
llmContent: `Error: Invalid parameters provided. Reason: ${validationError}`,
|
||||||
|
@ -219,6 +218,7 @@ export class ReadFileTool extends BaseTool<
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const filePath = params.file_path;
|
||||||
try {
|
try {
|
||||||
if (!fs.existsSync(filePath)) {
|
if (!fs.existsSync(filePath)) {
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -317,7 +317,7 @@ Use this tool for running build steps (\`npm install\`, \`make\`), linters (\`es
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Parameter Validation (unchanged) ---
|
// --- Parameter Validation (unchanged) ---
|
||||||
invalidParams(params: TerminalToolParams): string | null {
|
validateToolParams(params: TerminalToolParams): string | null {
|
||||||
if (
|
if (
|
||||||
!SchemaValidator.validate(
|
!SchemaValidator.validate(
|
||||||
this.parameterSchema as Record<string, unknown>,
|
this.parameterSchema as Record<string, unknown>,
|
||||||
|
@ -400,7 +400,7 @@ Use this tool for running build steps (\`npm install\`, \`make\`), linters (\`es
|
||||||
|
|
||||||
// --- Command Execution and Queueing (unchanged structure) ---
|
// --- Command Execution and Queueing (unchanged structure) ---
|
||||||
async execute(params: TerminalToolParams): Promise<TerminalToolResult> {
|
async execute(params: TerminalToolParams): Promise<TerminalToolResult> {
|
||||||
const validationError = this.invalidParams(params);
|
const validationError = this.validateToolParams(params);
|
||||||
if (validationError) {
|
if (validationError) {
|
||||||
return {
|
return {
|
||||||
llmContent: `Command rejected: ${params.command}\nReason: ${validationError}`,
|
llmContent: `Command rejected: ${params.command}\nReason: ${validationError}`,
|
||||||
|
|
|
@ -33,7 +33,7 @@ export interface Tool<
|
||||||
* @param params Parameters to validate
|
* @param params Parameters to validate
|
||||||
* @returns An error message string if invalid, null otherwise
|
* @returns An error message string if invalid, null otherwise
|
||||||
*/
|
*/
|
||||||
invalidParams(params: TParams): string | null;
|
validateToolParams(params: TParams): string | null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a pre-execution description of the tool operation
|
* Gets a pre-execution description of the tool operation
|
||||||
|
@ -99,7 +99,7 @@ export abstract class BaseTool<
|
||||||
* @param params Parameters to validate
|
* @param params Parameters to validate
|
||||||
* @returns An error message string if invalid, null otherwise
|
* @returns An error message string if invalid, null otherwise
|
||||||
*/
|
*/
|
||||||
invalidParams(params: TParams): string | null {
|
validateToolParams(params: TParams): string | null {
|
||||||
// Implementation would typically use a JSON Schema validator
|
// Implementation would typically use a JSON Schema validator
|
||||||
// This is a placeholder that should be implemented by derived classes
|
// This is a placeholder that should be implemented by derived classes
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -101,7 +101,7 @@ export class WriteFileTool extends BaseTool<
|
||||||
* @param params Parameters to validate
|
* @param params Parameters to validate
|
||||||
* @returns True if parameters are valid, false otherwise
|
* @returns True if parameters are valid, false otherwise
|
||||||
*/
|
*/
|
||||||
invalidParams(params: WriteFileToolParams): string | null {
|
validateToolParams(params: WriteFileToolParams): string | null {
|
||||||
if (
|
if (
|
||||||
this.schema.parameters &&
|
this.schema.parameters &&
|
||||||
!SchemaValidator.validate(
|
!SchemaValidator.validate(
|
||||||
|
@ -185,7 +185,7 @@ export class WriteFileTool extends BaseTool<
|
||||||
* @returns Result of the file writing operation
|
* @returns Result of the file writing operation
|
||||||
*/
|
*/
|
||||||
async execute(params: WriteFileToolParams): Promise<WriteFileToolResult> {
|
async execute(params: WriteFileToolParams): Promise<WriteFileToolResult> {
|
||||||
const validationError = this.invalidParams(params);
|
const validationError = this.validateToolParams(params);
|
||||||
if (validationError) {
|
if (validationError) {
|
||||||
return {
|
return {
|
||||||
llmContent: `Error: Invalid parameters provided. Reason: ${validationError}`,
|
llmContent: `Error: Invalid parameters provided. Reason: ${validationError}`,
|
||||||
|
|
Loading…
Reference in New Issue