Skip to content

Commit ee89655

Browse files
author
Zuhwa
committed
type clean up
1 parent 59dd6c2 commit ee89655

5 files changed

Lines changed: 132 additions & 80 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ const completedJobs = await acpClient.getCompletedJobs(page, pageSize);
121121
const cancelledJobs = await acpClient.getCancelledJobs(page, pageSize);
122122

123123
// Get specific job
124-
const job = await acpClient.getJobByOnChainJobId(onChainJobId);
124+
const job = await acpClient.getJobById(jobId);
125125

126126
// Get memo by ID
127-
const memo = await acpClient.getMemoById(onChainJobId, memoId);
127+
const memo = await acpClient.getMemoById(jobId, memoId);
128128
```
129129

130130
### Agent Discovery

interfaces.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { JSONSchemaType } from "ajv";
21
import { Address } from "viem";
32

43
export type AcpAgent = {
@@ -18,6 +17,7 @@ export type AcpAgent = {
1817
name: string;
1918
price: number;
2019
requirementSchema?: Object;
20+
deliverableSchema?: Object;
2121
}[];
2222
symbol: string | null;
2323
virtualAgentId: string | null;

src/acpClient.ts

Lines changed: 58 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -5,59 +5,12 @@ import { AcpAgent } from "../interfaces";
55
import AcpJob from "./acpJob";
66
import AcpMemo from "./acpMemo";
77
import AcpJobOffering from "./acpJobOffering";
8-
9-
export interface IDeliverable {
10-
type: string;
11-
value: string;
12-
}
13-
14-
interface IAcpMemoData {
15-
onChainJobId?: number;
16-
type: string;
17-
content: string;
18-
createdAt: string;
19-
memoId: number;
20-
memoType: MemoType;
21-
nextPhase: AcpJobPhases;
22-
}
23-
interface IAcpMemo {
24-
data: IAcpMemoData;
25-
error?: Error;
26-
}
27-
28-
interface IAcpJob {
29-
data: {
30-
onChainJobId: number;
31-
phase: AcpJobPhases;
32-
description: string;
33-
buyerAddress: `0x${string}`;
34-
sellerAddress: `0x${string}`;
35-
evaluatorAddress: `0x${string}`;
36-
price: number;
37-
deliverable: IDeliverable | null;
38-
memos: IAcpMemoData[];
39-
createdAt: string;
40-
};
41-
error?: Error;
42-
}
43-
interface IAcpJobResponse {
44-
data: IAcpJob["data"][];
45-
meta?: {
46-
pagination: {
47-
page: number;
48-
pageSize: number;
49-
pageCount: number;
50-
total: number;
51-
};
52-
};
53-
error?: Error;
54-
}
55-
56-
interface IAcpClientOptions {
57-
acpContractClient: AcpContractClient;
58-
onNewTask?: (job: AcpJob) => void;
59-
onEvaluate?: (job: AcpJob) => void;
60-
}
8+
import {
9+
IAcpClientOptions,
10+
IAcpJob,
11+
IAcpJobResponse,
12+
IAcpMemo,
13+
} from "./interfaces";
6114

6215
enum SocketEvents {
6316
ROOM_JOINED = "roomJoined",
@@ -118,12 +71,14 @@ class AcpClient {
11871
if (this.onEvaluate) {
11972
const job = new AcpJob(
12073
this,
121-
data.onChainJobId,
122-
data.sellerAddress,
74+
data.id,
75+
data.clientAddress,
76+
data.providerAddress,
77+
data.evaluatorAddress,
12378
data.memos.map((memo) => {
12479
return new AcpMemo(
12580
this,
126-
memo.memoId,
81+
memo.id,
12782
memo.memoType,
12883
memo.content,
12984
memo.nextPhase
@@ -145,12 +100,14 @@ class AcpClient {
145100
if (this.onNewTask) {
146101
const job = new AcpJob(
147102
this,
148-
data.onChainJobId,
149-
data.sellerAddress,
103+
data.id,
104+
data.clientAddress,
105+
data.providerAddress,
106+
data.evaluatorAddress,
150107
data.memos.map((memo) => {
151108
return new AcpMemo(
152109
this,
153-
memo.memoId,
110+
memo.id,
154111
memo.memoType,
155112
memo.content,
156113
memo.nextPhase
@@ -297,12 +254,14 @@ class AcpClient {
297254
return data.data.map((job) => {
298255
return new AcpJob(
299256
this,
300-
job.onChainJobId,
301-
job.sellerAddress,
257+
job.id,
258+
job.clientAddress,
259+
job.providerAddress,
260+
job.evaluatorAddress,
302261
job.memos.map((memo) => {
303262
return new AcpMemo(
304263
this,
305-
memo.memoId,
264+
memo.id,
306265
memo.memoType,
307266
memo.content,
308267
memo.nextPhase
@@ -335,12 +294,14 @@ class AcpClient {
335294
return data.data.map((job) => {
336295
return new AcpJob(
337296
this,
338-
job.onChainJobId,
339-
job.sellerAddress,
297+
job.id,
298+
job.clientAddress,
299+
job.providerAddress,
300+
job.evaluatorAddress,
340301
job.memos.map((memo) => {
341302
return new AcpMemo(
342303
this,
343-
memo.memoId,
304+
memo.id,
344305
memo.memoType,
345306
memo.content,
346307
memo.nextPhase
@@ -372,12 +333,14 @@ class AcpClient {
372333
return data.data.map((job) => {
373334
return new AcpJob(
374335
this,
375-
job.onChainJobId,
376-
job.sellerAddress,
336+
job.id,
337+
job.clientAddress,
338+
job.providerAddress,
339+
job.evaluatorAddress,
377340
job.memos.map((memo) => {
378341
return new AcpMemo(
379342
this,
380-
memo.memoId,
343+
memo.id,
381344
memo.memoType,
382345
memo.content,
383346
memo.nextPhase
@@ -391,8 +354,8 @@ class AcpClient {
391354
}
392355
}
393356

394-
async getJobByOnChainJobId(onChainJobId: number) {
395-
let url = `${this.acpUrl}/api/jobs/${onChainJobId}`;
357+
async getJobById(jobId: number) {
358+
let url = `${this.acpUrl}/api/jobs/${jobId}`;
396359

397360
try {
398361
const response = await fetch(url, {
@@ -414,12 +377,14 @@ class AcpClient {
414377

415378
return new AcpJob(
416379
this,
417-
job.onChainJobId,
418-
job.sellerAddress,
380+
job.id,
381+
job.clientAddress,
382+
job.providerAddress,
383+
job.evaluatorAddress,
419384
job.memos.map((memo) => {
420385
return new AcpMemo(
421386
this,
422-
memo.memoId,
387+
memo.id,
423388
memo.memoType,
424389
memo.content,
425390
memo.nextPhase
@@ -432,8 +397,8 @@ class AcpClient {
432397
}
433398
}
434399

435-
async getMemoById(onChainJobId: number, memoId: number) {
436-
let url = `${this.acpUrl}/api/jobs/${onChainJobId}/memos/${memoId}`;
400+
async getMemoById(jobId: number, memoId: number) {
401+
let url = `${this.acpUrl}/api/jobs/${jobId}/memos/${memoId}`;
437402

438403
try {
439404
const response = await fetch(url, {
@@ -455,7 +420,7 @@ class AcpClient {
455420

456421
return new AcpMemo(
457422
this,
458-
memo.memoId,
423+
memo.id,
459424
memo.memoType,
460425
memo.content,
461426
memo.nextPhase
@@ -464,6 +429,23 @@ class AcpClient {
464429
throw error;
465430
}
466431
}
432+
433+
async getAgent(walletAddress: Address) {
434+
const url = `${this.acpUrl}/api/agents?filters[walletAddress]=${walletAddress}`;
435+
436+
const response = await fetch(url);
437+
const data: {
438+
data: AcpAgent[];
439+
} = await response.json();
440+
441+
const agents = data.data || [];
442+
443+
if (agents.length === 0) {
444+
return;
445+
}
446+
447+
return agents[0];
448+
}
467449
}
468450

469451
export default AcpClient;

src/acpJob.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Address } from "viem";
12
import AcpClient from "./acpClient";
23
import { AcpJobPhases } from "./acpContractClient";
34
import AcpMemo from "./acpMemo";
@@ -6,7 +7,9 @@ class AcpJob {
67
constructor(
78
private acpClient: AcpClient,
89
public id: number,
9-
public providerAddress: string,
10+
public clientAddress: Address,
11+
public providerAddress: Address,
12+
public evaluatorAddress: Address,
1013
public memos: AcpMemo[],
1114
public phase: AcpJobPhases
1215
) {}
@@ -21,6 +24,18 @@ class AcpJob {
2124
?.content;
2225
}
2326

27+
public get providerAgent() {
28+
return this.acpClient.getAgent(this.providerAddress);
29+
}
30+
31+
public get clientAgent() {
32+
return this.acpClient.getAgent(this.clientAddress);
33+
}
34+
35+
public get evaluatorAgent() {
36+
return this.acpClient.getAgent(this.evaluatorAddress);
37+
}
38+
2439
async pay(amount: number, reason?: string) {
2540
const memo = this.memos.find(
2641
(m) => m.nextPhase === AcpJobPhases.TRANSACTION

src/interfaces.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { Address } from "viem";
2+
import AcpContractClient, { AcpJobPhases, MemoType } from "./acpContractClient";
3+
import AcpJob from "./acpJob";
4+
5+
export interface IDeliverable {
6+
type: string;
7+
value: string;
8+
}
9+
10+
export interface IAcpMemoData {
11+
id: number;
12+
type: string;
13+
content: string;
14+
createdAt: string;
15+
memoType: MemoType;
16+
nextPhase: AcpJobPhases;
17+
}
18+
export interface IAcpMemo {
19+
data: IAcpMemoData;
20+
error?: Error;
21+
}
22+
23+
export interface IAcpJob {
24+
data: {
25+
id: number;
26+
phase: AcpJobPhases;
27+
description: string;
28+
clientAddress: Address;
29+
providerAddress: Address;
30+
evaluatorAddress: Address;
31+
price: number;
32+
deliverable: IDeliverable | null;
33+
memos: IAcpMemoData[];
34+
createdAt: string;
35+
};
36+
error?: Error;
37+
}
38+
export interface IAcpJobResponse {
39+
data: IAcpJob["data"][];
40+
meta?: {
41+
pagination: {
42+
page: number;
43+
pageSize: number;
44+
pageCount: number;
45+
total: number;
46+
};
47+
};
48+
error?: Error;
49+
}
50+
51+
export interface IAcpClientOptions {
52+
acpContractClient: AcpContractClient;
53+
onNewTask?: (job: AcpJob) => void;
54+
onEvaluate?: (job: AcpJob) => void;
55+
}

0 commit comments

Comments
 (0)