@blockrun/clawrouter 0.11.13 → 0.11.14

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/dist/index.d.ts CHANGED
@@ -147,6 +147,7 @@ type RoutingDecision = {
147
147
  costEstimate: number;
148
148
  baselineCost: number;
149
149
  savings: number;
150
+ agenticScore?: number;
150
151
  };
151
152
  type TierConfig = {
152
153
  primary: string;
@@ -463,6 +464,48 @@ declare class BalanceMonitor {
463
464
  private buildInfo;
464
465
  }
465
466
 
467
+ /**
468
+ * Solana USDC Balance Monitor
469
+ *
470
+ * Checks USDC balance on Solana mainnet with caching.
471
+ * Absorbed from @blockrun/clawwallet's solana-adapter.ts (balance portion only).
472
+ */
473
+ type SolanaBalanceInfo = {
474
+ balance: bigint;
475
+ balanceUSD: string;
476
+ isLow: boolean;
477
+ isEmpty: boolean;
478
+ walletAddress: string;
479
+ };
480
+ /** Result from checkSufficient() */
481
+ type SolanaSufficiencyResult = {
482
+ sufficient: boolean;
483
+ info: SolanaBalanceInfo;
484
+ shortfall?: string;
485
+ };
486
+ declare class SolanaBalanceMonitor {
487
+ private readonly rpc;
488
+ private readonly walletAddress;
489
+ private cachedBalance;
490
+ private cachedAt;
491
+ constructor(walletAddress: string, rpcUrl?: string);
492
+ checkBalance(): Promise<SolanaBalanceInfo>;
493
+ deductEstimated(amountMicros: bigint): void;
494
+ invalidate(): void;
495
+ refresh(): Promise<SolanaBalanceInfo>;
496
+ /**
497
+ * Check if balance is sufficient for an estimated cost.
498
+ */
499
+ checkSufficient(estimatedCostMicros: bigint): Promise<SolanaSufficiencyResult>;
500
+ /**
501
+ * Format USDC amount (in micros) as "$X.XX".
502
+ */
503
+ formatUSDC(amountMicros: bigint): string;
504
+ getWalletAddress(): string;
505
+ private fetchBalance;
506
+ private buildInfo;
507
+ }
508
+
466
509
  /**
467
510
  * Session Persistence Store
468
511
  *
@@ -476,6 +519,9 @@ type SessionEntry = {
476
519
  createdAt: number;
477
520
  lastUsedAt: number;
478
521
  requestCount: number;
522
+ recentHashes: string[];
523
+ strikes: number;
524
+ escalated: boolean;
479
525
  };
480
526
  type SessionConfig = {
481
527
  /** Enable session persistence (default: false) */
@@ -529,6 +575,21 @@ declare class SessionStore {
529
575
  * Clean up expired sessions.
530
576
  */
531
577
  private cleanup;
578
+ /**
579
+ * Record a request content hash and detect repetitive patterns.
580
+ * Returns true if escalation should be triggered (3+ consecutive similar requests).
581
+ */
582
+ recordRequestHash(sessionId: string, hash: string): boolean;
583
+ /**
584
+ * Escalate session to next tier. Returns the new model/tier or null if already at max.
585
+ */
586
+ escalateSession(sessionId: string, tierConfigs: Record<string, {
587
+ primary: string;
588
+ fallback: string[];
589
+ }>): {
590
+ model: string;
591
+ tier: string;
592
+ } | null;
532
593
  /**
533
594
  * Stop the cleanup interval.
534
595
  */
@@ -538,6 +599,12 @@ declare class SessionStore {
538
599
  * Generate a session ID from request headers or create a default.
539
600
  */
540
601
  declare function getSessionId(headers: Record<string, string | string[] | undefined>, headerName?: string): string | undefined;
602
+ /**
603
+ * Generate a short hash fingerprint from request content.
604
+ * Captures: last user message text + tool call names (if any).
605
+ * Normalizes whitespace to avoid false negatives from minor formatting diffs.
606
+ */
607
+ declare function hashRequestContent(lastUserContent: string, toolCallNames?: string[]): string;
541
608
 
542
609
  /**
543
610
  * Local x402 Proxy Server
@@ -560,6 +627,9 @@ declare function getSessionId(headers: Record<string, string | string[] | undefi
560
627
  * - Usage logging: log every request as JSON line to ~/.openclaw/blockrun/logs/
561
628
  */
562
629
 
630
+ /** Union type for chain-agnostic balance monitoring */
631
+ type AnyBalanceMonitor = BalanceMonitor | SolanaBalanceMonitor;
632
+
563
633
  /**
564
634
  * Get the proxy port from pre-loaded configuration.
565
635
  * Port is validated at module load time, this just returns the cached value.
@@ -641,7 +711,7 @@ type ProxyHandle = {
641
711
  baseUrl: string;
642
712
  walletAddress: string;
643
713
  solanaAddress?: string;
644
- balanceMonitor: BalanceMonitor;
714
+ balanceMonitor: AnyBalanceMonitor;
645
715
  close: () => Promise<void>;
646
716
  };
647
717
  /**
@@ -765,6 +835,13 @@ type BlockRunModel = {
765
835
  vision?: boolean;
766
836
  /** Models optimized for agentic workflows (multi-step autonomous tasks) */
767
837
  agentic?: boolean;
838
+ /**
839
+ * Model supports OpenAI-compatible structured function/tool calling.
840
+ * Models without this flag output tool invocations as plain text JSON,
841
+ * which leaks raw {"command":"..."} into visible chat messages.
842
+ * Default: false (must opt-in to prevent silent regressions on new models).
843
+ */
844
+ toolCalling?: boolean;
768
845
  };
769
846
  declare const BLOCKRUN_MODELS: BlockRunModel[];
770
847
  /**
@@ -810,6 +887,8 @@ type UsageEntry = {
810
887
  baselineCost: number;
811
888
  savings: number;
812
889
  latencyMs: number;
890
+ /** Input (prompt) tokens reported by the provider */
891
+ inputTokens?: number;
813
892
  /** Partner service ID (e.g., "x_users_lookup") — only set for partner API calls */
814
893
  partnerId?: string;
815
894
  /** Partner service name (e.g., "AttentionVC") — only set for partner API calls */
@@ -854,34 +933,6 @@ declare class RequestDeduplicator {
854
933
  private prune;
855
934
  }
856
935
 
857
- /**
858
- * Solana USDC Balance Monitor
859
- *
860
- * Checks USDC balance on Solana mainnet with caching.
861
- * Absorbed from @blockrun/clawwallet's solana-adapter.ts (balance portion only).
862
- */
863
- type SolanaBalanceInfo = {
864
- balance: bigint;
865
- balanceUSD: string;
866
- isLow: boolean;
867
- isEmpty: boolean;
868
- walletAddress: string;
869
- };
870
- declare class SolanaBalanceMonitor {
871
- private readonly rpc;
872
- private readonly walletAddress;
873
- private cachedBalance;
874
- private cachedAt;
875
- constructor(walletAddress: string, rpcUrl?: string);
876
- checkBalance(): Promise<SolanaBalanceInfo>;
877
- deductEstimated(amountMicros: bigint): void;
878
- invalidate(): void;
879
- refresh(): Promise<SolanaBalanceInfo>;
880
- getWalletAddress(): string;
881
- private fetchBalance;
882
- private buildInfo;
883
- }
884
-
885
936
  /**
886
937
  * Spend Control - Time-windowed spending limits
887
938
  *
@@ -1277,4 +1328,4 @@ declare function buildPartnerTools(proxyBaseUrl: string): PartnerToolDefinition[
1277
1328
 
1278
1329
  declare const plugin: OpenClawPluginDefinition;
1279
1330
 
1280
- export { type AggregatedStats, BALANCE_THRESHOLDS, BLOCKRUN_MODELS, type BalanceInfo, BalanceMonitor, type CachedLLMResponse, type CachedResponse, type CheckResult, DEFAULT_RETRY_CONFIG, DEFAULT_ROUTING_CONFIG, DEFAULT_SESSION_CONFIG, type DailyStats, type DerivedKeys, EmptyWalletError, FileSpendControlStorage, InMemorySpendControlStorage, InsufficientFundsError, type InsufficientFundsInfo, type LowBalanceInfo, MODEL_ALIASES, OPENCLAW_MODELS, PARTNER_SERVICES, type PartnerServiceDefinition, type PartnerToolDefinition, type PaymentChain, type ProxyHandle, type ProxyOptions, RequestDeduplicator, ResponseCache, type ResponseCacheConfig, type RetryConfig, type RoutingConfig, type RoutingDecision, RpcError, type SessionConfig, type SessionEntry, SessionStore, type SolanaBalanceInfo, SolanaBalanceMonitor, SpendControl, type SpendControlOptions, type SpendControlStorage, type SpendLimits, type SpendRecord, type SpendWindow, type SpendingStatus, type SufficiencyResult, type Tier, type UsageEntry, type WalletConfig, type WalletResolution, blockrunProvider, buildPartnerTools, buildProviderModels, calculateModelCost, plugin as default, deriveAllKeys, deriveEvmKey, deriveSolanaKeyBytes, fetchWithRetry, formatDuration, formatStatsAscii, generateWalletMnemonic, getAgenticModels, getFallbackChain, getFallbackChainFiltered, getModelContextWindow, getPartnerService, getProxyPort, getSessionId, getStats, isAgenticModel, isBalanceError, isEmptyWalletError, isInsufficientFundsError, isRetryable, isRpcError, isValidMnemonic, loadPaymentChain, logUsage, resolveModelAlias, resolvePaymentChain, route, savePaymentChain, setupSolana, startProxy };
1331
+ export { type AggregatedStats, BALANCE_THRESHOLDS, BLOCKRUN_MODELS, type BalanceInfo, BalanceMonitor, type CachedLLMResponse, type CachedResponse, type CheckResult, DEFAULT_RETRY_CONFIG, DEFAULT_ROUTING_CONFIG, DEFAULT_SESSION_CONFIG, type DailyStats, type DerivedKeys, EmptyWalletError, FileSpendControlStorage, InMemorySpendControlStorage, InsufficientFundsError, type InsufficientFundsInfo, type LowBalanceInfo, MODEL_ALIASES, OPENCLAW_MODELS, PARTNER_SERVICES, type PartnerServiceDefinition, type PartnerToolDefinition, type PaymentChain, type ProxyHandle, type ProxyOptions, RequestDeduplicator, ResponseCache, type ResponseCacheConfig, type RetryConfig, type RoutingConfig, type RoutingDecision, RpcError, type SessionConfig, type SessionEntry, SessionStore, type SolanaBalanceInfo, SolanaBalanceMonitor, SpendControl, type SpendControlOptions, type SpendControlStorage, type SpendLimits, type SpendRecord, type SpendWindow, type SpendingStatus, type SufficiencyResult, type Tier, type UsageEntry, type WalletConfig, type WalletResolution, blockrunProvider, buildPartnerTools, buildProviderModels, calculateModelCost, plugin as default, deriveAllKeys, deriveEvmKey, deriveSolanaKeyBytes, fetchWithRetry, formatDuration, formatStatsAscii, generateWalletMnemonic, getAgenticModels, getFallbackChain, getFallbackChainFiltered, getModelContextWindow, getPartnerService, getProxyPort, getSessionId, getStats, hashRequestContent, isAgenticModel, isBalanceError, isEmptyWalletError, isInsufficientFundsError, isRetryable, isRpcError, isValidMnemonic, loadPaymentChain, logUsage, resolveModelAlias, resolvePaymentChain, route, savePaymentChain, setupSolana, startProxy };