@blockrun/clawrouter 0.9.4 → 0.9.6

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/index.d.ts CHANGED
@@ -581,7 +581,12 @@ declare const blockrunProvider: ProviderPlugin;
581
581
  declare const MODEL_ALIASES: Record<string, string>;
582
582
  /**
583
583
  * Resolve a model alias to its full model ID.
584
- * Returns the original model if not an alias.
584
+ * Also strips "blockrun/" prefix for direct model paths.
585
+ * Examples:
586
+ * - "claude" -> "anthropic/claude-sonnet-4" (alias)
587
+ * - "blockrun/claude" -> "anthropic/claude-sonnet-4" (alias with prefix)
588
+ * - "blockrun/anthropic/claude-sonnet-4" -> "anthropic/claude-sonnet-4" (prefix stripped)
589
+ * - "openai/gpt-4o" -> "openai/gpt-4o" (unchanged)
585
590
  */
586
591
  declare function resolveModelAlias(model: string): string;
587
592
  type BlockRunModel = {
package/dist/index.js CHANGED
@@ -37,6 +37,7 @@ function resolveModelAlias(model) {
37
37
  const withoutPrefix = normalized.slice("blockrun/".length);
38
38
  const resolvedWithoutPrefix = MODEL_ALIASES[withoutPrefix];
39
39
  if (resolvedWithoutPrefix) return resolvedWithoutPrefix;
40
+ return withoutPrefix;
40
41
  }
41
42
  return model;
42
43
  }
@@ -2111,9 +2112,11 @@ var RequestDeduplicator = class {
2111
2112
  removeInflight(key) {
2112
2113
  const entry = this.inflight.get(key);
2113
2114
  if (entry) {
2114
- const errorBody = Buffer.from(JSON.stringify({
2115
- error: { message: "Original request failed, please retry", type: "dedup_origin_failed" }
2116
- }));
2115
+ const errorBody = Buffer.from(
2116
+ JSON.stringify({
2117
+ error: { message: "Original request failed, please retry", type: "dedup_origin_failed" }
2118
+ })
2119
+ );
2117
2120
  for (const resolve of entry.resolvers) {
2118
2121
  resolve({
2119
2122
  status: 503,
@@ -3246,6 +3249,7 @@ var ROUTING_PROFILES = /* @__PURE__ */ new Set([
3246
3249
  "premium"
3247
3250
  ]);
3248
3251
  var FREE_MODEL = "nvidia/gpt-oss-120b";
3252
+ var MAX_MESSAGES = 200;
3249
3253
  var HEARTBEAT_INTERVAL_MS = 2e3;
3250
3254
  var DEFAULT_REQUEST_TIMEOUT_MS = 18e4;
3251
3255
  var MAX_FALLBACK_ATTEMPTS = 5;
@@ -3554,6 +3558,17 @@ function normalizeMessagesForThinking(messages) {
3554
3558
  });
3555
3559
  return hasChanges ? normalized : messages;
3556
3560
  }
3561
+ function truncateMessages(messages) {
3562
+ if (!messages || messages.length <= MAX_MESSAGES) return messages;
3563
+ const systemMsgs = messages.filter((m) => m.role === "system");
3564
+ const conversationMsgs = messages.filter((m) => m.role !== "system");
3565
+ const maxConversation = MAX_MESSAGES - systemMsgs.length;
3566
+ const truncatedConversation = conversationMsgs.slice(-maxConversation);
3567
+ console.log(
3568
+ `[ClawRouter] Truncated messages: ${messages.length} \u2192 ${systemMsgs.length + truncatedConversation.length} (kept ${systemMsgs.length} system + ${truncatedConversation.length} recent)`
3569
+ );
3570
+ return [...systemMsgs, ...truncatedConversation];
3571
+ }
3557
3572
  var KIMI_BLOCK_RE = /<[||][^<>]*begin[^<>]*[||]>[\s\S]*?<[||][^<>]*end[^<>]*[||]>/gi;
3558
3573
  var KIMI_TOKEN_RE = /<[||][^<>]*[||]>/g;
3559
3574
  var THINKING_TAG_RE = /<\s*\/?\s*(?:think(?:ing)?|thought|antthinking)\b[^>]*>/gi;
@@ -3863,6 +3878,9 @@ async function tryModelRequest(upstreamUrl, method, headers, body, modelId, maxT
3863
3878
  if (Array.isArray(parsed.messages)) {
3864
3879
  parsed.messages = normalizeMessageRoles(parsed.messages);
3865
3880
  }
3881
+ if (Array.isArray(parsed.messages)) {
3882
+ parsed.messages = truncateMessages(parsed.messages);
3883
+ }
3866
3884
  if (Array.isArray(parsed.messages)) {
3867
3885
  parsed.messages = sanitizeToolIds(parsed.messages);
3868
3886
  }