@aeon-ai-pay/aigateway 0.1.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 (44) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/LICENSE +21 -0
  3. package/README.md +116 -0
  4. package/bin/cli.mjs +155 -0
  5. package/docs/env-vars.md +73 -0
  6. package/docs/exit-codes.md +65 -0
  7. package/docs/ide-setup.md +60 -0
  8. package/docs/output-schema.md +188 -0
  9. package/docs/recipes/cron-issue-cards.md +69 -0
  10. package/docs/recipes/error-recovery.md +53 -0
  11. package/docs/recipes/integrate-in-agent.md +108 -0
  12. package/docs/recipes/merchant-integration.md +243 -0
  13. package/docs/release-process.md +98 -0
  14. package/docs/troubleshooting.md +200 -0
  15. package/package.json +58 -0
  16. package/scripts/postinstall.mjs +40 -0
  17. package/skills/aigateway/SKILL.md +370 -0
  18. package/skills/aigateway/references/check-status.md +68 -0
  19. package/skills/aigateway/references/create-card.md +114 -0
  20. package/skills/aigateway/references/store.md +87 -0
  21. package/skills/aigateway/references/x402-protocol.md +143 -0
  22. package/src/balance.mjs +92 -0
  23. package/src/commands/clean.mjs +65 -0
  24. package/src/commands/create-card-status.mjs +67 -0
  25. package/src/commands/create-card.mjs +333 -0
  26. package/src/commands/create-image.mjs +428 -0
  27. package/src/commands/wallet-balance.mjs +47 -0
  28. package/src/commands/wallet-gas.mjs +99 -0
  29. package/src/commands/wallet-init.mjs +42 -0
  30. package/src/commands/wallet-topup.mjs +221 -0
  31. package/src/commands/wallet-withdraw.mjs +183 -0
  32. package/src/config.mjs +50 -0
  33. package/src/constants.mjs +22 -0
  34. package/src/error-codes.mjs +50 -0
  35. package/src/funding.mjs +216 -0
  36. package/src/output.mjs +85 -0
  37. package/src/sanitize.mjs +48 -0
  38. package/src/update-check.mjs +69 -0
  39. package/src/walletconnect.mjs +712 -0
  40. package/src/x402.mjs +120 -0
  41. package/templates/cline/.clinerules +53 -0
  42. package/templates/codex/AGENTS.md +56 -0
  43. package/templates/cursor/.cursor/rules/aigateway.mdc +60 -0
  44. package/templates/windsurf/.windsurfrules +48 -0
@@ -0,0 +1,98 @@
1
+ # Release Process
2
+
3
+ ## Versioning
4
+
5
+ We follow [SemVer](https://semver.org/):
6
+
7
+ - **Patch** (`0.1.0` → `0.1.1`) — bug fixes, doc edits, no breaking change.
8
+ - **Minor** (`0.1.0` → `0.2.0`) — new commands, new flags, new error codes. Existing envelope schema preserved.
9
+ - **Major** (`0.1.0` → `1.0.0`) — breaking envelope schema, renamed command, removed flag.
10
+
11
+ ## Two version numbers, kept in lock-step
12
+
13
+ | File | Field |
14
+ | --- | --- |
15
+ | `package.json` | `version` |
16
+ | `skills/aigateway/SKILL.md` | frontmatter `metadata.version` |
17
+
18
+ **Both must move together** every release. The npm version drives `update-check.mjs`; the skill version drives `npx skills add` re-copy to IDE folders.
19
+
20
+ ## Release checklist
21
+
22
+ 1. Ensure `main` is clean and CI-green.
23
+
24
+ 2. Bump both versions to the same value:
25
+
26
+ ```bash
27
+ # 1. package.json
28
+ npm version patch --no-git-tag-version # or `minor`, `major`, or explicit "0.1.1"
29
+
30
+ # 2. SKILL.md frontmatter
31
+ sed -i.bak -E 's/^( version: ").*"/\1'"$(jq -r .version package.json)"'"/' skills/aigateway/SKILL.md
32
+ rm skills/aigateway/SKILL.md.bak
33
+ ```
34
+
35
+ 3. Update `CHANGELOG.md` with notable changes.
36
+
37
+ 4. Commit and tag:
38
+
39
+ ```bash
40
+ VERSION=$(jq -r .version package.json)
41
+ git add package.json skills/aigateway/SKILL.md CHANGELOG.md
42
+ git commit -m "release $VERSION"
43
+ git tag "v$VERSION"
44
+ git push && git push --tags
45
+ ```
46
+
47
+ 5. Publish:
48
+
49
+ ```bash
50
+ npm publish --access public
51
+ ```
52
+
53
+ 6. Verify:
54
+
55
+ ```bash
56
+ npm view @aeon-ai-pay/aigateway version # should show the new version
57
+ aigateway --version # local still old until next call triggers auto-upgrade
58
+ ```
59
+
60
+ ## What happens for users after publish
61
+
62
+ `src/update-check.mjs` runs on every CLI invocation. Within a few seconds of the next `aigateway <cmd>` call by any user, they will:
63
+
64
+ 1. See `[update] @aeon-ai-pay/aigateway 0.1.0 → 0.1.1, upgrading in background...` on stderr.
65
+ 2. The current command still completes normally.
66
+ 3. A detached child process runs `npm install -g @aeon-ai-pay/aigateway@0.1.1` + `node scripts/postinstall.mjs`, which calls `npx skills add ... -g -y --copy`.
67
+ 4. The new `SKILL.md` is re-installed into every detected IDE skill folder (Cursor / Claude Code / Codex / Windsurf / Cline / …).
68
+ 5. Next invocation uses the new CLI and the new agent reads the new skill.
69
+
70
+ Upgrade results land in `~/.aigateway/update.log`.
71
+
72
+ ## Rolling back
73
+
74
+ `npm` releases are immutable. If you cut a bad release:
75
+
76
+ 1. Publish a **new** patch with the fix (`0.1.2`), don't try to overwrite.
77
+ 2. If users are blocked, you can `npm deprecate @aeon-ai-pay/aigateway@0.1.1 "Use 0.1.2 instead"` so new installs skip it.
78
+
79
+ ## Pre-release (optional)
80
+
81
+ For staging / beta:
82
+
83
+ ```bash
84
+ npm version 0.2.0-beta.1 --no-git-tag-version
85
+ # bump SKILL.md version manually to 0.2.0-beta.1
86
+ npm publish --tag beta --access public
87
+
88
+ # Users opt-in:
89
+ npm install -g @aeon-ai-pay/aigateway@beta
90
+ ```
91
+
92
+ `update-check.mjs` reads the `latest` tag by default, so beta users won't be silently bumped to `latest` until you mark a stable release.
93
+
94
+ ## When not to ship
95
+
96
+ - **Breaking envelope schema change** without a major bump. Downstream agents and merchants parse the envelope; renaming `data.orderNo` to `data.id` will break them.
97
+ - **Renaming a command** without a major bump (and at least one release of deprecation warnings).
98
+ - **`--service-url` re-added or removed** — keep config / env-var contract stable.
@@ -0,0 +1,200 @@
1
+ # Troubleshooting
2
+
3
+ Common issues you (or your users) may hit, and what to do about them.
4
+
5
+ ## Setup / Install
6
+
7
+ ### `aigateway: command not found` after `npm install -g`
8
+
9
+ The global `bin/` directory is not on your `PATH`. Find where npm installs:
10
+
11
+ ```bash
12
+ npm bin -g
13
+ # /Users/me/.nvm/versions/node/v25.0.0/bin
14
+ ```
15
+
16
+ Add that to `~/.zshrc` or `~/.bashrc`:
17
+
18
+ ```bash
19
+ export PATH="$(npm bin -g):$PATH"
20
+ ```
21
+
22
+ On macOS with `nvm`, the path changes when you switch Node versions — re-install globally after switching.
23
+
24
+ ### `aigateway requires Node.js >= 25`
25
+
26
+ `bin/cli.mjs` enforces the engine. Upgrade Node:
27
+
28
+ ```bash
29
+ nvm install 25 && nvm use 25
30
+ npm install -g @aeon-ai-pay/aigateway
31
+ ```
32
+
33
+ ### postinstall fails to install the skill
34
+
35
+ The error usually looks like `npx skills add ...` returned non-zero, then a fallback message. The CLI still works; only the skill isn't installed to your IDE. Install manually:
36
+
37
+ ```bash
38
+ npx skills add AEON-Project/aigateway -g -y
39
+ ```
40
+
41
+ If the skills CLI itself isn't on `PATH`, install it once: `npm install -g skills`.
42
+
43
+ For IDEs not covered by skills CLI, copy the matching `templates/<ide>/...` file — see [ide-setup.md](./ide-setup.md).
44
+
45
+ ## Wallet / Funding
46
+
47
+ ### "Wallet not configured. Run: aigateway wallet-init"
48
+
49
+ The CLI couldn't find `~/.aigateway/config.json` or it has no `privateKey` field. Run:
50
+
51
+ ```bash
52
+ aigateway wallet-init
53
+ ```
54
+
55
+ If you're in a custodial / server context, inject the key via env var instead:
56
+
57
+ ```bash
58
+ EVM_PRIVATE_KEY=0x... aigateway wallet-balance
59
+ ```
60
+
61
+ ### QR window doesn't open during `wallet-topup`
62
+
63
+ The CLI tries `open` (macOS) / `start` (Windows) / `xdg-open` (Linux). In headless environments, it prints the file path. Open `file:///tmp/aigateway-qr.html` manually in any browser. If you're on a remote VM, port-forward `127.0.0.1:<status-port>` (printed in stderr) and open the file locally instead.
64
+
65
+ **Headless servers should never run `wallet-topup` interactively** — see [merchant-integration.md § 3.3](./recipes/merchant-integration.md) for the workstation pre-funding pattern.
66
+
67
+ ### `error.code: PAYMENT_TIMEOUT`
68
+
69
+ The 5-minute WalletConnect approval window expired (you didn't scan / confirm in time). The session is automatically torn down. Re-run the same command from scratch. **Do not auto-retry** without user confirmation.
70
+
71
+ ### `error.code: PAYMENT_REJECTED`
72
+
73
+ You (or the user) tapped "Reject" in the wallet app. Same as above — re-run only with explicit user re-confirmation.
74
+
75
+ ### `error.code: TOPUP_REQUIRED` even though I topped up
76
+
77
+ Likely causes:
78
+ 1. The `wallet-topup` you ran was on a **different** session key. Verify `aigateway wallet-balance` shows the same address you funded.
79
+ 2. The on-chain tx hasn't confirmed yet. BSC normally confirms within 3 seconds; if longer, check `~/.aigateway/update.log` and the explorer.
80
+ 3. You funded in the wrong network (BSC vs. ETH). aigateway only reads USDT on **BSC** (chain id 56, contract `0x55d3...955`).
81
+
82
+ ### `error.code: INSUFFICIENT_BNB`
83
+
84
+ `wallet-withdraw` and the one-time approve in `wallet-topup` are direct on-chain transactions and need BNB for gas. Run:
85
+
86
+ ```bash
87
+ aigateway wallet-gas --amount 0.001
88
+ ```
89
+
90
+ (scans QR to send 0.001 BNB from main wallet to session key.) Then retry.
91
+
92
+ ### `error.code: WC_SESSION_EXPIRED` mid-flow
93
+
94
+ WalletConnect's relay sometimes drops the session between transactions in the same flow. Re-run the original command. If it persists, your wallet app may have been backgrounded too long — keep it foregrounded during the QR scan.
95
+
96
+ ### "Allowance check failed" / RPC errors
97
+
98
+ BSC's public RPCs occasionally rate-limit. The CLI uses QuickNode by default. If you hit transient errors:
99
+
100
+ ```bash
101
+ # retry after a couple of seconds
102
+ sleep 3 && aigateway wallet-balance
103
+ ```
104
+
105
+ If reproducible, file an issue.
106
+
107
+ ## Skill / Agent integration
108
+
109
+ ### Skill not picked up by Cursor / Windsurf / Cline / Codex
110
+
111
+ `npx skills add` doesn't auto-install to every IDE. For IDEs not covered, copy the matching template manually — see [ide-setup.md](./ide-setup.md).
112
+
113
+ Then restart the IDE. Some IDEs index rules files only at startup.
114
+
115
+ ### Agent doesn't trigger the skill even after install
116
+
117
+ Check the IDE's "skill / rules registry" UI (or equivalent). The trigger description has to match the user's intent vocabulary. If you customized SKILL.md, make sure the `description:` frontmatter still matches.
118
+
119
+ ### `skills/aigateway/SKILL.md` version doesn't reflect my edits
120
+
121
+ The skill version is locked to `metadata.version` in the frontmatter. If you edit SKILL.md but don't bump the version, the skills CLI may skip re-copying it on `skills update`. Bump it:
122
+
123
+ ```yaml
124
+ metadata:
125
+ version: "0.1.1" # was 0.1.0
126
+ ```
127
+
128
+ Then `npx skills add AEON-Project/aigateway -g -y -f` (force) or re-run postinstall.
129
+
130
+ ## Auto-upgrade (`update-check.mjs`)
131
+
132
+ ### Auto-upgrade doesn't seem to run
133
+
134
+ Check `~/.aigateway/update.log`. The upgrade is a detached background process and may take 1–2 minutes after the CLI is invoked. If the log shows a failure, the most common reasons are:
135
+
136
+ - Your global npm registry needs auth and the background process can't prompt.
137
+ - The user lacks permission to write to the global node_modules (run with sudo, or use nvm).
138
+
139
+ You can force-upgrade manually:
140
+
141
+ ```bash
142
+ npm install -g @aeon-ai-pay/aigateway@latest
143
+ ```
144
+
145
+ ### Block the auto-upgrade
146
+
147
+ Currently no flag for this — but the upgrade is **non-blocking** and won't affect the current command. If you need a deterministic version (e.g. in CI), pin the install:
148
+
149
+ ```bash
150
+ npm install -g @aeon-ai-pay/aigateway@0.1.0
151
+ ```
152
+
153
+ The check still runs but the install is idempotent at the same version.
154
+
155
+ ## Subprocess / spawn issues
156
+
157
+ ### `JSON.parse` fails on envelope
158
+
159
+ Causes:
160
+ 1. **stderr leaking into stdout**: you spawned without separating streams. Use `stdio: ["ignore", "pipe", "pipe"]` (or `"inherit"` for stderr) and read **stdout** only.
161
+ 2. **npm / nvm preamble**: tools like nvm print version banners on `npm` calls. The envelope is always the **last** line of stdout — use `stdout.trim().split("\n").pop()`.
162
+ 3. **Buffering**: pass `--quiet` to silence stderr progress logs and you'll get a single clean stdout line.
163
+
164
+ ### `--quiet` doesn't fully silence stderr
165
+
166
+ `--quiet` suppresses progress info but **errors** still go to stderr (for human readability). That's intentional — the structured error is also in the envelope (`envelope.error`) on stdout.
167
+
168
+ ### Spawning hangs forever
169
+
170
+ If you spawn `wallet-topup` / `create-card` / `create-image` in a context where the QR window can't be shown (CI, server, headless), the CLI waits 5 minutes for the WalletConnect signature, then exits with `PAYMENT_TIMEOUT`. **Never spawn these without pre-funded session keys** — see [merchant-integration.md § 3](./recipes/merchant-integration.md).
171
+
172
+ ## Service / network
173
+
174
+ ### `error.code: SERVICE_UNAVAILABLE`
175
+
176
+ Upstream is degraded. Retry with exponential backoff (1s → 4s → 16s, max 3 attempts). If it persists for more than 5 minutes, contact AEON support with the `appId` and an example `orderNo`.
177
+
178
+ ### Staging vs. production
179
+
180
+ The default service URL is `https://ai-api.aeon.xyz` (production). To use a staging endpoint:
181
+
182
+ ```bash
183
+ AIGATEWAY_SERVICE_URL=https://staging-x402.aeon.xyz aigateway create-card --amount 5
184
+ ```
185
+
186
+ ## Getting more diagnostics
187
+
188
+ - `--verbose` — verbose stderr logs
189
+ - `~/.aigateway/update.log` — auto-upgrade history
190
+ - `~/.aigateway/config.json` — wallet state (session key is sensitive)
191
+ - `cat /tmp/aigateway-qr.html` — last generated QR page (debug only)
192
+
193
+ ## Still stuck?
194
+
195
+ File an issue at https://github.com/AEON-Project/aigateway/issues with:
196
+
197
+ - Output of `aigateway --version`
198
+ - Full envelope JSON from the failing command (redact `address` if sensitive)
199
+ - Last 20 lines of `~/.aigateway/update.log` if upgrade-related
200
+ - Node version (`node -v`) and OS
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@aeon-ai-pay/aigateway",
3
+ "version": "0.1.0",
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
+ "type": "module",
6
+ "bin": {
7
+ "aigateway": "bin/cli.mjs"
8
+ },
9
+ "files": [
10
+ "bin",
11
+ "src",
12
+ "skills",
13
+ "scripts",
14
+ "docs",
15
+ "templates",
16
+ "README.md",
17
+ "CHANGELOG.md",
18
+ "LICENSE"
19
+ ],
20
+ "scripts": {
21
+ "postinstall": "node scripts/postinstall.mjs",
22
+ "create-card": "node bin/cli.mjs create-card",
23
+ "create-image": "node bin/cli.mjs create-image",
24
+ "wallet-init": "node bin/cli.mjs wallet-init",
25
+ "wallet-topup": "node bin/cli.mjs wallet-topup",
26
+ "wallet-balance": "node bin/cli.mjs wallet-balance",
27
+ "release": "node scripts/release.mjs"
28
+ },
29
+ "dependencies": {
30
+ "@aeon-ai-pay/axios": "2.1.2",
31
+ "@aeon-ai-pay/evm": "2.1.4",
32
+ "@walletconnect/sign-client": "^2.17.0",
33
+ "axios": "^1.13.2",
34
+ "commander": "^13.0.0",
35
+ "qrcode-terminal": "^0.12.0",
36
+ "viem": "^2.39.0"
37
+ },
38
+ "engines": {
39
+ "node": ">=25"
40
+ },
41
+ "keywords": [
42
+ "agent-os",
43
+ "aigateway",
44
+ "agent-skills",
45
+ "x402",
46
+ "virtual-card",
47
+ "ai-image",
48
+ "skill-boss",
49
+ "crypto-payment",
50
+ "evm",
51
+ "bsc"
52
+ ],
53
+ "repository": {
54
+ "type": "git",
55
+ "url": "git+https://github.com/AEON-Project/aigateway.git"
56
+ },
57
+ "license": "MIT"
58
+ }
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * npm install -g 后自动安装 skill 到所有已检测的 AI 编码工具
5
+ *
6
+ * 优先使用 `npx skills add` (Vercel Labs) 统一安装到所有工具
7
+ * 失败时 fallback 到手动复制 Claude Code skills 目录
8
+ */
9
+
10
+ import { cpSync, existsSync, mkdirSync } from 'node:fs';
11
+ import { join, dirname } from 'node:path';
12
+ import { homedir } from 'node:os';
13
+ import { execFileSync } from 'node:child_process';
14
+ import { fileURLToPath } from 'node:url';
15
+
16
+ const __dirname = dirname(fileURLToPath(import.meta.url));
17
+ const skillSrc = join(__dirname, '..', 'skills', 'aigateway');
18
+
19
+ if (!existsSync(skillSrc)) {
20
+ process.exit(0);
21
+ }
22
+
23
+ // 尝试用 skills CLI 安装到所有工具
24
+ try {
25
+ execFileSync('npx', ['skills', 'add', skillSrc, '-g', '-y', '--copy'], {
26
+ stdio: 'inherit',
27
+ timeout: 30000,
28
+ cwd: join(__dirname, '..'),
29
+ });
30
+ console.log('✔ aigateway skill installed via skills CLI (all detected tools)');
31
+ process.exit(0);
32
+ } catch {
33
+ // skills CLI 不可用或失败,fallback
34
+ }
35
+
36
+ // Fallback: 手动复制到 Claude Code
37
+ const dest = join(homedir(), '.claude', 'skills', 'aigateway');
38
+ mkdirSync(dirname(dest), { recursive: true });
39
+ cpSync(skillSrc, dest, { recursive: true, force: true });
40
+ console.log(`✔ aigateway skill installed to ${dest} (fallback)`);