@blockrun/clawrouter 0.10.15 → 0.10.17
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 +26 -9
- package/dist/cli.js.map +1 -1
- package/dist/index.js +27 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
3
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
4
|
+
}) : x)(function(x) {
|
|
5
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
6
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
|
+
});
|
|
2
8
|
|
|
3
9
|
// src/proxy.ts
|
|
4
10
|
import { createServer } from "http";
|
|
@@ -511,6 +517,8 @@ function calibrateConfidence(distance, steepness) {
|
|
|
511
517
|
|
|
512
518
|
// src/router/selector.ts
|
|
513
519
|
var BASELINE_MODEL_ID = "anthropic/claude-opus-4.6";
|
|
520
|
+
var BASELINE_INPUT_PRICE = 5;
|
|
521
|
+
var BASELINE_OUTPUT_PRICE = 25;
|
|
514
522
|
function selectModel(tier, confidence, method, reasoning, tierConfigs, modelPricing, estimatedInputTokens, maxOutputTokens, routingProfile, agenticScore) {
|
|
515
523
|
const tierConfig = tierConfigs[tier];
|
|
516
524
|
const model = tierConfig.primary;
|
|
@@ -521,8 +529,8 @@ function selectModel(tier, confidence, method, reasoning, tierConfigs, modelPric
|
|
|
521
529
|
const outputCost = maxOutputTokens / 1e6 * outputPrice;
|
|
522
530
|
const costEstimate = inputCost + outputCost;
|
|
523
531
|
const opusPricing = modelPricing.get(BASELINE_MODEL_ID);
|
|
524
|
-
const opusInputPrice = opusPricing?.inputPrice ??
|
|
525
|
-
const opusOutputPrice = opusPricing?.outputPrice ??
|
|
532
|
+
const opusInputPrice = opusPricing?.inputPrice ?? BASELINE_INPUT_PRICE;
|
|
533
|
+
const opusOutputPrice = opusPricing?.outputPrice ?? BASELINE_OUTPUT_PRICE;
|
|
526
534
|
const baselineInput = estimatedInputTokens / 1e6 * opusInputPrice;
|
|
527
535
|
const baselineOutput = maxOutputTokens / 1e6 * opusOutputPrice;
|
|
528
536
|
const baselineCost = baselineInput + baselineOutput;
|
|
@@ -551,8 +559,8 @@ function calculateModelCost(model, modelPricing, estimatedInputTokens, maxOutput
|
|
|
551
559
|
const outputCost = maxOutputTokens / 1e6 * outputPrice;
|
|
552
560
|
const costEstimate = inputCost + outputCost;
|
|
553
561
|
const opusPricing = modelPricing.get(BASELINE_MODEL_ID);
|
|
554
|
-
const opusInputPrice = opusPricing?.inputPrice ??
|
|
555
|
-
const opusOutputPrice = opusPricing?.outputPrice ??
|
|
562
|
+
const opusInputPrice = opusPricing?.inputPrice ?? BASELINE_INPUT_PRICE;
|
|
563
|
+
const opusOutputPrice = opusPricing?.outputPrice ?? BASELINE_OUTPUT_PRICE;
|
|
556
564
|
const baselineInput = estimatedInputTokens / 1e6 * opusInputPrice;
|
|
557
565
|
const baselineOutput = maxOutputTokens / 1e6 * opusOutputPrice;
|
|
558
566
|
const baselineCost = baselineInput + baselineOutput;
|
|
@@ -1743,7 +1751,11 @@ var DEFAULT_ROUTING_CONFIG = {
|
|
|
1743
1751
|
MEDIUM: {
|
|
1744
1752
|
primary: "moonshot/kimi-k2.5",
|
|
1745
1753
|
// $0.50/$2.40 - strong tool use, handles function calls correctly
|
|
1746
|
-
fallback: [
|
|
1754
|
+
fallback: [
|
|
1755
|
+
"anthropic/claude-haiku-4.5",
|
|
1756
|
+
"deepseek/deepseek-chat",
|
|
1757
|
+
"xai/grok-4-1-fast-non-reasoning"
|
|
1758
|
+
]
|
|
1747
1759
|
},
|
|
1748
1760
|
COMPLEX: {
|
|
1749
1761
|
primary: "anthropic/claude-sonnet-4.6",
|
|
@@ -3827,7 +3839,7 @@ function shouldCompress(messages) {
|
|
|
3827
3839
|
|
|
3828
3840
|
// src/session.ts
|
|
3829
3841
|
var DEFAULT_SESSION_CONFIG = {
|
|
3830
|
-
enabled:
|
|
3842
|
+
enabled: true,
|
|
3831
3843
|
timeoutMs: 30 * 60 * 1e3,
|
|
3832
3844
|
// 30 minutes
|
|
3833
3845
|
headerName: "x-session-id"
|
|
@@ -3954,6 +3966,13 @@ function getSessionId(headers, headerName = DEFAULT_SESSION_CONFIG.headerName) {
|
|
|
3954
3966
|
}
|
|
3955
3967
|
return void 0;
|
|
3956
3968
|
}
|
|
3969
|
+
function deriveSessionId(messages) {
|
|
3970
|
+
const firstUser = messages.find((m) => m.role === "user");
|
|
3971
|
+
if (!firstUser) return void 0;
|
|
3972
|
+
const content = typeof firstUser.content === "string" ? firstUser.content : JSON.stringify(firstUser.content);
|
|
3973
|
+
const { createHash: createHash3 } = __require("crypto");
|
|
3974
|
+
return createHash3("sha256").update(content).digest("hex").slice(0, 8);
|
|
3975
|
+
}
|
|
3957
3976
|
|
|
3958
3977
|
// src/updater.ts
|
|
3959
3978
|
var NPM_REGISTRY = "https://registry.npmjs.org/@blockrun/clawrouter/latest";
|
|
@@ -5263,9 +5282,7 @@ async function proxyRequest(req, res, apiBase, payFetch, options, routerOpts, de
|
|
|
5263
5282
|
latencyMs: 0
|
|
5264
5283
|
});
|
|
5265
5284
|
} else {
|
|
5266
|
-
const sessionId2 = getSessionId(
|
|
5267
|
-
req.headers
|
|
5268
|
-
);
|
|
5285
|
+
const sessionId2 = getSessionId(req.headers) ?? deriveSessionId(parsedMessages);
|
|
5269
5286
|
const existingSession = sessionId2 ? sessionStore.getSession(sessionId2) : void 0;
|
|
5270
5287
|
if (existingSession) {
|
|
5271
5288
|
console.log(
|