@blockrun/clawrouter 0.12.267 → 0.12.269
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 +168 -21
- package/dist/cli.js +804 -204
- package/dist/index.d.ts +86 -12
- package/dist/index.js +465 -136
- 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
|
|
@@ -633,6 +665,14 @@ declare const PAYABLE_NETWORKS: readonly string[];
|
|
|
633
665
|
* pay, which is the one direction this file must never fail in. Callers
|
|
634
666
|
* classify on `instanceof`, not on the message text.
|
|
635
667
|
*/
|
|
668
|
+
/**
|
|
669
|
+
* spending.json exists but could not be read or parsed. Distinct from "no file
|
|
670
|
+
* yet" (load() returns null) so a reload can tell a failed read from an empty
|
|
671
|
+
* store and refuse to widen what the agent may pay.
|
|
672
|
+
*/
|
|
673
|
+
declare class UnreadableSpendPolicyError extends Error {
|
|
674
|
+
constructor(cause: unknown);
|
|
675
|
+
}
|
|
636
676
|
declare class MalformedSpendPolicyError extends Error {
|
|
637
677
|
constructor(key: string);
|
|
638
678
|
}
|
|
@@ -784,6 +824,15 @@ declare class SpendControl {
|
|
|
784
824
|
* reporting a change as applied.
|
|
785
825
|
*/
|
|
786
826
|
getPolicyFileError(): string | undefined;
|
|
827
|
+
/**
|
|
828
|
+
* Re-read limits from storage, keeping this instance's history and open
|
|
829
|
+
* reservations. Used on an in-process proxy restart so a hand-edit to
|
|
830
|
+
* spending.json made while the process was running still applies, without
|
|
831
|
+
* resetting the rolling windows. Fails closed exactly like the constructor:
|
|
832
|
+
* a malformed file refuses every payment until repaired, and a repaired
|
|
833
|
+
* file clears that refusal.
|
|
834
|
+
*/
|
|
835
|
+
reloadLimits(): void;
|
|
787
836
|
check(estimatedCost: number, counterparty?: CounterpartyInfo): CheckResult;
|
|
788
837
|
record(amount: number, metadata?: {
|
|
789
838
|
model?: string;
|
|
@@ -818,6 +867,16 @@ declare class SpendControl {
|
|
|
818
867
|
getRemaining(window: "hourly" | "daily" | "session"): number | null;
|
|
819
868
|
getStatus(): SpendingStatus;
|
|
820
869
|
getHistory(limit?: number): SpendRecord[];
|
|
870
|
+
/**
|
|
871
|
+
* Reset the session window. `sessionSpent`/`sessionCalls` are instance state
|
|
872
|
+
* that is never persisted, so this used to happen implicitly: every
|
|
873
|
+
* startProxy() built a fresh SpendControl. The process-wide ledger outlives
|
|
874
|
+
* an in-process proxy restart, which would silently redefine `session` as
|
|
875
|
+
* "since the gateway booted" — docs/configuration.md and the /policy help
|
|
876
|
+
* both promise "session resets on restart". The restart path in index.ts
|
|
877
|
+
* calls this to keep that promise. History and the rolling hourly/daily
|
|
878
|
+
* windows are deliberately untouched.
|
|
879
|
+
*/
|
|
821
880
|
resetSession(): void;
|
|
822
881
|
private cleanup;
|
|
823
882
|
private save;
|
|
@@ -999,8 +1058,8 @@ declare function hashRequestContent(lastUserContent: string, toolCallNames?: str
|
|
|
999
1058
|
* - Usage logging: log every request as JSON line to ~/.openclaw/blockrun/logs/
|
|
1000
1059
|
*/
|
|
1001
1060
|
|
|
1002
|
-
/** Union type for chain-agnostic balance monitoring */
|
|
1003
|
-
type AnyBalanceMonitor = BalanceMonitor | SolanaBalanceMonitor;
|
|
1061
|
+
/** Union type for chain- and auth-agnostic balance monitoring */
|
|
1062
|
+
type AnyBalanceMonitor = BalanceMonitor | SolanaBalanceMonitor | ApiKeyBalanceMonitor;
|
|
1004
1063
|
|
|
1005
1064
|
/**
|
|
1006
1065
|
* Get the proxy port from pre-loaded configuration.
|
|
@@ -1029,8 +1088,26 @@ type WalletConfig = string | {
|
|
|
1029
1088
|
solanaPrivateKeyBytes?: Uint8Array;
|
|
1030
1089
|
};
|
|
1031
1090
|
type PaymentChain = "base" | "solana";
|
|
1091
|
+
/**
|
|
1092
|
+
* How this proxy pays BlockRun.
|
|
1093
|
+
* - "wallet" — x402 micropayments signed per call from a local USDC wallet.
|
|
1094
|
+
* - "api-key" — a `brk_…` bearer token drawing on account credit topped up by
|
|
1095
|
+
* card at https://user.blockrun.ai. No wallet, no chain, no gas.
|
|
1096
|
+
*/
|
|
1097
|
+
type AuthMode = "wallet" | "api-key";
|
|
1032
1098
|
type ProxyOptions = {
|
|
1033
|
-
|
|
1099
|
+
/**
|
|
1100
|
+
* Wallet material for x402 mode. Optional only when `apiKey` is set — one of
|
|
1101
|
+
* the two must be present or the proxy has no way to pay for anything.
|
|
1102
|
+
*/
|
|
1103
|
+
wallet?: WalletConfig;
|
|
1104
|
+
/**
|
|
1105
|
+
* BlockRun API key (`brk_…`). When present it wins over `wallet`: the proxy
|
|
1106
|
+
* talks to api.blockrun.ai with a bearer token and signs no payments at all.
|
|
1107
|
+
* Also readable from BLOCKRUN_API_KEY / ~/.blockrun/.api-key via
|
|
1108
|
+
* resolveApiKey(); callers resolve it and pass it in.
|
|
1109
|
+
*/
|
|
1110
|
+
apiKey?: string;
|
|
1034
1111
|
apiBase?: string;
|
|
1035
1112
|
/**
|
|
1036
1113
|
* Payment chain: "base" or "solana". New installs persist "solana" at wallet
|
|
@@ -1132,19 +1209,16 @@ type ProxyOptions = {
|
|
|
1132
1209
|
type ProxyHandle = {
|
|
1133
1210
|
port: number;
|
|
1134
1211
|
baseUrl: string;
|
|
1212
|
+
/** The x402 signer's address, or "" in API-key mode (there is no wallet). */
|
|
1135
1213
|
walletAddress: string;
|
|
1136
1214
|
solanaAddress?: string;
|
|
1215
|
+
/** Which credential this proxy is paying with. */
|
|
1216
|
+
authMode: AuthMode;
|
|
1217
|
+
/** Masked API key, for status display. Only set in API-key mode. */
|
|
1218
|
+
apiKeyLabel?: string;
|
|
1137
1219
|
balanceMonitor: AnyBalanceMonitor;
|
|
1138
1220
|
close: () => Promise<void>;
|
|
1139
1221
|
};
|
|
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
1222
|
declare function startProxy(options: ProxyOptions): Promise<ProxyHandle>;
|
|
1149
1223
|
|
|
1150
1224
|
/**
|
|
@@ -1767,4 +1841,4 @@ declare function buildImageGenerationProvider(): ImageGenerationProviderPlugin;
|
|
|
1767
1841
|
|
|
1768
1842
|
declare const plugin: OpenClawPluginDefinition;
|
|
1769
1843
|
|
|
1770
|
-
export { type AggregatedStats, BALANCE_THRESHOLDS, BLOCKRUN_MODELS, BLOCKRUN_PLUGIN_ID, type BalanceInfo, BalanceMonitor, CAIP2_BASE, CAIP2_SOLANA_MAINNET, type CachedLLMResponse, type CachedResponse, type CheckResult, type CounterpartyInfo, DEFAULT_RETRY_CONFIG, DEFAULT_SESSION_CONFIG, type DailyStats, type DerivedKeys, EmptyWalletError, FileSpendControlStorage, InMemorySpendControlStorage, InsufficientFundsError, type InsufficientFundsInfo, type LowBalanceInfo, MODEL_ALIASES, MalformedSpendPolicyError, OPENCLAW_MODELS, PARTNER_SERVICES, PAYABLE_NETWORKS, type PartnerServiceDefinition, type PartnerToolDefinition, type PaymentChain, type PolicyList, type ProxyHandle, type ProxyOptions, RequestDeduplicator, ResponseCache, type ResponseCacheConfig, type RetryConfig, RpcError, type SessionConfig, type SessionEntry, SessionStore, type SolanaBalanceInfo, SolanaBalanceMonitor, SpendControl, type SpendControlOptions, type SpendControlStorage, type SpendLimits, SpendPolicyError, type SpendRecord, type SpendWindow, type SpendingStatus, type SufficiencyResult, type UsageEntry, VISIBLE_OPENCLAW_MODELS, type WalletConfig, type WalletResolution, blockrunProvider, buildImageGenerationProvider, buildPartnerTools, buildProviderModels, clearStats, plugin as default, deriveAllKeys, deriveEvmKey, deriveSolanaKeyBytes, fetchWithRetry, formatDuration, formatStatsAscii, generateWalletMnemonic, getAgenticModels, getModelContextWindow, getPartnerService, getProxyPort, getSessionId, getStats, hashRequestContent, injectAuthProfile, injectModelsConfig, isAgenticModel, isBalanceError, isBlockrunWebSearchDisabled, isEmptyWalletError, isInsufficientFundsError, isRetryable, isRpcError, isValidMnemonic, loadPaymentChain, logUsage, parseCallArgs, registerSpendPolicyHook, resolveModelAlias, resolvePaymentChain, savePaymentChain, setupSolana, startProxy, syncAgentModelCache };
|
|
1844
|
+
export { type AggregatedStats, BALANCE_THRESHOLDS, BLOCKRUN_MODELS, BLOCKRUN_PLUGIN_ID, type BalanceInfo, BalanceMonitor, CAIP2_BASE, CAIP2_SOLANA_MAINNET, type CachedLLMResponse, type CachedResponse, type CheckResult, type CounterpartyInfo, DEFAULT_RETRY_CONFIG, DEFAULT_SESSION_CONFIG, type DailyStats, type DerivedKeys, EmptyWalletError, FileSpendControlStorage, InMemorySpendControlStorage, InsufficientFundsError, type InsufficientFundsInfo, type LowBalanceInfo, MODEL_ALIASES, MalformedSpendPolicyError, OPENCLAW_MODELS, PARTNER_SERVICES, PAYABLE_NETWORKS, type PartnerServiceDefinition, type PartnerToolDefinition, type PaymentChain, type PolicyList, type ProxyHandle, type ProxyOptions, RequestDeduplicator, ResponseCache, type ResponseCacheConfig, type RetryConfig, RpcError, type SessionConfig, type SessionEntry, SessionStore, type SolanaBalanceInfo, SolanaBalanceMonitor, SpendControl, type SpendControlOptions, type SpendControlStorage, type SpendLimits, SpendPolicyError, type SpendRecord, type SpendWindow, type SpendingStatus, type SufficiencyResult, UnreadableSpendPolicyError, type UsageEntry, VISIBLE_OPENCLAW_MODELS, type WalletConfig, type WalletResolution, blockrunProvider, buildImageGenerationProvider, buildPartnerTools, buildProviderModels, clearStats, plugin as default, deriveAllKeys, deriveEvmKey, deriveSolanaKeyBytes, fetchWithRetry, formatDuration, formatStatsAscii, generateWalletMnemonic, getAgenticModels, getModelContextWindow, getPartnerService, getProxyPort, getSessionId, getStats, hashRequestContent, injectAuthProfile, injectModelsConfig, isAgenticModel, isBalanceError, isBlockrunWebSearchDisabled, isEmptyWalletError, isInsufficientFundsError, isRetryable, isRpcError, isValidMnemonic, loadPaymentChain, logUsage, parseCallArgs, registerSpendPolicyHook, resolveModelAlias, resolvePaymentChain, savePaymentChain, setupSolana, startProxy, syncAgentModelCache };
|