* Get agent by URL * Checks registered agents first, then discovered agents
(url: string, options: { viewerHasApiAccess?: boolean } = {})
| 90 | * Checks registered agents first, then discovered agents |
| 91 | */ |
| 92 | async getAgentByUrl(url: string, options: { viewerHasApiAccess?: boolean } = {}): Promise<Agent | undefined> { |
| 93 | const viewerHasApiAccess = options.viewerHasApiAccess ?? false; |
| 94 | // Mirror listAgents: API-access viewers can look up members_only agents |
| 95 | // on private profiles; unauth viewers stay scoped to public profiles. |
| 96 | const profiles = viewerHasApiAccess |
| 97 | ? await this.memberDb.listProfiles() |
| 98 | : await this.memberDb.listProfiles({ is_public: true }); |
| 99 | |
| 100 | for (const profile of profiles) { |
| 101 | for (const agentConfig of profile.agents || []) { |
| 102 | if (agentConfig.url !== url) continue; |
| 103 | if (!this.isVisibleToViewer(agentConfig.visibility, viewerHasApiAccess)) continue; |
| 104 | if (agentConfig.visibility === 'public' && !profile.is_public && !viewerHasApiAccess) continue; |
| 105 | return this.configToAgent(agentConfig, profile); |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | // Check discovered agents |
| 110 | const discoveredAgents = await this.federatedDb.getAllDiscoveredAgents(); |
| 111 | for (const discovered of discoveredAgents) { |
| 112 | if (discovered.agent_url === url) { |
| 113 | return this.discoveredToAgent(discovered); |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | return undefined; |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Get agent by identifier (URL or legacy slug format like "type/name") |
no test coverage detected