@paybox-sh/sdk 2.1.0 → 2.2.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.
package/README.md CHANGED
@@ -146,6 +146,64 @@ const result = await paybox.usePlugin({
146
146
  });
147
147
  ```
148
148
 
149
+ ## Run and resume a plugin request
150
+
151
+ `runPlugin` invokes a plugin once and drives its stored request. `resumeRequest`
152
+ reads an existing request and does not invoke the plugin again. Signing follows
153
+ validated Solana/EVM transaction capabilities and server-owned `refresh_before_sign`,
154
+ not plugin names. `resumeRequest` also consumes stored `wallet_sign` transaction
155
+ intents through the existing signer. Unknown formats, versioned plans and gasless
156
+ prepared plans stop with `outcome: "unsupported"`. Public plugins also use
157
+ `use_plugin`, with their installation ID as `plugin_id`; request completion does
158
+ not by itself prove a purchase or broadcast. Use the plugin contract to select an
159
+ enabled tool and construct its input.
160
+
161
+ ```ts
162
+ import type { UsePluginArgs } from "@paybox-sh/sdk";
163
+
164
+ async function runApprovedOperation(operation: UsePluginArgs) {
165
+ const execution = await paybox.runPlugin(operation, { timeoutMs: 60_000 });
166
+ if (execution.requestId) {
167
+ await saveRequestId(execution.requestId);
168
+ }
169
+ return execution;
170
+ }
171
+
172
+ const execution = await paybox.resumeRequest(savedRequestId, {
173
+ waitForApproval: true,
174
+ timeoutMs: 60_000,
175
+ });
176
+ ```
177
+
178
+ The example assumes application-owned storage through `saveRequestId` and
179
+ `savedRequestId`. Keep the request ID so another process can resume after a pause.
180
+ A paired signing key enables automatic signing. Set `autoSign: false` to stop
181
+ before signing. The server still enforces wallet grants and approval requirements.
182
+
183
+ | Outcome | Meaning |
184
+ | --- | --- |
185
+ | `terminal` | Check `response.status`: `success`, `denied`, or `error`. A signature alone is not success. |
186
+ | `approval_required` | The user must approve through Paybox. Approval waiting is disabled by default. |
187
+ | `signing_required` | Automatic signing is disabled or a signing key is unavailable. |
188
+ | `unsupported` | The result or signing plan is outside the supported contract. |
189
+ | `reconcile_required` | The client cannot confirm completion. Query the same request before further action. |
190
+ | `deadline_exceeded` / `cancelled` | The client stopped. The server operation can still finish. |
191
+
192
+ The default deadline is 300 seconds and includes network calls. Polling starts at
193
+ 2 seconds, doubles when the status is unchanged, and stops increasing at 30 seconds.
194
+ A status change resets the interval. `intervalMs` sets the starting interval from
195
+ 1 to 30,000 milliseconds. `signal` accepts an `AbortSignal` for cancellation.
196
+
197
+ Do not start concurrent drivers for the same request. After an uncertain result,
198
+ use `getRequest` before an explicit resume. The driver does not automatically retry
199
+ a signature submission or create a replacement request. If invocation stops before
200
+ a request ID arrives, reconcile outside this driver before invoking the plugin again.
201
+
202
+ `usePlugin` still returns the raw MCP result, including metadata. Use it for data
203
+ tools and unsupported flows. The new methods do not change existing CLI commands.
204
+ Funding requests stop with `outcome: "unsupported"`, `reason: "funding_required"`,
205
+ and a non-signing `pending_funding` response. They never reopen or submit a plan.
206
+
149
207
  ## Configuration
150
208
 
151
209
  Resolution order: explicit constructor options → environment → stored config.
@@ -205,10 +263,13 @@ pnpm install
205
263
  pnpm typecheck
206
264
  pnpm build # tsup → dist/ (ESM + types + paybox bin)
207
265
 
208
- # Refresh the generated tool types from a running server (the source of truth):
209
- PAYBOX_MCP_URL=http://127.0.0.1:8080/mcp PAYBOX_API_KEY=pbx_live_… pnpm gen
266
+ # Refresh the generated tool types from the MCP tool contract:
267
+ pnpm gen
210
268
  ```
211
269
 
212
- The argument and response types in `src/generated.ts` mirror the server's MCP
213
- tool schemas (`schemars`-derived) and `server/src/models.rs`. `pnpm gen` reads the
214
- live `list_tools` schemas so the client can't drift from the server contract.
270
+ The argument types in `src/types.generated.ts` come from
271
+ `artifacts/contracts/mcp-tools-v1.json`, the committed list of core MCP tools and
272
+ their input schemas. CI fails when the tools change and the file does not, or
273
+ when this file is not regenerated from it. Refresh it with
274
+ `PAYBOX_UPDATE_CONTRACTS=1 cargo test --lib mcp_tool_contract_matches_core_tools`
275
+ in `server/`. Response types in `src/types.ts` track `server/src/models.rs`.
package/SKILL.md CHANGED
@@ -10,9 +10,8 @@ description: >-
10
10
 
11
11
  # PayBox CLI setup
12
12
 
13
- The human and agent guide is `https://docs.paybox.sh` (start at
14
- getting-started and connect/mcp). This skill covers CLI tasks and setup. Grok
15
- (grok.com), Grok Bots, and Muse are different hosts; do not treat one as another.
13
+ This skill covers PayBox through the CLI. Grok (grok.com), Grok Bots, and Muse
14
+ are different hosts; do not treat one as another.
16
15
 
17
16
  ## Start with the requested task
18
17
 
@@ -21,8 +20,8 @@ Keep the requested action, amount, asset, network, and recipient.
21
20
  Ask for missing details before a money operation.
22
21
  Selecting PayBox does not authorize spending, signing, funding, or changing grants.
23
22
 
24
- Use an existing PayBox connector when available. Otherwise follow **Which host**
25
- below. For CLI tasks, check the installed CLI and run `paybox --json whoami`.
23
+ Follow **Which host** below first. For CLI tasks, check the installed CLI and
24
+ run `paybox --json whoami`.
26
25
  This command reports local configuration. It does not verify remote access.
27
26
  The setup sections below apply only to the missing steps identified here.
28
27
 
@@ -48,12 +47,13 @@ incomplete and stop.
48
47
  ## Which host
49
48
 
50
49
  - **Muse, Grok Bot, Grok Computer, or any agent on a computer or VM with no connector
51
- screen:** use the CLI on that machine. Check existing access before setup.
52
- Do not send the user to grok.com/connectors and do not paste the MCP
53
- URL as setup.
50
+ screen:** use only the CLI on that machine. Check existing access before
51
+ setup. Never use the MCP URL, a custom connector, a Client ID, or a host
52
+ secrets store, and never say PayBox is unavailable on this host.
54
53
  - **Grok at grok.com (chat in the browser):** the user adds the MCP connector at
55
54
  grok.com/connectors. Do not run this CLI install flow unless they explicitly
56
- want the CLI on a separate machine.
55
+ want the CLI on a separate machine. Use an existing PayBox connector there
56
+ when available.
57
57
 
58
58
  When the user says "install PayBox" and you are Muse, Grok Bot, or running on a
59
59
  computer, start here immediately.
@@ -72,11 +72,11 @@ One setup flow applies on every host. A host changes only the capability values
72
72
  below. The flow never branches on a host name. Prod is `https://api.paybox.sh` /
73
73
  `https://app.paybox.sh`.
74
74
 
75
- | Host | `link_surface` | `renders_buttons` | `keeps_process` | `cli_allowed` |
76
- |---|---|---|---|---|
77
- | Muse | `phone_browser` | no | no | yes |
78
- | Grok Bot | `app` | yes | yes | yes |
79
- | Unknown host | `phone_browser` | no | no | yes until it refuses |
75
+ | Host | `link_surface` | `renders_buttons` | `keeps_process` | `cli_allowed` | `group_login` |
76
+ |---|---|---|---|---|---|
77
+ | Muse | `phone_browser` | no | no | yes | yes until it refuses |
78
+ | Grok Bot | `app` | yes | yes | yes | no |
79
+ | Unknown host | `phone_browser` | no | no | yes until it refuses | yes until it refuses |
80
80
 
81
81
  For a host not listed, use the unknown-host row and correct a value only from
82
82
  observed behavior. A new host is one new row.
@@ -95,6 +95,9 @@ observed behavior. A new host is one new row.
95
95
  - `cli_allowed`: when the host refuses the CLI install, pairing, or signing,
96
96
  stop visibly. Say setup is not supported on this host. Do not retry, work
97
97
  around the host, or send the user to another path as a substitute.
98
+ - `group_login`: when no and the request comes from a group chat, say in one
99
+ line to send "install PayBox" in the private chat with the bot. Do not start
100
+ login in the group.
98
101
 
99
102
  Every host: English unless the user writes otherwise. Few words. Never show a
100
103
  secret. Never wipe `~/.config/paybox`. Do not send the user to Settings →
@@ -169,23 +172,23 @@ If access works, skip login and complete only the missing setup step.
169
172
  The command drives the whole flow itself. Do not reimplement any of it: it
170
173
  registers a client, starts device authorization, prints a verification URL and a
171
174
  short user code to stderr as plain prose (not JSON), and polls until the user
172
- approves. Read the `Code:` line and the URL from that stderr. There is no
173
- `user_code` field to wait for. After the poll writes `oauth`, the CLI may print
174
- an `/agent-key?client_id=` URL. Do not wait for it if this run already saved
175
- `oauth`.
175
+ approves. Read the URL from that stderr. The link already carries the code, so
176
+ do not send the `Code:` line. There is no `user_code` field to wait for. After
177
+ the poll writes `oauth`, the CLI may print an `/agent-key?client_id=` URL. Do
178
+ not wait for it if this run already saved `oauth`.
176
179
 
177
180
  ### Step 1: Authorize wallets
178
181
 
179
- The moment login prints the verification URL and code, send **one** message:
182
+ The moment login prints the verification URL, send **one** message:
180
183
 
181
184
  > **Welcome to PayBox.** Two quick steps:
182
- > 1. Tap [Connect CLI to PayBox](verification URL), choose the wallets to
183
- > share, and confirm. Code: `XXXX-XXXX`
184
- > 2. Next I will send a signing-key link to connect this machine.
185
+ > 1. Tap [Connect CLI to PayBox](verification URL), choose your wallets, and
186
+ > tap **Connect with PayBox CLI**.
187
+ > 2. Next I will send a link to connect your signing key.
185
188
 
186
189
  Use only the steps that are still missing. Say what the page asks the user to
187
- do: pick the wallets and use the connect button. Do not describe a passkey or
188
- code-entry step the page does not show. Apply `link_surface` from **Host
190
+ do: pick the wallets and tap **Connect with PayBox CLI**. Do not describe a
191
+ passkey or code-entry step the page does not show. Apply `link_surface` from **Host
189
192
  capabilities**. Then keep polling as `keeps_process` allows. Do not open the URL yourself.
190
193
 
191
194
  If the code expires before approval, run `paybox login --no-open` again for a
@@ -243,11 +246,11 @@ host without evidence.
243
246
 
244
247
  When setup finishes:
245
248
 
246
- > **PayBox is connected.**
249
+ > **PayBox is connected.** **$TOTAL** across N wallets.
247
250
 
248
- then a Token / Amount / USD table of the granted wallets (see **Once setup is
249
- done**), then the choices **Swap 20 USDC to SOL** and **Pay a Solana
250
- briefing**, as `renders_buttons` allows, plus a short "You can try" list.
251
+ then the wallet table (see **Once setup is done**), then the choices **Swap 20
252
+ USDC to SOL** and **Pay a Solana briefing**, as `renders_buttons` allows, plus
253
+ a short "You can try" list.
251
254
 
252
255
  Secondary suggestions: Get a Solana briefing, Show my portfolio, See my enabled
253
256
  plugins. Check the granted wallets, funds, and enabled plugins before offering
@@ -258,13 +261,27 @@ fees, and keep the platform approval.
258
261
  ## Once setup is done
259
262
 
260
263
  For a setup-only request, show the granted wallets with `paybox --json credentials`.
261
- Then use `paybox --json portfolio --address <wallet>` for balances. Every
262
- `--credential` takes the `credential.id` from that list; a wallet's name is not
263
- an id and the command will refuse it. Render a compact Token / Amount / USD
264
- table, never addresses or invented balances. The CLI cannot create wallets; it
265
- uses what the user granted during authorization. If the portfolio call fails
266
- after connection, report setup as complete and name that failure. Do not
267
- restart setup.
264
+ Then run `paybox --json portfolio --address <wallet>` for every granted wallet.
265
+ Every `--credential` takes the `credential.id` from that list; a wallet's name is
266
+ not an id and the command will refuse it. Show one Wallet / Holdings / USD table
267
+ with one row per wallet:
268
+
269
+ | Wallet | Holdings | USD |
270
+ |---|---|---|
271
+ | main-solana | 1.30 SOL · 34.48 USDC | $175.53 |
272
+ | main-evm (Base) | 28.47 USDC · 0.0008 ETH | $30.59 |
273
+
274
+ - Sort by USD, highest first. `$TOTAL` is the sum of each `total_usd`.
275
+ - Holdings: the top two tokens by USD, two decimals (four for SOL or ETH under 1).
276
+ - Skip tokens with `dust: true` or no price. Never show addresses or invented
277
+ balances.
278
+ - Merge wallets under $1 into one last row: "N small wallets".
279
+ - If a portfolio call fails or `total_usd` is null, show "unavailable" in that
280
+ row.
281
+
282
+ The CLI cannot create wallets; it uses what the user granted during
283
+ authorization. If a portfolio call fails after connection, report setup as
284
+ complete and name that failure. Do not restart setup.
268
285
 
269
286
  Spawn work only for tasks they named. Do not start `paybox buy-link` or a
270
287
  buy-dollars / card-checkout specialist unless they asked to buy dollars or
@@ -315,14 +332,32 @@ not treat Welcome as a catalog index.
315
332
  granted Solana wallet, then **Pay a Solana briefing**. Do not offer 0.001 SOL to USDC. If nothing is
316
333
  enabled, skip the extra plugin list and stay on the Plugins link.
317
334
 
318
- When they name a plugin or a job, search with `paybox --json plugins list
319
- <query> --status enabled`, then page with `--cursor <next_cursor>` only while
320
- the current page has no match. For an official plugin, run `paybox --json
321
- plugins contract <contract_uri>` with the URI unchanged, then `paybox --json
322
- plugins use <plugin_id> <tool_id> --input <json>` with input matching that
323
- contract. Unofficial discovery results already contain their tool schemas;
324
- reuse `--invocation-id` only to retrieve the exact same ambiguous call. Plugin
325
- money always pauses for passkey.
335
+ When they name a provider or a job that needs one (a Solana limit order,
336
+ a liquidity-pool investment, or concert tickets), search both catalogs with
337
+ `paybox --json plugins list <query>` and `paybox --json discover <query>`, even
338
+ when the first catalog matches. Use concise task keywords; for "use Kamino",
339
+ search both for Kamino. Keep only routes supporting the requested action and
340
+ chain. Keep default source and status filters unless the user restricted them,
341
+ so disabled official plugins remain visible. Follow available pagination before
342
+ claiming a sole match; plugin pages use `--cursor <next_cursor>`.
343
+
344
+ If multiple relevant routes remain, show provider names, plugin or service
345
+ labels, supported actions, and enablement requirements, then ask which to use.
346
+ If exactly one relevant route remains across both catalogs, state it and
347
+ continue without another route-choice question: one matching Kamino plugin and
348
+ no Kamino service means use the plugin. If neither matches, explain that and
349
+ offer a useful next step. For a selected disabled plugin, share its `enable_url`,
350
+ wait for enablement, and discover it again before invocation.
351
+
352
+ For an official plugin, run `paybox --json plugins contract <contract_uri>` with
353
+ the URI unchanged, then `paybox --json plugins use <plugin_id> <tool_id> --input
354
+ <json>` with input matching that contract. Unofficial discovery results already
355
+ contain their tool schemas; reuse `--invocation-id` only to retrieve the exact
356
+ same ambiguous call. For a service, follow its exact discovered contract through
357
+ the supported service/payment flow. Continue the original task after selection;
358
+ do not stop at a discovery summary. Ask for missing task details and keep all
359
+ required approvals. Route selection does not authorize spending or signing.
360
+ Plugin money always pauses for passkey.
326
361
 
327
362
  There are no per-plugin commands. `paybox world …` and `paybox hyperliquid …`
328
363
  were removed in 1.0.0; reach World and Hyperliquid through `paybox plugins`
@@ -349,6 +384,9 @@ Do not switch to staging. Do not report the dollar as sent.
349
384
  - You nudged a specialist after its last command was blocked.
350
385
  - You spawned more specialists than named jobs.
351
386
  - A token, API key, or `pbxk1.` value reached the transcript.
352
- - You sent Settings → Connectors → Add custom, or Manage Connectors.
387
+ - You offered a custom connector, a Client ID, a host secrets store, Settings →
388
+ Connectors → Add custom, or Manage Connectors.
389
+ - You told the user PayBox is unavailable on this host.
390
+ - You started login in a group chat where `group_login` is no.
353
391
  - You claimed signing readiness before `canSign` was true.
354
392
  - A setup-only Welcome replaced or interrupted a task the user already asked for.