fix: detect Claude format for /v1/messages + sanitize tool descriptions (#397)

This commit is contained in:
Ryan 2026-03-27 06:38:37 +03:00 committed by GitHub
parent 868eabffc0
commit 3b4184b09e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 8 additions and 5 deletions

View file

@ -21,6 +21,9 @@ export function detectFormatByEndpoint(pathname, body) {
// /v1/responses is always openai-responses
if (pathname.includes("/v1/responses")) return FORMATS.OPENAI_RESPONSES;
// /v1/messages is always Claude
if (pathname.includes("/v1/messages")) return FORMATS.CLAUDE;
// /v1/chat/completions + input[] → treat as openai (Cursor CLI sends Responses body via chat endpoint)
if (pathname.includes("/v1/chat/completions") && Array.isArray(body?.input)) {
return FORMATS.OPENAI;

View file

@ -87,7 +87,7 @@ export function filterToOpenAIFormat(body) {
type: "function",
function: {
name: tool.name,
description: tool.description || "",
description: String(tool.description || ""),
parameters: tool.input_schema || { type: "object", properties: {} }
}
};
@ -99,7 +99,7 @@ export function filterToOpenAIFormat(body) {
type: "function",
function: {
name: fn.name,
description: fn.description || "",
description: String(fn.description || ""),
parameters: fn.parameters || { type: "object", properties: {} }
}
}));

View file

@ -59,7 +59,7 @@ export function claudeToOpenAIRequest(model, body, stream) {
type: "function",
function: {
name: tool.name,
description: tool.description,
description: String(tool.description || ""),
parameters: tool.input_schema || { type: "object", properties: {} }
}
}));

View file

@ -138,7 +138,7 @@ export function openaiResponsesToOpenAIRequest(model, body, stream, credentials)
type: "function",
function: {
name,
description: tool.description,
description: String(tool.description || ""),
parameters: tool.parameters,
strict: tool.strict
}
@ -259,7 +259,7 @@ export function openaiToOpenAIResponsesRequest(model, body, stream, credentials)
return {
type: "function",
name: tool.function.name,
description: tool.function.description,
description: String(tool.function.description || ""),
parameters: tool.function.parameters,
strict: tool.function.strict
};