UNPKG

@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
/** * 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);