@aura-labs-ai/scout 0.2.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 +237 -0
- package/bin/scout-cli.js +325 -0
- package/examples/basic-purchase.js +112 -0
- package/examples/protocol-integration.js +294 -0
- package/package.json +63 -0
- package/src/activity.js +420 -0
- package/src/ap2/mandates.js +366 -0
- package/src/client.js +217 -0
- package/src/errors.js +66 -0
- package/src/index.js +655 -0
- package/src/intent-session.js +233 -0
- package/src/key-manager.js +204 -0
- package/src/key-manager.test.js +293 -0
- package/src/mcp/client.js +458 -0
- package/src/session.js +603 -0
- package/src/tap/visa.js +345 -0
- package/src/tests/README.md +157 -0
- package/src/tests/ap2-mandates.test.js +413 -0
- package/src/tests/intent-session.test.js +292 -0
- package/src/tests/mcp-client.test.js +224 -0
- package/src/tests/ping.test.js +282 -0
- package/src/tests/run-protocol-tests.js +57 -0
- package/src/tests/scenarios/ap2-scenarios.test.js +422 -0
- package/src/tests/scenarios/index.js +60 -0
- package/src/tests/scenarios/integration-scenarios.test.js +514 -0
- package/src/tests/scenarios/mcp-scenarios.test.js +419 -0
- package/src/tests/scenarios/tap-scenarios.test.js +461 -0
- package/src/tests/visa-tap.test.js +376 -0
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Protocol Integration Example
|
|
5
|
+
*
|
|
6
|
+
* Demonstrates how to use MCP, AP2, and Visa TAP together
|
|
7
|
+
* in a complete agentic commerce flow:
|
|
8
|
+
*
|
|
9
|
+
* 1. MCP - Connect to external tools for context
|
|
10
|
+
* 2. AP2 - Create user-signed mandates for authorization
|
|
11
|
+
* 3. TAP - Sign requests for payment network verification
|
|
12
|
+
*
|
|
13
|
+
* Usage:
|
|
14
|
+
* node examples/protocol-integration.js
|
|
15
|
+
*
|
|
16
|
+
* Environment:
|
|
17
|
+
* AURA_CORE_URL - Core API URL (optional)
|
|
18
|
+
* USER_PRIVATE_KEY - User's signing key (optional, generates one)
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import {
|
|
22
|
+
createScout,
|
|
23
|
+
MCPClient,
|
|
24
|
+
AP2Mandates,
|
|
25
|
+
generateAP2KeyPair,
|
|
26
|
+
VisaTAP,
|
|
27
|
+
} from '../src/index.js';
|
|
28
|
+
|
|
29
|
+
// =============================================================================
|
|
30
|
+
// Configuration
|
|
31
|
+
// =============================================================================
|
|
32
|
+
|
|
33
|
+
const CORE_URL = process.env.AURA_CORE_URL || 'https://aura-labsai-production.up.railway.app';
|
|
34
|
+
|
|
35
|
+
// Generate keys for demo (in production, these would be stored securely)
|
|
36
|
+
const userKeys = generateAP2KeyPair();
|
|
37
|
+
const agentKeys = VisaTAP.generateKeyPair();
|
|
38
|
+
|
|
39
|
+
// =============================================================================
|
|
40
|
+
// Main Demo Flow
|
|
41
|
+
// =============================================================================
|
|
42
|
+
|
|
43
|
+
async function main() {
|
|
44
|
+
console.log('\n' + '═'.repeat(70));
|
|
45
|
+
console.log(' Protocol Integration Demo: MCP + AP2 + Visa TAP');
|
|
46
|
+
console.log('═'.repeat(70) + '\n');
|
|
47
|
+
|
|
48
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
49
|
+
// Step 1: Initialize MCP Client (external tool access)
|
|
50
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
51
|
+
|
|
52
|
+
console.log('📡 Step 1: MCP Client Initialization\n');
|
|
53
|
+
|
|
54
|
+
const mcp = new MCPClient({
|
|
55
|
+
clientInfo: {
|
|
56
|
+
name: 'aura-scout-demo',
|
|
57
|
+
version: '1.0.0',
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// In production, you'd connect to real MCP servers
|
|
62
|
+
// For demo, we'll simulate the tool discovery
|
|
63
|
+
console.log(' Connecting to MCP servers...');
|
|
64
|
+
console.log(' (In production: await mcp.connect("https://tools.example.com/sse"))');
|
|
65
|
+
console.log(' ✓ MCP client ready\n');
|
|
66
|
+
|
|
67
|
+
// Example: List available tools from connected servers
|
|
68
|
+
// const tools = await mcp.listAllTools();
|
|
69
|
+
// console.log(' Available tools:', tools.map(t => t.name).join(', '));
|
|
70
|
+
|
|
71
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
72
|
+
// Step 2: Register Agent with Visa TAP
|
|
73
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
74
|
+
|
|
75
|
+
console.log('🔑 Step 2: Visa TAP Agent Registration\n');
|
|
76
|
+
|
|
77
|
+
const agentId = `demo-scout-${Date.now()}`;
|
|
78
|
+
|
|
79
|
+
// In production, this calls Visa's TAP registry
|
|
80
|
+
const tapRegistration = await VisaTAP.register({
|
|
81
|
+
agentId,
|
|
82
|
+
publicKey: agentKeys.publicKey,
|
|
83
|
+
metadata: {
|
|
84
|
+
name: 'AURA Shopping Scout',
|
|
85
|
+
operator: 'AURA Labs',
|
|
86
|
+
capabilities: ['shopping', 'comparison', 'payments'],
|
|
87
|
+
version: '1.0',
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
console.log(' Agent ID:', agentId);
|
|
92
|
+
console.log(' TAP ID:', tapRegistration.tapId);
|
|
93
|
+
console.log(' Status:', tapRegistration.status);
|
|
94
|
+
console.log(' Expires:', tapRegistration.expiresAt);
|
|
95
|
+
console.log(' ✓ Agent registered with TAP\n');
|
|
96
|
+
|
|
97
|
+
const tapCredentials = VisaTAP.createCredentials({
|
|
98
|
+
tapId: tapRegistration.tapId,
|
|
99
|
+
keyPair: agentKeys,
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
103
|
+
// Step 3: Create Intent Mandate (user authorization)
|
|
104
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
105
|
+
|
|
106
|
+
console.log('📜 Step 3: AP2 Intent Mandate Creation\n');
|
|
107
|
+
|
|
108
|
+
const userId = 'user-demo-001';
|
|
109
|
+
const intentMandate = await AP2Mandates.createIntent({
|
|
110
|
+
agentId,
|
|
111
|
+
userId,
|
|
112
|
+
userKey: userKeys.privateKey,
|
|
113
|
+
constraints: {
|
|
114
|
+
maxAmount: 5000,
|
|
115
|
+
currency: 'USD',
|
|
116
|
+
categories: ['electronics', 'office-supplies'],
|
|
117
|
+
validUntil: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000).toISOString(), // 7 days
|
|
118
|
+
merchantBlocklist: ['sketchy-seller-123'],
|
|
119
|
+
requireUserPresent: false, // Agent can shop autonomously
|
|
120
|
+
maxTransactions: 3,
|
|
121
|
+
},
|
|
122
|
+
metadata: {
|
|
123
|
+
purpose: 'Office equipment upgrade',
|
|
124
|
+
department: 'Engineering',
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
console.log(' Mandate ID:', intentMandate.id);
|
|
129
|
+
console.log(' Type:', intentMandate.type);
|
|
130
|
+
console.log(' Max Amount:', `$${intentMandate.constraints.maxAmount} ${intentMandate.constraints.currency}`);
|
|
131
|
+
console.log(' Categories:', intentMandate.constraints.categories.join(', '));
|
|
132
|
+
console.log(' Valid Until:', intentMandate.constraints.validUntil);
|
|
133
|
+
console.log(' Proof Type:', intentMandate.proof.type);
|
|
134
|
+
console.log(' ✓ Intent mandate signed by user\n');
|
|
135
|
+
|
|
136
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
137
|
+
// Step 4: Simulate Shopping Session
|
|
138
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
139
|
+
|
|
140
|
+
console.log('🛒 Step 4: Shopping Session (Simulated)\n');
|
|
141
|
+
|
|
142
|
+
// In a real flow, Scout would:
|
|
143
|
+
// 1. Create a session via AURA Core
|
|
144
|
+
// 2. Receive offers from Beacons
|
|
145
|
+
// 3. Evaluate against mandate constraints
|
|
146
|
+
|
|
147
|
+
const simulatedOffer = {
|
|
148
|
+
id: 'offer-abc-123',
|
|
149
|
+
beaconId: 'beacon-techmart-001',
|
|
150
|
+
beaconName: 'TechMart Electronics',
|
|
151
|
+
product: {
|
|
152
|
+
name: 'ProBook Business Laptop',
|
|
153
|
+
sku: 'ELEC-LAP-001',
|
|
154
|
+
},
|
|
155
|
+
unitPrice: 1299.00,
|
|
156
|
+
quantity: 2,
|
|
157
|
+
totalPrice: 2598.00,
|
|
158
|
+
currency: 'USD',
|
|
159
|
+
deliveryDate: '2026-02-15',
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
console.log(' Received offer:');
|
|
163
|
+
console.log(` - Product: ${simulatedOffer.product.name}`);
|
|
164
|
+
console.log(` - Merchant: ${simulatedOffer.beaconName}`);
|
|
165
|
+
console.log(` - Price: $${simulatedOffer.totalPrice}`);
|
|
166
|
+
console.log(` - Delivery: ${simulatedOffer.deliveryDate}\n`);
|
|
167
|
+
|
|
168
|
+
// Validate offer against intent mandate
|
|
169
|
+
const validation = AP2Mandates.validateIntentCoverage(intentMandate, {
|
|
170
|
+
totalAmount: simulatedOffer.totalPrice,
|
|
171
|
+
currency: simulatedOffer.currency,
|
|
172
|
+
category: 'electronics',
|
|
173
|
+
merchantId: simulatedOffer.beaconId,
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
if (validation.valid) {
|
|
177
|
+
console.log(' ✓ Offer passes intent mandate validation\n');
|
|
178
|
+
} else {
|
|
179
|
+
console.log(' ✗ Offer fails validation:', validation.errors.join(', '));
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
184
|
+
// Step 5: Create Cart Mandate (explicit user approval)
|
|
185
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
186
|
+
|
|
187
|
+
console.log('🎯 Step 5: AP2 Cart Mandate Creation\n');
|
|
188
|
+
|
|
189
|
+
const cartMandate = await AP2Mandates.createCart({
|
|
190
|
+
sessionId: 'session-xyz-789',
|
|
191
|
+
offer: simulatedOffer,
|
|
192
|
+
userKey: userKeys.privateKey,
|
|
193
|
+
userId,
|
|
194
|
+
intentMandateId: intentMandate.id,
|
|
195
|
+
metadata: {
|
|
196
|
+
approvalMethod: 'user-confirmation',
|
|
197
|
+
},
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
console.log(' Cart Mandate ID:', cartMandate.id);
|
|
201
|
+
console.log(' Intent Mandate Ref:', cartMandate.intentMandateRef);
|
|
202
|
+
console.log(' Total Amount:', `$${cartMandate.cart.totalAmount}`);
|
|
203
|
+
console.log(' User Present:', cartMandate.userPresent);
|
|
204
|
+
console.log(' Expires:', cartMandate.expiresAt);
|
|
205
|
+
console.log(' ✓ Cart mandate signed by user\n');
|
|
206
|
+
|
|
207
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
208
|
+
// Step 6: Create Payment Mandate + TAP-Signed Request
|
|
209
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
210
|
+
|
|
211
|
+
console.log('💳 Step 6: Payment Mandate + TAP Signing\n');
|
|
212
|
+
|
|
213
|
+
const paymentMandate = await AP2Mandates.createPayment({
|
|
214
|
+
cartMandate,
|
|
215
|
+
paymentMethod: {
|
|
216
|
+
type: 'card',
|
|
217
|
+
network: 'visa',
|
|
218
|
+
},
|
|
219
|
+
agentId,
|
|
220
|
+
agentKey: agentKeys.privateKey,
|
|
221
|
+
tapCredentials,
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
console.log(' Payment Mandate ID:', paymentMandate.id);
|
|
225
|
+
console.log(' TAP ID:', paymentMandate.agent.tapId);
|
|
226
|
+
console.log(' Amount:', `$${paymentMandate.transaction.amount} ${paymentMandate.transaction.currency}`);
|
|
227
|
+
console.log(' Payment Network:', paymentMandate.paymentMethod.network);
|
|
228
|
+
console.log(' User Auth Time:', paymentMandate.riskSignals.userAuthTime);
|
|
229
|
+
console.log(' ✓ Payment mandate signed by agent\n');
|
|
230
|
+
|
|
231
|
+
// Sign the payment request with Visa TAP
|
|
232
|
+
const paymentRequest = {
|
|
233
|
+
method: 'POST',
|
|
234
|
+
url: 'https://payment.example.com/api/v1/process',
|
|
235
|
+
headers: {},
|
|
236
|
+
body: {
|
|
237
|
+
amount: paymentMandate.transaction.amount,
|
|
238
|
+
currency: paymentMandate.transaction.currency,
|
|
239
|
+
merchantId: paymentMandate.transaction.merchantId,
|
|
240
|
+
mandateId: paymentMandate.id,
|
|
241
|
+
cartMandateId: paymentMandate.cartMandateRef,
|
|
242
|
+
},
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
const signedRequest = await VisaTAP.signRequest(paymentRequest, tapCredentials);
|
|
246
|
+
|
|
247
|
+
console.log(' TAP-Signed Request Headers:');
|
|
248
|
+
console.log(` - X-TAP-Agent-Id: ${signedRequest.headers['X-TAP-Agent-Id']}`);
|
|
249
|
+
console.log(` - X-TAP-Timestamp: ${signedRequest.headers['X-TAP-Timestamp']}`);
|
|
250
|
+
console.log(` - Signature-Input: ${signedRequest.headers['Signature-Input'].substring(0, 50)}...`);
|
|
251
|
+
console.log(' ✓ Request signed for TAP verification\n');
|
|
252
|
+
|
|
253
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
254
|
+
// Summary
|
|
255
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
256
|
+
|
|
257
|
+
console.log('═'.repeat(70));
|
|
258
|
+
console.log(' Protocol Integration Summary');
|
|
259
|
+
console.log('═'.repeat(70) + '\n');
|
|
260
|
+
|
|
261
|
+
console.log(' MCP:');
|
|
262
|
+
console.log(' • Client initialized for external tool access');
|
|
263
|
+
console.log(' • Can connect to any MCP-compatible server');
|
|
264
|
+
console.log('');
|
|
265
|
+
|
|
266
|
+
console.log(' Visa TAP:');
|
|
267
|
+
console.log(` • Agent registered: ${tapRegistration.tapId}`);
|
|
268
|
+
console.log(' • HTTP Message Signatures enabled');
|
|
269
|
+
console.log(' • Payment network can verify agent identity');
|
|
270
|
+
console.log('');
|
|
271
|
+
|
|
272
|
+
console.log(' AP2 Mandates:');
|
|
273
|
+
console.log(` • Intent Mandate: ${intentMandate.id}`);
|
|
274
|
+
console.log(` • Cart Mandate: ${cartMandate.id}`);
|
|
275
|
+
console.log(` • Payment Mandate: ${paymentMandate.id}`);
|
|
276
|
+
console.log(' • Complete audit trail from intent → cart → payment');
|
|
277
|
+
console.log('');
|
|
278
|
+
|
|
279
|
+
console.log(' Transaction Flow:');
|
|
280
|
+
console.log(' User → Intent Mandate → Agent shopping → Cart Mandate →');
|
|
281
|
+
console.log(' Payment Mandate + TAP Signature → Payment Network');
|
|
282
|
+
console.log('');
|
|
283
|
+
|
|
284
|
+
console.log('═'.repeat(70) + '\n');
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// =============================================================================
|
|
288
|
+
// Run Demo
|
|
289
|
+
// =============================================================================
|
|
290
|
+
|
|
291
|
+
main().catch((error) => {
|
|
292
|
+
console.error('Demo failed:', error);
|
|
293
|
+
process.exit(1);
|
|
294
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aura-labs-ai/scout",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Scout SDK for AURA - Build buying agents that participate in agentic commerce",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "src/index.js",
|
|
7
|
+
"types": "src/index.d.ts",
|
|
8
|
+
"bin": {
|
|
9
|
+
"scout-cli": "./bin/scout-cli.js",
|
|
10
|
+
"aura-scout": "./bin/scout-cli.js"
|
|
11
|
+
},
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": "./src/index.js",
|
|
15
|
+
"types": "./src/index.d.ts"
|
|
16
|
+
},
|
|
17
|
+
"./mcp": {
|
|
18
|
+
"import": "./src/mcp/client.js"
|
|
19
|
+
},
|
|
20
|
+
"./ap2": {
|
|
21
|
+
"import": "./src/ap2/mandates.js"
|
|
22
|
+
},
|
|
23
|
+
"./tap": {
|
|
24
|
+
"import": "./src/tap/visa.js"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"test": "node --test src/**/*.test.js",
|
|
29
|
+
"test:protocols": "node src/tests/run-protocol-tests.js",
|
|
30
|
+
"test:scenarios": "node src/tests/scenarios/index.js",
|
|
31
|
+
"test:ap2": "node --test src/tests/scenarios/ap2-scenarios.test.js",
|
|
32
|
+
"test:tap": "node --test src/tests/scenarios/tap-scenarios.test.js",
|
|
33
|
+
"test:mcp": "node --test src/tests/scenarios/mcp-scenarios.test.js",
|
|
34
|
+
"test:integration": "node --test src/tests/scenarios/integration-scenarios.test.js",
|
|
35
|
+
"cli": "node bin/scout-cli.js",
|
|
36
|
+
"example": "node examples/basic-purchase.js",
|
|
37
|
+
"example:protocols": "node examples/protocol-integration.js"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@aura-labs-ai/nlp": "^0.1.0",
|
|
41
|
+
"@aura-labs-ai/sdk-common": "^0.1.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@types/node": "^20.11.0"
|
|
45
|
+
},
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=18.0.0"
|
|
48
|
+
},
|
|
49
|
+
"keywords": [
|
|
50
|
+
"aura",
|
|
51
|
+
"agentic-commerce",
|
|
52
|
+
"ai-agent",
|
|
53
|
+
"shopping-agent",
|
|
54
|
+
"scout"
|
|
55
|
+
],
|
|
56
|
+
"author": "AURA Labs",
|
|
57
|
+
"license": "BSL-1.1",
|
|
58
|
+
"repository": {
|
|
59
|
+
"type": "git",
|
|
60
|
+
"url": "https://github.com/aura-labs-ai/aura-labs"
|
|
61
|
+
},
|
|
62
|
+
"homepage": "https://aura-labs.ai/docs/scout"
|
|
63
|
+
}
|