aptos-x402 2.2.3 → 2.3.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.
Files changed (212) hide show
  1. package/CHANGELOG.md +136 -0
  2. package/COMPOSER_IMPLEMENTATION.md +203 -0
  3. package/README.md +1 -19
  4. package/components/auth/LoginModal.tsx +82 -0
  5. package/components/auth/SessionProvider.tsx +11 -0
  6. package/components/auth/UserMenu.tsx +8 -0
  7. package/components/auth/UserMenuClient.tsx +117 -0
  8. package/components/composer/AgentCard.tsx +362 -0
  9. package/components/composer/AgentCardSkeleton.tsx +59 -0
  10. package/components/composer/AgentCreationWizard.tsx +311 -0
  11. package/components/composer/ApiSelector.tsx +230 -0
  12. package/components/composer/ChatInterface.tsx +605 -0
  13. package/components/composer/ChatInterfaceSkeleton.tsx +75 -0
  14. package/components/composer/ComposerClient.tsx +201 -0
  15. package/components/composer/FundingModal.tsx +143 -0
  16. package/components/composer/WaitlistModal.tsx +149 -0
  17. package/components/composer/WalletCard.tsx +152 -0
  18. package/components/ui/badge.tsx +46 -0
  19. package/components/ui/button.tsx +60 -0
  20. package/components/ui/card.tsx +92 -0
  21. package/components/ui/dialog.tsx +141 -0
  22. package/components/ui/input.tsx +27 -0
  23. package/components/ui/scroll-area.tsx +58 -0
  24. package/components/ui/select.tsx +185 -0
  25. package/components/ui/separator.tsx +26 -0
  26. package/components/ui/tabs.tsx +64 -0
  27. package/components/wallet/WalletProvider.tsx +20 -0
  28. package/components.json +22 -0
  29. package/contracts/arc8004/Move.toml +30 -0
  30. package/contracts/arc8004/sources/agent_identity.move +229 -0
  31. package/contracts/arc8004/sources/reputation.move +287 -0
  32. package/contracts/arc8004/sources/validation.move +228 -0
  33. package/dist/tsconfig.sdk.tsbuildinfo +1 -1
  34. package/drizzle/0000_nappy_kid_colt.sql +32 -0
  35. package/drizzle/0001_salty_spyke.sql +6 -0
  36. package/drizzle/0002_sloppy_the_twelve.sql +9 -0
  37. package/drizzle/0003_parched_cammi.sql +8 -0
  38. package/drizzle/0004_unusual_triton.sql +1 -0
  39. package/drizzle/0005_zippy_bulldozer.sql +66 -0
  40. package/drizzle/0006_auth_and_agent_wallets.sql +92 -0
  41. package/drizzle/0007_arc8004_tables.sql +144 -0
  42. package/drizzle/meta/0000_snapshot.json +211 -0
  43. package/drizzle/meta/0001_snapshot.json +303 -0
  44. package/drizzle/meta/0002_snapshot.json +364 -0
  45. package/drizzle/meta/0003_snapshot.json +427 -0
  46. package/drizzle/meta/0004_snapshot.json +433 -0
  47. package/drizzle/meta/0005_snapshot.json +901 -0
  48. package/drizzle/meta/_journal.json +55 -0
  49. package/drizzle.config.ts +11 -0
  50. package/package.json +1 -6
  51. package/proxy.ts +182 -0
  52. package/public/file.svg +1 -0
  53. package/public/globe.svg +1 -0
  54. package/public/logo_dark.svg +5 -0
  55. package/public/logo_white.png +0 -0
  56. package/public/next.svg +1 -0
  57. package/public/vercel.svg +1 -0
  58. package/public/window.svg +1 -0
  59. package/tsconfig.sdk.tsbuildinfo +1 -0
  60. package/tsconfig.tsbuildinfo +1 -0
  61. package/dist/lib/aptos-utils.d.ts +0 -47
  62. package/dist/lib/aptos-utils.d.ts.map +0 -1
  63. package/dist/lib/aptos-utils.js +0 -126
  64. package/dist/lib/aptos-utils.js.map +0 -1
  65. package/dist/lib/arc8004/chain/index.d.ts +0 -10
  66. package/dist/lib/arc8004/chain/index.d.ts.map +0 -1
  67. package/dist/lib/arc8004/chain/index.js +0 -9
  68. package/dist/lib/arc8004/chain/index.js.map +0 -1
  69. package/dist/lib/arc8004/chain/types.d.ts +0 -190
  70. package/dist/lib/arc8004/chain/types.d.ts.map +0 -1
  71. package/dist/lib/arc8004/chain/types.js +0 -278
  72. package/dist/lib/arc8004/chain/types.js.map +0 -1
  73. package/dist/lib/arc8004/identity/agent-card.d.ts +0 -66
  74. package/dist/lib/arc8004/identity/agent-card.d.ts.map +0 -1
  75. package/dist/lib/arc8004/identity/agent-card.js +0 -141
  76. package/dist/lib/arc8004/identity/agent-card.js.map +0 -1
  77. package/dist/lib/arc8004/identity/index.d.ts +0 -7
  78. package/dist/lib/arc8004/identity/index.d.ts.map +0 -1
  79. package/dist/lib/arc8004/identity/index.js +0 -7
  80. package/dist/lib/arc8004/identity/index.js.map +0 -1
  81. package/dist/lib/arc8004/identity/registry.d.ts +0 -73
  82. package/dist/lib/arc8004/identity/registry.d.ts.map +0 -1
  83. package/dist/lib/arc8004/identity/registry.js +0 -447
  84. package/dist/lib/arc8004/identity/registry.js.map +0 -1
  85. package/dist/lib/arc8004/index.d.ts +0 -49
  86. package/dist/lib/arc8004/index.d.ts.map +0 -1
  87. package/dist/lib/arc8004/index.js +0 -54
  88. package/dist/lib/arc8004/index.js.map +0 -1
  89. package/dist/lib/arc8004/reputation/index.d.ts +0 -7
  90. package/dist/lib/arc8004/reputation/index.d.ts.map +0 -1
  91. package/dist/lib/arc8004/reputation/index.js +0 -7
  92. package/dist/lib/arc8004/reputation/index.js.map +0 -1
  93. package/dist/lib/arc8004/reputation/registry.d.ts +0 -60
  94. package/dist/lib/arc8004/reputation/registry.d.ts.map +0 -1
  95. package/dist/lib/arc8004/reputation/registry.js +0 -373
  96. package/dist/lib/arc8004/reputation/registry.js.map +0 -1
  97. package/dist/lib/arc8004/reputation/scoring.d.ts +0 -60
  98. package/dist/lib/arc8004/reputation/scoring.d.ts.map +0 -1
  99. package/dist/lib/arc8004/reputation/scoring.js +0 -130
  100. package/dist/lib/arc8004/reputation/scoring.js.map +0 -1
  101. package/dist/lib/arc8004/storage/index.d.ts +0 -44
  102. package/dist/lib/arc8004/storage/index.d.ts.map +0 -1
  103. package/dist/lib/arc8004/storage/index.js +0 -76
  104. package/dist/lib/arc8004/storage/index.js.map +0 -1
  105. package/dist/lib/arc8004/storage/memory.d.ts +0 -114
  106. package/dist/lib/arc8004/storage/memory.d.ts.map +0 -1
  107. package/dist/lib/arc8004/storage/memory.js +0 -458
  108. package/dist/lib/arc8004/storage/memory.js.map +0 -1
  109. package/dist/lib/arc8004/storage/postgres.d.ts +0 -93
  110. package/dist/lib/arc8004/storage/postgres.d.ts.map +0 -1
  111. package/dist/lib/arc8004/storage/postgres.js +0 -637
  112. package/dist/lib/arc8004/storage/postgres.js.map +0 -1
  113. package/dist/lib/arc8004/storage/types.d.ts +0 -201
  114. package/dist/lib/arc8004/storage/types.d.ts.map +0 -1
  115. package/dist/lib/arc8004/storage/types.js +0 -12
  116. package/dist/lib/arc8004/storage/types.js.map +0 -1
  117. package/dist/lib/arc8004/types.d.ts +0 -323
  118. package/dist/lib/arc8004/types.d.ts.map +0 -1
  119. package/dist/lib/arc8004/types.js +0 -75
  120. package/dist/lib/arc8004/types.js.map +0 -1
  121. package/dist/lib/arc8004/validation/index.d.ts +0 -6
  122. package/dist/lib/arc8004/validation/index.d.ts.map +0 -1
  123. package/dist/lib/arc8004/validation/index.js +0 -6
  124. package/dist/lib/arc8004/validation/index.js.map +0 -1
  125. package/dist/lib/arc8004/validation/registry.d.ts +0 -72
  126. package/dist/lib/arc8004/validation/registry.d.ts.map +0 -1
  127. package/dist/lib/arc8004/validation/registry.js +0 -268
  128. package/dist/lib/arc8004/validation/registry.js.map +0 -1
  129. package/dist/lib/db/index.d.ts +0 -12
  130. package/dist/lib/db/index.d.ts.map +0 -1
  131. package/dist/lib/db/index.js +0 -33
  132. package/dist/lib/db/index.js.map +0 -1
  133. package/dist/lib/db/schema.d.ts +0 -2086
  134. package/dist/lib/db/schema.d.ts.map +0 -1
  135. package/dist/lib/db/schema.js +0 -220
  136. package/dist/lib/db/schema.js.map +0 -1
  137. package/dist/lib/facilitator-client.d.ts +0 -89
  138. package/dist/lib/facilitator-client.d.ts.map +0 -1
  139. package/dist/lib/facilitator-client.js +0 -140
  140. package/dist/lib/facilitator-client.js.map +0 -1
  141. package/dist/lib/index.d.ts +0 -44
  142. package/dist/lib/index.d.ts.map +0 -1
  143. package/dist/lib/index.js +0 -56
  144. package/dist/lib/index.js.map +0 -1
  145. package/dist/lib/services/geomi-gas-station.d.ts +0 -33
  146. package/dist/lib/services/geomi-gas-station.d.ts.map +0 -1
  147. package/dist/lib/services/geomi-gas-station.js +0 -97
  148. package/dist/lib/services/geomi-gas-station.js.map +0 -1
  149. package/dist/lib/utils.d.ts +0 -3
  150. package/dist/lib/utils.d.ts.map +0 -1
  151. package/dist/lib/utils.js +0 -6
  152. package/dist/lib/utils.js.map +0 -1
  153. package/dist/lib/x402-axios.d.ts +0 -45
  154. package/dist/lib/x402-axios.d.ts.map +0 -1
  155. package/dist/lib/x402-axios.js +0 -242
  156. package/dist/lib/x402-axios.js.map +0 -1
  157. package/dist/lib/x402-middleware.d.ts +0 -11
  158. package/dist/lib/x402-middleware.d.ts.map +0 -1
  159. package/dist/lib/x402-middleware.js +0 -183
  160. package/dist/lib/x402-middleware.js.map +0 -1
  161. package/dist/lib/x402-protocol-types.d.ts +0 -177
  162. package/dist/lib/x402-protocol-types.d.ts.map +0 -1
  163. package/dist/lib/x402-protocol-types.js +0 -63
  164. package/dist/lib/x402-protocol-types.js.map +0 -1
  165. package/dist/lib/x402-types.d.ts +0 -83
  166. package/dist/lib/x402-types.d.ts.map +0 -1
  167. package/dist/lib/x402-types.js +0 -30
  168. package/dist/lib/x402-types.js.map +0 -1
  169. package/dist/src/arc8004/client.d.ts +0 -313
  170. package/dist/src/arc8004/client.d.ts.map +0 -1
  171. package/dist/src/arc8004/client.js +0 -586
  172. package/dist/src/arc8004/client.js.map +0 -1
  173. package/dist/src/arc8004/index.d.ts +0 -54
  174. package/dist/src/arc8004/index.d.ts.map +0 -1
  175. package/dist/src/arc8004/index.js +0 -57
  176. package/dist/src/arc8004/index.js.map +0 -1
  177. package/dist/src/components/ui/shadcn-io/code-block/index.d.ts +0 -67
  178. package/dist/src/components/ui/shadcn-io/code-block/index.d.ts.map +0 -1
  179. package/dist/src/components/ui/shadcn-io/code-block/index.js +0 -209
  180. package/dist/src/components/ui/shadcn-io/code-block/index.js.map +0 -1
  181. package/dist/src/components/ui/shadcn-io/code-block/index.jsx +0 -227
  182. package/dist/src/components/ui/shadcn-io/code-block/index.jsx.map +0 -1
  183. package/dist/src/components/ui/shadcn-io/code-block/server.d.ts +0 -10
  184. package/dist/src/components/ui/shadcn-io/code-block/server.d.ts.map +0 -1
  185. package/dist/src/components/ui/shadcn-io/code-block/server.js +0 -35
  186. package/dist/src/components/ui/shadcn-io/code-block/server.js.map +0 -1
  187. package/dist/src/components/ui/shadcn-io/code-block/server.jsx +0 -34
  188. package/dist/src/components/ui/shadcn-io/code-block/server.jsx.map +0 -1
  189. package/dist/src/index.d.ts +0 -11
  190. package/dist/src/index.d.ts.map +0 -1
  191. package/dist/src/index.js +0 -13
  192. package/dist/src/index.js.map +0 -1
  193. package/dist/src/server/index.d.ts +0 -6
  194. package/dist/src/server/index.d.ts.map +0 -1
  195. package/dist/src/server/index.js +0 -5
  196. package/dist/src/server/index.js.map +0 -1
  197. package/dist/src/server/next.d.ts +0 -44
  198. package/dist/src/server/next.d.ts.map +0 -1
  199. package/dist/src/server/next.js +0 -220
  200. package/dist/src/server/next.js.map +0 -1
  201. package/dist/src/types/config.d.ts +0 -43
  202. package/dist/src/types/config.d.ts.map +0 -1
  203. package/dist/src/types/config.js +0 -6
  204. package/dist/src/types/config.js.map +0 -1
  205. package/dist/src/types/index.d.ts +0 -9
  206. package/dist/src/types/index.d.ts.map +0 -1
  207. package/dist/src/types/index.js +0 -7
  208. package/dist/src/types/index.js.map +0 -1
  209. package/dist/src/types/protocol.d.ts +0 -119
  210. package/dist/src/types/protocol.d.ts.map +0 -1
  211. package/dist/src/types/protocol.js +0 -12
  212. package/dist/src/types/protocol.js.map +0 -1
package/CHANGELOG.md ADDED
@@ -0,0 +1,136 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ ## [2.3.0] - 2026-01-17
6
+
7
+ ### 🔴 Breaking Change (V2 Protocol Compliance)
8
+ - **402 Response Format**: Payment requirements now sent via `PAYMENT-REQUIRED` header (base64 JSON) instead of response body
9
+ - **Header Constants**: Added `PAYMENT_REQUIRED_HEADER` export
10
+
11
+ ### ✨ Improvements
12
+ - **Backward Compatibility**: Client (`x402axios`) still reads from body if header is missing (V1 fallback)
13
+ - **Protocol Compliance**: Now fully compliant with official x402 V2 specification
14
+
15
+ ## [2.2.4] - 2026-01-17
16
+
17
+ ### 🐛 Bug Fixes
18
+ - Fixed npm package missing README and CHANGELOG
19
+
20
+ ## [2.2.3] - 2026-01-17
21
+
22
+ ### 🐛 Bug Fixes
23
+ - Fixed minor typo in CHANGELOG
24
+
25
+ ## [2.2.2] - 2026-01-17
26
+
27
+ ### 📚 Documentation
28
+ - Removed v1 deprecation warning from README
29
+
30
+ ## [2.2.1] - 2026-01-17
31
+
32
+ ### 📚 Documentation
33
+ - Fixed README examples: Removed non-existent `x402axios.create()` references
34
+ - Clarified v2 protocol changes: Header-based architecture, standard headers (no "X-" prefix), fungible assets
35
+ - Updated "What's new" section with accurate v2.2.0 features
36
+
37
+ ## [2.2.0] - 2026-01-17
38
+
39
+ ### 🌟 New Features (v2 Protocol)
40
+ - **Protocol Standards**: Removed "X-" prefix from headers (now `PAYMENT-SIGNATURE`).
41
+ - **Header-Based Architecture**: Moved payment specifications and proofs to headers.
42
+ - **Fungible Assets**: Native support for USDC transfers on Aptos (via `primary_fungible_store`).
43
+ - **Geomi Gas Sponsorship**: Facilitator-sponsored gas fees for better UX.
44
+ - **ARC-8004**: Added Agent Trust Layer (Identity, Reputation, Validation).
45
+
46
+ ### ⚡ Improvements
47
+ - **Performance**: Faster settlement times and bug fixes.
48
+ - **Bug Fixes**: Resolved performance bottlenecks and improved type safety.
49
+
50
+ ## [1.0.2] - 2025-01-10
51
+
52
+ ### ⚡ Performance Optimizations
53
+ - **Hex Encoding**: Replaced base64 encoding with hex for transaction/signature (faster, more compact)
54
+ - Direct JSON payment header (no outer base64 encoding)
55
+ - ~1-2ms improvement per request
56
+ - **Removed Verification Caching**: Eliminated middleware verification cache overhead (~5ms saved)
57
+ - **Skipped Middleware Validation**: Removed redundant validation checks in middleware (~2-5ms saved)
58
+ - Single source of truth: facilitator handles all validation
59
+ - **HTTP/2 Keep-Alive**: Added persistent connections for facilitator calls
60
+ - ~50-100ms improvement on subsequent requests
61
+ - Connection pooling and multiplexing support
62
+
63
+ ### 📊 Performance Impact
64
+ - **First call**: ~8-12ms faster
65
+ - **Subsequent calls**: ~58-112ms faster (with HTTP/2 keep-alive)
66
+ - **Total improvement**: Combined with previous optimizations (async confirmation, simulation-only verification)
67
+
68
+ ### 🔧 Technical Changes
69
+ - Updated all components to use consistent hex + JSON format
70
+ - Client (`x402axios`): Hex encoding for transaction/signature
71
+ - Middleware: Direct JSON parsing (no base64 decode)
72
+ - Facilitator endpoints: Hex decoding for transaction/signature
73
+ - Improved code consistency across client, middleware, and facilitator
74
+ - Better debugging with hex encoding (more human-readable)
75
+
76
+ ### 🐛 Bug Fixes
77
+ - Fixed TypeScript build error in middleware (type assertion for SettleResponse)
78
+ - Ensured all components use the same encoding format
79
+
80
+ ### ⚠️ Breaking Changes
81
+ - **Not backward compatible**: Old clients sending base64 will fail
82
+ - All components must be updated together (client, middleware, facilitator)
83
+
84
+ ## [0.2.0] - 2024-12-19
85
+
86
+ ### 🚀 Major Features
87
+ - **Axios-Compatible Interface**: Complete rewrite of x402axios to work exactly like axios
88
+ - Support for all axios methods: `.get()`, `.post()`, `.put()`, `.patch()`, `.delete()`, `.head()`, `.options()`
89
+ - Full axios configuration support: `timeout`, `headers`, `baseURL`, `params`, etc.
90
+ - `x402axios.create()` for creating instances with default configs
91
+ - Backward compatible with existing API
92
+
93
+ ### 🔧 Improvements
94
+ - **Zero Fallbacks Policy**: Removed all silent fallbacks to testnet
95
+ - Throws clear errors when environment variables are missing
96
+ - No more silent defaults that could cause confusion
97
+ - **Dynamic Explorer Links**: Explorer URLs now correctly reflect the network used
98
+ - Mainnet transactions show `?network=mainnet`
99
+ - Testnet transactions show `?network=testnet`
100
+ - No more hardcoded testnet links
101
+ - **Enhanced Error Handling**: Better error messages and validation
102
+ - Clear indication when network configuration is missing
103
+ - Proper error propagation throughout the payment flow
104
+
105
+ ### 🛠️ Technical Changes
106
+ - **Type Safety**: Full TypeScript support with proper interfaces
107
+ - `AxiosRequestConfig` interface for request configuration
108
+ - `AxiosResponse` interface for response handling
109
+ - Backward compatible `X402Response` alias
110
+ - **Network Detection**: Automatic network detection from 402 responses
111
+ - No hardcoded network assumptions
112
+ - Proper network mapping and validation
113
+ - **Documentation**: Comprehensive updates to all documentation
114
+ - Updated examples to use new axios interface
115
+ - Enhanced API reference with new types
116
+ - Improved quickstart guides
117
+
118
+ ### 🐛 Bug Fixes
119
+ - Fixed recipient/sender address mismatch issue
120
+ - Corrected network configuration handling
121
+ - Fixed explorer URL generation for different networks
122
+ - Resolved environment variable loading issues
123
+
124
+ ### 📚 Documentation
125
+ - Updated all code examples to use new axios interface
126
+ - Enhanced README with axios compatibility section
127
+ - Updated API reference with new types and methods
128
+ - Improved quickstart guides and troubleshooting
129
+
130
+ ## [0.1.3] - 2024-12-18
131
+
132
+ ### Features
133
+ - Initial release with basic x402 payment functionality
134
+ - Next.js middleware for payment protection
135
+ - Basic x402axios wrapper for payment handling
136
+ - Facilitator service for payment verification and settlement
@@ -0,0 +1,203 @@
1
+ # Agent Composer Platform - Implementation Summary
2
+
3
+ ## Overview
4
+ Successfully implemented a complete Agent Composer platform that allows users to create AI agents, assign them APIs/tools, fund them with APT (testnet), and interact with them through a chat interface. Agents autonomously make payments through the x402 protocol when calling APIs.
5
+
6
+ ## Implementation Details
7
+
8
+ ### 1. Storage Layer (`lib/storage/`)
9
+ - **agents.ts**: File-based JSON storage for agent configurations
10
+ - CRUD operations for agents
11
+ - Private key storage (server-side only, never exposed to client)
12
+ - Client-safe agent retrieval (excludes private keys)
13
+
14
+ - **chats.ts**: File-based JSON storage for chat conversations
15
+ - Thread management per agent
16
+ - Message history with metadata (API calls, payment hashes, errors)
17
+
18
+ - **apis.ts**: Hardcoded API registry
19
+ - Weather API (existing `/api/protected/weather`)
20
+ - Example APIs for testing (stocks, search)
21
+ - Category-based filtering and search functionality
22
+
23
+ ### 2. Agent Utilities (`lib/agent/`)
24
+ - **wallet.ts**: Wallet management utilities
25
+ - Agent wallet generation using `Account.generate()`
26
+ - Balance checking via Aptos SDK
27
+ - Faucet funding helper (for development)
28
+
29
+ - **executor.ts**: Agent execution logic
30
+ - Simple query parsing (keyword-based API selection)
31
+ - API calling via x402axios with agent's private key
32
+ - Error handling for insufficient funds and API failures
33
+
34
+ ### 3. API Endpoints (`app/api/`)
35
+ - **GET /api/apis**: List available APIs (with category/search filtering)
36
+ - **GET /api/agents**: List all agents (client-safe, no private keys)
37
+ - **POST /api/agents**: Create new agent (generates wallet automatically)
38
+ - **GET /api/agents/[agentId]**: Get agent details
39
+ - **PATCH /api/agents/[agentId]**: Update agent settings
40
+ - **DELETE /api/agents/[agentId]**: Delete agent
41
+ - **GET /api/agents/[agentId]/balance**: Get agent wallet balance
42
+ - **GET /api/agents/[agentId]/chat**: Get chat history
43
+ - **POST /api/agents/[agentId]/chat**: Send message and execute agent query
44
+
45
+ ### 4. UI Components (`components/composer/`)
46
+ - **AgentCard.tsx**: Agent display card with wallet info, balance, and actions
47
+ - **AgentCreationWizard.tsx**: 3-step wizard for creating agents
48
+ - Step 1: Display settings (name, description, image, visibility)
49
+ - Step 2: API/tool selection
50
+ - Step 3: Review and create
51
+ - **ApiSelector.tsx**: Searchable, filterable API browser with category tags
52
+ - **FundingModal.tsx**: Modal for viewing wallet address and funding agent
53
+ - **ChatInterface.tsx**: Full chat UI with message history, balance display, and funding integration
54
+
55
+ ### 5. Pages (`app/composer/`)
56
+ - **page.tsx**: Main composer dashboard showing all user agents
57
+ - **create/page.tsx**: Agent creation page
58
+ - **[agentId]/page.tsx**: Agent chat interface
59
+ - **[agentId]/settings/page.tsx**: Agent settings and wallet management
60
+
61
+ ### 6. Navigation
62
+ - Updated Navbar to include "Composer" link
63
+
64
+ ### 7. Storage Configuration
65
+ - Added `.composer-data/` to `.gitignore` for local storage files
66
+
67
+ ## Key Features Implemented
68
+
69
+ 1. **Agent Creation**
70
+ - Multi-step wizard with progress indicator
71
+ - Wallet generation (automatic Aptos wallet per agent)
72
+ - API selection from registry
73
+ - Public/private visibility settings
74
+
75
+ 2. **Agent Management**
76
+ - List view with balance display
77
+ - Edit agent settings
78
+ - Delete agents
79
+ - Wallet information display
80
+
81
+ 3. **Funding System**
82
+ - Display agent wallet address (copyable)
83
+ - Real-time balance checking
84
+ - Direct link to Aptos testnet faucet
85
+ - Balance refresh functionality
86
+
87
+ 4. **Chat Interface**
88
+ - Real-time messaging with agent
89
+ - Message history persistence
90
+ - Payment hash display for API calls
91
+ - Error handling with user-friendly messages
92
+ - Insufficient funds detection and funding prompts
93
+
94
+ 5. **Agent Execution**
95
+ - Simple keyword-based query parsing
96
+ - Automatic API selection based on query
97
+ - x402 payment handling (automatic via x402axios)
98
+ - Error handling and user feedback
99
+
100
+ ## Technical Stack
101
+
102
+ - **Storage**: File-based JSON (`.composer-data/` directory)
103
+ - **Wallet**: Aptos SDK (`@aptos-labs/ts-sdk`)
104
+ - **Payments**: x402 protocol via `x402axios`
105
+ - **UI**: Next.js 15, React 19, Tailwind CSS, shadcn/ui components
106
+ - **Network**: Aptos testnet (for development)
107
+
108
+ ## Security Considerations
109
+
110
+ - Private keys stored server-side only (never exposed to client)
111
+ - Client-safe agent retrieval (excludes private keys)
112
+ - Server-side validation for API calls
113
+ - Balance checks before executing transactions
114
+
115
+ ## Usage Flow
116
+
117
+ 1. User navigates to `/composer`
118
+ 2. Clicks "Create Agent"
119
+ 3. Fills in agent details (name, description, visibility)
120
+ 4. Selects APIs/tools for the agent
121
+ 5. Reviews and creates agent (wallet auto-generated)
122
+ 6. Funds agent wallet with APT (testnet)
123
+ 7. Starts chatting with agent
124
+ 8. Agent automatically calls APIs and makes payments via x402 protocol
125
+
126
+ ## File Structure
127
+
128
+ ```
129
+ lib/
130
+ storage/
131
+ agents.ts # Agent CRUD operations
132
+ chats.ts # Chat history storage
133
+ apis.ts # API registry
134
+ agent/
135
+ wallet.ts # Wallet utilities
136
+ executor.ts # Agent execution logic
137
+
138
+ app/
139
+ api/
140
+ apis/
141
+ route.ts # API listing endpoint
142
+ agents/
143
+ route.ts # Agent CRUD endpoints
144
+ [agentId]/
145
+ route.ts # Individual agent endpoints
146
+ balance/
147
+ route.ts # Balance checking
148
+ chat/
149
+ route.ts # Chat message handling
150
+ composer/
151
+ page.tsx # Main dashboard
152
+ create/
153
+ page.tsx # Agent creation
154
+ [agentId]/
155
+ page.tsx # Chat interface
156
+ settings/
157
+ page.tsx # Agent settings
158
+
159
+ components/
160
+ composer/
161
+ AgentCard.tsx
162
+ AgentCreationWizard.tsx
163
+ ApiSelector.tsx
164
+ FundingModal.tsx
165
+ ChatInterface.tsx
166
+ ui/
167
+ input.tsx # Input component (new)
168
+ ```
169
+
170
+ ## Environment Variables
171
+
172
+ - `NEXT_PUBLIC_BASE_URL`: Base URL for API endpoints (optional, defaults to localhost:3000)
173
+ - `FACILITATOR_URL`: x402 facilitator service URL (existing)
174
+ - `PAYMENT_RECIPIENT_ADDRESS`: Payment recipient address (existing)
175
+ - `APTOS_NETWORK`: Aptos network (testnet/mainnet) (existing)
176
+
177
+ ## Testing Recommendations
178
+
179
+ 1. Create an agent and verify wallet generation
180
+ 2. Fund agent wallet via testnet faucet
181
+ 3. Test chat interface with weather queries
182
+ 4. Verify x402 payments are processed correctly
183
+ 5. Test error handling (insufficient funds scenario)
184
+ 6. Test agent deletion and cleanup
185
+
186
+ ## Future Enhancements (Out of Scope for MVP)
187
+
188
+ - LLM integration for smarter query understanding
189
+ - Public agent marketplace
190
+ - Usage analytics dashboard
191
+ - API cost estimation before calls
192
+ - Multi-agent workflows
193
+ - Agent templates/presets
194
+ - On-chain storage for agent metadata (mentioned by user)
195
+
196
+ ## Notes
197
+
198
+ - All agent data stored locally in `.composer-data/` directory
199
+ - Private keys are stored in plain text (consider encryption for production)
200
+ - Base URL detection works in browser and server contexts
201
+ - Simple keyword-based API selection (can be enhanced with LLM later)
202
+
203
+
package/README.md CHANGED
@@ -30,7 +30,7 @@ Built for **machine-to-machine micropayments**, this SDK provides zero-friction
30
30
  - 🚚 **Header-Based Spec**: Payment specs and proofs handling moved entirely to headers.
31
31
  - ⚡ **Performance**: Significant speed improvements with bug fixes and optimizations.
32
32
 
33
- > ⚡ **Performance:** Latest optimizations deliver **faster settlement** with verification caching, async confirmation, and smart deduplication. See [PERFORMANCE_OPTIMIZATIONS.md](./PERFORMANCE_OPTIMIZATIONS.md) for details.
33
+ > ⚡ **Performance:** Latest optimizations deliver **faster settlement** with verification caching, async confirmation, and smart deduplication.
34
34
 
35
35
  <!-- ## Key Features
36
36
 
@@ -68,25 +68,7 @@ npm install aptos-x402
68
68
  - **TypeScript:** 5.x (recommended)
69
69
  - **Aptos SDK:** 1.26.0 or higher (included as peer dependency)
70
70
 
71
- ---
72
-
73
- ## 🤖 AI-Powered Setup (Cursor IDE)
74
-
75
- Get started in seconds with AI-assisted integration:
76
-
77
- ```bash
78
- mkdir -p .cursor/rules
79
- curl -o .cursor/rules/aptos-x402.mdc https://raw.githubusercontent.com/adipundir/aptos-x402/main/integration/aptos-x402.mdc
80
- ```
81
-
82
- **Restart Cursor IDE**, then ask:
83
- > "Set up Aptos x402 in my Next.js app with payment middleware and a test client component"
84
-
85
- The MDC context file provides Cursor with complete API documentation, types, and examples for accurate code generation.
86
71
 
87
- **Learn more:** [Cursor Integration Guide](./docs/guides/cursor-integration.md)
88
-
89
- ---
90
72
 
91
73
  ## 🛒 Client Integration (Consuming Paid APIs)
92
74
 
@@ -0,0 +1,82 @@
1
+ 'use client';
2
+
3
+ import { signIn } from 'next-auth/react';
4
+ import { useState } from 'react';
5
+ import { Button } from '@/components/ui/button';
6
+ import {
7
+ Dialog,
8
+ DialogContent,
9
+ DialogDescription,
10
+ DialogHeader,
11
+ DialogTitle,
12
+ } from '@/components/ui/dialog';
13
+ import { Loader2 } from 'lucide-react';
14
+ import { SiGoogle, SiGithub } from '@icons-pack/react-simple-icons';
15
+
16
+ interface LoginModalProps {
17
+ open: boolean;
18
+ onOpenChange: (open: boolean) => void;
19
+ }
20
+
21
+ export function LoginModal({ open, onOpenChange }: LoginModalProps) {
22
+ const [loading, setLoading] = useState<'google' | 'github' | null>(null);
23
+
24
+ const handleSignIn = async (provider: 'google' | 'github') => {
25
+ setLoading(provider);
26
+ try {
27
+ await signIn(provider, { callbackUrl: '/' });
28
+ } catch (error) {
29
+ console.error('Sign in error:', error);
30
+ setLoading(null);
31
+ }
32
+ };
33
+
34
+ return (
35
+ <Dialog open={open} onOpenChange={onOpenChange}>
36
+ <DialogContent className="sm:max-w-[380px] p-6 bg-white border border-zinc-200 shadow-xl rounded-xl">
37
+ <DialogHeader className="space-y-1 pb-2">
38
+ <DialogTitle className="text-lg font-semibold text-zinc-900">
39
+ Sign in
40
+ </DialogTitle>
41
+ <DialogDescription className="text-sm text-zinc-500">
42
+ Continue to Agent Composer (Beta)
43
+ </DialogDescription>
44
+ </DialogHeader>
45
+
46
+ <div className="space-y-3 pt-2">
47
+ <Button
48
+ onClick={() => handleSignIn('google')}
49
+ disabled={loading !== null}
50
+ variant="outline"
51
+ className="w-full h-11 bg-white hover:bg-zinc-50 text-zinc-900 border border-zinc-200 font-medium"
52
+ >
53
+ {loading === 'google' ? (
54
+ <Loader2 className="w-4 h-4 mr-2 animate-spin" />
55
+ ) : (
56
+ <SiGoogle className="w-4 h-4 mr-2" />
57
+ )}
58
+ Continue with Google
59
+ </Button>
60
+
61
+ <div className="relative">
62
+ <Button
63
+ disabled={true}
64
+ variant="outline"
65
+ className="w-full h-11 bg-zinc-50 text-zinc-400 border border-zinc-100 cursor-not-allowed font-medium"
66
+ >
67
+ <SiGithub className="w-4 h-4 mr-2 opacity-50" />
68
+ Continue with GitHub
69
+ </Button>
70
+ <span className="absolute right-3 top-1/2 -translate-y-1/2 text-[10px] px-1.5 py-0.5 bg-zinc-200 text-zinc-500 rounded font-medium">
71
+ Soon
72
+ </span>
73
+ </div>
74
+ </div>
75
+
76
+ <p className="text-[11px] text-zinc-400 text-center pt-3">
77
+ By continuing, you agree to our Terms & Privacy Policy
78
+ </p>
79
+ </DialogContent>
80
+ </Dialog>
81
+ );
82
+ }
@@ -0,0 +1,11 @@
1
+ 'use client';
2
+
3
+ import { SessionProvider as NextAuthSessionProvider } from 'next-auth/react';
4
+
5
+ export function SessionProvider({ children }: { children: React.ReactNode }) {
6
+ return <NextAuthSessionProvider>{children}</NextAuthSessionProvider>;
7
+ }
8
+
9
+
10
+
11
+
@@ -0,0 +1,8 @@
1
+ import { auth } from '@/lib/auth';
2
+ import { UserMenuClient } from './UserMenuClient';
3
+
4
+ export async function UserMenu() {
5
+ const session = await auth();
6
+
7
+ return <UserMenuClient session={session} />;
8
+ }
@@ -0,0 +1,117 @@
1
+ 'use client';
2
+
3
+ import { signOut } from 'next-auth/react';
4
+ import Link from 'next/link';
5
+ import { Button } from '@/components/ui/button';
6
+ import { LogOut, User, ChevronDown } from 'lucide-react';
7
+ import { useState, useRef, useEffect } from 'react';
8
+ import { LoginModal } from './LoginModal';
9
+ import type { Session } from 'next-auth';
10
+
11
+ interface UserMenuClientProps {
12
+ session: Session | null;
13
+ }
14
+
15
+ export function UserMenuClient({ session }: UserMenuClientProps) {
16
+ const [isOpen, setIsOpen] = useState(false);
17
+ const [loginModalOpen, setLoginModalOpen] = useState(false);
18
+ const menuRef = useRef<HTMLDivElement>(null);
19
+
20
+ useEffect(() => {
21
+ function handleClickOutside(event: MouseEvent) {
22
+ if (menuRef.current && !menuRef.current.contains(event.target as Node)) {
23
+ setIsOpen(false);
24
+ }
25
+ }
26
+ document.addEventListener('mousedown', handleClickOutside);
27
+ return () => document.removeEventListener('mousedown', handleClickOutside);
28
+ }, []);
29
+
30
+ if (!session) {
31
+ return (
32
+ <>
33
+ <Button
34
+ variant="outline"
35
+ size="sm"
36
+ className="border-zinc-200"
37
+ onClick={() => setLoginModalOpen(true)}
38
+ >
39
+ Sign In
40
+ </Button>
41
+ <LoginModal open={loginModalOpen} onOpenChange={setLoginModalOpen} />
42
+ </>
43
+ );
44
+ }
45
+
46
+ return (
47
+ <div className="relative" ref={menuRef}>
48
+ <button
49
+ onClick={() => setIsOpen(!isOpen)}
50
+ className="flex items-center gap-2 px-3 py-1.5 rounded-full bg-zinc-100 hover:bg-zinc-200 transition-colors"
51
+ >
52
+ {session.user?.image ? (
53
+ <img
54
+ src={session.user.image}
55
+ alt={session.user.name || 'User'}
56
+ className="w-7 h-7 rounded-full"
57
+ />
58
+ ) : (
59
+ <div className="w-7 h-7 rounded-full bg-zinc-900 flex items-center justify-center text-white text-sm font-medium">
60
+ {session.user?.name?.charAt(0) || 'U'}
61
+ </div>
62
+ )}
63
+ <span className="text-sm font-medium text-zinc-900 hidden sm:inline">
64
+ {session.user?.name?.split(' ')[0] || 'User'}
65
+ </span>
66
+ <ChevronDown className="w-4 h-4 text-zinc-500" />
67
+ </button>
68
+
69
+ {isOpen && (
70
+ <div className="absolute right-0 mt-2 w-72 rounded-xl bg-white shadow-lg border border-zinc-200 py-2 z-50">
71
+ <div className="px-4 py-3 border-b border-zinc-100">
72
+ <div className="flex items-center gap-3">
73
+ {session.user?.image ? (
74
+ <img
75
+ src={session.user.image}
76
+ alt={session.user.name || 'User'}
77
+ className="w-10 h-10 rounded-full"
78
+ />
79
+ ) : (
80
+ <div className="w-10 h-10 rounded-full bg-zinc-900 flex items-center justify-center text-white font-medium">
81
+ {session.user?.name?.charAt(0) || 'U'}
82
+ </div>
83
+ )}
84
+ <div className="flex-1 min-w-0">
85
+ <p className="text-sm font-medium text-zinc-900 truncate">
86
+ {session.user?.name || 'User'}
87
+ </p>
88
+ <p className="text-xs text-zinc-500 truncate">
89
+ {session.user?.email}
90
+ </p>
91
+ </div>
92
+ </div>
93
+ </div>
94
+
95
+ <div className="px-2 py-2">
96
+ <Link
97
+ href="/composer"
98
+ onClick={() => setIsOpen(false)}
99
+ className="flex items-center gap-3 px-3 py-2 rounded-lg hover:bg-zinc-50 transition-colors"
100
+ >
101
+ <User className="w-4 h-4 text-zinc-500" />
102
+ <span className="text-sm text-zinc-700">My Agents</span>
103
+ </Link>
104
+ <button
105
+ onClick={() => signOut({ callbackUrl: '/' })}
106
+ className="w-full flex items-center gap-3 px-3 py-2 rounded-lg hover:bg-red-50 transition-colors text-red-600"
107
+ >
108
+ <LogOut className="w-4 h-4" />
109
+ <span className="text-sm">Sign Out</span>
110
+ </button>
111
+ </div>
112
+ </div>
113
+ )}
114
+ </div>
115
+ );
116
+ }
117
+