@blockrun/clawrouter 0.10.16 → 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 +21 -8
- package/dist/cli.js.map +1 -1
- package/dist/index.js +22 -8
- 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;
|
|
@@ -3831,7 +3839,7 @@ function shouldCompress(messages) {
|
|
|
3831
3839
|
|
|
3832
3840
|
// src/session.ts
|
|
3833
3841
|
var DEFAULT_SESSION_CONFIG = {
|
|
3834
|
-
enabled:
|
|
3842
|
+
enabled: true,
|
|
3835
3843
|
timeoutMs: 30 * 60 * 1e3,
|
|
3836
3844
|
// 30 minutes
|
|
3837
3845
|
headerName: "x-session-id"
|
|
@@ -3958,6 +3966,13 @@ function getSessionId(headers, headerName = DEFAULT_SESSION_CONFIG.headerName) {
|
|
|
3958
3966
|
}
|
|
3959
3967
|
return void 0;
|
|
3960
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
|
+
}
|
|
3961
3976
|
|
|
3962
3977
|
// src/updater.ts
|
|
3963
3978
|
var NPM_REGISTRY = "https://registry.npmjs.org/@blockrun/clawrouter/latest";
|
|
@@ -5267,9 +5282,7 @@ async function proxyRequest(req, res, apiBase, payFetch, options, routerOpts, de
|
|
|
5267
5282
|
latencyMs: 0
|
|
5268
5283
|
});
|
|
5269
5284
|
} else {
|
|
5270
|
-
const sessionId2 = getSessionId(
|
|
5271
|
-
req.headers
|
|
5272
|
-
);
|
|
5285
|
+
const sessionId2 = getSessionId(req.headers) ?? deriveSessionId(parsedMessages);
|
|
5273
5286
|
const existingSession = sessionId2 ? sessionStore.getSession(sessionId2) : void 0;
|
|
5274
5287
|
if (existingSession) {
|
|
5275
5288
|
console.log(
|