@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/index.js
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
+
});
|
|
7
|
+
|
|
1
8
|
// src/models.ts
|
|
2
9
|
var MODEL_ALIASES = {
|
|
3
10
|
// Claude - use newest versions (4.6)
|
|
@@ -1141,6 +1148,8 @@ function calibrateConfidence(distance, steepness) {
|
|
|
1141
1148
|
|
|
1142
1149
|
// src/router/selector.ts
|
|
1143
1150
|
var BASELINE_MODEL_ID = "anthropic/claude-opus-4.6";
|
|
1151
|
+
var BASELINE_INPUT_PRICE = 5;
|
|
1152
|
+
var BASELINE_OUTPUT_PRICE = 25;
|
|
1144
1153
|
function selectModel(tier, confidence, method, reasoning, tierConfigs, modelPricing, estimatedInputTokens, maxOutputTokens, routingProfile, agenticScore) {
|
|
1145
1154
|
const tierConfig = tierConfigs[tier];
|
|
1146
1155
|
const model = tierConfig.primary;
|
|
@@ -1151,8 +1160,8 @@ function selectModel(tier, confidence, method, reasoning, tierConfigs, modelPric
|
|
|
1151
1160
|
const outputCost = maxOutputTokens / 1e6 * outputPrice;
|
|
1152
1161
|
const costEstimate = inputCost + outputCost;
|
|
1153
1162
|
const opusPricing = modelPricing.get(BASELINE_MODEL_ID);
|
|
1154
|
-
const opusInputPrice = opusPricing?.inputPrice ??
|
|
1155
|
-
const opusOutputPrice = opusPricing?.outputPrice ??
|
|
1163
|
+
const opusInputPrice = opusPricing?.inputPrice ?? BASELINE_INPUT_PRICE;
|
|
1164
|
+
const opusOutputPrice = opusPricing?.outputPrice ?? BASELINE_OUTPUT_PRICE;
|
|
1156
1165
|
const baselineInput = estimatedInputTokens / 1e6 * opusInputPrice;
|
|
1157
1166
|
const baselineOutput = maxOutputTokens / 1e6 * opusOutputPrice;
|
|
1158
1167
|
const baselineCost = baselineInput + baselineOutput;
|
|
@@ -1181,8 +1190,8 @@ function calculateModelCost(model, modelPricing, estimatedInputTokens, maxOutput
|
|
|
1181
1190
|
const outputCost = maxOutputTokens / 1e6 * outputPrice;
|
|
1182
1191
|
const costEstimate = inputCost + outputCost;
|
|
1183
1192
|
const opusPricing = modelPricing.get(BASELINE_MODEL_ID);
|
|
1184
|
-
const opusInputPrice = opusPricing?.inputPrice ??
|
|
1185
|
-
const opusOutputPrice = opusPricing?.outputPrice ??
|
|
1193
|
+
const opusInputPrice = opusPricing?.inputPrice ?? BASELINE_INPUT_PRICE;
|
|
1194
|
+
const opusOutputPrice = opusPricing?.outputPrice ?? BASELINE_OUTPUT_PRICE;
|
|
1186
1195
|
const baselineInput = estimatedInputTokens / 1e6 * opusInputPrice;
|
|
1187
1196
|
const baselineOutput = maxOutputTokens / 1e6 * opusOutputPrice;
|
|
1188
1197
|
const baselineCost = baselineInput + baselineOutput;
|
|
@@ -3981,7 +3990,7 @@ function shouldCompress(messages) {
|
|
|
3981
3990
|
|
|
3982
3991
|
// src/session.ts
|
|
3983
3992
|
var DEFAULT_SESSION_CONFIG = {
|
|
3984
|
-
enabled:
|
|
3993
|
+
enabled: true,
|
|
3985
3994
|
timeoutMs: 30 * 60 * 1e3,
|
|
3986
3995
|
// 30 minutes
|
|
3987
3996
|
headerName: "x-session-id"
|
|
@@ -4108,6 +4117,13 @@ function getSessionId(headers, headerName = DEFAULT_SESSION_CONFIG.headerName) {
|
|
|
4108
4117
|
}
|
|
4109
4118
|
return void 0;
|
|
4110
4119
|
}
|
|
4120
|
+
function deriveSessionId(messages) {
|
|
4121
|
+
const firstUser = messages.find((m) => m.role === "user");
|
|
4122
|
+
if (!firstUser) return void 0;
|
|
4123
|
+
const content = typeof firstUser.content === "string" ? firstUser.content : JSON.stringify(firstUser.content);
|
|
4124
|
+
const { createHash: createHash3 } = __require("crypto");
|
|
4125
|
+
return createHash3("sha256").update(content).digest("hex").slice(0, 8);
|
|
4126
|
+
}
|
|
4111
4127
|
|
|
4112
4128
|
// src/updater.ts
|
|
4113
4129
|
var NPM_REGISTRY = "https://registry.npmjs.org/@blockrun/clawrouter/latest";
|
|
@@ -5417,9 +5433,7 @@ async function proxyRequest(req, res, apiBase, payFetch, options, routerOpts, de
|
|
|
5417
5433
|
latencyMs: 0
|
|
5418
5434
|
});
|
|
5419
5435
|
} else {
|
|
5420
|
-
const sessionId2 = getSessionId(
|
|
5421
|
-
req.headers
|
|
5422
|
-
);
|
|
5436
|
+
const sessionId2 = getSessionId(req.headers) ?? deriveSessionId(parsedMessages);
|
|
5423
5437
|
const existingSession = sessionId2 ? sessionStore.getSession(sessionId2) : void 0;
|
|
5424
5438
|
if (existingSession) {
|
|
5425
5439
|
console.log(
|