import { SafeConversationalAgent } from '../src/main/services/SafeConversationalAgent'; import * as dotenv from 'dotenv'; dotenv.config(); /** * Debug script to see exactly what's happening with tool invocation */ async function debugToolInvocation(): Promise { console.log('šŸ› DEBUG: Tool invocation analysis...\n'); if (!process.env.HEDERA_OPERATOR_ID || !process.env.HEDERA_OPERATOR_KEY || !process.env.OPENAI_API_KEY) { throw new Error('Required environment variables not set'); } const config = { accountId: process.env.HEDERA_OPERATOR_ID, privateKey: process.env.HEDERA_OPERATOR_KEY, network: 'testnet' as any, openAIApiKey: process.env.OPENAI_API_KEY, llmProvider: 'openai' as const, operationalMode: 'test' as const, verbose: true, disableLogging: false }; let agent: SafeConversationalAgent | null = null; try { console.log('šŸš€ Initializing agent...'); agent = new SafeConversationalAgent(config); await agent.initialize(); console.log('āœ… Agent initialized\n'); const testCases = [ { name: "Content-ref inscription (SHOULD generate form)", message: "I want to inscribe content-ref:test-123 as a Hashinal NFT" }, { name: "Direct inscription call", message: "Please call inscribeHashinal with contentRef: content-ref:test-123" }, { name: "Simple inscription request", message: "inscribe this as NFT: content-ref:test-123" } ]; for (const testCase of testCases) { console.log(`\nšŸ“‹ TEST: ${testCase.name}`); console.log(`Message: "${testCase.message}"`); console.log('━'.repeat(80)); try { const result = await agent.processMessage(testCase.message); console.log('šŸ“Š RESULT ANALYSIS:'); console.log('- Type:', typeof result); console.log('- Has requiresForm:', !!result?.requiresForm); console.log('- Has formMessage:', !!result?.formMessage); console.log('- Has error:', !!result?.error); console.log('- Response length:', result?.output?.length || 0); if (result?.formMessage) { console.log('āœ… FORM GENERATED'); console.log('- Form ID:', result.formMessage.id); console.log('- Tool name:', result.formMessage.toolName); console.log('- Field count:', result.formMessage.formConfig?.fields?.length || 0); } else { console.log('āŒ NO FORM GENERATED'); console.log('- Response preview:', (result?.output || '').substring(0, 100) + '...'); } const fullResponse = JSON.stringify(result); if (fullResponse.includes('error') || fullResponse.includes('Error')) { console.log('āš ļø Error indicators found in response'); } } catch (error) { console.log('āŒ ERROR during processing:', error); } } } catch (error) { console.error('āŒ Debug failed:', error); throw error; } finally { if (agent) { try { await agent.disconnect(); } catch (e) { console.warn('Warning: Could not disconnect agent:', e); } } } } debugToolInvocation().catch(error => { console.error('Debug execution failed:', error); process.exit(1); });