@aeon-ai-pay/aigateway 0.1.0 → 0.1.1
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/CHANGELOG.md +12 -0
- package/package.json +1 -1
- package/skills/aigateway/SKILL.md +58 -21
- package/src/commands/wallet-init.mjs +70 -8
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.1.1] — 2026-05-19
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
- **`wallet-init` now reports full funding status**, not just local-key readiness. Envelope `data` adds:
|
|
14
|
+
`usdt`, `bnb`, `allowance`, `needsTopup`, `topupReason` (`no_prior_funding` / `low_balance` / `no_approve`),
|
|
15
|
+
`minTopup`, `presets`, `chainCheck`. Agents can decide the next step (`wallet-topup` vs. go straight to a paid
|
|
16
|
+
call) from this single envelope without a separate `wallet-balance` call.
|
|
17
|
+
- **SKILL.md workflow re-ordered** so agents prompt the user for a top-up amount **before** invoking the first
|
|
18
|
+
paid command, eliminating the previous "try-create-card → fail with `TOPUP_REQUIRED` → ask amount" UX bug.
|
|
19
|
+
- SKILL.md adds an "If `aigateway` is not found (exit 127)" fallback that instructs the agent to run
|
|
20
|
+
`npm install -g @aeon-ai-pay/aigateway` once and retry.
|
|
21
|
+
|
|
10
22
|
## [0.1.0] — 2026-05-18
|
|
11
23
|
|
|
12
24
|
Initial release of **AEON AI Gateway**, merging the prior `@aeon-ai-pay/aicard` and `@aeon-ai-pay/agentos` projects into a single unified CLI and agent skill.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeon-ai-pay/aigateway",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "AI Agents discover, invoke, and settle paid LLMs, APIs, and Skills — starting with Skill Boss. No manual key setup. No prepayment. Pay-per-call via x402 or Agent Card.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -16,7 +16,7 @@ description: >
|
|
|
16
16
|
emoji: "🛰️"
|
|
17
17
|
homepage: https://github.com/AEON-Project/aigateway
|
|
18
18
|
metadata:
|
|
19
|
-
version: "0.1.
|
|
19
|
+
version: "0.1.1"
|
|
20
20
|
author: AEON-Project
|
|
21
21
|
openclaw:
|
|
22
22
|
requires:
|
|
@@ -73,13 +73,13 @@ See [docs/output-schema.md](../../docs/output-schema.md) and [docs/exit-codes.md
|
|
|
73
73
|
## Command Overview
|
|
74
74
|
|
|
75
75
|
```bash
|
|
76
|
-
aigateway wallet-init # Pre-check /
|
|
76
|
+
aigateway wallet-init # Pre-check / create wallet AND report needsTopup status (one-stop pre-flight)
|
|
77
77
|
aigateway wallet-topup [--amount <usdt>] # WalletConnect: top-up USDT (≥5; presets 5/10/20/50) + first-time facilitator approve
|
|
78
78
|
aigateway create-card --amount <usd> --poll # Issue a virtual card ($0.6 ~ $800)
|
|
79
79
|
aigateway create-image --prompt "<text>" # Generate AI image
|
|
80
80
|
aigateway create-card-status --order-no <orderNo> [--poll] # Query card status
|
|
81
|
-
aigateway wallet-balance #
|
|
82
|
-
aigateway wallet-gas [--amount <bnb>]
|
|
81
|
+
aigateway wallet-balance # (optional) Re-query balance — agent rarely needs this; wallet-init already reports it
|
|
82
|
+
aigateway wallet-gas [--amount <bnb>] # Top up BNB for session key (for withdraw)
|
|
83
83
|
aigateway wallet-withdraw [--to <addr>] [--amount <usdt>] # Reclaim funds
|
|
84
84
|
aigateway clean # Uninstall skill, clear cache
|
|
85
85
|
```
|
|
@@ -104,33 +104,70 @@ Output template:
|
|
|
104
104
|
> Pre-check in progress...
|
|
105
105
|
```
|
|
106
106
|
|
|
107
|
-
|
|
107
|
+
### If `aigateway` is not found (exit 127 / "command not found")
|
|
108
108
|
|
|
109
|
-
|
|
110
|
-
- `created: false`, `ready: true` → "0x0...{last4} Ready."
|
|
111
|
-
- Record `amountLimits.{min,max}` for any subsequent card amount validation.
|
|
109
|
+
The CLI hasn't been installed on this host yet. Output to the user **verbatim**:
|
|
112
110
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
111
|
+
```
|
|
112
|
+
> Installing aigateway...
|
|
113
|
+
```
|
|
116
114
|
|
|
117
|
-
|
|
115
|
+
Then run **in the foreground** (this can take 30–60 seconds; do **not** background it):
|
|
118
116
|
|
|
119
117
|
```bash
|
|
120
|
-
|
|
121
|
-
aigateway wallet-topup --amount 5 # Non-interactive (recommended for agent invocations)
|
|
118
|
+
npm install -g @aeon-ai-pay/aigateway
|
|
122
119
|
```
|
|
123
120
|
|
|
124
|
-
|
|
121
|
+
After install completes, re-run `aigateway wallet-init`. If `npm install` itself fails (network / permissions), surface the raw error and ask the user to fix their npm environment.
|
|
122
|
+
|
|
123
|
+
### Envelope on success
|
|
124
|
+
|
|
125
|
+
`envelope.data` (full shape):
|
|
126
|
+
|
|
127
|
+
```json
|
|
128
|
+
{
|
|
129
|
+
"ready": true,
|
|
130
|
+
"created": false,
|
|
131
|
+
"address": "0x...",
|
|
132
|
+
"mainWallet": "0x..." | null,
|
|
133
|
+
"usdt": "5.0",
|
|
134
|
+
"bnb": "0.0003",
|
|
135
|
+
"allowance": "115792...max" | "0",
|
|
136
|
+
"needsTopup": false,
|
|
137
|
+
"topupReason": null | "no_prior_funding" | "low_balance" | "no_approve",
|
|
138
|
+
"minTopup": 5,
|
|
139
|
+
"presets": [5, 10, 20, 50],
|
|
140
|
+
"amountLimits": { "min": 0.6, "max": 800 }
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Decision tree (this is the whole pre-flight)
|
|
145
|
+
|
|
146
|
+
| Field | Action |
|
|
147
|
+
| --- | --- |
|
|
148
|
+
| `created: true` | "Auto-creating your designated wallet..." + "0x0...{last4} Ready." |
|
|
149
|
+
| `created: false`, `ready: true` | "0x0...{last4} Ready." |
|
|
150
|
+
| **`needsTopup: true`** | **Go to Step 2 immediately.** Use `presets` / `minTopup` from this envelope (don't hardcode). |
|
|
151
|
+
| `needsTopup: false` | Wallet has enough USDT and is approved. **Skip Step 2** and jump straight to the user's intent (`create-card` / `create-image` / other). |
|
|
125
152
|
|
|
126
|
-
|
|
153
|
+
Record `amountLimits.{min,max}` for any subsequent card amount validation.
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
## Step 2: Top up (only if Step 1's envelope says `needsTopup: true`)
|
|
158
|
+
|
|
159
|
+
Trigger: `wallet-init` envelope reports `needsTopup: true` (any of `no_prior_funding` / `low_balance` / `no_approve`), **or** the user explicitly asks to top up / load funds.
|
|
127
160
|
|
|
128
161
|
### Amount selection
|
|
129
162
|
|
|
130
163
|
- Presets: **5 / 10 / 20 / 50 USDT**. Custom amounts must be ≥ 5 USDT.
|
|
131
|
-
-
|
|
164
|
+
- Ask the user **before** running the command:
|
|
132
165
|
> How much USDT would you like to load? (presets: 5 / 10 / 20 / 50, or any custom amount ≥ 5)
|
|
133
|
-
- Once the user picks an amount, run
|
|
166
|
+
- Once the user picks an amount, run:
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
aigateway wallet-topup --amount <n> # always pass --amount in agent context
|
|
170
|
+
```
|
|
134
171
|
|
|
135
172
|
### Output template
|
|
136
173
|
|
|
@@ -151,8 +188,8 @@ Approve: {approveTx truncated or "already approved"}
|
|
|
151
188
|
|
|
152
189
|
| `error.code` | Action |
|
|
153
190
|
| --- | --- |
|
|
154
|
-
| `TOPUP_REQUIRED` (
|
|
155
|
-
| `TOPUP_AMOUNT_TOO_SMALL` | Show `error.minTopup`, ask
|
|
191
|
+
| `TOPUP_REQUIRED` (would only happen if you skipped Step 2) | Bug in agent — should have asked for amount in Step 3. Ask now, then rerun with `--amount <n>`. |
|
|
192
|
+
| `TOPUP_AMOUNT_TOO_SMALL` | Show `error.minTopup`, ask the user for a larger amount. |
|
|
156
193
|
| `PAYMENT_REJECTED` | User cancelled in wallet. **Do not auto-retry**; ask user. |
|
|
157
194
|
| `PAYMENT_TIMEOUT` | 5-minute WalletConnect window expired. **Do not auto-retry**; ask user. |
|
|
158
195
|
| `INSUFFICIENT_BNB` (post-funding) | Run `aigateway wallet-gas` (interactive) to add BNB, then retry. |
|
|
@@ -164,7 +201,7 @@ Approve: {approveTx truncated or "already approved"}
|
|
|
164
201
|
|
|
165
202
|
## Step 3a: Create Virtual Card
|
|
166
203
|
|
|
167
|
-
Trigger: user wants to **buy / create / get a virtual card
|
|
204
|
+
Trigger: user wants to **buy / create / get a virtual card** *and* Step 1 envelope showed `needsTopup: false` (or Step 2 just completed successfully).
|
|
168
205
|
|
|
169
206
|
### Amount confirmation
|
|
170
207
|
|
|
@@ -1,15 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* init
|
|
2
|
+
* wallet-init:本地 session 钱包 check / 创建 + 链上状态评估
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* 步骤:
|
|
5
|
+
* 1. 若 ~/.aigateway/config.json 缺 privateKey → 用 viem.generatePrivateKey() 生成
|
|
6
|
+
* 2. 查 USDT / BNB 余额(除非刚 created,则跳过查询直接判定为 needsTopup)
|
|
7
|
+
* 3. 查 facilitator allowance(同上规则)
|
|
8
|
+
* 4. 综合判定 needsTopup 与原因,返回完整就绪状态供 agent 决策
|
|
7
9
|
*
|
|
8
|
-
*
|
|
10
|
+
* 设计意图:agent 跑完 wallet-init 一条命令就拿到决策依据:
|
|
11
|
+
* - data.ready=true 表示钱包私钥可用
|
|
12
|
+
* - data.needsTopup=true → 必须先 wallet-topup(envelope 里附带 presets / minTopup / reason)
|
|
13
|
+
* - data.needsTopup=false → 可直接 create-card / create-image
|
|
9
14
|
*/
|
|
10
15
|
import { loadConfig, saveConfig } from "../config.mjs";
|
|
11
16
|
import { MIN_AMOUNT, MAX_AMOUNT } from "../constants.mjs";
|
|
12
|
-
import {
|
|
17
|
+
import { getWalletBalance, getAllowance } from "../balance.mjs";
|
|
18
|
+
import {
|
|
19
|
+
LOW_BALANCE_THRESHOLD,
|
|
20
|
+
MIN_TOPUP_USDT,
|
|
21
|
+
TOPUP_PRESETS,
|
|
22
|
+
} from "../funding.mjs";
|
|
23
|
+
import { emitOk, logInfo } from "../output.mjs";
|
|
13
24
|
|
|
14
25
|
export async function initWallet(opts) {
|
|
15
26
|
const config = loadConfig();
|
|
@@ -25,18 +36,69 @@ export async function initWallet(opts) {
|
|
|
25
36
|
config.mode = "private-key";
|
|
26
37
|
created = true;
|
|
27
38
|
saveConfig(config);
|
|
39
|
+
logInfo(`Auto-created session wallet: ${config.address}`);
|
|
40
|
+
} else {
|
|
41
|
+
logInfo(`Wallet: ${config.address}`);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// 链上状态评估
|
|
45
|
+
let usdt = "0";
|
|
46
|
+
let bnb = "0";
|
|
47
|
+
let usdtNum = 0;
|
|
48
|
+
let allowance = 0n;
|
|
49
|
+
let chainCheckOk = true;
|
|
50
|
+
let chainCheckError = null;
|
|
51
|
+
|
|
52
|
+
if (created) {
|
|
53
|
+
// 刚建好的钱包余额必然为 0,跳过链上查询节省 ~500ms
|
|
54
|
+
logInfo("Fresh wallet — skipping balance lookup (assumed empty).");
|
|
55
|
+
} else {
|
|
56
|
+
try {
|
|
57
|
+
const bal = await getWalletBalance(config.privateKey);
|
|
58
|
+
usdt = bal.usdt;
|
|
59
|
+
bnb = bal.bnb;
|
|
60
|
+
usdtNum = parseFloat(usdt);
|
|
61
|
+
logInfo(`Balance: ${usdt} USDT, ${bnb} BNB`);
|
|
62
|
+
allowance = await getAllowance(config.address);
|
|
63
|
+
logInfo(`Allowance: ${allowance === 0n ? "0 (approve required)" : "already approved"}`);
|
|
64
|
+
} catch (e) {
|
|
65
|
+
chainCheckOk = false;
|
|
66
|
+
chainCheckError = e.message;
|
|
67
|
+
logInfo(`Chain status check failed: ${e.message}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// 决策:是否需要 topup
|
|
72
|
+
let needsTopup = false;
|
|
73
|
+
let topupReason = null;
|
|
74
|
+
if (created || !config.mainWallet) {
|
|
75
|
+
needsTopup = true;
|
|
76
|
+
topupReason = "no_prior_funding";
|
|
77
|
+
} else if (chainCheckOk && usdtNum < LOW_BALANCE_THRESHOLD) {
|
|
78
|
+
needsTopup = true;
|
|
79
|
+
topupReason = "low_balance";
|
|
80
|
+
} else if (chainCheckOk && allowance === 0n) {
|
|
81
|
+
needsTopup = true;
|
|
82
|
+
topupReason = "no_approve";
|
|
28
83
|
}
|
|
29
84
|
|
|
30
|
-
const ready = !!(config.serviceUrl && config.privateKey);
|
|
31
85
|
const data = {
|
|
32
|
-
ready,
|
|
86
|
+
ready: true,
|
|
33
87
|
created,
|
|
34
88
|
appId,
|
|
35
89
|
mode: config.mode || null,
|
|
36
90
|
address: config.address || null,
|
|
37
91
|
mainWallet: config.mainWallet || null,
|
|
38
92
|
serviceUrl: config.serviceUrl || null,
|
|
93
|
+
usdt,
|
|
94
|
+
bnb,
|
|
95
|
+
allowance: allowance.toString(),
|
|
96
|
+
needsTopup,
|
|
97
|
+
topupReason, // "no_prior_funding" | "low_balance" | "no_approve" | null
|
|
98
|
+
minTopup: MIN_TOPUP_USDT,
|
|
99
|
+
presets: TOPUP_PRESETS,
|
|
39
100
|
amountLimits: { min: MIN_AMOUNT, max: MAX_AMOUNT },
|
|
101
|
+
chainCheck: chainCheckOk ? "ok" : { error: chainCheckError },
|
|
40
102
|
};
|
|
41
103
|
emitOk("wallet-init", data, data);
|
|
42
104
|
}
|