From e073eb0a184de16ec106d177f4b34f54ebf11ef1 Mon Sep 17 00:00:00 2001 From: jaime wang Date: Wed, 7 May 2025 10:49:55 +0800 Subject: [PATCH 1/2] feat: query agent info via acp client --- plugins/acpPlugin/src/acpClient.ts | 24 ++++++++++++++++++++++++ plugins/acpPlugin/src/acpPlugin.ts | 4 ++++ 2 files changed, 28 insertions(+) diff --git a/plugins/acpPlugin/src/acpClient.ts b/plugins/acpPlugin/src/acpClient.ts index 81073c51..937587a4 100644 --- a/plugins/acpPlugin/src/acpClient.ts +++ b/plugins/acpPlugin/src/acpClient.ts @@ -66,6 +66,30 @@ export class AcpClient { })); } + async queryAgent(address: string) { + const baseUrl = + this.agentRepoUrl || "https://acpx-staging.virtuals.io/api/agents"; + + let url = `${baseUrl}?filters[walletAddress][$eq]=${address}`; + + const response = await fetch(url); + if (!response.ok) { + throw new Error( + `Failed to browse agents: ${response.status} ${response.statusText}` + ); + } + + const responseJson = await response.json(); + return (responseJson.data as AcpAgent[]).map((agent) => ({ + id: agent.id, + name: agent.name, + description: agent.description, + walletAddress: agent.walletAddress, + twitterHandler: agent.twitterHandle, + offerings: agent.offerings, + })); + } + async createJob( providerAddress: string, evaluatorAddress: string, diff --git a/plugins/acpPlugin/src/acpPlugin.ts b/plugins/acpPlugin/src/acpPlugin.ts index ecaf3a35..4d9fd876 100644 --- a/plugins/acpPlugin/src/acpPlugin.ts +++ b/plugins/acpPlugin/src/acpPlugin.ts @@ -187,6 +187,10 @@ class AcpPlugin { return serverState; } + public async getAcpClient() { + return this.acpClient; + } + public getWorker(data?: { functions?: GameFunction[]; getEnvironment?: () => Promise>; From 96d158828c79a63e30976022fba54efd613bde64 Mon Sep 17 00:00:00 2001 From: jaime wang Date: Wed, 7 May 2025 10:53:19 +0800 Subject: [PATCH 2/2] feat: opt the return value --- plugins/acpPlugin/src/acpClient.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/acpPlugin/src/acpClient.ts b/plugins/acpPlugin/src/acpClient.ts index 937587a4..7debf5a0 100644 --- a/plugins/acpPlugin/src/acpClient.ts +++ b/plugins/acpPlugin/src/acpClient.ts @@ -75,12 +75,12 @@ export class AcpClient { const response = await fetch(url); if (!response.ok) { throw new Error( - `Failed to browse agents: ${response.status} ${response.statusText}` + `Failed to query agent: ${response.status} ${response.statusText}` ); } const responseJson = await response.json(); - return (responseJson.data as AcpAgent[]).map((agent) => ({ + const agents = (responseJson.data as AcpAgent[]).map((agent) => ({ id: agent.id, name: agent.name, description: agent.description, @@ -88,6 +88,7 @@ export class AcpClient { twitterHandler: agent.twitterHandle, offerings: agent.offerings, })); + return agents.length > 0 ? agents[0] : undefined; } async createJob(