@hashgraphonline/conversational-agent
Version:
Hashgraph Online conversational AI agent implementing HCS-10 communication, HCS-2 registries, and content inscription on Hedera. https://hol.org
103 lines (82 loc) โข 4.08 kB
text/typescript
/**
* Test script for the external tool wrapper functionality
* Run with: pnpm tsx src/scripts/test-external-tool-wrapper.ts
*/
import { examples } from '../examples/external-tool-wrapper-example';
async function testExternalToolWrapper(): Promise<void> {
console.log('๐งช Testing External Tool Wrapper\n');
try {
console.log('๐ Test 1: Basic external tool wrapping');
const basicTool = examples.basicWrapping();
console.log(`โ
Tool "${basicTool.name}" wrapped successfully`);
console.log(` Description: ${basicTool.description}`);
console.log(` Schema type: ${basicTool.schema.constructor.name}`);
const testInput = {
fromAccountId: '0.0.123',
toAccountId: '0.0.456',
amount: 1000000,
memo: 'Test transfer'
};
const result = await (basicTool as { _call: (input: unknown) => Promise<string> })._call(testInput);
console.log(` Execution result: ${result}\n`);
console.log('๐ Test 2: Preset configurations');
const presetTool = examples.presetConfigurations();
console.log(`โ
Tool "${presetTool.name}" wrapped with preset config`);
console.log(` Description: ${presetTool.description}\n`);
console.log('๐ Test 3: Batch wrapping multiple tools');
const batchTools = examples.batchWrapping();
console.log(`โ
Wrapped ${batchTools.length} tools in batch`);
batchTools.forEach((tool, index) => {
console.log(` Tool ${index + 1}: ${tool.name}`);
});
console.log();
console.log('๐ Test 4: Form validation integration');
const formTool = examples.formValidationIntegration();
console.log(`โ
Tool "${formTool.name}" wrapped with form validation`);
console.log(` Tool type: ${formTool.constructor.name}`);
const incompleteInput = {
fromAccountId: '0.0.123'
} as { fromAccountId: string };
try {
const formResult = await (formTool as { _call: (input: unknown) => Promise<string> })._call(incompleteInput);
const parsedResult = JSON.parse(formResult);
if (parsedResult.requiresForm) {
console.log(` โ
Form generation triggered for missing fields`);
console.log(` Form ID: ${parsedResult.formMessage.id}`);
console.log(` Form title: ${parsedResult.formMessage.formConfig.title}`);
console.log(` Fields in form: ${parsedResult.formMessage.formConfig.fields.length}`);
}
} catch (error) {
console.log(` โ ๏ธ Form generation test encountered error: ${error}`);
}
console.log();
console.log('๐ Test 5: Custom field configurations');
const customTool = examples.customFieldConfigs();
console.log(`โ
Tool "${customTool.name}" wrapped with custom configs`);
console.log(` Description: ${customTool.description}`);
const schema = customTool.schema as { _def: { shape: () => Record<string, { _renderConfig?: unknown }> } };
const shape = schema._def.shape();
let fieldConfigCount = 0;
for (const [, fieldSchema] of Object.entries(shape)) {
if (fieldSchema._renderConfig) {
fieldConfigCount++;
}
}
console.log(` Fields with render configs: ${fieldConfigCount}`);
console.log();
console.log('๐ Test 6: Render config helpers');
const { renderConfigs } = await import('../langchain/external-tool-wrapper');
const textConfig = renderConfigs.text('Test Field', 'placeholder', 'help text');
console.log(`โ
Text config: ${JSON.stringify(textConfig, null, 2)}`);
const numberConfig = renderConfigs.number('Amount', 0, 100, 'Enter amount');
console.log(`โ
Number config: ${JSON.stringify(numberConfig, null, 2)}`);
const accountConfig = renderConfigs.accountId('Account ID');
console.log(`โ
Account ID config: ${JSON.stringify(accountConfig, null, 2)}`);
console.log();
console.log('๐ All tests completed successfully!');
} catch (error) {
console.error('โ Test failed:', error);
process.exit(1);
}
}
testExternalToolWrapper().catch(console.error);