@blockrun/clawrouter 0.12.267 → 0.12.268
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 +147 -21
- package/dist/cli.js +664 -157
- package/dist/index.d.ts +58 -11
- package/dist/index.js +326 -90
- package/docs/configuration.md +102 -9
- package/openclaw.plugin.json +9 -0
- package/package.json +3 -2
package/dist/index.d.ts
CHANGED
|
@@ -543,6 +543,38 @@ declare class BalanceMonitor {
|
|
|
543
543
|
/** Build BalanceInfo from raw balance */
|
|
544
544
|
private buildInfo;
|
|
545
545
|
}
|
|
546
|
+
/**
|
|
547
|
+
* The balance monitor for API-key mode.
|
|
548
|
+
*
|
|
549
|
+
* There is no wallet to read. Credit lives in the customer's BlockRun account
|
|
550
|
+
* and the gateway is its own authority on it: a call that outruns the balance
|
|
551
|
+
* comes back as HTTP 402 `insufficient_quota`, with a message pointing at the
|
|
552
|
+
* top-up page. api.blockrun.ai publishes no key-authenticated balance endpoint,
|
|
553
|
+
* so ClawRouter cannot poll one, and inventing a number here would be worse
|
|
554
|
+
* than having none — the free-model fallback downgrades a request the moment
|
|
555
|
+
* the monitor reports empty, and a guessed zero would silently move a paying
|
|
556
|
+
* customer onto the free tier.
|
|
557
|
+
*
|
|
558
|
+
* So this reports "always sufficient" and lets the server refuse. That is not
|
|
559
|
+
* a bypass of the spend gate: the gate it satisfies is the local *wallet*
|
|
560
|
+
* check, which exists because an x402 payment that fails after the stream
|
|
561
|
+
* opens is unrecoverable. An API-key call is refused before a single token is
|
|
562
|
+
* generated, which is the stronger guarantee, and it is enforced server-side
|
|
563
|
+
* where the actual balance is.
|
|
564
|
+
*/
|
|
565
|
+
declare class ApiKeyBalanceMonitor {
|
|
566
|
+
/** Large enough that every `balance >= estimatedCost` comparison passes. */
|
|
567
|
+
private static readonly UNMETERED;
|
|
568
|
+
checkBalance(): Promise<BalanceInfo>;
|
|
569
|
+
checkSufficient(): Promise<SufficiencyResult>;
|
|
570
|
+
/** No local cache to adjust — the server keeps the books. */
|
|
571
|
+
deductEstimated(): void;
|
|
572
|
+
invalidate(): void;
|
|
573
|
+
refresh(): Promise<BalanceInfo>;
|
|
574
|
+
formatUSDC(amountMicros: bigint): string;
|
|
575
|
+
/** No wallet in this mode; callers render the account instead. */
|
|
576
|
+
getWalletAddress(): string;
|
|
577
|
+
}
|
|
546
578
|
|
|
547
579
|
/**
|
|
548
580
|
* Solana USDC Balance Monitor
|
|
@@ -999,8 +1031,8 @@ declare function hashRequestContent(lastUserContent: string, toolCallNames?: str
|
|
|
999
1031
|
* - Usage logging: log every request as JSON line to ~/.openclaw/blockrun/logs/
|
|
1000
1032
|
*/
|
|
1001
1033
|
|
|
1002
|
-
/** Union type for chain-agnostic balance monitoring */
|
|
1003
|
-
type AnyBalanceMonitor = BalanceMonitor | SolanaBalanceMonitor;
|
|
1034
|
+
/** Union type for chain- and auth-agnostic balance monitoring */
|
|
1035
|
+
type AnyBalanceMonitor = BalanceMonitor | SolanaBalanceMonitor | ApiKeyBalanceMonitor;
|
|
1004
1036
|
|
|
1005
1037
|
/**
|
|
1006
1038
|
* Get the proxy port from pre-loaded configuration.
|
|
@@ -1029,8 +1061,26 @@ type WalletConfig = string | {
|
|
|
1029
1061
|
solanaPrivateKeyBytes?: Uint8Array;
|
|
1030
1062
|
};
|
|
1031
1063
|
type PaymentChain = "base" | "solana";
|
|
1064
|
+
/**
|
|
1065
|
+
* How this proxy pays BlockRun.
|
|
1066
|
+
* - "wallet" — x402 micropayments signed per call from a local USDC wallet.
|
|
1067
|
+
* - "api-key" — a `brk_…` bearer token drawing on account credit topped up by
|
|
1068
|
+
* card at https://user.blockrun.ai. No wallet, no chain, no gas.
|
|
1069
|
+
*/
|
|
1070
|
+
type AuthMode = "wallet" | "api-key";
|
|
1032
1071
|
type ProxyOptions = {
|
|
1033
|
-
|
|
1072
|
+
/**
|
|
1073
|
+
* Wallet material for x402 mode. Optional only when `apiKey` is set — one of
|
|
1074
|
+
* the two must be present or the proxy has no way to pay for anything.
|
|
1075
|
+
*/
|
|
1076
|
+
wallet?: WalletConfig;
|
|
1077
|
+
/**
|
|
1078
|
+
* BlockRun API key (`brk_…`). When present it wins over `wallet`: the proxy
|
|
1079
|
+
* talks to api.blockrun.ai with a bearer token and signs no payments at all.
|
|
1080
|
+
* Also readable from BLOCKRUN_API_KEY / ~/.blockrun/.api-key via
|
|
1081
|
+
* resolveApiKey(); callers resolve it and pass it in.
|
|
1082
|
+
*/
|
|
1083
|
+
apiKey?: string;
|
|
1034
1084
|
apiBase?: string;
|
|
1035
1085
|
/**
|
|
1036
1086
|
* Payment chain: "base" or "solana". New installs persist "solana" at wallet
|
|
@@ -1132,19 +1182,16 @@ type ProxyOptions = {
|
|
|
1132
1182
|
type ProxyHandle = {
|
|
1133
1183
|
port: number;
|
|
1134
1184
|
baseUrl: string;
|
|
1185
|
+
/** The x402 signer's address, or "" in API-key mode (there is no wallet). */
|
|
1135
1186
|
walletAddress: string;
|
|
1136
1187
|
solanaAddress?: string;
|
|
1188
|
+
/** Which credential this proxy is paying with. */
|
|
1189
|
+
authMode: AuthMode;
|
|
1190
|
+
/** Masked API key, for status display. Only set in API-key mode. */
|
|
1191
|
+
apiKeyLabel?: string;
|
|
1137
1192
|
balanceMonitor: AnyBalanceMonitor;
|
|
1138
1193
|
close: () => Promise<void>;
|
|
1139
1194
|
};
|
|
1140
|
-
/**
|
|
1141
|
-
* Start the local x402 proxy server.
|
|
1142
|
-
*
|
|
1143
|
-
* If a proxy is already running on the target port, reuses it instead of failing.
|
|
1144
|
-
* Port can be configured via BLOCKRUN_PROXY_PORT environment variable.
|
|
1145
|
-
*
|
|
1146
|
-
* Returns a handle with the assigned port, base URL, and a close function.
|
|
1147
|
-
*/
|
|
1148
1195
|
declare function startProxy(options: ProxyOptions): Promise<ProxyHandle>;
|
|
1149
1196
|
|
|
1150
1197
|
/**
|