autonomo-sdk 0.1.4 → 0.1.6
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/LICENSE +21 -21
- package/README.md +174 -174
- package/dist/cli.js +63 -57
- package/dist/index.d.ts +16 -2
- package/dist/index.js +19 -6
- package/package.json +50 -50
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Autonomo
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Autonomo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,174 +1,174 @@
|
|
|
1
|
-
# Autonomo SDK for TypeScript
|
|
2
|
-
|
|
3
|
-
One call for AI agents. Say what you need, and the SDK:
|
|
4
|
-
|
|
5
|
-
1. **Finds the right API** on [Autonomo](https://autonomo.fun), from your words and the kind of input you give
|
|
6
|
-
(a token or wallet address, a transaction hash, a link).
|
|
7
|
-
2. **Pays for it** with x402, in USDG or $AUTONOMO on Robinhood Chain, or USDC on Base, whichever the wallet can afford.
|
|
8
|
-
3. **Pays privately through [Gloam](https://gloam.trade)** when you ask, so the payment doesn't link to your wallet.
|
|
9
|
-
4. **Borrows from a [Borro](https://borro.markets) credit line** when the wallet is short of USDG.
|
|
10
|
-
5. **Keeps to your caps**: a most-per-call and a daily budget, checked before anything is signed.
|
|
11
|
-
6. **Returns the answer and a receipt**: which API, how it was paid, the amount and the transaction link.
|
|
12
|
-
|
|
13
|
-
```bash
|
|
14
|
-
npm install autonomo-sdk
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
Full examples for each way to pay: [autonomo.fun/docs/sdk](https://autonomo.fun/docs/sdk).
|
|
18
|
-
|
|
19
|
-
```ts
|
|
20
|
-
import { Autonomo } from "autonomo-sdk";
|
|
21
|
-
|
|
22
|
-
const autonomo = new Autonomo({ privateKey: process.env.AUTONOMO_WALLET_KEY });
|
|
23
|
-
|
|
24
|
-
const { data, receipt } = await autonomo.call("is this token safe", {
|
|
25
|
-
input: "0x86b57bcb9d249cf096cf8e21426c9dc9cafdec49",
|
|
26
|
-
});
|
|
27
|
-
console.log(data);
|
|
28
|
-
console.log(receipt.route, receipt.amount, receipt.token, receipt.explorer);
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
Use a **new wallet just for the agent**, holding only what it may spend. A little USDG covers many calls (most APIs
|
|
32
|
-
cost
|
|
33
|
-
|
|
34
|
-
## Finding APIs without paying
|
|
35
|
-
|
|
36
|
-
```ts
|
|
37
|
-
const autonomo = new Autonomo(); // no key needed to look
|
|
38
|
-
await autonomo.find("wallet holdings"); // best matches first
|
|
39
|
-
await autonomo.quote("explain this transaction", { input: "0x…" }); // the API, the URL and every price
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
To skip the search, name the API: `autonomo.call("", { slug: "token-risk", path: "/risk/0x…" })`.
|
|
43
|
-
|
|
44
|
-
To see what the wallet can pay with, `await autonomo.balances()` returns what it holds on both chains: USDG,
|
|
45
|
-
$AUTONOMO and ETH on Robinhood Chain, and USDC on Base. It only reads.
|
|
46
|
-
|
|
47
|
-
## From the terminal
|
|
48
|
-
|
|
49
|
-
The package also installs a command, for people and for agents that run shell commands. `find`, `quote`, `spend` and
|
|
50
|
-
`--dry-run` need no wallet:
|
|
51
|
-
|
|
52
|
-
```bash
|
|
53
|
-
npx autonomo-sdk find "wallet holdings"
|
|
54
|
-
npx autonomo-sdk risk 0x86b57bcb9d249cf096cf8e21426c9dc9cafdec49 --dry-run # the price, without paying
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
To pay, put the agent wallet's key in `AUTONOMO_WALLET_KEY`. It's never taken as a flag, so it stays out of your
|
|
58
|
-
shell history.
|
|
59
|
-
|
|
60
|
-
```bash
|
|
61
|
-
npx autonomo-sdk risk 0x86b57bcb9d249cf096cf8e21426c9dc9cafdec49
|
|
62
|
-
npx autonomo-sdk call "explain this transaction" 0x… --max 0.02 --daily 0.5 --json
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
| Command | |
|
|
66
|
-
| --- | --- |
|
|
67
|
-
| `find [words] [input]` | List APIs, best matches first |
|
|
68
|
-
| `quote <words> [input]` | The API a call would use, and its prices |
|
|
69
|
-
| `call <words> [input]` | Find the right API, pay for one call, print the answer |
|
|
70
|
-
| `price [token]`, `launches [n]`, `risk <token>`, `holders <token>`, `dev <token>`, `tx <hash>`, `payment <hash>`, `portfolio <wallet>`, `gas`, `read <link>`, `site <link or domain>`, `health <link>`, `jobs <words>` | Shortcuts for the official APIs |
|
|
71
|
-
| `spend` | Today's spending against your limits |
|
|
72
|
-
| `wallet` | What the wallet holds on Robinhood Chain and Base |
|
|
73
|
-
|
|
74
|
-
`--chain base` (or `robinhood`) goes with the shortcuts that read a chain: `price` with a token, `launches`, `risk`,
|
|
75
|
-
`holders`, `dev`, `tx`, `payment`, `portfolio` and `gas`. Left out, they read Robinhood Chain, and Base when the
|
|
76
|
-
token, wallet or transaction is only there.
|
|
77
|
-
|
|
78
|
-
`--max` and `--daily` set the USDG limits (`--max-autonomo` and `--daily-autonomo` for $AUTONOMO), `--pay-with`
|
|
79
|
-
picks the token and `--borro <credit line>` borrows when the wallet is short. At a terminal it shows the price and
|
|
80
|
-
asks before paying; `--yes` skips the question, and scripts are never asked. The answer goes to stdout and the
|
|
81
|
-
receipt to stderr, so piping into `jq` works, and `--json` prints `{ data, receipt }` as one object. Exit codes: 0
|
|
82
|
-
done, 1 failed, 2 bad usage, 3 over a limit, 4 can't pay, 5 payment refused, 6 no such API.
|
|
83
|
-
|
|
84
|
-
After `npm install -g autonomo-sdk` the command is `autonomo`. (`npx autonomo` is someone else's package.)
|
|
85
|
-
|
|
86
|
-
### Paying privately from the terminal
|
|
87
|
-
|
|
88
|
-
```bash
|
|
89
|
-
npx autonomo-sdk risk 0x86b57bcb9d249cf096cf8e21426c9dc9cafdec49 --private --dry-run # the private price
|
|
90
|
-
npx autonomo-sdk risk 0x86b57bcb9d249cf096cf8e21426c9dc9cafdec49 --private # pay from Gloam
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
`--private` pays from your private Gloam balance, so the payment doesn't link to a wallet. The command starts Gloam's
|
|
94
|
-
own server (`npx -y @gloamtrade/mcp`) on your machine for that one payment and stops it afterwards.
|
|
95
|
-
|
|
96
|
-
- Set Gloam up once: its key and limits go in `~/.gloam/agent.env` and USDG goes into its private balance (see
|
|
97
|
-
[Pay privately with Gloam](https://autonomo.fun/docs/sdk#pay-privately-with-gloam)). The command never reads
|
|
98
|
-
Gloam's key, and Gloam's server is never given `AUTONOMO_WALLET_KEY`.
|
|
99
|
-
- No `AUTONOMO_WALLET_KEY` is needed for private calls.
|
|
100
|
-
- The price includes Gloam's fee and counts against `--max` and `--daily`. It can't be combined with `--pay-with`
|
|
101
|
-
or `--borro`.
|
|
102
|
-
- Paying can take a few minutes, since Gloam builds the payment's proofs on your machine.
|
|
103
|
-
- If Gloam paid but the API didn't answer, the error prints a payment header: run the same command again with
|
|
104
|
-
`--retry-header <header>` to get the answer without paying twice.
|
|
105
|
-
|
|
106
|
-
## Limits
|
|
107
|
-
|
|
108
|
-
```ts
|
|
109
|
-
new Autonomo({
|
|
110
|
-
privateKey,
|
|
111
|
-
payWith: "auto", // or "usdg" / "autonomo" / "usdc" (USDC on Base)
|
|
112
|
-
limits: {
|
|
113
|
-
perCall: { usdg: "0.
|
|
114
|
-
daily: { usdg: "
|
|
115
|
-
},
|
|
116
|
-
});
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
A call over a limit is refused before anything is signed, with the reason. Spending is kept in
|
|
120
|
-
`~/.autonomo/spend.json` (shared with the Python SDK); pass `spendStore: memoryStore()` or your own store to change
|
|
121
|
-
that.
|
|
122
|
-
|
|
123
|
-
## Private payments with Gloam
|
|
124
|
-
|
|
125
|
-
`private: true` pays from a private Gloam balance through Gloam's own MCP server, `@gloamtrade/mcp`, running on your
|
|
126
|
-
machine with its key and limits in `~/.gloam/agent.env`. The SDK calls its `gloam_fetch_paid` tool; Gloam cashes out
|
|
127
|
-
exactly the price through its relay and calls the API with it. The SDK holds no Gloam keys, and no wallet key is needed.
|
|
128
|
-
See the [SDK guide](https://autonomo.fun/docs/sdk) for the setup and a full example.
|
|
129
|
-
|
|
130
|
-
```ts
|
|
131
|
-
const autonomo = new Autonomo({
|
|
132
|
-
gloam: {
|
|
133
|
-
fetchPaid: async (args) => {
|
|
134
|
-
// gloam: an MCP client for @gloamtrade/mcp. A private payment can take a few minutes, so wait up to 5.
|
|
135
|
-
const out = await gloam.callTool({ name: "gloam_fetch_paid", arguments: args }, undefined, { timeout: 300_000 });
|
|
136
|
-
return JSON.parse((out.content as Array<{ text: string }>)[0].text);
|
|
137
|
-
},
|
|
138
|
-
},
|
|
139
|
-
});
|
|
140
|
-
await autonomo.call("newest launches", { private: true });
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
A private call only ever pays through Gloam. If the API doesn't offer it, or Gloam isn't set up, it's refused, never
|
|
144
|
-
sent as a public payment. The price includes Gloam's cash-out fee (about 0.0105 USDG for a 0.01 call).
|
|
145
|
-
|
|
146
|
-
## Borrowing with Borro
|
|
147
|
-
|
|
148
|
-
```ts
|
|
149
|
-
const autonomo = new Autonomo({ privateKey, borro: { account: "0xYourCreditLine" } });
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
When the wallet can't afford a call, the SDK asks Borro's MCP server to prepare a borrow of just what it's short,
|
|
153
|
-
sends it from the wallet (this needs a little ETH for gas), waits for the USDG and pays. The line needs x402 bills
|
|
154
|
-
turned on; see [Pay with a Borro credit line](https://autonomo.fun/docs/borro). Borro's own daily limit still applies.
|
|
155
|
-
|
|
156
|
-
Borro's answer is checked before anything is signed. The SDK sends only one transaction: a `borrow` on your own credit
|
|
157
|
-
line, into this wallet, with no ETH attached, of no more than the call's price. Anything else in the answer, such as a
|
|
158
|
-
transfer, an approval or a second transaction, is refused with `borro_unsafe` and nothing is sent. The call's price is
|
|
159
|
-
still checked against your caps first.
|
|
160
|
-
|
|
161
|
-
## The receipt
|
|
162
|
-
|
|
163
|
-
| Field | |
|
|
164
|
-
| --- | --- |
|
|
165
|
-
| `api` | The API's slug and name |
|
|
166
|
-
| `route` | `usdg`, `autonomo`, `usdc`, `gloam` or `borro` |
|
|
167
|
-
| `amount`, `token`, `chain` | What was paid, and on which chain: `Robinhood Chain` or `Base` |
|
|
168
|
-
| `payer`, `payTo` | The wallet (or "private (Gloam)") and the API's payment address |
|
|
169
|
-
| `tx`, `explorer` | The payment transaction and its link on Blockscout, or on Basescan for Base |
|
|
170
|
-
| `borrowTxs`, `approveTx` | Borro borrows and the one-time Permit2 approval, when there were any |
|
|
171
|
-
| `spentToday` | Today's total against the daily budget |
|
|
172
|
-
|
|
173
|
-
Errors are `AutonomoError` with a `code` such as `cannot_pay`, `over_limit`, `no_private_option` or `payment_refused`.
|
|
174
|
-
If an API fails after a payment is signed, the payment doesn't settle, so you aren't charged.
|
|
1
|
+
# Autonomo SDK for TypeScript
|
|
2
|
+
|
|
3
|
+
One call for AI agents. Say what you need, and the SDK:
|
|
4
|
+
|
|
5
|
+
1. **Finds the right API** on [Autonomo](https://autonomo.fun), from your words and the kind of input you give
|
|
6
|
+
(a token or wallet address, a transaction hash, a link).
|
|
7
|
+
2. **Pays for it** with x402, in USDG or $AUTONOMO on Robinhood Chain, or USDC on Base, whichever the wallet can afford.
|
|
8
|
+
3. **Pays privately through [Gloam](https://gloam.trade)** when you ask, so the payment doesn't link to your wallet.
|
|
9
|
+
4. **Borrows from a [Borro](https://borro.markets) credit line** when the wallet is short of USDG.
|
|
10
|
+
5. **Keeps to your caps**: a most-per-call and a daily budget, checked before anything is signed.
|
|
11
|
+
6. **Returns the answer and a receipt**: which API, how it was paid, the amount and the transaction link.
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install autonomo-sdk
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Full examples for each way to pay: [autonomo.fun/docs/sdk](https://autonomo.fun/docs/sdk).
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { Autonomo } from "autonomo-sdk";
|
|
21
|
+
|
|
22
|
+
const autonomo = new Autonomo({ privateKey: process.env.AUTONOMO_WALLET_KEY });
|
|
23
|
+
|
|
24
|
+
const { data, receipt } = await autonomo.call("is this token safe", {
|
|
25
|
+
input: "0x86b57bcb9d249cf096cf8e21426c9dc9cafdec49",
|
|
26
|
+
});
|
|
27
|
+
console.log(data);
|
|
28
|
+
console.log(receipt.route, receipt.amount, receipt.token, receipt.explorer);
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Use a **new wallet just for the agent**, holding only what it may spend. A little USDG covers many calls (most APIs
|
|
32
|
+
cost a few cents). Paying in $AUTONOMO needs a little ETH once, for a Permit2 approval. Node 20 or later.
|
|
33
|
+
|
|
34
|
+
## Finding APIs without paying
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
const autonomo = new Autonomo(); // no key needed to look
|
|
38
|
+
await autonomo.find("wallet holdings"); // best matches first
|
|
39
|
+
await autonomo.quote("explain this transaction", { input: "0x…" }); // the API, the URL and every price
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
To skip the search, name the API: `autonomo.call("", { slug: "token-risk", path: "/risk/0x…" })`.
|
|
43
|
+
|
|
44
|
+
To see what the wallet can pay with, `await autonomo.balances()` returns what it holds on both chains: USDG,
|
|
45
|
+
$AUTONOMO and ETH on Robinhood Chain, and USDC on Base. It only reads.
|
|
46
|
+
|
|
47
|
+
## From the terminal
|
|
48
|
+
|
|
49
|
+
The package also installs a command, for people and for agents that run shell commands. `find`, `quote`, `spend` and
|
|
50
|
+
`--dry-run` need no wallet:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
npx autonomo-sdk find "wallet holdings"
|
|
54
|
+
npx autonomo-sdk risk 0x86b57bcb9d249cf096cf8e21426c9dc9cafdec49 --dry-run # the price, without paying
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
To pay, put the agent wallet's key in `AUTONOMO_WALLET_KEY`. It's never taken as a flag, so it stays out of your
|
|
58
|
+
shell history.
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
npx autonomo-sdk risk 0x86b57bcb9d249cf096cf8e21426c9dc9cafdec49
|
|
62
|
+
npx autonomo-sdk call "explain this transaction" 0x… --max 0.02 --daily 0.5 --json
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
| Command | |
|
|
66
|
+
| --- | --- |
|
|
67
|
+
| `find [words] [input]` | List APIs, best matches first |
|
|
68
|
+
| `quote <words> [input]` | The API a call would use, and its prices |
|
|
69
|
+
| `call <words> [input]` | Find the right API, pay for one call, print the answer |
|
|
70
|
+
| `price [token]`, `launches [n]`, `risk <token>`, `holders <token>`, `dev <token>`, `tx <hash>`, `payment <hash>`, `portfolio <wallet>`, `gas`, `read <link>`, `site <link or domain>`, `health <link>`, `jobs <words>` | Shortcuts for the official APIs |
|
|
71
|
+
| `spend` | Today's spending against your limits |
|
|
72
|
+
| `wallet` | What the wallet holds on Robinhood Chain and Base |
|
|
73
|
+
|
|
74
|
+
`--chain base` (or `robinhood`) goes with the shortcuts that read a chain: `price` with a token, `launches`, `risk`,
|
|
75
|
+
`holders`, `dev`, `tx`, `payment`, `portfolio` and `gas`. Left out, they read Robinhood Chain, and Base when the
|
|
76
|
+
token, wallet or transaction is only there.
|
|
77
|
+
|
|
78
|
+
`--max` and `--daily` set the USDG limits (`--max-autonomo` and `--daily-autonomo` for $AUTONOMO), `--pay-with`
|
|
79
|
+
picks the token and `--borro <credit line>` borrows when the wallet is short. At a terminal it shows the price and
|
|
80
|
+
asks before paying; `--yes` skips the question, and scripts are never asked. The answer goes to stdout and the
|
|
81
|
+
receipt to stderr, so piping into `jq` works, and `--json` prints `{ data, receipt }` as one object. Exit codes: 0
|
|
82
|
+
done, 1 failed, 2 bad usage, 3 over a limit, 4 can't pay, 5 payment refused, 6 no such API.
|
|
83
|
+
|
|
84
|
+
After `npm install -g autonomo-sdk` the command is `autonomo`. (`npx autonomo` is someone else's package.)
|
|
85
|
+
|
|
86
|
+
### Paying privately from the terminal
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
npx autonomo-sdk risk 0x86b57bcb9d249cf096cf8e21426c9dc9cafdec49 --private --dry-run # the private price
|
|
90
|
+
npx autonomo-sdk risk 0x86b57bcb9d249cf096cf8e21426c9dc9cafdec49 --private # pay from Gloam
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
`--private` pays from your private Gloam balance, so the payment doesn't link to a wallet. The command starts Gloam's
|
|
94
|
+
own server (`npx -y @gloamtrade/mcp`) on your machine for that one payment and stops it afterwards.
|
|
95
|
+
|
|
96
|
+
- Set Gloam up once: its key and limits go in `~/.gloam/agent.env` and USDG goes into its private balance (see
|
|
97
|
+
[Pay privately with Gloam](https://autonomo.fun/docs/sdk#pay-privately-with-gloam)). The command never reads
|
|
98
|
+
Gloam's key, and Gloam's server is never given `AUTONOMO_WALLET_KEY`.
|
|
99
|
+
- No `AUTONOMO_WALLET_KEY` is needed for private calls.
|
|
100
|
+
- The price includes Gloam's fee and counts against `--max` and `--daily`. It can't be combined with `--pay-with`
|
|
101
|
+
or `--borro`.
|
|
102
|
+
- Paying can take a few minutes, since Gloam builds the payment's proofs on your machine.
|
|
103
|
+
- If Gloam paid but the API didn't answer, the error prints a payment header: run the same command again with
|
|
104
|
+
`--retry-header <header>` to get the answer without paying twice.
|
|
105
|
+
|
|
106
|
+
## Limits
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
new Autonomo({
|
|
110
|
+
privateKey,
|
|
111
|
+
payWith: "auto", // or "usdg" / "autonomo" / "usdc" (USDC on Base)
|
|
112
|
+
limits: {
|
|
113
|
+
perCall: { usdg: "0.5", autonomo: "5000" }, // the defaults
|
|
114
|
+
daily: { usdg: "5", autonomo: "10000" }, // per UTC day; Gloam and Borro count as USDG
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
A call over a limit is refused before anything is signed, with the reason. Spending is kept in
|
|
120
|
+
`~/.autonomo/spend.json` (shared with the Python SDK); pass `spendStore: memoryStore()` or your own store to change
|
|
121
|
+
that.
|
|
122
|
+
|
|
123
|
+
## Private payments with Gloam
|
|
124
|
+
|
|
125
|
+
`private: true` pays from a private Gloam balance through Gloam's own MCP server, `@gloamtrade/mcp`, running on your
|
|
126
|
+
machine with its key and limits in `~/.gloam/agent.env`. The SDK calls its `gloam_fetch_paid` tool; Gloam cashes out
|
|
127
|
+
exactly the price through its relay and calls the API with it. The SDK holds no Gloam keys, and no wallet key is needed.
|
|
128
|
+
See the [SDK guide](https://autonomo.fun/docs/sdk) for the setup and a full example.
|
|
129
|
+
|
|
130
|
+
```ts
|
|
131
|
+
const autonomo = new Autonomo({
|
|
132
|
+
gloam: {
|
|
133
|
+
fetchPaid: async (args) => {
|
|
134
|
+
// gloam: an MCP client for @gloamtrade/mcp. A private payment can take a few minutes, so wait up to 5.
|
|
135
|
+
const out = await gloam.callTool({ name: "gloam_fetch_paid", arguments: args }, undefined, { timeout: 300_000 });
|
|
136
|
+
return JSON.parse((out.content as Array<{ text: string }>)[0].text);
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
await autonomo.call("newest launches", { private: true });
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
A private call only ever pays through Gloam. If the API doesn't offer it, or Gloam isn't set up, it's refused, never
|
|
144
|
+
sent as a public payment. The price includes Gloam's cash-out fee (about 0.0105 USDG for a 0.01 call).
|
|
145
|
+
|
|
146
|
+
## Borrowing with Borro
|
|
147
|
+
|
|
148
|
+
```ts
|
|
149
|
+
const autonomo = new Autonomo({ privateKey, borro: { account: "0xYourCreditLine" } });
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
When the wallet can't afford a call, the SDK asks Borro's MCP server to prepare a borrow of just what it's short,
|
|
153
|
+
sends it from the wallet (this needs a little ETH for gas), waits for the USDG and pays. The line needs x402 bills
|
|
154
|
+
turned on; see [Pay with a Borro credit line](https://autonomo.fun/docs/borro). Borro's own daily limit still applies.
|
|
155
|
+
|
|
156
|
+
Borro's answer is checked before anything is signed. The SDK sends only one transaction: a `borrow` on your own credit
|
|
157
|
+
line, into this wallet, with no ETH attached, of no more than the call's price. Anything else in the answer, such as a
|
|
158
|
+
transfer, an approval or a second transaction, is refused with `borro_unsafe` and nothing is sent. The call's price is
|
|
159
|
+
still checked against your caps first.
|
|
160
|
+
|
|
161
|
+
## The receipt
|
|
162
|
+
|
|
163
|
+
| Field | |
|
|
164
|
+
| --- | --- |
|
|
165
|
+
| `api` | The API's slug and name |
|
|
166
|
+
| `route` | `usdg`, `autonomo`, `usdc`, `gloam` or `borro` |
|
|
167
|
+
| `amount`, `token`, `chain` | What was paid, and on which chain: `Robinhood Chain` or `Base` |
|
|
168
|
+
| `payer`, `payTo` | The wallet (or "private (Gloam)") and the API's payment address |
|
|
169
|
+
| `tx`, `explorer` | The payment transaction and its link on Blockscout, or on Basescan for Base |
|
|
170
|
+
| `borrowTxs`, `approveTx` | Borro borrows and the one-time Permit2 approval, when there were any |
|
|
171
|
+
| `spentToday` | Today's total against the daily budget |
|
|
172
|
+
|
|
173
|
+
Errors are `AutonomoError` with a `code` such as `cannot_pay`, `over_limit`, `no_private_option` or `payment_refused`.
|
|
174
|
+
If an API fails after a payment is signed, the payment doesn't settle, so you aren't charged.
|
package/dist/cli.js
CHANGED
|
@@ -15,63 +15,64 @@ import { createInterface } from "node:readline/promises";
|
|
|
15
15
|
import { fileURLToPath } from "node:url";
|
|
16
16
|
import { parseArgs } from "node:util";
|
|
17
17
|
import { formatUnits } from "viem";
|
|
18
|
+
import { privateKeyToAccount } from "viem/accounts";
|
|
18
19
|
import { startGloam } from "./gloam.js";
|
|
19
20
|
import { Autonomo, AutonomoError, DEFAULT_LIMITS, TOKENS, VERSION, fileStore } from "./index.js";
|
|
20
21
|
export const EXIT = { ok: 0, failed: 1, usage: 2, overLimit: 3, cannotPay: 4, refused: 5, notFound: 6 };
|
|
21
|
-
const HELP = `Autonomo CLI ${VERSION}: find and pay for APIs on autonomo.fun
|
|
22
|
-
|
|
23
|
-
Usage
|
|
24
|
-
autonomo find [words] [input] List APIs, best matches first. Free.
|
|
25
|
-
autonomo quote <words> [input] The API a call would use and its prices. Free.
|
|
26
|
-
autonomo call <words> [input] Find the right API, pay for one call, print the answer.
|
|
27
|
-
autonomo spend Today's spending against your limits.
|
|
28
|
-
autonomo wallet What the wallet holds on Robinhood Chain and Base.
|
|
29
|
-
|
|
30
|
-
Shortcuts for the official APIs
|
|
31
|
-
autonomo price [token address] $AUTONOMO's price, or any token's
|
|
32
|
-
autonomo launches [how many] Newest token launches
|
|
33
|
-
autonomo risk <token address> Rug-risk check
|
|
34
|
-
autonomo holders <token address> Top holders, bundles and snipers
|
|
35
|
-
autonomo dev <token address> What the token's creator did
|
|
36
|
-
autonomo tx <transaction hash> A transaction in plain words
|
|
37
|
-
autonomo payment <tx hash> Did an x402 payment settle, and who paid whom
|
|
38
|
-
autonomo portfolio <wallet> What a wallet holds
|
|
39
|
-
autonomo gas The gas price and what common actions cost
|
|
40
|
-
autonomo read <https link> A web page's text
|
|
41
|
-
autonomo site <link or domain> Trust check for a website
|
|
42
|
-
autonomo health <https link> Is an x402 API up and payable
|
|
43
|
-
autonomo jobs <the work> Open paid jobs on Tokyo Futuro
|
|
44
|
-
|
|
45
|
-
Options
|
|
46
|
-
--max <dollars> Most to pay for one call in USDG or USDC (default ${DEFAULT_LIMITS.perCall.usdg})
|
|
47
|
-
--daily <dollars> Most to spend per UTC day in USDG and USDC together (default ${DEFAULT_LIMITS.daily.usdg})
|
|
48
|
-
--max-autonomo <amount> The same two limits when paying in $AUTONOMO
|
|
49
|
-
--daily-autonomo <amount> (defaults ${DEFAULT_LIMITS.perCall.autonomo} and ${DEFAULT_LIMITS.daily.autonomo})
|
|
50
|
-
--pay-with <token> usdg, autonomo, usdc or auto (default: USDG, then $AUTONOMO, then USDC on Base)
|
|
51
|
-
--chain <chain> robinhood or base, for the shortcuts that read a chain: price with a token, launches, risk,
|
|
52
|
-
holders, dev, tx, payment, portfolio and gas. Left out: Robinhood Chain, and Base when the
|
|
53
|
-
token, wallet or transaction is only there
|
|
54
|
-
--borro <credit line> Borrow from this Borro line when the wallet is short of USDG
|
|
55
|
-
--private Pay from your private Gloam balance, so the payment doesn't link to a wallet
|
|
56
|
-
--retry-header <header> With --private: finish a call Gloam paid for but the API didn't answer, without paying again
|
|
57
|
-
--slug <api> --path <p> With call or quote: use this API and path, skipping the search
|
|
58
|
-
--dry-run Show the price instead of paying
|
|
59
|
-
--yes Don't ask before paying
|
|
60
|
-
--json One JSON object on stdout: { data, receipt }
|
|
61
|
-
--help, --version
|
|
62
|
-
|
|
63
|
-
Wallet
|
|
64
|
-
Set AUTONOMO_WALLET_KEY to the private key of a wallet made just for the agent, holding only what it may spend.
|
|
65
|
-
The same wallet pays with USDG or $AUTONOMO on Robinhood Chain, or with USDC on Base; it needs no ETH on either.
|
|
66
|
-
find, quote, spend and --dry-run need no wallet. wallet only reads balances and signs nothing.
|
|
67
|
-
|
|
68
|
-
Private payments
|
|
69
|
-
--private starts Gloam's own server on this machine (npx @gloamtrade/mcp) and has it pay in USDG. It needs no
|
|
70
|
-
AUTONOMO_WALLET_KEY: Gloam uses its own key and limits from ~/.gloam/agent.env, and that key is never read by
|
|
71
|
-
this command. Deposit USDG into Gloam's private balance first. The price includes Gloam's fee, counts against
|
|
72
|
-
--max and --daily, and paying can take a few minutes. Setup: autonomo.fun/docs/sdk#pay-privately-with-gloam
|
|
73
|
-
|
|
74
|
-
Exit codes
|
|
22
|
+
const HELP = `Autonomo CLI ${VERSION}: find and pay for APIs on autonomo.fun
|
|
23
|
+
|
|
24
|
+
Usage
|
|
25
|
+
autonomo find [words] [input] List APIs, best matches first. Free.
|
|
26
|
+
autonomo quote <words> [input] The API a call would use and its prices. Free.
|
|
27
|
+
autonomo call <words> [input] Find the right API, pay for one call, print the answer.
|
|
28
|
+
autonomo spend Today's spending against your limits.
|
|
29
|
+
autonomo wallet What the wallet holds on Robinhood Chain and Base.
|
|
30
|
+
|
|
31
|
+
Shortcuts for the official APIs
|
|
32
|
+
autonomo price [token address] $AUTONOMO's price, or any token's
|
|
33
|
+
autonomo launches [how many] Newest token launches
|
|
34
|
+
autonomo risk <token address> Rug-risk check
|
|
35
|
+
autonomo holders <token address> Top holders, bundles and snipers
|
|
36
|
+
autonomo dev <token address> What the token's creator did
|
|
37
|
+
autonomo tx <transaction hash> A transaction in plain words
|
|
38
|
+
autonomo payment <tx hash> Did an x402 payment settle, and who paid whom
|
|
39
|
+
autonomo portfolio <wallet> What a wallet holds
|
|
40
|
+
autonomo gas The gas price and what common actions cost
|
|
41
|
+
autonomo read <https link> A web page's text
|
|
42
|
+
autonomo site <link or domain> Trust check for a website
|
|
43
|
+
autonomo health <https link> Is an x402 API up and payable
|
|
44
|
+
autonomo jobs <the work> Open paid jobs on Tokyo Futuro
|
|
45
|
+
|
|
46
|
+
Options
|
|
47
|
+
--max <dollars> Most to pay for one call in USDG or USDC (default ${DEFAULT_LIMITS.perCall.usdg})
|
|
48
|
+
--daily <dollars> Most to spend per UTC day in USDG and USDC together (default ${DEFAULT_LIMITS.daily.usdg})
|
|
49
|
+
--max-autonomo <amount> The same two limits when paying in $AUTONOMO
|
|
50
|
+
--daily-autonomo <amount> (defaults ${DEFAULT_LIMITS.perCall.autonomo} and ${DEFAULT_LIMITS.daily.autonomo})
|
|
51
|
+
--pay-with <token> usdg, autonomo, usdc or auto (default: USDG, then $AUTONOMO, then USDC on Base)
|
|
52
|
+
--chain <chain> robinhood or base, for the shortcuts that read a chain: price with a token, launches, risk,
|
|
53
|
+
holders, dev, tx, payment, portfolio and gas. Left out: Robinhood Chain, and Base when the
|
|
54
|
+
token, wallet or transaction is only there
|
|
55
|
+
--borro <credit line> Borrow from this Borro line when the wallet is short of USDG
|
|
56
|
+
--private Pay from your private Gloam balance, so the payment doesn't link to a wallet
|
|
57
|
+
--retry-header <header> With --private: finish a call Gloam paid for but the API didn't answer, without paying again
|
|
58
|
+
--slug <api> --path <p> With call or quote: use this API and path, skipping the search
|
|
59
|
+
--dry-run Show the price instead of paying
|
|
60
|
+
--yes Don't ask before paying
|
|
61
|
+
--json One JSON object on stdout: { data, receipt }
|
|
62
|
+
--help, --version
|
|
63
|
+
|
|
64
|
+
Wallet
|
|
65
|
+
Set AUTONOMO_WALLET_KEY to the private key of a wallet made just for the agent, holding only what it may spend.
|
|
66
|
+
The same wallet pays with USDG or $AUTONOMO on Robinhood Chain, or with USDC on Base; it needs no ETH on either.
|
|
67
|
+
find, quote, spend and --dry-run need no wallet. wallet only reads balances and signs nothing.
|
|
68
|
+
|
|
69
|
+
Private payments
|
|
70
|
+
--private starts Gloam's own server on this machine (npx @gloamtrade/mcp) and has it pay in USDG. It needs no
|
|
71
|
+
AUTONOMO_WALLET_KEY: Gloam uses its own key and limits from ~/.gloam/agent.env, and that key is never read by
|
|
72
|
+
this command. Deposit USDG into Gloam's private balance first. The price includes Gloam's fee, counts against
|
|
73
|
+
--max and --daily, and paying can take a few minutes. Setup: autonomo.fun/docs/sdk#pay-privately-with-gloam
|
|
74
|
+
|
|
75
|
+
Exit codes
|
|
75
76
|
0 done 1 failed 2 bad usage 3 over a limit 4 can't pay 5 payment refused 6 no such API`;
|
|
76
77
|
const ADDRESS = /^0x[0-9a-fA-F]{40}$/;
|
|
77
78
|
const TX_HASH = /^0x[0-9a-fA-F]{64}$/;
|
|
@@ -363,12 +364,17 @@ export async function run(argv, io) {
|
|
|
363
364
|
usage("--chain goes with the shortcuts. With call or quote, put chain=base in --path instead.");
|
|
364
365
|
}
|
|
365
366
|
if (quoteOnly) {
|
|
366
|
-
|
|
367
|
+
// The price is shown for the agent's wallet when its key is set, so a holder sees the holder price. Nothing is signed.
|
|
368
|
+
const key = io.env.AUTONOMO_WALLET_KEY?.trim();
|
|
369
|
+
const payer = key && /^0x[0-9a-fA-F]{64}$/.test(key) ? privateKeyToAccount(key).address : undefined;
|
|
370
|
+
const q = await client(false).quote(words, { ...opts, payer });
|
|
367
371
|
if (json)
|
|
368
372
|
return print(q), EXIT.ok;
|
|
369
373
|
io.out(`${q.api.name} (${q.api.slug})\n ${q.url}`);
|
|
370
374
|
for (const o of q.offers)
|
|
371
375
|
io.out(` ${o.amount} ${o.token}${o.private ? " private, through Gloam" : ""}`);
|
|
376
|
+
if (q.holderPrice)
|
|
377
|
+
io.out(` Holder price: half, because ${payer} held $20 of Autonomo-token on average yesterday.`);
|
|
372
378
|
return EXIT.ok;
|
|
373
379
|
}
|
|
374
380
|
if (values.private) {
|
|
@@ -441,14 +447,14 @@ export async function run(argv, io) {
|
|
|
441
447
|
if (io.interactive && !values.yes) {
|
|
442
448
|
const q = await autonomo.quote(words, opts);
|
|
443
449
|
const prices = q.offers.filter((o) => !o.private).map((o) => `${o.amount} ${o.token}`).join(" or ");
|
|
444
|
-
if (!(await io.confirm(`${q.api.name} costs ${prices}. Pay from ${autonomo.address}? [y/N] `)))
|
|
450
|
+
if (!(await io.confirm(`${q.api.name} costs ${prices}${q.holderPrice ? " (holder price)" : ""}. Pay from ${autonomo.address}? [y/N] `)))
|
|
445
451
|
return io.err("Not paid."), EXIT.ok;
|
|
446
452
|
}
|
|
447
453
|
const { data, receipt } = await autonomo.call(words, opts);
|
|
448
454
|
if (json)
|
|
449
455
|
return print({ data, receipt }), EXIT.ok;
|
|
450
456
|
print(data);
|
|
451
|
-
io.err(`Paid ${receipt.amount} ${receipt.token} to ${receipt.api.name}${receipt.route === "borro" ? " on Borro credit" : ""}. Today: ${receipt.spentToday}.`);
|
|
457
|
+
io.err(`Paid ${receipt.amount} ${receipt.token} to ${receipt.api.name}${receipt.holderPrice ? " at the holder price" : ""}${receipt.route === "borro" ? " on Borro credit" : ""}. Today: ${receipt.spentToday}.`);
|
|
452
458
|
if (receipt.explorer)
|
|
453
459
|
io.err(receipt.explorer);
|
|
454
460
|
return EXIT.ok;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Hex } from "viem";
|
|
2
|
-
export declare const VERSION = "0.1.
|
|
2
|
+
export declare const VERSION = "0.1.6";
|
|
3
3
|
export type TokenName = "usdg" | "autonomo" | "usdc";
|
|
4
4
|
/** The tokens with limits of their own. USDC on Base is held to the USDG (dollar) limits. */
|
|
5
5
|
type LimitName = "usdg" | "autonomo";
|
|
@@ -26,7 +26,7 @@ export declare const DEFAULT_LIMITS: {
|
|
|
26
26
|
};
|
|
27
27
|
};
|
|
28
28
|
export type Limits = {
|
|
29
|
-
/** Most to pay for one call, in whole tokens, e.g. { usdg: "0.
|
|
29
|
+
/** Most to pay for one call, in whole tokens, e.g. { usdg: "0.5" }. The usdg limit covers USDC on Base too. */
|
|
30
30
|
perCall?: Partial<Record<LimitName, string>>;
|
|
31
31
|
/** Most to spend per UTC day, in whole tokens. USDC on Base, Gloam and Borro payments count against the usdg limit. */
|
|
32
32
|
daily?: Partial<Record<LimitName, string>>;
|
|
@@ -104,6 +104,11 @@ export type CallOptions = {
|
|
|
104
104
|
private?: boolean;
|
|
105
105
|
/** Override payWith for this call. */
|
|
106
106
|
payWith?: TokenName | "auto";
|
|
107
|
+
/**
|
|
108
|
+
* The wallet to show prices for, when quoting without a key. With a key it is that wallet. A wallet that held $20 of
|
|
109
|
+
* Autonomo-token on average the day before is shown, and pays, the holder price on Autonomo's official APIs: half.
|
|
110
|
+
*/
|
|
111
|
+
payer?: string;
|
|
107
112
|
};
|
|
108
113
|
export type Route = "usdg" | "autonomo" | "usdc" | "gloam" | "borro";
|
|
109
114
|
export type Receipt = {
|
|
@@ -125,6 +130,8 @@ export type Receipt = {
|
|
|
125
130
|
approveTx: string | null;
|
|
126
131
|
at: string;
|
|
127
132
|
spentToday: string;
|
|
133
|
+
/** Paid at the holder price: half, because the wallet held $20 of Autonomo-token on average the day before. */
|
|
134
|
+
holderPrice: boolean;
|
|
128
135
|
};
|
|
129
136
|
export type CallResult<T = unknown> = {
|
|
130
137
|
data: T;
|
|
@@ -179,6 +186,8 @@ export declare class Autonomo {
|
|
|
179
186
|
quote(query: string, opts?: CallOptions): Promise<{
|
|
180
187
|
api: Api;
|
|
181
188
|
url: string;
|
|
189
|
+
/** The prices are the holder price: half (see CallOptions.payer). */
|
|
190
|
+
holderPrice: boolean;
|
|
182
191
|
offers: {
|
|
183
192
|
scheme: string;
|
|
184
193
|
token: string;
|
|
@@ -193,6 +202,11 @@ export declare class Autonomo {
|
|
|
193
202
|
private get;
|
|
194
203
|
private gatewayUrl;
|
|
195
204
|
private resolve;
|
|
205
|
+
private readonly holder;
|
|
206
|
+
/**
|
|
207
|
+
* The 402 price list for a call. The paying wallet is named in X-Autonomo-Payer, so a wallet that has the holder
|
|
208
|
+
* price is shown it. The gateway checks the wallet that signs the payment, so naming one proves nothing on its own.
|
|
209
|
+
*/
|
|
196
210
|
private priceList;
|
|
197
211
|
/**
|
|
198
212
|
* Signs an x402 exact payment (EIP-3009 for USDG and USDC on Base, Permit2 for $AUTONOMO) and sends the request with
|
package/dist/index.js
CHANGED
|
@@ -17,7 +17,7 @@ import { homedir } from "node:os";
|
|
|
17
17
|
import { dirname, join } from "node:path";
|
|
18
18
|
import { createPublicClient, createWalletClient, defineChain, erc20Abi, formatEther, formatUnits, getAddress, http, maxUint256, parseUnits, toHex, } from "viem";
|
|
19
19
|
import { privateKeyToAccount } from "viem/accounts";
|
|
20
|
-
export const VERSION = "0.1.
|
|
20
|
+
export const VERSION = "0.1.6";
|
|
21
21
|
const NETWORK = "eip155:4663";
|
|
22
22
|
const CHAIN_ID = 4663;
|
|
23
23
|
const EXPLORER = "https://robinhoodchain.blockscout.com";
|
|
@@ -33,8 +33,8 @@ export const TOKENS = {
|
|
|
33
33
|
};
|
|
34
34
|
const limitOf = (t) => (t === "autonomo" ? "autonomo" : "usdg");
|
|
35
35
|
export const DEFAULT_LIMITS = {
|
|
36
|
-
perCall: { usdg: "0.
|
|
37
|
-
daily: { usdg: "
|
|
36
|
+
perCall: { usdg: "0.5", autonomo: "5000" },
|
|
37
|
+
daily: { usdg: "5", autonomo: "10000" },
|
|
38
38
|
};
|
|
39
39
|
export class AutonomoError extends Error {
|
|
40
40
|
code;
|
|
@@ -236,10 +236,12 @@ export class Autonomo {
|
|
|
236
236
|
/** What a call would cost, without paying. */
|
|
237
237
|
async quote(query, opts = {}) {
|
|
238
238
|
const { api, url } = await this.resolve(query, opts);
|
|
239
|
-
const required = await this.priceList(url);
|
|
239
|
+
const required = await this.priceList(url, opts.payer);
|
|
240
240
|
return {
|
|
241
241
|
api,
|
|
242
242
|
url,
|
|
243
|
+
/** The prices are the holder price: half (see CallOptions.payer). */
|
|
244
|
+
holderPrice: this.holder.get(required) === true,
|
|
243
245
|
offers: required.accepts.map((a) => {
|
|
244
246
|
const t = tokenByAsset(a.asset, a.network);
|
|
245
247
|
const label = t ? (t.name === "usdc" ? "USDC on Base" : t.symbol) : a.asset;
|
|
@@ -254,6 +256,7 @@ export class Autonomo {
|
|
|
254
256
|
const account = this.account;
|
|
255
257
|
const { api, url } = await this.resolve(query, opts);
|
|
256
258
|
const required = await this.priceList(url);
|
|
259
|
+
const holderPrice = this.holder.get(required) === true;
|
|
257
260
|
const day = today();
|
|
258
261
|
const spent = await this.store.get(day);
|
|
259
262
|
const pay = async (route, token, amount, send) => {
|
|
@@ -298,6 +301,7 @@ export class Autonomo {
|
|
|
298
301
|
approveTx: null,
|
|
299
302
|
at: new Date().toISOString(),
|
|
300
303
|
spentToday: `${formatUnits(after, token.decimals)} of ${formatUnits(this.daily[limit], token.decimals)} ${unit}`,
|
|
304
|
+
holderPrice: holderPrice && route !== "gloam",
|
|
301
305
|
...extra,
|
|
302
306
|
};
|
|
303
307
|
return { data: data, receipt };
|
|
@@ -416,8 +420,16 @@ export class Autonomo {
|
|
|
416
420
|
}
|
|
417
421
|
return { api, url: this.gatewayUrl(api.slug, opts.path ?? fill(api.path, opts.input)) };
|
|
418
422
|
}
|
|
419
|
-
|
|
420
|
-
|
|
423
|
+
// Which price lists came at the holder price, as the gateway said in X-Autonomo-Holder-Price.
|
|
424
|
+
holder = new WeakMap();
|
|
425
|
+
/**
|
|
426
|
+
* The 402 price list for a call. The paying wallet is named in X-Autonomo-Payer, so a wallet that has the holder
|
|
427
|
+
* price is shown it. The gateway checks the wallet that signs the payment, so naming one proves nothing on its own.
|
|
428
|
+
*/
|
|
429
|
+
async priceList(url, payer) {
|
|
430
|
+
const who = payer ?? this.account?.address;
|
|
431
|
+
const headers = who && /^0x[0-9a-fA-F]{40}$/.test(who) ? { "X-Autonomo-Payer": who } : {};
|
|
432
|
+
const res = await this.fetch(url, { headers, signal: AbortSignal.timeout(20_000) });
|
|
421
433
|
let required = unb64(res.headers.get("payment-required"));
|
|
422
434
|
if (!required && res.status === 402) {
|
|
423
435
|
try {
|
|
@@ -434,6 +446,7 @@ export class Autonomo {
|
|
|
434
446
|
fail("updating", "This API is paused or being updated. Try again later.");
|
|
435
447
|
if (res.status !== 402 || !Array.isArray(required?.accepts))
|
|
436
448
|
fail("no_price", `Expected a 402 price list from ${url}, got ${res.status}.`);
|
|
449
|
+
this.holder.set(required, res.headers.get("x-autonomo-holder-price") === "half");
|
|
437
450
|
return required;
|
|
438
451
|
}
|
|
439
452
|
/**
|
package/package.json
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "autonomo-sdk",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "One call for AI agents: find the right paid API on Autonomo, pay in USDG or $AUTONOMO (privately through Gloam, or on Borro credit), within spending caps, and get a receipt.",
|
|
5
|
-
"homepage": "https://autonomo.fun",
|
|
6
|
-
"author": "Autonomo (https://autonomo.fun)",
|
|
7
|
-
"license": "MIT",
|
|
8
|
-
"type": "module",
|
|
9
|
-
"main": "dist/index.js",
|
|
10
|
-
"types": "dist/index.d.ts",
|
|
11
|
-
"exports": {
|
|
12
|
-
".": {
|
|
13
|
-
"types": "./dist/index.d.ts",
|
|
14
|
-
"import": "./dist/index.js"
|
|
15
|
-
}
|
|
16
|
-
},
|
|
17
|
-
"files": [
|
|
18
|
-
"dist",
|
|
19
|
-
"README.md",
|
|
20
|
-
"LICENSE"
|
|
21
|
-
],
|
|
22
|
-
"engines": {
|
|
23
|
-
"node": ">=20"
|
|
24
|
-
},
|
|
25
|
-
"scripts": {
|
|
26
|
-
"build": "tsc -p .",
|
|
27
|
-
"test": "node --test test/*.test.mjs"
|
|
28
|
-
},
|
|
29
|
-
"keywords": [
|
|
30
|
-
"x402",
|
|
31
|
-
"autonomo",
|
|
32
|
-
"ai-agents",
|
|
33
|
-
"robinhood-chain",
|
|
34
|
-
"usdg",
|
|
35
|
-
"payments",
|
|
36
|
-
"gloam",
|
|
37
|
-
"borro"
|
|
38
|
-
],
|
|
39
|
-
"dependencies": {
|
|
40
|
-
"viem": "2.57.12"
|
|
41
|
-
},
|
|
42
|
-
"devDependencies": {
|
|
43
|
-
"@modelcontextprotocol/sdk": "^1.32.1",
|
|
44
|
-
"@types/node": "26.6.5",
|
|
45
|
-
"typescript": "7.0.2"
|
|
46
|
-
},
|
|
47
|
-
"bin": {
|
|
48
|
-
"autonomo": "dist/cli.js"
|
|
49
|
-
}
|
|
50
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "autonomo-sdk",
|
|
3
|
+
"version": "0.1.6",
|
|
4
|
+
"description": "One call for AI agents: find the right paid API on Autonomo, pay in USDG or $AUTONOMO (privately through Gloam, or on Borro credit), within spending caps, and get a receipt.",
|
|
5
|
+
"homepage": "https://autonomo.fun",
|
|
6
|
+
"author": "Autonomo (https://autonomo.fun)",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"main": "dist/index.js",
|
|
10
|
+
"types": "dist/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"README.md",
|
|
20
|
+
"LICENSE"
|
|
21
|
+
],
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=20"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsc -p .",
|
|
27
|
+
"test": "node --test test/*.test.mjs"
|
|
28
|
+
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"x402",
|
|
31
|
+
"autonomo",
|
|
32
|
+
"ai-agents",
|
|
33
|
+
"robinhood-chain",
|
|
34
|
+
"usdg",
|
|
35
|
+
"payments",
|
|
36
|
+
"gloam",
|
|
37
|
+
"borro"
|
|
38
|
+
],
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"viem": "2.57.12"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@modelcontextprotocol/sdk": "^1.32.1",
|
|
44
|
+
"@types/node": "26.6.5",
|
|
45
|
+
"typescript": "7.0.2"
|
|
46
|
+
},
|
|
47
|
+
"bin": {
|
|
48
|
+
"autonomo": "dist/cli.js"
|
|
49
|
+
}
|
|
50
|
+
}
|