(agent: Agent)
| 63 | } |
| 64 | |
| 65 | async discoverCapabilities(agent: Agent): Promise<AgentCapabilityProfile> { |
| 66 | const cached = this.cache.get(agent.url); |
| 67 | if (cached && Date.now() - new Date(cached.last_discovered).getTime() < this.CACHE_TTL_MS) { |
| 68 | return cached; |
| 69 | } |
| 70 | |
| 71 | const startTime = Date.now(); |
| 72 | try { |
| 73 | const protocol = agent.protocol || "mcp"; |
| 74 | const tools = await this.discoverTools(agent.url, protocol); |
| 75 | |
| 76 | logOutboundRequest({ |
| 77 | agent_url: agent.url, |
| 78 | request_type: 'discovery', |
| 79 | user_agent: AAO_UA_DISCOVERY, |
| 80 | response_time_ms: Date.now() - startTime, |
| 81 | success: true, |
| 82 | }); |
| 83 | |
| 84 | const profile: AgentCapabilityProfile = { |
| 85 | agent_url: agent.url, |
| 86 | protocol, |
| 87 | discovered_tools: tools, |
| 88 | last_discovered: new Date().toISOString(), |
| 89 | }; |
| 90 | |
| 91 | // Analyze all matching capabilities (agent may support multiple types) |
| 92 | const toolNames = new Set(tools.map((t) => t.name.toLowerCase())); |
| 93 | |
| 94 | if (CapabilityDiscovery.SALES_TOOLS.some(t => toolNames.has(t))) { |
| 95 | profile.standard_operations = this.analyzeSalesCapabilities(tools); |
| 96 | } |
| 97 | if (CapabilityDiscovery.CREATIVE_TOOLS.some(t => toolNames.has(t))) { |
| 98 | profile.creative_capabilities = await this.analyzeCreativeCapabilities(agent, tools); |
| 99 | } |
| 100 | if (CapabilityDiscovery.SIGNALS_TOOLS.some(t => toolNames.has(t))) { |
| 101 | profile.signals_capabilities = this.analyzeSignalsCapabilities(tools); |
| 102 | } |
| 103 | |
| 104 | this.cache.set(agent.url, profile); |
| 105 | return profile; |
| 106 | } catch (error: any) { |
| 107 | logOutboundRequest({ |
| 108 | agent_url: agent.url, |
| 109 | request_type: 'discovery', |
| 110 | user_agent: AAO_UA_DISCOVERY, |
| 111 | response_time_ms: Date.now() - startTime, |
| 112 | success: false, |
| 113 | error_message: error.message, |
| 114 | }); |
| 115 | |
| 116 | const isOAuthError = error instanceof AuthenticationRequiredError; |
| 117 | const errorProfile: AgentCapabilityProfile = { |
| 118 | agent_url: agent.url, |
| 119 | protocol: agent.protocol || "mcp", |
| 120 | discovered_tools: [], |
| 121 | last_discovered: new Date().toISOString(), |
| 122 | discovery_error: error.message, |
no test coverage detected