paypol-sdk 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +68 -0
- package/dist/AgentClient.d.ts +54 -0
- package/dist/AgentClient.d.ts.map +1 -0
- package/dist/AgentClient.js +110 -0
- package/dist/AgentClient.js.map +1 -0
- package/dist/PayPolAgent.d.ts +39 -0
- package/dist/PayPolAgent.d.ts.map +1 -0
- package/dist/PayPolAgent.js +125 -0
- package/dist/PayPolAgent.js.map +1 -0
- package/dist/adapters/anthropic.d.ts +78 -0
- package/dist/adapters/anthropic.d.ts.map +1 -0
- package/dist/adapters/anthropic.js +158 -0
- package/dist/adapters/anthropic.js.map +1 -0
- package/dist/adapters/index.d.ts +15 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +22 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/openai.d.ts +77 -0
- package/dist/adapters/openai.d.ts.map +1 -0
- package/dist/adapters/openai.js +154 -0
- package/dist/adapters/openai.js.map +1 -0
- package/dist/index.d.ts +57 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +86 -0
- package/dist/index.js.map +1 -0
- package/dist/register.d.ts +22 -0
- package/dist/register.d.ts.map +1 -0
- package/dist/register.js +52 -0
- package/dist/register.js.map +1 -0
- package/dist/types.d.ts +122 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/package.json +43 -0
package/README.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# paypol-sdk
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for the PayPol Agent Marketplace on Tempo L1. Build agents that earn crypto, hire agents via API, and dispatch payments.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install paypol-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Build an Agent
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { PayPolAgent } from 'paypol-sdk';
|
|
15
|
+
|
|
16
|
+
const agent = new PayPolAgent({
|
|
17
|
+
id: 'my-agent',
|
|
18
|
+
name: 'My Agent',
|
|
19
|
+
description: 'Real on-chain agent on Tempo L1',
|
|
20
|
+
category: 'analytics',
|
|
21
|
+
version: '1.0.0',
|
|
22
|
+
price: 50,
|
|
23
|
+
capabilities: ['portfolio', 'tracking'],
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
agent.onJob(async (job) => {
|
|
27
|
+
const result = await doWork(job.prompt);
|
|
28
|
+
return {
|
|
29
|
+
jobId: job.jobId,
|
|
30
|
+
agentId: 'my-agent',
|
|
31
|
+
status: 'success',
|
|
32
|
+
result: { data: result },
|
|
33
|
+
executionTimeMs: Date.now() - job.timestamp,
|
|
34
|
+
timestamp: Date.now(),
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
agent.listen(3020);
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Hire an Agent
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
import { AgentClient } from 'paypol-sdk';
|
|
45
|
+
|
|
46
|
+
const client = new AgentClient('https://api.paypol.xyz');
|
|
47
|
+
const result = await client.hire('contract-auditor', 'Audit this Solidity file...', '0xYourWallet');
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Adapters
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
// OpenAI function-calling
|
|
54
|
+
import { getOpenAITools } from 'paypol-sdk/openai';
|
|
55
|
+
|
|
56
|
+
// Anthropic tool-use
|
|
57
|
+
import { getAnthropicTools } from 'paypol-sdk/anthropic';
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Links
|
|
61
|
+
|
|
62
|
+
- [Documentation](https://paypol.xyz/docs/documentation)
|
|
63
|
+
- [GitHub](https://github.com/PayPol-Foundation/paypol-protocol)
|
|
64
|
+
- [Agent Template](https://github.com/PayPol-Foundation/paypol-protocol/tree/main/templates/agent-template)
|
|
65
|
+
|
|
66
|
+
## License
|
|
67
|
+
|
|
68
|
+
MIT
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { AgentManifest, JobResult, HireOptions, EscrowParams, ReputationScore } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Client for discovering and hiring agents from the PayPol marketplace.
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
* const client = new AgentClient('http://localhost:3001');
|
|
7
|
+
* const agents = await client.listAgents();
|
|
8
|
+
* const result = await client.hire('contract-auditor', 'Audit this contract...', '0x...');
|
|
9
|
+
*
|
|
10
|
+
* APS-1 integration:
|
|
11
|
+
* const rep = await client.getReputation('contract-auditor');
|
|
12
|
+
* const filtered = await client.searchAgents({ category: 'security', maxPrice: 10 });
|
|
13
|
+
*/
|
|
14
|
+
export declare class AgentClient {
|
|
15
|
+
private readonly baseUrl;
|
|
16
|
+
constructor(baseUrl: string);
|
|
17
|
+
/** List all active agents in the marketplace. */
|
|
18
|
+
listAgents(): Promise<AgentManifest[]>;
|
|
19
|
+
/** Get a single agent's manifest by ID. */
|
|
20
|
+
getAgent(agentId: string): Promise<AgentManifest>;
|
|
21
|
+
/**
|
|
22
|
+
* Search agents by category, price, or capability.
|
|
23
|
+
* Filters are applied client-side on the full agent list.
|
|
24
|
+
*/
|
|
25
|
+
searchAgents(query: {
|
|
26
|
+
category?: string;
|
|
27
|
+
maxPrice?: number;
|
|
28
|
+
capability?: string;
|
|
29
|
+
}): Promise<AgentManifest[]>;
|
|
30
|
+
/**
|
|
31
|
+
* Hire an agent to execute a job.
|
|
32
|
+
* @param agentId Target agent ID
|
|
33
|
+
* @param prompt Natural-language instruction
|
|
34
|
+
* @param callerWallet Wallet address of the client
|
|
35
|
+
* @param options Optional jobId, payload, callbackUrl
|
|
36
|
+
*/
|
|
37
|
+
hire(agentId: string, prompt: string, callerWallet: string, options?: HireOptions): Promise<JobResult>;
|
|
38
|
+
/**
|
|
39
|
+
* Hire an agent with escrow protection (APS-1 flow).
|
|
40
|
+
* Creates an on-chain escrow before execution, then settles after.
|
|
41
|
+
*
|
|
42
|
+
* @param agentId Target agent ID
|
|
43
|
+
* @param prompt Natural-language instruction
|
|
44
|
+
* @param callerWallet Wallet address of the client
|
|
45
|
+
* @param escrow Escrow parameters (method, token, amount)
|
|
46
|
+
*/
|
|
47
|
+
hireWithEscrow(agentId: string, prompt: string, callerWallet: string, escrow: EscrowParams): Promise<JobResult>;
|
|
48
|
+
/**
|
|
49
|
+
* Get the on-chain reputation score for an agent.
|
|
50
|
+
* Reads from the ReputationRegistry contract via the marketplace API.
|
|
51
|
+
*/
|
|
52
|
+
getReputation(agentIdOrWallet: string): Promise<ReputationScore>;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=AgentClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentClient.d.ts","sourceRoot":"","sources":["../src/AgentClient.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAc,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE3G;;;;;;;;;;;GAWG;AACH,qBAAa,WAAW;IACV,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAAP,OAAO,EAAE,MAAM;IAI5C,iDAAiD;IAC3C,UAAU,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;IAK5C,2CAA2C;IACrC,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAKvD;;;OAGG;IACG,YAAY,CAAC,KAAK,EAAE;QACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAY5B;;;;;;OAMG;IACG,IAAI,CACR,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,MAAM,EACpB,OAAO,GAAE,WAAgB,GACxB,OAAO,CAAC,SAAS,CAAC;IAkBrB;;;;;;;;OAQG;IACG,cAAc,CAClB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,YAAY,GACnB,OAAO,CAAC,SAAS,CAAC;IAwBrB;;;OAGG;IACG,aAAa,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;CAOvE"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.AgentClient = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const crypto_1 = require("crypto");
|
|
9
|
+
/**
|
|
10
|
+
* Client for discovering and hiring agents from the PayPol marketplace.
|
|
11
|
+
*
|
|
12
|
+
* Usage:
|
|
13
|
+
* const client = new AgentClient('http://localhost:3001');
|
|
14
|
+
* const agents = await client.listAgents();
|
|
15
|
+
* const result = await client.hire('contract-auditor', 'Audit this contract...', '0x...');
|
|
16
|
+
*
|
|
17
|
+
* APS-1 integration:
|
|
18
|
+
* const rep = await client.getReputation('contract-auditor');
|
|
19
|
+
* const filtered = await client.searchAgents({ category: 'security', maxPrice: 10 });
|
|
20
|
+
*/
|
|
21
|
+
class AgentClient {
|
|
22
|
+
constructor(baseUrl) {
|
|
23
|
+
this.baseUrl = baseUrl;
|
|
24
|
+
}
|
|
25
|
+
// ── Discovery ──────────────────────────────────────────
|
|
26
|
+
/** List all active agents in the marketplace. */
|
|
27
|
+
async listAgents() {
|
|
28
|
+
const { data } = await axios_1.default.get(`${this.baseUrl}/agents`);
|
|
29
|
+
return data;
|
|
30
|
+
}
|
|
31
|
+
/** Get a single agent's manifest by ID. */
|
|
32
|
+
async getAgent(agentId) {
|
|
33
|
+
const { data } = await axios_1.default.get(`${this.baseUrl}/agents/${agentId}`);
|
|
34
|
+
return data;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Search agents by category, price, or capability.
|
|
38
|
+
* Filters are applied client-side on the full agent list.
|
|
39
|
+
*/
|
|
40
|
+
async searchAgents(query) {
|
|
41
|
+
const all = await this.listAgents();
|
|
42
|
+
return all.filter(a => {
|
|
43
|
+
if (query.category && a.category !== query.category)
|
|
44
|
+
return false;
|
|
45
|
+
if (query.maxPrice && a.price > query.maxPrice)
|
|
46
|
+
return false;
|
|
47
|
+
if (query.capability && !a.capabilities.includes(query.capability))
|
|
48
|
+
return false;
|
|
49
|
+
return true;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
// ── Hiring ─────────────────────────────────────────────
|
|
53
|
+
/**
|
|
54
|
+
* Hire an agent to execute a job.
|
|
55
|
+
* @param agentId Target agent ID
|
|
56
|
+
* @param prompt Natural-language instruction
|
|
57
|
+
* @param callerWallet Wallet address of the client
|
|
58
|
+
* @param options Optional jobId, payload, callbackUrl
|
|
59
|
+
*/
|
|
60
|
+
async hire(agentId, prompt, callerWallet, options = {}) {
|
|
61
|
+
const job = {
|
|
62
|
+
jobId: options.jobId ?? (0, crypto_1.randomUUID)(),
|
|
63
|
+
agentId,
|
|
64
|
+
prompt,
|
|
65
|
+
payload: options.payload,
|
|
66
|
+
callerWallet,
|
|
67
|
+
timestamp: Date.now(),
|
|
68
|
+
callbackUrl: options.callbackUrl,
|
|
69
|
+
};
|
|
70
|
+
const { data } = await axios_1.default.post(`${this.baseUrl}/agents/${agentId}/execute`, job);
|
|
71
|
+
return data;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Hire an agent with escrow protection (APS-1 flow).
|
|
75
|
+
* Creates an on-chain escrow before execution, then settles after.
|
|
76
|
+
*
|
|
77
|
+
* @param agentId Target agent ID
|
|
78
|
+
* @param prompt Natural-language instruction
|
|
79
|
+
* @param callerWallet Wallet address of the client
|
|
80
|
+
* @param escrow Escrow parameters (method, token, amount)
|
|
81
|
+
*/
|
|
82
|
+
async hireWithEscrow(agentId, prompt, callerWallet, escrow) {
|
|
83
|
+
const jobId = (0, crypto_1.randomUUID)();
|
|
84
|
+
const { data } = await axios_1.default.post(`${this.baseUrl}/agents/${agentId}/execute`, {
|
|
85
|
+
jobId,
|
|
86
|
+
agentId,
|
|
87
|
+
prompt,
|
|
88
|
+
callerWallet,
|
|
89
|
+
timestamp: Date.now(),
|
|
90
|
+
escrow: {
|
|
91
|
+
method: escrow.method,
|
|
92
|
+
token: escrow.token,
|
|
93
|
+
amount: escrow.amount,
|
|
94
|
+
deadlineSeconds: escrow.deadlineSeconds ?? 86400,
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
return data;
|
|
98
|
+
}
|
|
99
|
+
// ── Reputation ─────────────────────────────────────────
|
|
100
|
+
/**
|
|
101
|
+
* Get the on-chain reputation score for an agent.
|
|
102
|
+
* Reads from the ReputationRegistry contract via the marketplace API.
|
|
103
|
+
*/
|
|
104
|
+
async getReputation(agentIdOrWallet) {
|
|
105
|
+
const { data } = await axios_1.default.get(`${this.baseUrl}/api/reputation`, { params: { wallet: agentIdOrWallet } });
|
|
106
|
+
return data;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
exports.AgentClient = AgentClient;
|
|
110
|
+
//# sourceMappingURL=AgentClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentClient.js","sourceRoot":"","sources":["../src/AgentClient.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,mCAAoC;AAGpC;;;;;;;;;;;GAWG;AACH,MAAa,WAAW;IACtB,YAA6B,OAAe;QAAf,YAAO,GAAP,OAAO,CAAQ;IAAG,CAAC;IAEhD,0DAA0D;IAE1D,iDAAiD;IACj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C,GAAG,EAAE;YACxB,WAAW,EAAG,OAAO,CAAC,WAAW;SAClC,CAAC;QAEF,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,eAAK,CAAC,IAAI,CAC/B,GAAG,IAAI,CAAC,OAAO,WAAW,OAAO,UAAU,EAC3C,GAAG,CACJ,CAAC;QACF,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,cAAc,CAClB,OAAe,EACf,MAAc,EACd,YAAoB,EACpB,MAAoB;QAEpB,MAAM,KAAK,GAAG,IAAA,mBAAU,GAAE,CAAC;QAE3B,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,eAAK,CAAC,IAAI,CAC/B,GAAG,IAAI,CAAC,OAAO,WAAW,OAAO,UAAU,EAC3C;YACE,KAAK;YACL,OAAO;YACP,MAAM;YACN,YAAY;YACZ,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;YACrB,MAAM,EAAE;gBACN,MAAM,EAAE,MAAM,CAAC,MAAM;gBACrB,KAAK,EAAE,MAAM,CAAC,KAAK;gBACnB,MAAM,EAAE,MAAM,CAAC,MAAM;gBACrB,eAAe,EAAE,MAAM,CAAC,eAAe,IAAI,KAAK;aACjD;SACF,CACF,CAAC;QACF,OAAO,IAAI,CAAC;IACd,CAAC;IAED,0DAA0D;IAE1D;;;OAGG;IACH,KAAK,CAAC,aAAa,CAAC,eAAuB;QACzC,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,eAAK,CAAC,GAAG,CAC9B,GAAG,IAAI,CAAC,OAAO,iBAAiB,EAChC,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,eAAe,EAAE,EAAE,CACxC,CAAC;QACF,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AApHD,kCAoHC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { AgentConfig, AgentManifest, JobRequest, JobResult, AgentRegistrationResponse } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Base class for building PayPol-compatible agents.
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
* const agent = new PayPolAgent({ id: 'my-agent', ... });
|
|
7
|
+
* agent.onJob(async (job) => { ... return result; });
|
|
8
|
+
* agent.listen(3002);
|
|
9
|
+
*/
|
|
10
|
+
export declare class PayPolAgent {
|
|
11
|
+
private config;
|
|
12
|
+
private jobHandler?;
|
|
13
|
+
private app;
|
|
14
|
+
constructor(config: AgentConfig);
|
|
15
|
+
/**
|
|
16
|
+
* Register the async handler called for every incoming job.
|
|
17
|
+
* Throw an Error inside to return status: 'error' automatically.
|
|
18
|
+
*/
|
|
19
|
+
onJob(handler: (job: JobRequest) => Promise<JobResult>): this;
|
|
20
|
+
/** Start the HTTP server. */
|
|
21
|
+
listen(port: number, cb?: () => void): void;
|
|
22
|
+
/** Serialise the agent descriptor (used for marketplace registration). */
|
|
23
|
+
toManifest(): AgentManifest;
|
|
24
|
+
/**
|
|
25
|
+
* Self-register this agent on the PayPol marketplace.
|
|
26
|
+
* Calls /api/marketplace/register with the agent's manifest + webhook URL.
|
|
27
|
+
*
|
|
28
|
+
* @param webhookUrl Publicly reachable base URL of this agent's server
|
|
29
|
+
* @param ownerWallet Wallet address that receives payment
|
|
30
|
+
* @param options Optional: githubHandle, avatarEmoji, marketplaceUrl
|
|
31
|
+
*/
|
|
32
|
+
register(webhookUrl: string, ownerWallet: string, options?: {
|
|
33
|
+
githubHandle?: string;
|
|
34
|
+
avatarEmoji?: string;
|
|
35
|
+
marketplaceUrl?: string;
|
|
36
|
+
}): Promise<AgentRegistrationResponse>;
|
|
37
|
+
private _registerRoutes;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=PayPolAgent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PayPolAgent.d.ts","sourceRoot":"","sources":["../src/PayPolAgent.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,WAAW,EACX,aAAa,EACb,UAAU,EACV,SAAS,EAET,yBAAyB,EAC1B,MAAM,SAAS,CAAC;AAGjB;;;;;;;GAOG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,UAAU,CAAC,CAA0C;IAC7D,OAAO,CAAC,GAAG,CAAa;gBAEZ,MAAM,EAAE,WAAW;IAQ/B;;;OAGG;IACH,KAAK,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,UAAU,KAAK,OAAO,CAAC,SAAS,CAAC,GAAG,IAAI;IAK7D,6BAA6B;IAC7B,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,IAAI,GAAG,IAAI;IAO3C,0EAA0E;IAC1E,UAAU,IAAI,aAAa;IAc3B;;;;;;;OAOG;IACG,QAAQ,CACZ,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,MAAM,EACnB,OAAO,CAAC,EAAE;QACR,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,cAAc,CAAC,EAAE,MAAM,CAAC;KACzB,GACA,OAAO,CAAC,yBAAyB,CAAC;IAqBrC,OAAO,CAAC,eAAe;CA6CxB"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.PayPolAgent = void 0;
|
|
7
|
+
const express_1 = __importDefault(require("express"));
|
|
8
|
+
const crypto_1 = require("crypto");
|
|
9
|
+
const register_1 = require("./register");
|
|
10
|
+
/**
|
|
11
|
+
* Base class for building PayPol-compatible agents.
|
|
12
|
+
*
|
|
13
|
+
* Usage:
|
|
14
|
+
* const agent = new PayPolAgent({ id: 'my-agent', ... });
|
|
15
|
+
* agent.onJob(async (job) => { ... return result; });
|
|
16
|
+
* agent.listen(3002);
|
|
17
|
+
*/
|
|
18
|
+
class PayPolAgent {
|
|
19
|
+
constructor(config) {
|
|
20
|
+
this.app = (0, express_1.default)();
|
|
21
|
+
this.config = config;
|
|
22
|
+
this.app.use(express_1.default.json());
|
|
23
|
+
this._registerRoutes();
|
|
24
|
+
}
|
|
25
|
+
// ── Public API ─────────────────────────────────────────
|
|
26
|
+
/**
|
|
27
|
+
* Register the async handler called for every incoming job.
|
|
28
|
+
* Throw an Error inside to return status: 'error' automatically.
|
|
29
|
+
*/
|
|
30
|
+
onJob(handler) {
|
|
31
|
+
this.jobHandler = handler;
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
/** Start the HTTP server. */
|
|
35
|
+
listen(port, cb) {
|
|
36
|
+
this.app.listen(port, () => {
|
|
37
|
+
console.log(`[${this.config.name}] Listening on port ${port}`);
|
|
38
|
+
cb?.();
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/** Serialise the agent descriptor (used for marketplace registration). */
|
|
42
|
+
toManifest() {
|
|
43
|
+
return {
|
|
44
|
+
id: this.config.id,
|
|
45
|
+
name: this.config.name,
|
|
46
|
+
description: this.config.description,
|
|
47
|
+
category: this.config.category,
|
|
48
|
+
version: this.config.version,
|
|
49
|
+
price: this.config.price,
|
|
50
|
+
capabilities: this.config.capabilities,
|
|
51
|
+
author: this.config.author ?? 'unknown',
|
|
52
|
+
createdAt: new Date().toISOString(),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Self-register this agent on the PayPol marketplace.
|
|
57
|
+
* Calls /api/marketplace/register with the agent's manifest + webhook URL.
|
|
58
|
+
*
|
|
59
|
+
* @param webhookUrl Publicly reachable base URL of this agent's server
|
|
60
|
+
* @param ownerWallet Wallet address that receives payment
|
|
61
|
+
* @param options Optional: githubHandle, avatarEmoji, marketplaceUrl
|
|
62
|
+
*/
|
|
63
|
+
async register(webhookUrl, ownerWallet, options) {
|
|
64
|
+
const payload = {
|
|
65
|
+
id: this.config.id,
|
|
66
|
+
name: this.config.name,
|
|
67
|
+
description: this.config.description,
|
|
68
|
+
category: this.config.category,
|
|
69
|
+
version: this.config.version,
|
|
70
|
+
price: this.config.price,
|
|
71
|
+
capabilities: this.config.capabilities,
|
|
72
|
+
webhookUrl,
|
|
73
|
+
ownerWallet,
|
|
74
|
+
author: this.config.author,
|
|
75
|
+
avatarEmoji: options?.avatarEmoji,
|
|
76
|
+
githubHandle: options?.githubHandle,
|
|
77
|
+
};
|
|
78
|
+
return (0, register_1.registerAgent)(payload, options?.marketplaceUrl);
|
|
79
|
+
}
|
|
80
|
+
// ── Routes ─────────────────────────────────────────────
|
|
81
|
+
_registerRoutes() {
|
|
82
|
+
/** GET /manifest - agent self-description */
|
|
83
|
+
this.app.get('/manifest', (_req, res) => {
|
|
84
|
+
res.json(this.toManifest());
|
|
85
|
+
});
|
|
86
|
+
/** POST /execute - trigger a job */
|
|
87
|
+
this.app.post('/execute', async (req, res) => {
|
|
88
|
+
if (!this.jobHandler) {
|
|
89
|
+
return res.status(501).json({ error: 'No job handler registered' });
|
|
90
|
+
}
|
|
91
|
+
const job = {
|
|
92
|
+
jobId: req.body.jobId ?? (0, crypto_1.randomUUID)(),
|
|
93
|
+
agentId: this.config.id,
|
|
94
|
+
prompt: req.body.prompt ?? '',
|
|
95
|
+
payload: req.body.payload,
|
|
96
|
+
callerWallet: req.body.callerWallet ?? '',
|
|
97
|
+
timestamp: Date.now(),
|
|
98
|
+
callbackUrl: req.body.callbackUrl,
|
|
99
|
+
};
|
|
100
|
+
const start = Date.now();
|
|
101
|
+
try {
|
|
102
|
+
const result = await this.jobHandler(job);
|
|
103
|
+
result.executionTimeMs = Date.now() - start;
|
|
104
|
+
res.json(result);
|
|
105
|
+
}
|
|
106
|
+
catch (err) {
|
|
107
|
+
const result = {
|
|
108
|
+
jobId: job.jobId,
|
|
109
|
+
agentId: this.config.id,
|
|
110
|
+
status: 'error',
|
|
111
|
+
error: err.message ?? String(err),
|
|
112
|
+
executionTimeMs: Date.now() - start,
|
|
113
|
+
timestamp: Date.now(),
|
|
114
|
+
};
|
|
115
|
+
res.status(500).json(result);
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
/** GET /health */
|
|
119
|
+
this.app.get('/health', (_req, res) => {
|
|
120
|
+
res.json({ status: 'ok', agent: this.config.id });
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
exports.PayPolAgent = PayPolAgent;
|
|
125
|
+
//# sourceMappingURL=PayPolAgent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PayPolAgent.js","sourceRoot":"","sources":["../src/PayPolAgent.ts"],"names":[],"mappings":";;;;;;AAAA,sDAAqD;AACrD,mCAAoC;AASpC,yCAA2C;AAE3C;;;;;;;GAOG;AACH,MAAa,WAAW;IAKtB,YAAY,MAAmB;QAFvB,QAAG,GAAG,IAAA,iBAAO,GAAE,CAAC;QAGtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,iBAAO,CAAC,IAAI,EAAE,CAAC,CAAC;QAC7B,IAAI,CAAC,eAAe,EAAE,CAAC;IACzB,CAAC;IAED,0DAA0D;IAE1D;;;OAGG;IACH,KAAK,CAAC,OAAgD;QACpD,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC;QAC1B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,6BAA6B;IAC7B,MAAM,CAAC,IAAY,EAAE,EAAe;QAClC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE;YACzB,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,uBAAuB,IAAI,EAAE,CAAC,CAAC;YAC/D,EAAE,EAAE,EAAE,CAAC;QACT,CAAC,CAAC,CAAC;IACL,CAAC;IAED,0EAA0E;IAC1E,UAAU;QACR,OAAO;YACL,EAAE,EAAY,I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BACzB,OAAO,EAAS,IAAI,CAAC,MAAM,CAAC,EAAE;oBAC9B,MAAM,EAAU,OAAO;oBACvB,KAAK,EAAW,GAAG,CAAC,OAAO,IAAI,MAAM,CAAC,GAAG,CAAC;oBAC1C,eAAe,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK;oBACnC,SAAS,EAAO,IAAI,CAAC,GAAG,EAAE;iBAC3B,CAAC;gBACF,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAC/B,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,kBAAkB;QAClB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,IAAa,EAAE,GAAa,EAAE,EAAE;YACvD,GAAG,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC;QACpD,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AA/HD,kCA+HC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anthropic Tool-Use Adapter for PayPol Agents
|
|
3
|
+
*
|
|
4
|
+
* Converts PayPol marketplace agents into Anthropic tool-use definitions.
|
|
5
|
+
* Works with Claude's tool-use API (Claude 3 Opus, Sonnet, Haiku, etc.)
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { AgentClient } from 'paypol-sdk';
|
|
10
|
+
* import { toAnthropicTools, handleAnthropicToolUse } from 'paypol-sdk/adapters/anthropic';
|
|
11
|
+
*
|
|
12
|
+
* const client = new AgentClient('https://paypol.xyz');
|
|
13
|
+
* const tools = await toAnthropicTools(client);
|
|
14
|
+
*
|
|
15
|
+
* const response = await anthropic.messages.create({
|
|
16
|
+
* model: 'claude-sonnet-4-20250514',
|
|
17
|
+
* max_tokens: 4096,
|
|
18
|
+
* tools,
|
|
19
|
+
* messages: [{ role: 'user', content: 'Audit this smart contract for vulnerabilities' }],
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* // Handle tool use
|
|
23
|
+
* const toolUse = response.content.find(c => c.type === 'tool_use');
|
|
24
|
+
* if (toolUse) {
|
|
25
|
+
* const result = await handleAnthropicToolUse(client, toolUse, '0xMyWallet');
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
import { AgentClient } from '../AgentClient';
|
|
30
|
+
export interface AnthropicTool {
|
|
31
|
+
name: string;
|
|
32
|
+
description: string;
|
|
33
|
+
input_schema: {
|
|
34
|
+
type: 'object';
|
|
35
|
+
properties: Record<string, {
|
|
36
|
+
type: string;
|
|
37
|
+
description: string;
|
|
38
|
+
}>;
|
|
39
|
+
required: string[];
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export interface AnthropicToolUse {
|
|
43
|
+
type: 'tool_use';
|
|
44
|
+
id: string;
|
|
45
|
+
name: string;
|
|
46
|
+
input: Record<string, unknown>;
|
|
47
|
+
}
|
|
48
|
+
export interface AnthropicToolResult {
|
|
49
|
+
type: 'tool_result';
|
|
50
|
+
tool_use_id: string;
|
|
51
|
+
content: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Convert PayPol agents to Anthropic tool-use definitions.
|
|
55
|
+
*
|
|
56
|
+
* @param client AgentClient instance (used for dynamic agent list)
|
|
57
|
+
* @param agentIds Optional filter - only include these agent IDs
|
|
58
|
+
*/
|
|
59
|
+
export declare function toAnthropicTools(client?: AgentClient, agentIds?: string[]): Promise<AnthropicTool[]>;
|
|
60
|
+
/**
|
|
61
|
+
* Handle an Anthropic tool use block by dispatching to the correct PayPol agent.
|
|
62
|
+
*
|
|
63
|
+
* @param client AgentClient instance
|
|
64
|
+
* @param toolUse The tool_use block from Claude's response
|
|
65
|
+
* @param callerWallet Wallet address of the caller
|
|
66
|
+
* @returns AnthropicToolResult ready to send back in the conversation
|
|
67
|
+
*/
|
|
68
|
+
export declare function handleAnthropicToolUse(client: AgentClient, toolUse: AnthropicToolUse, callerWallet: string): Promise<AnthropicToolResult>;
|
|
69
|
+
/**
|
|
70
|
+
* Get the static agent catalog (no API call needed).
|
|
71
|
+
*/
|
|
72
|
+
export declare function getAgentCatalog(): {
|
|
73
|
+
id: string;
|
|
74
|
+
name: string;
|
|
75
|
+
description: string;
|
|
76
|
+
category: string;
|
|
77
|
+
}[];
|
|
78
|
+
//# sourceMappingURL=anthropic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../src/adapters/anthropic.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAI7C,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE;QACZ,IAAI,EAAE,QAAQ,CAAC;QACf,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,WAAW,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;QAClE,QAAQ,EAAE,MAAM,EAAE,CAAC;KACpB,CAAC;CACH;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,UAAU,CAAC;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,aAAa,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;CACjB;AAyCD;;;;;GAKG;AACH,wBAAsB,gBAAgB,CACpC,MAAM,CAAC,EAAE,WAAW,EACpB,QAAQ,CAAC,EAAE,MAAM,EAAE,GAClB,OAAO,CAAC,aAAa,EAAE,CAAC,CAyC1B;AAED;;;;;;;GAOG;AACH,wBAAsB,sBAAsB,CAC1C,MAAM,EAAE,WAAW,EACnB,OAAO,EAAE,gBAAgB,EACzB,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,mBAAmB,CAAC,CAkC9B;AAED;;GAEG;AACH,wBAAgB,eAAe;QA5IJ,MAAM;UAAQ,MAAM;iBAAe,MAAM;cAAY,MAAM;IA8IrF"}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Anthropic Tool-Use Adapter for PayPol Agents
|
|
4
|
+
*
|
|
5
|
+
* Converts PayPol marketplace agents into Anthropic tool-use definitions.
|
|
6
|
+
* Works with Claude's tool-use API (Claude 3 Opus, Sonnet, Haiku, etc.)
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { AgentClient } from 'paypol-sdk';
|
|
11
|
+
* import { toAnthropicTools, handleAnthropicToolUse } from 'paypol-sdk/adapters/anthropic';
|
|
12
|
+
*
|
|
13
|
+
* const client = new AgentClient('https://paypol.xyz');
|
|
14
|
+
* const tools = await toAnthropicTools(client);
|
|
15
|
+
*
|
|
16
|
+
* const response = await anthropic.messages.create({
|
|
17
|
+
* model: 'claude-sonnet-4-20250514',
|
|
18
|
+
* max_tokens: 4096,
|
|
19
|
+
* tools,
|
|
20
|
+
* messages: [{ role: 'user', content: 'Audit this smart contract for vulnerabilities' }],
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* // Handle tool use
|
|
24
|
+
* const toolUse = response.content.find(c => c.type === 'tool_use');
|
|
25
|
+
* if (toolUse) {
|
|
26
|
+
* const result = await handleAnthropicToolUse(client, toolUse, '0xMyWallet');
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
+
exports.toAnthropicTools = toAnthropicTools;
|
|
32
|
+
exports.handleAnthropicToolUse = handleAnthropicToolUse;
|
|
33
|
+
exports.getAgentCatalog = getAgentCatalog;
|
|
34
|
+
// ── Agent Catalog ────────────────────────────────────────
|
|
35
|
+
const AGENT_CATALOG = [
|
|
36
|
+
{ id: 'contract-auditor', name: 'Contract Auditor', description: 'Audit Solidity smart contracts for vulnerabilities, reentrancy bugs, and security issues on Tempo L1', category: 'security' },
|
|
37
|
+
{ id: 'yield-optimizer', name: 'Yield Optimizer', description: 'Analyze and optimize DeFi yield farming strategies across protocols', category: 'defi' },
|
|
38
|
+
{ id: 'payroll-planner', name: 'Payroll Planner', description: 'Plan and execute crypto payroll distributions with tax optimization', category: 'payroll' },
|
|
39
|
+
{ id: 'gas-predictor', name: 'Gas Predictor', description: 'Predict gas costs and recommend optimal transaction timing', category: 'analytics' },
|
|
40
|
+
{ id: 'arbitrage-scanner', name: 'Arbitrage Scanner', description: 'Scan for cross-DEX arbitrage opportunities in real-time', category: 'defi' },
|
|
41
|
+
{ id: 'compliance-advisor', name: 'Compliance Advisor', description: 'Provide regulatory compliance analysis for crypto operations', category: 'compliance' },
|
|
42
|
+
{ id: 'nft-forensics', name: 'NFT Forensics', description: 'Analyze NFT provenance, wash trading, and fraud patterns', category: 'security' },
|
|
43
|
+
{ id: 'bridge-analyzer', name: 'Bridge Analyzer', description: 'Analyze cross-chain bridge security and capital efficiency', category: 'security' },
|
|
44
|
+
{ id: 'dao-advisor', name: 'DAO Advisor', description: 'Provide governance analysis, voting power assessment, and proposal recommendations', category: 'analytics' },
|
|
45
|
+
{ id: 'risk-analyzer', name: 'Risk Analyzer', description: 'Assess portfolio risk using VaR, correlation analysis, and mitigation strategies', category: 'analytics' },
|
|
46
|
+
{ id: 'crypto-tax-navigator', name: 'Crypto Tax Navigator', description: 'Navigate multi-jurisdiction crypto tax regulations and optimize reporting', category: 'compliance' },
|
|
47
|
+
{ id: 'portfolio-rebalancer', name: 'Portfolio Rebalancer', description: 'Rebalance crypto portfolio based on market conditions and risk parameters', category: 'defi' },
|
|
48
|
+
{ id: 'token-deployer', name: 'Token Deployer', description: 'Deploy ERC20 tokens with custom parameters on Tempo L1', category: 'deployment' },
|
|
49
|
+
{ id: 'airdrop-tracker', name: 'Airdrop Tracker', description: 'Track and claim eligible airdrops for a wallet address', category: 'analytics' },
|
|
50
|
+
{ id: 'mev-sentinel', name: 'MEV Sentinel', description: 'Monitor and protect against MEV extraction attacks', category: 'security' },
|
|
51
|
+
{ id: 'liquidity-manager', name: 'Liquidity Manager', description: 'Manage LP positions and optimize liquidity provisioning across DEXs', category: 'defi' },
|
|
52
|
+
{ id: 'whale-tracker', name: 'Whale Tracker', description: 'Track large wallet movements and whale accumulation patterns', category: 'analytics' },
|
|
53
|
+
{ id: 'social-radar', name: 'Social Radar', description: 'Monitor social media sentiment and trending tokens', category: 'analytics' },
|
|
54
|
+
{ id: 'omnibridge-router', name: 'OmniBridge Router', description: 'Find optimal cross-chain bridging routes by cost and speed', category: 'defi' },
|
|
55
|
+
{ id: 'nft-appraiser', name: 'NFT Appraiser', description: 'Appraise NFT value based on rarity, market data, and collection trends', category: 'analytics' },
|
|
56
|
+
{ id: 'proposal-writer', name: 'Proposal Writer', description: 'Draft governance proposals with on-chain analysis and impact assessment', category: 'analytics' },
|
|
57
|
+
{ id: 'vesting-planner', name: 'Vesting Planner', description: 'Plan and manage token vesting schedules with cliff and linear unlock', category: 'payroll' },
|
|
58
|
+
{ id: 'defi-insurance', name: 'DeFi Insurance', description: 'Analyze DeFi insurance options, coverage gaps, and premium optimization', category: 'defi' },
|
|
59
|
+
{ id: 'contract-deploy-pro', name: 'Contract Deploy Pro', description: 'Deploy and verify smart contracts on Tempo L1 with gas optimization', category: 'deployment' },
|
|
60
|
+
{ id: 'escrow-guardian', name: 'Escrow Guardian', description: 'Create and manage escrow transactions via NexusV2 smart contract', category: 'escrow' },
|
|
61
|
+
{ id: 'shield-master', name: 'Shield Master', description: 'Execute ZK-shielded private payments via ShieldVaultV2', category: 'privacy' },
|
|
62
|
+
{ id: 'multisend-pro', name: 'Multisend Pro', description: 'Batch send payments to multiple recipients via MultisendV2', category: 'payments' },
|
|
63
|
+
{ id: 'stream-architect', name: 'Stream Architect', description: 'Create and manage milestone-based payment streams via StreamV1', category: 'streams' },
|
|
64
|
+
{ id: 'proof-verifier', name: 'Proof Verifier', description: 'Verify AI execution proofs on-chain via AIProofRegistry', category: 'verification' },
|
|
65
|
+
{ id: 'agent-coordinator', name: 'Agent Coordinator', description: 'Orchestrate multi-agent A2A workflows with dependency resolution', category: 'orchestration' },
|
|
66
|
+
{ id: 'payroll-autopilot', name: 'Payroll Autopilot', description: 'Set up recurring automated payroll with conditional rules', category: 'payroll' },
|
|
67
|
+
{ id: 'admin-dashboard', name: 'Admin Dashboard', description: 'Monitor protocol health, TVL, and agent performance metrics', category: 'admin' },
|
|
68
|
+
];
|
|
69
|
+
// ── Converters ───────────────────────────────────────────
|
|
70
|
+
/**
|
|
71
|
+
* Convert PayPol agents to Anthropic tool-use definitions.
|
|
72
|
+
*
|
|
73
|
+
* @param client AgentClient instance (used for dynamic agent list)
|
|
74
|
+
* @param agentIds Optional filter - only include these agent IDs
|
|
75
|
+
*/
|
|
76
|
+
async function toAnthropicTools(client, agentIds) {
|
|
77
|
+
let agents = AGENT_CATALOG;
|
|
78
|
+
if (client) {
|
|
79
|
+
try {
|
|
80
|
+
const live = await client.listAgents();
|
|
81
|
+
if (live.length > 0) {
|
|
82
|
+
agents = live.map(a => ({
|
|
83
|
+
id: a.id,
|
|
84
|
+
name: a.name,
|
|
85
|
+
description: a.description,
|
|
86
|
+
category: a.category,
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
// Fall back to static catalog
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (agentIds) {
|
|
95
|
+
agents = agents.filter(a => agentIds.includes(a.id));
|
|
96
|
+
}
|
|
97
|
+
return agents.map(agent => ({
|
|
98
|
+
name: `paypol_${agent.id.replace(/-/g, '_')}`,
|
|
99
|
+
description: `[PayPol Agent] ${agent.name}: ${agent.description}`,
|
|
100
|
+
input_schema: {
|
|
101
|
+
type: 'object',
|
|
102
|
+
properties: {
|
|
103
|
+
prompt: {
|
|
104
|
+
type: 'string',
|
|
105
|
+
description: `Task instruction for ${agent.name}. Be specific about what you want analyzed or executed.`,
|
|
106
|
+
},
|
|
107
|
+
payload: {
|
|
108
|
+
type: 'string',
|
|
109
|
+
description: 'Optional JSON string with additional structured data (e.g. contract source code, wallet addresses, parameters)',
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
required: ['prompt'],
|
|
113
|
+
},
|
|
114
|
+
}));
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Handle an Anthropic tool use block by dispatching to the correct PayPol agent.
|
|
118
|
+
*
|
|
119
|
+
* @param client AgentClient instance
|
|
120
|
+
* @param toolUse The tool_use block from Claude's response
|
|
121
|
+
* @param callerWallet Wallet address of the caller
|
|
122
|
+
* @returns AnthropicToolResult ready to send back in the conversation
|
|
123
|
+
*/
|
|
124
|
+
async function handleAnthropicToolUse(client, toolUse, callerWallet) {
|
|
125
|
+
const agentId = toolUse.name.replace('paypol_', '').replace(/_/g, '-');
|
|
126
|
+
const input = toolUse.input;
|
|
127
|
+
if (!input.prompt) {
|
|
128
|
+
return {
|
|
129
|
+
type: 'tool_result',
|
|
130
|
+
tool_use_id: toolUse.id,
|
|
131
|
+
content: JSON.stringify({ error: 'Missing required "prompt" parameter' }),
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
try {
|
|
135
|
+
const result = await client.hire(agentId, input.prompt, callerWallet, {
|
|
136
|
+
payload: input.payload ? JSON.parse(input.payload) : undefined,
|
|
137
|
+
});
|
|
138
|
+
return {
|
|
139
|
+
type: 'tool_result',
|
|
140
|
+
tool_use_id: toolUse.id,
|
|
141
|
+
content: JSON.stringify(result),
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
catch (err) {
|
|
145
|
+
return {
|
|
146
|
+
type: 'tool_result',
|
|
147
|
+
tool_use_id: toolUse.id,
|
|
148
|
+
content: JSON.stringify({ error: err.message || 'Agent execution failed' }),
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Get the static agent catalog (no API call needed).
|
|
154
|
+
*/
|
|
155
|
+
function getAgentCatalog() {
|
|
156
|
+
return [...AGENT_CATALOG];
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=anthropic.js.map
|