Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

fix: rename Hindi locale in→hi, global tool name filter, collapse \n artifacts (#642, #637, #638)

diegosouzapw875279035222
diff --git a/open-sse/handlers/chatCore.ts b/open-sse/handlers/chatCore.ts
index 1da929b673..7f542124e3 100644
--- a/open-sse/handlers/chatCore.ts
+++ b/open-sse/handlers/chatCore.ts
@@ -347,6 +347,38 @@ export async function handleChatCore({
log?.debug?.("FORMAT", `${sourceFormat} → ${targetFormat} | stream=${stream}`);
+ // ── Common input sanitization (runs for ALL paths including passthrough) ──
+ // #291: Strip empty name fields from messages/input items
+ // Upstream providers (OpenAI, Codex) reject name:"" with 400 errors.
+ if (Array.isArray(body.messages)) {
+ body.messages = body.messages.map((msg: Record<string, unknown>) => {
+ if (msg.name === "") {
+ const { name: _n, ...rest } = msg;
+ return rest;
+ }
+ return msg;
+ });
+ }
+ if (Array.isArray(body.input)) {
+ body.input = body.input.map((item: Record<string, unknown>) => {
+ if (item.name === "") {
+ const { name: _n, ...rest } = item;
+ return rest;
+ }
+ return item;
+ });
+ }
+ // #346/#637: Strip tools with empty name
+ // Clients sometimes forward tool definitions with empty names, causing
+ // upstream providers to reject with 400 "Invalid 'tools[0].name': empty string."
+ if (Array.isArray(body.tools)) {
+ body.tools = body.tools.filter((tool: Record<string, unknown>) => {
+ const fn = tool.function as Record<string, unknown> | undefined;
+ const name = fn?.name ?? tool.name;
+ return name && String(name).trim().length > 0;
+ });
+ }
+
// Translate request (pass reqLogger for intermediate logging)
let translatedBody = body;
const isClaudePassthrough = sourceFormat === FORMATS.CLAUDE && targetFormat === FORMATS.CLAUDE;
@@ -401,40 +433,6 @@ export async function handleChatCore({
translatedBody._disableToolPrefix = true;
}
- // ── #291: Strip empty name fields from messages/input items ──
- // Upstream providers (OpenAI, Codex) reject name:"" with 400 errors.
- // Clients like PocketPaw may forward empty name fields from assistant turns.
- if (Array.isArray(translatedBody.messages)) {
- translatedBody.messages = translatedBody.messages.map((msg: Record<string, unknown>) => {
- if (msg.name === "") {
- const { name: _n, ...rest } = msg;
- return rest;
- }
- return msg;
- });
- }
- if (Array.isArray(translatedBody.input)) {
- translatedBody.input = translatedBody.input.map((item: Record<string, unknown>) => {
- if (item.name === "") {
- const { name: _n, ...rest } = item;
- return rest;
- }
- return item;
- });
- }
- // ── #346: Strip tools with empty name ──
- // Claude Code sometimes forwards tool definitions with empty names, causing
- // OpenAI-compatible upstream providers to reject with:
- // "Invalid 'input[N].name': empty string. Expected minimum length 1."
- // Handles both OpenAI format ({ function: { name } }) and Anthropic format ({ name }).
- if (Array.isArray(translatedBody.tools)) {
- translatedBody.tools = translatedBody.tools.filter((tool: Record<string, unknown>) => {
- const fn = tool.function as Record<string, unknown> | undefined;
- const name = fn?.name ?? tool.name;
- return name && String(name).trim().length > 0;
- });
- }
-
// Strip empty text content blocks from messages.
// Anthropic API rejects {"type":"text","text":""} with 400 "text content blocks must be non-empty".
// Some clients (LiteLLM passthrough, @ai-sdk/anthropic) may forward these empty blocks as-is.
diff --git a/open-sse/handlers/responseSanitizer.ts b/open-sse/handlers/responseSanitizer.ts
index 76500b1840..cb56c5efda 100644
--- a/open-sse/handlers/responseSanitizer.ts
+++ b/open-sse/handlers/responseSanitizer.ts
@@ -36,6 +36,13 @@ function toNumber(value: unknown): number | undefined {
// Matches <think>...</think> blocks (greedy, dotAll)
const THINK_TAG_REGEX = /<think>([\s\S]*?)<\/think>/gi;
+// #638: Collapse runs of 3+ consecutive newlines into \n\n
+// Tool call responses from thinking models often accumulate excessive newlines
+const EXCESSIVE_NEWLINES = /\n{3,}/g;
+function collapseExcessiveNewlines(text: string): string {
+ return text.replace(EXCESSIVE_NEWLINES, "\n\n");
+}
+
/**
* Extract <think> blocks from text content and return separated parts.
* @returns {{ content: string, thinking: string | null }}
@@ -157,7 +164,7 @@ function sanitizeMessage(msg: unknown): unknown {
// Handle content — extract <think> tags
if (typeof msgRecord.content === "string") {
const { content, thinking } = extractThinkingFromContent(msgRecord.content);
- sanitized.content = content;
+ sanitized.content = collapseExcessiveNewlines(content);
// Set reasoning_content from <think> tags (if not already set)
if (thinking && !msgRecord.reasoning_content) {
@@ -304,7 +311,12 @@ export function sanitizeStreamingChunk(parsed: unknown): unknown {
if (deltaRecord) {
const delta: JsonRecord = {};
if (deltaRecord.role !== undefined) delta.role = deltaRecord.role;
- if (deltaRecord.content !== undefined) delta.content = deltaRecord.content;
+ if (deltaRecord.content !== undefined) {
+ delta.content =
+ typeof deltaRecord.content === "string"
+ ? collapseExcessiveNewlines(deltaRecord.content)
+ : deltaRecord.content;
+ }
if (deltaRecord.reasoning_content !== undefined) {
delta.reasoning_content = deltaRecord.reasoning_content;
} else if (typeof deltaRecord.reasoning === "string" && deltaRecord.reasoning) {
diff --git a/src/i18n/config.ts b/src/i18n/config.ts
index 05ba25c32e..3b4b3ad560 100644
--- a/src/i18n/config.ts
+++ b/src/i18n/config.ts
@@ -11,7 +11,7 @@ export const LOCALES = [
"he",
"hu",
"id",
- "in",
+ "hi",
"it",
"ja",
"ko",
@@ -52,7 +52,7 @@ export const LANGUAGES: readonly {
{ code: "he", label: "HE", name: "עברית", flag: "🇮🇱" },
{ code: "hu", label: "HU", name: "Magyar", flag: "🇭🇺" },
{ code: "id", label: "ID", name: "Bahasa Indonesia", flag: "🇮🇩" },
- { code: "in", label: "IN", name: "हिन्दी", flag: "🇮🇳" },
+ { code: "hi", label: "HI", name: "हिन्दी", flag: "🇮🇳" },
{ code: "it", label: "IT", name: "Italiano", flag: "🇮🇹" },
{ code: "ja", label: "JA", name: "日本語", flag: "🇯🇵" },
{ code: "ko", label: "KO", name: "한국어", flag: "🇰🇷" },
diff --git a/src/i18n/messages/in.json b/src/i18n/messages/hi.json
similarity index 100%
rename from src/i18n/messages/in.json
rename to src/i18n/messages/hi.json