fix add tool

This commit is contained in:
nasir@endelospay.com
2025-07-19 03:08:10 +05:00
parent 3ec4b2d41a
commit 811b9bee91
17 changed files with 51683 additions and 725 deletions

131
test-tool-execution.js Normal file
View File

@@ -0,0 +1,131 @@
#!/usr/bin/env node
/**
* Test Tool Execution
* Verify that specific tools can be found and executed
*/
import { ConfigManager } from "./src/config/ConfigManager.js";
import { AuthManager } from "./src/auth/AuthManager.js";
import { ApiClient } from "./src/proxy/ApiClient.js";
import { ToolGenerator } from "./src/tools/ToolGenerator.js";
async function testToolExecution() {
try {
console.log("🧪 Testing Tool Execution...\n");
// Initialize components
const config = new ConfigManager();
const authManager = new AuthManager(null, config.getAll(true));
const apiClient = new ApiClient(config.getAll(), authManager);
const toolGenerator = new ToolGenerator(apiClient);
// Generate all tools
console.log("📋 Generating all tools...");
const allTools = toolGenerator.generateAllTools();
console.log(`✅ Generated ${allTools.length} tools`);
// Test finding specific tool
const testToolName = "public_create_login";
console.log(`\n🔍 Looking for tool: ${testToolName}`);
const toolDef = allTools.find((tool) => tool.name === testToolName);
if (!toolDef) {
console.error(`❌ Tool ${testToolName} not found in generated tools`);
console.log("\n📋 Available public tools:");
const publicTools = allTools.filter((tool) =>
tool.name.startsWith("public_")
);
publicTools.slice(0, 10).forEach((tool) => {
console.log(` - ${tool.name}`);
});
if (publicTools.length > 10) {
console.log(` ... and ${publicTools.length - 10} more public tools`);
}
return false;
}
console.log(`✅ Found tool: ${toolDef.name}`);
console.log(`📝 Description: ${toolDef.description}`);
console.log(
`🔧 Input Schema:`,
JSON.stringify(toolDef.inputSchema, null, 2)
);
// Get the actual tool implementation
const tool = toolGenerator.getTool(testToolName);
if (!tool || !tool.execute) {
console.error(`❌ Tool ${testToolName} has no execute method`);
return false;
}
console.log(`✅ Tool has execute method`);
console.log(`📊 Tool details:`, {
name: tool.name,
authType: tool.authType,
endpoint: {
path: tool.endpoint.path,
method: tool.endpoint.method,
controller: tool.endpoint.controller,
},
});
// Test tool execution (this will fail due to network, but we can verify the structure)
console.log(`\n🚀 Testing tool execution structure...`);
try {
const testParams = {
username: "test@example.com",
password: "test123",
};
console.log(`📝 Test parameters:`, testParams);
// This will likely fail due to network/API issues, but we can catch and verify the structure
await tool.execute(testParams);
console.log(`✅ Tool execution completed successfully`);
} catch (error) {
if (
error.message.includes("ENOTFOUND") ||
error.message.includes("connect")
) {
console.log(
`✅ Tool execution structure is correct (network error expected)`
);
console.log(`📋 Network error: ${error.message}`);
} else if (
error.message.includes("Invalid credentials") ||
error.message.includes("Unauthorized")
) {
console.log(
`✅ Tool execution structure is correct (authentication error expected with test credentials)`
);
console.log(`📋 API response: ${error.message}`);
} else {
console.error(
`❌ Tool execution failed with unexpected error:`,
error.message
);
return false;
}
}
console.log("\n🎉 Tool execution test completed successfully!");
return true;
} catch (error) {
console.error("❌ Test failed:", error.message);
console.error("📋 Stack:", error.stack);
return false;
}
}
// Run the test
testToolExecution().then((success) => {
if (success) {
console.log("\n✅ All tests passed!");
process.exit(0);
} else {
console.log("\n❌ Tests failed!");
process.exit(1);
}
});