@blockrun/clawrouter 0.9.19 → 0.9.20
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 +2 -2
- package/dist/cli.js +115 -43
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +6 -4
- package/dist/index.js +122 -44
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/scripts/reinstall.sh +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -667,16 +667,16 @@ declare const blockrunProvider: ProviderPlugin;
|
|
|
667
667
|
|
|
668
668
|
/**
|
|
669
669
|
* Model aliases for convenient shorthand access.
|
|
670
|
-
* Users can type `/model claude` instead of `/model blockrun/anthropic/claude-sonnet-4`.
|
|
670
|
+
* Users can type `/model claude` instead of `/model blockrun/anthropic/claude-sonnet-4.6`.
|
|
671
671
|
*/
|
|
672
672
|
declare const MODEL_ALIASES: Record<string, string>;
|
|
673
673
|
/**
|
|
674
674
|
* Resolve a model alias to its full model ID.
|
|
675
675
|
* Also strips "blockrun/" prefix for direct model paths.
|
|
676
676
|
* Examples:
|
|
677
|
-
* - "claude" -> "anthropic/claude-sonnet-4" (alias)
|
|
678
|
-
* - "blockrun/claude" -> "anthropic/claude-sonnet-4" (alias with prefix)
|
|
679
|
-
* - "blockrun/anthropic/claude-sonnet-4" -> "anthropic/claude-sonnet-4" (prefix stripped)
|
|
677
|
+
* - "claude" -> "anthropic/claude-sonnet-4.6" (alias)
|
|
678
|
+
* - "blockrun/claude" -> "anthropic/claude-sonnet-4.6" (alias with prefix)
|
|
679
|
+
* - "blockrun/anthropic/claude-sonnet-4.6" -> "anthropic/claude-sonnet-4.6" (prefix stripped)
|
|
680
680
|
* - "openai/gpt-4o" -> "openai/gpt-4o" (unchanged)
|
|
681
681
|
*/
|
|
682
682
|
declare function resolveModelAlias(model: string): string;
|
|
@@ -793,6 +793,8 @@ type CachedPaymentParams = {
|
|
|
793
793
|
version?: string;
|
|
794
794
|
};
|
|
795
795
|
maxTimeoutSeconds?: number;
|
|
796
|
+
resourceUrl?: string;
|
|
797
|
+
resourceDescription?: string;
|
|
796
798
|
cachedAt: number;
|
|
797
799
|
};
|
|
798
800
|
declare class PaymentCache {
|
package/dist/index.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
// src/models.ts
|
|
2
2
|
var MODEL_ALIASES = {
|
|
3
3
|
// Claude - short names
|
|
4
|
-
claude: "anthropic/claude-sonnet-4",
|
|
5
|
-
sonnet: "anthropic/claude-sonnet-4",
|
|
4
|
+
claude: "anthropic/claude-sonnet-4.6",
|
|
5
|
+
sonnet: "anthropic/claude-sonnet-4.6",
|
|
6
6
|
opus: "anthropic/claude-opus-4.6",
|
|
7
7
|
// Updated to latest Opus 4.6
|
|
8
8
|
"opus-46": "anthropic/claude-opus-4.6",
|
|
9
9
|
"opus-45": "anthropic/claude-opus-4.5",
|
|
10
10
|
haiku: "anthropic/claude-haiku-4.5",
|
|
11
11
|
// Claude - provider/shortname patterns (common in agent frameworks)
|
|
12
|
-
"anthropic/sonnet": "anthropic/claude-sonnet-4",
|
|
12
|
+
"anthropic/sonnet": "anthropic/claude-sonnet-4.6",
|
|
13
13
|
"anthropic/opus": "anthropic/claude-opus-4.6",
|
|
14
14
|
"anthropic/haiku": "anthropic/claude-haiku-4.5",
|
|
15
|
-
"anthropic/claude": "anthropic/claude-sonnet-4",
|
|
15
|
+
"anthropic/claude": "anthropic/claude-sonnet-4.6",
|
|
16
16
|
// OpenAI
|
|
17
17
|
gpt: "openai/gpt-4o",
|
|
18
18
|
gpt4: "openai/gpt-4o",
|
|
@@ -208,8 +208,8 @@ var BLOCKRUN_MODELS = [
|
|
|
208
208
|
agentic: true
|
|
209
209
|
},
|
|
210
210
|
{
|
|
211
|
-
id: "anthropic/claude-sonnet-4",
|
|
212
|
-
name: "Claude Sonnet 4",
|
|
211
|
+
id: "anthropic/claude-sonnet-4.6",
|
|
212
|
+
name: "Claude Sonnet 4.6",
|
|
213
213
|
inputPrice: 3,
|
|
214
214
|
outputPrice: 15,
|
|
215
215
|
contextWindow: 2e5,
|
|
@@ -514,13 +514,11 @@ var PaymentCache = class {
|
|
|
514
514
|
|
|
515
515
|
// src/x402.ts
|
|
516
516
|
var BASE_CHAIN_ID = 8453;
|
|
517
|
-
var
|
|
518
|
-
var
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
verifyingContract: USDC_BASE
|
|
523
|
-
};
|
|
517
|
+
var BASE_SEPOLIA_CHAIN_ID = 84532;
|
|
518
|
+
var DEFAULT_TOKEN_NAME = "USD Coin";
|
|
519
|
+
var DEFAULT_TOKEN_VERSION = "2";
|
|
520
|
+
var DEFAULT_NETWORK = "eip155:8453";
|
|
521
|
+
var DEFAULT_MAX_TIMEOUT_SECONDS = 300;
|
|
524
522
|
var TRANSFER_TYPES = {
|
|
525
523
|
TransferWithAuthorization: [
|
|
526
524
|
{ name: "from", type: "address" },
|
|
@@ -536,18 +534,78 @@ function createNonce() {
|
|
|
536
534
|
crypto.getRandomValues(bytes);
|
|
537
535
|
return `0x${Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("")}`;
|
|
538
536
|
}
|
|
539
|
-
function
|
|
540
|
-
const
|
|
537
|
+
function decodeBase64Json(value) {
|
|
538
|
+
const normalized = value.replace(/-/g, "+").replace(/_/g, "/");
|
|
539
|
+
const padding = (4 - normalized.length % 4) % 4;
|
|
540
|
+
const padded = normalized + "=".repeat(padding);
|
|
541
|
+
const decoded = Buffer.from(padded, "base64").toString("utf8");
|
|
541
542
|
return JSON.parse(decoded);
|
|
542
543
|
}
|
|
543
|
-
|
|
544
|
+
function encodeBase64Json(value) {
|
|
545
|
+
return Buffer.from(JSON.stringify(value), "utf8").toString("base64");
|
|
546
|
+
}
|
|
547
|
+
function parsePaymentRequired(headerValue) {
|
|
548
|
+
return decodeBase64Json(headerValue);
|
|
549
|
+
}
|
|
550
|
+
function normalizeNetwork(network) {
|
|
551
|
+
if (!network || network.trim().length === 0) {
|
|
552
|
+
return DEFAULT_NETWORK;
|
|
553
|
+
}
|
|
554
|
+
return network.trim().toLowerCase();
|
|
555
|
+
}
|
|
556
|
+
function resolveChainId(network) {
|
|
557
|
+
const eip155Match = network.match(/^eip155:(\d+)$/i);
|
|
558
|
+
if (eip155Match) {
|
|
559
|
+
const parsed = Number.parseInt(eip155Match[1], 10);
|
|
560
|
+
if (Number.isFinite(parsed) && parsed > 0) {
|
|
561
|
+
return parsed;
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
if (network === "base") return BASE_CHAIN_ID;
|
|
565
|
+
if (network === "base-sepolia") return BASE_SEPOLIA_CHAIN_ID;
|
|
566
|
+
return BASE_CHAIN_ID;
|
|
567
|
+
}
|
|
568
|
+
function parseHexAddress(value) {
|
|
569
|
+
if (!value) return void 0;
|
|
570
|
+
const direct = value.match(/^0x[a-fA-F0-9]{40}$/);
|
|
571
|
+
if (direct) {
|
|
572
|
+
return direct[0];
|
|
573
|
+
}
|
|
574
|
+
const caipSuffix = value.match(/0x[a-fA-F0-9]{40}$/);
|
|
575
|
+
if (caipSuffix) {
|
|
576
|
+
return caipSuffix[0];
|
|
577
|
+
}
|
|
578
|
+
return void 0;
|
|
579
|
+
}
|
|
580
|
+
function requireHexAddress(value, field) {
|
|
581
|
+
const parsed = parseHexAddress(value);
|
|
582
|
+
if (!parsed) {
|
|
583
|
+
throw new Error(`Invalid ${field} in payment requirements: ${String(value)}`);
|
|
584
|
+
}
|
|
585
|
+
return parsed;
|
|
586
|
+
}
|
|
587
|
+
function setPaymentHeaders(headers, payload) {
|
|
588
|
+
headers.set("payment-signature", payload);
|
|
589
|
+
headers.set("x-payment", payload);
|
|
590
|
+
}
|
|
591
|
+
async function createPaymentPayload(privateKey, fromAddress, option, amount, requestUrl, resource) {
|
|
592
|
+
const network = normalizeNetwork(option.network);
|
|
593
|
+
const chainId = resolveChainId(network);
|
|
594
|
+
const recipient = requireHexAddress(option.payTo, "payTo");
|
|
595
|
+
const verifyingContract = requireHexAddress(option.asset, "asset");
|
|
596
|
+
const maxTimeoutSeconds = typeof option.maxTimeoutSeconds === "number" && option.maxTimeoutSeconds > 0 ? Math.floor(option.maxTimeoutSeconds) : DEFAULT_MAX_TIMEOUT_SECONDS;
|
|
544
597
|
const now = Math.floor(Date.now() / 1e3);
|
|
545
598
|
const validAfter = now - 600;
|
|
546
|
-
const validBefore = now +
|
|
599
|
+
const validBefore = now + maxTimeoutSeconds;
|
|
547
600
|
const nonce = createNonce();
|
|
548
601
|
const signature = await signTypedData({
|
|
549
602
|
privateKey,
|
|
550
|
-
domain:
|
|
603
|
+
domain: {
|
|
604
|
+
name: option.extra?.name || DEFAULT_TOKEN_NAME,
|
|
605
|
+
version: option.extra?.version || DEFAULT_TOKEN_VERSION,
|
|
606
|
+
chainId,
|
|
607
|
+
verifyingContract
|
|
608
|
+
},
|
|
551
609
|
types: TRANSFER_TYPES,
|
|
552
610
|
primaryType: "TransferWithAuthorization",
|
|
553
611
|
message: {
|
|
@@ -562,18 +620,18 @@ async function createPaymentPayload(privateKey, fromAddress, recipient, amount,
|
|
|
562
620
|
const paymentData = {
|
|
563
621
|
x402Version: 2,
|
|
564
622
|
resource: {
|
|
565
|
-
url:
|
|
566
|
-
description: "BlockRun AI API call",
|
|
623
|
+
url: resource?.url || requestUrl,
|
|
624
|
+
description: resource?.description || "BlockRun AI API call",
|
|
567
625
|
mimeType: "application/json"
|
|
568
626
|
},
|
|
569
627
|
accepted: {
|
|
570
|
-
scheme:
|
|
571
|
-
network
|
|
628
|
+
scheme: option.scheme,
|
|
629
|
+
network,
|
|
572
630
|
amount,
|
|
573
|
-
asset:
|
|
574
|
-
payTo:
|
|
575
|
-
maxTimeoutSeconds:
|
|
576
|
-
extra:
|
|
631
|
+
asset: option.asset,
|
|
632
|
+
payTo: option.payTo,
|
|
633
|
+
maxTimeoutSeconds: option.maxTimeoutSeconds,
|
|
634
|
+
extra: option.extra
|
|
577
635
|
},
|
|
578
636
|
payload: {
|
|
579
637
|
signature,
|
|
@@ -588,7 +646,7 @@ async function createPaymentPayload(privateKey, fromAddress, recipient, amount,
|
|
|
588
646
|
},
|
|
589
647
|
extensions: {}
|
|
590
648
|
};
|
|
591
|
-
return
|
|
649
|
+
return encodeBase64Json(paymentData);
|
|
592
650
|
}
|
|
593
651
|
function createPaymentFetch(privateKey) {
|
|
594
652
|
const account = privateKeyToAccount(privateKey);
|
|
@@ -602,12 +660,23 @@ function createPaymentFetch(privateKey) {
|
|
|
602
660
|
const paymentPayload = await createPaymentPayload(
|
|
603
661
|
privateKey,
|
|
604
662
|
walletAddress,
|
|
605
|
-
|
|
663
|
+
{
|
|
664
|
+
scheme: cached.scheme,
|
|
665
|
+
network: cached.network,
|
|
666
|
+
asset: cached.asset,
|
|
667
|
+
payTo: cached.payTo,
|
|
668
|
+
maxTimeoutSeconds: cached.maxTimeoutSeconds,
|
|
669
|
+
extra: cached.extra
|
|
670
|
+
},
|
|
606
671
|
preAuth.estimatedAmount,
|
|
607
|
-
url
|
|
672
|
+
url,
|
|
673
|
+
{
|
|
674
|
+
url: cached.resourceUrl,
|
|
675
|
+
description: cached.resourceDescription
|
|
676
|
+
}
|
|
608
677
|
);
|
|
609
678
|
const preAuthHeaders = new Headers(init?.headers);
|
|
610
|
-
preAuthHeaders
|
|
679
|
+
setPaymentHeaders(preAuthHeaders, paymentPayload);
|
|
611
680
|
const response2 = await fetch(input, { ...init, headers: preAuthHeaders });
|
|
612
681
|
if (response2.status !== 402) {
|
|
613
682
|
return response2;
|
|
@@ -653,17 +722,20 @@ function createPaymentFetch(privateKey) {
|
|
|
653
722
|
scheme: option.scheme,
|
|
654
723
|
network: option.network,
|
|
655
724
|
extra: option.extra,
|
|
656
|
-
maxTimeoutSeconds: option.maxTimeoutSeconds
|
|
725
|
+
maxTimeoutSeconds: option.maxTimeoutSeconds,
|
|
726
|
+
resourceUrl: paymentRequired.resource?.url,
|
|
727
|
+
resourceDescription: paymentRequired.resource?.description
|
|
657
728
|
});
|
|
658
729
|
const paymentPayload = await createPaymentPayload(
|
|
659
730
|
privateKey,
|
|
660
731
|
walletAddress,
|
|
661
|
-
option
|
|
732
|
+
option,
|
|
662
733
|
amount,
|
|
663
|
-
url
|
|
734
|
+
url,
|
|
735
|
+
paymentRequired.resource
|
|
664
736
|
);
|
|
665
737
|
const retryHeaders = new Headers(init?.headers);
|
|
666
|
-
retryHeaders
|
|
738
|
+
setPaymentHeaders(retryHeaders, paymentPayload);
|
|
667
739
|
return fetch(input, {
|
|
668
740
|
...init,
|
|
669
741
|
headers: retryHeaders
|
|
@@ -1635,7 +1707,7 @@ var DEFAULT_ROUTING_CONFIG = {
|
|
|
1635
1707
|
"openai/gpt-5.2",
|
|
1636
1708
|
// Newer and cheaper input than gpt-4o
|
|
1637
1709
|
"openai/gpt-4o",
|
|
1638
|
-
"anthropic/claude-sonnet-4"
|
|
1710
|
+
"anthropic/claude-sonnet-4.6"
|
|
1639
1711
|
]
|
|
1640
1712
|
},
|
|
1641
1713
|
REASONING: {
|
|
@@ -1688,7 +1760,7 @@ var DEFAULT_ROUTING_CONFIG = {
|
|
|
1688
1760
|
"moonshot/kimi-k2.5",
|
|
1689
1761
|
"google/gemini-2.5-pro",
|
|
1690
1762
|
"xai/grok-4-0709",
|
|
1691
|
-
"anthropic/claude-sonnet-4"
|
|
1763
|
+
"anthropic/claude-sonnet-4.6"
|
|
1692
1764
|
]
|
|
1693
1765
|
},
|
|
1694
1766
|
COMPLEX: {
|
|
@@ -1697,13 +1769,13 @@ var DEFAULT_ROUTING_CONFIG = {
|
|
|
1697
1769
|
fallback: [
|
|
1698
1770
|
"openai/gpt-5.2-codex",
|
|
1699
1771
|
"anthropic/claude-opus-4.5",
|
|
1700
|
-
"anthropic/claude-sonnet-4",
|
|
1772
|
+
"anthropic/claude-sonnet-4.6",
|
|
1701
1773
|
"google/gemini-3-pro-preview",
|
|
1702
1774
|
"moonshot/kimi-k2.5"
|
|
1703
1775
|
]
|
|
1704
1776
|
},
|
|
1705
1777
|
REASONING: {
|
|
1706
|
-
primary: "anthropic/claude-sonnet-4",
|
|
1778
|
+
primary: "anthropic/claude-sonnet-4.6",
|
|
1707
1779
|
// $3/$15 - best for reasoning/instructions
|
|
1708
1780
|
fallback: [
|
|
1709
1781
|
"anthropic/claude-opus-4.6",
|
|
@@ -1729,10 +1801,10 @@ var DEFAULT_ROUTING_CONFIG = {
|
|
|
1729
1801
|
MEDIUM: {
|
|
1730
1802
|
primary: "xai/grok-code-fast-1",
|
|
1731
1803
|
// Code specialist for agentic coding
|
|
1732
|
-
fallback: ["moonshot/kimi-k2.5", "anthropic/claude-haiku-4.5", "anthropic/claude-sonnet-4"]
|
|
1804
|
+
fallback: ["moonshot/kimi-k2.5", "anthropic/claude-haiku-4.5", "anthropic/claude-sonnet-4.6"]
|
|
1733
1805
|
},
|
|
1734
1806
|
COMPLEX: {
|
|
1735
|
-
primary: "anthropic/claude-sonnet-4",
|
|
1807
|
+
primary: "anthropic/claude-sonnet-4.6",
|
|
1736
1808
|
fallback: [
|
|
1737
1809
|
"anthropic/claude-opus-4.6",
|
|
1738
1810
|
// Latest Opus - best agentic
|
|
@@ -1742,7 +1814,7 @@ var DEFAULT_ROUTING_CONFIG = {
|
|
|
1742
1814
|
]
|
|
1743
1815
|
},
|
|
1744
1816
|
REASONING: {
|
|
1745
|
-
primary: "anthropic/claude-sonnet-4",
|
|
1817
|
+
primary: "anthropic/claude-sonnet-4.6",
|
|
1746
1818
|
// Strong tool use + reasoning for agentic tasks
|
|
1747
1819
|
fallback: [
|
|
1748
1820
|
"anthropic/claude-opus-4.6",
|
|
@@ -2434,7 +2506,7 @@ function isRpcError(error) {
|
|
|
2434
2506
|
}
|
|
2435
2507
|
|
|
2436
2508
|
// src/balance.ts
|
|
2437
|
-
var
|
|
2509
|
+
var USDC_BASE = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
|
|
2438
2510
|
var CACHE_TTL_MS = 3e4;
|
|
2439
2511
|
var BALANCE_THRESHOLDS = {
|
|
2440
2512
|
/** Low balance warning threshold: $1.00 */
|
|
@@ -2533,7 +2605,7 @@ var BalanceMonitor = class {
|
|
|
2533
2605
|
async fetchBalance() {
|
|
2534
2606
|
try {
|
|
2535
2607
|
const balance = await this.client.readContract({
|
|
2536
|
-
address:
|
|
2608
|
+
address: USDC_BASE,
|
|
2537
2609
|
abi: erc20Abi,
|
|
2538
2610
|
functionName: "balanceOf",
|
|
2539
2611
|
args: [this.walletAddress]
|
|
@@ -5268,7 +5340,13 @@ function injectModelsConfig(logger) {
|
|
|
5268
5340
|
{ id: "gemini", alias: "gemini" },
|
|
5269
5341
|
{ id: "flash", alias: "flash" }
|
|
5270
5342
|
];
|
|
5271
|
-
const DEPRECATED_ALIASES = [
|
|
5343
|
+
const DEPRECATED_ALIASES = [
|
|
5344
|
+
"blockrun/nvidia",
|
|
5345
|
+
"blockrun/gpt",
|
|
5346
|
+
"blockrun/o3",
|
|
5347
|
+
"blockrun/grok",
|
|
5348
|
+
"blockrun/mini"
|
|
5349
|
+
];
|
|
5272
5350
|
if (!defaults.models) {
|
|
5273
5351
|
defaults.models = {};
|
|
5274
5352
|
needsWrite = true;
|