@@ -5,59 +5,12 @@ import { AcpAgent } from "../interfaces";
55import AcpJob from "./acpJob" ;
66import AcpMemo from "./acpMemo" ;
77import 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
6215enum 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
469451export default AcpClient ;
0 commit comments