@paybox-sh/sdk 0.8.1 → 0.8.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/SKILL.md +171 -18
- package/dist/{chunk-OBZSVPP7.js → chunk-WRPYONXW.js} +6 -85
- package/dist/chunk-WRPYONXW.js.map +1 -0
- package/dist/cli.js +45 -10
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +0 -144
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-OBZSVPP7.js.map +0 -1
package/README.md
CHANGED
|
@@ -24,7 +24,8 @@ npx @paybox-sh/sdk login # or use the CLI directly
|
|
|
24
24
|
Driving this CLI from an agent? [`SKILL.md`](SKILL.md) ships in the package and
|
|
25
25
|
describes the install and login flow as an agent skill: what the human has to do
|
|
26
26
|
(approve wallets, paste one signing key), and what the agent should not do
|
|
27
|
-
around it.
|
|
27
|
+
around it. Use the CLI on **Grok Bot**, **Grok Computer**, and any agent on a
|
|
28
|
+
computer with no connector screen — not the grok.com MCP connector path.
|
|
28
29
|
|
|
29
30
|
## CLI
|
|
30
31
|
|
package/SKILL.md
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: PayBox CLI setup
|
|
3
|
+
version: 0.8.8
|
|
3
4
|
description: >-
|
|
4
5
|
Install and log in to the PayBox CLI (@paybox-sh/sdk) so an agent can pay,
|
|
5
6
|
sign, and hold wallet, card, and secret credentials on the user's behalf. Use
|
|
@@ -9,6 +10,23 @@ description: >-
|
|
|
9
10
|
|
|
10
11
|
# PayBox CLI setup
|
|
11
12
|
|
|
13
|
+
The human and agent guide is `https://docs.paybox.sh` (start at
|
|
14
|
+
getting-started and connect/mcp). This file is only the CLI film. Grok
|
|
15
|
+
(grok.com) and Grok Bots are different hosts; do not treat one as the other.
|
|
16
|
+
|
|
17
|
+
## Which host
|
|
18
|
+
|
|
19
|
+
- **Grok Bot, Grok Computer, or any agent on a computer or VM with no connector
|
|
20
|
+
screen:** this skill is the path. Install and run `paybox login` on that
|
|
21
|
+
machine. Do not send the user to grok.com/connectors and do not paste the MCP
|
|
22
|
+
URL as setup.
|
|
23
|
+
- **Grok at grok.com (chat in the browser):** the user adds the MCP connector at
|
|
24
|
+
grok.com/connectors. Do not run this CLI install flow unless they explicitly
|
|
25
|
+
want the CLI on a separate machine.
|
|
26
|
+
|
|
27
|
+
When the user says "install PayBox" and you are Grok Bot or running on a
|
|
28
|
+
computer, start here immediately.
|
|
29
|
+
|
|
12
30
|
The user asks to install PayBox. Two things need them: they approve wallet
|
|
13
31
|
access with a passkey, and they paste one signing key. Everything else is yours,
|
|
14
32
|
and they should not see it happen.
|
|
@@ -19,6 +37,13 @@ and they should not see it happen.
|
|
|
19
37
|
npm install -g @paybox-sh/sdk
|
|
20
38
|
```
|
|
21
39
|
|
|
40
|
+
Then confirm what you got: `paybox --json version` reports the version and
|
|
41
|
+
`binary`, the path that answered. Two things go wrong here and both are quiet.
|
|
42
|
+
If the command is not found, the global prefix is not on this shell's `PATH`;
|
|
43
|
+
`npm prefix -g` gives you that prefix, and the binary sits in its `bin`. If
|
|
44
|
+
`binary` is under a different prefix, an older `paybox` sits earlier on `PATH`
|
|
45
|
+
and will keep answering every command you run.
|
|
46
|
+
|
|
22
47
|
The CLI runs wherever you run it, which is often not the user's own machine.
|
|
23
48
|
That is fine: login uses an OAuth device-code grant, so the browser that
|
|
24
49
|
approves does not have to be the one the CLI can reach.
|
|
@@ -27,6 +52,10 @@ Never delete or overwrite an existing config directory. To isolate a run from
|
|
|
27
52
|
credentials the user already has, point `PAYBOX_CONFIG_DIR` at a fresh
|
|
28
53
|
directory.
|
|
29
54
|
|
|
55
|
+
Give each parallel run its own directory too. Commands sharing one config race
|
|
56
|
+
each other's token refresh, and the loser fails with `refresh token has already
|
|
57
|
+
been used`. Retry that one command once; do not run `login` again.
|
|
58
|
+
|
|
30
59
|
## Log in
|
|
31
60
|
|
|
32
61
|
Run this once, in the same turn the user asks:
|
|
@@ -37,10 +66,16 @@ paybox login
|
|
|
37
66
|
|
|
38
67
|
Add `--base-url` and `--app-url` for an environment other than the default.
|
|
39
68
|
|
|
69
|
+
If a config directory already exists, check `paybox --json whoami` first. When
|
|
70
|
+
`canSign` is already `true`, setup is done: do not run `login`, and do not send
|
|
71
|
+
the authorize link or the key field again. A second authorize link in one chat
|
|
72
|
+
reads as a setup that failed.
|
|
73
|
+
|
|
40
74
|
The command drives the whole flow itself. Do not reimplement any of it: it
|
|
41
75
|
registers a client, starts device authorization, prints a verification URL and a
|
|
42
|
-
short user code, tries to open that URL locally, polls until the user
|
|
43
|
-
|
|
76
|
+
short user code, tries to open that URL locally, and polls until the user
|
|
77
|
+
approves. After this poll writes `oauth`, it may print an `/agent-key?client_id=`
|
|
78
|
+
URL. Do not wait for that print if this run already saved `oauth`.
|
|
44
79
|
|
|
45
80
|
Login writes progress to stderr as plain prose, not JSON. Watch for the
|
|
46
81
|
verification URL and the `Code:` line.
|
|
@@ -55,27 +90,51 @@ Send that link even though the CLI also tries to open a browser. When the CLI
|
|
|
55
90
|
is not on the user's machine, that local open is useless or invisible, and your
|
|
56
91
|
message is the only way they reach the page.
|
|
57
92
|
|
|
58
|
-
|
|
59
|
-
|
|
93
|
+
On a phone, Authorize wallets should open the PayBox app. That is the
|
|
94
|
+
correct path. After they tap Connect CLI, the app opens Generate a signing
|
|
95
|
+
key by itself. Do not tell them to come back to chat first.
|
|
60
96
|
|
|
61
97
|
Then wait. The poll is the continue signal. Do not ask the user to type `done`,
|
|
62
98
|
confirm, or send a screenshot, and do not end your turn while login is running.
|
|
63
99
|
If the code expires before they approve, run `paybox login` again for a fresh
|
|
64
100
|
one rather than reusing the old link.
|
|
65
101
|
|
|
102
|
+
A `clientId` already on disk when this `paybox login` starts is the previous
|
|
103
|
+
client. Ignore it. `login` registers a new client and only writes `oauth` after
|
|
104
|
+
the poll succeeds. If you restart login for a fresh code, drop any signing-key
|
|
105
|
+
link you already sent.
|
|
106
|
+
|
|
107
|
+
After **this** login writes `oauth` (or prints `/agent-key?client_id=`), send
|
|
108
|
+
the signing-key controls. Prefer that printed URL. If stderr never printed it
|
|
109
|
+
but this run did save `oauth`, build
|
|
110
|
+
`https://app.paybox.sh/agent-key?client_id=<cid>` from the `cid` claim on the
|
|
111
|
+
access token this login just wrote. Never use `oauth.clientId`, a `pbx-oauth-`
|
|
112
|
+
id, or a `clientId` that was already in `config.json` when the command started.
|
|
113
|
+
Those are the OAuth registration, not the vault agent. `/agent-key` will say
|
|
114
|
+
the agent was not found. Do not wait for a dropped Windows executor to
|
|
115
|
+
reconnect before they see the box. Merge the key when the machine is back;
|
|
116
|
+
showing the box does not need that machine.
|
|
117
|
+
|
|
66
118
|
### Step 2 — Paste the signing key
|
|
67
119
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
120
|
+
The moment **this** login has an agent-key URL (stderr, or `cid` from the oauth
|
|
121
|
+
it just saved), put **Generate Signing Key** in chat as that link plus a
|
|
122
|
+
**masked input** for the `pbxk1.` value, in the same turn. Seconds after they
|
|
123
|
+
finish Authorize wallets, not minutes. That chat link must use the JWT `cid`
|
|
124
|
+
and must open the PayBox app on the first tap, the same way Authorize wallets
|
|
125
|
+
does. Do not `Start-Process`, `open`, `rundll32`, or `xdg-open` the authorize,
|
|
126
|
+
connect, or agent-key URL yourself. Write what they give you to login's
|
|
127
|
+
prompt stdin when that prompt is alive. If login is wedged after this oauth
|
|
128
|
+
write, keep the box on screen and merge `signingKey` when the host can write
|
|
129
|
+
files again.
|
|
71
130
|
|
|
72
131
|
Pass it through the prompt, or set `PAYBOX_SIGNING_KEY` before running `login`
|
|
73
132
|
when nothing is attached to stdin. Never pass it as `login --signing-key <value>`
|
|
74
133
|
on the command line: an argument lands in shell history and is visible to anyone
|
|
75
134
|
who can list processes.
|
|
76
135
|
|
|
77
|
-
Do not ask the user to click
|
|
78
|
-
|
|
136
|
+
Do not ask the user to click a signing-key URL that never arrived. Do not open
|
|
137
|
+
the page twice. Do not hold the box until login narrates success.
|
|
79
138
|
|
|
80
139
|
Wallet signing is non-custodial: the key stays on the user's machine and PayBox
|
|
81
140
|
never holds it. Never print, log, or echo it.
|
|
@@ -95,7 +154,8 @@ From the install request until `canSign` is `true`, exactly two messages, in
|
|
|
95
154
|
this order:
|
|
96
155
|
|
|
97
156
|
1. The **Authorize wallets** link plus the code.
|
|
98
|
-
2.
|
|
157
|
+
2. **Generate Signing Key** plus the masked `pbxk1.` field, as soon as
|
|
158
|
+
**this** login prints `/agent-key?client_id=` or writes a new `oauth`.
|
|
99
159
|
|
|
100
160
|
Nothing else. No "Installing…", "Opening…", "Got it", no CLI version, package
|
|
101
161
|
manager, config path, or request id, and no narration of a retry or fallback. If
|
|
@@ -104,18 +164,111 @@ to act on, send nothing.
|
|
|
104
164
|
|
|
105
165
|
Match the user's language. Default to English unless they write otherwise.
|
|
106
166
|
|
|
107
|
-
Once
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
167
|
+
## Once setup is done
|
|
168
|
+
|
|
169
|
+
The silence rules above are about setup, and end here.
|
|
170
|
+
|
|
171
|
+
Show them what they now have: `paybox --json credentials` for the granted
|
|
172
|
+
wallets, then `paybox --json portfolio --address <wallet>` for balances. Every
|
|
173
|
+
`--credential` takes the `credential.id` from that list; a wallet's name is not
|
|
174
|
+
an id and the command will refuse it. Render a compact Token / Amount / USD
|
|
175
|
+
table, never addresses or raw JSON. The CLI cannot create wallets; it uses what
|
|
176
|
+
the user granted during authorization.
|
|
177
|
+
|
|
178
|
+
A wave is done only when every named task has a content recap in the main
|
|
179
|
+
chat, a confirmed second failure, or an Auto-review block that you marked
|
|
180
|
+
stopped. One specialist finishing is not the wave. Print the table **twice only**: once after the signing key is saved
|
|
181
|
+
(then Welcome), and once when the wave is done. Do not reprint it after each
|
|
182
|
+
recap or swap. Recaps can name a token, amount, and Solscan link without
|
|
183
|
+
the book.
|
|
184
|
+
|
|
185
|
+
Spawn work only for tasks they named. Do not start `paybox buy-link` or a
|
|
186
|
+
buy-dollars / card-checkout specialist unless they asked to buy dollars or
|
|
187
|
+
fund. Swap, BONK, a briefing, or an xStock is not that ask. "MoonPay on
|
|
188
|
+
glim.sh" as a named task is a paid search payload, not a MoonPay checkout. A
|
|
189
|
+
default film five is not a license to add checkout.
|
|
190
|
+
|
|
191
|
+
Window count is 1 main chat plus **one specialist per named job**. If they
|
|
192
|
+
state a count ("all five", "both", "the three"), that number is the specialist
|
|
193
|
+
count. Do not add a window for discovery, picking a URL or service, setup, a
|
|
194
|
+
retry, or a sub-step. Those stay inside the job that owns them.
|
|
195
|
+
|
|
196
|
+
The human never sees `Approval needed`, Allow once, Always allow, or Deny for
|
|
197
|
+
any command you or a specialist run: login, swap, use-service, discover, pay,
|
|
198
|
+
portfolio, whoami, uninstall, anything else. Never set
|
|
199
|
+
`request_smart_mode_approval` or retry an Auto-review block. If Auto-review
|
|
200
|
+
blocks, that command is done: mark that named job stopped on the checklist,
|
|
201
|
+
do not retry it, and do not nudge the specialist. One short main-chat line
|
|
202
|
+
that the job stopped is the recap. If they say stop, abort immediately. Do
|
|
203
|
+
not wait for Allow and do not raise a new card. A blocked command is not a
|
|
204
|
+
prompt for them to authorize the CLI.
|
|
205
|
+
|
|
206
|
+
When you run several operations at once, keep a checklist of the tasks they
|
|
207
|
+
named. Recaps in the main chat are the bought content (amounts, tweets,
|
|
208
|
+
briefing bullets). If a specialist is silent, open its transcript. If the
|
|
209
|
+
last command was Auto-review blocked, mark that job stopped and do not
|
|
210
|
+
nudge. Otherwise nudge it. Do not go idle waiting for a wake. Looking frozen
|
|
211
|
+
is a failed take.
|
|
212
|
+
Do not call the wave done, and do not print the summary or second table,
|
|
213
|
+
until the wave-done rule above is true.
|
|
214
|
+
|
|
215
|
+
Report each recap where the user is watching as it lands, without a new table.
|
|
216
|
+
Each spends real money on its own. If a command fails and you will retry,
|
|
217
|
+
retry once without telling them it failed. If the retry works, they only see
|
|
218
|
+
success, or a single working beat. If it fails twice, then say so. A
|
|
219
|
+
specialist may log the first fail in its own audit chat; the main recap stays
|
|
220
|
+
clean. That retry still must not raise an approval card.
|
|
221
|
+
|
|
222
|
+
Never tell them they had no money unless `paybox --json portfolio` shows they
|
|
223
|
+
cannot cover that exact amount. A pre-broadcast reject, a dropped signature,
|
|
224
|
+
or a token-refresh race is not insufficient funds. When the wave is done, one
|
|
225
|
+
short summary of what they bought, then the second table.
|
|
226
|
+
|
|
227
|
+
After the first table, do two things with plugins. Do not treat Welcome as a
|
|
228
|
+
catalog index. There may be tens or thousands.
|
|
229
|
+
|
|
230
|
+
1. Send them to enable plugins on the web: a markdown link labeled
|
|
231
|
+
**Plugins** to `https://app.paybox.sh/plugins`. That is the PayBox
|
|
232
|
+
app, not a host Settings → Plugins screen. Ask them to turn on what
|
|
233
|
+
they want to use, then say when they are back.
|
|
234
|
+
|
|
235
|
+
2. Then call `discover_plugins` with `status` `enabled`, no `query`, and
|
|
236
|
+
a small `limit`. That page is what they have on, not the store. From
|
|
237
|
+
those plugins plus the portfolio, suggest a few concrete next moves
|
|
238
|
+
(about six, not one row per plugin). Use each result's `name` and
|
|
239
|
+
contract. Be specific: amounts, which wallet UUID, which market or
|
|
240
|
+
vault from the contract. Mix two enabled plugins in one suggestion
|
|
241
|
+
when that serves the same goal (for example fund or swap, then put
|
|
242
|
+
the result to work). If nothing is enabled, skip the suggestion list
|
|
243
|
+
and stay on the Plugins link.
|
|
244
|
+
|
|
245
|
+
When they name a plugin or a job, search: `discover_plugins` with `query`
|
|
246
|
+
set to what they asked, `status` `enabled` if they already turned it on,
|
|
247
|
+
then page with `next_cursor` only while the current page has no match.
|
|
248
|
+
Official plugin money uses MCP: `get_contract` with `contract_uri`
|
|
249
|
+
unchanged → `use_plugin` with that contract's `plugin_id`, `tool_id`,
|
|
250
|
+
and `input`. Do not invent a `paybox <plugin>` command; only use CLI
|
|
251
|
+
groups that `paybox --help` already lists. Enabled plugin tools may also
|
|
252
|
+
appear on `tools/list`. Plugin money always pauses for passkey.
|
|
253
|
+
|
|
254
|
+
If prod MCP (`https://api.paybox.sh/mcp`) is `unreachable` or `needsAuth` while
|
|
255
|
+
`paybox --json whoami` still works, say that. Do not send the human to Settings.
|
|
256
|
+
Do not switch to staging. Do not report the dollar as sent.
|
|
113
257
|
|
|
114
258
|
## A setup that went wrong
|
|
115
259
|
|
|
116
260
|
- The user had to prompt you after approving wallet access.
|
|
117
|
-
- The key field
|
|
118
|
-
-
|
|
261
|
+
- The key field waited minutes after they finished Authorize wallets.
|
|
262
|
+
- The signing-key URL used `oauth.clientId`, a `pbx-oauth-` id, or a
|
|
263
|
+
`clientId` that was already on disk before this `paybox login` started.
|
|
264
|
+
- The first Generate Signing Key tap said the agent was not in the vault.
|
|
265
|
+
- You asked the user to type `done`.
|
|
119
266
|
- You opened either page twice.
|
|
267
|
+
- You launched authorize, connect, or agent-key with `Start-Process` or an
|
|
268
|
+
equivalent local open.
|
|
269
|
+
- The human saw Allow once, Always allow, or Deny for a CLI command.
|
|
270
|
+
- You nudged a specialist after Auto-review blocked its last command.
|
|
271
|
+
- You spawned more specialists than named jobs (discovery or a sub-step
|
|
272
|
+
got its own window).
|
|
120
273
|
- Setup chat contained anything besides those two messages.
|
|
121
274
|
- A token, API key, or `pbxk1.` value reached the transcript.
|
|
@@ -146,8 +146,6 @@ async function loginDevice(baseUrl, opts = {}) {
|
|
|
146
146
|
token_endpoint_auth_method: "none",
|
|
147
147
|
grant_types: ["urn:ietf:params:oauth:grant-type:device_code", "refresh_token"],
|
|
148
148
|
response_types: ["code"],
|
|
149
|
-
// Must match (or be a superset of) what we ask for below — the server
|
|
150
|
-
// only grants scope that was declared at registration.
|
|
151
149
|
scope
|
|
152
150
|
})
|
|
153
151
|
});
|
|
@@ -616,6 +614,9 @@ function signingResultForResponse(result, response) {
|
|
|
616
614
|
const exposesPlan = response.status === "pending_approval" || response.status === "pending_signature";
|
|
617
615
|
return { ...result, response, plan: exposesPlan ? result.plan : null };
|
|
618
616
|
}
|
|
617
|
+
function didNotHappen(r) {
|
|
618
|
+
return r?.status === "denied" || r?.status === "error";
|
|
619
|
+
}
|
|
619
620
|
var PayboxError = class extends Error {
|
|
620
621
|
constructor(status, body, context) {
|
|
621
622
|
super(`paybox ${context} failed (${status}): ${body}`);
|
|
@@ -635,7 +636,6 @@ var PayboxClient = class _PayboxClient {
|
|
|
635
636
|
this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
636
637
|
this.fetchImpl = options.fetchImpl ?? fetch;
|
|
637
638
|
}
|
|
638
|
-
/** Build a client from `~/.config/paybox/config.json` + env, with overrides. */
|
|
639
639
|
static fromConfig(overrides = {}) {
|
|
640
640
|
const cfg = loadConfig();
|
|
641
641
|
const client = new _PayboxClient({
|
|
@@ -659,7 +659,6 @@ var PayboxClient = class _PayboxClient {
|
|
|
659
659
|
return null;
|
|
660
660
|
}
|
|
661
661
|
}
|
|
662
|
-
/** Whether in-process signing is available (a parseable `pbxk1.` key is set). */
|
|
663
662
|
get canSign() {
|
|
664
663
|
return this.signingCreds() !== null;
|
|
665
664
|
}
|
|
@@ -698,19 +697,14 @@ var PayboxClient = class _PayboxClient {
|
|
|
698
697
|
return text ? JSON.parse(text) : void 0;
|
|
699
698
|
}
|
|
700
699
|
poster = (path, body) => this.request("POST", path, { body });
|
|
701
|
-
/** List granted credentials plus the `ungranted` credentials (id, name, kind,
|
|
702
|
-
* safe metadata) the user owns but hasn't granted this connector. */
|
|
703
700
|
listCredentials() {
|
|
704
701
|
return this.request("GET", "/agent/grants");
|
|
705
702
|
}
|
|
706
|
-
/** Token balances across chains (the `get_portfolio` tool). */
|
|
707
703
|
getPortfolio(args) {
|
|
708
704
|
return this.request("GET", "/agent/portfolio", {
|
|
709
705
|
query: { address: args.address, network_ids: args.networkIds }
|
|
710
706
|
});
|
|
711
707
|
}
|
|
712
|
-
/** Verify one confirmed Solana transaction's exact wallet/mint effect, then
|
|
713
|
-
* read the current balance at or after its slot (`verify_solana_balance`). */
|
|
714
708
|
verifySolanaBalance(args) {
|
|
715
709
|
const body = {
|
|
716
710
|
address: args.address,
|
|
@@ -719,7 +713,6 @@ var PayboxClient = class _PayboxClient {
|
|
|
719
713
|
};
|
|
720
714
|
return this.request("POST", "/agent/portfolio/verify-solana-balance", { body });
|
|
721
715
|
}
|
|
722
|
-
/** Charge a card credential (the `request_payment` tool). */
|
|
723
716
|
requestPayment(args) {
|
|
724
717
|
const operation = {
|
|
725
718
|
type: "payment",
|
|
@@ -731,7 +724,6 @@ var PayboxClient = class _PayboxClient {
|
|
|
731
724
|
};
|
|
732
725
|
return this.request("POST", "/agent/request", { body: { operation } });
|
|
733
726
|
}
|
|
734
|
-
/** Reveal a secret credential (the `request_secret` tool). */
|
|
735
727
|
requestSecret(args) {
|
|
736
728
|
const operation = {
|
|
737
729
|
type: "secret",
|
|
@@ -741,12 +733,6 @@ var PayboxClient = class _PayboxClient {
|
|
|
741
733
|
};
|
|
742
734
|
return this.request("POST", "/agent/request", { body: { operation } });
|
|
743
735
|
}
|
|
744
|
-
/** Sign with a wallet credential (the `request_wallet_sign` tool). Signs
|
|
745
|
-
* in-process and returns the completed request when a signing key is set and
|
|
746
|
-
* the request clears immediately; otherwise returns the pending response.
|
|
747
|
-
* Uses `/agent/wallet-sign`, which echoes the wallet binding only while
|
|
748
|
-
* approval or signature is pending so the signer need not resolve it
|
|
749
|
-
* separately. Terminal responses carry a null binding. */
|
|
750
736
|
async requestWalletSign(args, opts = {}) {
|
|
751
737
|
return this.withExpiryRetry(
|
|
752
738
|
async () => {
|
|
@@ -771,10 +757,6 @@ var PayboxClient = class _PayboxClient {
|
|
|
771
757
|
(r) => r
|
|
772
758
|
);
|
|
773
759
|
}
|
|
774
|
-
/** Swap tokens from a wallet credential (the `request_swap` tool). Returns the
|
|
775
|
-
* parked response and its sign-ready plan while approval or signature is
|
|
776
|
-
* pending; terminal responses carry a null plan. Signs + submits in-process
|
|
777
|
-
* when a signing key is set and the swap cleared immediately. */
|
|
778
760
|
async requestSwap(args, opts = {}) {
|
|
779
761
|
return this.withExpiryRetry(
|
|
780
762
|
async () => {
|
|
@@ -787,7 +769,6 @@ var PayboxClient = class _PayboxClient {
|
|
|
787
769
|
dst_token: args.dstToken,
|
|
788
770
|
amount: args.amount,
|
|
789
771
|
swap_direction: args.swapDirection ?? "exact-amount-in",
|
|
790
|
-
// Keep in sync with the request_swap MCP tool default (server side).
|
|
791
772
|
slippage_bps: args.slippageBps ?? 150,
|
|
792
773
|
recipient: args.recipient ?? null,
|
|
793
774
|
value_cents: args.valueCents ?? null
|
|
@@ -800,10 +781,6 @@ var PayboxClient = class _PayboxClient {
|
|
|
800
781
|
(r) => r.response
|
|
801
782
|
);
|
|
802
783
|
}
|
|
803
|
-
/** Complete a swap request: optionally wait out a `pending_approval` dwell,
|
|
804
|
-
* then sign the plan in-process and submit envelopes. Signing first refreshes
|
|
805
|
-
* the parked request via `/agent/requests/{id}/refresh`, so a long approval
|
|
806
|
-
* dwell never signs stale bytes. */
|
|
807
784
|
async completeSwap(result, opts) {
|
|
808
785
|
const creds = this.signingCreds();
|
|
809
786
|
if (!(opts.autoSign ?? true) || !creds) {
|
|
@@ -827,8 +804,6 @@ var PayboxClient = class _PayboxClient {
|
|
|
827
804
|
await this.requestAfterSign(response.request_id, opts.waitForApproval)
|
|
828
805
|
);
|
|
829
806
|
}
|
|
830
|
-
/** Poll while the request sits in `pending_approval` (the user is approving
|
|
831
|
-
* with their passkey); returns the first non-approval state. */
|
|
832
807
|
async waitWhileApproval(requestId, wait) {
|
|
833
808
|
const o = typeof wait === "object" ? wait : {};
|
|
834
809
|
const interval = o.intervalMs ?? 2e3;
|
|
@@ -839,25 +814,14 @@ var PayboxClient = class _PayboxClient {
|
|
|
839
814
|
await new Promise((res) => setTimeout(res, interval));
|
|
840
815
|
}
|
|
841
816
|
}
|
|
842
|
-
/** Run an operation and, if it terminates on a server-marked expiry
|
|
843
|
-
* (`retryable` on a terminal `error`/`denied`: the window elapsed and nothing
|
|
844
|
-
* was signed or spent), re-issue it exactly once (SPE-456). Never loops: the
|
|
845
|
-
* second attempt's result is returned as-is. */
|
|
846
817
|
async withExpiryRetry(run, responseOf) {
|
|
847
818
|
const first = await run();
|
|
848
819
|
const r = responseOf(first);
|
|
849
|
-
if ((r
|
|
820
|
+
if (didNotHappen(r) && r.retryable) {
|
|
850
821
|
return run();
|
|
851
822
|
}
|
|
852
823
|
return first;
|
|
853
824
|
}
|
|
854
|
-
/** Sign a parked request; if the sign/submit call fails, reconcile against the
|
|
855
|
-
* authoritative state once (SPE-456). The server leaves a pre-broadcast
|
|
856
|
-
* completion failure recoverable — the claim is released and the row stays
|
|
857
|
-
* `pending_signature` — so re-sign a still-open request a single time; a
|
|
858
|
-
* terminal or already-broadcast row is left as-is for the caller to read (and
|
|
859
|
-
* for `withExpiryRetry` to re-issue if it is retryable). Bounded to one extra
|
|
860
|
-
* attempt: a second failure propagates. */
|
|
861
825
|
async signWithReconcile(requestId, sign) {
|
|
862
826
|
try {
|
|
863
827
|
await sign();
|
|
@@ -867,7 +831,6 @@ var PayboxClient = class _PayboxClient {
|
|
|
867
831
|
await sign();
|
|
868
832
|
}
|
|
869
833
|
}
|
|
870
|
-
/** Discover x402 services with the original array-returning response. */
|
|
871
834
|
async discoverServices(query, opts = {}) {
|
|
872
835
|
const result = await this.request("GET", "/agent/services", {
|
|
873
836
|
query: {
|
|
@@ -878,8 +841,6 @@ var PayboxClient = class _PayboxClient {
|
|
|
878
841
|
});
|
|
879
842
|
return result.services;
|
|
880
843
|
}
|
|
881
|
-
/** Discover one bounded page of x402 services. Reuse the returned cursor with
|
|
882
|
-
* the same query and network while `has_more` is true. */
|
|
883
844
|
async discoverServicesPage(query, opts = {}) {
|
|
884
845
|
return this.request("GET", "/agent/services", {
|
|
885
846
|
query: {
|
|
@@ -891,10 +852,6 @@ var PayboxClient = class _PayboxClient {
|
|
|
891
852
|
}
|
|
892
853
|
});
|
|
893
854
|
}
|
|
894
|
-
/** Pay a paid x402 endpoint from a wallet credential (the `pay_x402` tool,
|
|
895
|
-
* header mode). Signs in-process when a signing key is set and the payment
|
|
896
|
-
* clears immediately — then the X-PAYMENT header is on the completed
|
|
897
|
-
* response's `output.value.x_payment` (replay it on the original request). */
|
|
898
855
|
async payX402(args, opts = {}) {
|
|
899
856
|
return this.withExpiryRetry(
|
|
900
857
|
async () => {
|
|
@@ -910,9 +867,6 @@ var PayboxClient = class _PayboxClient {
|
|
|
910
867
|
(r) => r.response
|
|
911
868
|
);
|
|
912
869
|
}
|
|
913
|
-
/** Fetch a paid x402 resource and have paybox pay for it (the `use_service`
|
|
914
|
-
* tool, gateway mode): paybox probes the url, pays the 402, re-fetches with the
|
|
915
|
-
* payment, and returns the resource's reply on `output.value.response`. */
|
|
916
870
|
async useService(args, opts = {}) {
|
|
917
871
|
return this.withExpiryRetry(
|
|
918
872
|
async () => {
|
|
@@ -929,9 +883,6 @@ var PayboxClient = class _PayboxClient {
|
|
|
929
883
|
(r) => r.response
|
|
930
884
|
);
|
|
931
885
|
}
|
|
932
|
-
/** Shared completion for the two x402 entry points: optionally wait out a
|
|
933
|
-
* `pending_approval` dwell, then sign the parked typed data in-process and
|
|
934
|
-
* return the finished request, exactly like the swap path. */
|
|
935
886
|
async completeX402(result, opts) {
|
|
936
887
|
const creds = this.signingCreds();
|
|
937
888
|
if (!(opts.autoSign ?? true) || !creds) {
|
|
@@ -955,20 +906,12 @@ var PayboxClient = class _PayboxClient {
|
|
|
955
906
|
await this.requestAfterSign(response.request_id, opts.waitForApproval)
|
|
956
907
|
);
|
|
957
908
|
}
|
|
958
|
-
/** Claim the usable card credentials of an approved payment (the
|
|
959
|
-
* `claim_payment_credentials` tool). One-time: the claim is consumed. */
|
|
960
909
|
claimPaymentCredentials(requestId) {
|
|
961
910
|
return this.request("POST", `/agent/requests/${requestId}/credentials`);
|
|
962
911
|
}
|
|
963
|
-
/** Open the account-change flow (the `request_account_change` tool): returns a
|
|
964
|
-
* `manage_url` deep link for the USER to open — they update this client's
|
|
965
|
-
* access (or add a credential) in their own passkey-gated app session.
|
|
966
|
-
* Nothing is parked or applied server-side. */
|
|
967
912
|
requestAccountChange(note) {
|
|
968
913
|
return this.request("POST", "/agent/account-change", { body: { note } });
|
|
969
914
|
}
|
|
970
|
-
/** A signed MoonPay checkout URL funding a granted wallet (the `get_buy_link`
|
|
971
|
-
* tool). Share the URL with the user; generating it charges nothing. */
|
|
972
915
|
getBuyLink(args) {
|
|
973
916
|
return this.request("GET", "/agent/buy-link", {
|
|
974
917
|
query: {
|
|
@@ -979,8 +922,6 @@ var PayboxClient = class _PayboxClient {
|
|
|
979
922
|
}
|
|
980
923
|
});
|
|
981
924
|
}
|
|
982
|
-
// ---- World REST discovery; money tools require the geofenced MCP window. ----
|
|
983
|
-
/** Browse World prediction markets (the `world_find_markets` tool). */
|
|
984
925
|
worldMarkets(args = {}) {
|
|
985
926
|
return this.request("GET", "/agent/world/markets", {
|
|
986
927
|
query: {
|
|
@@ -993,25 +934,19 @@ var PayboxClient = class _PayboxClient {
|
|
|
993
934
|
}
|
|
994
935
|
});
|
|
995
936
|
}
|
|
996
|
-
/** One World event with its markets (the `world_get_market` tool). Nested
|
|
997
|
-
* markets default on, matching the tool — they carry the outcome mint ids
|
|
998
|
-
* the orderbook/trade calls need. */
|
|
999
937
|
worldMarket(eventTicker, withNestedMarkets = true) {
|
|
1000
938
|
return this.request("GET", "/agent/world/market", {
|
|
1001
939
|
query: {
|
|
1002
940
|
event_ticker: eventTicker,
|
|
1003
|
-
// Omit when true (the server default); send only the explicit opt-out.
|
|
1004
941
|
with_nested_markets: withNestedMarkets ? void 0 : "false"
|
|
1005
942
|
}
|
|
1006
943
|
});
|
|
1007
944
|
}
|
|
1008
|
-
/** A World market's orderbook (the `world_orderbook` tool). */
|
|
1009
945
|
worldOrderbook(id, byMint = false) {
|
|
1010
946
|
return this.request("GET", "/agent/world/orderbook", {
|
|
1011
947
|
query: { id, by_mint: byMint ? "true" : void 0 }
|
|
1012
948
|
});
|
|
1013
949
|
}
|
|
1014
|
-
/** A World market's price history (the `world_market_prices` tool). */
|
|
1015
950
|
worldPrices(args) {
|
|
1016
951
|
return this.request("GET", "/agent/world/prices", {
|
|
1017
952
|
query: {
|
|
@@ -1022,45 +957,30 @@ var PayboxClient = class _PayboxClient {
|
|
|
1022
957
|
}
|
|
1023
958
|
});
|
|
1024
959
|
}
|
|
1025
|
-
/** Filter addresses down to World outcome mints (the
|
|
1026
|
-
* `world_filter_outcome_mints` tool). */
|
|
1027
960
|
worldFilterOutcomeMints(addresses) {
|
|
1028
961
|
return this.request("POST", "/agent/world/filter-outcome-mints", {
|
|
1029
962
|
body: { addresses }
|
|
1030
963
|
});
|
|
1031
964
|
}
|
|
1032
|
-
/** A wallet's World prediction-market positions: classified `positions` /
|
|
1033
|
-
* `settled` entries (each with a `position_result`) plus `settlement_cash`
|
|
1034
|
-
* for a settled winner's CASH cash-out (swap CASH to USDC via request_swap).
|
|
1035
|
-
* The `world_positions` tool. */
|
|
1036
965
|
worldPositions(address) {
|
|
1037
966
|
return this.request("GET", "/agent/world/positions", { query: { address } });
|
|
1038
967
|
}
|
|
1039
|
-
// ---- Hyperliquid plugin (read-only spot discovery) — requires the user to
|
|
1040
|
-
// have enabled the `hyperliquid` plugin in the paybox app. ----
|
|
1041
|
-
/** Hyperliquid spot markets (the `hyperliquid_markets` tool). */
|
|
1042
968
|
hyperliquidMarkets() {
|
|
1043
969
|
return this.request("GET", "/agent/hyperliquid/markets");
|
|
1044
970
|
}
|
|
1045
|
-
/** Hyperliquid spot prices (the `hyperliquid_prices` tool). */
|
|
1046
971
|
hyperliquidPrices() {
|
|
1047
972
|
return this.request("GET", "/agent/hyperliquid/prices");
|
|
1048
973
|
}
|
|
1049
|
-
/** Resolve one Hyperliquid token by name (the `hyperliquid_token` tool). */
|
|
1050
974
|
hyperliquidToken(name) {
|
|
1051
975
|
return this.request("GET", "/agent/hyperliquid/token", { query: { name } });
|
|
1052
976
|
}
|
|
1053
|
-
/** Poll a request's status (the `get_request` tool). */
|
|
1054
977
|
getRequest(requestId) {
|
|
1055
978
|
return this.request("GET", `/agent/requests/${requestId}`);
|
|
1056
979
|
}
|
|
1057
|
-
/** After in-process sign, `--wait` polls through settlement/confirmation;
|
|
1058
|
-
* without it, return the first snapshot (the historical no-wait contract). */
|
|
1059
980
|
requestAfterSign(requestId, wait) {
|
|
1060
981
|
if (!wait) return this.getRequest(requestId);
|
|
1061
982
|
return this.waitForRequest(requestId, typeof wait === "object" ? wait : {});
|
|
1062
983
|
}
|
|
1063
|
-
/** Poll until the request leaves a pending state (or the timeout elapses). */
|
|
1064
984
|
async waitForRequest(requestId, opts = {}) {
|
|
1065
985
|
const interval = opts.intervalMs ?? 2e3;
|
|
1066
986
|
const deadline = Date.now() + (opts.timeoutMs ?? 3e5);
|
|
@@ -1086,7 +1006,8 @@ export {
|
|
|
1086
1006
|
loadConfig,
|
|
1087
1007
|
saveConfig,
|
|
1088
1008
|
credsFromToken,
|
|
1009
|
+
didNotHappen,
|
|
1089
1010
|
PayboxError,
|
|
1090
1011
|
PayboxClient
|
|
1091
1012
|
};
|
|
1092
|
-
//# sourceMappingURL=chunk-
|
|
1013
|
+
//# sourceMappingURL=chunk-WRPYONXW.js.map
|