@blockrun/clawrouter 0.12.241 → 0.12.242
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/cli.d.ts +1 -0
- package/dist/cli.js +1620 -118
- package/dist/index.d.ts +13 -176
- package/dist/index.js +1620 -118
- package/dist/router/index.d.ts +1 -0
- package/dist/router/index.js +3292 -0
- package/package.json +6 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { RoutingConfig, RoutingDecision } from '@blockrun/router-core';
|
|
2
|
+
export { DEFAULT_ROUTING_CONFIG, RouterOptions, RoutingConfig, RoutingDecision, TaskType, Tier, calculateModelCost, filterCandidatesByCapacity, getFallbackChain, getFallbackChainFiltered, inferToolRequirement, route } from '@blockrun/router-core';
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
5
|
* OpenClaw Plugin Types (locally defined)
|
|
3
6
|
*
|
|
@@ -355,181 +358,6 @@ type OpenClawPluginDefinition = {
|
|
|
355
358
|
};
|
|
356
359
|
};
|
|
357
360
|
|
|
358
|
-
/**
|
|
359
|
-
* Tier → Model Selection
|
|
360
|
-
*
|
|
361
|
-
* Maps a classification tier to the cheapest capable model.
|
|
362
|
-
* Builds RoutingDecision metadata with cost estimates and savings.
|
|
363
|
-
*/
|
|
364
|
-
|
|
365
|
-
type ModelPricing = {
|
|
366
|
-
inputPrice: number;
|
|
367
|
-
outputPrice: number;
|
|
368
|
-
/** Active promo flat price per request (overrides token-based pricing when set) */
|
|
369
|
-
flatPrice?: number;
|
|
370
|
-
};
|
|
371
|
-
/**
|
|
372
|
-
* Get the ordered fallback chain for a tier: [primary, ...fallbacks].
|
|
373
|
-
*/
|
|
374
|
-
declare function getFallbackChain(tier: Tier, tierConfigs: Record<Tier, TierConfig>): string[];
|
|
375
|
-
declare function calculateModelCost(model: string, modelPricing: Map<string, ModelPricing>, estimatedInputTokens: number, maxOutputTokens: number, routingProfile?: "free" | "eco" | "auto" | "premium"): {
|
|
376
|
-
costEstimate: number;
|
|
377
|
-
baselineCost: number;
|
|
378
|
-
savings: number;
|
|
379
|
-
};
|
|
380
|
-
/**
|
|
381
|
-
* Get the fallback chain filtered by context length.
|
|
382
|
-
* Only returns models that can handle the estimated total context.
|
|
383
|
-
*
|
|
384
|
-
* @param tier - The tier to get fallback chain for
|
|
385
|
-
* @param tierConfigs - Tier configurations
|
|
386
|
-
* @param estimatedTotalTokens - Estimated total context (input + output)
|
|
387
|
-
* @param getContextWindow - Function to get context window for a model ID
|
|
388
|
-
* @returns Filtered list of models that can handle the context
|
|
389
|
-
*/
|
|
390
|
-
declare function getFallbackChainFiltered(tier: Tier, tierConfigs: Record<Tier, TierConfig>, estimatedTotalTokens: number, getContextWindow: (modelId: string) => number | undefined): string[];
|
|
391
|
-
|
|
392
|
-
/**
|
|
393
|
-
* Smart Router Types
|
|
394
|
-
*
|
|
395
|
-
* Four classification tiers — REASONING is distinct from COMPLEX because
|
|
396
|
-
* reasoning tasks need different models (o3, gemini-pro) than general
|
|
397
|
-
* complex tasks (gpt-4o, sonnet-4).
|
|
398
|
-
*
|
|
399
|
-
* Scoring uses weighted float dimensions with sigmoid confidence calibration.
|
|
400
|
-
*/
|
|
401
|
-
type Tier = "SIMPLE" | "MEDIUM" | "COMPLEX" | "REASONING";
|
|
402
|
-
type RoutingDecision = {
|
|
403
|
-
model: string;
|
|
404
|
-
tier: Tier;
|
|
405
|
-
confidence: number;
|
|
406
|
-
method: "rules" | "llm";
|
|
407
|
-
reasoning: string;
|
|
408
|
-
costEstimate: number;
|
|
409
|
-
baselineCost: number;
|
|
410
|
-
savings: number;
|
|
411
|
-
agenticScore?: number;
|
|
412
|
-
/** Which tier configs were used (auto/eco/premium/agentic) — avoids re-derivation in proxy */
|
|
413
|
-
tierConfigs?: Record<Tier, TierConfig>;
|
|
414
|
-
/** Which routing profile was applied */
|
|
415
|
-
profile?: "auto" | "eco" | "premium" | "agentic";
|
|
416
|
-
};
|
|
417
|
-
type RouterOptions = {
|
|
418
|
-
config: RoutingConfig;
|
|
419
|
-
modelPricing: Map<string, ModelPricing>;
|
|
420
|
-
routingProfile?: "eco" | "auto" | "premium";
|
|
421
|
-
hasTools?: boolean;
|
|
422
|
-
/** Override current time for promotion window checks (for testing). Default: new Date() */
|
|
423
|
-
now?: Date;
|
|
424
|
-
};
|
|
425
|
-
type TierConfig = {
|
|
426
|
-
primary: string;
|
|
427
|
-
fallback: string[];
|
|
428
|
-
};
|
|
429
|
-
type ScoringConfig = {
|
|
430
|
-
tokenCountThresholds: {
|
|
431
|
-
simple: number;
|
|
432
|
-
complex: number;
|
|
433
|
-
};
|
|
434
|
-
codeKeywords: string[];
|
|
435
|
-
reasoningKeywords: string[];
|
|
436
|
-
simpleKeywords: string[];
|
|
437
|
-
technicalKeywords: string[];
|
|
438
|
-
creativeKeywords: string[];
|
|
439
|
-
imperativeVerbs: string[];
|
|
440
|
-
constraintIndicators: string[];
|
|
441
|
-
outputFormatKeywords: string[];
|
|
442
|
-
referenceKeywords: string[];
|
|
443
|
-
negationKeywords: string[];
|
|
444
|
-
domainSpecificKeywords: string[];
|
|
445
|
-
agenticTaskKeywords: string[];
|
|
446
|
-
dimensionWeights: Record<string, number>;
|
|
447
|
-
tierBoundaries: {
|
|
448
|
-
simpleMedium: number;
|
|
449
|
-
mediumComplex: number;
|
|
450
|
-
complexReasoning: number;
|
|
451
|
-
};
|
|
452
|
-
confidenceSteepness: number;
|
|
453
|
-
confidenceThreshold: number;
|
|
454
|
-
};
|
|
455
|
-
type ClassifierConfig = {
|
|
456
|
-
llmModel: string;
|
|
457
|
-
llmMaxTokens: number;
|
|
458
|
-
llmTemperature: number;
|
|
459
|
-
promptTruncationChars: number;
|
|
460
|
-
cacheTtlMs: number;
|
|
461
|
-
};
|
|
462
|
-
type OverridesConfig = {
|
|
463
|
-
maxTokensForceComplex: number;
|
|
464
|
-
structuredOutputMinTier: Tier;
|
|
465
|
-
ambiguousDefaultTier: Tier;
|
|
466
|
-
/**
|
|
467
|
-
* When enabled, prefer models optimized for agentic workflows.
|
|
468
|
-
* Agentic models continue autonomously with multi-step tasks
|
|
469
|
-
* instead of stopping and waiting for user input.
|
|
470
|
-
*/
|
|
471
|
-
agenticMode?: boolean;
|
|
472
|
-
};
|
|
473
|
-
/**
|
|
474
|
-
* Time-windowed promotion that temporarily overrides tier routing.
|
|
475
|
-
* Active promotions are auto-applied; expired ones are ignored at runtime.
|
|
476
|
-
*/
|
|
477
|
-
type Promotion = {
|
|
478
|
-
/** Human-readable label (e.g. "GLM-5 Launch Promo") */
|
|
479
|
-
name: string;
|
|
480
|
-
/** ISO date string, promotion starts (inclusive). e.g. "2026-04-01" */
|
|
481
|
-
startDate: string;
|
|
482
|
-
/** ISO date string, promotion ends (exclusive). e.g. "2026-04-15" */
|
|
483
|
-
endDate: string;
|
|
484
|
-
/** Partial tier overrides — merged into the active tier configs (primary/fallback) */
|
|
485
|
-
tierOverrides: Partial<Record<Tier, Partial<TierConfig>>>;
|
|
486
|
-
/** Which profiles this applies to. Default: all profiles. */
|
|
487
|
-
profiles?: Array<"auto" | "eco" | "premium" | "agentic">;
|
|
488
|
-
};
|
|
489
|
-
type RoutingConfig = {
|
|
490
|
-
version: string;
|
|
491
|
-
classifier: ClassifierConfig;
|
|
492
|
-
scoring: ScoringConfig;
|
|
493
|
-
tiers: Record<Tier, TierConfig>;
|
|
494
|
-
/**
|
|
495
|
-
* Tier configs for agentic mode — models that excel at multi-step tasks.
|
|
496
|
-
* Set to `null` to disable agentic tier selection entirely (forces all
|
|
497
|
-
* requests through `tiers`, even when tools are present in the request).
|
|
498
|
-
*/
|
|
499
|
-
agenticTiers?: Record<Tier, TierConfig> | null;
|
|
500
|
-
/** Tier configs for eco profile — ultra cost-optimized (blockrun/eco). `null` falls back to `tiers`. */
|
|
501
|
-
ecoTiers?: Record<Tier, TierConfig> | null;
|
|
502
|
-
/** Tier configs for premium profile — best quality (blockrun/premium). `null` falls back to `tiers`. */
|
|
503
|
-
premiumTiers?: Record<Tier, TierConfig> | null;
|
|
504
|
-
/** Time-windowed promotions that temporarily override tier routing */
|
|
505
|
-
promotions?: Promotion[];
|
|
506
|
-
overrides: OverridesConfig;
|
|
507
|
-
};
|
|
508
|
-
|
|
509
|
-
/**
|
|
510
|
-
* Default Routing Config
|
|
511
|
-
*
|
|
512
|
-
* All routing parameters as a TypeScript constant.
|
|
513
|
-
* Operators override via openclaw.yaml plugin config.
|
|
514
|
-
*
|
|
515
|
-
* Scoring uses 15 weighted dimensions with sigmoid confidence calibration.
|
|
516
|
-
*/
|
|
517
|
-
|
|
518
|
-
declare const DEFAULT_ROUTING_CONFIG: RoutingConfig;
|
|
519
|
-
|
|
520
|
-
/**
|
|
521
|
-
* Smart Router Entry Point
|
|
522
|
-
*
|
|
523
|
-
* Classifies requests and routes to the cheapest capable model.
|
|
524
|
-
* Delegates to pluggable RouterStrategy (default: RulesStrategy, <1ms).
|
|
525
|
-
*/
|
|
526
|
-
|
|
527
|
-
/**
|
|
528
|
-
* Route a request to the cheapest capable model.
|
|
529
|
-
* Delegates to the registered "rules" strategy by default.
|
|
530
|
-
*/
|
|
531
|
-
declare function route(prompt: string, systemPrompt: string | undefined, maxOutputTokens: number, options: RouterOptions): RoutingDecision;
|
|
532
|
-
|
|
533
361
|
/**
|
|
534
362
|
* Response Cache for LLM Completions
|
|
535
363
|
*
|
|
@@ -1000,6 +828,15 @@ type ProxyOptions = {
|
|
|
1000
828
|
network: string;
|
|
1001
829
|
}) => void;
|
|
1002
830
|
onRouted?: (decision: RoutingDecision) => void;
|
|
831
|
+
/** Local comparison only; it never changes the serving request or sends another completion. */
|
|
832
|
+
onShadowRouted?: (comparison: {
|
|
833
|
+
executed: RoutingDecision;
|
|
834
|
+
shadow: RoutingDecision;
|
|
835
|
+
sameModel: boolean;
|
|
836
|
+
hasTools: boolean;
|
|
837
|
+
hasVision: boolean;
|
|
838
|
+
requiresStructuredOutput: boolean;
|
|
839
|
+
}) => void;
|
|
1003
840
|
/** Called when balance drops below $1.00 (warning, request still proceeds) */
|
|
1004
841
|
onLowBalance?: (info: LowBalanceInfo) => void;
|
|
1005
842
|
/** Called when balance is insufficient for a request (request fails) */
|
|
@@ -1752,4 +1589,4 @@ declare function parseCallArgs(raw: string): {
|
|
|
1752
1589
|
};
|
|
1753
1590
|
declare const plugin: OpenClawPluginDefinition;
|
|
1754
1591
|
|
|
1755
|
-
export { type AggregatedStats, BALANCE_THRESHOLDS, BLOCKRUN_MODELS, type BalanceInfo, BalanceMonitor, type CachedLLMResponse, type CachedResponse, type CheckResult, DEFAULT_RETRY_CONFIG,
|
|
1592
|
+
export { type AggregatedStats, BALANCE_THRESHOLDS, BLOCKRUN_MODELS, type BalanceInfo, BalanceMonitor, type CachedLLMResponse, type CachedResponse, type CheckResult, DEFAULT_RETRY_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, 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 UsageEntry, VISIBLE_OPENCLAW_MODELS, type WalletConfig, type WalletResolution, blockrunProvider, 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, resolveModelAlias, resolvePaymentChain, savePaymentChain, setupSolana, startProxy, syncAgentModelCache };
|