mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-19 09:33:53 +00:00
Rename invalidParams to validateToolParams (#12)
Methods should be verbs. Fixes #4.
This commit is contained in:
@@ -92,7 +92,7 @@ export class GlobTool extends BaseTool<GlobToolParams, ToolResult> {
|
||||
* @param params Parameters to validate
|
||||
* @returns An error message string if invalid, null otherwise
|
||||
*/
|
||||
invalidParams(params: GlobToolParams): string | null {
|
||||
validateToolParams(params: GlobToolParams): string | null {
|
||||
if (
|
||||
this.schema.parameters &&
|
||||
!SchemaValidator.validate(
|
||||
@@ -161,7 +161,7 @@ export class GlobTool extends BaseTool<GlobToolParams, ToolResult> {
|
||||
* @returns Result of the glob search
|
||||
*/
|
||||
async execute(params: GlobToolParams): Promise<ToolResult> {
|
||||
const validationError = this.invalidParams(params);
|
||||
const validationError = this.validateToolParams(params);
|
||||
if (validationError) {
|
||||
return {
|
||||
llmContent: `Error: Invalid parameters provided. Reason: ${validationError}`,
|
||||
|
||||
@@ -127,7 +127,7 @@ export class GrepTool extends BaseTool<GrepToolParams, ToolResult> {
|
||||
* @param params Parameters to validate
|
||||
* @returns An error message string if invalid, null otherwise
|
||||
*/
|
||||
invalidParams(params: GrepToolParams): string | null {
|
||||
validateToolParams(params: GrepToolParams): string | null {
|
||||
if (
|
||||
this.schema.parameters &&
|
||||
!SchemaValidator.validate(
|
||||
@@ -161,7 +161,7 @@ export class GrepTool extends BaseTool<GrepToolParams, ToolResult> {
|
||||
* @returns Result of the grep search
|
||||
*/
|
||||
async execute(params: GrepToolParams): Promise<ToolResult> {
|
||||
const validationError = this.invalidParams(params);
|
||||
const validationError = this.validateToolParams(params);
|
||||
if (validationError) {
|
||||
console.error(`GrepTool Parameter Validation Failed: ${validationError}`);
|
||||
return {
|
||||
|
||||
@@ -135,9 +135,10 @@ export class LSTool extends BaseTool<LSToolParams, LSToolResult> {
|
||||
* @param params Parameters to validate
|
||||
* @returns An error message string if invalid, null otherwise
|
||||
*/
|
||||
invalidParams(params: LSToolParams): string | null {
|
||||
validateToolParams(params: LSToolParams): string | null {
|
||||
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.';
|
||||
}
|
||||
if (!path.isAbsolute(params.path)) {
|
||||
@@ -199,7 +200,7 @@ export class LSTool extends BaseTool<LSToolParams, LSToolResult> {
|
||||
* @returns Result of the LS operation
|
||||
*/
|
||||
async execute(params: LSToolParams): Promise<LSToolResult> {
|
||||
const validationError = this.invalidParams(params);
|
||||
const validationError = this.validateToolParams(params);
|
||||
if (validationError) {
|
||||
return this.errorResult(
|
||||
params,
|
||||
|
||||
@@ -106,7 +106,7 @@ export class ReadFileTool extends BaseTool<
|
||||
* @param params Parameters to validate
|
||||
* @returns True if parameters are valid, false otherwise
|
||||
*/
|
||||
invalidParams(params: ReadFileToolParams): string | null {
|
||||
validateToolParams(params: ReadFileToolParams): string | null {
|
||||
if (
|
||||
this.schema.parameters &&
|
||||
!SchemaValidator.validate(
|
||||
@@ -210,8 +210,7 @@ export class ReadFileTool extends BaseTool<
|
||||
* @returns Result with file contents
|
||||
*/
|
||||
async execute(params: ReadFileToolParams): Promise<ToolResult> {
|
||||
const validationError = this.invalidParams(params);
|
||||
const filePath = params.file_path;
|
||||
const validationError = this.validateToolParams(params);
|
||||
if (validationError) {
|
||||
return {
|
||||
llmContent: `Error: Invalid parameters provided. Reason: ${validationError}`,
|
||||
@@ -219,6 +218,7 @@ export class ReadFileTool extends BaseTool<
|
||||
};
|
||||
}
|
||||
|
||||
const filePath = params.file_path;
|
||||
try {
|
||||
if (!fs.existsSync(filePath)) {
|
||||
return {
|
||||
|
||||
@@ -317,7 +317,7 @@ Use this tool for running build steps (\`npm install\`, \`make\`), linters (\`es
|
||||
}
|
||||
|
||||
// --- Parameter Validation (unchanged) ---
|
||||
invalidParams(params: TerminalToolParams): string | null {
|
||||
validateToolParams(params: TerminalToolParams): string | null {
|
||||
if (
|
||||
!SchemaValidator.validate(
|
||||
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) ---
|
||||
async execute(params: TerminalToolParams): Promise<TerminalToolResult> {
|
||||
const validationError = this.invalidParams(params);
|
||||
const validationError = this.validateToolParams(params);
|
||||
if (validationError) {
|
||||
return {
|
||||
llmContent: `Command rejected: ${params.command}\nReason: ${validationError}`,
|
||||
|
||||
@@ -33,7 +33,7 @@ export interface Tool<
|
||||
* @param params Parameters to validate
|
||||
* @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
|
||||
@@ -99,7 +99,7 @@ export abstract class BaseTool<
|
||||
* @param params Parameters to validate
|
||||
* @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
|
||||
// This is a placeholder that should be implemented by derived classes
|
||||
return null;
|
||||
|
||||
@@ -101,7 +101,7 @@ export class WriteFileTool extends BaseTool<
|
||||
* @param params Parameters to validate
|
||||
* @returns True if parameters are valid, false otherwise
|
||||
*/
|
||||
invalidParams(params: WriteFileToolParams): string | null {
|
||||
validateToolParams(params: WriteFileToolParams): string | null {
|
||||
if (
|
||||
this.schema.parameters &&
|
||||
!SchemaValidator.validate(
|
||||
@@ -185,7 +185,7 @@ export class WriteFileTool extends BaseTool<
|
||||
* @returns Result of the file writing operation
|
||||
*/
|
||||
async execute(params: WriteFileToolParams): Promise<WriteFileToolResult> {
|
||||
const validationError = this.invalidParams(params);
|
||||
const validationError = this.validateToolParams(params);
|
||||
if (validationError) {
|
||||
return {
|
||||
llmContent: `Error: Invalid parameters provided. Reason: ${validationError}`,
|
||||
|
||||
Reference in New Issue
Block a user