mirror of
https://github.com/Nezumi-2711/9router.git
synced 2026-09-22 13:38:31 +00:00
fix: detect Claude format for /v1/messages + sanitize tool descriptions (#397)
This commit is contained in:
@@ -21,6 +21,9 @@ export function detectFormatByEndpoint(pathname, body) {
|
|||||||
// /v1/responses is always openai-responses
|
// /v1/responses is always openai-responses
|
||||||
if (pathname.includes("/v1/responses")) return FORMATS.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)
|
// /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)) {
|
if (pathname.includes("/v1/chat/completions") && Array.isArray(body?.input)) {
|
||||||
return FORMATS.OPENAI;
|
return FORMATS.OPENAI;
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ export function filterToOpenAIFormat(body) {
|
|||||||
type: "function",
|
type: "function",
|
||||||
function: {
|
function: {
|
||||||
name: tool.name,
|
name: tool.name,
|
||||||
description: tool.description || "",
|
description: String(tool.description || ""),
|
||||||
parameters: tool.input_schema || { type: "object", properties: {} }
|
parameters: tool.input_schema || { type: "object", properties: {} }
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -99,7 +99,7 @@ export function filterToOpenAIFormat(body) {
|
|||||||
type: "function",
|
type: "function",
|
||||||
function: {
|
function: {
|
||||||
name: fn.name,
|
name: fn.name,
|
||||||
description: fn.description || "",
|
description: String(fn.description || ""),
|
||||||
parameters: fn.parameters || { type: "object", properties: {} }
|
parameters: fn.parameters || { type: "object", properties: {} }
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ export function claudeToOpenAIRequest(model, body, stream) {
|
|||||||
type: "function",
|
type: "function",
|
||||||
function: {
|
function: {
|
||||||
name: tool.name,
|
name: tool.name,
|
||||||
description: tool.description,
|
description: String(tool.description || ""),
|
||||||
parameters: tool.input_schema || { type: "object", properties: {} }
|
parameters: tool.input_schema || { type: "object", properties: {} }
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ export function openaiResponsesToOpenAIRequest(model, body, stream, credentials)
|
|||||||
type: "function",
|
type: "function",
|
||||||
function: {
|
function: {
|
||||||
name,
|
name,
|
||||||
description: tool.description,
|
description: String(tool.description || ""),
|
||||||
parameters: tool.parameters,
|
parameters: tool.parameters,
|
||||||
strict: tool.strict
|
strict: tool.strict
|
||||||
}
|
}
|
||||||
@@ -259,7 +259,7 @@ export function openaiToOpenAIResponsesRequest(model, body, stream, credentials)
|
|||||||
return {
|
return {
|
||||||
type: "function",
|
type: "function",
|
||||||
name: tool.function.name,
|
name: tool.function.name,
|
||||||
description: tool.function.description,
|
description: String(tool.function.description || ""),
|
||||||
parameters: tool.function.parameters,
|
parameters: tool.function.parameters,
|
||||||
strict: tool.function.strict
|
strict: tool.function.strict
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user