@bnbagent/studio-runtime

中文文档
0.0.16发布于 2026/10/26Apache-2.0TypeScriptESM + CJS近 30 天下载 1793

Runtime library for bnbagent-studio seller agents on BNB Chain (config, wallet, audit, ERC-8004/8183, x402 or MPP over B402, Pieverse, read-only chain tools).

原始使用文档
文档目录20 节
  1. Where it sits
  2. What the runtime provides
  3. Install
  4. Recommended: let Studio wire it for you
  5. Direct library installation
  6. Root API
  7. Public subpaths
  8. Common integrations
  9. Read-only chain tools
  10. Guarded x402 buying
  11. ERC-8183 workflows
  12. ERC-8004 identity
  13. Runtime conventions
  14. Project discovery
  15. Configuration and amounts
  16. Wallet material
  17. Storage and audit
  18. Security boundaries
  19. Runtime versus CLI
  20. Disclaimer

@bnbagent/studio-runtime

npm version Node.js License

The TypeScript runtime library behind bnbagent-studio seller agents: configuration, wallet custody, signing policy, audit, ERC-8004 identity, ERC-8183 commerce, x402 or MPP payments over B402, Pieverse credit, deliverable storage, and read-only chain tools.

Most users should not start by programming against this package. Install @bnbagent/studio-cli, run bag skills install, and use /bnbagent-studio in Claude Code or Cursor. The skill designs the workflow; bag init generates the agent; the generated agent imports this runtime.

The runtime is under active development and may introduce breaking changes before 1.0. Start on BSC testnet and pin compatible Studio and SDK versions.

Where it sits

Claude Code / Cursor
        │  /bnbagent-studio
        ▼
@bnbagent/studio-cli (`bag`)       design, scaffold, diagnose, deploy, operate
        │  generates
        ▼
your app/agent source              business value, prompts, faces, fixed signing
        │  imports
        ▼
@bnbagent/studio-runtime           config, custody, policy, commerce, storage, tools
        │  uses
        ▼
@bnbagent/sdk + BNB Chain          protocol and on-chain implementation

The runtime is a deployment dependency; the CLI is not. An emitted agent keeps running if the global CLI is removed. Studio releases the CLI and runtime together so newly generated code and its runtime surface stay aligned.

What the runtime provides

  • A consistent studio.toml and workspace-discovery model for local and deployed execution.
  • Exactly three wallet backends: encrypted evm-local, Trust Wallet Agent Kit twak, and bounded-session altana.
  • Fixed signing policy and spend boundaries for ERC-8183 and x402 operations.
  • ERC-8004 registration, resolution, metadata, and service-endpoint reconciliation.
  • ERC-8183 quote verification plus buy, submit, fetch, and settle workflows.
  • Guarded x402 and native MPP+B402 buyers with host, recipient, asset, network, per-request, retry/dispatch, receipt, and daily-budget checks.
  • A protocol-selecting B402 seller with alternative x402 and MPP adapters, settle-before-work paid requests, explicit FREE passthrough, and replay protection.
  • Pieverse authentication, model discovery, usage, credit, x402 top-up, and renewal building blocks.
  • Local or IPFS deliverable storage and append-only redacted audit events.
  • Fifteen read-only tools that can be wrapped for Vercel AI SDK, MCP, or another agent framework.

Install

npm install --global @bnbagent/studio-cli
bag skills install

Then ask the installed skill to create or extend a seller:

/bnbagent-studio Create a BNB Chain seller agent named researchagent and help me
choose its commerce rail, service faces, wallet, LLM, storage, and deployment.

bag init writes a compatible runtime and SDK dependency into app/agent/package.json.

Direct library installation

npm install @bnbagent/studio-runtime @bnbagent/sdk

Requirements and package formats:

  • Node.js 22 or newer;
  • peer dependency @bnbagent/sdk >=0.6.1 <0.7.0 (0.6.1 is the security floor: it carries the SDK bug-bounty fixes the seller gate and wallet flows rely on);
  • ESM, CommonJS, and TypeScript declarations for the root and every documented subpath;
  • framework-neutral core: no agent framework or web server is imported by this package.

LLM model resolution uses the Vercel AI SDK. Chain access and transaction types use viem and @bnbagent/sdk.

Root API

The root export is intentionally small and matches the conveniences used by generated code:

import {
  findProjectRoot,
  getPolicy,
  getWallet,
  loadStudioToml,
} from "@bnbagent/studio-runtime";

const projectRoot = findProjectRoot();
if (projectRoot === null) {
  throw new Error("studio.toml was not found");
}

const config = loadStudioToml();
const policy = getPolicy();
const wallet = getWallet();

console.log({
  projectRoot,
  project: config.project,
  walletAddress: wallet.address,
  policy,
});

The root also exports Policy and the telemetry emit helper. Import focused APIs from subpaths so dependencies and security boundaries remain visible in your code.

Public subpaths

ImportMain responsibilities
@bnbagent/studio-runtimeProject discovery plus config, policy, telemetry, and wallet conveniences.
@bnbagent/studio-runtime/configFind workspace and agent roots, load studio.toml, load local env values, and read the agent registry.
@bnbagent/studio-runtime/policyConstruct the frozen runtime Policy used by generated code.
@bnbagent/studio-runtime/secretWriteAtomically create owner-only secret files.
@bnbagent/studio-runtime/networksBSC network and U-token registry, RPC selection, and decimal-string/bigint conversion.
@bnbagent/studio-runtime/walletBuild evm-local, twak, or altana wallet providers and apply signing policy.
@bnbagent/studio-runtime/llmResolve Studio LLM configuration to a Vercel AI SDK language model.
@bnbagent/studio-runtime/storageSelect local development storage or durable IPFS storage for deliverables.
@bnbagent/studio-runtime/auditRecord, query, tail, and wrap operations in append-only redacted audit events.
@bnbagent/studio-runtime/erc8004Register and resolve identities; update metadata and protocol-specific service endpoints.
@bnbagent/studio-runtime/erc8183Negotiate, verify, buy, inspect, submit, fetch, and settle escrowed jobs.
@bnbagent/studio-runtime/x402Guarded x402 buyer, budget ledger, payment signing, seller policy, B402 seller, and HTTP envelope middleware.
@bnbagent/studio-runtime/mppNative MPP+B402 quote/buy client, merchant trust policy, payment-outcome errors, and EIP-3009-only dispatch.
@bnbagent/studio-runtime/b402Protocol-neutral B402 seller, canonical policy, X402/MPP adapter selection, sell-path resolution, MPP replay-store injection, and HTTP envelope middleware.
@bnbagent/studio-runtime/pieverseSIWE/API-key lifecycle, model catalogue, usage, credit allocation, top-up, and auto-renew support.
@bnbagent/studio-runtime/toolsFifteen pure read-only wallet, chain, identity, commerce, transaction, block, contract-view, and network tools.

The generated .d.ts files shipped with the package are the exact symbol and argument reference for every entry point.

Common integrations

Read-only chain tools

The tools module does not expose signing. You can call it directly or wrap selected functions for an LLM framework:

import {
  balanceNative,
  balanceU,
  networkInfo,
  walletAddress,
} from "@bnbagent/studio-runtime/tools";

const address = await walletAddress();
const [native, u, network] = await Promise.all([
  balanceNative(address, "bsc-testnet"),
  balanceU(address, "bsc-testnet"),
  networkInfo("bsc-testnet"),
]);

console.log({ native, u, network });

The complete read-only set is walletInfo, walletList, walletAddress, balanceNative, balanceU, pieverseUsage, agentInfo, agentByAddress, jobStatus, jobList, jobCount, txStatus, blockInfo, contractCallView, and networkInfo.

Guarded x402 buying

The buyer first probes a protected URL, validates the returned payment requirements against policy, signs the bounded payment, and retries the paid request. Configure or trust the merchant before using it; an allowed host is not permission to pay an arbitrary recipient.

The parallel MPP buyer lives at @bnbagent/studio-runtime/mpp. It accepts only native b402.charge challenges, validates a pinned realm and recipient plus Studio-owned B402 token facts, and permits one EIP-3009 paid dispatch. A missing success receipt or lost post-dispatch response is reported as unknown; callers must not retry automatically. P0 requires an evm-local-compatible sign.typed_data wallet.

import { loadStudioToml } from "@bnbagent/studio-runtime/config";
import { getWallet } from "@bnbagent/studio-runtime/wallet";
import {
  fetchWithPayment,
  X402BuyerPolicy,
} from "@bnbagent/studio-runtime/x402";

const policy = X402BuyerPolicy.fromToml(loadStudioToml());
const result = await fetchWithPayment("https://merchant.example/resource", {
  wallet: getWallet(),
  maxUsd: Math.min(0.25, policy.maxPerRequestUsd),
  allowedHosts: [...policy.effectiveAllowedHosts],
});

console.log({
  status: result.statusCode,
  paidUsd: result.paidUsd,
  body: result.json,
});

Use bag x402 trust to pin a merchant domain to its expected payout address and per-call cap. The runtime byte-compares the challenge recipient, constrains the network and asset, applies the tighter of caller and policy caps, and shares the configured daily ledger with other paid calls.

ERC-8183 workflows

The ERC-8183 subpath separates the critical stages rather than exposing a general transaction primitive:

  • negotiateWithSeller obtains a seller's signed quote;
  • verifySignedJob checks that an on-chain funded job still matches the signed terms and expected seller;
  • buyWorkflow performs the buyer-side create, register, budget, and fund sequence;
  • submitWorkflow submits the seller's deliverable reference;
  • fetchWorkflow retrieves a submitted deliverable;
  • settleWorkflow performs the authorized approve, reject, or dispute decision;
  • getJobSummary reads the current on-chain state.

Generated seller code keeps quote creation and funded-job verification in src/signing.ts. The LLM implements only the work in src/sellerCore.ts; it does not choose prices, see raw signing methods, or decide whether a job is funded.

ERC-8004 identity

The identity subpath provides register, show, resolve, resolveService, setMetadata, updateEndpoint, and updateServiceEndpoint. The protocol-aware helpers normalize A2A agent-card and MCP streamable endpoints so updating one service does not erase another.

In a generated project, prefer bag deploy verify --provider <bnb|aws> after deployment. It checks provider state and reconciles the live endpoint with ERC-8004. Direct runtime functions are appropriate when you are integrating Studio into another application and own the lifecycle yourself.

Runtime conventions

Project discovery

Generated workspaces keep studio.toml in app/agent/ and sensitive local state in workspace-root .studio/. Discovery walks upward from the current process and understands both locations. Do not move the wallet directory under app/agent/; that directory is the deployable code root.

Configuration and amounts

  • Configuration and CLI boundaries use decimal strings so token amounts do not lose precision.
  • Payment code converts amounts to bigint internally.
  • U used by ERC-8183 has 18 decimals; a B402/x402 test token may use different decimals and is not interchangeable.
  • "0" is a deliberate FREE price, not a missing value. ERC-8183 skips token escrow at zero; x402 bypasses B402 entirely at zero.
  • RPC overrides are per network. Signing domains, allowed hosts, recipients, assets, contract addresses, and budgets are security configuration, not cosmetic settings.

Wallet material

  • evm-local reads an encrypted keystore from workspace-root .studio/wallets/ and unlocks it with WALLET_PASSWORD.
  • twak uses a project-dedicated Trust Wallet Agent Kit home and its custody provider.
  • altana keeps the admin keystore local and gives the runtime only a bounded session through ALTANA_SESSION.

Local secrets are not part of the deploy artifact. The CLI collects the minimum runtime material and sends it through the selected deployment secret channel. Do not manually bundle .studio/, echo secret values, or put passwords on command lines.

Storage and audit

Local deliverable storage is for development and deliberately fails deploy readiness because it will not survive a remote runtime. IPFS storage is durable and public; configure the pinning service upload endpoint and write key before a real delivery. Audit helpers redact sensitive fields and append operation records, but an audit log is not a substitute for on-chain state verification.

Security boundaries

  • One signer: the generated agent is the only wallet holder for its seller runtime.
  • No LLM signing: never wrap wallet signing, arbitrary transactions, quote signing, or settlement as an LLM tool.
  • Deterministic money paths: price clamps, quote signing, funded-state verification, and x402 settlement belong in fixed code.
  • Verify before work: positive-price ERC-8183 work begins only after the funded job matches the signed terms; positive-price x402 work begins only after settlement.
  • Fail closed: recipient, host, asset, network, amount, contract, nonce, expiry, retry, and daily-budget checks are authorization boundaries.
  • Manual buyer settlement: a submitted ERC-8183 job still requires an authorized approve, reject, or dispute action.
  • No generic transaction toolkit: use the bounded workflow APIs and keep the LLM-facing tool surface read-only.

Runtime versus CLI

NeedUse
Create, extend, run, diagnose, or deploy a seller/bnbagent-studio skill installed by @bnbagent/studio-cli
Automate a documented lifecycle stepbag CLI
Implement the generated agent's runtime behavior@bnbagent/studio-runtime
Build a custom host or framework integrationRuntime subpath APIs plus @bnbagent/sdk
Inspect exact command flagsbag --help or bag <command> --help
Inspect exact TypeScript symbolsThe package's shipped declaration files

Disclaimer

This runtime handles wallet access, signing policy, blockchain transactions, paid requests, and deliverable storage. Its checks reduce specific risks, but they do not make an agent, integration, counterparty, smart contract, model output, storage provider, RPC service, payment facilitator, or deployment platform trustworthy.

If you integrate the runtime directly, you are responsible for preserving its fixed signing boundaries, validating configuration and counterparties, protecting keys and credentials, reviewing transaction and settlement authority, limiting spend, securing infrastructure, and paying any resulting network or cloud costs. Test custom code and contract deployments on BSC testnet before using real funds.

This package is licensed under Apache-2.0 and provided as is, without warranties or guarantees. The authors and contributors are not responsible for lost funds, compromised credentials, service interruptions, unexpected charges, or other damages arising from its use. Nothing in this package is financial, investment, legal, or tax advice.

版本与发布记录

@bnbagent/studio-runtime 共发布 53 个版本,首次发布于 2026/07/30;过去 12 个月发布了 53 个版本。

版本发布日期距今
0.0.16latest2026/10/2613 天前
0.0.152026/10/1623 天前
0.0.15-alpha.1alpha2026/10/1523 天前
0.0.142026/09/201 个月前
0.0.14-alpha.102026/09/161 个月前
0.0.14-alpha.92026/09/151 个月前

关于 @bnbagent/studio-runtime 的常见问题

@bnbagent/studio-runtime 是什么?

Runtime library for bnbagent-studio seller agents on BNB Chain (config, wallet, audit, ERC-8004/8183, x402 or MPP over B402, Pieverse, read-only chain tools).

如何安装 @bnbagent/studio-runtime?

在项目目录运行 npm install @bnbagent/studio-runtime,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@bnbagent/sdk(>=0.6.1 <0.7.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@bnbagent/studio-runtime 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@bnbagent/studio-runtime 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@bnbagent/studio-runtime 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@bnbagent/studio-runtime 可以商用吗?

@bnbagent/studio-runtime 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@bnbagent/studio-runtime 的下载量有多少?

根据 npm 官方下载统计,@bnbagent/studio-runtime 在 2026/10/09 – 2026/11/07 这 30 天内被下载 1,793 次,日均约 60 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@bnbagent/studio-runtime 还在维护吗?

最新版本 0.0.16 发布于 2026/10/26(13 天前);至今共发布 53 个版本,其中过去 12 个月发布了 53 个;首次发布于 2026/07/30。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。