* Validate that a brand agent is reachable
(agentUrl: string)
| 837 | * Validate that a brand agent is reachable |
| 838 | */ |
| 839 | async validateBrandAgent(agentUrl: string): Promise<BrandAgentValidationResult> { |
| 840 | const result: BrandAgentValidationResult = { |
| 841 | agent_url: agentUrl, |
| 842 | valid: false, |
| 843 | errors: [], |
| 844 | }; |
| 845 | |
| 846 | const startTime = Date.now(); |
| 847 | const MCP_TIMEOUT_MS = 5000; |
| 848 | |
| 849 | try { |
| 850 | const { AdCPClient } = await import('@adcp/client'); |
| 851 | const multiClient = new AdCPClient([ |
| 852 | { |
| 853 | id: 'brand-agent-check', |
| 854 | name: 'Brand Agent Checker', |
| 855 | agent_uri: agentUrl, |
| 856 | protocol: 'mcp', |
| 857 | }, |
| 858 | ]); |
| 859 | const client = multiClient.agent('brand-agent-check'); |
| 860 | |
| 861 | const agentInfo = await Promise.race([ |
| 862 | client.getAgentInfo(), |
| 863 | new Promise<never>((_, reject) => |
| 864 | setTimeout(() => reject(new Error('MCP connection timed out')), MCP_TIMEOUT_MS) |
| 865 | ), |
| 866 | ]); |
| 867 | |
| 868 | result.response_time_ms = Date.now() - startTime; |
| 869 | result.valid = true; |
| 870 | result.agent_data = { |
| 871 | name: agentInfo.name, |
| 872 | protocol: 'mcp', |
| 873 | tools: agentInfo.tools?.map((t: { name: string }) => t.name) || [], |
| 874 | tools_count: agentInfo.tools?.length || 0, |
| 875 | }; |
| 876 | } catch (error) { |
| 877 | result.response_time_ms = Date.now() - startTime; |
| 878 | const message = error instanceof Error ? error.message : 'Unknown error'; |
| 879 | result.errors.push(`MCP connection failed: ${message}`); |
| 880 | } |
| 881 | |
| 882 | return result; |
| 883 | } |
| 884 | |
| 885 | /** |
| 886 | * Create a house redirect brand.json file |
no test coverage detected