@blockrun/clawrouter 0.8.8 → 0.8.10
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.js +16 -8
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +17 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -221,6 +221,15 @@ type ModelPricing = {
|
|
|
221
221
|
* Get the ordered fallback chain for a tier: [primary, ...fallbacks].
|
|
222
222
|
*/
|
|
223
223
|
declare function getFallbackChain(tier: Tier, tierConfigs: Record<Tier, TierConfig>): string[];
|
|
224
|
+
/**
|
|
225
|
+
* Calculate cost for a specific model (used when fallback model is used).
|
|
226
|
+
* Returns updated cost fields for RoutingDecision.
|
|
227
|
+
*/
|
|
228
|
+
declare function calculateModelCost(model: string, modelPricing: Map<string, ModelPricing>, estimatedInputTokens: number, maxOutputTokens: number): {
|
|
229
|
+
costEstimate: number;
|
|
230
|
+
baselineCost: number;
|
|
231
|
+
savings: number;
|
|
232
|
+
};
|
|
224
233
|
/**
|
|
225
234
|
* Get the fallback chain filtered by context length.
|
|
226
235
|
* Only returns models that can handle the estimated total context.
|
|
@@ -882,4 +891,4 @@ declare function formatStatsAscii(stats: AggregatedStats): string;
|
|
|
882
891
|
|
|
883
892
|
declare const plugin: OpenClawPluginDefinition;
|
|
884
893
|
|
|
885
|
-
export { type AggregatedStats, BALANCE_THRESHOLDS, BLOCKRUN_MODELS, type BalanceInfo, BalanceMonitor, type CachedPaymentParams, type CachedResponse, DEFAULT_RETRY_CONFIG, DEFAULT_ROUTING_CONFIG, DEFAULT_SESSION_CONFIG, type DailyStats, EmptyWalletError, InsufficientFundsError, type InsufficientFundsInfo, type LowBalanceInfo, MODEL_ALIASES, OPENCLAW_MODELS, PaymentCache, type PaymentFetchResult, type PreAuthParams, type ProxyHandle, type ProxyOptions, RequestDeduplicator, type RetryConfig, type RoutingConfig, type RoutingDecision, RpcError, type SessionConfig, type SessionEntry, SessionStore, type SufficiencyResult, type Tier, type UsageEntry, blockrunProvider, buildProviderModels, createPaymentFetch, plugin as default, fetchWithRetry, formatStatsAscii, getAgenticModels, getFallbackChain, getFallbackChainFiltered, getModelContextWindow, getProxyPort, getSessionId, getStats, isAgenticModel, isBalanceError, isEmptyWalletError, isInsufficientFundsError, isRetryable, isRpcError, logUsage, resolveModelAlias, route, startProxy };
|
|
894
|
+
export { type AggregatedStats, BALANCE_THRESHOLDS, BLOCKRUN_MODELS, type BalanceInfo, BalanceMonitor, type CachedPaymentParams, type CachedResponse, DEFAULT_RETRY_CONFIG, DEFAULT_ROUTING_CONFIG, DEFAULT_SESSION_CONFIG, type DailyStats, EmptyWalletError, InsufficientFundsError, type InsufficientFundsInfo, type LowBalanceInfo, MODEL_ALIASES, OPENCLAW_MODELS, PaymentCache, type PaymentFetchResult, type PreAuthParams, type ProxyHandle, type ProxyOptions, RequestDeduplicator, type RetryConfig, type RoutingConfig, type RoutingDecision, RpcError, type SessionConfig, type SessionEntry, SessionStore, type SufficiencyResult, type Tier, type UsageEntry, blockrunProvider, buildProviderModels, calculateModelCost, createPaymentFetch, plugin as default, fetchWithRetry, formatStatsAscii, getAgenticModels, getFallbackChain, getFallbackChainFiltered, getModelContextWindow, getProxyPort, getSessionId, getStats, isAgenticModel, isBalanceError, isEmptyWalletError, isInsufficientFundsError, isRetryable, isRpcError, logUsage, resolveModelAlias, route, startProxy };
|
package/dist/index.js
CHANGED
|
@@ -908,12 +908,16 @@ function selectModel(tier, confidence, method, reasoning, tierConfigs, modelPric
|
|
|
908
908
|
const tierConfig = tierConfigs[tier];
|
|
909
909
|
const model = tierConfig.primary;
|
|
910
910
|
const pricing = modelPricing.get(model);
|
|
911
|
-
const
|
|
912
|
-
const
|
|
911
|
+
const inputPrice = pricing?.inputPrice ?? 0;
|
|
912
|
+
const outputPrice = pricing?.outputPrice ?? 0;
|
|
913
|
+
const inputCost = estimatedInputTokens / 1e6 * inputPrice;
|
|
914
|
+
const outputCost = maxOutputTokens / 1e6 * outputPrice;
|
|
913
915
|
const costEstimate = inputCost + outputCost;
|
|
914
916
|
const opusPricing = modelPricing.get("anthropic/claude-opus-4");
|
|
915
|
-
const
|
|
916
|
-
const
|
|
917
|
+
const opusInputPrice = opusPricing?.inputPrice ?? 0;
|
|
918
|
+
const opusOutputPrice = opusPricing?.outputPrice ?? 0;
|
|
919
|
+
const baselineInput = estimatedInputTokens / 1e6 * opusInputPrice;
|
|
920
|
+
const baselineOutput = maxOutputTokens / 1e6 * opusOutputPrice;
|
|
917
921
|
const baselineCost = baselineInput + baselineOutput;
|
|
918
922
|
const savings = baselineCost > 0 ? Math.max(0, (baselineCost - costEstimate) / baselineCost) : 0;
|
|
919
923
|
return {
|
|
@@ -933,12 +937,16 @@ function getFallbackChain(tier, tierConfigs) {
|
|
|
933
937
|
}
|
|
934
938
|
function calculateModelCost(model, modelPricing, estimatedInputTokens, maxOutputTokens) {
|
|
935
939
|
const pricing = modelPricing.get(model);
|
|
936
|
-
const
|
|
937
|
-
const
|
|
940
|
+
const inputPrice = pricing?.inputPrice ?? 0;
|
|
941
|
+
const outputPrice = pricing?.outputPrice ?? 0;
|
|
942
|
+
const inputCost = estimatedInputTokens / 1e6 * inputPrice;
|
|
943
|
+
const outputCost = maxOutputTokens / 1e6 * outputPrice;
|
|
938
944
|
const costEstimate = inputCost + outputCost;
|
|
939
945
|
const opusPricing = modelPricing.get("anthropic/claude-opus-4");
|
|
940
|
-
const
|
|
941
|
-
const
|
|
946
|
+
const opusInputPrice = opusPricing?.inputPrice ?? 0;
|
|
947
|
+
const opusOutputPrice = opusPricing?.outputPrice ?? 0;
|
|
948
|
+
const baselineInput = estimatedInputTokens / 1e6 * opusInputPrice;
|
|
949
|
+
const baselineOutput = maxOutputTokens / 1e6 * opusOutputPrice;
|
|
942
950
|
const baselineCost = baselineInput + baselineOutput;
|
|
943
951
|
const savings = baselineCost > 0 ? Math.max(0, (baselineCost - costEstimate) / baselineCost) : 0;
|
|
944
952
|
return { costEstimate, baselineCost, savings };
|
|
@@ -3996,6 +4004,7 @@ export {
|
|
|
3996
4004
|
SessionStore,
|
|
3997
4005
|
blockrunProvider,
|
|
3998
4006
|
buildProviderModels,
|
|
4007
|
+
calculateModelCost,
|
|
3999
4008
|
createPaymentFetch,
|
|
4000
4009
|
index_default as default,
|
|
4001
4010
|
fetchWithRetry,
|