repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | /** |
| #2 | * Agent Discovery |
| #3 | * |
| #4 | * Discover other agents via ERC-8004 registry queries. |
| #5 | * Fetch and parse agent cards from URIs. |
| #6 | */ |
| #7 | import { queryAgent, getTotalAgents } from "./erc8004.js"; |
| #8 | /** |
| #9 | * Discover agents by scanning the registry. |
| #10 | * Returns a list of discovered agents with their metadata. |
| #11 | */ |
| #12 | export async function discoverAgents(limit = 20, network = "mainnet") { |
| #13 | const total = await getTotalAgents(network); |
| #14 | const scanCount = Math.min(total, limit); |
| #15 | const agents = []; |
| #16 | // Scan from most recent to oldest |
| #17 | for (let i = total; i > total - scanCount && i > 0; i--) { |
| #18 | const agent = await queryAgent(i.toString(), network); |
| #19 | if (agent) { |
| #20 | // Try to fetch the agent card for additional metadata |
| #21 | try { |
| #22 | const card = await fetchAgentCard(agent.agentURI); |
| #23 | if (card) { |
| #24 | agent.name = card.name; |
| #25 | agent.description = card.description; |
| #26 | } |
| #27 | } |
| #28 | catch { |
| #29 | // Card fetch failed, use basic info |
| #30 | } |
| #31 | agents.push(agent); |
| #32 | } |
| #33 | } |
| #34 | return agents; |
| #35 | } |
| #36 | /** |
| #37 | * Fetch an agent card from a URI. |
| #38 | */ |
| #39 | export async function fetchAgentCard(uri) { |
| #40 | try { |
| #41 | // Handle IPFS URIs |
| #42 | let fetchUrl = uri; |
| #43 | if (uri.startsWith("ipfs://")) { |
| #44 | fetchUrl = `https://ipfs.io/ipfs/${uri.slice(7)}`; |
| #45 | } |
| #46 | const response = await fetch(fetchUrl, { |
| #47 | signal: AbortSignal.timeout(10000), |
| #48 | }); |
| #49 | if (!response.ok) |
| #50 | return null; |
| #51 | const card = (await response.json()); |
| #52 | // Basic validation |
| #53 | if (!card.name || !card.type) |
| #54 | return null; |
| #55 | return card; |
| #56 | } |
| #57 | catch { |
| #58 | return null; |
| #59 | } |
| #60 | } |
| #61 | /** |
| #62 | * Search for agents by name or description. |
| #63 | * Scans recent registrations and filters by keyword. |
| #64 | */ |
| #65 | export async function searchAgents(keyword, limit = 10, network = "mainnet") { |
| #66 | const all = await discoverAgents(50, network); |
| #67 | const lower = keyword.toLowerCase(); |
| #68 | return all |
| #69 | .filter((a) => a.name?.toLowerCase().includes(lower) || |
| #70 | a.description?.toLowerCase().includes(lower) || |
| #71 | a.owner.toLowerCase().includes(lower)) |
| #72 | .slice(0, limit); |
| #73 | } |
| #74 | //# sourceMappingURL=discovery.js.map |