@blockrun/clawrouter 0.12.286 → 0.12.287
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 +35 -0
- package/dist/cli.js +47567 -41123
- package/dist/index.d.ts +124 -123
- package/dist/index.js +6783 -365
- package/package.json +2 -1
package/dist/index.d.ts
CHANGED
|
@@ -359,9 +359,128 @@ type OpenClawPluginDefinition = {
|
|
|
359
359
|
};
|
|
360
360
|
};
|
|
361
361
|
|
|
362
|
+
/**
|
|
363
|
+
* BlockRun Model Definitions for OpenClaw
|
|
364
|
+
*
|
|
365
|
+
* Maps BlockRun's model catalog to OpenClaw's ModelDefinitionConfig format.
|
|
366
|
+
* All models use the "openai-completions" API since BlockRun is OpenAI-compatible.
|
|
367
|
+
*
|
|
368
|
+
* Pricing is in USD per 1M tokens. Operators pay these rates via x402;
|
|
369
|
+
* they set their own markup when reselling to end users (Phase 2).
|
|
370
|
+
*/
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* Model aliases for convenient shorthand access.
|
|
374
|
+
* Users can type `/model claude` instead of `/model blockrun/anthropic/claude-sonnet-4-6`.
|
|
375
|
+
*/
|
|
376
|
+
declare const MODEL_ALIASES: Record<string, string>;
|
|
377
|
+
/**
|
|
378
|
+
* Resolve a model alias to its full model ID.
|
|
379
|
+
* Also strips "blockrun/" prefix for direct model paths.
|
|
380
|
+
* Examples:
|
|
381
|
+
* - "claude" -> "anthropic/claude-sonnet-4-6" (alias)
|
|
382
|
+
* - "blockrun/claude" -> "anthropic/claude-sonnet-4-6" (alias with prefix)
|
|
383
|
+
* - "blockrun/anthropic/claude-sonnet-4-6" -> "anthropic/claude-sonnet-4-6" (prefix stripped)
|
|
384
|
+
* - "openai/gpt-4o" -> "openai/gpt-4o" (unchanged)
|
|
385
|
+
*/
|
|
386
|
+
declare function resolveModelAlias(model: string): string;
|
|
387
|
+
type BlockRunModel = {
|
|
388
|
+
id: string;
|
|
389
|
+
name: string;
|
|
390
|
+
/** Model version (e.g., "4.6", "3.1", "5.2") for tracking updates */
|
|
391
|
+
version?: string;
|
|
392
|
+
inputPrice: number;
|
|
393
|
+
outputPrice: number;
|
|
394
|
+
contextWindow: number;
|
|
395
|
+
maxOutput: number;
|
|
396
|
+
reasoning?: boolean;
|
|
397
|
+
vision?: boolean;
|
|
398
|
+
/** Models optimized for agentic workflows (multi-step autonomous tasks) */
|
|
399
|
+
agentic?: boolean;
|
|
400
|
+
/**
|
|
401
|
+
* Model supports OpenAI-compatible structured function/tool calling.
|
|
402
|
+
* Models without this flag output tool invocations as plain text JSON,
|
|
403
|
+
* which leaks raw {"command":"..."} into visible chat messages.
|
|
404
|
+
* Default: false (must opt-in to prevent silent regressions on new models).
|
|
405
|
+
*/
|
|
406
|
+
toolCalling?: boolean;
|
|
407
|
+
/** Model is deprecated — will be routed to fallbackModel if set */
|
|
408
|
+
deprecated?: boolean;
|
|
409
|
+
/** Model ID to route to when this model is deprecated */
|
|
410
|
+
fallbackModel?: string;
|
|
411
|
+
/** Time-limited promotional pricing — auto-expires after endDate */
|
|
412
|
+
promo?: {
|
|
413
|
+
/** Flat price per request in USD (replaces token-based pricing) */
|
|
414
|
+
flatPrice: number;
|
|
415
|
+
/** ISO date, promo starts (inclusive). e.g. "2026-04-01" */
|
|
416
|
+
startDate: string;
|
|
417
|
+
/** ISO date, promo ends (exclusive). e.g. "2026-04-15" */
|
|
418
|
+
endDate: string;
|
|
419
|
+
};
|
|
420
|
+
/**
|
|
421
|
+
* Permanent flat per-request price in USD (backend billingMode: "flat").
|
|
422
|
+
* Unlike promo, this never expires. Takes precedence over promo.
|
|
423
|
+
*/
|
|
424
|
+
flatPrice?: number;
|
|
425
|
+
};
|
|
426
|
+
declare const BLOCKRUN_MODELS: BlockRunModel[];
|
|
427
|
+
/**
|
|
428
|
+
* All BlockRun models in OpenClaw format (including aliases).
|
|
429
|
+
* Used for proxy-side resolution (alias → target ID), tool routing, etc.
|
|
430
|
+
*
|
|
431
|
+
* Catalog entries shadowed by an identically-keyed alias are excluded:
|
|
432
|
+
* resolveModelAlias checks MODEL_ALIASES first, so those catalog entries are
|
|
433
|
+
* unreachable and their metadata (name/pricing) would misadvertise what
|
|
434
|
+
* callers actually get. The alias-derived entry carries the redirect
|
|
435
|
+
* target's real metadata instead.
|
|
436
|
+
*/
|
|
437
|
+
declare const OPENCLAW_MODELS: ModelDefinitionConfig[];
|
|
438
|
+
declare const VISIBLE_OPENCLAW_MODELS: ModelDefinitionConfig[];
|
|
439
|
+
/**
|
|
440
|
+
* Build a ModelProviderConfig for BlockRun.
|
|
441
|
+
*
|
|
442
|
+
* Returns only the TOP_MODELS-listed subset so the OpenClaw picker stays
|
|
443
|
+
* focused. Hidden models are still resolvable through the proxy.
|
|
444
|
+
*
|
|
445
|
+
* @param baseUrl - The proxy's local base URL (e.g., "http://127.0.0.1:12345")
|
|
446
|
+
*/
|
|
447
|
+
declare function buildProviderModels(baseUrl: string): ModelProviderConfig;
|
|
448
|
+
/**
|
|
449
|
+
* Check if a model is optimized for agentic workflows.
|
|
450
|
+
* Agentic models continue autonomously with multi-step tasks
|
|
451
|
+
* instead of stopping and waiting for user input.
|
|
452
|
+
*/
|
|
453
|
+
declare function isAgenticModel(modelId: string): boolean;
|
|
454
|
+
/**
|
|
455
|
+
* Get all agentic-capable models.
|
|
456
|
+
*/
|
|
457
|
+
declare function getAgenticModels(): string[];
|
|
458
|
+
/**
|
|
459
|
+
* Get context window size for a model.
|
|
460
|
+
* Returns undefined if model not found.
|
|
461
|
+
*/
|
|
462
|
+
declare function getModelContextWindow(modelId: string): number | undefined;
|
|
463
|
+
|
|
362
464
|
/** OpenClaw's bundled router owns `clawrouter`; BlockRun must never claim it. */
|
|
363
465
|
declare const BLOCKRUN_PLUGIN_ID = "blockrun-clawrouter";
|
|
364
466
|
|
|
467
|
+
/** Model metadata only. This client has no wallet or payment-signing capability. */
|
|
468
|
+
|
|
469
|
+
type ModelCatalogView = {
|
|
470
|
+
models: BlockRunModel[];
|
|
471
|
+
openclaw: ModelDefinitionConfig[];
|
|
472
|
+
visible: ModelDefinitionConfig[];
|
|
473
|
+
/**
|
|
474
|
+
* Models ClawRouter treats as free: its own `free/*` products, and only
|
|
475
|
+
* those. This set gates the strict cost cap, the balance preflight and the
|
|
476
|
+
* budget filters, so it never takes a gateway listing's word for it: a
|
|
477
|
+
* model the listing calls free but whose 402 quotes a price would otherwise
|
|
478
|
+
* be signed with no cap check. A gateway-free model is still priced at 0
|
|
479
|
+
* here, so its estimates are 0 and the signing hooks check its real quote.
|
|
480
|
+
*/
|
|
481
|
+
freeIds: ReadonlySet<string>;
|
|
482
|
+
};
|
|
483
|
+
|
|
365
484
|
/**
|
|
366
485
|
* Response Cache for LLM Completions
|
|
367
486
|
*
|
|
@@ -1105,27 +1224,6 @@ interface SolanaBatchSettings {
|
|
|
1105
1224
|
inDoubtMaxWaitMs?: number;
|
|
1106
1225
|
}
|
|
1107
1226
|
|
|
1108
|
-
/**
|
|
1109
|
-
* Local x402 Proxy Server
|
|
1110
|
-
*
|
|
1111
|
-
* Sits between OpenClaw's pi-ai (which makes standard OpenAI-format requests)
|
|
1112
|
-
* and BlockRun's API (which requires x402 micropayments).
|
|
1113
|
-
*
|
|
1114
|
-
* Flow:
|
|
1115
|
-
* pi-ai → http://localhost:{port}/v1/chat/completions
|
|
1116
|
-
* → proxy forwards to https://blockrun.ai/api/v1/chat/completions
|
|
1117
|
-
* → gets 402 → @x402/fetch signs payment → retries
|
|
1118
|
-
* → streams response back to pi-ai
|
|
1119
|
-
*
|
|
1120
|
-
* Optimizations (v0.3.0):
|
|
1121
|
-
* - SSE heartbeat: for streaming requests, sends headers + heartbeat immediately
|
|
1122
|
-
* before the x402 flow, preventing OpenClaw's 10-15s timeout from firing.
|
|
1123
|
-
* - Response dedup: hashes request bodies and caches responses for 30s,
|
|
1124
|
-
* preventing double-charging when OpenClaw retries after timeout.
|
|
1125
|
-
* - Smart routing: when model is "blockrun/auto", classify query and pick cheapest model.
|
|
1126
|
-
* - Usage logging: log every request as JSON line to ~/.openclaw/blockrun/logs/
|
|
1127
|
-
*/
|
|
1128
|
-
|
|
1129
1227
|
/** Union type for chain- and auth-agnostic balance monitoring */
|
|
1130
1228
|
type AnyBalanceMonitor = BalanceMonitor | SolanaBalanceMonitor | ApiKeyBalanceMonitor;
|
|
1131
1229
|
|
|
@@ -1240,6 +1338,7 @@ type ProxyOptions = {
|
|
|
1240
1338
|
* Loaded from ~/.openclaw/blockrun/exclude-models.json
|
|
1241
1339
|
*/
|
|
1242
1340
|
excludeModels?: Set<string>;
|
|
1341
|
+
onCatalogUpdated?: (models: ModelCatalogView["visible"]) => void;
|
|
1243
1342
|
onReady?: (port: number) => void;
|
|
1244
1343
|
onError?: (error: Error) => void;
|
|
1245
1344
|
onPayment?: (info: {
|
|
@@ -1285,6 +1384,8 @@ type ProxyOptions = {
|
|
|
1285
1384
|
upstreamProxy?: string;
|
|
1286
1385
|
};
|
|
1287
1386
|
type ProxyHandle = {
|
|
1387
|
+
/** Current proxy-owned picker view; credentials are never exposed here. */
|
|
1388
|
+
getCatalogModels?: () => ModelCatalogView["visible"];
|
|
1288
1389
|
port: number;
|
|
1289
1390
|
baseUrl: string;
|
|
1290
1391
|
/** The x402 signer's address, or "" in API-key mode (there is no wallet). */
|
|
@@ -1373,108 +1474,6 @@ declare function resolvePaymentChain(): Promise<"base" | "solana">;
|
|
|
1373
1474
|
*/
|
|
1374
1475
|
declare const blockrunProvider: ProviderPlugin;
|
|
1375
1476
|
|
|
1376
|
-
/**
|
|
1377
|
-
* BlockRun Model Definitions for OpenClaw
|
|
1378
|
-
*
|
|
1379
|
-
* Maps BlockRun's model catalog to OpenClaw's ModelDefinitionConfig format.
|
|
1380
|
-
* All models use the "openai-completions" API since BlockRun is OpenAI-compatible.
|
|
1381
|
-
*
|
|
1382
|
-
* Pricing is in USD per 1M tokens. Operators pay these rates via x402;
|
|
1383
|
-
* they set their own markup when reselling to end users (Phase 2).
|
|
1384
|
-
*/
|
|
1385
|
-
|
|
1386
|
-
/**
|
|
1387
|
-
* Model aliases for convenient shorthand access.
|
|
1388
|
-
* Users can type `/model claude` instead of `/model blockrun/anthropic/claude-sonnet-4-6`.
|
|
1389
|
-
*/
|
|
1390
|
-
declare const MODEL_ALIASES: Record<string, string>;
|
|
1391
|
-
/**
|
|
1392
|
-
* Resolve a model alias to its full model ID.
|
|
1393
|
-
* Also strips "blockrun/" prefix for direct model paths.
|
|
1394
|
-
* Examples:
|
|
1395
|
-
* - "claude" -> "anthropic/claude-sonnet-4-6" (alias)
|
|
1396
|
-
* - "blockrun/claude" -> "anthropic/claude-sonnet-4-6" (alias with prefix)
|
|
1397
|
-
* - "blockrun/anthropic/claude-sonnet-4-6" -> "anthropic/claude-sonnet-4-6" (prefix stripped)
|
|
1398
|
-
* - "openai/gpt-4o" -> "openai/gpt-4o" (unchanged)
|
|
1399
|
-
*/
|
|
1400
|
-
declare function resolveModelAlias(model: string): string;
|
|
1401
|
-
type BlockRunModel = {
|
|
1402
|
-
id: string;
|
|
1403
|
-
name: string;
|
|
1404
|
-
/** Model version (e.g., "4.6", "3.1", "5.2") for tracking updates */
|
|
1405
|
-
version?: string;
|
|
1406
|
-
inputPrice: number;
|
|
1407
|
-
outputPrice: number;
|
|
1408
|
-
contextWindow: number;
|
|
1409
|
-
maxOutput: number;
|
|
1410
|
-
reasoning?: boolean;
|
|
1411
|
-
vision?: boolean;
|
|
1412
|
-
/** Models optimized for agentic workflows (multi-step autonomous tasks) */
|
|
1413
|
-
agentic?: boolean;
|
|
1414
|
-
/**
|
|
1415
|
-
* Model supports OpenAI-compatible structured function/tool calling.
|
|
1416
|
-
* Models without this flag output tool invocations as plain text JSON,
|
|
1417
|
-
* which leaks raw {"command":"..."} into visible chat messages.
|
|
1418
|
-
* Default: false (must opt-in to prevent silent regressions on new models).
|
|
1419
|
-
*/
|
|
1420
|
-
toolCalling?: boolean;
|
|
1421
|
-
/** Model is deprecated — will be routed to fallbackModel if set */
|
|
1422
|
-
deprecated?: boolean;
|
|
1423
|
-
/** Model ID to route to when this model is deprecated */
|
|
1424
|
-
fallbackModel?: string;
|
|
1425
|
-
/** Time-limited promotional pricing — auto-expires after endDate */
|
|
1426
|
-
promo?: {
|
|
1427
|
-
/** Flat price per request in USD (replaces token-based pricing) */
|
|
1428
|
-
flatPrice: number;
|
|
1429
|
-
/** ISO date, promo starts (inclusive). e.g. "2026-04-01" */
|
|
1430
|
-
startDate: string;
|
|
1431
|
-
/** ISO date, promo ends (exclusive). e.g. "2026-04-15" */
|
|
1432
|
-
endDate: string;
|
|
1433
|
-
};
|
|
1434
|
-
/**
|
|
1435
|
-
* Permanent flat per-request price in USD (backend billingMode: "flat").
|
|
1436
|
-
* Unlike promo, this never expires. Takes precedence over promo.
|
|
1437
|
-
*/
|
|
1438
|
-
flatPrice?: number;
|
|
1439
|
-
};
|
|
1440
|
-
declare const BLOCKRUN_MODELS: BlockRunModel[];
|
|
1441
|
-
/**
|
|
1442
|
-
* All BlockRun models in OpenClaw format (including aliases).
|
|
1443
|
-
* Used for proxy-side resolution (alias → target ID), tool routing, etc.
|
|
1444
|
-
*
|
|
1445
|
-
* Catalog entries shadowed by an identically-keyed alias are excluded:
|
|
1446
|
-
* resolveModelAlias checks MODEL_ALIASES first, so those catalog entries are
|
|
1447
|
-
* unreachable and their metadata (name/pricing) would misadvertise what
|
|
1448
|
-
* callers actually get. The alias-derived entry carries the redirect
|
|
1449
|
-
* target's real metadata instead.
|
|
1450
|
-
*/
|
|
1451
|
-
declare const OPENCLAW_MODELS: ModelDefinitionConfig[];
|
|
1452
|
-
declare const VISIBLE_OPENCLAW_MODELS: ModelDefinitionConfig[];
|
|
1453
|
-
/**
|
|
1454
|
-
* Build a ModelProviderConfig for BlockRun.
|
|
1455
|
-
*
|
|
1456
|
-
* Returns only the TOP_MODELS-listed subset so the OpenClaw picker stays
|
|
1457
|
-
* focused. Hidden models are still resolvable through the proxy.
|
|
1458
|
-
*
|
|
1459
|
-
* @param baseUrl - The proxy's local base URL (e.g., "http://127.0.0.1:12345")
|
|
1460
|
-
*/
|
|
1461
|
-
declare function buildProviderModels(baseUrl: string): ModelProviderConfig;
|
|
1462
|
-
/**
|
|
1463
|
-
* Check if a model is optimized for agentic workflows.
|
|
1464
|
-
* Agentic models continue autonomously with multi-step tasks
|
|
1465
|
-
* instead of stopping and waiting for user input.
|
|
1466
|
-
*/
|
|
1467
|
-
declare function isAgenticModel(modelId: string): boolean;
|
|
1468
|
-
/**
|
|
1469
|
-
* Get all agentic-capable models.
|
|
1470
|
-
*/
|
|
1471
|
-
declare function getAgenticModels(): string[];
|
|
1472
|
-
/**
|
|
1473
|
-
* Get context window size for a model.
|
|
1474
|
-
* Returns undefined if model not found.
|
|
1475
|
-
*/
|
|
1476
|
-
declare function getModelContextWindow(modelId: string): number | undefined;
|
|
1477
|
-
|
|
1478
1477
|
/**
|
|
1479
1478
|
* Usage Logger
|
|
1480
1479
|
*
|
|
@@ -1868,6 +1867,7 @@ declare function injectModelsConfig(logger: {
|
|
|
1868
1867
|
info: (msg: string) => void;
|
|
1869
1868
|
}, options?: {
|
|
1870
1869
|
forceWrite?: boolean;
|
|
1870
|
+
catalogModels?: typeof VISIBLE_OPENCLAW_MODELS;
|
|
1871
1871
|
}): void;
|
|
1872
1872
|
/**
|
|
1873
1873
|
* Repair the per-agent model cache OpenClaw keeps at
|
|
@@ -1894,6 +1894,7 @@ declare function syncAgentModelCache(logger: {
|
|
|
1894
1894
|
info: (msg: string) => void;
|
|
1895
1895
|
}, options?: {
|
|
1896
1896
|
forceWrite?: boolean;
|
|
1897
|
+
catalogModels?: typeof VISIBLE_OPENCLAW_MODELS;
|
|
1897
1898
|
}): void;
|
|
1898
1899
|
/**
|
|
1899
1900
|
* Inject dummy auth profile for BlockRun into agent auth stores.
|