@t402/a2a 2.4.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 +182 -0
- package/dist/cjs/client.cjs +147 -0
- package/dist/cjs/client.d.cts +102 -0
- package/dist/cjs/index.cjs +388 -0
- package/dist/cjs/index.d.cts +4 -0
- package/dist/cjs/server.cjs +239 -0
- package/dist/cjs/server.d.cts +177 -0
- package/dist/esm/chunk-6TJQKXTN.mjs +219 -0
- package/dist/esm/chunk-IPWV3JOP.mjs +127 -0
- package/dist/esm/client.d.ts +102 -0
- package/dist/esm/client.mjs +6 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.mjs +38 -0
- package/dist/esm/server.d.ts +177 -0
- package/dist/esm/server.mjs +6 -0
- package/package.json +86 -0
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { PaymentPayload, PaymentRequired, SettleResponse, A2AMessage, A2ATaskStatus, A2ATask } from '@t402/core/types';
|
|
2
|
+
import { FacilitatorClient } from '@t402/core/server';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A2A Payment Server
|
|
6
|
+
*
|
|
7
|
+
* Handles server-side payment processing for A2A agent endpoints,
|
|
8
|
+
* including generating payment requirements and processing payment submissions.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Result of payment processing
|
|
13
|
+
*/
|
|
14
|
+
interface A2APaymentResult {
|
|
15
|
+
/** Whether payment was successful */
|
|
16
|
+
success: boolean;
|
|
17
|
+
/** Settlement receipts (if settled) */
|
|
18
|
+
receipts?: SettleResponse[];
|
|
19
|
+
/** Error message (if failed) */
|
|
20
|
+
error?: string;
|
|
21
|
+
/** A2A message to include in response */
|
|
22
|
+
message: A2AMessage;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Payment handler function type
|
|
26
|
+
*/
|
|
27
|
+
type A2APaymentHandler = (payload: PaymentPayload, requirements: PaymentRequired) => Promise<A2APaymentResult>;
|
|
28
|
+
/**
|
|
29
|
+
* Options for A2APaymentServer
|
|
30
|
+
*/
|
|
31
|
+
interface A2APaymentServerOptions {
|
|
32
|
+
/**
|
|
33
|
+
* Facilitator client for verification and settlement
|
|
34
|
+
*/
|
|
35
|
+
facilitator?: FacilitatorClient;
|
|
36
|
+
/**
|
|
37
|
+
* Custom payment handler (alternative to facilitator)
|
|
38
|
+
*/
|
|
39
|
+
paymentHandler?: A2APaymentHandler;
|
|
40
|
+
/**
|
|
41
|
+
* Default payment requirements template
|
|
42
|
+
*/
|
|
43
|
+
defaultRequirements?: Partial<PaymentRequired>;
|
|
44
|
+
/**
|
|
45
|
+
* Optional callback when payment is received
|
|
46
|
+
*/
|
|
47
|
+
onPaymentReceived?: (payload: PaymentPayload) => void;
|
|
48
|
+
/**
|
|
49
|
+
* Optional callback when payment is verified
|
|
50
|
+
*/
|
|
51
|
+
onPaymentVerified?: (payload: PaymentPayload) => void;
|
|
52
|
+
/**
|
|
53
|
+
* Optional callback when payment is settled
|
|
54
|
+
*/
|
|
55
|
+
onPaymentSettled?: (receipts: SettleResponse[]) => void;
|
|
56
|
+
/**
|
|
57
|
+
* Optional callback when payment fails
|
|
58
|
+
*/
|
|
59
|
+
onPaymentFailed?: (error: string, payload?: PaymentPayload) => void;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* A2A Payment Server
|
|
63
|
+
*
|
|
64
|
+
* Provides server-side payment handling for A2A agent endpoints.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* const server = new A2APaymentServer({
|
|
69
|
+
* facilitator: facilitatorClient,
|
|
70
|
+
* defaultRequirements: {
|
|
71
|
+
* t402Version: 2,
|
|
72
|
+
* resource: 'agent://my-agent/skill',
|
|
73
|
+
* },
|
|
74
|
+
* });
|
|
75
|
+
*
|
|
76
|
+
* // Create payment-required response
|
|
77
|
+
* const requirements = server.createRequirements({
|
|
78
|
+
* accepts: [{ scheme: 'exact', network: 'eip155:8453', amount: '1000000', ... }],
|
|
79
|
+
* });
|
|
80
|
+
* const task = server.createPaymentRequiredTask(taskId, requirements);
|
|
81
|
+
*
|
|
82
|
+
* // Process payment submission
|
|
83
|
+
* const result = await server.processPayment(message, requirements);
|
|
84
|
+
* if (result.success) {
|
|
85
|
+
* // Continue with task execution
|
|
86
|
+
* }
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
declare class A2APaymentServer {
|
|
90
|
+
private options;
|
|
91
|
+
constructor(options?: A2APaymentServerOptions);
|
|
92
|
+
/**
|
|
93
|
+
* Create payment requirements with defaults
|
|
94
|
+
*
|
|
95
|
+
* @param requirements - Partial requirements to merge with defaults
|
|
96
|
+
* @returns Complete payment requirements
|
|
97
|
+
*/
|
|
98
|
+
createRequirements(requirements: Partial<PaymentRequired>): PaymentRequired;
|
|
99
|
+
/**
|
|
100
|
+
* Create a payment-required task status
|
|
101
|
+
*
|
|
102
|
+
* @param requirements - Payment requirements
|
|
103
|
+
* @param text - Optional text message
|
|
104
|
+
* @returns A2A task status
|
|
105
|
+
*/
|
|
106
|
+
createPaymentRequiredStatus(requirements: PaymentRequired, text?: string): A2ATaskStatus;
|
|
107
|
+
/**
|
|
108
|
+
* Create a payment-required task
|
|
109
|
+
*
|
|
110
|
+
* @param taskId - Task identifier
|
|
111
|
+
* @param requirements - Payment requirements
|
|
112
|
+
* @param text - Optional text message
|
|
113
|
+
* @returns A2A task in input-required state
|
|
114
|
+
*/
|
|
115
|
+
createPaymentRequiredTask(taskId: string, requirements: PaymentRequired, text?: string): A2ATask;
|
|
116
|
+
/**
|
|
117
|
+
* Extract payment payload from an A2A message
|
|
118
|
+
*
|
|
119
|
+
* @param message - A2A message that may contain payment
|
|
120
|
+
* @returns Payment payload or undefined
|
|
121
|
+
*/
|
|
122
|
+
extractPaymentPayload(message: A2AMessage): PaymentPayload | undefined;
|
|
123
|
+
/**
|
|
124
|
+
* Check if a message contains a payment submission
|
|
125
|
+
*
|
|
126
|
+
* @param message - A2A message to check
|
|
127
|
+
* @returns Whether the message contains a payment
|
|
128
|
+
*/
|
|
129
|
+
hasPaymentPayload(message: A2AMessage): boolean;
|
|
130
|
+
/**
|
|
131
|
+
* Process a payment submission
|
|
132
|
+
*
|
|
133
|
+
* @param message - A2A message containing payment payload
|
|
134
|
+
* @param requirements - Original payment requirements
|
|
135
|
+
* @returns Payment processing result
|
|
136
|
+
*/
|
|
137
|
+
processPayment(message: A2AMessage, requirements: PaymentRequired): Promise<A2APaymentResult>;
|
|
138
|
+
/**
|
|
139
|
+
* Create a completed task status with payment receipts
|
|
140
|
+
*
|
|
141
|
+
* @param receipts - Settlement receipts
|
|
142
|
+
* @param text - Optional text message
|
|
143
|
+
* @returns A2A task status
|
|
144
|
+
*/
|
|
145
|
+
createPaymentCompletedStatus(receipts: SettleResponse[], text?: string): A2ATaskStatus;
|
|
146
|
+
/**
|
|
147
|
+
* Create a failed task status with payment error
|
|
148
|
+
*
|
|
149
|
+
* @param error - Error message
|
|
150
|
+
* @param receipts - Optional settlement receipts
|
|
151
|
+
* @param errorCode - Optional error code
|
|
152
|
+
* @returns A2A task status
|
|
153
|
+
*/
|
|
154
|
+
createPaymentFailedStatus(error: string, receipts?: SettleResponse[], errorCode?: string): A2ATaskStatus;
|
|
155
|
+
/**
|
|
156
|
+
* Update a task with payment completion
|
|
157
|
+
*
|
|
158
|
+
* @param task - Original task
|
|
159
|
+
* @param result - Payment processing result
|
|
160
|
+
* @returns Updated task
|
|
161
|
+
*/
|
|
162
|
+
updateTaskWithPaymentResult(task: A2ATask, result: A2APaymentResult): A2ATask;
|
|
163
|
+
/**
|
|
164
|
+
* Handle a complete payment flow for a task
|
|
165
|
+
*
|
|
166
|
+
* This is a convenience method that processes a payment submission
|
|
167
|
+
* and returns an updated task.
|
|
168
|
+
*
|
|
169
|
+
* @param task - The current A2A task
|
|
170
|
+
* @param message - The message containing payment payload
|
|
171
|
+
* @param requirements - Payment requirements
|
|
172
|
+
* @returns Updated task with payment result
|
|
173
|
+
*/
|
|
174
|
+
handlePayment(task: A2ATask, message: A2AMessage, requirements: PaymentRequired): Promise<A2ATask>;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export { type A2APaymentHandler, type A2APaymentResult, A2APaymentServer, type A2APaymentServerOptions };
|
package/package.json
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@t402/a2a",
|
|
3
|
+
"version": "2.4.0",
|
|
4
|
+
"description": "A2A (Agent-to-Agent) transport for t402 payment protocol",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/cjs/index.cjs",
|
|
7
|
+
"module": "./dist/esm/index.mjs",
|
|
8
|
+
"types": "./dist/esm/index.d.mts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/esm/index.d.mts",
|
|
13
|
+
"default": "./dist/esm/index.mjs"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/cjs/index.d.cts",
|
|
17
|
+
"default": "./dist/cjs/index.cjs"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"./client": {
|
|
21
|
+
"import": {
|
|
22
|
+
"types": "./dist/esm/client.d.mts",
|
|
23
|
+
"default": "./dist/esm/client.mjs"
|
|
24
|
+
},
|
|
25
|
+
"require": {
|
|
26
|
+
"types": "./dist/cjs/client.d.cts",
|
|
27
|
+
"default": "./dist/cjs/client.cjs"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"./server": {
|
|
31
|
+
"import": {
|
|
32
|
+
"types": "./dist/esm/server.d.mts",
|
|
33
|
+
"default": "./dist/esm/server.mjs"
|
|
34
|
+
},
|
|
35
|
+
"require": {
|
|
36
|
+
"types": "./dist/cjs/server.d.cts",
|
|
37
|
+
"default": "./dist/cjs/server.cjs"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"files": [
|
|
42
|
+
"dist",
|
|
43
|
+
"README.md"
|
|
44
|
+
],
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@t402/core": "2.4.0"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@types/node": "^22.10.0",
|
|
50
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
51
|
+
"tsup": "^8.0.0",
|
|
52
|
+
"typescript": "^5.3.3",
|
|
53
|
+
"vite-tsconfig-paths": "^5.1.4",
|
|
54
|
+
"vitest": "^3.2.4"
|
|
55
|
+
},
|
|
56
|
+
"keywords": [
|
|
57
|
+
"t402",
|
|
58
|
+
"a2a",
|
|
59
|
+
"agent-to-agent",
|
|
60
|
+
"payments",
|
|
61
|
+
"crypto",
|
|
62
|
+
"stablecoin",
|
|
63
|
+
"usdt",
|
|
64
|
+
"usdc",
|
|
65
|
+
"ai-agents"
|
|
66
|
+
],
|
|
67
|
+
"author": "T402 Contributors",
|
|
68
|
+
"license": "Apache-2.0",
|
|
69
|
+
"repository": {
|
|
70
|
+
"type": "git",
|
|
71
|
+
"url": "https://github.com/t402-io/t402.git",
|
|
72
|
+
"directory": "sdks/typescript/packages/a2a"
|
|
73
|
+
},
|
|
74
|
+
"bugs": {
|
|
75
|
+
"url": "https://github.com/t402-io/t402/issues"
|
|
76
|
+
},
|
|
77
|
+
"homepage": "https://t402.io",
|
|
78
|
+
"scripts": {
|
|
79
|
+
"build": "tsup",
|
|
80
|
+
"dev": "tsup --watch",
|
|
81
|
+
"test": "vitest run",
|
|
82
|
+
"test:watch": "vitest",
|
|
83
|
+
"typecheck": "tsc --noEmit",
|
|
84
|
+
"clean": "rm -rf dist coverage"
|
|
85
|
+
}
|
|
86
|
+
}
|