From d69e1287da0c5e19e208a48f10eb44af8b65f2a6 Mon Sep 17 00:00:00 2001 From: "kiloconnect[bot]" <240665456+kiloconnect[bot]@users.noreply.github.com> Date: Thu, 7 May 2026 06:53:51 +0000 Subject: [PATCH 1/2] refactor(openrouter): extract determineFallbackFeature helper Replace the legacy /openrouter path check with a system-prompt-based fallback: only default to 'direct-gateway' when the system prompt does not contain the Kilo or OpenClaw markers. --- apps/web/src/app/api/openrouter/[...path]/route.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/apps/web/src/app/api/openrouter/[...path]/route.ts b/apps/web/src/app/api/openrouter/[...path]/route.ts index 011a64332..96d516edf 100644 --- a/apps/web/src/app/api/openrouter/[...path]/route.ts +++ b/apps/web/src/app/api/openrouter/[...path]/route.ts @@ -132,6 +132,17 @@ function extractPromptInfo(requestBodyParsed: GatewayRequest): PromptInfo { return extractChatCompletionsPromptInfo(requestBodyParsed.body); } +function determineFallbackFeature(requestBodyParsed: GatewayRequest): 'direct-gateway' | null { + const { system_prompt_prefix } = extractPromptInfo(requestBodyParsed); + if ( + system_prompt_prefix.includes('You are Kilo') || + system_prompt_prefix.includes('You are a personal assistant running inside OpenClaw') + ) { + return null; + } + return 'direct-gateway'; +} + async function resolveRateLimit( feature: FeatureValue | null, ipAddress: string, @@ -217,10 +228,9 @@ export async function POST(request: NextRequest): Promise Date: Thu, 7 May 2026 07:49:01 +0000 Subject: [PATCH 2/2] simplify: return empty string fallback instead of null --- apps/web/src/app/api/openrouter/[...path]/route.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/web/src/app/api/openrouter/[...path]/route.ts b/apps/web/src/app/api/openrouter/[...path]/route.ts index 96d516edf..a388a9a76 100644 --- a/apps/web/src/app/api/openrouter/[...path]/route.ts +++ b/apps/web/src/app/api/openrouter/[...path]/route.ts @@ -132,13 +132,13 @@ function extractPromptInfo(requestBodyParsed: GatewayRequest): PromptInfo { return extractChatCompletionsPromptInfo(requestBodyParsed.body); } -function determineFallbackFeature(requestBodyParsed: GatewayRequest): 'direct-gateway' | null { +function determineFallbackFeature(requestBodyParsed: GatewayRequest): 'direct-gateway' | '' { const { system_prompt_prefix } = extractPromptInfo(requestBodyParsed); if ( system_prompt_prefix.includes('You are Kilo') || system_prompt_prefix.includes('You are a personal assistant running inside OpenClaw') ) { - return null; + return ''; } return 'direct-gateway'; } @@ -230,7 +230,7 @@ export async function POST(request: NextRequest): Promise