@bnbagent/studio-cli 0.0.11 → 0.0.12-alpha.2

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.
File without changes
File without changes
@@ -21,8 +21,15 @@ import { stringify as tomlStringify } from "smol-toml";
21
21
  import { createHash } from "crypto";
22
22
  import * as fs from "fs";
23
23
  import * as path from "path";
24
+ import {
25
+ TURNKEY_SDK_SERVER_PACKAGE,
26
+ TURNKEY_VIEM_PACKAGE
27
+ } from "@bnbagent/sdk/wallets";
24
28
  import { loadStudioToml } from "@bnbagent/studio-runtime/config";
25
- import { resolveProjectAltanaSdkEntry } from "@bnbagent/studio-runtime/wallet";
29
+ import {
30
+ resolveProjectAltanaSdkEntry,
31
+ resolveProjectTurnkeySdkEntry
32
+ } from "@bnbagent/studio-runtime/wallet";
26
33
  import { build as esbuildBuild } from "esbuild";
27
34
 
28
35
  // src/cli/utils/protocol.ts
@@ -141,6 +148,7 @@ async function buildZip(agentDir, outZip, opts = {}) {
141
148
  stageManifest(agentDir, buildRoot, entrypoint);
142
149
  stageStudioToml(agentDir, buildRoot);
143
150
  await stageAltanaSdk(agentDir, buildRoot, opts.bundle ?? bundleEntry);
151
+ await stageTurnkeySdk(agentDir, buildRoot, opts.bundle ?? bundleEntry);
144
152
  assertWithinUncompressedCap(
145
153
  buildRoot,
146
154
  opts.maxUncompressedBytes ?? MAX_UNCOMPRESSED_BYTES
@@ -277,7 +285,7 @@ async function stageAltanaSdk(agentDir, buildRoot, bundle) {
277
285
  }
278
286
  if (entry === null) {
279
287
  throw new Error(
280
- "wallet.kind='altana' but @altananetwork/sdk is not resolvable from the agent project \u2014 the zip runtime could never load the Altana session wallet. Run `pnpm add @altananetwork/sdk@0.5.1` in app/agent, or deploy as a container."
288
+ "wallet.kind='altana' but @altananetwork/sdk is not resolvable from the agent project \u2014 the zip runtime could never load the Altana session wallet. Run `pnpm add @altananetwork/sdk@0.7.1` in app/agent, or deploy as a container."
281
289
  );
282
290
  }
283
291
  const pkgDir = path.join(buildRoot, "node_modules", "@altananetwork", "sdk");
@@ -288,7 +296,7 @@ async function stageAltanaSdk(agentDir, buildRoot, bundle) {
288
296
  `${JSON.stringify(
289
297
  {
290
298
  name: "@altananetwork/sdk",
291
- version: altanaSdkVersionOf(entry),
299
+ version: packageVersionOf(entry, "@altananetwork/sdk"),
292
300
  private: true,
293
301
  type: "module",
294
302
  main: "index.js"
@@ -299,14 +307,76 @@ async function stageAltanaSdk(agentDir, buildRoot, bundle) {
299
307
  `
300
308
  );
301
309
  }
302
- function altanaSdkVersionOf(entry) {
310
+ async function stageTurnkeySdk(agentDir, buildRoot, bundle) {
311
+ let kind = "evm-local";
312
+ try {
313
+ const cfg = loadStudioToml(path.join(agentDir, "studio.toml"));
314
+ const wallet = cfg.wallet;
315
+ if (wallet !== null && typeof wallet === "object" && !Array.isArray(wallet)) {
316
+ kind = String(wallet.kind ?? "evm-local");
317
+ }
318
+ } catch {
319
+ }
320
+ if (kind !== "turnkey") {
321
+ return;
322
+ }
323
+ const packageNames = [
324
+ TURNKEY_SDK_SERVER_PACKAGE,
325
+ TURNKEY_VIEM_PACKAGE
326
+ ];
327
+ const entries = /* @__PURE__ */ new Map();
328
+ try {
329
+ for (const packageName of packageNames) {
330
+ const entry = resolveProjectTurnkeySdkEntry(agentDir, packageName);
331
+ if (entry !== null) {
332
+ entries.set(packageName, entry);
333
+ }
334
+ }
335
+ } catch (exc) {
336
+ throw new Error(
337
+ `wallet.kind='turnkey' zip build: ${exc instanceof Error ? exc.message : exc}`
338
+ );
339
+ }
340
+ if (entries.size !== packageNames.length) {
341
+ const missing = packageNames.filter((name) => !entries.has(name));
342
+ throw new Error(
343
+ `wallet.kind='turnkey' zip build: missing ${missing.join(", ")}; install both Turnkey packages in app/agent: pnpm add ${TURNKEY_SDK_SERVER_PACKAGE} ${TURNKEY_VIEM_PACKAGE}, or deploy as a container.`
344
+ );
345
+ }
346
+ for (const packageName of packageNames) {
347
+ const entry = entries.get(packageName);
348
+ const packageDir = path.join(
349
+ buildRoot,
350
+ "node_modules",
351
+ ...packageName.split("/")
352
+ );
353
+ fs.mkdirSync(packageDir, { recursive: true });
354
+ await bundle(entry, path.join(packageDir, "index.js"));
355
+ fs.writeFileSync(
356
+ path.join(packageDir, "package.json"),
357
+ `${JSON.stringify(
358
+ {
359
+ name: packageName,
360
+ version: packageVersionOf(entry, packageName),
361
+ private: true,
362
+ type: "module",
363
+ main: "index.js"
364
+ },
365
+ null,
366
+ 2
367
+ )}
368
+ `
369
+ );
370
+ }
371
+ }
372
+ function packageVersionOf(entry, packageName) {
303
373
  let cursor = path.dirname(entry);
304
374
  for (let i = 0; i < 4; i += 1) {
305
375
  const manifest = path.join(cursor, "package.json");
306
376
  if (isFile(manifest)) {
307
377
  try {
308
378
  const pkg = JSON.parse(fs.readFileSync(manifest, "utf-8"));
309
- if (pkg.name === "@altananetwork/sdk") {
379
+ if (pkg.name === packageName) {
310
380
  return typeof pkg.version === "string" ? pkg.version : "0.0.0";
311
381
  }
312
382
  } catch {
@@ -686,8 +756,8 @@ function packageRoot() {
686
756
  }
687
757
  }
688
758
  function studioCliVersion() {
689
- if ("0.0.11") {
690
- return "0.0.11";
759
+ if ("0.0.12-alpha.2") {
760
+ return "0.0.12-alpha.2";
691
761
  }
692
762
  const file = path3.join(packageRoot(), "package.json");
693
763
  const pkg = JSON.parse(fs3.readFileSync(file, "utf-8"));
@@ -18,7 +18,7 @@ import {
18
18
  runPlatformAccountCommand,
19
19
  trialFromDeployCliJson,
20
20
  withDeployFiles
21
- } from "./chunk-VGSWNATS.js";
21
+ } from "./chunk-XJFJU2AT.js";
22
22
  import "./chunk-RO726HJG.js";
23
23
  export {
24
24
  BNB_PLATFORM_API_URL,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bnbagent/studio-cli",
3
- "version": "0.0.11",
3
+ "version": "0.0.12-alpha.2",
4
4
  "description": "Skills-first toolkit and bag CLI for BNB Chain seller agents: ERC-8004 identity, ERC-8183 escrowed commerce, and x402 payments.",
5
5
  "keywords": [
6
6
  "bnb-chain",
@@ -25,7 +25,6 @@
25
25
  "directory": "packages/studio-cli"
26
26
  },
27
27
  "type": "module",
28
- "packageManager": "pnpm@10.24.0",
29
28
  "engines": {
30
29
  "node": ">=22"
31
30
  },
@@ -42,16 +41,8 @@
42
41
  "bin": {
43
42
  "bag": "./dist/bag.js"
44
43
  },
45
- "scripts": {
46
- "build": "tsup",
47
- "test": "vitest run",
48
- "lint": "biome check src tests",
49
- "typecheck": "tsc --noEmit",
50
- "check": "pnpm typecheck && pnpm lint && pnpm test && pnpm build"
51
- },
52
44
  "dependencies": {
53
- "@bnbagent/sdk": "0.5.0",
54
- "@bnbagent/studio-runtime": "0.0.11",
45
+ "@bnbagent/sdk": "0.5.1-alpha.3",
55
46
  "ai": "^7.0.29",
56
47
  "archiver": "^8.0.0",
57
48
  "commander": "^15.0.0",
@@ -62,7 +53,8 @@
62
53
  "smol-toml": "^1.3.0",
63
54
  "tar": "^7.4.0",
64
55
  "viem": "^2.54.0",
65
- "yaml": "^2.9.0"
56
+ "yaml": "^2.9.0",
57
+ "@bnbagent/studio-runtime": "0.0.12-alpha.2"
66
58
  },
67
59
  "devDependencies": {
68
60
  "@a2a-js/sdk": "^0.3.14",
@@ -78,5 +70,12 @@
78
70
  "typescript": "^5.5.0",
79
71
  "vitest": "^2.0.0",
80
72
  "zod": "^3.25.76"
73
+ },
74
+ "scripts": {
75
+ "build": "tsup",
76
+ "test": "vitest run",
77
+ "lint": "biome check src tests",
78
+ "typecheck": "tsc --noEmit",
79
+ "check": "pnpm typecheck && pnpm lint && pnpm test && pnpm build"
81
80
  }
82
- }
81
+ }
@@ -11,7 +11,7 @@ node = [
11
11
  # neutral. The agent project's serving deps (@a2a-js/sdk / MCP SDK / ai)
12
12
  # come from the runtimes/<R>/ recipe selected at `bag init` time.
13
13
  "@bnbagent/studio-runtime",
14
- "@bnbagent/sdk@0.5.0",
14
+ "@bnbagent/sdk@0.5.1-alpha.2",
15
15
  ]
16
16
 
17
17
  [env]
@@ -32,7 +32,7 @@ node = [
32
32
  # BNBAGENT_RUNTIME_SECRET_ID is set (default secretsmanager mode + platform).
33
33
  "@aws-sdk/client-secrets-manager@^3.600.0",
34
34
  "@bnbagent/studio-runtime",
35
- "@bnbagent/sdk@0.5.0",
35
+ "@bnbagent/sdk@0.5.1-alpha.2",
36
36
  # The LLM work hook (generateText + tools) and the model factory.
37
37
  "ai@^7.0.29",
38
38
  # Tool input schemas (AI SDK tools + MCP registerTool).
@@ -29,7 +29,7 @@ node = [
29
29
  # on either cloud.
30
30
  "@aws-sdk/client-secrets-manager@^3.600.0",
31
31
  "@bnbagent/studio-runtime",
32
- "@bnbagent/sdk@0.5.0",
32
+ "@bnbagent/sdk@0.5.1-alpha.2",
33
33
  # The LLM work hook (generateText + tools) and the model factory
34
34
  # (model.ts buildModel — studio.toml [llm] + the provider key env).
35
35
  "ai@^7.0.29",
@@ -1,17 +1,22 @@
1
1
  [recipe]
2
2
  name = "wallet"
3
- description = "Configures the agent's wallet: 'evm-local' (default encrypted keystore), 'twak' (Trust Wallet Agent Kit CLI), or 'altana' (encrypted admin keystore plus one bounded runtime session)."
3
+ description = "Configures the agent's wallet: 'evm-local' (default encrypted keystore), 'twak' (Trust Wallet Agent Kit CLI), 'altana' (encrypted admin keystore plus one bounded runtime session), or 'turnkey' (remote signer; the key lives in Turnkey's AWS Nitro enclave)."
4
4
 
5
5
  [dependencies]
6
6
  node = ["@bnbagent/studio-runtime"]
7
7
 
8
8
  [dependencies.altana]
9
- node = ["@altananetwork/sdk@0.5.1"]
9
+ node = ["@altananetwork/sdk@0.7.1"]
10
+
11
+ [dependencies.turnkey]
12
+ node = ["@turnkey/sdk-server@8.1.0", "@turnkey/viem@0.14.34"]
10
13
 
11
14
  [env]
12
15
  # kind='twak': the twak CLI reads the unlock password from the environment —
13
16
  # it never goes on a command line.
14
17
  TWAK_WALLET_PASSWORD = "unlocks ~/.twak/wallet.json (twak kind); set in .studio/.env.local"
18
+ # kind='turnkey': P-256 API credential; the signing key never leaves Turnkey's enclave.
19
+ TURNKEY_API_PRIVATE_KEY = "Turnkey P-256 API private key (turnkey kind); set in .studio/.env.local"
15
20
  # kind='evm-local' (the `bag init` default) or kind='altana' admin operations:
16
21
  WALLET_PASSWORD = "set to a strong password (>= 12 chars); encrypts .studio/wallets/<addr>.json (runtime never receives it for altana)"
17
22
 
@@ -6,7 +6,7 @@ status = "v0.0.x"
6
6
  [dependencies]
7
7
  node = [
8
8
  "@bnbagent/studio-runtime",
9
- "@bnbagent/sdk@0.5.0",
9
+ "@bnbagent/sdk@0.5.1-alpha.2",
10
10
  "ai@^7.0.29", # AI SDK `tool` wrappers around the buyer functions
11
11
  "zod@^3.25.0", # tool input schemas
12
12
  ]
@@ -51,6 +51,8 @@ verified = true # studio-reviewed shelf
51
51
 
52
52
  Hard-stop cases: a reviewed merchant whose live payTo drifts from the studio pin (address rotation or tampering - upgrade studio or verify out-of-band and pass `--pay-to`), and `--cap` below the live per-call price.
53
53
 
54
+ Wallet kinds and rails: `evm-local` signs EIP-3009 locally; `twak` and `altana` route through a delegated payer that prefers the merchant's permit2 route. Altana smart-account payments are verified by the B402 facilitator on its permit2 rails (live since 2026-08, CMC field-verified) and need the one-time `bag wallet session x402-setup` arming (checker approval + bounded U→Permit2 allowance) - `bag doctor` shows the arming state as `[wallet] Altana x402 buying`.
55
+
54
56
  ## Step 2 - wire the buyer tools into the agent
55
57
 
56
58
  ```bash
@@ -99,7 +101,8 @@ bag dev # then ask the agent something that needs the paid data
99
101
  | `X402RecipientRequiredError` | No pinned recipient for that host → same fix |
100
102
  | `X402RecipientMismatchError` | Live payTo drifted from the pin - do NOT override casually; re-verify the merchant |
101
103
  | `X402BudgetExhaustedError` | Per-call cap or daily budget hit - raise `per_call_cap_usd` / `[budget].max_per_day_usd` deliberately |
102
- | `x402 402 has no EIP-3009-payable option` | Merchant offers only permit2/other methods for $U on this network - not payable by this buyer today |
104
+ | `x402 402 has no EIP-3009-payable option` | Merchant offers only permit2/other methods for $U on this network - a local-signing (`evm-local`) buyer cannot sign those. Delegated wallets pay permit2 routes through their own client: `twak` (mainnet), or `altana` sessions (ERC-1271; B402 verifies them on the permit2 rails - arm once with `bag wallet session x402-setup`) |
105
+ | `U→Permit2 allowance … cannot cover max_usd` | Altana only: the bounded Permit2 allowance is spent/too small - re-run `bag wallet session x402-setup --allowance-u <amount>` (admin key) |
103
106
  | `X402PolicyError` / `PolicyViolation` | Signing allowlist - see `bnbagent-studio-extending-signing.md` |
104
107
 
105
108
  **Different from**:
@@ -61,7 +61,7 @@ The user wants the agent to pay e.g. `api.example.com` via x402.
61
61
  2. The service uses **EIP-3009 `TransferWithAuthorization`** (or `ReceiveWithAuthorization`). If it uses Permit2 or a custom primary type → goes to Section B.
62
62
  3. The token contract address on BSC is known and the user can confirm it. Don't guess from a token symbol - look up the deployed address.
63
63
 
64
- If any of (1)-(3) fail, **stop and tell the user**. The current release cannot integrate cross-chain services or non-EIP-3009 payment rails. Do not work around it; the SigningPolicy will refuse the request.
64
+ If any of (1)-(3) fail, **stop and tell the user**. The current release cannot integrate cross-chain services or non-EIP-3009 payment rails into the LOCAL signer. Do not work around it; the SigningPolicy will refuse the request. (Merchants that only offer permit2 are still payable without touching SigningPolicy - through a delegated wallet kind: `twak`, or `altana` sessions, whose ERC-1271 signatures B402 verifies on its permit2 rails. That is a wallet-kind choice, not a signing extension.)
65
65
 
66
66
  **Steps when (1)-(3) all pass:**
67
67
 
@@ -144,7 +144,7 @@ When the credentials, IP allowlist, and facilitator environment are ready, run t
144
144
  bag x402 sell status
145
145
  ```
146
146
 
147
- For a sandbox/trial agent, it must find exact/eip3009 U on `eip155:97`. For production it must find the mainnet environment expected by the project. A network mismatch is not safe to ignore.
147
+ For a sandbox/trial agent, it must find an exact U kind on `eip155:97` (the probe lists the offered rails, e.g. `(eip3009, permit2-exact)`). For production it must find the mainnet environment expected by the project. A network mismatch is not safe to ignore.
148
148
 
149
149
  Run the deployment gate, then redeploy to activate the selected mode:
150
150
 
@@ -165,4 +165,5 @@ On the managed platform the deploy summary must say `x402 rail is ACTIVE` (or `A
165
165
  - Settlement happens before work. A later work failure retains the payment and does not trigger an automatic refund.
166
166
  - The rail activates on AgentCore and Azure Foundry targets (managed platform or self-hosted); self-hosted targets have no anonymous URL and need an operator-run envelope-v1 front.
167
167
  - PAID B402 payout wallets must use `wallet.kind` `evm-local` (private-key wallet stored as an encrypted keystore) or `twak`. Altana is unsupported. FREE x402 bypasses B402, has no payout, and must not be described as Altana B402 support.
168
+ - Buyer compatibility: the 402 challenge advertises both `exact` rails - `eip3009` (EOA buyers, no pre-authorization) and `permit2-exact` (B402 verifies ERC-1271 smart-account signatures on this rail, so Altana sessions and ERC-4337 wallets can pay; the buyer needs a bounded U→Permit2 allowance first - see `bnbagent-studio-using-altana-wallet.md`). Rails are filtered against the facilitator's live `/supported`; `bag x402 sell status` prints which rails it actually offers, e.g. `(eip3009, permit2-exact)`. The seller never verifies signatures locally on either rail.
168
169
  - Never describe FREE as a zero-value B402 settlement. It bypasses B402.
@@ -48,6 +48,8 @@ x402 buying remains separate and exact-bounded:
48
48
  bag wallet session x402-setup --allowance-u <U> --yes
49
49
  ```
50
50
 
51
+ Once armed, `bag x402 buy` pays b402-facilitated merchants (e.g. CoinMarketCap) end to end: B402 verifies the session's ERC-1271 signature on its **permit2 rails** (live since 2026-08). Studio's own b402 sellers advertise `permit2-exact` alongside `eip3009`, so Altana wallets can pay studio-hosted merchants too; eip3009-only merchants still need a 65-byte EOA signature and cannot be paid by a smart account. The buy preflight checks the U→Permit2 allowance against the spend cap, and `bag doctor` reports `[wallet] Altana x402 buying`. Use `@altananetwork/sdk` 0.7.1 in the project.
52
+
51
53
  Altana cannot be the b402 **seller** payout wallet for a positive price (paid mode allows `evm-local` and `twak` only); init, `bag x402 sell init`, and deploy readiness reject that paid combination. Explicit `price_usd = "0"` is allowed because FREE passthrough performs no payout and bypasses B402. The outbound buying authority above remains a separate feature.
52
54
 
53
55
  For troubleshooting, run `bag doctor` and `bag wallet session status`. Do not print, parse, or copy the `signer` portion of the serialized session, and never move `.studio/wallets/` under `app/agent/`.