@blockrun/clawrouter 0.9.12 → 0.9.14
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 +42 -25
- package/dist/cli.js.map +1 -1
- package/dist/index.js +42 -25
- package/dist/index.js.map +1 -1
- package/package.json +4 -2
- package/scripts/reinstall.sh +17 -0
package/dist/cli.js
CHANGED
|
@@ -1356,7 +1356,7 @@ function route(prompt, systemPrompt, maxOutputTokens, options) {
|
|
|
1356
1356
|
|
|
1357
1357
|
// src/models.ts
|
|
1358
1358
|
var MODEL_ALIASES = {
|
|
1359
|
-
// Claude
|
|
1359
|
+
// Claude - short names
|
|
1360
1360
|
claude: "anthropic/claude-sonnet-4",
|
|
1361
1361
|
sonnet: "anthropic/claude-sonnet-4",
|
|
1362
1362
|
opus: "anthropic/claude-opus-4.6",
|
|
@@ -1364,6 +1364,11 @@ var MODEL_ALIASES = {
|
|
|
1364
1364
|
"opus-46": "anthropic/claude-opus-4.6",
|
|
1365
1365
|
"opus-45": "anthropic/claude-opus-4.5",
|
|
1366
1366
|
haiku: "anthropic/claude-haiku-4.5",
|
|
1367
|
+
// Claude - provider/shortname patterns (common in agent frameworks)
|
|
1368
|
+
"anthropic/sonnet": "anthropic/claude-sonnet-4",
|
|
1369
|
+
"anthropic/opus": "anthropic/claude-opus-4.6",
|
|
1370
|
+
"anthropic/haiku": "anthropic/claude-haiku-4.5",
|
|
1371
|
+
"anthropic/claude": "anthropic/claude-sonnet-4",
|
|
1367
1372
|
// OpenAI
|
|
1368
1373
|
gpt: "openai/gpt-4o",
|
|
1369
1374
|
gpt4: "openai/gpt-4o",
|
|
@@ -2441,12 +2446,13 @@ var DEFAULT_COMPRESSION_CONFIG = {
|
|
|
2441
2446
|
// src/compression/layers/deduplication.ts
|
|
2442
2447
|
import crypto2 from "crypto";
|
|
2443
2448
|
function hashMessage(message) {
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
message.content
|
|
2447
|
-
|
|
2448
|
-
message.
|
|
2449
|
-
|
|
2449
|
+
let contentStr = "";
|
|
2450
|
+
if (typeof message.content === "string") {
|
|
2451
|
+
contentStr = message.content;
|
|
2452
|
+
} else if (Array.isArray(message.content)) {
|
|
2453
|
+
contentStr = JSON.stringify(message.content);
|
|
2454
|
+
}
|
|
2455
|
+
const parts = [message.role, contentStr, message.tool_call_id || "", message.name || ""];
|
|
2450
2456
|
if (message.tool_calls) {
|
|
2451
2457
|
parts.push(
|
|
2452
2458
|
JSON.stringify(
|
|
@@ -2509,13 +2515,13 @@ function deduplicateMessages(messages) {
|
|
|
2509
2515
|
|
|
2510
2516
|
// src/compression/layers/whitespace.ts
|
|
2511
2517
|
function normalizeWhitespace(content) {
|
|
2512
|
-
if (!content) return content;
|
|
2518
|
+
if (!content || typeof content !== "string") return content;
|
|
2513
2519
|
return content.replace(/\r\n/g, "\n").replace(/\r/g, "\n").replace(/\n{3,}/g, "\n\n").replace(/[ \t]+$/gm, "").replace(/([^\n]) {2,}/g, "$1 ").replace(/^[ ]{8,}/gm, (match) => " ".repeat(Math.ceil(match.length / 4))).replace(/\t/g, " ").trim();
|
|
2514
2520
|
}
|
|
2515
2521
|
function normalizeMessagesWhitespace(messages) {
|
|
2516
2522
|
let charsSaved = 0;
|
|
2517
2523
|
const result = messages.map((message) => {
|
|
2518
|
-
if (!message.content) return message;
|
|
2524
|
+
if (!message.content || typeof message.content !== "string") return message;
|
|
2519
2525
|
const originalLength = message.content.length;
|
|
2520
2526
|
const normalizedContent = normalizeWhitespace(message.content);
|
|
2521
2527
|
charsSaved += originalLength - normalizedContent.length;
|
|
@@ -2619,6 +2625,9 @@ function generateCodebookHeader(usedCodes, pathMap = {}) {
|
|
|
2619
2625
|
|
|
2620
2626
|
// src/compression/layers/dictionary.ts
|
|
2621
2627
|
function encodeContent(content, inverseCodebook) {
|
|
2628
|
+
if (!content || typeof content !== "string") {
|
|
2629
|
+
return { encoded: content, substitutions: 0, codes: /* @__PURE__ */ new Set(), charsSaved: 0 };
|
|
2630
|
+
}
|
|
2622
2631
|
let encoded = content;
|
|
2623
2632
|
let substitutions = 0;
|
|
2624
2633
|
let charsSaved = 0;
|
|
@@ -2646,7 +2655,7 @@ function encodeMessages(messages) {
|
|
|
2646
2655
|
let totalCharsSaved = 0;
|
|
2647
2656
|
const allUsedCodes = /* @__PURE__ */ new Set();
|
|
2648
2657
|
const result = messages.map((message) => {
|
|
2649
|
-
if (!message.content) return message;
|
|
2658
|
+
if (!message.content || typeof message.content !== "string") return message;
|
|
2650
2659
|
const { encoded, substitutions, codes, charsSaved } = encodeContent(
|
|
2651
2660
|
message.content,
|
|
2652
2661
|
inverseCodebook
|
|
@@ -2672,7 +2681,7 @@ var PATH_REGEX = /(?:\/[\w.-]+){3,}/g;
|
|
|
2672
2681
|
function extractPaths(messages) {
|
|
2673
2682
|
const paths = [];
|
|
2674
2683
|
for (const message of messages) {
|
|
2675
|
-
if (!message.content) continue;
|
|
2684
|
+
if (!message.content || typeof message.content !== "string") continue;
|
|
2676
2685
|
const matches = message.content.match(PATH_REGEX);
|
|
2677
2686
|
if (matches) {
|
|
2678
2687
|
paths.push(...matches);
|
|
@@ -2714,7 +2723,7 @@ function shortenPaths(messages) {
|
|
|
2714
2723
|
});
|
|
2715
2724
|
let charsSaved = 0;
|
|
2716
2725
|
const result = messages.map((message) => {
|
|
2717
|
-
if (!message.content) return message;
|
|
2726
|
+
if (!message.content || typeof message.content !== "string") return message;
|
|
2718
2727
|
let content = message.content;
|
|
2719
2728
|
const originalLength = content.length;
|
|
2720
2729
|
for (const [code, prefix] of Object.entries(pathMap)) {
|
|
@@ -2765,7 +2774,7 @@ function compactMessagesJson(messages) {
|
|
|
2765
2774
|
const newLength = JSON.stringify(newMessage.tool_calls).length;
|
|
2766
2775
|
charsSaved += originalLength - newLength;
|
|
2767
2776
|
}
|
|
2768
|
-
if (message.role === "tool" && message.content && looksLikeJson(message.content)) {
|
|
2777
|
+
if (message.role === "tool" && message.content && typeof message.content === "string" && looksLikeJson(message.content)) {
|
|
2769
2778
|
const originalLength = message.content.length;
|
|
2770
2779
|
const compacted = compactJson(message.content);
|
|
2771
2780
|
charsSaved += originalLength - compacted.length;
|
|
@@ -2830,7 +2839,7 @@ function deduplicateLargeBlocks(messages) {
|
|
|
2830
2839
|
const blockHashes = /* @__PURE__ */ new Map();
|
|
2831
2840
|
let charsSaved = 0;
|
|
2832
2841
|
const result = messages.map((msg, idx) => {
|
|
2833
|
-
if (!msg.content || msg.content.length < 500) {
|
|
2842
|
+
if (!msg.content || typeof msg.content !== "string" || msg.content.length < 500) {
|
|
2834
2843
|
return msg;
|
|
2835
2844
|
}
|
|
2836
2845
|
const blockKey = msg.content.slice(0, 200);
|
|
@@ -2850,7 +2859,7 @@ function compressObservations(messages) {
|
|
|
2850
2859
|
let charsSaved = 0;
|
|
2851
2860
|
let observationsCompressed = 0;
|
|
2852
2861
|
let result = messages.map((msg) => {
|
|
2853
|
-
if (msg.role !== "tool" || !msg.content) {
|
|
2862
|
+
if (msg.role !== "tool" || !msg.content || typeof msg.content !== "string") {
|
|
2854
2863
|
return msg;
|
|
2855
2864
|
}
|
|
2856
2865
|
const original = msg.content;
|
|
@@ -2903,7 +2912,7 @@ function findRepeatedPhrases(allContent) {
|
|
|
2903
2912
|
function buildDynamicCodebook(messages) {
|
|
2904
2913
|
let allContent = "";
|
|
2905
2914
|
for (const msg of messages) {
|
|
2906
|
-
if (msg.content) {
|
|
2915
|
+
if (msg.content && typeof msg.content === "string") {
|
|
2907
2916
|
allContent += msg.content + "\n";
|
|
2908
2917
|
}
|
|
2909
2918
|
}
|
|
@@ -2928,6 +2937,7 @@ function buildDynamicCodebook(messages) {
|
|
|
2928
2937
|
return codebook;
|
|
2929
2938
|
}
|
|
2930
2939
|
function escapeRegex2(str) {
|
|
2940
|
+
if (!str || typeof str !== "string") return "";
|
|
2931
2941
|
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2932
2942
|
}
|
|
2933
2943
|
function applyDynamicCodebook(messages) {
|
|
@@ -2948,7 +2958,7 @@ function applyDynamicCodebook(messages) {
|
|
|
2948
2958
|
let charsSaved = 0;
|
|
2949
2959
|
let substitutions = 0;
|
|
2950
2960
|
const result = messages.map((msg) => {
|
|
2951
|
-
if (!msg.content) return msg;
|
|
2961
|
+
if (!msg.content || typeof msg.content !== "string") return msg;
|
|
2952
2962
|
let content = msg.content;
|
|
2953
2963
|
for (const phrase of sortedPhrases) {
|
|
2954
2964
|
const code = phraseToCode[phrase];
|
|
@@ -2981,7 +2991,12 @@ function generateDynamicCodebookHeader(codebook) {
|
|
|
2981
2991
|
// src/compression/index.ts
|
|
2982
2992
|
function calculateTotalChars(messages) {
|
|
2983
2993
|
return messages.reduce((total, msg) => {
|
|
2984
|
-
let chars =
|
|
2994
|
+
let chars = 0;
|
|
2995
|
+
if (typeof msg.content === "string") {
|
|
2996
|
+
chars = msg.content.length;
|
|
2997
|
+
} else if (Array.isArray(msg.content)) {
|
|
2998
|
+
chars = JSON.stringify(msg.content).length;
|
|
2999
|
+
}
|
|
2985
3000
|
if (msg.tool_calls) {
|
|
2986
3001
|
chars += JSON.stringify(msg.tool_calls).length;
|
|
2987
3002
|
}
|
|
@@ -3000,12 +3015,14 @@ function prependCodebookHeader(messages, usedCodes, pathMap) {
|
|
|
3000
3015
|
}
|
|
3001
3016
|
return messages.map((msg, i) => {
|
|
3002
3017
|
if (i === userIndex) {
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
|
|
3018
|
+
if (typeof msg.content === "string") {
|
|
3019
|
+
return {
|
|
3020
|
+
...msg,
|
|
3021
|
+
content: `${header}
|
|
3006
3022
|
|
|
3007
|
-
${msg.content
|
|
3008
|
-
|
|
3023
|
+
${msg.content}`
|
|
3024
|
+
};
|
|
3025
|
+
}
|
|
3009
3026
|
}
|
|
3010
3027
|
return msg;
|
|
3011
3028
|
});
|
|
@@ -3110,11 +3127,11 @@ async function compressContext(messages, config = {}) {
|
|
|
3110
3127
|
const dynHeader = generateDynamicCodebookHeader(dynamicCodes);
|
|
3111
3128
|
if (dynHeader) {
|
|
3112
3129
|
const systemIndex = result.findIndex((m) => m.role === "system");
|
|
3113
|
-
if (systemIndex >= 0) {
|
|
3130
|
+
if (systemIndex >= 0 && typeof result[systemIndex].content === "string") {
|
|
3114
3131
|
result[systemIndex] = {
|
|
3115
3132
|
...result[systemIndex],
|
|
3116
3133
|
content: `${dynHeader}
|
|
3117
|
-
${result[systemIndex].content
|
|
3134
|
+
${result[systemIndex].content}`
|
|
3118
3135
|
};
|
|
3119
3136
|
}
|
|
3120
3137
|
}
|