import { ProviderManager } from '../providers/manager.js'; import { HealthMonitor } from '../services/health.js'; import { ProviderHealth } from '../config/types.js'; import { duckArt } from '../utils/ascii-art.js'; import { logger } from '../utils/logger.js'; export async function listDucksTool( providerManager: ProviderManager, healthMonitor: HealthMonitor, args: Record ) { const { check_health = false } = args as { check_health?: boolean; }; // Get all providers with their info const providers = providerManager.getAllProviders(); // Perform health check if requested let healthStatus = new Map(); if (check_health) { const healthResults = await healthMonitor.performHealthChecks(); healthStatus = new Map(healthResults.map((result) => [result.provider, result])); } // Build response let response = `${duckArt.panel}\n\n`; response += `Found ${providers.length} duck(s) in the pond:\n\n`; for (const provider of providers) { const health = healthStatus.get(provider.name); const statusEmoji = health?.healthy ? 'āœ…' : health === undefined ? 'ā“' : 'āŒ'; const providerType = provider.info.type === 'cli' ? 'CLI' : 'HTTP'; response += `${statusEmoji} **${provider.info.nickname}** (${provider.name}) [${providerType}]\n`; response += ` šŸ“ Model: ${provider.info.model}\n`; if (provider.info.type === 'cli') { response += ` šŸ–„ļø Command: ${provider.info.cliCommand || 'default'}\n`; response += ` šŸ”§ CLI Type: ${provider.info.cliType || 'unknown'}\n`; } else { response += ` šŸ”— Endpoint: ${provider.info.baseURL}\n`; response += ` šŸ”‘ API Key: ${provider.info.hasApiKey ? 'Configured' : 'Not required'}\n`; } if (health) { response += ` šŸ’“ Health: ${health.healthy ? 'Healthy' : 'Unhealthy'}`; if (health.latency) { response += ` (${health.latency}ms)`; } if (health.error) { response += `\n āš ļø Error: ${health.error}`; } response += `\n šŸ•’ Last check: ${health.lastCheck.toLocaleTimeString()}\n`; } response += '\n'; } // Add summary const healthyCount = Array.from(healthStatus.values()).filter((h) => h.healthy).length; response += `\nšŸ“Š Summary: ${healthyCount}/${providers.length} ducks are healthy and ready!`; logger.info(`Listed ${providers.length} ducks, ${healthyCount} healthy`); return { content: [ { type: 'text', text: response, }, ], }; }