@paylobster/mcp-server 1.3.1 → 1.6.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/BUILD_SUMMARY.md +294 -0
- package/CHANGELOG.md +77 -0
- package/COMPLETION_REPORT.md +284 -0
- package/INTEGRATION.md +286 -0
- package/QUICKSTART.md +226 -0
- package/README.md +232 -127
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -3
- package/dist/index.js.map +1 -1
- package/dist/lib/config.d.ts +7 -0
- package/dist/lib/config.d.ts.map +1 -0
- package/dist/lib/config.js +16 -0
- package/dist/lib/config.js.map +1 -0
- package/dist/lib/contracts.d.ts +15 -0
- package/dist/lib/contracts.d.ts.map +1 -0
- package/dist/lib/contracts.js +148 -0
- package/dist/lib/contracts.js.map +1 -0
- package/dist/lib/types.d.ts +39 -0
- package/dist/lib/types.d.ts.map +1 -0
- package/dist/{types/index.js → lib/types.js} +1 -1
- package/dist/lib/types.js.map +1 -0
- package/dist/resources/agent.d.ts +3 -0
- package/dist/resources/agent.d.ts.map +1 -0
- package/dist/resources/agent.js +36 -0
- package/dist/resources/agent.js.map +1 -0
- package/dist/resources/escrow.d.ts +3 -0
- package/dist/resources/escrow.d.ts.map +1 -0
- package/dist/resources/escrow.js +33 -0
- package/dist/resources/escrow.js.map +1 -0
- package/dist/resources/services.d.ts +2 -0
- package/dist/resources/services.d.ts.map +1 -0
- package/dist/resources/services.js +55 -0
- package/dist/resources/services.js.map +1 -0
- package/dist/server.d.ts +6 -3
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +114 -941
- package/dist/server.js.map +1 -1
- package/dist/tools/agent.d.ts +17 -0
- package/dist/tools/agent.d.ts.map +1 -0
- package/dist/tools/agent.js +51 -0
- package/dist/tools/agent.js.map +1 -0
- package/dist/tools/balance.d.ts +16 -5
- package/dist/tools/balance.d.ts.map +1 -1
- package/dist/tools/balance.js +44 -26
- package/dist/tools/balance.js.map +1 -1
- package/dist/tools/escrow.d.ts +31 -90
- package/dist/tools/escrow.d.ts.map +1 -1
- package/dist/tools/escrow.js +98 -215
- package/dist/tools/escrow.js.map +1 -1
- package/dist/tools/reputation.d.ts +15 -49
- package/dist/tools/reputation.d.ts.map +1 -1
- package/dist/tools/reputation.js +45 -107
- package/dist/tools/reputation.js.map +1 -1
- package/dist/tools/search.d.ts +30 -54
- package/dist/tools/search.d.ts.map +1 -1
- package/dist/tools/search.js +122 -85
- package/dist/tools/search.js.map +1 -1
- package/examples/test-server.ts +36 -0
- package/examples/test-tools.ts +64 -0
- package/package.json +20 -11
- package/src/__tests__/server.test.ts +24 -0
- package/src/index.ts +24 -0
- package/src/lib/config.ts +22 -0
- package/src/lib/contracts.ts +164 -0
- package/src/lib/types.ts +44 -0
- package/src/resources/agent.ts +40 -0
- package/src/resources/escrow.ts +35 -0
- package/src/resources/services.ts +53 -0
- package/src/server.ts +190 -0
- package/src/tools/agent.ts +56 -0
- package/src/tools/balance.ts +61 -0
- package/src/tools/escrow.ts +142 -0
- package/src/tools/reputation.ts +69 -0
- package/src/tools/search.ts +148 -0
- package/tsconfig.json +20 -0
- package/dist/cli.d.ts +0 -3
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js +0 -86
- package/dist/cli.js.map +0 -1
- package/dist/resources/index.d.ts +0 -9
- package/dist/resources/index.d.ts.map +0 -1
- package/dist/resources/index.js +0 -159
- package/dist/resources/index.js.map +0 -1
- package/dist/tools/bridge.d.ts +0 -142
- package/dist/tools/bridge.d.ts.map +0 -1
- package/dist/tools/bridge.js +0 -121
- package/dist/tools/bridge.js.map +0 -1
- package/dist/tools/cascade.d.ts +0 -59
- package/dist/tools/cascade.d.ts.map +0 -1
- package/dist/tools/cascade.js +0 -119
- package/dist/tools/cascade.js.map +0 -1
- package/dist/tools/compliance.d.ts +0 -36
- package/dist/tools/compliance.d.ts.map +0 -1
- package/dist/tools/compliance.js +0 -57
- package/dist/tools/compliance.js.map +0 -1
- package/dist/tools/credit.d.ts +0 -46
- package/dist/tools/credit.d.ts.map +0 -1
- package/dist/tools/credit.js +0 -102
- package/dist/tools/credit.js.map +0 -1
- package/dist/tools/disputes.d.ts +0 -71
- package/dist/tools/disputes.d.ts.map +0 -1
- package/dist/tools/disputes.js +0 -121
- package/dist/tools/disputes.js.map +0 -1
- package/dist/tools/intent.d.ts +0 -78
- package/dist/tools/intent.d.ts.map +0 -1
- package/dist/tools/intent.js +0 -192
- package/dist/tools/intent.js.map +0 -1
- package/dist/tools/portfolio.d.ts +0 -44
- package/dist/tools/portfolio.d.ts.map +0 -1
- package/dist/tools/portfolio.js +0 -166
- package/dist/tools/portfolio.js.map +0 -1
- package/dist/tools/revenue.d.ts +0 -42
- package/dist/tools/revenue.d.ts.map +0 -1
- package/dist/tools/revenue.js +0 -67
- package/dist/tools/revenue.js.map +0 -1
- package/dist/tools/streaming.d.ts +0 -60
- package/dist/tools/streaming.d.ts.map +0 -1
- package/dist/tools/streaming.js +0 -163
- package/dist/tools/streaming.js.map +0 -1
- package/dist/tools/swap.d.ts +0 -93
- package/dist/tools/swap.d.ts.map +0 -1
- package/dist/tools/swap.js +0 -150
- package/dist/tools/swap.js.map +0 -1
- package/dist/tools/treasury.d.ts +0 -267
- package/dist/tools/treasury.d.ts.map +0 -1
- package/dist/tools/treasury.js +0 -722
- package/dist/tools/treasury.js.map +0 -1
- package/dist/types/index.d.ts +0 -83
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js.map +0 -1
- package/dist/utils/contracts.d.ts +0 -552
- package/dist/utils/contracts.d.ts.map +0 -1
- package/dist/utils/contracts.js +0 -401
- package/dist/utils/contracts.js.map +0 -1
package/dist/tools/escrow.js
CHANGED
|
@@ -1,244 +1,127 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.
|
|
5
|
-
exports.
|
|
6
|
-
exports.getEscrow = getEscrow;
|
|
7
|
-
exports.listEscrows = listEscrows;
|
|
3
|
+
exports.listEscrowsTool = exports.getEscrowTool = void 0;
|
|
4
|
+
exports.handleGetEscrow = handleGetEscrow;
|
|
5
|
+
exports.handleListEscrows = handleListEscrows;
|
|
8
6
|
const zod_1 = require("zod");
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
amount: zod_1.z.string().describe('Amount in USDC'),
|
|
13
|
-
currency: zod_1.z.string().default('USDC'),
|
|
14
|
-
terms: zod_1.z.object({
|
|
15
|
-
releaseOn: zod_1.z.enum(['delivery-confirmed', 'timeout', 'manual']).default('delivery-confirmed'),
|
|
16
|
-
timeout: zod_1.z.string().optional().describe('ISO 8601 duration (e.g., P1D for 1 day)'),
|
|
17
|
-
disputeWindow: zod_1.z.string().optional().describe('ISO 8601 duration'),
|
|
18
|
-
}).optional(),
|
|
19
|
-
metadata: zod_1.z.record(zod_1.z.any()).optional(),
|
|
7
|
+
const viem_1 = require("viem");
|
|
8
|
+
const GetEscrowInput = zod_1.z.object({
|
|
9
|
+
escrowId: zod_1.z.string().regex(/^\d+$/, 'Escrow ID must be a number'),
|
|
20
10
|
});
|
|
21
|
-
|
|
22
|
-
|
|
11
|
+
const ListEscrowsInput = zod_1.z.object({
|
|
12
|
+
address: zod_1.z.string().regex(/^0x[a-fA-F0-9]{40}$/, 'Invalid Ethereum address'),
|
|
23
13
|
});
|
|
24
|
-
exports.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
await publicClient.waitForTransactionReceipt({ hash: approveHash });
|
|
55
|
-
// Step 2: Create escrow
|
|
56
|
-
const description = JSON.stringify(params.metadata || {});
|
|
57
|
-
const hash = await walletClient.writeContract({
|
|
58
|
-
address: contracts.escrow,
|
|
59
|
-
abi: contracts_1.ESCROW_ABI,
|
|
60
|
-
functionName: 'createEscrow',
|
|
61
|
-
args: [params.to, amountBigInt, contracts.usdc, description],
|
|
62
|
-
account,
|
|
63
|
-
});
|
|
64
|
-
// Wait for transaction confirmation
|
|
65
|
-
const receipt = await publicClient.waitForTransactionReceipt({ hash });
|
|
66
|
-
// Parse escrow ID from event logs
|
|
67
|
-
let escrowId = '0';
|
|
68
|
-
if (receipt.logs && receipt.logs.length > 0) {
|
|
69
|
-
// Look for EscrowCreated event - escrowId is first indexed parameter
|
|
70
|
-
const escrowCreatedLog = receipt.logs.find((log) => log.topics && log.topics.length > 1);
|
|
71
|
-
if (escrowCreatedLog && escrowCreatedLog.topics) {
|
|
72
|
-
escrowId = BigInt(escrowCreatedLog.topics[1]).toString();
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return {
|
|
76
|
-
escrowId,
|
|
77
|
-
transactionHash: hash,
|
|
78
|
-
amount: params.amount,
|
|
79
|
-
currency: params.currency,
|
|
80
|
-
releaseAt: Date.now() + timeoutMs,
|
|
81
|
-
status: 'active',
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
catch (error) {
|
|
85
|
-
throw new Error(`Failed to create escrow: ${error.message}`);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
async function releaseEscrow(params, client) {
|
|
89
|
-
const account = client.getAccount();
|
|
90
|
-
const walletClient = client.getWalletClient();
|
|
91
|
-
const publicClient = client.getPublicClient();
|
|
92
|
-
const contracts = client.getContracts();
|
|
14
|
+
exports.getEscrowTool = {
|
|
15
|
+
name: 'paylobster_get_escrow',
|
|
16
|
+
description: 'Get details for a specific escrow by ID',
|
|
17
|
+
inputSchema: {
|
|
18
|
+
type: 'object',
|
|
19
|
+
properties: {
|
|
20
|
+
escrowId: {
|
|
21
|
+
type: 'string',
|
|
22
|
+
description: 'Escrow ID (numeric string)',
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
required: ['escrowId'],
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
exports.listEscrowsTool = {
|
|
29
|
+
name: 'paylobster_list_escrows',
|
|
30
|
+
description: 'List all escrows for a given address',
|
|
31
|
+
inputSchema: {
|
|
32
|
+
type: 'object',
|
|
33
|
+
properties: {
|
|
34
|
+
address: {
|
|
35
|
+
type: 'string',
|
|
36
|
+
description: 'Ethereum address to list escrows for',
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
required: ['address'],
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
const ESCROW_STATUS = ['Pending', 'Active', 'Released', 'Refunded', 'Disputed'];
|
|
43
|
+
async function handleGetEscrow(input, contracts) {
|
|
93
44
|
try {
|
|
94
|
-
|
|
45
|
+
const params = GetEscrowInput.parse(input);
|
|
95
46
|
const escrowId = BigInt(params.escrowId);
|
|
96
|
-
const
|
|
97
|
-
address: contracts.escrow,
|
|
98
|
-
abi: contracts_1.ESCROW_ABI,
|
|
99
|
-
functionName: 'getEscrow',
|
|
100
|
-
args: [escrowId],
|
|
101
|
-
});
|
|
102
|
-
if (status !== 1) { // 1 = active status
|
|
103
|
-
throw new Error(`Escrow ${params.escrowId} is not active`);
|
|
104
|
-
}
|
|
105
|
-
// Release escrow
|
|
106
|
-
const hash = await walletClient.writeContract({
|
|
107
|
-
address: contracts.escrow,
|
|
108
|
-
abi: contracts_1.ESCROW_ABI,
|
|
109
|
-
functionName: 'releaseEscrow',
|
|
110
|
-
args: [escrowId],
|
|
111
|
-
account,
|
|
112
|
-
});
|
|
113
|
-
await publicClient.waitForTransactionReceipt({ hash });
|
|
114
|
-
return {
|
|
115
|
-
transactionHash: hash,
|
|
116
|
-
released: client.formatUSDC(amount),
|
|
117
|
-
recipient: recipient,
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
catch (error) {
|
|
121
|
-
throw new Error(`Failed to release escrow: ${error.message}`);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
async function getEscrow(params, client) {
|
|
125
|
-
const publicClient = client.getPublicClient();
|
|
126
|
-
const contracts = client.getContracts();
|
|
127
|
-
try {
|
|
128
|
-
const escrowId = BigInt(params.escrowId);
|
|
129
|
-
const [sender, recipient, amount, token, status] = await publicClient.readContract({
|
|
130
|
-
address: contracts.escrow,
|
|
131
|
-
abi: contracts_1.ESCROW_ABI,
|
|
132
|
-
functionName: 'getEscrow',
|
|
133
|
-
args: [escrowId],
|
|
134
|
-
});
|
|
135
|
-
// Map contract status (uint8) to string status
|
|
136
|
-
const statusMap = {
|
|
137
|
-
0: 'pending',
|
|
138
|
-
1: 'active',
|
|
139
|
-
2: 'released',
|
|
140
|
-
3: 'disputed',
|
|
141
|
-
4: 'refunded',
|
|
142
|
-
};
|
|
47
|
+
const escrow = await contracts.getEscrow(escrowId);
|
|
143
48
|
return {
|
|
144
49
|
escrowId: params.escrowId,
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
amount:
|
|
148
|
-
|
|
149
|
-
status:
|
|
150
|
-
|
|
151
|
-
releaseAt: undefined,
|
|
152
|
-
releasedAt: status === 2 ? Date.now() : undefined,
|
|
50
|
+
sender: escrow.sender,
|
|
51
|
+
recipient: escrow.recipient,
|
|
52
|
+
amount: (0, viem_1.formatUnits)(escrow.amount, 6),
|
|
53
|
+
token: escrow.token,
|
|
54
|
+
status: ESCROW_STATUS[escrow.status] || 'Unknown',
|
|
55
|
+
rawStatus: escrow.status,
|
|
153
56
|
};
|
|
154
57
|
}
|
|
155
58
|
catch (error) {
|
|
156
|
-
|
|
59
|
+
if (error instanceof zod_1.z.ZodError) {
|
|
60
|
+
throw {
|
|
61
|
+
code: 'ERR_INVALID_INPUT',
|
|
62
|
+
message: 'Invalid input parameters',
|
|
63
|
+
details: error.errors,
|
|
64
|
+
retryable: false,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
throw {
|
|
68
|
+
code: 'ERR_NETWORK_ERROR',
|
|
69
|
+
message: error instanceof Error ? error.message : 'Failed to fetch escrow',
|
|
70
|
+
retryable: true,
|
|
71
|
+
};
|
|
157
72
|
}
|
|
158
73
|
}
|
|
159
|
-
async function
|
|
160
|
-
const publicClient = client.getPublicClient();
|
|
161
|
-
const contracts = client.getContracts();
|
|
74
|
+
async function handleListEscrows(input, contracts) {
|
|
162
75
|
try {
|
|
163
|
-
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
});
|
|
172
|
-
// Parse logs into escrow data
|
|
173
|
-
let escrows = [];
|
|
174
|
-
for (const log of logs) {
|
|
175
|
-
const { escrowId, sender, recipient, amount } = log.args;
|
|
176
|
-
// Apply filters
|
|
177
|
-
if (params.creator && sender.toLowerCase() !== params.creator.toLowerCase()) {
|
|
178
|
-
continue;
|
|
179
|
-
}
|
|
180
|
-
if (params.provider && recipient.toLowerCase() !== params.provider.toLowerCase()) {
|
|
181
|
-
continue;
|
|
182
|
-
}
|
|
183
|
-
// Fetch full escrow details
|
|
76
|
+
const params = ListEscrowsInput.parse(input);
|
|
77
|
+
const address = params.address;
|
|
78
|
+
// Get count of escrows for this address
|
|
79
|
+
const count = await contracts.getUserTransactionCount(address);
|
|
80
|
+
// Fetch details for recent escrows (up to 10)
|
|
81
|
+
const limit = Math.min(Number(count), 10);
|
|
82
|
+
const escrows = [];
|
|
83
|
+
for (let i = 0; i < limit; i++) {
|
|
184
84
|
try {
|
|
185
|
-
const
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
};
|
|
198
|
-
const escrowStatus = statusMap[status] || 'pending';
|
|
199
|
-
// Apply status filter
|
|
200
|
-
if (params.status && escrowStatus !== params.status) {
|
|
201
|
-
continue;
|
|
85
|
+
const escrowId = BigInt(i);
|
|
86
|
+
const escrow = await contracts.getEscrow(escrowId);
|
|
87
|
+
// Only include if this address is involved
|
|
88
|
+
if (escrow.sender === address || escrow.recipient === address) {
|
|
89
|
+
escrows.push({
|
|
90
|
+
escrowId: i.toString(),
|
|
91
|
+
sender: escrow.sender,
|
|
92
|
+
recipient: escrow.recipient,
|
|
93
|
+
amount: (0, viem_1.formatUnits)(escrow.amount, 6),
|
|
94
|
+
token: escrow.token,
|
|
95
|
+
status: ESCROW_STATUS[escrow.status] || 'Unknown',
|
|
96
|
+
});
|
|
202
97
|
}
|
|
203
|
-
escrows.push({
|
|
204
|
-
escrowId: escrowId.toString(),
|
|
205
|
-
from: sender,
|
|
206
|
-
to: recipient,
|
|
207
|
-
amount: client.formatUSDC(amountFull),
|
|
208
|
-
currency: 'USDC',
|
|
209
|
-
status: escrowStatus,
|
|
210
|
-
createdAt: Date.now(), // Would parse from block timestamp
|
|
211
|
-
});
|
|
212
98
|
}
|
|
213
|
-
catch (
|
|
214
|
-
// Skip escrows that
|
|
99
|
+
catch (err) {
|
|
100
|
+
// Skip escrows that don't exist or can't be read
|
|
215
101
|
continue;
|
|
216
102
|
}
|
|
217
103
|
}
|
|
218
|
-
// Sort by creation (most recent first) and limit
|
|
219
|
-
escrows = escrows.slice(0, params.limit);
|
|
220
104
|
return {
|
|
105
|
+
address,
|
|
106
|
+
totalCount: count.toString(),
|
|
221
107
|
escrows,
|
|
222
|
-
|
|
108
|
+
note: escrows.length < Number(count) ? 'Showing most recent 10 escrows' : undefined,
|
|
223
109
|
};
|
|
224
110
|
}
|
|
225
111
|
catch (error) {
|
|
226
|
-
|
|
112
|
+
if (error instanceof zod_1.z.ZodError) {
|
|
113
|
+
throw {
|
|
114
|
+
code: 'ERR_INVALID_INPUT',
|
|
115
|
+
message: 'Invalid input parameters',
|
|
116
|
+
details: error.errors,
|
|
117
|
+
retryable: false,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
throw {
|
|
121
|
+
code: 'ERR_NETWORK_ERROR',
|
|
122
|
+
message: error instanceof Error ? error.message : 'Failed to list escrows',
|
|
123
|
+
retryable: true,
|
|
124
|
+
};
|
|
227
125
|
}
|
|
228
126
|
}
|
|
229
|
-
// Helper function to parse ISO 8601 duration
|
|
230
|
-
function parseDuration(duration) {
|
|
231
|
-
// Simple parser for P{n}D (days), P{n}H (hours), P{n}M (minutes)
|
|
232
|
-
const days = duration.match(/P(\d+)D/);
|
|
233
|
-
const hours = duration.match(/PT?(\d+)H/);
|
|
234
|
-
const minutes = duration.match(/PT?(\d+)M/);
|
|
235
|
-
let ms = 0;
|
|
236
|
-
if (days)
|
|
237
|
-
ms += parseInt(days[1]) * 24 * 60 * 60 * 1000;
|
|
238
|
-
if (hours)
|
|
239
|
-
ms += parseInt(hours[1]) * 60 * 60 * 1000;
|
|
240
|
-
if (minutes)
|
|
241
|
-
ms += parseInt(minutes[1]) * 60 * 1000;
|
|
242
|
-
return ms || 7 * 24 * 60 * 60 * 1000; // Default 7 days
|
|
243
|
-
}
|
|
244
127
|
//# sourceMappingURL=escrow.js.map
|
package/dist/tools/escrow.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"escrow.js","sourceRoot":"","sources":["../../src/tools/escrow.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"escrow.js","sourceRoot":"","sources":["../../src/tools/escrow.ts"],"names":[],"mappings":";;;AA6CA,0CAmCC;AAED,8CA2DC;AA7ID,6BAAwB;AAExB,+BAAmC;AAGnC,MAAM,cAAc,GAAG,OAAC,CAAC,MAAM,CAAC;IAC9B,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,4BAA4B,CAAC;CAClE,CAAC,CAAC;AAEH,MAA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AS,EAAE,IAAI;SAChB,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -1,51 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { ReputationData } from '../types';
|
|
4
|
-
export declare const getReputationSchema: z.ZodObject<{
|
|
5
|
-
address: z.ZodString;
|
|
6
|
-
}, "strip", z.ZodTypeAny, {
|
|
7
|
-
address: string;
|
|
8
|
-
}, {
|
|
9
|
-
address: string;
|
|
10
|
-
}>;
|
|
11
|
-
export declare const registerAgentSchema: z.ZodObject<{
|
|
12
|
-
name: z.ZodString;
|
|
13
|
-
metadata: z.ZodOptional<z.ZodObject<{
|
|
14
|
-
description: z.ZodOptional<z.ZodString>;
|
|
15
|
-
website: z.ZodOptional<z.ZodString>;
|
|
16
|
-
contact: z.ZodOptional<z.ZodString>;
|
|
17
|
-
}, "strip", z.ZodTypeAny, {
|
|
18
|
-
description?: string | undefined;
|
|
19
|
-
website?: string | undefined;
|
|
20
|
-
contact?: string | undefined;
|
|
21
|
-
}, {
|
|
22
|
-
description?: string | undefined;
|
|
23
|
-
website?: string | undefined;
|
|
24
|
-
contact?: string | undefined;
|
|
25
|
-
}>>;
|
|
26
|
-
stake: z.ZodString;
|
|
27
|
-
}, "strip", z.ZodTypeAny, {
|
|
1
|
+
import type { ContractsClient } from '../lib/contracts.js';
|
|
2
|
+
export declare const getReputationTool: {
|
|
28
3
|
name: string;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
} | undefined;
|
|
43
|
-
}>;
|
|
44
|
-
export declare function getReputation(params: z.infer<typeof getReputationSchema>, client: ContractClient): Promise<ReputationData>;
|
|
45
|
-
export declare function registerAgent(params: z.infer<typeof registerAgentSchema>, client: ContractClient): Promise<{
|
|
46
|
-
address: string;
|
|
47
|
-
transactionHash: string;
|
|
48
|
-
blockNumber: number;
|
|
49
|
-
identityId: string;
|
|
50
|
-
}>;
|
|
4
|
+
description: string;
|
|
5
|
+
inputSchema: {
|
|
6
|
+
type: string;
|
|
7
|
+
properties: {
|
|
8
|
+
address: {
|
|
9
|
+
type: string;
|
|
10
|
+
description: string;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
required: string[];
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export declare function handleGetReputation(input: unknown, contracts: ContractsClient): Promise<object>;
|
|
51
17
|
//# sourceMappingURL=reputation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reputation.d.ts","sourceRoot":"","sources":["../../src/tools/reputation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"reputation.d.ts","sourceRoot":"","sources":["../../src/tools/reputation.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAM3D,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;CAa7B,CAAC;AAEF,wBAAsB,mBAAmB,CACvC,KAAK,EAAE,OAAO,EACd,SAAS,EAAE,eAAe,GACzB,OAAO,CAAC,MAAM,CAAC,CA0CjB"}
|
package/dist/tools/reputation.js
CHANGED
|
@@ -1,125 +1,63 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.
|
|
5
|
-
exports.registerAgent = registerAgent;
|
|
3
|
+
exports.getReputationTool = void 0;
|
|
4
|
+
exports.handleGetReputation = handleGetReputation;
|
|
6
5
|
const zod_1 = require("zod");
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
address: zod_1.z.string().describe('Ethereum address'),
|
|
6
|
+
const GetReputationInput = zod_1.z.object({
|
|
7
|
+
address: zod_1.z.string().regex(/^0x[a-fA-F0-9]{40}$/, 'Invalid Ethereum address'),
|
|
10
8
|
});
|
|
11
|
-
exports.
|
|
12
|
-
name:
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
9
|
+
exports.getReputationTool = {
|
|
10
|
+
name: 'paylobster_get_reputation',
|
|
11
|
+
description: 'Get reputation score and trust metrics for any agent address on PayLobster',
|
|
12
|
+
inputSchema: {
|
|
13
|
+
type: 'object',
|
|
14
|
+
properties: {
|
|
15
|
+
address: {
|
|
16
|
+
type: 'string',
|
|
17
|
+
description: 'Ethereum address of the agent',
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
required: ['address'],
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
async function handleGetReputation(input, contracts) {
|
|
21
24
|
try {
|
|
22
|
-
const
|
|
23
|
-
const contracts = client.getContracts();
|
|
25
|
+
const params = GetReputationInput.parse(input);
|
|
24
26
|
const address = params.address;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
});
|
|
32
|
-
// Get reputation score and trust vector
|
|
33
|
-
const [reputationScore, trustVector] = await publicClient.readContract({
|
|
34
|
-
address: contracts.reputation,
|
|
35
|
-
abi: contracts_1.REPUTATION_ABI,
|
|
36
|
-
functionName: 'getReputation',
|
|
37
|
-
args: [address],
|
|
38
|
-
});
|
|
39
|
-
// Convert on-chain score (0-100) to 0-5 rating
|
|
40
|
-
const score = Number(reputationScore) / 20;
|
|
41
|
-
// Note: Additional metrics like totalJobs, completedJobs would come from event indexing
|
|
42
|
-
// For now, derive basic stats from what we have
|
|
27
|
+
const [reputation, agentInfo] = await Promise.all([
|
|
28
|
+
contracts.getReputation(address),
|
|
29
|
+
contracts.getAgentInfo(address),
|
|
30
|
+
]);
|
|
31
|
+
// Convert score (0-5000) to 0-5 scale
|
|
32
|
+
const normalizedScore = Number(reputation.score) / 1000;
|
|
43
33
|
return {
|
|
44
34
|
address,
|
|
45
35
|
reputation: {
|
|
46
|
-
score,
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
disputeRate: 5 - (score * 0.8), // Inverse relationship with score
|
|
50
|
-
verified: registered,
|
|
36
|
+
score: normalizedScore,
|
|
37
|
+
trustVector: reputation.trustVector.toString(),
|
|
38
|
+
verified: agentInfo.registered,
|
|
51
39
|
},
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
onChainData: {
|
|
57
|
-
registeredSince: registered ? Date.now() - 365 * 86400000 : 0, // Would come from registration event
|
|
58
|
-
totalVolume: '0.00', // Would come from escrow event aggregation
|
|
59
|
-
activeServices: 0, // Would come from service registration events
|
|
40
|
+
agentInfo: {
|
|
41
|
+
name: agentInfo.name || 'Unknown',
|
|
42
|
+
tokenId: agentInfo.tokenId.toString(),
|
|
43
|
+
registered: agentInfo.registered,
|
|
60
44
|
},
|
|
61
45
|
};
|
|
62
46
|
}
|
|
63
47
|
catch (error) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
badges: [],
|
|
77
|
-
},
|
|
78
|
-
onChainData: {
|
|
79
|
-
registeredSince: 0,
|
|
80
|
-
totalVolume: '0.00',
|
|
81
|
-
activeServices: 0,
|
|
82
|
-
},
|
|
48
|
+
if (error instanceof zod_1.z.ZodError) {
|
|
49
|
+
throw {
|
|
50
|
+
code: 'ERR_INVALID_INPUT',
|
|
51
|
+
message: 'Invalid input parameters',
|
|
52
|
+
details: error.errors,
|
|
53
|
+
retryable: false,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
throw {
|
|
57
|
+
code: 'ERR_NETWORK_ERROR',
|
|
58
|
+
message: error instanceof Error ? error.message : 'Failed to fetch reputation',
|
|
59
|
+
retryable: true,
|
|
83
60
|
};
|
|
84
61
|
}
|
|
85
62
|
}
|
|
86
|
-
async function registerAgent(params, client) {
|
|
87
|
-
const account = client.getAccount();
|
|
88
|
-
const walletClient = client.getWalletClient();
|
|
89
|
-
const publicClient = client.getPublicClient();
|
|
90
|
-
const contracts = client.getContracts();
|
|
91
|
-
// Validate stake amount
|
|
92
|
-
const stakeAmount = parseFloat(params.stake);
|
|
93
|
-
if (stakeAmount < 100) {
|
|
94
|
-
throw new Error('Minimum stake is 100 USDC');
|
|
95
|
-
}
|
|
96
|
-
try {
|
|
97
|
-
// Prepare agent URI and capabilities JSON
|
|
98
|
-
const agentURI = params.metadata?.website || '';
|
|
99
|
-
const capabilities = JSON.stringify({
|
|
100
|
-
name: params.name,
|
|
101
|
-
description: params.metadata?.description || '',
|
|
102
|
-
contact: params.metadata?.contact || '',
|
|
103
|
-
});
|
|
104
|
-
// Call identity contract register()
|
|
105
|
-
const hash = await walletClient.writeContract({
|
|
106
|
-
address: contracts.identity,
|
|
107
|
-
abi: contracts_1.IDENTITY_ABI,
|
|
108
|
-
functionName: 'register',
|
|
109
|
-
args: [agentURI, params.name, capabilities],
|
|
110
|
-
account,
|
|
111
|
-
});
|
|
112
|
-
// Wait for transaction confirmation
|
|
113
|
-
const receipt = await publicClient.waitForTransactionReceipt({ hash });
|
|
114
|
-
return {
|
|
115
|
-
address: account.address,
|
|
116
|
-
transactionHash: hash,
|
|
117
|
-
blockNumber: Number(receipt.blockNumber),
|
|
118
|
-
identityId: hash, // In production, parse from event logs
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
catch (error) {
|
|
122
|
-
throw new Error(`Failed to register agent: ${error.message}`);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
63
|
//# sourceMappingURL=reputation.js.map
|